Forum Groups
  All forums
    Help & Feedback
      Questions
      Work in progress
      Finished Art
      Non-Max related
    Community
      Offtopic
      News
    Hardware
    Photography



Maxunderground news unavailable

 
First page  Go to the previous page   [01]  [02]  Go to the next page  Last page
 
Unwrapping + Flattening code help
show user profile  jpedleham
rollout Unreal_Unwrapper "Unreal_Unwrapper" width:177 height:140
(
button doit "Unwrap this bitch!" pos:[9,36] width:160 height:43
progressBar doit_prog "ProgressBar" pos:[10,83] width:159 height:22
label lbl2 "Unreal Unwrapper" pos:[34,14] width:145 height:17
on doit pressed do
(

objArray = geometry as array -- get all geometry objects into array

for i = 1 to objArray.count do -- and iterate through all of them

(

doit_prog.value = 100.*i/objArray.count


max modify mode
convertto objArray[i] editable_mesh
modPanel.setCurrentObject objArray[i]
subObjectLevel = 4
Unwrapper = Unwrap_UVW name: ["Unreal_Unwrapper"]
Unwrapper.setApplyToWholeObject true
addModifier objArray[i] Unwrapper
Temp = objArray[i].modifiers["Unreal_Unwrapper"]
Temp.setMapChannel 2
Temp.setTVSubObjectMode 3
Temp.flattenMap 45.0 () 0.02 true 0 true true
subObjectLevel = 0

print objArray[i].name

)-- end i loop
doit_prog.value = 0
)
)

createDialog Unreal_Unwrapper 177 140


The above code seems to have worked for others in the past however currently it wont product any result, it throws out different errors each time it runs from

'Syntax error: at string, expected "(" or "["
-- In line: Unwrapper = Unwrap_UVW name: #"Unreal_Unwrapper #"'

'MAXScript FileIn Exception:
-- Syntax error: at , expected '

and

'Unable to convert: undefined to type: Point3'

Can anyone help me sort this code out. I understand whats going on in it i just dont see the problem that max is seeing.
Thanks
Jack

read 504 times
2/10/2015 4:04:22 PM (last edit: 2/10/2015 4:05:32 PM)
show user profile  Garp
Just a guess. Try removing the brackets in Unwrapper = Unwrap_UVW name: ["Unreal_Unwrapper"].
I think parameter 'name' is expecting a string.




read 476 times
2/10/2015 7:09:12 PM (last edit: 2/10/2015 7:09:12 PM)
show user profile  jpedleham
Thanks for the suggestion, it didnt seem to affect it, it gets to the line

Temp.flattenMap 45.0 () 0.02 true 0 true true

and throws the error

"Unable to convert: undefined to type: Point3"
read 467 times
2/10/2015 9:50:48 PM (last edit: 2/10/2015 9:50:48 PM)
show user profile  Garp
If it passes through the previous line that triggered an error, then it's one error solved :)

The second parameter to flattenMap() is an array of vectors. All it gets is a pair of parentheses. There's something missing here.
Doc: 'normalList specifies an array of normal vectors defining clusters'.




read 463 times
2/10/2015 11:31:43 PM (last edit: 2/10/2015 11:31:43 PM)
show user profile  jpedleham
Ah right, its possible i have just missed off a '#' infront of the parenthesis as the normallist will take an empty array according to the docs. Il shall report back.
read 453 times
2/11/2015 9:53:05 AM (last edit: 2/11/2015 9:53:05 AM)
show user profile  jpedleham
Yeah that was the problem. I have one other problem to fix, I want to try and make the script run only on the selected geometry. If i use;

objarray = #($)

it works fine with one object but if i select multiple objects it cant handle it.

im trying

objarray = getcurrentselection()

at the moment but this feels a little buggy as it occasionally throws an out of range error on the sub object level 4 line but sometimes it will run fine. Perhaps just adding a try & catch or some error handling to ensure only geometry nodes are selected might sort me out.

