Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Is it possible to call an OBIClothRenderer BakeMesh method
#1
Is it possible to call the Obi Cloth Renderer "Bake Mesh" function from code? 

Reason:
I have a complex inflating cloth object that is too slow to use OBI at run time when playing the game. So instead I want to perform the inflation in development version (slowly) and bake around 60 meshes, which I can then cycle through at runtime. So the OBI calculations will not happen at run time, I will just use the baked meshes.

Q1. To achieve this, I want to be able to spawn 60 meshes from code at various periods. Is there a way to call this method from code?

Q2. Is there a way to detect that the Solver sleep threshold has been met and the solver is asleep? This is the point in time I want to generate the baked mesh, then increase the inflation to capture the next frame.

Regards,

Michendo
Reply
#2
(17-09-2023, 02:09 AM)michendo Wrote: Is it possible to call the Obi Cloth Renderer "Bake Mesh" function from code? 

Reason:
I have a complex inflating cloth object that is too slow to use OBI at run time when playing the game. So instead I want to perform the inflation in development version (slowly) and bake around 60 meshes, which I can then cycle through at runtime. So the OBI calculations will not happen at run time, I will just use the baked meshes.

Q1. To achieve this, I want to be able to spawn 60 meshes from code at various periods. Is there a way to call this method from code?

Q2. Is there a way to detect that the Solver sleep threshold has been met and the solver is asleep? This is the point in time I want to generate the baked mesh, then increase the inflation to capture the next frame.

Regards,

Michendo

Hi Michendo,

Q1. The "BakeMesh" button just takes ObiClothRenderer.clothMesh and saves it as an asset. The function that does this is
Code:
ObiEditorUtils.SaveMesh(Mesh mesh, string title, string name, bool makeNewInstance = true, bool optimizeMesh = true);

You can call this function in-editor yourself.

Q2. There's no such thing as a per-solver sleep threshold in Obi, it's a per-particle threshold. You can iterate trough all particles and check whether their energy level (squared velocity magnitude) is below the sleep threshold. To do this, use the particles API.

kind regards,
Reply
#3
Thank you josemendez, that is very helpful.

regards,

Michendo
Reply
#4
I have a follow-up question, though this might be more related to O/S than OBI...

When I call up ObiEditorUtils.SaveMesh on my MacOS pops up a dialog box where I have to hit the save button. I want to automate this with no human interaction. 

Is it possible to override this dialog box so it saves immediately to the file specified?
Reply
#5
(18-09-2023, 12:22 PM)michendo Wrote: I have a follow-up question, though this might be more related to O/S than OBI...

When I call up ObiEditorUtils.SaveMesh on my MacOS pops up a dialog box where I have to hit the save button. I want to automate this with no human interaction. 

Is it possible to override this dialog box so it saves immediately to the file specified?

Hi,

Yes, it's possible. Instead of using ObiEditorUtils.SaveMesh, look into Unity's AssetDatabase.CreateAsset method to save assets to disk. This is what ObiEditorUtils.SaveMesh uses internally, after asking the user for the path where the asset should be saved via a popup dialog box. You can just use CreateAsset() with a hardcoded path instead.
Reply