ipc-sim / IPC

Incremental Potential Contact (IPC) is for robust and accurate time stepping of nonlinear elastodynamics. IPC guarantees intersection- and inversion-free trajectories regardless of materials, time-step sizes, velocities, or deformation severity.
https://ipc-sim.github.io/
MIT License
558 stars 73 forks source link

Export only the mesh of select bodies #24

Open zfergus opened 3 years ago

zfergus commented 3 years ago

Creating a feature request from an email I received:

We are simulating the bouncing sphere inside of a closed boundary, so we input multiple mesh files (including the mesh of the surrounding boxes, and the mesh of the sphere). Is there a way to only output the mesh file we are interested in? (we only want the output mesh to contain the sphere, not the surrounding constraints).

My reply:

Unfortunately, exporting each input shape individually is not implemented. The reason being that all shapes are concatenated together and simulated as one large shape with disconnected components.

Probably the easiest way for you to implement this feature is as a post-process of the exported OBJ files. I would for each OBJ: load the OBJ, separate the mesh into disconnected components, save the component you want. The order of components should be consistent with the input order of shapes and is consistent throughout the simulation. The "complicated" part is splitting by disconnected components, but luckily libigl has some functions for this or PyMesh has a single function that does exactly this.

Alternatively, I think it would be easy to keep track of which vertices/faces belong to which input shape and modify IPC to export the components individually. If you are comfortable with C++ and want to try adding this feature to IPC it would be welcomed. Otherwise, I think it is worth my time to add this, but I don't know when I will have time to get to it.

This should help me keep track of the feature request.