Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Lock Softbody Movement & Cut it
#11
(27-05-2020, 01:24 PM)josemendez Wrote: My bad, in 5.0 and up, the equivalent to InSolver is "isLoaded". You can see all other snippets in the page using it, instead of InSolver. I just updated the snippet to reflect this.

This is the result video with a new problem after implementing everything -



The setup -

So I have succeeded in "locking" the softbody in position, hovering it, without any COM calculations using a simple clever solution. I used invisible blocking colliders to 'lock' and 'hover' the slime above table -

   

Now, this works, I have setup the cutting & blueprint and softbody generation is successful. But the final softbody has a very weird glitchy shape and effect (Shown in attached short cutting video above)

First, I'm baking the mesh & mesh collider every frame and it's creating no performance issues. Once the knife enters mesh collider (Of slime), The cut occurs and splits mesh into two. The split meshes look like this (BEFORE the soft body generation). One of the split meshes is slightly moved in this picture to point out their perfect cut shapes -

   

Then, I detect the larger mesh out of the two using mesh bounds size, then pass on the larger mesh to the softbody generation code below (Called using StartCoroutine after mesh splitting code) -

Code:
private IEnumerator Generate_SB_Cut_Piece(MeshFilter Mesh, Material mat, ObiSolver solver, GameObject DisablePiece)
{
        // create the blueprint: (ObiSoftbodySurfaceBlueprint, ObiSoftbodyVolumeBlueprint)
        var blueprint = ScriptableObject.CreateInstance<ObiSoftbodySurfaceBlueprint>();

        // set the blueprint's particle radius and cluster radius:
        blueprint.inputMesh = Mesh.mesh;
        blueprint.scale = Vector3.one;
        blueprint.particleRadius = 0.1f;
        blueprint.particleOverlap = 0.2f;
        blueprint.shapeSmoothing = 0.5f;
        blueprint.anisotropyNeighborhood = 0.2f;
        blueprint.maxAnisotropy = 3f;
        blueprint.softClusterRadius = 0.3f;
        blueprint.oneSided = false;

        // generate the blueprint:
        yield return StartCoroutine(blueprint.Generate());

        // create the softbody actor/renderer:
        GameObject softbodyObject = new GameObject("Softbody_FallOFF", typeof(ObiSoftbody), typeof(ObiSoftbodySkinner));
        softbodyObject.AddComponent<SetPhase>().phase = 4;
        softbodyObject.layer = 14;

        // get component references:
        ObiSoftbody softbody = softbodyObject.GetComponent<ObiSoftbody>();
        ObiSoftbodySkinner skinner = softbodyObject.GetComponent<ObiSoftbodySkinner>();
        SkinnedMeshRenderer meshRenderer = softbodyObject.GetComponent<SkinnedMeshRenderer>();
        meshRenderer.sharedMaterial = mat;
        skinner.Source = softbody;

        // instantiate and set the blueprint:
        softbody.softbodyBlueprint = ScriptableObject.Instantiate(blueprint);

        // set the mesh for the skinned mesh renderer:
        meshRenderer.sharedMesh = blueprint.inputMesh;

        // bind the mesh to the softbody (synchronously):
        IEnumerator bind = skinner.BindSkin();
        while (bind.MoveNext()) { }

        // parent the softbody under a solver to start simulation:
        softbody.transform.parent = solver.transform;

        DisablePiece.SetActive(false);
}

Before the blueprint generation, I know the mesh generated does not have double vertices or stiching issues as the mesh cutter is reliable and makes a pretty vanilla mesh, this is the topology of the generated mesh (As viewed in inspector of mesh filter of one of the split objects) -

   

If you're wondering that the front face above with strangely long triangles might be a problem, I have even tried temporarily passing a vanilla non-split complete slime sphere mesh (With no stretched triangles) to the blueprint generation code above and the result still looks like the garble shown in video.

I'm hence trying to understand why the soft body generated looks so corrupted. Hence I know the mesh is not really at fault here. Why is the generated softbody so messed up?
Reply
#12
Looks to me like no clusters are being generated. This could be due to the cluster radius being too small, this is mentioned in the manual:
http://obi.virtualmethodstudio.com/tutor...setup.html

Code:
If parts of your softbody are detaching from it at runtime, it means your cluster network is fragmented. Use a larger soft cluster radius to ensure all clusters overlap with each other.

Add a ObiParticleRenderer component to your softbody to see what's happening with the particles. Chances are they are just moving independently from each other, due to no/few clusters being generated. If this is the case, increase your soft cluster radius a bit.
Reply
#13
(01-06-2020, 10:46 AM)josemendez Wrote: Looks to me like no clusters are being generated. This could be due to the cluster radius being too small, this is mentioned in the manual:
http://obi.virtualmethodstudio.com/tutor...setup.html

Code:
If parts of your softbody are detaching from it at runtime, it means your cluster network is fragmented. Use a larger soft cluster radius to ensure all clusters overlap with each other.

Add a ObiParticleRenderer component to your softbody to see what's happening with the particles. Chances are they are just moving independently from each other, due to no/few clusters being generated. If this is the case, increase your soft cluster radius a bit.

Okay, it worked, although there are still tiny glitches, but I think I should be able to resolve them.

1. What is the best way to scale the softbody? The spawned piece seems way bigger than the actual object and changing it's transform or even parent's transform does nothing.
2. How do I make the piece fall down with a "melting" effect? Right now, the piece seems too stiff, I want it to be super soft.

Almost there otherwise!

EDIT: Also some times the spawned softbody objects simply fall through the table platform, even if I have set them up correctly! (Different phases, collider Obi components), the only way to fix this is seemingly to quickly move the platform transform a little at spawn time of any softbody (+0.1f in Y-direction, wait for 0.01f seconds and then back, using a coroutine) and only then the softbodies start noticing it's presence! Is this a bug? (Could it be related to me using Enter quick play mode without domain reload in Unity?)
Reply
#14
(01-06-2020, 12:24 PM)arrnav96 Wrote: Okay, it worked, although there are still tiny glitches, but I think I should be able to resolve them.

1. What is the best way to scale the softbody? The spawned piece seems way bigger than the actual object and changing it's transform or even parent's transform does nothing.
2. How do I make the piece fall down with a "melting" effect? Right now, the piece seems too stiff, I want it to be super soft.

Almost there otherwise!

EDIT: Also some times the spawned softbody objects simply fall through the table platform, even if I have set them up correctly! (Different phases, collider Obi components), the only way to fix this is seemingly to quickly move the platform transform a little at spawn time of any softbody (+0.1f in Y-direction, wait for 0.01f seconds and then back, using a coroutine) and only then the softbodies start noticing it's presence! Is this a bug? (Could it be related to me using Enter quick play mode without domain reload in Unity?)


1.- Scaling a deformable object isn't as trivial as it sounds. Mathematically, it does not make any sense to scale a deformable object since it has no clear "center" or "origin"...where would you scale from, if the object can change its shape in many ways? Same for translation and rotation: only rigid shapes can be transformed in the traditional (affine) sense, in a meaningful way.

Now, you could either generate the blueprint from a smaller version of the mesh (by "smaller mesh" I mean exactly that: not the same mesh with a smaller transform scale, but actual vertices closer together), or scale the simulation as a whole, using the solver transform (doable because the simulation is performed in solver space).

Dealing with transforms in deformable object simulations *really* requires good understanding of affine transforms and vector spaces.

2.- Using a lower deformation resistance for shape matching constraints will do: http://obi.virtualmethodstudio.com/tutor...aints.html
Reply