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

Local axis rotation on multiple objects

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
Anonymous
5311 Views, 6 Replies

Local axis rotation on multiple objects

Hi everyone,

 

I'm having problems with a project I'm working on.  I've got a series of lines drawn in Rhino that are pointing in various different directions.  I've imported the lines as individual splines into 3d Max and everything seems fine (screengrab 001 - top and perspective wireframe view). 

 

I want to sweep the lines into a box, which is also fine (screengrab 002 - direction of the sweep is fine - end result is how i want them to be orientated). 

 

However when I change the reference coordinate system to local all the line's axis are facing the same direction (screengrab 003 - top view). 

 

Is there any way to have the axis for each object face outwards without having to align it for each object?

 

Appreciate any suggestions. 

 

Cheers,

 

 

 

 

 

 

Screengrab 001Screengrab 001Screengrab 002Screengrab 002Screengrab 003Screengrab 003

6 REPLIES 6
Message 2 of 7
jibijib
in reply to: Anonymous

Shouldn't they have axis' pointing to the direction you want to go anyway, unless the exporter 'reset the xform'?

Message 3 of 7
Anonymous
in reply to: jibijib

Hi jibijib

 

Thanks for your reply.  Sorry but I'm not sure what you mean by this.  I want each individual box to have an axis that moves "out" ("out" based on its own orientation) when you select local in the reference coordinate system.  If I xform them all or individually it doesn't change that all the local axis gismos are still facing the same direction.

 

Hope this makes sense....

Message 4 of 7
leeminardi
in reply to: Anonymous

I think the problem is that the lines are create at a skewed orientation.  They should be created vertically and then rotated to the correct orientation.  Whether they are created natively in Max or imported their pivot orientation will be aligned to the world not to the direction of the line.

 

Let's assume you would like the Z axis of the line to be collinear with the line itself.  If you were to create a line in Max that was parallel to the world Z axis then it's pivot Z axis would be aligned with the line.  If you were to now rotate that line in 3D then the line's Z pivot would still point in the direction of the line.  Now create a Transform Script for the line and you might see something like this:

tt1.JPG

 

 

This matrix includes 4 vectors.  The third vector is a unit vector in the z direction. The first is a unit vector in the x direction of the object and the second is the unit vector of the pivot's Y direction. Note that these values don't really matter for a line since the line can be rotated about it length by any amount and not really affect its orientation.  The fourth vector is the location of the line.

 

If you know the z unit vector that a line should have you can simply copy and paste it to replace the third matrix vector.

 

What you need is to determine z unit vector of the lines and then use that information along with the position and length to create the line at the rotated orientation.  This task is beyond my limited scripting skills but should be straightforward for someone familiar with the process of retrieving line ends with a script and create a line using a matrix.

 

lee.minardi
Message 5 of 7
Anonymous
in reply to: leeminardi

Hi lee.minardi,

 

Thanks for your reply.  I have to be honest - I have very little understanding of scripting (waaaaaaaay less than you i'm guessing).  I kind of thought that the solution would be something along those lines as the information for the rotation of the local axis seemed lost on import.  

I actually managed to sort it out this morning by searching the internet for a few days - https://www.youtube.com/watch?v=gLyhlkjN7ik&feature=youtu.be - this video had a similar problem and the user inputted the below script.  It only works with single faced editable polys - but i just extruded each spline a little way and collapsed them to use the script.  Works pretty well and I have no idea how it works 🙂  Something for me to learn when I'm not busy I guess 🙂

 

Align local axis to Single face script:

 

fn RotatePivotOnly obj index=
(
rot = (matrixFromNormal (polyop.getFaceNormal obj index)*obj.transform ) as quat
rotValInv=inverse rot
animate off in coordsys local obj.rotation*=RotValInv
obj.objectoffsetrot*=RotValInv
obj.objectoffsetpos*=RotValInv
)
for a in selection do
(
setrefCoordSys #local
CenterPivot a
theNormal=polyop.getFaceNormal a 1
RotatePivotOnly a 1
)

 

Many thanks again for taking the time to reply!

Message 6 of 7
leeminardi
in reply to: Anonymous

This has been a good project to teach myself a bit about Max scripts.

 

I have been successful in writing a script that will align the  Z axis of the pivot to a line.  That is, it will align the pivot z-axis to the first two vertices of a spline.  When I have a little more time I will modify it to operate on all selected splines.

 

Here is the code.

 

spl = selection[1]
s = 1	
e1 = getKnotPoint spl s 1 
e2 = getKnotPoint spl s 2
mid12 = (e1+e2)/2
v = e2-e1
vlen = length(v)
vu = v/vlen
m = spl.transform
ftm = translate (matrixfromnormal vu) mid12
itm = ftm*(inverse m)
spl.transform = ftm
spl.objectOffsetPos *= inverse itm
spl.objectOffsetRot *= inverse itm.rotation
spl.transform

   

lee.minardi
Message 7 of 7
leeminardi
in reply to: leeminardi

This version of the Maxscript will work on a selection of objects but will only change the pivot of lines.

-- modifies the pivot of selected lines so that the pivot is located at the midpoint 
-- of the line and the pivot's Z axis is aligned with the line. for spl in selection where classof spl == line do ( s=1 e1 = getKnotPoint spl s 1 e2 = getKnotPoint spl s 2 mid12 = (e1+e2)/2 v = e2-e1 -- vector from vertex 1 to 2 vlen = length(v) vu = v/vlen -- unit vector m = spl.transform -- spline matrix ftm = translate (matrixfromnormal vu) mid12 itm = ftm*(inverse m) spl.transform = ftm spl.objectOffsetPos *= inverse itm spl.objectOffsetRot *= inverse itm.rotation spl.transform )

 

lee.minardi

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

Post to forums  

Autodesk Design & Make Report