View Full Version : Export Animation Data in a xml File

02 February 2013, 02:45 PM
Hi does anybody have a idea how to export the velocity data of my animated object wich is animated via attach to moition path in a XML File.

What i need is an xml File with the following information.

I have a komplex Path animation with a lot of straight and kurve parts like a road.
And know i need all the Position and the Velocity values on my Pathlenght.

Lets say:
frame 0-50 = x mph ( this is a Straight Part )
frame 50-120 = x mph ( this is a Kurve Part )
frame 120-170 = x mph ( this is a Straight Part )
frame 170-220 = x mph ( this is a Kurve Part )

.. and so on.

Maybe someone have a idea of to export this information to a XML File.

The reason why i need this is that i need to synchronisize the Movement of my object along the path with some other animated Grafik stuff.And i dont want to do it manually, because when i have a xml with all these data it can be do automatically.

thanks in advance

02 February 2013, 02:58 PM
well, to my understanding, if you don't need to have very complex rules of calculating average velocity, you could sample position in intervals, and calculate sampled velocities first (velocity(now) = position(now)-position(before)/time(between now and before)).

When you have those velocities sample, say, at the start of each frame, calculating average in a given time range is really not that hard:)

02 February 2013, 05:30 PM
Maybe this works but i am not a programmer.
Mybe you or someone can help me, or is ther a script wich can do this ??

thanks in advance.

02 February 2013, 07:40 PM
well you posted in programming section, so I naturally assumed responded like programmer to programmer.
I don't know if there are tools that do that. I guess you'll have to find someone to code that for you.

02 February 2013, 12:06 AM
not that hard to do, at least if I understood your request correctly.

Select your animated object(s) for which you want to read out the velocity data, edit the animation start and end times for which you want the readout, then run this code:

$selection = `ls -sl`;

if(size($selection)) {

int $startTime = `playbackOptions -q -ast`;
int $endTime = `playbackOptions -q -aet`;

// set file here
string $fileName = "C:/velocity_Readout.xml";

int $f = `fopen $fileName "w"`;
if($f) {

for($object in $selection) {

// open <object> element
fprint $f ("<object name=\"" + $object + "\">\n");

for($i = $startTime; $i <= $endTime; $i++) {
// open <frame> element
fprint $f ("\t<frame time=\"" + $i + "\">\n");

currentTime ($i - 1);
float $posB[] = `xform -q -ws -t $object`;
currentTime $i;
float $posN[] = `xform -q -ws -t $object`;

float $dX = abs($posN[0] - $posB[0]);
float $dY = abs($posN[1] - $posB[1]);
float $dZ = abs($posN[2] - $posB[2]);

float $sqrX = `pow $dX 2.0`;
float $sqrY = `pow $dY 2.0`;
float $sqrZ = `pow $dZ 2.0`;

float $velocity = sqrt( $sqrX + $sqrY + $sqrZ );

// add <velocity> element
fprint $f ("\t\t<velocity>" + $velocity + "</velocity>\n");
// add <vX>, <vY>, <vZ> elements
fprint $f ("\t\t<vX>" + $dX + "</vX>\n");
fprint $f ("\t\t<vY>" + $dY + "</vY>\n");
fprint $f ("\t\t<vZ>" + $dY + "</vZ>\n");

// close <frame> element
fprint $f ("\t</frame>\n");

fflush $f;
// close <object> element
fprint $f ("</object>\n");
fclose $f;
else {
print("Select an object first!\n");

Would create a file "velocity_Readout.xml" that looks something like this:
<object name="pSphere1">
<frame time="1">
<frame time="2">
<frame time="3">
<frame time="4">
<frame time="5">
<frame time="6">
<frame time="7">
<frame time="8">
<frame time="9">

Disclaimer: though I think my math is correct, I'm notoriously bad at such things, so you may want to double check the results.

Feel free to modify the xml structure to your needs.

02 February 2013, 02:31 AM
...I think my math is correct, I'm notoriously bad at such things, so you may want to double check the results.

"I concur. Your logic is sound." said Spock with a bashful giigle.

CGTalk Moderation
02 February 2013, 02:31 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.