public override IObiConstraintsBatch Clone() { var clone = new ObiDistanceConstraintsBatch(this); clone.particleIndices.ResizeUninitialized(particleIndices.count); clone.restLengths.ResizeUninitialized(restLengths.count); clone.stiffnesses.ResizeUninitialized(stiffnesses.count); clone.particleIndices.CopyFrom(particleIndices); clone.restLengths.CopyFrom(restLengths); clone.stiffnesses.CopyFrom(stiffnesses); return(clone); }
protected virtual IEnumerator CreateDistanceConstraints() { distanceConstraintsData = new ObiDistanceConstraintsData(); // Add two batches: for even and odd constraints: distanceConstraintsData.AddBatch(new ObiDistanceConstraintsBatch()); distanceConstraintsData.AddBatch(new ObiDistanceConstraintsBatch()); for (int i = 0; i < totalParticles - 1; i++) { var batch = distanceConstraintsData.batches[i % 2] as ObiDistanceConstraintsBatch; if (i < m_ActiveParticleCount - 1) { Vector2Int indices = new Vector2Int(i, i + 1); restLengths[i] = Vector3.Distance(positions[indices.x], positions[indices.y]); batch.AddConstraint(indices, restLengths[i]); batch.activeConstraintCount++; } else { restLengths[i] = m_InterParticleDistance; batch.AddConstraint(Vector2Int.zero, 0); } if (i % 500 == 0) { yield return(new CoroutineJob.ProgressInfo("ObiRope: generating structural constraints...", i / (float)(totalParticles - 1))); } } // if the path is closed, add the last, loop closing constraint to a new batch to avoid sharing particles. if (path.Closed) { var loopClosingBatch = new ObiDistanceConstraintsBatch(); distanceConstraintsData.AddBatch(loopClosingBatch); Vector2Int indices = new Vector2Int(m_ActiveParticleCount - 1, 0); restLengths[m_ActiveParticleCount - 2] = Vector3.Distance(positions[indices.x], positions[indices.y]); loopClosingBatch.AddConstraint(indices, restLengths[m_ActiveParticleCount - 2]); loopClosingBatch.activeConstraintCount++; } }
public ObiDistanceConstraintsBatch(ObiDistanceConstraintsBatch source = null) : base(source) { }
public ObiDistanceConstraintsBatch(ObiDistanceConstraintsData constraints = null, ObiDistanceConstraintsBatch source = null) : base(source) { m_Constraints = constraints; }