Community
3ds Max Programming
Welcome to Autodesk’s 3ds Max Forums. Share your knowledge, ask questions, and explore popular 3ds Max SDK, Maxscript and Python topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Help with Max's magic spline orientations?

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
senorpablo
914 Views, 4 Replies

Help with Max's magic spline orientations?

I'm stumped by the issue in Max whereby splines have some magic orientation that you can't alter after the fact. For example, they always extrude in the direction of the viewport in which they were created. There are many cases in which that simply isn't an option. Such as with imported splines, or splines created from edges of existing geometry. Also, when you create a spline via script, it seems to default to the XY plane, so that extrusions are world Z-up. 

 

This is an annoying issue which has led to many issues over the years, there are many forum posts on the subject. Solutions range from creating a new slpine in the desired viewport, attaching the original one and then deleting the temporary one. Or, you can rotate the spline to the XY plane and perform a reset Xform with collapse. 

 

I'm running into this issue with a problem I'm trying to solve. I have a script which creates a spline from a series of polygon edges. I need the orientation of the spline to match the face normal of the polygons from which it was created. But, maxscript forces new splines created via script to have their magic orientation to be Z-up. How can I work around this issue? I've created a simple illustration attempting to depict the problem and the desired outcome. 

 

I think the process would be to:

  1. align the spline to the XY plane based on a provided normal of the desired extrusion orientation(the face normal)
  2. reset xform and collapse the spline
  3. perform desired operations on the spline
  4. rotate the spline or new object back into the original orientation and position

Extrusion is just an example I chose for purposes of illustrating problem, it's not the desired result. 

 

Can anyone provide an elegant solution to this? Much appreciated. 

 

Spline Transform.jpg

 

 

 

 

4 REPLIES 4
Message 2 of 5
senorpablo
in reply to: senorpablo

Here's a basic framework I use for testing:

 

b= box()
convertto b editable_poly

alignnormal = polyop.getfacenormal b 3

edges = polyop.getfaceedges b 3
spline = polyop.createShape b edges name:"splinetest"

newspline = $splinetest

-- transform to XY plane based on alignnormal



-------------------------------------------------------
-- do some work
resetxform newspline
collapse newslpine
converttopoly newspline
-------------------------------------------------------
--  transform back to original position

Message 3 of 5

fn setPivotRotation obj point =
(
	worldAlignPivot obj
	local rot = inverse point.rotationpart
	
	animate off in coordsys local obj.rotation *= rot
	obj.objectoffsetrot *= rot
	obj.objectoffsetpos *= rot
	obj.objecttransform
)

delete objects
gc()
sp = 
(
	p = converttopoly (geosphere name:#poly segs:1 smooth:off wirecolor:orange)

	f = random 1 p.numfaces

	n = polyop.getfacenormal p f
	c = polyop.getfacecenter p f
	ee = polyop.getfaceedges p f
	polyop.createShape p ee name:"spline" 
	sp = objects[objects.count]
	updateshape sp
	sp.wirecolor = green
	sp.pivot = c
	setPivotRotation sp (matrixfromnormal n)
	
	sp
)

sure... it might be a smarter algorithm for an 'orientation' but I hope the basic idea is clean enough

 

 

Message 4 of 5

if we want to align the spline node the algorithm could be:

 

delete objects
gc()
sp = 
(
	p = converttopoly (geosphere name:#poly segs:1 smooth:off wirecolor:orange)

	f = random 1 p.numfaces

	n = polyop.getfacenormal p f
	c = polyop.getfacecenter p f
	ee = polyop.getfaceedges p f
	polyop.createShape p ee name:"spline" 
	sp = objects[objects.count]
	updateshape sp
	sp.wirecolor = green
	sp.pivot = c
	tm = matrixfromnormal n
	
	rotate sp tm.rotation 
	resetxform sp
	converttosplineshape sp
	rotate sp (inverse tm.rotation) 
	
	sp
)

 

of course we can put the pivot to the first knot position and orient the rotation matrix using the source poly (v0,v1) side vector as front. But searching this or CGTalk forums you can find a solution how to do it (I showed it there several times) 

 

Message 5 of 5

Thank you Denis, that's exactly what I needed. Very elegant!

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report