Any ideas?
Thanks
Jack.



read 449 times
2/11/2015 10:16:33 AM (last edit: 2/11/2015 10:16:33 AM)
show user profile  jpedleham
Unfortunately ive broken my code messing around too much as is usually the case!

rollout Unreal_Unwrapper "Unreal_Unwrapper" width:177 height:140
(
button doit "Unwrap this bitch!" pos:[9,36] width:160 height:43
progressBar doit_prog "ProgressBar" pos:[10,83] width:159 height:22
label lbl1 "Created by Jack" pos:[16,112] width:148 height:24
label lbl2 "Unreal Unwrapper" pos:[34,14] width:145 height:17
on doit pressed do
(

objArray = getCurrentSelection()

for i = 1 to objArray.count do -- and iterate through all of them

(

doit_prog.value = 100.*i/objArray.count


max modify mode
convertto objArray[i] editable_mesh
modPanel.setCurrentObject objArray[i]
subObjectLevel = 4
Unwrapper = Unwrap_UVW name: "Unreal_Lightmap"
Unwrapper.setApplyToWholeObject true
addModifier objArray[i] Unwrapper
Temp = objArray[i].modifiers["Unreal_Lightmap"]
Temp.setMapChannel 2
Temp.setTVSubObjectMode 3
Temp.flattenMap 45.0 #() 0.02 true 0 true true
subObjectLevel = 0

print objArray[i].name

)-- end i loop
doit_prog.value = 0
)
)



createDialog Unreal_Unwrapper 177 140


the code completes but once completed it throws the error

Runtime error: Requested sub-object level out of range: 4

it also started throwing

Modifier is not appropriate: Unwrap_UVW:Unreal_Unwrapper

until i changed it to "Unreal_Lightmap" which is an error it didnt throw before. T think i may have some parenthesis in the wrong place. Could someone take a looksee at my code. maybe try running it yourself?
Thanks
Jack
read 440 times
2/11/2015 10:38:14 AM (last edit: 2/11/2015 10:38:14 AM)
show user profile  Garp
You could create two arrays - one for the geometry and one for the selection - and get their intersection or you could use a for loop with a filter. Two ways:
objArray = for obj in selection where superClassOf obj == geometryClass collect obj
objArray = for obj in geometry where obj.isSelected collect obj
- The where clause in the loop acts as a filter. The loop iterates only through the elements in the collection for which the condition is true.
- The for ... collect loop returns an array of whatever its body evaluates to (here just obj).




read 438 times
2/11/2015 10:38:42 AM (last edit: 2/11/2015 10:40:05 AM)
show user profile  Garp
The geometry object set contains all the objects of superclass geometryClass. This is a little vague as it applies also to primitives and particle systems, for example. If you know that you're dealing with, say, editable meshes, you should say so explicitely:
objArray = for obj in selection where classOf obj == editable_mesh collect obj




