Notifications
Clear all

[Closed] Mesh UVS change after being attached?

I’m working on a script to collapse some geometry before doing an export. I’m running into a problem with attach() or meshop.attach(). I’d like to take an array of nodes, and attach copies of them to a new mesh, then I will export that new mesh.

My problem is that when I loop through the array of nodes and attach them to the mesh, the UVs of the new mesh do not match the UVs of the individual nodes. After looking through the docs I thought Meshop.attach() might fix this by setting the targetnode:, but i’m not sure if I understand how that works.

Here is some sample code that shoes the problem, after running this look at the UVs of $myCollapsedMesh. I would expect to see typical box mapping there, but thats not the case.

(
	--An array of random geometry
	For i=1 to 4 do(  
		NewBox = box()
		NewBox.pos.x = (i*100)
	)
	
	MyGeo = $box*     
		
	--Make an empty mesh
		
	NewExportMesh = editable_mesh()
	NewExportMesh.name = "myCollapsedMesh"
	
	--Attach copies of objs in MyGeo to the empty mesh
	
	for obj in MyGeo do(
			NewMesh = snapshotasmesh obj
			--attach NewExportMesh NewMesh
			meshop.attach NewExportMesh NewMesh targetNode:NewExportMesh.baseobject
		)
	addModifier NewExportMesh (Unwrap_UVW ())
		
)

Any Ideas?
Thanks in advance!

1 Reply

The reason it breaks on your example is your boxes have no UVs to begin with. This code should work:

(
–An array of random geometry
For i=1 to 4 do(
NewBox = box mapcoords:true
NewBox.pos.x = (i*100)
)

    MyGeo = $box*     
        
    --Make an empty mesh
        
    NewExportMesh = editable_mesh()
    NewExportMesh.name = "myCollapsedMesh"
    
    --Attach copies of objs in MyGeo to the empty mesh
    
    for obj in MyGeo do(
            NewMesh = snapshotasmesh obj
            --attach NewExportMesh NewMesh
            meshop.attach NewExportMesh NewMesh targetNode:NewExportMesh.baseobject
        )
    addModifier NewExportMesh (Unwrap_UVW ())
        
)

Now I am not sure what is going on with your other case. I would add an Unwrap UVW, or other mapping method, to each one before attaching them, that may fix the problem.

-Eric