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:
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.
Solved! Go to Solution.
Solved by denisT.MaxDoctor. Go to Solution.
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
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
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)