Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Initialize a softbody on scaled objects via script
#1
Pregunta 
Imagine I have a skinned mesh object and it is scaled by its bones, is there a way to initialize & bind skin (using its current shape) from scripts?
Reply
#2
(23-08-2019, 08:24 AM)aznaf Wrote: Imagine I have a skinned mesh object and it is scaled by its bones, is there a way to initialize & bind skin (using its current shape) from scripts?

Bone scaling is not supported. Well, it is, but won't act as you expect it to.

Suppose you scale a bone to double its size (scale <2,2,2>). Scaling a bone acts upon the mesh vertex positions after skinning is done each frame. However, the shared mesh (used to generate the topology, and the cloth asset) is not affected in any way by this. So skin constraints are constraining the cloth to the scaled/skinned mesh vertex positions, but all other constraints (distance, bend, etc) still work with the unscaled mesh. The end result would overstretch all constraints to double its rest length.

For this to work you'd have to bake bone scale onto the shared mesh vertices, freeze bone scale to 1 (so that the "doubled size" becomes its natural size), then generate the topology, and reinitialize the cloth. This is quite complex but could be done. The first two steps don't have anything to do with Obi. Generating a topology and reinitializing at runtime can be done. See the included "RuntimeCloth" sample scene and its associated scripts.
Reply
#3
(23-08-2019, 09:57 AM)josemendez Wrote: Bone scaling is not supported. Well, it is, but won't act as you expect it to.

Suppose you scale a bone to double its size (scale <2,2,2>). Scaling a bone acts upon the mesh vertex positions after skinning is done each frame. However, the shared mesh (used to generate the topology, and the cloth asset) is not affected in any way by this. So skin constraints are constraining the cloth to the scaled/skinned mesh vertex positions, but all other constraints (distance, bend, etc) still work with the unscaled mesh. The end result would overstretch all constraints to double its rest length.

For this to work you'd have to bake bone scale onto the shared mesh vertices, freeze bone scale to 1 (so that the "doubled size" becomes its natural size), then generate the topology, and reinitialize the cloth. This is quite complex but could be done. The first two steps don't have anything to do with Obi. Generating a topology and reinitializing at runtime can be done. See the included "RuntimeCloth" sample scene and its associated scripts.

Thank you for your reply, but I couldn't find a scene named "RuntimeCloth".

Are we still talking about Obi Softbody Huh
Reply
#4
(23-08-2019, 10:16 AM)aznaf Wrote: Thank you for your reply, but I couldn't find a scene named "RuntimeCloth".

Are we still talking about Obi Softbody Huh

My apologies, since you were talking about character skin, I assumed we were talking about ObiCloth. Didn't even realize we are in the ObiSoftbody subforum  Triste .

Same thing applies to soft bodies though. Keep in mind that softbody generation involves two steps:
generate the particle representation using a skinned mesh, then bind another skinned mesh to it via ObiSoftbodySkinner. Both meshes don't need to be the same one.

I assume you use the same mesh for both generation and skinning. Once you have your bone scale baked into your shared mesh vertices as I described in the previous post (which is outside of the scope of Obi), generating the soft body is done by calling the GeneratePhysicRepresentationFromMesh coroutine.

Code:
yield return softbody.StartCoroutine(actor.GeneratePhysicRepresentationForMesh());

After this coroutine is completed, then bind the skin by calling the skinner's BindSkin coroutine:
Code:
yield return skinner.StartCoroutine(skinner.BindSkin());

Finally, assuming your softbody has been assigned a solver, add it to the solver to start simulation:
Code:
softbody.AddToSolver(null);
Reply
#5
(23-08-2019, 10:47 AM)josemendez Wrote: My apologies, since you were talking about character skin, I assumed we were talking about ObiCloth. Didn't even realize we are in the ObiSoftbody subforum  Triste .

Same thing applies to soft bodies though. Keep in mind that softbody generation involves two steps:
generate the particle representation using a skinned mesh, then bind another skinned mesh to it via ObiSoftbodySkinner. Both meshes don't need to be the same one.

I assume you use the same mesh for both generation and skinning. Once you have your bone scale baked into your shared mesh vertices as I described in the previous post (which is outside of the scope of Obi), generating the soft body is done by calling the GeneratePhysicRepresentationFromMesh coroutine.

Code:
yield return softbody.StartCoroutine(actor.GeneratePhysicRepresentationForMesh());

After this coroutine is completed, then bind the skin by calling the skinner's BindSkin coroutine:
Code:
yield return skinner.StartCoroutine(skinner.BindSkin());

Finally, assuming your softbody has been assigned a solver, add it to the solver to start simulation:
Code:
softbody.AddToSolver(null);


Thank you very much! code examples are very helpful.
Saving a scaled mesh to another mesh asset sounds reasonable. I will give it a try. Sonrisa

Still have one question though, right after GeneratePhysicRepresentationFromMesh coroutine (the same with "Initialize" in editor?) is done,
is it possible to edit particles from scripts to tell which part of my mesh should be simulated?
Reply
#6
Any news?
Reply
#7
(30-08-2019, 05:54 AM)aznaf Wrote: Any news?

Hi there,

You can use the particles API to edit particles at runtime. See:
http://obi.virtualmethodstudio.com/tutor...icles.html
Reply