View Full Version : importing txt xyz as a trajectory for animation.
Hi I am trying to get a hold of script that will import xyz coords from a csv text file and animate an object across these coordinates.
The text is in the following format. where first column is time (frame) which starts at 1. The next 3 columns are xyz.
Frame x y z
this is a link to the csv file i am trying to import
I found the below on http://area.autodesk.com/index.php/forums/viewthread/2377/ (http://area.autodesk.com/index.php/forums/viewthread/2377/)
and it works and looks good BUT the xyz's are not the same values as in the csv file.
I have no idea why.
(--start a local scope. You can add a MacroScript definition above to make it a button
--pick the file:
local theFilename = getOpenFileName types:"Comma Separated Values (*.CSV)|*.CSV|All Files (*.*)|*.*"
if theFilename != undefined do ( --if a valid filename picked,
local theFile = openFile theFilename --open the file
local theDummy = Point showtrajectory:true --create a helper with trajectory on
while not eof theFile do ( --loop until the end of tile
theTime = floor ((readValue theFile)*30 + 0.5) --read time and round to closest frame
with animate on --enable autokey animation context
at time theTime --set the current time for the following expression
theDummy.pos = Point3 (readValue theFile) (readValue theFile) (readValue theFile)
)--and read the position from the file for each time step
close theFile --close the file when done
Note that your file was saved at 30 FPS frame rate, so the time samples have to be multiplied by 30 to give you frames. If you want to resample to a different frame rate or remove the quantization of values to full frames, you can change the line to
theTime = (readValue theFile)*FrameRate
This will import the 30 samples on sub-frames if the FrameRate is, say, 24 or 25, and at 30 you might get some frame values like 3.999 instead of 4.0, showing as narrow keys in the timeline. Dividing 1.0 by 30.0 is not fun ;)
ok i worked out why my units in max were not the same as in the CSV. My system units setup was different to my units setup. doh
11-20-2008, 04:56 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.
vBulletin v3.0.5, Copyright ©2000-2013, Jelsoft Enterprises Ltd.