PDA

View Full Version : Adding unwrap_uvw problem


JLuna
11-11-2009, 05:46 PM
Hello there,

Im working on a script that creates a second UVW channel (using unwrap_uvw modifier), and fills it with some values (the index of the vertexes).
The problem is: when I select ONLY one object an do the logic, it works. But when I have more than one object selected, it does not work. It seems that the modifier is not initialized, as I read in another post.
Here is the code:




fn findUV2Modifier obj=
(
hasUVW0 = false
--find the second UV2, and also check if we have the UV0 set
for i=1 to obj.modifiers.count do
(
if classof obj.modifiers[i] == unwrap_uvw then
(
--search for UV2
if obj.modifiers[i].getMapChannel() == 2 then
return obj.modifiers[i]
else if obj.modifiers[i].getMapChannel() == 0 then
hasUVW0 = true
)
)
--add a UVW0 and colaps. Its a hack, I know, but its needed to work.
if (hasUVW0 == false) then
(
print "Adding uvw0"
nMod = createInstance unwrap_uvw
if (classof obj.modifiers[1] == skin) then
(
addModifier obj nMod before:1
maxOps.CollapseNodeTo obj 2 true
)
else
(
addModifier obj nMod
maxOps.CollapseNodeTo obj 1 true
)
)

--we didnt find it, so add a new modifier.
nMod = createInstance unwrap_uvw
if (classof obj.modifiers[1] == skin) then
(
--it should be after the skin modifier
addModifier obj nMod before:1
nMod.SetMapChannel 2
nMod.name = "Metadata channel"
return nMod
)
else
(
addModifier obj nMod
nMod.SetMapChannel 2
nMod.name = "Metadata channel"
return nMod
)
)

fn generateUV2forMesh obj=
(
try
(
_uv2 = null
_uv2 =findUV2Modifier obj
if _uv2.NumberVertices() == 0 then
(
print "UV2 vertexes == 0"
)
--add some metadata in second UV channel
--if you edit this unwrap_uvw, you SHOULD see a diagonal line starting from (0,0)
for i = 1 to _uv2.NumberVertices() do
(
v = i - 1
pos = point3 v v v
_uv2.SetVertexPosition 1 i pos
)
)
catch
(
format "*** % ***\n" (getCurrentException())
)

)

fn clearUVWinMesh obj=
(
for i=1 to obj.modifiers.count do
(
if classof obj.modifiers[i] == unwrap_uvw then
(
deleteModifier obj i
)
)
)

fn fillUV2=
(
for obj in (selection as array) do
(
print ("Processing " + obj.name)
generateUV2forMesh obj
)
)

fn createUV2=
(
for obj in (selection as array) do
(
print ("Processing " + obj.name)
findUV2Modifier obj
)
)
fn clearUVW=
(
for obj in (selection as array) do
(
clearUVWinMesh obj
)
)

rollout helperMain "Avatar helper"
(

button fillUV2bt "Generate UV2 fix" pos:[10,10] width:220 height:18
on fillUV2bt pressed do
(
fillUV2()
print "Done"
)

button clearUVWbt "Clear UVW" pos:[10,30] width:220 height:18
on clearUVWbt pressed do
(
clearUVW()
)
)


avatarHelper = newRolloutfloater "Avatar helper" 250 150
addrollout helperMain avatarHelper



Can anybody help me?
Thanks!!

Jorge Adriano Luna

CGTalk Moderation
11-11-2009, 05:46 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.