public static SolveJoint ( Vector3 pos1, Vector3 pos2, float length ) : Vector3 | ||
pos1 | Vector3 | |
pos2 | Vector3 | |
length | float | |
Результат | Vector3 |
public void Stage1(FBIKChain[] chain) { for (int i = 0; i < this.children.Length; i++) { chain[this.children[i]].Stage1(chain); } if (this.children.Length == 0) { this.ForwardReach(this.nodes[this.nodes.Length - 1].solverPosition); return; } Vector3 a = this.nodes[this.nodes.Length - 1].solverPosition; this.SolveChildConstraints(); for (int j = 0; j < this.children.Length; j++) { Vector3 a2 = chain[this.children[j]].nodes[0].solverPosition; if (chain[this.children[j]].rootLength > 0f) { a2 = IKSolverFABRIK.SolveJoint(this.nodes[this.nodes.Length - 1].solverPosition, chain[this.children[j]].nodes[0].solverPosition, chain[this.children[j]].rootLength); } if (this.pullParentSum > 0f) { a += (a2 - this.nodes[this.nodes.Length - 1].solverPosition) * (chain[this.children[j]].pull / this.pullParentSum); } } this.ForwardReach(Vector3.Lerp(a, this.nodes[this.nodes.Length - 1].solverPosition, this.pin)); }
private void BackwardReach(Vector3 position) { this.spine[0].ikPosition = position; for (int i = 1; i < this.spine.Length; i++) { this.spine[i].ikPosition = IKSolverFABRIK.SolveJoint(this.spine[i].ikPosition, this.spine[i - 1].ikPosition, this.spine[i - 1].length); } }
public void ForwardReach(Vector3 position) { this.spine[this.spineBones.Length - 1].ikPosition = position; for (int i = this.spine.Length - 2; i > -1; i--) { this.spine[i].ikPosition = IKSolverFABRIK.SolveJoint(this.spine[i].ikPosition, this.spine[i + 1].ikPosition, this.spine[i].length); } }
private void BackwardReachUnlimited(Vector3 position) { this.bones[0].solverPosition = position; for (int i = 1; i < this.bones.Length; i++) { this.bones[i].solverPosition = IKSolverFABRIK.SolveJoint(this.bones[i].solverPosition, this.bones[i - 1].solverPosition, this.bones[i - 1].length); } }
public void ForwardReach(Vector3 position) { this.nodes[this.nodes.Length - 1].solverPosition = position; for (int i = this.nodes.Length - 2; i > -1; i--) { this.nodes[i].solverPosition = IKSolverFABRIK.SolveJoint(this.nodes[i].solverPosition, this.nodes[i + 1].solverPosition, this.nodes[i].length); } }
/* * Stage 2 of the FABRIK algorithm * */ private void BackwardReach(Vector3 position) { spine[0].ikPosition = position; // Finding joint positions for (int i = 1; i < spine.Length; i++) { spine[i].ikPosition = IKSolverFABRIK.SolveJoint(spine[i].ikPosition, spine[i - 1].ikPosition, spine[i - 1].length); } }
/* * FABRIK Forward reach * */ public void ForwardReach(Vector3 position) { // Lerp last node's solverPosition to position nodes[nodes.Length - 1].solverPosition = position; for (int i = nodes.Length - 2; i > -1; i--) { // Finding joint positions nodes[i].solverPosition = IKSolverFABRIK.SolveJoint(nodes[i].solverPosition, nodes[i + 1].solverPosition, nodes[i].length); } }
/* * Stage 1 of the FABRIK algorithm. * */ public void ForwardReach(Vector3 position) { // Lerp last bone's ikPosition to position spine[spineBones.Length - 1].ikPosition = position; for (int i = spine.Length - 2; i > -1; i--) { // Finding joint positions spine[i].ikPosition = IKSolverFABRIK.SolveJoint(spine[i].ikPosition, spine[i + 1].ikPosition, spine[i].length); } }
private void BackwardReach(Vector3 position) { if (this.rootLength > 0f) { position = IKSolverFABRIK.SolveJoint(this.nodes[0].solverPosition, position, this.rootLength); } this.nodes[0].solverPosition = position; for (int i = 1; i < this.nodes.Length; i++) { this.nodes[i].solverPosition = IKSolverFABRIK.SolveJoint(this.nodes[i].solverPosition, this.nodes[i - 1].solverPosition, this.nodes[i - 1].length); } }
private void ForwardReach(Vector3 position) { this.bones[this.bones.Length - 1].solverPosition = Vector3.Lerp(this.bones[this.bones.Length - 1].solverPosition, position, this.IKPositionWeight); for (int i = 0; i < this.limitedBones.Length; i++) { this.limitedBones[i] = false; } for (int j = this.bones.Length - 2; j > -1; j--) { this.bones[j].solverPosition = IKSolverFABRIK.SolveJoint(this.bones[j].solverPosition, this.bones[j + 1].solverPosition, this.bones[j].length); this.LimitForward(j, j + 1); } this.LimitForward(0, 0); }
/* * FABRIK Backward reach * */ private void BackwardReach(Vector3 position) { // Solve forst node only if it already hasn't been solved in SolveConstraintSystems if (rootLength > 0) { position = IKSolverFABRIK.SolveJoint(nodes[0].solverPosition, position, rootLength); } nodes[0].solverPosition = position; // Finding joint positions for (int i = 1; i < nodes.Length; i++) { nodes[i].solverPosition = IKSolverFABRIK.SolveJoint(nodes[i].solverPosition, nodes[i - 1].solverPosition, nodes[i - 1].length); } }
/* * Stage 1 of the FABRIK algorithm * */ public void Stage1(FBIKChain[] chain) { // Stage 1 for (int i = 0; i < children.Length; i++) { chain[children[i]].Stage1(chain); } // If is the last chain in this hierarchy, solve immediatelly and return if (children.Length == 0) { ForwardReach(nodes[nodes.Length - 1].solverPosition); return; } // Finding the total pull force by all child chains float pullParentSum = 0f; for (int i = 0; i < children.Length; i++) { pullParentSum += chain[children[i]].pull; } Vector3 centroid = nodes[nodes.Length - 1].solverPosition; // Satisfying child constraints SolveChildConstraints(); // Finding the centroid position of all child chains according to their individual pull weights for (int i = 0; i < children.Length; i++) { Vector3 childPosition = chain[children[i]].nodes[0].solverPosition; if (chain[children[i]].rootLength > 0) { childPosition = IKSolverFABRIK.SolveJoint(nodes[nodes.Length - 1].solverPosition, chain[children[i]].nodes[0].solverPosition, chain[children[i]].rootLength); } if (pullParentSum > 0) { centroid += (childPosition - nodes[nodes.Length - 1].solverPosition) * (chain[children[i]].pull / Mathf.Clamp(pullParentSum, 1f, Mathf.Infinity)); } } // Forward reach to the centroid (unless pinned) ForwardReach(Vector3.Lerp(centroid, nodes[nodes.Length - 1].solverPosition, pin)); }
private void BackwardReachLimited(Vector3 position) { this.bones[0].solverPosition = position; for (int i = 0; i < this.bones.Length - 1; i++) { Vector3 a = IKSolverFABRIK.SolveJoint(this.bones[i + 1].solverPosition, this.bones[i].solverPosition, this.bones[i].length); Quaternion lhs = Quaternion.FromToRotation(this.bones[i].solverRotation * this.bones[i].axis, a - this.bones[i].solverPosition); Quaternion quaternion = lhs * this.bones[i].solverRotation; if (this.bones[i].rotationLimit != null) { bool flag = false; quaternion = this.GetLimitedRotation(i, quaternion, out flag); } Quaternion rotation = QuaTools.FromToRotation(this.bones[i].solverRotation, quaternion); this.bones[i].solverRotation = quaternion; this.SolverRotateChildren(i, rotation); this.bones[i + 1].solverPosition = this.bones[i].solverPosition + this.bones[i].solverRotation * this.solverLocalPositions[i + 1]; } for (int j = 0; j < this.bones.Length; j++) { this.bones[j].solverRotation = Quaternion.LookRotation(this.bones[j].solverRotation * Vector3.forward, this.bones[j].solverRotation * Vector3.up); } }