public override void PushDataToSolver(ObiBatchedConstraints constraints) { if (constraints == null || constraints.Actor == null || !constraints.Actor.InSolver) { return; } ObiShapeMatchingConstraints sc = (ObiShapeMatchingConstraints)constraints; restComs = new AlignedVector4Array(ConstraintCount); coms = new AlignedVector4Array(ConstraintCount); orientations = new AlignedQuaternionArray(ConstraintCount, constraints.Actor.ActorLocalToSolverMatrix.rotation); for (int i = 0; i < shapeMaterialParameters.Count; i++) { shapeMaterialParameters[i] = new Oni.ElastoplasticMaterial(sc.stiffness, sc.plasticYield, sc.plasticCreep, sc.plasticRecovery, sc.maxDeform); } Oni.SetShapeMatchingConstraints(batch, solverIndices, firstIndex.ToArray(), numIndices.ToArray(), explicitGroup.ToArray(), shapeMaterialParameters.ToArray(), restComs.GetIntPtr(), coms.GetIntPtr(), orientations.GetIntPtr(), ConstraintCount); Oni.CalculateRestShapeMatching(constraints.Actor.Solver.OniSolver, batch); }
protected override void OnAddToSolver(ObiBatchedConstraints constraints) { // Set solver constraint data: solverIndices = new int[aerodynamicIndices.Count]; for (int i = 0; i < aerodynamicIndices.Count; i++) { solverIndices[i] = constraints.Actor.particleIndices[aerodynamicIndices[i]]; } }
public void AddToSolver(ObiBatchedConstraints constraints) { // create a constraint batch: batch = Oni.CreateBatch((int)GetConstraintType(), cooked); Oni.AddBatch(constraints.Actor.Solver.OniSolver, batch, sharesParticles); // custom stuff: OnAddToSolver(constraints); }
protected override void OnAddToSolver(ObiBatchedConstraints constraints) { // Set solver constraint data: solverIndices = new int[tetherIndices.Count]; for (int i = 0; i < ConstraintCount; i++) { solverIndices[i * 2] = constraints.Actor.particleIndices[tetherIndices[i * 2]]; solverIndices[i * 2 + 1] = constraints.Actor.particleIndices[tetherIndices[i * 2 + 1]]; } }
protected override void OnAddToSolver(ObiBatchedConstraints constraints) { // Set solver constraint data: solverIndices = new int[bendingIndices.Count]; for (int i = 0; i < restBends.Count; i++) { solverIndices[i * 3] = constraints.Actor.particleIndices[bendingIndices[i * 3]]; solverIndices[i * 3 + 1] = constraints.Actor.particleIndices[bendingIndices[i * 3 + 1]]; solverIndices[i * 3 + 2] = constraints.Actor.particleIndices[bendingIndices[i * 3 + 2]]; } }
protected override void OnAddToSolver(ObiBatchedConstraints constraints) { // Set solver constraint data: solverIndices = new int[pinIndices.Count]; solverColliders = new IntPtr[pinIndices.Count]; for (int i = 0; i < pinOffsets.Count; i++) { solverIndices[i] = constraints.Actor.particleIndices[pinIndices[i]]; solverColliders[i] = pinBodies[i] != null ? pinBodies[i].OniCollider : IntPtr.Zero; } }
protected override void OnAddToSolver(ObiBatchedConstraints constraints) { // Set solver constraint data: solverIndices = new int[pinIndices.Count * 2]; for (int i = 0; i < pinOffsets.Count; i++) { solverIndices[i * 2] = constraints.Actor.particleIndices[pinIndices[i]]; } UpdateColliderIndices(constraints.Actor.Solver.colliderGroup); }
public void RemoveFromSolver(ObiBatchedConstraints constraints) { // custom stuff: OnRemoveFromSolver(constraints); // remove the constraint batch from the solver // (no need to destroy it as its destruction is managed by the solver) Oni.RemoveBatch(constraints.Actor.Solver.OniSolver, batch); // important: set the batch pointer to null, as it could be destroyed by the solver. batch = IntPtr.Zero; }
public override void PushDataToSolver(ObiBatchedConstraints constraints) { if (constraints == null || constraints.Actor == null || !constraints.Actor.InSolver) { return; } ObiPinConstraints pc = (ObiPinConstraints)constraints; for (int i = 0; i < stiffnesses.Count; i++) { stiffnesses[i] = StiffnessToCompliance(pc.stiffness); } Oni.SetPinConstraints(batch, solverIndices, pinOffsets.ToArray(), restDarbouxVectors.ToArray(), solverColliders, stiffnesses.ToArray(), ConstraintCount); }
protected override void OnAddToSolver(ObiBatchedConstraints constraints) { // Set solver constraint data: solverIndices = new int[springIndices.Count]; solverRestLengths = new float[restLengths.Count]; solverStiffnesses = new Vector3[stiffnesses.Count]; int j = 0; foreach (int i in ObiUtils.BilateralInterleaved(restLengths.Count)) { solverIndices[j * 2] = constraints.Actor.particleIndices[springIndices[i * 2]]; solverIndices[j * 2 + 1] = constraints.Actor.particleIndices[springIndices[i * 2 + 1]]; solverRestLengths[j] = restLengths[i]; solverStiffnesses[j] = stiffnesses[i]; j++; } }
public override void PushDataToSolver(ObiBatchedConstraints constraints) { if (constraints == null || constraints.Actor == null || !constraints.Actor.InSolver) { return; } ObiBendingConstraints bc = (ObiBendingConstraints)constraints; for (int i = 0; i < bendingStiffnesses.Count; i++) { bendingStiffnesses[i] = new Vector2(bc.maxBending, StiffnessToCompliance(bc.stiffness)); } Oni.SetBendingConstraints(batch, solverIndices, restBends.ToArray(), bendingStiffnesses.ToArray(), ConstraintCount); Oni.SetBatchPhaseSizes(batch, phaseSizes.ToArray(), phaseSizes.Count); }
public override void PushDataToSolver(ObiBatchedConstraints constraints) { if (constraints == null || constraints.Actor == null || !constraints.Actor.InSolver) { return; } ObiAerodynamicConstraints dc = (ObiAerodynamicConstraints)constraints; for (int i = 0; i < aerodynamicCoeffs.Count; i += 3) { aerodynamicCoeffs[i + 1] = dc.dragCoefficient * dc.airDensity; aerodynamicCoeffs[i + 2] = dc.liftCoefficient * dc.airDensity; } Oni.SetAerodynamicConstraints(batch, solverIndices, aerodynamicCoeffs.ToArray(), ConstraintCount); }
protected override void OnAddToSolver(ObiBatchedConstraints constraints) { // Set solver constraint data: solverIndices = new int[springIndices.Count]; solverDarboux = new Quaternion[restDarbouxVectors.Count]; solverStiffnesses = new Vector3[stiffnesses.Count]; int j = 0; foreach (int i in ObiUtils.BilateralInterleaved(restDarbouxVectors.Count)) { solverIndices[j * 2] = constraints.Actor.particleIndices[springIndices[i * 2]]; solverIndices[j * 2 + 1] = constraints.Actor.particleIndices[springIndices[i * 2 + 1]]; solverDarboux[j] = restDarbouxVectors[i]; solverStiffnesses[j] = stiffnesses[i]; ++j; } }
public override void PushDataToSolver(ObiBatchedConstraints constraints) { if (constraints == null || constraints.Actor == null || !constraints.Actor.InSolver) { return; } ObiChainConstraints dc = (ObiChainConstraints)constraints; Vector2[] scaledLengths = new Vector2[lengths.Count]; for (int i = 0; i < lengths.Count; i++) { scaledLengths[i] = new Vector2(lengths[i].y * dc.tightness, lengths[i].y); } Oni.SetChainConstraints(batch, solverIndices, scaledLengths, firstParticle.ToArray(), numParticles.ToArray(), ConstraintCount); }
public override void PushDataToSolver(ObiBatchedConstraints constraints) { if (constraints == null || constraints.Actor == null || !constraints.Actor.InSolver) { return; } ObiTetherConstraints tc = (ObiTetherConstraints)constraints; for (int i = 0; i < ConstraintCount; i++) { maxLengthsScales[i] = new Vector2(maxLengthsScales[i].x, tc.tetherScale); stiffnesses[i] = StiffnessToCompliance(tc.stiffness); } Oni.SetTetherConstraints(batch, solverIndices, maxLengthsScales.ToArray(), stiffnesses.ToArray(), ConstraintCount); Oni.SetBatchPhaseSizes(batch, phaseSizes.ToArray(), phaseSizes.Count); }
public override void PushDataToSolver(ObiBatchedConstraints constraints) { if (constraints == null || constraints.Actor == null || !constraints.Actor.InSolver) { return; } ObiBendTwistConstraints dc = (ObiBendTwistConstraints)constraints; for (int i = 0; i < restDarbouxVectors.Count; i++) { solverStiffnesses[i] = new Vector3(StiffnessToCompliance(dc.bendStiffness1), StiffnessToCompliance(dc.bendStiffness2), StiffnessToCompliance(dc.torsionStiffness)); } Oni.SetBendTwistConstraints(batch, solverIndices, solverDarboux, solverStiffnesses, ConstraintCount); }
public override void PullDataFromSolver(ObiBatchedConstraints constraints) { if (constraints == null || constraints.Actor == null || !constraints.Actor.InSolver) { return; } int[] cookedIndices = new int[constraintCount]; Vector4[] cookedPoints = new Vector4[constraintCount]; Vector4[] cookedNormals = new Vector4[constraintCount]; float[] cookedRadiiBackstop = new float[constraintCount * 3]; float[] cookedStiffnesses = new float[constraintCount]; Oni.GetSkinConstraints(batch, cookedIndices, cookedPoints, cookedNormals, cookedRadiiBackstop, cookedStiffnesses); skinPoints = new List <Vector4>(cookedPoints); skinNormals = new List <Vector4>(cookedNormals); // dont retrieve radii and stiffness, since the solver never modifies them. }
public override void PullDataFromSolver(ObiBatchedConstraints constraints) { if (constraints == null || constraints.Actor == null || !constraints.Actor.InSolver) { return; } int[] cookedIndices = new int[constraintCount]; Vector4[] cookedPoints = new Vector4[constraintCount]; Vector4[] cookedNormals = new Vector4[constraintCount]; float[] cookedRadiiBackstop = new float[constraintCount * 3]; float[] cookedStiffnesses = new float[constraintCount]; Oni.GetSkinConstraints(batch, cookedIndices, cookedPoints, cookedNormals, cookedRadiiBackstop, cookedStiffnesses); skinPoints = new List <Vector4>(cookedPoints); skinNormals = new List <Vector4>(cookedNormals); skinRadiiBackstop = new List <float>(cookedRadiiBackstop); skinStiffnesses = new List <float>(cookedStiffnesses); }
public override void PushDataToSolver(ObiBatchedConstraints constraints) { if (constraints == null || constraints.Actor == null || !constraints.Actor.InSolver) { return; } ObiDistanceConstraints dc = (ObiDistanceConstraints)constraints; float[] scaledRestLengths = new float[restLengths.Count]; for (int i = 0; i < restLengths.Count; i++) { scaledRestLengths[i] = restLengths[i] * dc.stretchingScale; stiffnesses[i] = new Vector2(StiffnessToCompliance(dc.stiffness), dc.slack * scaledRestLengths[i]); } Oni.SetDistanceConstraints(batch, solverIndices, scaledRestLengths, stiffnesses.ToArray(), ConstraintCount); Oni.SetBatchPhaseSizes(batch, phaseSizes.ToArray(), phaseSizes.Count); }
public override void PushDataToSolver(ObiBatchedConstraints constraints) { if (constraints == null || constraints.Actor == null || !constraints.Actor.InSolver) { return; } ObiStretchShearConstraints dc = (ObiStretchShearConstraints)constraints; int[] orientationIndices = new int[restLengths.Count]; for (int i = 0; i < restLengths.Count; i++) { solverStiffnesses[i] = new Vector3(StiffnessToCompliance(dc.shearStiffness1), StiffnessToCompliance(dc.shearStiffness2), StiffnessToCompliance(dc.stretchStiffness)); orientationIndices[i] = solverIndices[i * 2]; } Oni.SetStretchShearConstraints(batch, solverIndices, orientationIndices, solverRestLengths, solverRestOrientations, solverStiffnesses, ConstraintCount); }
public override void PushDataToSolver(ObiBatchedConstraints constraints) { if (constraints == null || constraints.Actor == null || !constraints.Actor.InSolver) { return; } ObiVolumeConstraints vc = (ObiVolumeConstraints)constraints; for (int i = 0; i < pressureStiffness.Count; i++) { pressureStiffness[i] = new Vector2(vc.overpressure, StiffnessToCompliance(vc.stiffness)); } Oni.SetVolumeConstraints(batch, solverIndices, firstTriangle.ToArray(), numTriangles.ToArray(), restVolumes.ToArray(), pressureStiffness.ToArray(), ConstraintCount); }
public override void PushDataToSolver(ObiBatchedConstraints constraints) { if (constraints == null || constraints.Actor == null || !constraints.Actor.InSolver) { return; } //ObiShapeMatchingConstraints sc = (ObiShapeMatchingConstraints) constraints; for (int i = 0; i < shapeStiffness.Count; i++) { shapeStiffness[i] = 1; //StiffnessToCompliance(sc.stiffness); } Oni.SetShapeMatchingConstraints(batch, solverIndices, firstIndex.ToArray(), numIndices.ToArray(), shapeStiffness.ToArray(), ConstraintCount); Oni.CalculateRestShapeMatching(constraints.Actor.Solver.OniSolver, batch); }
public override void PushDataToSolver(ObiBatchedConstraints constraints) { if (constraints == null || constraints.Actor == null || !constraints.Actor.InSolver) { return; } ObiSkinConstraints sc = (ObiSkinConstraints)constraints; float[] stiffnesses = new float[skinStiffnesses.Count]; for (int i = 0; i < stiffnesses.Length; i++) { stiffnesses[i] = StiffnessToCompliance(skinStiffnesses[i] * sc.stiffness); } Oni.SetSkinConstraints(batch, solverIndices, skinPoints.ToArray(), skinNormals.ToArray(), skinRadiiBackstop.ToArray(), stiffnesses, ConstraintCount); Oni.SetBatchPhaseSizes(batch, phaseSizes.ToArray(), phaseSizes.Count); }
// Implement these methods to push/pull constraint data to/from the solver. public abstract void PushDataToSolver(ObiBatchedConstraints constraints);
public abstract void PullDataFromSolver(ObiBatchedConstraints constraints);
protected override void OnRemoveFromSolver(ObiBatchedConstraints constraints) { }
// Implement these methods to perform custom actions when adding/removing the batch from the solver. protected abstract void OnAddToSolver(ObiBatchedConstraints constraints);
public override void PullDataFromSolver(ObiBatchedConstraints constraints) { }
protected abstract void OnRemoveFromSolver(ObiBatchedConstraints constraints);