Inside Sabertooth
Learn how Sabertooth uses 3ds Max to create 3D interactive projects, including HBO Go’s Game of Thrones interactive experience
  • 1/3
You are here: Forum Home / Autodesk 3ds® Max® / MaxScript / Rotation values don't stay correct when applied to dummy.
  RSS 2.0 ATOM  
2 pages: 1.2 last

Rotation values don't stay correct when applied to dummy.
Rate this thread
 
2029
 
Permlink of this thread  
avatar
  • RichM
  • Posted: 27 November 2007 11:24 AM
  • Total Posts: 2
  • Joined: 27 November 2007 07:08 PM

Hi,

First time post.  Question for everyone: 

I am reading in motion data from a while through maxscript.  I create a dummy for each object moving, and then read in time data, position data and rotation data for a given time segment.  The data looks like this…

t[s] x [ft] y [ft] z [ft] phi1[deg] phi2[deg] phi3[deg] vx[mph] vy[mph] vz[mph]

0.000 233.04 633.51 2.02 0.00 0.00 0.90 37.00 0.58 0.00
0.100 238.46 633.60 2.02 0.00 0.00 0.90 37.00 0.58 -0.00
0.200 243.89 633.68 2.02 0.00 0.00 0.90 37.00 0.58 0.00
0.300 249.32 633.77 2.02 0.00 0.00 0.90 37.00 0.58 -0.00

We skip the last three velocity rows, and just deal with position and rotation.

I create a dummy object with a position of [0,0,0] and rotation of [0,0,0] to start with.

dummyName = CreateDummyName()
dummyObj = dummy pos:[0,0,0] rot:[0,0,0] boxsize:[1,1,1] name:dummyName
selectMore dummyObj

Once it’s selected, I think move to reading the transform data…

while not eof PccrashStream do
(
for node in selection do
(
readTransformData node
import_prog.value = 100.*(filePos PccrashStream)/EOFPosition
)
)

so we send the node in (which is the dummy) to this method…

