public override IObiConstraintsBatch Clone(IObiConstraints constraints) { var clone = new ObiBendConstraintsBatch(constraints as ObiBendConstraintsData, this); clone.particleIndices.ResizeUninitialized(particleIndices.count); clone.restBends.ResizeUninitialized(restBends.count); clone.bendingStiffnesses.ResizeUninitialized(bendingStiffnesses.count); clone.particleIndices.CopyFrom(particleIndices); clone.restBends.CopyFrom(restBends); clone.bendingStiffnesses.CopyFrom(bendingStiffnesses); return(clone); }
protected virtual IEnumerator CreateBendingConstraints() { bendConstraintsData = new ObiBendConstraintsData(); // Add three batches: bendConstraintsData.AddBatch(new ObiBendConstraintsBatch()); bendConstraintsData.AddBatch(new ObiBendConstraintsBatch()); bendConstraintsData.AddBatch(new ObiBendConstraintsBatch()); for (int i = 0; i < totalParticles - 2; i++) { var batch = bendConstraintsData.batches[i % 3] as ObiBendConstraintsBatch; Vector3Int indices = new Vector3Int(i, i + 2, i + 1); float restBend = ObiUtils.RestBendingConstraint(restPositions[indices[0]], restPositions[indices[1]], restPositions[indices[2]]); batch.AddConstraint(indices, restBend); if (i < m_ActiveParticleCount - 2) { batch.activeConstraintCount++; } if (i % 500 == 0) { yield return(new CoroutineJob.ProgressInfo("ObiRope: generating structural constraints...", i / (float)(totalParticles - 2))); } } // if the path is closed, add the last, loop closing constraints to a new batch to avoid sharing particles. if (path.Closed) { var loopClosingBatch = new ObiBendConstraintsBatch(); bendConstraintsData.AddBatch(loopClosingBatch); Vector3Int indices = new Vector3Int(m_ActiveParticleCount - 2, 0, m_ActiveParticleCount - 1); loopClosingBatch.AddConstraint(indices, 0); loopClosingBatch.activeConstraintCount++; var loopClosingBatch2 = new ObiBendConstraintsBatch(); bendConstraintsData.AddBatch(loopClosingBatch2); indices = new Vector3Int(m_ActiveParticleCount - 1, 1, 0); loopClosingBatch2.AddConstraint(indices, 0); loopClosingBatch2.activeConstraintCount++; } }
public ObiBendConstraintsBatch(ObiBendConstraintsData constraints = null, ObiBendConstraintsBatch source = null) : base(source) { m_Constraints = constraints; }
public ObiBendConstraintsBatch(ObiBendConstraintsBatch source = null) : base(source) { }