[Closed] UVW Unwrap unknown Error
this is how you may handle it as script only creation…
fn lerp a b s = (a + s * (b - a))
-- sets edge vis
fn mxssetedgevisflags m face flags =
(
setEdgeVis m face 1 flags[1];
setEdgeVis m face 2 flags[2];
setEdgeVis m face 3 flags[3];
)
-- generate ucoords base on distances
fn GetUCoords msh nsegs =
(
ucoords = #();
ucoords.count = nsegs + 1;
ucoords[1] = 0.0;
if nsegs == 1 then
ucoords[2] = 1.0;
else
(
tlen = 0.0;
p1 = getvert msh 1
for i = 2 to nsegs + 1 do
(
p2 = getvert msh i;
tlen += distance p1 p2;
ucoords[i] = tlen;
p1 = p2;
)
for i = 1 to ucoords.count do ucoords[i] /= tlen; -- normalize to the total length
)
ucoords
)
-- generate V coords base on the x or y dimension
fn GetVCoords msh nsegs size xdim =
(
vcoords = #();
vcoords.count = nsegs + 1;
scalar = 0.5/size;
for i = 1 to nsegs + 1 do
(
p = getvert msh i;
if xdim then
vcoords[i] = scalar * abs p.x;
else
vcoords[i] = scalar * abs p.y;
)
vcoords;
)
-- build the mesh
fn BuildPicframeMesh width height size zscale profile mapCoords contUV =
(
nsegs = profile.count - 1;
nsegs_p1 = nsegs + 1;
nverts = nsegs_p1 * 4;
nfaces = nsegs * 4 * 2;
-- offsets and sizes
w = width * 0.5;
h = height * 0.5;
s = size * 0.5;
-- "cardinal" points that form the interior and exterior corners of the picture frame
cp = #([-w-s,-h-s,0],[-w+s,-h+s,0],[w+s,-h-s,0],[w-s,-h+s,0],[w+s,h+s,0],[w-s,h-s,0],[-w-s,h+s,0],[-w+s,h-s,0]);
msh = mesh numverts:nverts numfaces:nfaces;
-- geo verts
vi = 1; -- vert incrementer
for i = 1 to 4 do
(
pind = i*2;
p1 = cp[pind - 1];
p2 = cp[pind];
for j = 1 to nsegs_p1 do
(
p = lerp p1 p2 profile[j].x;
p.z = profile[j].y * zscale;
setvert msh vi p;
vi += 1;
)
)
-- geo faces
fi = 1; -- face incrementer
si_offset = 0;
ei_offset = nsegs_p1;
for i = 1 to 4 do
(
for j = 1 to nsegs do
(
s1 = si_offset + j;
e1 = ei_offset + j;
s2 = s1 + 1;
e2 = e1 + 1;
setface msh fi [e1,e2,s1]
mxssetedgevisflags msh fi #{1,3}
fi += 1;
setface msh fi [s2,s1,e2]
mxssetedgevisflags msh fi #{1,3}
fi += 1;
)
si_offset += nsegs_p1;
ei_offset += nsegs_p1;
if i == 3 then ei_offset = 0;
)
if mapCoords then
(
if contUV then
(
-- allocate mapping
ntverts = nverts + nsegs_p1;
meshop.setMapSupport msh 1 true;
meshop.setNumMapVerts msh 1 ntverts;
meshop.setNumMapFaces msh 1 nfaces;
-- mapping verts
tlen = 2 * (width + height);
vcoords = #(0.0, width/tlen, (width + height)/tlen, (2.0 * width + height)/tlen, 1.0);
ucoords = GetUCoords msh nsegs;
vi = 1;
for i = 1 to 5 do -- no wrap around with uv verts
(
for j = 1 to nsegs_p1 do
(
meshop.setmapvert msh 1 vi [ucoords[j], vcoords[i],0.0];
vi += 1;
)
)
-- mapping faces
fi = 1;
si_offset = 0;
ei_offset = nsegs_p1;
for i = 1 to 4 do
(
for j = 1 to nsegs do
(
s1 = si_offset + j;
e1 = ei_offset + j;
s2 = s1 + 1;
e2 = e1 + 1;
meshop.setMapFace msh 1 fi [e1,e2,s1]
fi += 1;
meshop.setMapFace msh 1 fi [s2,s1,e2]
fi += 1;
)
si_offset += nsegs_p1;
ei_offset += nsegs_p1;
)
)
else -- create mapping base on xy positions
(
ntverts = 4 * 2 * nsegs_p1;
meshop.setMapSupport msh 1 true;
meshop.setNumMapVerts msh 1 ntverts;
meshop.setNumMapFaces msh 1 nfaces;
ucoords = GetUCoords msh nsegs;
w_vcoords = GetVCoords msh nsegs size true;
h_vcoords = GetVCoords msh nsegs size false;
vi = 1;
for i = 1 to 4 do
(
for j = 1 to nsegs_p1 do
(
if i == 1 or i == 3 then
vcoord = w_vcoords[j];
else
vcoord = h_vcoords[j];
meshop.setmapvert msh 1 vi [ucoords[j], 0.5 + vcoord,0.0];
vi += 1;
)
for j = 1 to nsegs_p1 do
(
if i == 1 or i == 3 then
vcoord = w_vcoords[j];
else
vcoord = h_vcoords[j];
meshop.setmapvert msh 1 vi [ucoords[j], 0.5 - vcoord, 0.0];
vi += 1;
)
)
fi = 1;
si_offset = 0;
ei_offset = nsegs_p1;
for i = 1 to 4 do
(
for j = 1 to nsegs do
(
s1 = si_offset + j;
e1 = ei_offset + j;
s2 = s1 + 1;
e2 = e1 + 1;
meshop.setMapFace msh 1 fi [e1,e2,s1]
fi += 1;
meshop.setMapFace msh 1 fi [s2,s1,e2]
fi += 1;
)
si_offset += nsegs_p1 * 2;
ei_offset += nsegs_p1 * 2;
)
)
)
update msh;
msh;
)
-- simple square profile
pictframe = BuildPicframeMesh 10.0 8.0 2.0 1.5 #([0,0],[0,1],[1,1],[1,0]) true false;
Thanks for the breakdown. So after working on this all day I have finally understood what this is doing (I started maxscript a week and a half ago), though i don’t understand the purpose of doing the setFaces as it doesn’t seem to change the unwrap at all? How might you go about using the break function? And the relax function? Can you do those without a UVW unwrap? I need to break each side into an individual piece so that I can rotate the side pieces. I’m using a wood procedural map and i’d like the grain to flow the correct way.
here’s the mesh building script with some more UV options and a picture quad. Also the overall size is based on the frame interior eddge/picture size not the frame center.
fn lerp a b s = (a + s * (b - a))
-- sets edge vis
fn mxssetedgevisflags m face flags =
(
setEdgeVis m face 1 flags[1];
setEdgeVis m face 2 flags[2];
setEdgeVis m face 3 flags[3];
)
-- generate ucoords base on distances
fn GetUCoords msh nsegs =
(
ucoords = #();
ucoords.count = nsegs + 1;
ucoords[1] = 0.0;
if nsegs == 1 then
ucoords[2] = 1.0;
else
(
tlen = 0.0;
p1 = getvert msh 1
for i = 2 to nsegs + 1 do
(
p2 = getvert msh i;
tlen += distance p1 p2;
ucoords[i] = tlen;
p1 = p2;
)
for i = 1 to ucoords.count do ucoords[i] /= tlen; -- normalize to the total length
)
ucoords
)
-- generate V coords base on the x or y dimension
fn GetVCoords msh nsegs size xdim =
(
vcoords = #();
vcoords.count = nsegs + 1;
scalar = 0.5/size;
for i = 1 to nsegs + 1 do
(
p = getvert msh i;
if xdim then
vcoords[i] = scalar * abs p.x;
else
vcoords[i] = scalar * abs p.y;
)
vcoords;
)
fn BuildPictureFrameMesh width height size zscale profile mapCoords contUV flipUV =
(
nsegs = profile.count - 1;
nsegs_p1 = nsegs + 1;
nverts = nsegs_p1 * 4;
nfaces = nsegs * 4 * 2 + 2;
-- offsets and sizes
w = width * 0.5;
h = height * 0.5;
s = size;
-- "cardinal" points that form the interior and exterior corners of the picture frame
cp = #([-w-s,-h-s,0],[-w,-h,0], [w+s,-h-s,0],[w,-h,0], [w+s,h+s,0],[w,h,0], [-w-s,h+s,0],[-w,h,0]);
msh = mesh numverts:nverts numfaces:nfaces;
-- geo verts
vi = 1; -- vert incrementer
for i = 1 to 4 do
(
pind = i*2;
p1 = cp[pind - 1];
p2 = cp[pind];
for j = 1 to nsegs_p1 do
(
p = lerp p1 p2 profile[j].x;
p.z = profile[j].y * zscale;
setvert msh vi p;
vi += 1;
)
)
-- geo faces
fi = 1; -- face incrementer
si_offset = 0;
ei_offset = nsegs_p1;
for i = 1 to 4 do
(
smg = 2;
if mod i 2 == 0 then smg = 4; -- odd and even smoothing groups
for j = 1 to nsegs do
(
s1 = si_offset + j;
e1 = ei_offset + j;
s2 = s1 + 1;
e2 = e1 + 1;
-- quad face 1
setface msh fi [e1,e2,s1];
mxssetedgevisflags msh fi #{1,3};
setFaceSmoothGroup msh fi smg;
setFaceMatID msh fi 1;
fi += 1;
-- quad face 2
setface msh fi [s2,s1,e2];
mxssetedgevisflags msh fi #{1,3};
setFaceSmoothGroup msh fi smg;
setFaceMatID msh fi 1;
fi += 1;
)
si_offset += nsegs_p1;
ei_offset += nsegs_p1;
if i == 3 then ei_offset = 0; -- wrap around the mesh make the first vert row our end verts
)
-- create the picture quad
c = #(nsegs_p1,nsegs_p1 * 2,nsegs_p1 * 3,nsegs_p1 * 4); --pic quad vert indices
-- face1
setface msh fi [c[4],c[1],c[3]];
mxssetedgevisflags msh fi #{1,3};
setFaceSmoothGroup msh fi 1;
setFaceMatID msh fi 2;
fi += 1;
-- face2
setface msh fi [c[2],c[3],c[1]];
mxssetedgevisflags msh fi #{1,3};
setFaceSmoothGroup msh fi 1;
setFaceMatID msh fi 2;
fi += 1;
if mapCoords then
(
if contUV then
(
-- allocate mapping
ntverts = nverts + nsegs_p1 + 4;
meshop.setMapSupport msh 1 true;
meshop.setNumMapVerts msh 1 ntverts;
meshop.setNumMapFaces msh 1 nfaces;
-- mapping verts
tlen = 2 * (width + height);
vcoords = #(0.0, width/tlen, (width + height)/tlen, (2.0 * width + height)/tlen, 1.0);
ucoords = GetUCoords msh nsegs;
vi = 1;
for i = 1 to 5 do -- no wrap around with uv verts
(
for j = 1 to nsegs_p1 do
(
u = ucoords[j];
v = vcoords[i];
if flipUV then swap v u;
meshop.setmapvert msh 1 vi [u,v,0.0];
vi += 1;
)
)
-- mapping faces
fi = 1;
si_offset = 0;
ei_offset = nsegs_p1;
for i = 1 to 4 do
(
for j = 1 to nsegs do
(
s1 = si_offset + j;
e1 = ei_offset + j;
s2 = s1 + 1;
e2 = e1 + 1;
meshop.setMapFace msh 1 fi [e1,e2,s1]
fi += 1;
meshop.setMapFace msh 1 fi [s2,s1,e2]
fi += 1;
)
si_offset += nsegs_p1;
ei_offset += nsegs_p1;
)
)
else -- create mapping base on xy positions
(
ntverts = 4 * 2 * nsegs_p1 + 4;
meshop.setMapSupport msh 1 true;
meshop.setNumMapVerts msh 1 ntverts;
meshop.setNumMapFaces msh 1 nfaces;
ucoords = GetUCoords msh nsegs;
w_vcoords = GetVCoords msh nsegs size true;
h_vcoords = GetVCoords msh nsegs size false;
vi = 1;
for i = 1 to 4 do
(
for j = 1 to nsegs_p1 do
(
u = ucoords[j];
if i == 1 or i == 3 then
v = 0.5 + w_vcoords[j];
else
v = 0.5 + h_vcoords[j];
if flipUV then swap v u;
meshop.setmapvert msh 1 vi [u,v,0.0];
vi += 1;
)
for j = 1 to nsegs_p1 do
(
u = ucoords[j];
if i == 1 or i == 3 then
v = 0.5 - w_vcoords[j];
else
v = 0.5 - h_vcoords[j];
if flipUV then swap v u;
meshop.setmapvert msh 1 vi [u,v,0.0];
vi += 1;
)
)
fi = 1;
si_offset = 0;
ei_offset = nsegs_p1;
for i = 1 to 4 do
(
for j = 1 to nsegs do
(
s1 = si_offset + j;
e1 = ei_offset + j;
s2 = s1 + 1;
e2 = e1 + 1;
meshop.setMapFace msh 1 fi [e1,e2,s1];
fi += 1;
meshop.setMapFace msh 1 fi [s2,s1,e2];
fi += 1;
)
si_offset += nsegs_p1 * 2;
ei_offset += nsegs_p1 * 2;
)
)
-- picture quad uv coords
tverts = #([0.0,0.0,0.0],[1.0,0.0,0.0],[0.0,1.0,0.0],[1.0,1.0,0.0]);
c = #(0,0,0,0);
-- verts
for i = 1 to 4 do
(
c[i] = vi;
meshop.setmapvert msh 1 vi tverts[i];
vi += 1;
)
-- faces
meshop.setMapFace msh 1 fi [c[3],c[1],c[4]];
fi += 1;
meshop.setMapFace msh 1 fi [c[2],c[4],c[1]];
)
update msh;
msh;
)
BuildPictureFrameMesh 11.0 17.0 1.5 1.0 #([0,0],[0,1],[1,1],[1,0]) true false true;
Thanks Klunk you’re my hero! Ha. I can currently only get one side to unwrap at a time as i don’t fully understand the triangulation of the map faces, or normal faces for that matter. Which point corresponds to what? does to go something from top to bottom? or Left to right? In my loop some of the faces lead to criss crosses rather that the faces lining up. If i change the vertices that are wrong it simply changes which side is successfully unwrapped. I numbered mine a bit different then you but each vertex is in the right place and each face has the right vertices just in the wrong order. The code is below.
Thanks
D3Mi
fn extrudeFrame =
(
setNumVerts picture_Frame 16 true
setNumFaces picture_Frame 26 true
i = 5
while (i < 17) do
(
if (i < 9) then
(
setVert picture_Frame i ((((getVert picture_Frame (i-4)) * inverse picture_Frame.transform) + [0,0,30]) * picture_Frame.transform)
i += 1
)
else if (i < 13) then
(
for a = 1 to 2 do
(
for v = 1 to 2 do
(
if (a == 1) then y = -150 else y = 150
if (v == 1)then x = -150 else x = 150
setVert picture_Frame i ((((getVert picture_Frame (i-4)) * inverse picture_Frame.transform) + [x, y, 0]) * picture_Frame.transform)
i += 1
)
)
)
else
(
setVert picture_Frame i ((((getVert picture_Frame (i-4)) * inverse picture_Frame.transform) + [0,0,-30]) * picture_Frame.transform)
i += 1
)
)
face = 3
for i = 1 to 3 do
(
vert = i
if (i==1) or (i==3) then
(
for v = 1 to 3 do
(
setFace picture_Frame face [vert,vert+5,vert+1]
mxssetedgevisflags face #{2,3}
face += 1
setFace picture_Frame face [vert+4, vert+5, vert]
mxssetedgevisflags face #{1,3}
face += 1
vert += 4
)
)
vert = i
if (i == 1) or (i == 2) then
(
for v = 1 to 3 do
(
setFace picture_Frame face [vert+2, vert+6, vert]
mxssetedgevisflags face #{1,3}
face += 1
setFace picture_Frame face [vert, vert+6, vert+4]
mxssetedgevisflags face #{2,3}
face+= 1
vert += 4
)
)
)
meshop.setMapSupport picture_Frame 1 true;
meshop.setNumMapVerts picture_Frame 1 36;
meshop.setNumMapFaces picture_Frame 1 26;
ucoords = GetUCoords()
w_vcoords = GetVCoords true
h_vcoords = GetVCoords false
print ("Ucoords: " + ucoords as string)
print ("w_v: " + w_vcoords as string)
print ("h_v: " + h_vcoords as string)
meshOp.setMapVert picture_Frame 1 1 [1,0,0]
meshOp.setMapVert picture_Frame 1 2 [1,1,0]
meshOp.setMapVert picture_Frame 1 3 [0,0,0]
meshOp.setMapVert picture_Frame 1 4 [0,1,0]
meshop.setMapFace picture_Frame 1 1 [1,2,3]
meshop.setMapFace picture_Frame 1 2 [2,4,3]
vi = 5
for i = 1 to 4 do
(
for j = 1 to 4 do
(
u = ucoords[j];
if i == 2 or i == 3 then
v = 0.5 + h_vcoords[j];
else
v = 0.5 + w_vcoords[j];
meshop.setmapvert picture_Frame 1 vi [u,v,0.0];
print ("vert " + vi as string + ": " + meshOp.getMapVert picture_Frame 1 vi as string)
vi += 1;
)
for j = 1 to 4 do
(
u = ucoords[j];
if i == 1 or i == 4 then
v = 0.5 - h_vcoords[j];
else
v = 0.5 - w_vcoords[j];
meshop.setmapvert picture_Frame 1 vi [u,v,0.0];
print ("vert " + vi as string + ": " + meshOp.getMapVert picture_Frame 1 vi as string)
vi += 1;
)
)
fi = 3
vi = 5
for i = 1 to 4 do
(
if i == 3 then vi += 8
for j = 1 to 3 do
(
if i == 1 or i ==3 then offset = 12
else offset = 4
p1 = vi
p2 = p1+1
p3 = p1+offset
p4 = p2+offset
meshOp.setMapFace picture_Frame 1 fi [p3,p2,p1]
print vi
print ("Face " + fi as string + ": " + meshOp.getMapFace picture_Frame 1 fi as string)
fi += 1
meshOp.setMapFace picture_Frame 1 fi [p4,p2,p3]
print ("Face " + fi as string + ": " + meshOp.getMapFace picture_Frame 1 fi as string)
fi += 1
vi += 1
)
vi += 1
)