function readTransformData obj=
(

tempLine = readLine PccrashStream
tempArray = filterstring tempLine “ “

if (tempArray[1] == “ “) then
(messagebox “No Data here")
else
(

Time = tempArray[1]
Frame = (tempArray[1] as float) * 30

--Position

VehPosition = copy obj.position

VehPosition.x = tempArray[2] as float
VehPosition.y = tempArray[3] as float
VehPosition.z = tempArray[4] as float

--rotation

VehRotationPart = copy obj.rotation

VehRotationPart.x = (tempArray[5] as float)
VehRotationPart.y = (tempArray[6] as float)
VehRotationPart.z = (tempArray[7] as float)

messagebox ("Before Time: “ + (Frame as string) + “ VehX: “ + (VehPosition.x as string) + “ VehY: “ + (VehPosition.y as string) + “ VehZ: “ + (VehPosition.z as string) + “ RotX: “ + (VehRotationPart.x as string) + “ RotY: “ + (VehRotationPart.y as string) + “ RotZ: “ + (VehRotationPart.z as string))


at time Frame animate on obj.rotation = VehRotationPart
at time Frame animate on obj.position = VehPosition

messagebox ("After Time: “ + (Frame as string) + “ VehX: “ + (VehPosition.x as string) + “ VehY: “ + (VehPosition.y as string) + “ VehZ: “ + (VehPosition.z as string) + “ RotX: “ + (VehRotationPart.x as string) + “ RotY: “ + (VehRotationPart.y as string) + “ RotZ: “ + (VehRotationPart.z as string))

)
)

So we read the data in, assign it to these objects and then on the “at time Frame animate” lines, we make the keyframes.  All fine and dandy.

Position works fine.  The “Before Time” and “After Time” boxes show the correct data, and then when we double check the keyframes, the X,Y,Z positions are all correct for all times.

However, rotation is another matter.  The rotation data should be [0,0,.9] (we’re going to disallow radian vs degrees at this point as we can make that conversion easily) for the 4 points listed.  However:

We should get:  We actually get:
---------------------- ----------------------
[0,0,.9] [0,0,83.974]
[0,0,.9] [0,0,100.895]
[0,0,.9] [0,0,100.895]
[0,0,.9] [0,0,100.895]

Further down the line, the actual data changes values, never going above 1 in X, 3 in Y and -10 in Z..  In the data we see in the keyframes, we get values that change a max of 100 down to about 8 in the Z value.  These changes do not happen to correspond with the changes in the actual data either.  As you can tell from the example above, the actual keyframe changes when the data does not. 

One thing to add:  I have tried to put in the rotation values as 0.  That causes the data to be 0, and the keyframes to be 0 as well.  So it appears that having a value for data causes it to get changed, but having all 0’s causes no change.. (or 0 * something = 0)

I’ve ruled out some sort of normalization (as the changes in keyframe data don’t change the same as the actual data) and I’ve ruled out conversion things… I’ve also ruled out the data getting changed as my Before Time: message box matches my After Time: message box. 

Something is changing when the data is keyframed, and I have no clue why.  Any thoughts?

Thanks.
Rich



Replies: 0
avatar
  • focomoso
  • Posted: 28 November 2007 03:13 AM

A couple of things:

First, if you’re going to post code, it’s a good idea to post code we can actually run so if we think we know what’s wrong, we can test it. Comment out your comments; don’t use functions not defined in your snippet (like: CreateDummyName); get rid of the smart quotes and disable smilies so the code doesn’t get parsed (you can post code using the key word “code” in square brackets).

Second, you’re going to find life much easier if you get rid of all those message boxes and use the format function to look at the output in the listener.

Third, I’d recommend simplifying the problem as much as you can in the post. We have to wade through a lot of stuff to get at what you’re asking.

Now, to the problem at hand:

Without being able to run the code, something to look at might be to not use reserved maxscript keywords as variable names (Time and Frame).

Ahh, think I got it. Rotations are held in quatrains in maxScript, not euler xyz values (even if the object has an euler_xyz controller on it). So you need to convert your x y z values to a euler angle with:

ea eulerAngles (tempArray[5] as float) (tempArray[6] as float) (tempArray[7] as float)

And then convert that to a quat with:

obj.rotation eulerToQuat ea

If that doesn’t work. Ask again.

ps – depending on the data, you may have trouble with the xyz order of the rotation data.



--
James Kelly
fo co mo so

Replies: 0
avatar
  • RichM
  • Posted: 28 November 2007 09:58 AM

Sorry for the formatting… I wasn’t expecting people to run the code snippets I had posted, but simply to see how I was accomplishing things.

I thought the main thrust was that when the data went into the rotation keyframing, it was changing.  And I think we found out about the same time, as our answer and your answer were very much alike.

Our initial thought was, data is entered just as <frame,data> rather than all these calculations.  We thought that MaxScript would follow with the same convention.  And yet, it didn’t.  We stumbled through it and figured the same things out you found out.

Thanks!



Replies: 0
avatar
  • focomoso
  • Posted: 28 November 2007 06:26 PM

Once you get the hang of quats, you’ll see why maxscript uses them. Much more powerful (and more consistent) than euler angles.



--
James Kelly
fo co mo so

Replies: 0
avatar

You should also rotate first then position.



Replies: 0
avatar
  • paul_TRL
  • Posted: 06 December 2007 11:01 AM

Hi Rich

Is it possible to share the code with us as it is used?  I’ve posted a similar thread earlier today, then stubbled across this one.  Seems like we’re trying to achieve similar things?

Any help would be greatly appreciated!

Thanks in advance

Paul



Paul Fidler

Accident Investigation - 3D Modelling - Simulation

3ds Max 2011 (64-bit)
Intel Core i7-970
12GB RAM
NVIDIA QuadroFX 3800

Replies: 0
avatar

Hello Rich,

I am trying to do the exact same thing, bring a bunch of points from pc crash into max. The only problem is that I have never coded anything and your code looks very daunting to someone un-experienced. So my question is how would I go about entering/applying this script to the pccrash data I have and how to apply it in 3ds max?

Anything would help?

Alexander Mascagni



Replies: 1
/userdata/avatar/avatar_79126.png

It would help if we knew what the pc crash data looked like, but generally, you read in the file, parse out the data, create objects if they don’t already exist and then apply the values to your objects.

Author: focomoso

Replied: 16 July 2009 11:29 AM  
avatar

The data looks like the data in the original post.

We can export the data in whatever timestep we need.

Gary



Replies: 1
/userdata/avatar/avatar_79126.png

This is all in the help. What have you tried and what isn’t working?
- can you read in the file? (use openFile <filename_string>)
- can you parse out the data? (readLine <filestream> and readDelimitedString <filestream> <string>)
- what do you want to do with the data once you have it? Apply it to objects? Create dummies?

You’re asking a very general question. The more specific you are, the better we can help you.

Author: focomoso

Replied: 17 July 2009 07:07 AM  
avatar

I want to make the data to be keyframes from an object.  (A vehicle)

The data looks like this.

t[s] x [ft] y [ft] z [ft] phi1[deg] phi2[deg] phi3[deg] vx[mph] vy[mph] vz[mph]

0.000 233.04 633.51 2.02 0.00 0.00 0.90 37.00 0.58 0.00
0.100 238.46 633.60 2.02 0.00 0.00 0.90 37.00 0.58 -0.00
0.200 243.89 633.68 2.02 0.00 0.00 0.90 37.00 0.58 0.00
0.300 249.32 633.77 2.02 0.00 0.00 0.90 37.00 0.58 -0.00

I plan on having data that’s is about 6.5 seconds long with points every 0.05 seconds.

Right now, when I try to put and an object in the angles seem to be wrong.

Gary



Replies: 0
avatar
  • focomoso
  • Posted: 17 July 2009 09:02 PM

garyosterholt 17 July 2009 05:15 PM

I want to make the data to be keyframes from an object.  (A vehicle)

The data looks like this.

t[s] x [ft] y [ft] z [ft] phi1[deg] phi2[deg] phi3[deg] vx[mph] vy[mph] vz[mph]

0.000 233.04 633.51 2.02 0.00 0.00 0.90 37.00 0.58 0.00
0.100 238.46 633.60 2.02 0.00 0.00 0.90 37.00 0.58 -0.00
0.200 243.89 633.68 2.02 0.00 0.00 0.90 37.00 0.58 0.00
0.300 249.32 633.77 2.02 0.00 0.00 0.90 37.00 0.58 -0.00


I plan on having data that’s is about 6.5 seconds long with points every 0.05 seconds.

You’re better off doing one point per frame. So that’s every 0.0416 at 24fps or 0.0333 at 30fps.

Right now, when I try to put and an object in the angles seem to be wrong.

What are you doing (the code) and how are they wrong? Did you see my post above about converting eulerAngles to quats?



--
James Kelly
fo co mo so

Replies: 0
avatar

Ok so I have found a script that works for the xyz coordinates of the vehicle. I put the xyz data in a dat file.

s = $Group01
-- Function Definition
fn AnimateObject spaz file=
(
local f = openFile file
t=0
while (not eof f) do
(
with animate on at time t spaz.pos = [readValue f,readValue f,readValue f]
t += 1
)
close f
)
-- EVALUATE FUNCTION
AnimateObject s “infiniti2.dat”

Now I want to use sort of the same code to do rotation of the xyz. Does anyone know how to rework this code to do that?



Replies: 1
/userdata/avatar/avatar_79126.png

This is untested code, but assuming you appended the rotation values after the position values (as described above) it would look something like:

$Group01
-- Function Definition
fn AnimateObject spaz file 
(
 local f 
openFile file
 t
=0
 with animate on (
 
while (not eof f) do (
 at time t (
 spaz
.pos [readValue f,readValue f,readValue f]
 ea 
eulerAngles (readValue f) (readValue f) (readValue f)
 spaz
.rotation eulerToQuat ea  
 )
 t 
+= 1
 )
 )
 close f
)

-- EVALUATE FUNCTION
AnimateObject s “infiniti2.dat”
Author: focomoso

Replied: 29 July 2009 10:05 AM  
2 pages: 1.2 last