[Closed] write and read TXT file on the run
Ok here is the plan.
To design a maxscript that outputs a TXT file with the XYZ coord. of a moving object and at the same time (maybe a frame latter) create a line from the information stored in that file.
I have managed to do this using 2 different script, but I need to run one after the other, which is not what I need or want.
The problem here is that the source of movement is an AI.agent that does not generate a MotionPath, which means it does not have a pre-defined movement, it can change its final location at every run, that is why I said 1 frame latter…
anyway…not so clear…going to have a beer!!
F.
anyway…not so clear…going to have a beer!!
that explain why its not so clear
sorry but i dont understant tu use of a text file output? you what to update the TXT realtime as the object move or have a list of the coord XYZ frame by frame ex
fr1 objpos.[34,55,66]
fr2-objpos.[44,59,55]
fr3-objpos.[44,52,08]
and so on?
ok drinking coffee now:
This is the thing, I have agents (helpers) in the max setup to simulate people in an urban environment, just like you have in games like GTA or CS and so on, and I need to track down their movement in XYZ coord. for 2 reason:
– to create a trail of their individual movement
– to output a file with the coord. for other programs to use, like python or autocad etc. (this is why I need the output)
In the scene I have 10.000 agents simulating over a 3000-5000 frame range, unfortunetly the agents can change their movement at anytime through their AI algorithm, and therefore no Motion path is created by max. To understant what I mean please visit my site (its a 2Mb flash site) http://www.tzero.org/master/thesis/index.html
There you will see one simulation, the problem there is that the simulation had to be done using a Particle System to generates small points that eventualy look like a line by the end of the simulation.
So far I have a script to export the XYZ of each agent like this:
(it is still stupid cause it has to run the entire simulation to print a single agent movement)
helpers_array = #()
helpers_array = $ch* as array –put all objs named ca into array
probar=-1 – porgressbar parameter
timestart = timeStamp()–progressbar doit color:red
progressStart “Exporting files…”
for h in helpers_array do
(
hname = h.name
filename = hname + “.txt”
file = createFile filename
slidertime = 0f
reset
progressUpdate (100.0 * (probar +=1) / helpers_array.count)
– set the animation range
for i in 0 to 1500 do
(
slidertime=(i+1)
format “%, %
” slidertime h.pos to:file
reset
)
close file
)
So this prints out a file like so:
(as you probably can see in the script the filename is the object’s name, so in this case Ag0001.txt)
0f [-83.5749,394.188,0]
1f [-81.5761,394.119,0]
2f [-79.5871,393.91,0]
3f [-77.6308,393.494,0]
The following is the script to write the lines:
fn makeline pa filename= – to run ‘makefile [0,0,0] “xxx.txt”
(
f = openFile filename
ss = splineShape pos:pa name:(f as string) wirecolor:red renderable:true thickness:10
addnewspline ss
curframe = 0
while not eof f do
(
local frames = readValue f,
knotpos = readValue f
addKnot ss 1 #corner #line knotpos
curframe += 1
)
updateShape ss
close f
)
makeline [0,0,0] “ag0001.txt”
makeline [0,0,0] “ag0002.txt”
makeline [0,0,0] “ag0003.txt”
As you can se I still haven’t made this script loop over all the the TXT files in the folder (getFiles “d:\blablabla\*.txt”) so I had to run the functions for each file individually in the end, but that is ok for now, but is not going to be fun with 5000-10000 agents.
So the thing here is to start the simulation at frame zero, then create 1 file for each of the agents, then open each one individually and start creating a line, then move to frame 1, record the XYZ, and continue with the line by adding another knot (I believe), then move to frame 2 and so on.
Was it a bit more clear?
F.
ok drinking coffee now:
This is the thing, I have agents (helpers) in the max setup to simulate people in an urban environment, just like you have in games like GTA or CS and so on, and I need to track down their movement in XYZ coord. for 2 reason:
-- to create a trail of their individual movement
-- to output a file with the coord. for other programs to use, like python or autocad etc. (this is why I need the output)
In the scene I have 10.000 agents simulating over a 3000-5000 frame range, unfortunetly the agents can change their movement at anytime through their AI algorithm, and therefore no Motion path is created by max. To understant why I mean please visit my site [ http://www.tzero.org/master/thesis/index.html ]( http://www.tzero.org/master/thesis/index.html)
There you will see one simulation, the problem there is that the simulation had to be done using a Particle System to generates small points that eventualy look like a line by the end of the simulation.
So far I have a script to export the XYZ of each agent like this:
(it is still stupid cause it has to run the entire simulation to print a single agent movement)
helpers_array = #()
helpers_array = $ag* as array --put all objs named ca into array
probar=-1 -- porgressbar parameter
timestart = timeStamp()
progressStart "Exporting files..."
for h in helpers_array do
(
hname = h.name
filename = hname + ".txt"
file = createFile filename
slidertime = 0f
reset
progressUpdate (100.0 * (probar +=1) / helpers_array.count)
-- set the animation range
for i in -1 to (int(animationrange.end)-1) do
(
slidertime=(i+1)
format "%, %
" slidertime h.pos to:file
reset
)
close file
)
So this prints out a file like so:
(as you probably can see in the script the filename is the object's name, so in this case Ag0001.txt)
0f [-83.5749,394.188,0] 1f [-81.5761,394.119,0] 2f [-79.5871,393.91,0] 3f [-77.6308,393.494,0]
The following is the script to write the lines:
fn makeline pa filename= -- to run 'makefile [0,0,0] "xxx.txt"
(
f = openFile filename
ss = splineShape pos:pa name:(f as string) wirecolor:red renderable:true thickness:10
addnewspline ss
curframe = 0
while not eof f do
(
local frames = readValue f,
knotpos = readValue f
addKnot ss 1 #corner #line knotpos
curframe += 1
)
updateShape ss
close f
)
makeline [0,0,0] "ag0001.txt"
makeline [0,0,0] "ag0002.txt"
makeline [0,0,0] "ag0003.txt"
As you can see I still haven't made this script loop over all the the TXT files in the folder (getFiles "d:\\blablabla\\*.txt") so I had to run the functions for each file individually in the end, but that is ok for now...but is not going to be fun with 5000-10000 agents.
So the thing here is to start the simulation at frame zero, then create 1 file for each of the agents, then open each one individually and start creating a line, then move to frame 1, record the XYZ, and continue with the line by adding another knot (I believe), then move to frame 2 and so on.
Was it a bit more clear?
Fabiano