/** * Generates new valid rest positions for the entire rope. */ public override void RegenerateRestPositions() { ObiStretchShearConstraintBatch distanceBatch = StretchShearConstraints.GetFirstBatch(); // Iterate trough all distance constraints in order: int particle = -1; int lastParticle = -1; float accumulatedDistance = 0; for (int i = 0; i < distanceBatch.ConstraintCount; ++i) { if (i == 0) { lastParticle = particle = distanceBatch.springIndices[i * 2]; restPositions[particle] = new Vector4(0, 0, 0, 1); } accumulatedDistance += Mathf.Min(interParticleDistance, principalRadii[particle][0], principalRadii[lastParticle][0]); particle = distanceBatch.springIndices[i * 2 + 1]; restPositions[particle] = Vector3.right * accumulatedDistance; restPositions[particle][3] = 1; // activate rest position } PushDataToSolver(ParticleData.REST_POSITIONS); }
/** * Returns the rest length of a structural constraint */ public override float GetStructuralConstraintRestLength(int constraintIndex) { ObiStretchShearConstraintBatch distanceBatch = StretchShearConstraints.GetFirstBatch(); if (distanceBatch != null && constraintIndex >= 0 && constraintIndex < distanceBatch.ConstraintCount) { return(distanceBatch.restLengths[constraintIndex]); } return(0); }
/** * Returns the index of the structural constraint at a given normalized rope coordinate. */ public override int GetConstraintIndexAtNormalizedCoordinate(float coord) { ObiStretchShearConstraintBatch distanceBatch = StretchShearConstraints.GetFirstBatch(); if (distanceBatch != null) { float mu = coord * distanceBatch.ConstraintCount; return(Mathf.Clamp(Mathf.FloorToInt(mu), 0, distanceBatch.ConstraintCount - 1)); } return(-1); }
/** * Returns the particle indices affected by a structural constraint */ public override bool GetStructuralConstraintParticles(int constraintIndex, ref int particleIndex1, ref int particleIndex2) { ObiStretchShearConstraintBatch distanceBatch = StretchShearConstraints.GetFirstBatch(); if (distanceBatch != null && constraintIndex >= 0 && constraintIndex < distanceBatch.ConstraintCount) { particleIndex1 = distanceBatch.springIndices[constraintIndex * 2]; particleIndex2 = distanceBatch.springIndices[constraintIndex * 2 + 1]; return(true); } return(false); }
/** * Returns the amount of structural constraints in the rope. */ public override int GetStructuralConstraintCount() { ObiStretchShearConstraintBatch distanceBatch = StretchShearConstraints.GetFirstBatch(); return(distanceBatch != null ? distanceBatch.ConstraintCount:0); }