Notifications
Clear all

[Closed] pivot alignment

after Anubis help and a bit playing I got the pivot maxscript working.
i’m able to flip the pivot and the normals using this code part:

			ns = getNurbsSet $ #relational
 			flipNormals = true

the nurbsSurface is collapsed into a nurbssurface
looking for body object now

Damn that was fast
thank you… just downloaded…
I’m testing, it works on nurbssurface and on body objects too.
i added all other axis combinations
i’m experiencing that only on body objects flipping one axis, the normals are flipped showing the black side.
i also added the XYZ to test it… and it returns with black normals too.
while using the XY, YZ, ZX, the normals returns right.


 rollout MirrorPivot "MirrorPivot"
 (
 	button x "X" across:2 align:#center
 	button xy "XY" align:#center
 	button y "Y" across:2 align:#center
 	button yz "YZ" align:#center	
 	button z "Z" across:2 align:#center
 	button zx "ZX" align:#center
 	button xyz "		  XYZ		  " align:#center
 	checkbox col "Flip Normals and Collapse" align:#center
 	fn flipNormals o = 
 	(
 		nm = Normalmodifier()
 		nm.flip = true
 		case (classOf o) of (
 			PolyMeshObject :(
 								addmodifier o nm
 								if col.state do convertToPoly o
 							)
 			Editable_Poly : s(
 								addmodifier o nm
 								if col.state do convertToPoly o
 							)
 			Editable_mesh : (	
 								addmodifier o nm
 								if col.state do convertToMesh o
 							)
 			NURBSSurf :		(
 								ns = getNurbsSet o #relational
 								surfs  = for s in ns  where classof s == NURBSPointSurface collect s
 								for s in surfs do s.flipNormals = true
 							)
 		)
 	)
 	fn setTm o axis = 
 	(
 			if col.state do collapseStack o
 			local xf = xform name:("MirrorPivot " + axis as string)
 			xf.gizmo.transform = matrix3 (axis[1]*xf.gizmo.transform[1]) (axis[2]*xf.gizmo.transform[2]) (axis[3]*xf.gizmo.transform[3]) xf.gizmo.transform[4]
 			addmodifier o xf
 			flipNormals o 
 			if col.state do collapseStack o
 			o.transform = Matrix3 (axis[1]*o.transform[1]) (axis[2]*o.transform[2]) (axis[3]*o.transform[3]) o.transform[4]
 	)
 	
 	fn mirrorA axis = 
 	(
 		local sel = selection as array 
 		if sel.count > 0 do (
 			case axis of(
 				1:(	for o in sel do setTm o [-1,1,1])
 				2:(	for o in sel do setTm o [1,-1,1])
 				3:(	for o in sel do setTm o [1,1,-1])
 				4:(	for o in sel do setTm o [-1,-1,1])
 				5:(	for o in sel do setTm o [1,-1,-1])
 				6:(	for o in sel do setTm o [-1,1,-1])
 				7:(	for o in sel do setTm o [-1,-1,-1])
 			)
 		)
 	)
 	on x pressed do with undo label:"Mirror Pivots X" on mirrorA 1
 	on y pressed do with undo label:"Mirror Pivots Y" on mirrorA 2		
 	on z pressed do with undo label:"Mirror Pivots Z" on mirrorA 3
 	on xy pressed do with undo label:"Mirror Pivots XY" on mirrorA 4
 	on yz pressed do with undo label:"Mirror Pivots XZ" on mirrorA 5		
 	on zx pressed do with undo label:"Mirror Pivots ZX" on mirrorA 6
 	on xyz pressed do with undo label:"Mirror Pivots XYZ" on mirrorA 7		
 )
 createDialog MirrorPivot

it show that 1 axis flipping on body objects turns wrong.
any thought?

EDITED:
anyway used for my personal porpoise it’s ok… because the pivot reorient script flips some normals…
but for those that just want to flip the pivots on right looking normals objects it’s could get wrong results. (for a series of objects)

changing the class like below the script work anyway… and on NURBSSurface too
maybe you could create a new part only for body objects with a double normals flipping!
what do you think about?


 Body_Object :	  (
 								ns = getNurbsSet o #relational
 								surfs  = for s in ns  where classof s == NURBSPointSurface collect s
 								for s in surfs do s.flipNormals = true
 							  )
 

What is it Body_Object ?
Is it part of some plugin that you use?

1 Reply
(@jinj)
Joined: 11 months ago

Posts: 0

no it’s part from max 2011 and 2012 see help file.
its a nurbs geometry a bit different from nurbssurface. i think it has to do with brep…
http://docs.autodesk.com/3DSMAX/14/ENU/MAXScript%20Help%202012/index.html?url=files/GUID-7D318CC2-5F06-4E16-A141-5B3DC5194DA-3028.htm,topicNumber=d28e1016815

i created one for the body objects because it works also on the Nurbs one in wrong way…



