converting a 3ds rotation to a Quaternion

Well, a while ago I thought I had this problem sorted.. But it seems that the magical pony that is 3ds max has given me another curve ball.. Recently myself and my group discoed, that even though we set our units to 1m = 1 unit, things as such as obj exporters and function calls inside of maxscript (body.pos.z) on the other hand were using data that was 40x as large.. (we are using the build in .obj exporter in 3ds max) I could get the actual units through use of:

fn getFormated unFormated = 
(
	brokenUp = filterstring (units.formatValue unFormated) "m"
	return brokenUp[1]
)

which this fixed both scale and position.. however.. it seemed to have broken rotation aswel.. Which is just dandy..

this is my old exporter for pos, rot, scl

format "\t\t<position> " to:currentFile				
format "% " body.pos.x  to:currentFile	
format "% " body.pos.z  to:currentFile
format "% " -body.pos.y  to:currentFile								
format "</position>\n" to:currentFile
 
format "\t\t<rotation> " to:currentFile									
format "% " body.rotation.w to:currentFile
format "% " body.rotation.x to:currentFile
format "% " body.rotation.z to:currentFile
format "% " -body.rotation.y to:currentFile
format "</rotation>\n" to:currentFile
 
format "\t\t<scale> " to:currentFile									
format "% " body.scale[1]  to:currentFile
format "% " body.scale[3]  to:currentFile
format "% " body.scale[2]  to:currentFile								
format "</scale>\n" to:currentFile

and this is the new, which exports correctly scaled data (with an exception to the now broken rotation)

format "\t\t<position> " to:currentFile
frmtd = getFormated(body.pos.x)						
format "% " frmtd  to:currentFile
frmtd = getFormated(body.pos.z)	
format "% " frmtd  to:currentFile
frmtd = getFormated(-body.pos.y)	
format "% " frmtd  to:currentFile								
format "</position>\n" to:currentFile
 
format "\t\t<rotation> " to:currentFile	
format "% " body.rotation.w to:currentFile
format "% " body.rotation.x to:currentFile
format "% " body.rotation.z to:currentFile
format "% " -body.rotation.y to:currentFile
format "</rotation>\n" to:currentFile
 
format "\t\t<scale> " to:currentFile
frmtd = getFormated(body.scale[1])	
format "% " frmtd  to:currentFile
frmtd = getFormated(body.scale[3])	
format "% " frmtd  to:currentFile
frmtd = getFormated(body.scale[2])	
format "% " frmtd  to:currentFile								
format "</scale>\n" to:currentFile

is there some way to apply:
units.formatValue
to a x,y,z,w rotation???

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
barigazy's picture

Also u can use xRot =

Also u can use

xRot = obj[3][2][1].value
yRot = obj[3][2][2].value
zRot = obj[3][2][3].value
objRot = eulerAngles xRot yRot zRot
EulerToQuad objRot

bga

falconmick's picture

I used only this: xRot =

I used only this:
xRot = obj[3][2][1].value
yRot = obj[3][2][2].value
zRot = obj[3][2][3].value

We have a euler to quat converter..,im,gonna try extracting quat data ur way tomorow, but I had to crash...

barigazy's picture

Why don't youtry to

Why don't you try to resetXform and place pivot at the objects center before you store data in XML.

max modify mode
with redraw off 
(
    local arr = for obj in objects where isKindOf obj GeometryClass and not isKindOf obj TargetObject collect
    (
		(ResetXForm obj) ; CenterPivot obj ; obj
    )
    convertToMesh arr ; free arr
)
--and try with formating

bga

falconmick's picture

ok, I tried that,

ok, I tried that, unfortunately it produced the same results, heres one of the issues I was talking about:

(just if the immage isn't clear, the grey ends i circled are the purple parts in the 3ds max scene, they are rotated incorrectly but positioned correctly(to the best of my knollage)
http://i48.tinypic.com/20z6x5l.png

what I think is the issue is scaling.. I found out that I had to use units.formatValue for my rotation and scale the act of changing those has caused my rotation to break.. I believe that before it was rotated correctly, but due to my lack of sleep I will doubt anything :\ but you don't have my other code (in my engine) so assume that my engine is doing it correctly and it's the extraction of the data from 3ds max to my xml which is where the problem occurs.. another reason to assume is that before I found that scale issue and fixed it I ran extensive testing of rotation, scale and positioning which they all worked... I will re-run the tests, but I honestly can't read or concentrate, so ima hurt myself if I go on anymore.

just repeating.. I have had problems with scale!!! (the scl/pos is fixed now)

hopefully when I get up you've worked your magic once again.. your amazing

barigazy's picture

Are you try usin EulerToQuad

Are you try usin EulerToQuad method
See this topic under "Related Method"
http://docs.autodesk.com/3DSMAX/15/ENU/MAXScript-Help/index.html?url=fil...

bga

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.