PDA

View Full Version : Export Animation Data in a xml File


elay
02-01-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

uiron
02-01-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:)

elay
02-01-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.

uiron
02-01-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.

Nyro
02-02-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">
<velocity>0</velocity>
<vX>0</vX>
<vY>0</vY>
<vZ>0</vZ>
</frame>
<frame time="2">
<velocity>4.293893631</velocity>
<vX>0.4498593883</vX>
<vY>0.2650591258</vY>
<vZ>0.2650591258</vZ>
</frame>
<frame time="3">
<velocity>8.718324661</velocity>
<vX>3.149014485</vX>
<vY>1.855413374</vY>
<vZ>1.855413374</vZ>
</frame>
<frame time="4">
<velocity>10.79741718</velocity>
<vX>8.547326234</vX>
<vY>5.036122897</vY>
<vZ>5.036122897</vZ>
</frame>
<frame time="5">
<velocity>36.11181577</velocity>
<vX>18.93799437</vX>
<vY>18.26306014</vY>
<vZ>18.26306014</vZ>
</frame>
<frame time="6">
<velocity>61.45925345</velocity>
<vX>26.53348449</vX>
<vY>31.0300431</vY>
<vZ>31.0300431</vZ>
</frame>
<frame time="7">
<velocity>46.06580738</velocity>
<vX>25.14678085</vX>
<vY>29.62805733</vY>
<vZ>29.62805733</vZ>
</frame>
<frame time="8">
<velocity>83.58976132</velocity>
<vX>23.70417233</vX>
<vY>27.10068841</vY>
<vZ>27.10068841</vZ>
</frame>
<frame time="9">
<velocity>78.00125813</velocity>
<vX>12.97446499</vX>
<vY>14.99862128</vY>
<vZ>14.99862128</vZ>
</frame>
</object>


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.

Chrisgibbs
02-02-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-02-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.