Help setting UV coords (using meshop.setMapVert)

Hello! I am playing around with writing a script to edit UVs, and am not having any luck getting meshop.setMapVert to result in any change to UVs.

Is there some sort of update function that needs to get called after setting a coordinate? Because setting a new coordinate appears to have no effect.

Take this example script. For each map UV vert in the selected mesh, I should be setting a totally random UV coordinate.

numverts = meshop.getNumMapVerts $.mesh 1
for i in 1 to numverts do
(
	RandomCoord = [random 0.0 1.0, random 0.0 1.0, 0.0]
	meshop.setMapVert $.mesh 1 i RandomCoord
)

But running this has no visible affect on the selected mesh's UV coords.

Here's a version that shows that the meshop.getMapVert function returns the same original coordinate, both before and after being set.

msg = "";
numverts = meshop.getNumMapVerts $.mesh 1
for i in 1 to numverts do
(
	CoordPre = meshop.getMapVert $.mesh 1 i
	RandomCoord = [random 0.0 1.0, random 0.0 1.0, 0.0];
	meshop.setMapVert $.mesh 1 i RandomCoord
	CoordPost = meshop.getMapVert $.mesh 1 i
	msg += (i as string) + "  |  same: " +((CoordPre == CoordPost) as string)+" | Pre: " + (CoordPre as string) + "  | Post: " + (CoordPost as string)+ "  | RadomCoord: "+(RandomCoord  as string)+"\n";
)
msg

Any idea what I'm missing here? Thanks!

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Swordslayer's picture

Not how it works

Each time you call $.mesh, you get a new mesh (you should also delete it when you're done assigning it back btw.), only some changes are allowed to propagate back (and only when the node is editable_mesh anyway), most of them don't. So for example this will be a different story:

 

msg = ""
m = snapshotAsMesh $
numverts = meshop.getNumMapVerts m 1
for i in 1 to numverts do
(
	CoordPre = meshop.getMapVert m 1 i
	RandomCoord = [random 0.0 1.0, random 0.0 1.0, 0.0];
	meshop.setMapVert m 1 i RandomCoord
	CoordPost = meshop.getMapVert m 1 i
	msg += (i as string) + "  |  same: " +((CoordPre == CoordPost) as string)+" | Pre: " + (CoordPre as string) + "  | Post: " + (CoordPost as string)+ "  | RadomCoord: "+(RandomCoord  as string)+"\n";
)
delete m
msg

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.