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


Messages In This Thread
Lock Softbody Movement & Cut it - by arrnav96 - 27-05-2020, 06:42 AM
RE: Lock Softbody Movement & Cut it - by arrnav96 - 27-05-2020, 09:51 AM
RE: Lock Softbody Movement & Cut it - by arrnav96 - 27-05-2020, 10:39 AM
RE: Lock Softbody Movement & Cut it - by arrnav96 - 27-05-2020, 10:59 AM
RE: Lock Softbody Movement & Cut it - by arrnav96 - 27-05-2020, 01:20 PM
RE: Lock Softbody Movement & Cut it - by arrnav96 - 01-06-2020, 10:36 AM
RE: Lock Softbody Movement & Cut it - by arrnav96 - 01-06-2020, 12:24 PM