Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  How can I extract the fluid rendering mesh?
#1
Corazón 
Hello,
I have recently tried out the new grid-based fluid renderer and it looks fantastic, very captivating. Now, I would like to extract the mesh from a specific frame. There are many interesting things that can be done with this mesh, such as freezing it and setting it as a mesh collider. The possibilities are quite exciting to think about.
So, how should I go about doing this? How can I extract the mesh from a specific frame and turn it into a prefab, etc.?
Thank you!
Reply
#2
(10-07-2024, 02:34 PM)GuoliZheng Wrote: Hello,
I have recently tried out the new grid-based fluid renderer and it looks fantastic, very captivating. Now, I would like to extract the mesh from a specific frame. There are many interesting things that can be done with this mesh, such as freezing it and setting it as a mesh collider. The possibilities are quite exciting to think about.
So, how should I go about doing this? How can I extract the mesh from a specific frame and turn it into a prefab, etc.?
Thank you!

Hi!

Right click on the ObiFluidSurfaceMesher component, then “Bake Mesh”. This will save the current frame as a mesh asset in your project, you can then use it on prefabs, etc.

Kind regards,
Reply
#3
(10-07-2024, 03:52 PM)josemendez Wrote: Hi!

Right click on the ObiFluidSurfaceMesher component, then “Bake Mesh”. This will save the current frame as a mesh asset in your project, you can then use it on prefabs, etc.

Kind regards,
How do I use a script to call the BakeMesh command? I can't access the 7.0 version of the API from the web API button; I can only see version 6.4 and below.
Thank you ! Gran sonrisa
Reply
#4
(10-07-2024, 04:32 PM)GuoliZheng Wrote: How do I use a script to call the BakeMesh command? I can't access the 7.0 version of the API from the web API button; I can only see version 6.4 and below.
Thank you ! Gran sonrisa

You can call IFluidRenderSystem.BakeMesh. Like so:

Code:
var system = emitter.solver.GetRenderSystem<ObiFluidSurfaceMesher>() as IFluidRenderSystem;

if (system != null)
{
       var mesh = new Mesh();
       system.BakeMesh(yourObiFluidSurfaceMesher, ref mesh);

       // optional, save the mesh as an asset in the project:
       ObiEditorUtils.SaveMesh(mesh, "Save fluid mesh", "fluid mesh");
       GameObject.DestroyImmediate(mesh);
}

Note this is a very expensive operation, specially when using the Compute backend as it must read mesh data back from the GPU and will stall the entire render pipeline. It's not recommended to do this at runtime.

kind regards
Reply