rollout MirrorPivot "MirrorPivotBodyObject"
(
	button x "X" across:2 align:#center
	button xy "XY" align:#center
	button y "Y" across:2 align:#center
	button yz "YZ" align:#center	
	button z "Z" across:2 align:#center
	button zx "ZX" align:#center
	button xyz "		  XYZ		  " align:#center
	checkbox col "Flip Normals and Collapse" align:#center
	fn flipNormals o = 
	(
		nm = Normalmodifier()
		nm.flip = true
		case (classOf o) of   (
			Body_Object :	  (
								ns = getNurbsSet o #relational
								surfs  = for s in ns  where classof s == NurbsPointSurface collect s
								for s in surfs do s.flipNormals = true
							  )
							  
		)
	)
	fn setTm o axis = 
	(
			if col.state do collapseStack o
			local xf = xform name:("MirrorPivot " + axis as string)
			xf.gizmo.transform = matrix3 (axis[1]*xf.gizmo.transform[1]) (axis[2]*xf.gizmo.transform[2]) (axis[3]*xf.gizmo.transform[3]) xf.gizmo.transform[4]
			addmodifier o xf
			flipNormals = true	
			o.transform = Matrix3 (axis[1]*o.transform[1]) (axis[2]*o.transform[2]) (axis[3]*o.transform[3]) o.transform[4]
			addmodifier o xf			
			flipNormals = true
			if col.state do collapseStack o
			o.transform = Matrix3 (axis[1]*o.transform[1]) (axis[2]*o.transform[2]) (axis[3]*o.transform[3]) o.transform[4]
	)
	
	fn mirrorA axis = 
	(
		local sel = selection as array 
		if sel.count > 0 do (
			case axis of(
				1:(	for o in sel do setTm o [-1,1,1])
				2:(	for o in sel do setTm o [1,-1,1])
				3:(	for o in sel do setTm o [1,1,-1])
				4:(	for o in sel do setTm o [-1,-1,1])
				5:(	for o in sel do setTm o [1,-1,-1])
				6:(	for o in sel do setTm o [-1,1,-1])
				7:(	for o in sel do setTm o [-1,-1,-1])
			)
		)
	)
	on x pressed do with undo label:"Mirror Pivots X" on mirrorA 1
	on y pressed do with undo label:"Mirror Pivots Y" on mirrorA 2		
	on z pressed do with undo label:"Mirror Pivots Z" on mirrorA 3
	on xy pressed do with undo label:"Mirror Pivots XY" on mirrorA 4
	on yz pressed do with undo label:"Mirror Pivots XZ" on mirrorA 5		
	on zx pressed do with undo label:"Mirror Pivots ZX" on mirrorA 6
	on xyz pressed do with undo label:"Mirror Pivots XYZ" on mirrorA 7	
)
createDialog MirrorPivot

Ok . Now I see.
I use max 2009

the body object were introduced since max can import directly a ACIS Sat file with nurbs in it.

it was introduced firstly by “npower translater pro” as plugin… but now it’s inside max.

after importing an ACIS Sat into max i got a log file.
could some info inside helpful to get more knowledge about the created body object?
btw i’m trying to register to npower forum to get some help on the body object side for maxscripting.


Started logging messages at Sun Jan 08 17:16:47 2012
Info:	Using UV tolerance 1e-006
Info:	Using UV tolerance 1e-006
Info:	HwNlibToTSLib options selected:
Info:		Points: Off
Info:		Curves: On
Info:		Surfaces: Off
Info:		BReps: On
Info:		Create IwAssembly/IwAssemblyInstance objects
Info:		Making untrimmed surfaces into BReps
Info:		Making solids into single BReps
Info:		Make components of failed trims
Info:		Make faces of failed B-reps
Info:	HW SAT v1.2.6-maint
Info:	Reading C:\Users\Desktop\seam.sat
Info:	Processing C:\Users\Desktop\seam.sat
Info:	Transferring C:\Users\Desktop\seam.sat
Info:	
Info:	Found 0 points in file
Info:	Found 0 curves in file
Info:	Found 0 surfaces in file
Info:	Found 0 trimmed surfaces in file
Info:	Found 1 B-reps in file
Info:	Found 2 B-rep faces in file
Info:	
Info:	Using 3D tolerance 1e-006
Info:	Working on 0
Info:		Working on 43
Info:			Created 
Info:		Working on 45
Info:			Created 
Info:		Working on 41
Info:			Created 
Info:		Working on 39
Info:			Created 
Info:		Working on 5
Info:			Created 
Info:		Working on 16
Info:			Created 
Info:		Created 
Info:	Working on BRep 0
Info:		Using 3D tolerance 2.32008e-006
Info:		Using 3D tolerance 1e-006
Info:		Created BRep 
Info:	Points:				 0 found	   0 created	   0 failed
Info:	Coordinate Systems	  0 found	   0 created	   0 failed
Info:	Curves:				 0 found	   0 created	   0 failed
Info:	Surfaces:			   0 found	   0 created	   0 failed
Info:	Trimmed Surfaces:	   0 found	   0 created	   0 failed
Info:	Breps:				  1 found	   1 created	   0 failed
Finished logging messages at Sun Jan 08 17:16:47 2012

what you do to flip a pivot is overcomplicated…
here is all that you really need:


 try(destroydialog FlipPivotRollout) catch()
 rollout FlipPivotRollout "Flip Pivot by denisT" width:202
 (
 	button flipX_bt "X" width:60 align:#left offset:[-5,0] tooltip:"Flip Pivot X" across:3
 	button flipY_bt "Y" width:60 align:#center offset:[0,0] tooltip:"Flip Pivot Y" 
 	button flipZ_bt "Z" width:60 align:#right offset:[5,0] tooltip:"Flip Pivot Z"
 
 	mapped fn flipPivot node axis:#x = 
 	(
 		local sc = case axis of
 		(
 			 #x: [-1,1,1]
 			 #y: [1,-1,1]
 			 #z: [1,1,-1]
 		default: [1,1,1]
 		)
 		node.transform = prescale node.transform sc
 		node.objectoffsetscale *= sc
 		node
 	 )
 	on flipX_bt pressed do undo "Flip Pivot" on flipPivot selection axis:#x
 	on flipY_bt pressed do undo "Flip Pivot" on flipPivot selection axis:#y
 	on flipZ_bt pressed do undo "Flip Pivot" on flipPivot selection axis:#z
 )
 createdialog FlipPivotRollout
 

PS. if pivot’s position is off the object’s center you also have to adjust the object’s objectoffsetpos

Page 5 / 7