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 / Import x.y.z into Max using dummy object?
  RSS 2.0 ATOM  

Import x.y.z into Max using dummy object?
Rate this thread
 
2377
 
Permlink of this thread  
avatar
  • paul_TRL
  • Posted: 06 December 2007 05:01 AM
  • Location: London, UK
  • Total Posts: 15
  • Joined: 13 December 2006 04:48 PM

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

Replies: 0
avatar
  • Stokes
  • Posted: 06 December 2007 11:15 AM
  • Location: Boston Area, Massachusetts
  • Total Posts: 198
  • Joined: 22 August 2006 03:52 PM
  • Permlink of this post

Reading the file is pretty simple. Here’s a snippet of code:

-- open the file as textread mode
openFile "myFile.csv" mode:"rt"

-- if it opened successfully (existsetc)...
if 
!= 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
        
[ lf[ 1 ] as Floatlf [ 2 ] as Floatlf[ 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

Replies: 0
avatar
  • paul_TRL
  • Posted: 06 December 2007 12: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



Paul Fidler

Accident Investigation - 3D Modelling - Simulation

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

Attachment Attachment
Replies: 0
avatar

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 scopeYou 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

Replies: 0
avatar

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?



Replies: 0
avatar
  • jmtari
  • Posted: 23 July 2008 05:19 AM

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



Replies: 0