particles from CSV file


#1

hya people,

i have a sequence with a grid displaying a animated water sequence.
sorta like this, but much bigger

-999 0 -999 0.02
-999 0.1 -999 0.02
-999 0.2 -999 0.02
-999 0 0 0.02
-999 0 -999 0.02

i have written a python script that converts this into a other format (x,y,z):
1,2,0
1,3,0.02
2,2,0.1
2,4,0.02
3,2,0
3,3,0
etc

i want to get this into 3D, so i thought particles will help me out.
I’m trying to read particles from this file sequence.


on ChannelsUsed pCont do
(
	 pCont.useTime = true
	 pCont.useAge = true
	 pCont.usePosition = true
	 pCont.useSpeed = true
)

on Init pCont do 
(
		global partArray = #()
		frameNumber = substring (currenttime.frame as string) 1 1
		spath = @"C:\data\" 
		filename = spath + "ex_dm1d000" + (frameNumber) +".csv"
		fs = openFile filename
		counter=1
		while not eof fs do  (
			tmp = readline fs
			ss = tmp as StringStream
			x = (readDelimitedString ss ",") as float
			y = (readDelimitedString ss ",") as float
			z = (readDelimitedString ss ",") as float
			partArray[counter]= #(x,y,z)
			counter = counter + 1
		)
		print ("Data read frome file : " + filename)
		close fs
)


on Proceed pCont do 
(
	st = timestamp()
	--if (pCont.NumParticles() <= 0) then (
		t1 = pCont.getTimeStart() as float
		t2 = pCont.getTimeEnd() as float
		if (t1 < 0) then (t1 = 0) 
		for t=1 to partArray.count do (
			pCont.AddParticle()
			pCont.particleIndex = pCont.NumParticles() 
			pCont.particleAge = 0
			pCont.particleTime = 0
			pCont.particleSpeed = [0, 0, 0]
			pCont.particlePosition = [partArray[t][1], partArray[t][2], partArray[t][3]]
	--	)
	)
	format "Number of particles : % took:%secs
" (partArray.count) (timestamp()-st)
)


on Release pCont do 
(
 	
)


problem with this is that the array is loaded one time (when i press ctrl-e). then the current frame is read into the array and displayed (and may i say not that fast…)
i also tried putting the reading of the file into the On Proceed but that gets Very slow

Sow, perhaps any1 of you people can help me out here…

Many thanks in advance! if needed i can upload a sequence somewhere!


#2

I think any script solution would be slow. Looks like a job for Krakatoa :slight_smile: It will directly import .csv format through a PRT loader

http://www.franticfilms.com/software/support/krakatoa/csv_file_format.php


#3

Hi there,

I have looked at krakatoa. but that can display/render particles but i think it is not possible to create a mesh out of that? sorta thing like blobmesh/particles…


#4

Not sure you can put the loading code in the init handler, unless you load all the frames at once. In my experience loading the position values in the Proceed handler works just fine.
Here’s a birth script for CSV files I wrote a while ago. It will spawn all the particles existing in a CSV file for that given frame. It doesn’t do a very good job in catching any formatting errors and the like, but I think it shows what I mean:


on ChannelsUsed pCont do
(
	pCont.usePosition = true
)

on Init pCont do 
(
	
)

on Proceed pCont do 
(

	in_file = openFile ((GetDir #export)+"/particles."+currentTime as string+".csv")

	if in_file != undefined then

	(

		num_particles = readValue in_file 

		for p = 1 to num_particles do
		(
			pCont.AddParticle()
			pCont.particleIndex = pCont.NumParticles() -- last particle that was added
			pCont.particlePosition = (readValue in_file)
		)

	close in_file

	)
)

on Release pCont do 
(
 
)

where the file is formatted like this (first number is number of particles in file):


4
[3.56197,6.04401,-192],
[3.66155,3.90171,-188.97],
[-9.92647,-1.75683,-185.939],
[-2.7883,8.71924,-182.909],

By the looks of it though, your input data resembles a heightfield, in which case I think you’d be better off creating an image sequence from your data and using it in conjunction with the Displace modifier.

Either that or look in to creating a scripted object.


#5

Krakatoa has dedicated PFlow operators that can load particles (incl. correctly formatted CSV files) into a PFlow. Then you could just use the Blobmesh or PWrapper to turn the PFlow into a blob.
We have our own (and pretty damn amazing) Particle Mesher but it is not part of Krakatoa and has not been made commercial.


#6

Way to tease us, now you’ve got to release it :smiley:


#7

A couple of things:

  1. It is not my call. If it was, it would be part of Krakatoa.
  2. It depends on how many people really want it.
  3. It depends on what people are willing to pay for it. Seeing how PWrapper is expensive and still popular, there might be some market. But there is also a free render-time VRay blob plugin and people might prefer that…

#8

there is a very nice plugin made for Vray wich does blobmesh things:
http://www.chaosgroup.com/forums/vbulletin/showthread.php?t=45994

some genious named Jerry Ylilammi made it…

Perhaps that is usefull for more people :slight_smile:

but indeed bobe, dont tease hehehe


#9

The Vray Blobmesh that Bercon made works great!

Small test I did a little while back Metaball Test

It is even faster & more memory efficient than prwapper.


#10

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.