Example #1
0
        public override IObiConstraintsBatch Clone()
        {
            var clone = new ObiVolumeConstraintsBatch(this);

            clone.particleIndices.ResizeUninitialized(particleIndices.count);
            clone.firstTriangle.ResizeUninitialized(firstTriangle.count);
            clone.restVolumes.ResizeUninitialized(restVolumes.count);
            clone.pressureStiffness.ResizeUninitialized(pressureStiffness.count);

            clone.particleIndices.CopyFrom(particleIndices);
            clone.firstTriangle.CopyFrom(firstTriangle);
            clone.restVolumes.CopyFrom(restVolumes);
            clone.pressureStiffness.CopyFrom(pressureStiffness);

            return(clone);
        }
Example #2
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 #3
0
 public ObiVolumeConstraintsBatch(ObiVolumeConstraintsBatch source = null) : base(source)
 {
 }
 public ObiVolumeConstraintsBatch(ObiVolumeConstraintsData constraints = null, ObiVolumeConstraintsBatch source = null) : base(source)
 {
     m_Constraints = constraints;
 }