Obi Official Forum
Help How can I extract the fluid rendering mesh? - Printable Version

+- Obi Official Forum (https://obi.virtualmethodstudio.com/forum)
+-- Forum: Obi Users Category (https://obi.virtualmethodstudio.com/forum/forum-1.html)
+--- Forum: Obi Fluid (https://obi.virtualmethodstudio.com/forum/forum-3.html)
+--- Thread: Help How can I extract the fluid rendering mesh? (/thread-4287.html)



How can I extract the fluid rendering mesh? - GuoliZheng - 10-07-2024

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!


RE: How can I extract the fluid rendering mesh? - josemendez - 10-07-2024

(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,


RE: How can I extract the fluid rendering mesh? - GuoliZheng - 10-07-2024

(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


RE: How can I extract the fluid rendering mesh? - josemendez - 11-07-2024

(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