PDA

View Full Version : flip normal script


gonzo_xb
11-16-2005, 10:13 PM
I am trying to create a max script that will allow me to Reset XForm, flip all normals, and collapse the stack (in that order) on a specific object. I have been able to get it to work but only on all objects in the scene. Anyone know how to do this to just one object with a script?

Any help would be greatly appreciated. Thanks

PEN
11-16-2005, 10:53 PM
What does your code look like so far?

gonzo_xb
11-16-2005, 11:10 PM
Here's what i have so far. I am completely new at scripting, so the following is just from hacking together different scripts and just plain old trial and error. So I am pretty sure that I am going completely in the wrong direction. Thanks for the help!


For Selection in geometry do

(

max utility mode

resetxform $;

macros.run "Modifier Stack" "Collapse_Stack"

max modify mode

modPanel.addModToSelection (Normalmodifier ())

Selection.modifiers[#Normal].flip = true

)

macros.run "Modifier Stack" "Collapse_Stack"

prettyPixel
11-16-2005, 11:15 PM
I think this can help you.
This is a part of one my scripts.

fn resetXFormAndFlip obj =
(
local rotvalue=obj.rotation
obj.rotation=(quat 0 0 0 1)
local M=obj.transform
obj.transform=transMatrix obj.pos
local p=obj.objecttransform*(inverse obj.transform)
obj.objectoffsetPos=[0,0,0]
obj.objectoffsetRot=(quat 0 0 0 1)
obj.objectoffsetScale=[1,1,1]
M.translation=[0,0,0]
M=p*M
local xformMod=XForm()
addmodifier obj xformMod
xformMod.gizmo.transform=M
obj.rotation=rotvalue
addmodifier obj (Normalmodifier flip:true)
)--fn
And to collapse the stack will not be very difficult ;)

gonzo_xb
11-16-2005, 11:55 PM
I think this can help you.
This is a part of one my scripts.

excellent!! thank you! I was able to get what I needed from your code. here is what I ended up with. I can probably take out the extra collapse stack, but I am just so glad that it works! Amazing how hard it is to do the simplest script when you have no idea what you are doing. ;)


maxutility mode
resetxform $;
macros.run "Modifier Stack""Collapse_Stack"
modPanel.addModToSelection (Normalmodifier flip:true)
macros.run "Modifier Stack""Collapse_Stack"

PEN
11-17-2005, 12:27 AM
I think this can help you.
This is a part of one my scripts.

fn resetXFormAndFlip obj =
(
local rotvalue=obj.rotation
obj.rotation=(quat 0 0 0 1)
local M=obj.transform
obj.transform=transMatrix obj.pos
local p=obj.objecttransform*(inverse obj.transform)
obj.objectoffsetPos=[0,0,0]
obj.objectoffsetRot=(quat 0 0 0 1)
obj.objectoffsetScale=[1,1,1]
M.translation=[0,0,0]
M=p*M
local xformMod=XForm()
addmodifier obj xformMod
xformMod.gizmo.transform=M
obj.rotation=rotvalue
addmodifier obj (Normalmodifier flip:true)
)--fn
And to collapse the stack will not be very difficult ;)

Why is your so long prettyPixel? Is mine missing something?

Also I forgot that there is a resetXform() function built in. That would make it even shorter.

Now does any one know of a full proof and short way of knowing if an object has been negatively scaled? Only way I can think is checking if the object matrix has been inverted.


fn resetXform2=
(
for x in selection do
(
local xFrm=xForm()
objTm=x.objectTransform
x.Transform=(matrix3 [1,0,0] [0,1,0] [0,0,1] objTm[4])
addModifier x xFrm
xFrm.gizmo.transform=objTm*inverse (transMatrix objTm[4])
addModifier x (Normalmodifier flip:true)
collapseStack x
)
)

PEN
11-17-2005, 12:32 AM
better yet


mapped fn resetXform3 obj=
(
resetXform obj
addModifier obj (Normalmodifier flip:true)
collapseStack obj
)

gonzo_xb
11-17-2005, 12:47 AM
Thanks for the help guys. This site is great!

PEN
11-17-2005, 01:23 AM
prettyPixel:

I see what you are doing you are realigning the orientation of the axis. Nice touch. I think I will leave that as an option as most of the time I want it to re-orient the axis to the world but on the odd occasions I don't .

The other option that I'm going to add is keeping the current stack on the object. I think that will be useful as well.

j-man
11-17-2005, 08:39 AM
I was wondering why no-one was using a mapped function Paul!

J.

prettyPixel
11-17-2005, 12:05 PM
Why is your so long prettyPixel? Is mine missing something?
Maybe because I am not a programmer ? lol.
Seriouly I wrote this function a long time ago... The script was to be compatible with 3DSmax5 and when I gave the function I did not think of reading again it. I just did a copy from the script...
Of course your function is better with resetXform().



Now does any one know of a full proof and short way of knowing if an object has been negatively scaled? Only way I can think is checking if the object matrix has been inverted.
in my script I use that:

if ((obj.scale.x < 0) OR (obj.scale.y < 0) OR (obj.scale.z < 0)) do (resetXFormAndFlip obj)

but I am also interested to know a better way to do that.
I am not sure that the test is always valid.

PEN
11-17-2005, 12:18 PM
Maybe because I am not a programmer ? lol.
Seriouly I wrote this function a long time ago... The script was to be compatible with 3DSmax5 and when I gave the function I did not think of reading again it. I just did a copy from the script...
Of course your function is better with resetXform().




in my script I use that:

if ((obj.scale.x < 0) OR (obj.scale.y < 0) OR (obj.scale.z < 0)) do (resetXFormAndFlip obj)

but I am also interested to know a better way to do that.
I am not sure that the test is always valid.

Ya that test isn't always valid. If you were to reset the scale in the hierarchy panel this test would fail. I think that I'm going to have to test if the matrix is left or right handed so that you know if it has been mirrored. I have to think about that a bit though and work out some tests to see if it will catch everything.

I'm also not a programmer but I'm slowely becomming one. Your code works but I think that it can be reduced. I used to work beside on of the best programmers that I have known, very brillant. One of his sayings was "The best code is code that works" I guess it would be like having a car with a huge engine that should go really fast but it blows up ever time you press the gas.

CGTalk Moderation
11-17-2005, 12:18 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.