taichi-dev / taichi_elements

High-performance multi-material continuum physics engine in Taichi
MIT License
486 stars 69 forks source link

Seed from arbitrary geometry #5

Closed yuanming-hu closed 4 years ago

yuanming-hu commented 4 years ago

To do this it's better to first voxelize the geometries in Blender, and then pass the voxel grid to Taichi. Not sure if there's a voxelization modified in Blender (https://docs.blender.org/manual/en/latest/modeling/modifiers/generate/remesh.html)

PavelBlend commented 4 years ago

The blender does not have tools for creating a voxel grid. You will have to create these tools yourself. And how did you get the voxel grid when you created this example?: https://raw.githubusercontent.com/yuanming-hu/public_files/master/graphics/mls-mpm-cpic/armodillo.gif

yuanming-hu commented 4 years ago

Taichi used to have a ray-casting based voxelization system. However, the ray-casting stuff depends on Intel Embree and leads to some portability issues. Therefore I removed that functionality... Let me think about an alternative way to do this.

yuanming-hu commented 4 years ago

There seems to be a Block modifier that does voxelization: https://www.youtube.com/watch?v=l31iUlFiciI

PavelBlend commented 4 years ago

This modifier converts the mesh to voxels, but the mesh is still output. You will have to convert this mesh to voxels (although it will be easier than converting the original mesh). It seems to me that it is better to copy the voxelizer from another simulator. You can see how voxelization occurs in these repositories: https://github.com/rlguy/Blender-FLIP-Fluids https://github.com/doyubkim/fluid-engine-dev Or you can see how this modifier works in the source code of the blender.

There is no data type such as volume in the blender (this data type appeared in 2.83). Therefore, I do not think that it is possible to implement conversion to voxels using standard blender tools.

yuanming-hu commented 4 years ago

Thanks for the info! I prefer not to introduce a C++ voxelizer since that will make this solver less portable (and will prevent people from trying it). With everything considered, I decided to write a voxelizer in Taichi.

  1. Fetch the triangles of the Blender mesh into a numpy array of size #triangles x 9, where each column has 3x3=9 float numbers, representing 3x3D coordinates of that triangle.
  2. Write a voxelizer in Taichi (instead of C++) that takes the numpy array from the modified mesh and generate a voxel grid in Taichi
  3. Seed from the voxel grid in Taichi

I can do 2 and 3. Could you help with 1? I can start with an external numpy array of triangles so no rush on 1. I'm recently quite occupied, therefore I need 1-2 weeks to finish 2 and 3.

PavelBlend commented 4 years ago

good, I will write the first paragraph. I can do today. If there is something wrong, then I will have time to correct the errors.

PavelBlend commented 4 years ago

I made the first point. All triangles are stored in the triangles list: 7667cdf2871abbe42ce3970a12d837afb3c975f7 If I did something wrong, let me know.

yuanming-hu commented 4 years ago

Thanks! This is really helpful.

On my end, voxelizer done. A layer-by-layer view of voxelized Suzanne (gif file may take a while to load):

video

(There are two floating components. Not sure if it is caused by the fact that the mesh isn't watertight or there's some precision issue in the voxelizer. Will fix later.)

I will proceed to 3 in a couple of days.

PavelBlend commented 4 years ago

Great job!

Yes, Suzanne is an open mesh (Non-Manifold Mesh). Such meshes are not suitable for voxelization. You can try to close the holes in the eyes or use another mesh.

How long does voxelization take? And at what resolution?

yuanming-hu commented 4 years ago

At 256^3 it takes 0.013s. I wouldn't worry about its performance too much :-)

You can try it on your end, if you download and unzip triangles.zip, then run voxelizer.py

yuanming-hu commented 4 years ago

Done. See demo_3d_mesh.py: https://www.youtube.com/watch?v=vWVQ0KICUkc&feature=youtu.be (We should use a manifold mesh next time :-)

Btw could you please integrate this new feature into Blender? I believe we will end up with an awesome simulator!

PavelBlend commented 4 years ago

It is very cool!

I will try to integrate this function into a blender.

PavelBlend commented 4 years ago

At the moment, seed from geometry has been made. I think you can close this issue.