Beispiel #1
0
        public IEnumerator Generate()
        {
            m_Empty = true;

            m_ActiveParticleCount        = 0;
            distanceConstraintsData      = null;
            bendConstraintsData          = null;
            skinConstraintsData          = null;
            tetherConstraintsData        = null;
            bendTwistConstraintsData     = null;
            stretchShearConstraintsData  = null;
            shapeMatchingConstraintsData = null;
            aerodynamicConstraintsData   = null;
            chainConstraintsData         = null;
            volumeConstraintsData        = null;

            points    = null;
            edges     = null;
            triangles = null;

            IEnumerator g = Initialize();

            while (g.MoveNext())
            {
                yield return(g.Current);
            }

            RecalculateBounds();

            m_Empty = false;
            m_InitialActiveParticleCount = m_ActiveParticleCount;

            foreach (IObiConstraints constraints in GetConstraints())
            {
                for (int i = 0; i < constraints.GetBatchCount(); ++i)
                {
                    constraints.GetBatch(i).initialActiveConstraintCount = constraints.GetBatch(i).activeConstraintCount;
                }
            }

#if UNITY_EDITOR
            EditorUtility.SetDirty(this);
#endif

            if (OnBlueprintGenerate != null)
            {
                OnBlueprintGenerate(this);
            }
        }
Beispiel #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);
            }
        }
Beispiel #3
0
 public ObiVolumeConstraintsData(ObiActor actor = null, ObiVolumeConstraintsData source = null) : base(actor, source)
 {
 }
 public ObiVolumeConstraintsBatch(ObiVolumeConstraintsData constraints = null) : base()
 {
 }
 public ObiVolumeConstraintsBatch(ObiVolumeConstraintsData constraints = null, ObiVolumeConstraintsBatch source = null) : base(source)
 {
     m_Constraints = constraints;
 }