Example #1
0
        protected virtual IEnumerator CreateVolumeConstraints()
        {
            //Create pressure constraints if the mesh is closed:
            if (topology.closed)
            {
                volumeConstraintsData = new ObiVolumeConstraintsData();

                ObiVolumeConstraintsBatch volumeBatch = new ObiVolumeConstraintsBatch();
                volumeConstraintsData.AddBatch(volumeBatch);

                float avgInitialScale = (scale.x + scale.y + scale.z) * 0.33f;

                int[] triangleIndices = new int[topology.faces.Count * 3];
                for (int i = 0; i < topology.faces.Count; i++)
                {
                    HalfEdgeMesh.Face face = topology.faces[i];

                    HalfEdgeMesh.HalfEdge e1 = topology.halfEdges[face.halfEdge];
                    HalfEdgeMesh.HalfEdge e2 = topology.halfEdges[e1.nextHalfEdge];
                    HalfEdgeMesh.HalfEdge e3 = topology.halfEdges[e2.nextHalfEdge];

                    triangleIndices[i * 3]     = e1.endVertex;
                    triangleIndices[i * 3 + 1] = e2.endVertex;
                    triangleIndices[i * 3 + 2] = e3.endVertex;

                    if (i % 500 == 0)
                    {
                        yield return(new CoroutineJob.ProgressInfo("ObiCloth: generating volume constraints...", i / (float)topology.faces.Count));
                    }
                }

                volumeBatch.AddConstraint(triangleIndices, topology.volume * avgInitialScale);

                // Set initial amount of active constraints:
                for (int i = 0; i < volumeConstraintsData.batches.Count; ++i)
                {
                    volumeConstraintsData.batches[i].activeConstraintCount = volumeConstraintsData.batches[i].constraintCount;
                }

                // last triangle is the triangle count:
                volumeBatch.firstTriangle.Add(volumeBatch.particleIndices.count / 3);
            }
        }
Example #2
0
        protected virtual IEnumerator CreateSimplices()
        {
            triangles   = new int[topology.faces.Count * 3];
            restNormals = new Vector3[topology.vertices.Count];

            // Generate deformable triangles:
            for (int i = 0; i < topology.faces.Count; i++)
            {
                HalfEdgeMesh.Face face = topology.faces[i];

                HalfEdgeMesh.HalfEdge e1 = topology.halfEdges[face.halfEdge];
                HalfEdgeMesh.HalfEdge e2 = topology.halfEdges[e1.nextHalfEdge];
                HalfEdgeMesh.HalfEdge e3 = topology.halfEdges[e2.nextHalfEdge];

                triangles[i * 3]     = e1.endVertex;
                triangles[i * 3 + 1] = e2.endVertex;
                triangles[i * 3 + 2] = e3.endVertex;

                Vector3 v1 = positions[e1.endVertex];
                Vector3 v2 = positions[e2.endVertex];
                Vector3 v3 = positions[e3.endVertex];

                Vector3 n = Vector3.Cross(v2 - v1, v3 - v1);

                restNormals[e1.endVertex] += n;
                restNormals[e2.endVertex] += n;
                restNormals[e3.endVertex] += n;

                if (i % 500 == 0)
                {
                    yield return(new CoroutineJob.ProgressInfo("ObiCloth: generating deformable geometry...", i / (float)topology.faces.Count));
                }
            }

            for (int i = 0; i < restNormals.Length; ++i)
            {
                restNormals[i].Normalize();
            }
        }