[Closed] How to put back a changed UV vertex into the mesh
Hi guys,
I’m trying to automatically check a mesh for UV coordinates that are smaller than 0 or bigger than 1.
If so, I give them a value of 0.5.
After that I want to store those vertex values back into the mesh, but I don’t understand how to do that last step.
This is my script:
clearlistener()
obj = $Box001
for f = 1 to obj.numfaces do
(
face = getFace obj f
vertx = getVert obj face.x
verty = getVert obj face.y
vertz = getVert obj face.z
tFace = meshOp.getMapFace obj 1 f -- getTVFace obj f
uvwVertX = meshOp.getMapVert obj 1 tFace.x
uvwVertY = meshOp.getMapVert obj 1 tFace.y
uvwVertZ = meshOp.getMapVert obj 1 tFace.z
if(uvwVertX.x<0.0 or uvwVertX.x>1.0) do
(
print("uvwVertX.x = " + uvwVertX.x as string)
uvwVertX.x = 0.5
)
if(uvwVertX.y<0.0 or uvwVertX.y>1.0) do
(
print("uvwVertX.y = " + uvwVertX.y as string)
uvwVertX.y = 0.5
)
if(uvwVertY.x<0.0 or uvwVertY.x>1.0) do
(
print("uvwVertY.x = " + uvwVertY.x as string)
uvwVertY.x = 0.5
)
if(uvwVertY.y<0.0 or uvwVertY.y>1.0) do
(
print("uvwVertY.y = " + uvwVertY.y as string)
uvwVertY.y = 0.5
)
if(uvwVertZ.x<0.0 or uvwVertZ.x>1.0) do
(
print("uvwVertZ.x = " + uvwVertX.x as string)
uvwVertZ.x = 0.5
)
if(uvwVertZ.y<0.0 or uvwVertZ.y>1.0) do
(
print("uvwVertZ.y = " + uvwVertZ.y as string)
uvwVertZ.y = 0.5
)
-- meshop.setMapVert obj 1 f [uvwVertX, uvwVertY, uvwVertZ]
)
The last line (blocked out) fails because I’m using 3 x point3 values instead of 1 point3 value.
setMapVert asks for 1 point, but I have 3 points.
Could anyone teach me how to put all three values back into the mesh?
I have attached a simple box with UV coordinates that are out of bounds, as example.
Thanks so much!
Never mind, the solution is this:
meshop.setMapVert obj 1 tFace.x uvwVertX
meshop.setMapVert obj 1 tFace.y uvwVertY
meshop.setMapVert obj 1 tFace.z uvwVertZ
Thank you very much! You’re welcome dude. You’re awesome. Nah, you are.
FYI, the x/y/z components of a Point3 value can be accessed via an index – so you can use a for-loop instead of repeating your tests for all three axes.
The same goes for accessing the corners of a tri-face – it feels more natural to refer to a face-corner as faceVerts[3] instead of faceVerts.y
You aren’t doing anything with face-data, at least not in your example, so you might as well just run through each map-vert directly.
So a shorter/faster method for doing the same thing might be:
(
local obj = $
local chan = 1
-- Get number of mapping-verts in channel 1:
local numMapVerts = meshOp.GetNumMapVerts chan obj
-- Process each mapping-vert:
for mapVertNum = 1 to numMapVerts do
(
-- Get mapping-vert:
local mapVert =*meshOp.GetMapVert obj chan mapVertNum
-- We only really need to modify mesh if there's been a change:
local changed = False
-- Process point's x/y/z, which can be accessed by index:
for xyz = 1 to 3 do*
(
local val =*mapVert[xyz]
if (val < 0.0) or (val*> 1.0) do
(
mapVert[xyz]*= 0.5
changed = True
)
)
-- Make changes to the mesh:
if*changed do*
(
meshop.SetMapVert obj chan mapVertNum*mapVert
)
)
-- Editable Mesh needs 'Update' to show changes in the viewport:
Update*obj
)