Notifications
Clear all

[Closed] quat as String then back to quat again

Ive been storing a quat value in an objects userproperties, like this:

setUserProp $Box01 “QUAT” $Torus01.rotation

which works fine but I think that this has converted the quat into a string.

so when I try to retrieve it from the user properties and use it as a quat again
Maxscript will say Unable to covert to type:Quaternion.

This is what the string looks like:

“(quat -0.164006 0.0264648 0.274527 0.94712)”

I`ve been trying to use the userproperty in a rotation script like this:

VAL = getUserProp $Box01 “QUAT”
VAL

So I suppose I am asking how do I convert a string back to a quat, as quat does
not work.

Thanks for reading

Dan

7 Replies

hi,
to turn the string back to a quat you could execute it

blah = “(quat -0.164006 0.0264648 0.274527 0.94712)”
bleet = execute blah

$.rotation = bleet

mark

Cheers,

That worked great.

Dan

 PEN

Can I suggest another plan of attack. Don’t use the userProps to store it. Create a custom attribute and store the quat there so that you can store is as a quat and not a string. Then there is no need for the conversion from quat to string and back again.

Hi Paul,

I thought about that but ( I am showing my ignorance here) I was not sure how
to go about that. As a quat value has the word “quat” in it plus brackets so I didnt think a CA spinner could store it.

Is it easy to do?

Thanks

Dan

 PEN

You are not storing the word quat you are storing a quat value. Also you don’t need a spinner but you do need to write your own CA def. As it turns out you can’t directly store the quat you need to store a matrix. You just need to convert the quat to a matrix and then store it.


 b=box()
 
 --CA Def
 def=attributes quatHolder
 (
 	parameters params
 	(
 		matrixValue type:#matrix3
 	)
 )
 
 --Apply the def to the object
 custAttributes.add b def
 
 --Set the value of the matrix3
 b.matrixValue=(quat -0.707107 0 0 0.707107) as matrix3
 
 --Use that value to set the rotation of the box
 b.rotation=inverse b.matrixValue.rotation
 

Let me know if that makes any sense to you.

Thanks it worked great,I tried the example and I was able to get and set the matrixValue CA. would this way be faster for max to do rather than the converting string solution using execute?

Cheers

Dan

 PEN

You really want to try avoiding using execute. Best way that you could test it is read it in using a loop and a timeStamp and test to see how long both methods take.