예제 #1
0
        private unsafe void RetrieveCloth(IntPtr worldHandle)
        {
            IntPtr positions     = (IntPtr)0;
            int    positionsSize = 0;
            IntPtr faces         = (IntPtr)0;
            int    facesSize     = 0;

            //Debug.Log($"Attempt retrieve cloth. ClothHandle = {_clothHandle}");
            UClothImports.ucloth_retrieveClothInfo(_clothHandle, worldHandle, ref positions, ref positionsSize, ref faces, ref facesSize);

            Marshal.Copy(positions, _positionValues, 0, positionsSize * 3);
            Vector3[] vertices = _mesh.vertices;

            for (int i = 0; i < _mesh.vertices.Length; i++)
            {
                vertices[i] = new Vector3(_positionValues[i * 3], _positionValues[i * 3 + 1], _positionValues[i * 3 + 2]);
            }

            _mesh.vertices = vertices;
        }
예제 #2
0
        private unsafe IntPtr CreateCloth(IntPtr worldHandle, Mesh mesh, float mass, float elasticity, float damping)
        {
            Vector3[] vertices = mesh.vertices;
            int[]     faces    = mesh.triangles;

            // allocate arrays one time only for performance. We don't wanna allocate each time for marshalling later.
            if (_positionValues == null)
            {
                _positionValues = new float[vertices.Length * 3];
            }
            if (_facesValues == null)
                _facesValues = new int[faces.Length];

            fixed(Vector3 *v = vertices)
            {
                fixed(int *f = faces)
                {
                    return(UClothImports.ucloth_addCloth(worldHandle, v, mesh.vertexCount, f, mesh.triangles.Length, mass, elasticity, damping));
                }
            }
        }
예제 #3
0
 UClothWorld()
 {
     _worldHandle = UClothImports.ucloth_createWorld();
     UClothImports.ucloth_addAcceleration(_worldHandle, ref gravity);
 }
예제 #4
0
 // Update is called once per frame
 void OnDestroy()
 {
     UClothImports.ucloth_deletePBDSimulation(_simulationHandle);
     Debug.Log("Destroyed PBD simulation");
 }
예제 #5
0
 void FixedUpdate()
 {
     UClothImports.ucloth_simulate(_simulationHandle, UClothWorld.Instance.GetHandle(), 5, Time.fixedDeltaTime);    
 }
예제 #6
0
 // Start is called before the first frame update
 void Awake()
 {
     Debug.Log("Attempt create PBD simulation");
     _simulationHandle = UClothImports.ucloth_createPBDSimulation();
     Debug.Log("Created PBD simulation");
 }
예제 #7
0
 private void AttachIndexToPosition(IntPtr worldHandle, IntPtr clothHandle, uint index, Vector3 position)
 {
     UClothImports.ucloth_attachParticleToPosition(worldHandle, clothHandle, index, position);
 }