Hello there!
Workflow:
1. imported targetObj (cube, poly, *.obj)
2. on-scene sceneObj (cube, poly, later point helper)
3. sceneObj.rotation = targetObj.rotation (the two cubes need to overlap)
3. sceneObj.pos = targetObj.pos
Problem:
Can't set proper axis / rotation to sceneObj from face normal of targetObj. Transformation nooberism.
Details:
I'm working on a simple import plugin, that imports custom mesh from another app into 3ds Max. In the 3ds Max scene I have a helper (a cube for testing right now) and I need to fit the position and rotation to another one (same size, 6 polys) which is imported. This proves to be extremely difficult for me, and while the position is no problem at all (sceneObj.pos = targetObj.pos) I'm totally lost at matrix3, eulerangles and quat values. And (sceneObj.rotation = targetObj.rotation) is not an option, as the simple imported *.obj file has NO rotation at all.
So - I've thought that getting the matrix3 of the normal of face 3 (front face) of the targetObj. I managed to somehow translate the rotation to my scene object but I think the axis are all wrong - some of them keep the sceneObj aligned properly, while when targetObj orientation changes it rotates the sceneObj in the wrong direction / along wrong axis.
Code:
fn getAngleFromNormal targetObj sceneObj =
(
--RESET sceneObj ROTATION
oldTranslateMtx = transMatrix sceneObj.transform.pos
oldScaleMtx = scaleMatrix sceneObj.transform.scale
sceneObj.transform = oldScaleMtx * oldTranslateMtx
mtx = matrixFromNormal (polyOp.getFaceNormal targetObj 3)
sceneObj.transform *= mtx
eu = mtx as eulerangles
rx = eu.x
ry = eu.y
rz = eu.z
sceneObj.rotation *= inverse (eu as quat)
sceneObj.pos = targetObj.pos
)Screenshots:
http://i.imgur.com/XHDe9ic.jpg
http://i.imgur.com/89LRbv9.jpg
http://i.imgur.com/cA0YU5D.jpg
I'm really, really hopeless if it goes for things such as these, so I'd appreciate any and all help that can direct and teach me even a bit.
Thanks for your time,
Michelle.
By shiro · 2015-04-21