Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Flipping cloth? ScaleX == -1?
#11
Here, I wrote this for you. Add it to the cloth component, and set it to update after the solver in ScriptExecutionOrder. This way it is 100% sure it will be done after all simulation is completed.

Code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Obi;

[RequireComponent(typeof (ObiCloth))]
public class FlipNormals : MonoBehaviour {

    private ObiCloth actor;
    
    // Update is called once per frame
    void Awake ()
        {
        actor = GetComponent<ObiCloth>();
    }

    private void LateUpdate()
    {
        Vector3 solverScale = actor.Solver.transform.localScale;

        if (solverScale.x < 0 || solverScale.y < 0 || solverScale.z < 0)
        {
            Vector3[] normals = actor.clothMesh.normals;

            for (int i = 0; i < normals.Length; i++)
                normals[i] *= -1;

            actor.clothMesh.normals = normals;
        }
    }
}

Works fine, collisions with colliders and all. Still, doing this in the vertex shader would be far more performant.

The solver is set up in local space mode, and all colliders, cloth, etc are parented under it. Note that none of the colliders has negative scale, only the solver does. I'm also attaching a video of the results:

Reply


Messages In This Thread
Flipping cloth? ScaleX == -1? - by cubrman - 13-08-2019, 05:29 PM
RE: Flipping cloth? ScaleX == -1? - by josemendez - 14-08-2019, 09:10 AM
RE: Flipping cloth? ScaleX == -1? - by cubrman - 14-08-2019, 11:11 AM
RE: Flipping cloth? ScaleX == -1? - by josemendez - 14-08-2019, 12:19 PM
RE: Flipping cloth? ScaleX == -1? - by cubrman - 14-08-2019, 04:48 PM
RE: Flipping cloth? ScaleX == -1? - by josemendez - 14-08-2019, 05:30 PM
RE: Flipping cloth? ScaleX == -1? - by cubrman - 22-08-2019, 06:13 PM
RE: Flipping cloth? ScaleX == -1? - by josemendez - 23-08-2019, 07:17 AM
RE: Flipping cloth? ScaleX == -1? - by cubrman - 23-08-2019, 10:03 AM
RE: Flipping cloth? ScaleX == -1? - by josemendez - 23-08-2019, 10:05 AM
RE: Flipping cloth? ScaleX == -1? - by josemendez - 23-08-2019, 10:35 AM
RE: Flipping cloth? ScaleX == -1? - by cubrman - 23-08-2019, 12:10 PM
RE: Flipping cloth? ScaleX == -1? - by josemendez - 23-08-2019, 01:06 PM