read 432 times
2/11/2015 10:55:24 AM (last edit: 2/11/2015 10:55:24 AM)
show user profile  jpedleham
The script doesnt convert the selection to an editable mesh until it has put them in an array so it is possible they could be polys, meshes and sometimes xref objects so i cant really filter to jsut editable meshes. ill give your initial suggestions a go. any idea how ive managed to break my code haha. Like i say it executes correctly but it throws an error straight after completing on a line that is before the unwrap has even began making me think its looping through twice even when i only have one object selected.
read 425 times
2/11/2015 11:37:15 AM (last edit: 2/11/2015 11:37:15 AM)
show user profile  jpedleham
I think ive managed to fix it, i had some strange looping going on because of an extra set of brackets. Last question (i promise!) I had to remove the convert to mesh as it was removing the instancing from the objects. If i select multiple instances of the same object it applies multiple versions of the unwrap to it. Could you point me in the right direction of a way to check if the modifier is on the stack already, then if it is, skip the object?
Jack
read 411 times
2/11/2015 2:29:57 PM (last edit: 2/11/2015 2:35:36 PM)
show user profile  Garp
That's an easy one :)
if my_object.modifiers[#modifier_name] != undefined do...




read 401 times
2/11/2015 9:53:50 PM (last edit: 2/11/2015 9:53:50 PM)
show user profile  jpedleham
Awesome thanks! Ive given it a go but im having trouble finding where to place it within my code. Would you be able to demonstrate how this would go into my code? At the moment it doesnt unwrap anything anymore regardless of whether the object already has a uvw unwrap applied
i have placed it here;

rollout Unreal_Unwrapper "Unreal Unwrapper" width:170 height:300
( --Neccesary UI Bollocks
button doit "Unwrap This Bitch!" pos:[3,96] width:180 height:39
progressBar doit_prog "ProgressBar" pos:[4,139] width:182 height:23
label lbl1 "Unreal UV Maker" pos:[33,5] width:141 height:19

on doit pressed do --button press event
(

objArray = for obj in geometry where obj.isSelected collect obj --gather geometry into an array

for i = 1 to objArray.count do -- and iterate through all of them
(
doit_prog.value = 100.*i/objArray.count
local uvcheck = objarray[i].modifiers[#Unwrap_UVW]



if (uvcheck != undefined) then ( --check to see if modifier is already in the stack
max modify mode
--create unwrap modifier
modPanel.setCurrentObject objArray[i]
subObjectLevel = 4
Unwrapper = Unwrap_UVW name: "Unreal_Lightmap" --name modifier
Unwrapper.setApplyToWholeObject true
addModifier objArray[i] Unwrapper --add the unwrap
Temp = objArray[i].modifiers["Unreal_Lightmap"]
Temp.setMapChannel 2 --set mapping channel
Temp.setTVSubObjectMode 3 --select polygon unwrap mode
Temp.flattenMap 45.0 #() 0.02 true 0 true true --flatten mapping
Temp.packNoParams() --use default pack settings and pack
subObjectLevel = 0

print objArray[i].name
forcecompleteredraw dodisabled:true
)
else (
i = i+1
)
)-- end i loop
doit_prog.value = 0 --reset progress bar
)
)


Is this where im supposed to put it?

Thanks
read 398 times
2/11/2015 10:23:17 PM (last edit: 2/12/2015 10:00:05 PM)
show user profile  jpedleham
Still having issues with the above code. Ive tried the if statement in different places outside different brackets etc and still no dice unfortunately.
read 348 times
2/13/2015 9:32:41 AM (last edit: 2/13/2015 9:32:41 AM)
show user profile  Garp
Hm.. Lets see.

First, you (try to) get the unwrap modifier from the object:
local uvcheck = objarray[i].modifiers[#Unwrap_UVW]
Then you check that you did get it (there is an unwrap applied to the object):
if (uvcheck != undefined) then (
In which case, you add a new unwrap modifier to it (?!):
addModifier objArray[i] Unwrapper --add the unwrap
And then you carry on doing stuff with the modifier you've just added, only to an object that already had one.

Another thing. If there is no unwrap modifier (if uvcheck is undefined), you increment the loop counter:
else ( i = i+1 )
In effect, if the unwrap modifier is missing on an object, you skip over the next object (the counter gets incremented once by the loop and once by your code).

Give me a moment to try and figure what it is that you want to do...


edit: There's something I'm not sure. The whole point is to flatten and pack the UVs, right?
Do you want to do it to:
1. all the objects in the array?
2. only those objects that already have an unwrap modifier applied, but then through a different unwrap modifier?
One way or the other, the whole thing could be simplified A LOT.




read 340 times
2/13/2015 3:15:11 PM (last edit: 2/13/2015 3:28:56 PM)
 
First page  Go to the previous page   [01]  [02]  Go to the next page  Last page
 
#Maxforums IRC
Open chat window


Support Maxforums.org