InteractiveComputerGraphics / SPlisHSPlasH

SPlisHSPlasH is an open-source library for the physically-based simulation of fluids.
https://splishsplash.physics-simulation.org/
MIT License
1.59k stars 288 forks source link

bgeo file python reader and fluid surface viewing #68

Closed xingyul3 closed 4 years ago

xingyul3 commented 4 years ago

Hi, thanks for releasing this awesome project. I'm just wondering how to read the dumped bgeo files with python (both particle positions and velocities). Also, how to reconstruct transparent fluid surfaces from the particles to high-quality generate images like this video? Is it possible to read the reconstructed surface also in python (e.g. as a mesh)? Thanks a lot!

digitalillusions commented 4 years ago

Hi, we purposefully do not include any instructions for doing this, because there are many different ways to achieve a rendering such as the one in the video. First for reading partio files, have a look at the partio repository. If you decide to use the python bindings you could use code similar to the following to read partio data

import partio
import numpy as np
def read_partio_data(file):
    headers = partio.readHeaders(file)
    data = partio.read(file)
    info = {headers.attributeInfo(i).name: (headers.attributeInfo(i), headers.attributeInfo(i).count, headers.attributeInfo(i).type) for i in range(headers.numAttributes())}
    np_data = np.array([data.get(info["position"][0], i) for i in range(data.numParticles())]).astype(np.float64)
    min = np.array([np.amin(np_data[:,i]) for i in range(3)]) - np.ones((3,))
    max = np.array([np.amax(np_data[:,i]) for i in range(3)]) + np.ones((3,))
    return np_data, min.astype(np.float32), max.astype(np.float64)

As an alternative you could use vtk to export particle data. Going from particle data to what you see in the video typically involves the following steps

  1. Reconstruct a surface mesh from particle data, using e.g. a marching cubes algorithm
  2. Import the reconstructed surface meshes into Blender or Maya
  3. Set up lighting and materials and render the video using some kind of light tracing (e.g. Cycles in Blender or Arnold in Maya)

There are many additional resources out there to help you with the steps above. This project is "only" meant to solve incompressible fluid flow problems using SPH and none of the above.

xingyul3 commented 4 years ago

Thanks a lot for the replies. They are really helpful.