Sign in to follow this  
leandro

OpenGL MaxScript transforms

Recommended Posts

Hello, I'm trying to write a 3DSMax MaxScript exporter to save to a custom format geometry, keyframes, material and hierarchies. I had no problems with geometry, materials and keyframes but I messed it up with hierarchies. I can build the hierarchy but when I add keyframes to it translations rotations and/or scales looks wrong. I've tryied to work out the offset transform, etc. that 3DXMax uses for transforms, but I couldn't get anything. Can anyone tell me how to proper manipulate the transforms of objects without messing the hierarchies relative position, transformations, etc. I need the transforms in object space, but it would be good to know how to get them in world, etc. spaces. Also, how do I transform left-handed rotations to right-handed (Or is it the other way about? I don't remember right now, but I want to use OpenGL). Thanks a lot.

Share this post


Link to post
Share on other sites
Not sure about the hierarchies thing, I've not gotten that far with my 3ds parser yet, but to tranform between the different world axes is fairly simple. To begin with 3dMax has its world axes on their side, ie: z looks up and y looks into the screen, so first you have to multiply all your verts by the following matrix to get the y axis going up:

1, 0, 0
0, 0, 1
0, 1, 0

Only problem now is that the z axis is flipped due to the difference in handed coord systems. This is fixed now by simply negating all the verts' z coords. Just one more thing that you might not have encountered yet. When you rotate your meshes in 3ds it doesn't update the mesh normals for you so they'll end up reflecting light incorrectly in OpenGL or DirectX. Hence before applying the world axis correction above to the normals you first have to multiply them by the meshes rotation matrix. Hope this helps

PS: Just occured to me, with the normals above I'm talking about when you export to an .ASE file. It might be different when working from within the package, I'm not sure.

Share this post


Link to post
Share on other sites
To get an object's transform in local space, that is relative to it's parent, you multiply it's transform by the inverse of it's parent's transform. For example, to collect the local transforms for all of the objects in the scene you could do this:


(
local SceneTransforms = #()

for Obj in Objects do
(
local ObjLocalTransform = Obj.transform

if( Obj.parent != undefined ) then
(
ObjLocalTransform = Obj.transform * ( inverse Obj.parent.transform )
)

append SceneTransforms ObjLocalTransform
)
)



Hope that helps!

-John

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Tanks a lot. I'll try and update my exporter. Now I have another starting point for reading and experimenting

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this