Notifications
Clear all

[Closed] flip normal script

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

11 Replies
 PEN

What does your code look like so far?

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”

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

1 Reply
(@gonzo_xb)
Joined: 11 months ago

Posts: 0

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.
[color=red]

max[/color]utility mode
resetxform $;
macros.run “Modifier Stack”“Collapse_Stack”
modPanel.addModToSelection (Normalmodifier flip:true)
macros.run “Modifier Stack”“Collapse_Stack”

 PEN

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
  	)
  )
  
1 Reply
(@prettypixel)
Joined: 11 months ago

Posts: 0

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.

 PEN

better yet


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

Thanks for the help guys. This site is great!

 PEN

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.

I was wondering why no-one was using a mapped function Paul!

J.

 PEN

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.