Diancoff
11-14-2010, 10:40 AM
Ok, I'm trying to make a script that applies box mapping to a group of objects and moves the UVs to positive X and Y space. Doesn't sound so hard, right?
Well, for example if I add convertto $ editable_poly at the end of the script to collapse the stack, the vertices don't get aligned at all.
Also, despite the "for" loop I can't get the vertices to move on more than 1 object.
And, so on... Here is the script. Can anyone point me some errors that I've made, please?
fn applyMapping =
(
-- Apply box mapping
max modify mode
uv = uvwmap maptype:4 realWorldMapSize:true
for obj in selection do
(
convertto obj editable_poly
addModifier obj uv
convertto obj editable_poly
)
uv.gizmo.position = [0,0,0]
)
fn alignMapVerts =
(
for obj in selection do
(
convertto obj editable_poly
unw = unwrap_UVW()
addModifier obj unw
all_verts = #{1..unw.numberVertices()}
unw.selectVertices all_verts
pos = polyop.getmapvert obj 1 1
minx = pos[1]
miny = pos[2]
for v=1 to (polyop.getnummapverts obj 1) do
(
pos = polyop.getmapvert obj 1 v
if pos[1] < minx then minx=pos[1]
if pos[2] < miny then miny=pos[2]
)
unw.moveSelectedVertices [-minx,-miny,0]
convertto obj editable_poly
)
)
Well, for example if I add convertto $ editable_poly at the end of the script to collapse the stack, the vertices don't get aligned at all.
Also, despite the "for" loop I can't get the vertices to move on more than 1 object.
And, so on... Here is the script. Can anyone point me some errors that I've made, please?
fn applyMapping =
(
-- Apply box mapping
max modify mode
uv = uvwmap maptype:4 realWorldMapSize:true
for obj in selection do
(
convertto obj editable_poly
addModifier obj uv
convertto obj editable_poly
)
uv.gizmo.position = [0,0,0]
)
fn alignMapVerts =
(
for obj in selection do
(
convertto obj editable_poly
unw = unwrap_UVW()
addModifier obj unw
all_verts = #{1..unw.numberVertices()}
unw.selectVertices all_verts
pos = polyop.getmapvert obj 1 1
minx = pos[1]
miny = pos[2]
for v=1 to (polyop.getnummapverts obj 1) do
(
pos = polyop.getmapvert obj 1 v
if pos[1] < minx then minx=pos[1]
if pos[2] < miny then miny=pos[2]
)
unw.moveSelectedVertices [-minx,-miny,0]
convertto obj editable_poly
)
)
