|
|
|
Tell us what you think of the site.
|
Autodesk Media & Entertainment User Community
|
Autodesk® 3ds Max®
|
|
Autodesk® Maya®
|
|
Autodesk® Softimage®
|
|
Autodesk® MotionBuilder®
|
|
Autodesk® Mudbox™
|
|
Autodesk® ImageModeler™
|
|
Autodesk® Sketchbook® Pro
|
|
Autodesk® Smoke on Mac®
|
| Import x.y.z into Max using dummy object?
|
|
|
Hi all
I’ve got some data in the form of a .csv file. The data is positional xyz data for an object. What i’d like to do is create a script that will create a dummy object in max and then have values from the csv file (in this case xyz data) applied to it.
The first line of the csv might be.....
20,50,60
21,51,60
...etc
The second part to this would be to also assign rotational data to an object using a similar method.
I have a decent amount of experience in Max but I’ve never tried scripting before and have no idea where to begin!
Any help/suggestions/code would be greatly appreciated!
Cheers
Paul
Paul Fidler
Accident Investigation - 3D Modelling - Simulation
3ds Max 2011 (64-bit)
Intel Core i7-970
12GB RAM
NVIDIA QuadroFX 3800
|
|
|
|
Reading the file is pretty simple. Here’s a snippet of code:
-- open the file as text, read mode
f = openFile "myFile.csv" mode:"rt"
-- if it opened successfully (exists, etc)...
if f != undefined do
(
while not eof f do
(
-- Read a line from the file
l = readline f
-- turn that line into an array of strings using commas as delimiters
lf = filterString l ","
-- Create a Point3 from the array
p = [ lf[ 1 ] as Float, lf [ 2 ] as Float, lf[ 3 ] as Float ]
-- Make a dummy object using that point as pos
d = Dummy pos:p
-- Do whatever else you need to from here on out
-- ...
)
close f )
That is some basic stuff; it just creates Dummy objects at every point defined in the CSV. It doesn’t do any error-checking or anything; a line with fewer than three numbers will cause the script to fail, as will non-numeric entries.
Look up Filestream Values in the MAXScript documentation for more info.
David “Stokes” Stokes
Senior Technical Artist, Blue Fang Games
|
|
|
|
Thanks for the reply Stokes! Was really helpful.
That seems to work fine! My next stage is to animate the dummy object from a .csv.
If you see the attached file it contains four columns of data
Time, X, Y, Z
What I’m trying to do is:
1) create a dummy object
2) create key frames at each integral time step (in the file time step is 0.333s)
3) apply the corresponding xyz data at each point
The data is for a vehicle moving. I also have corresponding roll pitch and yaw data at each point but I’m trying to take it one step at a time!
Any ideas anyone?
Paul
Paul Fidler
Accident Investigation - 3D Modelling - Simulation
3ds Max 2011 (64-bit)
Intel Core i7-970
12GB RAM
NVIDIA QuadroFX 3800
|
|
|
paul_TRL 06 December 2007 03:06 PM
Thanks for the reply Stokes! Was really helpful.
That seems to work fine! My next stage is to animate the dummy object from a .csv.
If you see the attached file it contains four columns of data
Time, X, Y, Z
What I’m trying to do is:
1) create a dummy object
2) create key frames at each integral time step (in the file time step is 0.333s)
3) apply the corresponding xyz data at each point
The data is for a vehicle moving. I also have corresponding roll pitch and yaw data at each point but I’m trying to take it one step at a time!
Any ideas anyone?
Paul
(--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 )--end if
)--end script
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 ;)
Borislav “Bobo” Petrov
|
|
|
|
Wow! Thats really cool. So if this was to be used for cars, how would you make the car turn/bank as its position changes? Maybe convert the trajectory into a spline and use the path constraint controller...? I guess if the xyz data stayed in the same position for a few seconds (as if teh car had stopped at traffic lights) this wouldn’t work huh?
|
|
|
|
Dear Borislav,
I’ve also used your script for the same purpose. It works great, thank you so much. Just a small other question (I don’t know a lot about scripting so excuse my stupid question). How could I do if I want to open several *.csv files at once (let’s say, 1000 files ;-) ?
And if I don’t want it to become dummy but let’s say point mesh or other simple mesh like sphere or mesh I choose?
Thanks a lot
Jean-Michel Tari
Art Director - Ubisoft Paris
Independant Filmmaker
|
|
|
|
|
|