5
$\begingroup$

I've been trying to write out particles cache files from Houdini to Blender.

I successfully exported a sequence of bphys file, which Blender loads fine. the code is roughly ( in python ):

    dataType = 1
    nParticles = npoints
    data = struct.pack("8c","B","P","H","Y","S","I","C","S")
    data += struct.pack("III",dataType,nParticles,31) # I don't understand that 31 ...

    for i in range(nParticles):        
        #index 
        data += struct.pack('I',idList[i]) 
        #Location
        data += struct.pack('fff',positionList[i][0], positionList[i][2]*-1, positionList[i][1]) 
        #Velocity
        data += struct.pack('fff',velocityList[i][0], velocityList[i][2]*-1, velocityList[i][1]) 
        #Rotation
        data += struct.pack('ffff',0.0,0.0,0.0,0.0) ## no values for now
        #Avelocity
        data += struct.pack('fff',5.0,10.0,0.5) ## no values for now

This code runs for every frame in the animation. Lastly, I write the very first bphys file ( with 6 padded zeros) "filename_000000_00.bphys" , containing a list of all the particles 'times' in the simulation, with the good header data.

dataType = 1
nParticles = len(particlesList)
data = struct.pack("8c","B","P","H","Y","S","I","C","S")
data += struct.pack("III",dataType,nParticles,64)

for particle in particlesList:    
    data += struct.pack('fff', particle['birth'], particle['death'], particle['lifetime'])

Now, that's a good first step. Althought I haven't been able to see any Angular velocity in blender; Location and Velocity are read fine.

One of the key parameters I would love to export from Houdini, is the scale parameter. But I have no idea how to add this value to the bphys file. I tried to add a float to the "collection" , of course it doesn't work. I must have to change something in the header. This "31" value seems to correspond to the amount of data per particles. There seems to be a lot of different possible values for this parameter. How can I find some informations about that ? ( if possible without having to dive into C++ source code, which I tried )

I feel like I'm almost there

I need some light ^^

$\endgroup$
1
$\begingroup$

not sure if you found a solution, but here is python script, that reads and writes bphys data

https://blenderartists.org/forum/showthread.php?318831-Point-Cache-Doctor-script

via phonybone and here is nice solution via kram1032

Can I access the particle system through Python to build custom simulations?

$\endgroup$
0
$\begingroup$

BPHYS file format

The actual content of the cache files has to start with a header describing the data, with the first 8 bytes being “BPHYSICS”, followed by an unsigned int with the lower 2 bytes defining the simulation type, and the higher 2 bytes defining additional flags for the following data, such as compression or extra data after the main data. What comes next can be customized by the simulation in it”s point cache ID, but usually there is an unsigned int defining the specific data streams that will follow, and an unsigned int for the amount of points each data stream has. After this the actual data streams can start.

The data stream itself depends in the simulation type. Looking at what the particle system writes there is a set of flags containing what data is stored and will be read.

31 means:

  • INDEX (1)
  • LOCATION (2)
  • VELOCITY (4)
  • ROTATION (8)
  • AVELOCITY (16)

64 in you code means that the TIME fields us present in the cache (life, die, age), but no other field.

Note: that creating files with other structures even leaving out parts or adding parts is not supported as nowhere the file format describes how long a single record is. This flag tells blender what to expect. but everything is in a specific order and uses a specific size.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.