initial upload
This commit is contained in:
@ -0,0 +1,317 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
namespace RootMotion.FinalIK {
|
||||
|
||||
/// <summary>
|
||||
/// %IK system for standard biped characters that is designed to replicate and enhance the behaviour of the Unity's built-in character %IK setup.
|
||||
/// </summary>
|
||||
[HelpURL("http://www.root-motion.com/finalikdox/html/page4.html")]
|
||||
[AddComponentMenu("Scripts/RootMotion.FinalIK/IK/Biped IK")]
|
||||
public class BipedIK : SolverManager {
|
||||
|
||||
// Open the User Manual URL
|
||||
[ContextMenu("User Manual")]
|
||||
private void OpenUserManual() {
|
||||
Application.OpenURL("http://www.root-motion.com/finalikdox/html/page4.html");
|
||||
}
|
||||
|
||||
// Open the Script Reference URL
|
||||
[ContextMenu("Scrpt Reference")]
|
||||
private void OpenScriptReference() {
|
||||
Application.OpenURL("http://www.root-motion.com/finalikdox/html/class_root_motion_1_1_final_i_k_1_1_biped_i_k.html");
|
||||
}
|
||||
|
||||
// Link to the Final IK Google Group
|
||||
[ContextMenu("Support Group")]
|
||||
void SupportGroup() {
|
||||
Application.OpenURL("https://groups.google.com/forum/#!forum/final-ik");
|
||||
}
|
||||
|
||||
// Link to the Final IK Asset Store thread in the Unity Community
|
||||
[ContextMenu("Asset Store Thread")]
|
||||
void ASThread() {
|
||||
Application.OpenURL("http://forum.unity3d.com/threads/final-ik-full-body-ik-aim-look-at-fabrik-ccd-ik-1-0-released.222685/");
|
||||
}
|
||||
|
||||
#region Main Interface
|
||||
|
||||
/// <summary>
|
||||
/// References to character bones.
|
||||
/// </summary>
|
||||
public BipedReferences references = new BipedReferences();
|
||||
/// <summary>
|
||||
/// The %IK solvers.
|
||||
/// </summary>
|
||||
public BipedIKSolvers solvers = new BipedIKSolvers();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the %IK position weight.
|
||||
/// </summary>
|
||||
/// <param name='goal'>
|
||||
/// %IK Goal.
|
||||
/// </param>
|
||||
public float GetIKPositionWeight(AvatarIKGoal goal) {
|
||||
return GetGoalIK(goal).GetIKPositionWeight();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the %IK rotation weight.
|
||||
/// </summary>
|
||||
/// <param name='goal'>
|
||||
/// IK Goal.
|
||||
/// </param>
|
||||
public float GetIKRotationWeight(AvatarIKGoal goal) {
|
||||
return GetGoalIK(goal).GetIKRotationWeight();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the %IK position weight.
|
||||
/// </summary>
|
||||
/// <param name='goal'>
|
||||
/// %IK Goal.
|
||||
/// </param>
|
||||
/// <param name='weight'>
|
||||
/// Weight.
|
||||
/// </param>
|
||||
public void SetIKPositionWeight(AvatarIKGoal goal, float weight) {
|
||||
GetGoalIK(goal).SetIKPositionWeight(weight);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the %IK rotation weight.
|
||||
/// </summary>
|
||||
/// <param name='goal'>
|
||||
/// %IK Goal.
|
||||
/// </param>
|
||||
/// <param name='weight'>
|
||||
/// Weight.
|
||||
/// </param>
|
||||
public void SetIKRotationWeight(AvatarIKGoal goal, float weight) {
|
||||
GetGoalIK(goal).SetIKRotationWeight(weight);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the %IK position.
|
||||
/// </summary>
|
||||
/// <param name='goal'>
|
||||
/// %IK Goal.
|
||||
/// </param>
|
||||
/// <param name='IKPosition'>
|
||||
/// Position.
|
||||
/// </param>
|
||||
public void SetIKPosition(AvatarIKGoal goal, Vector3 IKPosition) {
|
||||
GetGoalIK(goal).SetIKPosition(IKPosition);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the %IK rotation.
|
||||
/// </summary>
|
||||
/// <param name='goal'>
|
||||
/// %IK Goal.
|
||||
/// </param>
|
||||
/// <param name='IKRotation'>
|
||||
/// Rotation.
|
||||
/// </param>
|
||||
public void SetIKRotation(AvatarIKGoal goal, Quaternion IKRotation) {
|
||||
GetGoalIK(goal).SetIKRotation(IKRotation);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the %IK position.
|
||||
/// </summary>
|
||||
/// <param name='goal'>
|
||||
/// %IK Goal.
|
||||
/// </param>
|
||||
public Vector3 GetIKPosition(AvatarIKGoal goal) {
|
||||
return GetGoalIK(goal).GetIKPosition();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the %IK rotation.
|
||||
/// </summary>
|
||||
/// <param name='goal'>
|
||||
/// %IK Goal.
|
||||
/// </param>
|
||||
public Quaternion GetIKRotation(AvatarIKGoal goal) {
|
||||
return GetGoalIK(goal).GetIKRotation();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the look at weight.
|
||||
/// </summary>
|
||||
/// <param name='weight'>
|
||||
/// Master Weight.
|
||||
/// </param>
|
||||
/// <param name='bodyWeight'>
|
||||
/// Body weight.
|
||||
/// </param>
|
||||
/// <param name='headWeight'>
|
||||
/// Head weight.
|
||||
/// </param>
|
||||
/// <param name='eyesWeight'>
|
||||
/// Eyes weight.
|
||||
/// </param>
|
||||
/// <param name='clampWeight'>
|
||||
/// Clamp weight for body and head.
|
||||
/// </param>
|
||||
/// <param name='clampWeightEyes'>
|
||||
/// Clamp weight for eyes.
|
||||
/// </param>
|
||||
public void SetLookAtWeight(float weight, float bodyWeight , float headWeight, float eyesWeight, float clampWeight, float clampWeightHead, float clampWeightEyes) {
|
||||
solvers.lookAt.SetLookAtWeight(weight, bodyWeight, headWeight, eyesWeight, clampWeight, clampWeightHead, clampWeightEyes);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the look at target.
|
||||
/// </summary>
|
||||
/// <param name='lookAtPosition'>
|
||||
/// Look at position.
|
||||
/// </param>
|
||||
public void SetLookAtPosition(Vector3 lookAtPosition) {
|
||||
solvers.lookAt.SetIKPosition(lookAtPosition);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the spine %IK position.
|
||||
/// </summary>
|
||||
/// <param name='spinePosition'>
|
||||
/// Spine %IK position.
|
||||
/// </param>
|
||||
public void SetSpinePosition(Vector3 spinePosition) {
|
||||
solvers.spine.SetIKPosition(spinePosition);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the spine weight.
|
||||
/// </summary>
|
||||
/// <param name='weight'>
|
||||
/// Weight.
|
||||
/// </param>
|
||||
public void SetSpineWeight(float weight) {
|
||||
solvers.spine.SetIKPositionWeight(weight);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the limb solver for the %IK Goal.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// The solver.
|
||||
/// </returns>
|
||||
/// <param name='goal'>
|
||||
/// %IK Goal.
|
||||
/// </param>
|
||||
public IKSolverLimb GetGoalIK(AvatarIKGoal goal) {
|
||||
switch(goal) {
|
||||
case AvatarIKGoal.LeftFoot: return solvers.leftFoot;
|
||||
case AvatarIKGoal.RightFoot: return solvers.rightFoot;
|
||||
case AvatarIKGoal.LeftHand: return solvers.leftHand;
|
||||
case AvatarIKGoal.RightHand: return solvers.rightHand;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// (Re)Initiates the biped IK solvers.
|
||||
/// </summary>
|
||||
public void InitiateBipedIK() {
|
||||
InitiateSolver();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updating BipedIK
|
||||
/// </summary>
|
||||
public void UpdateBipedIK() {
|
||||
UpdateSolver();
|
||||
}
|
||||
|
||||
/*
|
||||
* Set default solver values.
|
||||
* */
|
||||
public void SetToDefaults() {
|
||||
// Limbs
|
||||
foreach (IKSolverLimb limb in solvers.limbs) {
|
||||
limb.SetIKPositionWeight(0f);
|
||||
limb.SetIKRotationWeight(0f);
|
||||
limb.bendModifier = IKSolverLimb.BendModifier.Animation;
|
||||
limb.bendModifierWeight = 1f;
|
||||
}
|
||||
|
||||
solvers.leftHand.maintainRotationWeight = 0f;
|
||||
solvers.rightHand.maintainRotationWeight = 0f;
|
||||
|
||||
// Spine
|
||||
solvers.spine.SetIKPositionWeight(0f);
|
||||
solvers.spine.tolerance = 0f;
|
||||
solvers.spine.maxIterations = 2;
|
||||
solvers.spine.useRotationLimits = false;
|
||||
|
||||
// Aim
|
||||
solvers.aim.SetIKPositionWeight(0f);
|
||||
solvers.aim.tolerance = 0f;
|
||||
solvers.aim.maxIterations = 2;
|
||||
|
||||
// LookAt
|
||||
SetLookAtWeight(0f, 0.5f, 1f, 1f, 0.5f, 0.7f, 0.5f);
|
||||
}
|
||||
|
||||
#endregion Main Interface
|
||||
|
||||
/*
|
||||
* Fixes all the Transforms used by the solver to their default local states.
|
||||
* */
|
||||
protected override void FixTransforms() {
|
||||
solvers.pelvis.FixTransforms();
|
||||
solvers.lookAt.FixTransforms();
|
||||
for (int i = 0; i < solvers.limbs.Length; i++) solvers.limbs[i].FixTransforms();
|
||||
}
|
||||
|
||||
/*
|
||||
* Initiates the %IK solver
|
||||
* */
|
||||
protected override void InitiateSolver() {
|
||||
string message = "";
|
||||
if (BipedReferences.SetupError(references, ref message)) {
|
||||
Warning.Log(message, references.root, false);
|
||||
return;
|
||||
}
|
||||
solvers.AssignReferences(references);
|
||||
|
||||
// Initiating solvers
|
||||
if (solvers.spine.bones.Length > 1) solvers.spine.Initiate(transform);
|
||||
solvers.lookAt.Initiate(transform);
|
||||
solvers.aim.Initiate(transform);
|
||||
foreach (IKSolverLimb limb in solvers.limbs) limb.Initiate(transform);
|
||||
|
||||
// Initiating constraints
|
||||
solvers.pelvis.Initiate(references.pelvis);
|
||||
}
|
||||
|
||||
/*
|
||||
* Updates the solvers. If you need full control of the execution order of your IK solvers, disable this script and call UpdateSolver() instead.
|
||||
* */
|
||||
protected override void UpdateSolver() {
|
||||
// Storing Limb bend and rotation before %IK
|
||||
for (int i = 0; i < solvers.limbs.Length; i++) {
|
||||
solvers.limbs[i].MaintainBend();
|
||||
solvers.limbs[i].MaintainRotation();
|
||||
}
|
||||
|
||||
// Updating constraints
|
||||
solvers.pelvis.Update();
|
||||
|
||||
// Updating %IK solvers
|
||||
if (solvers.spine.bones.Length > 1) solvers.spine.Update();
|
||||
solvers.aim.Update();
|
||||
solvers.lookAt.Update();
|
||||
for (int i = 0; i < solvers.limbs.Length; i++) solvers.limbs[i].Update();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Logs the warning if no other warning has beed logged in this session.
|
||||
/// </summary>
|
||||
public void LogWarning(string message) {
|
||||
Warning.Log(message, transform);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6d406d8b892f54ccaa5b0ef4de59944a
|
||||
labels:
|
||||
- InverseKinematics
|
||||
- IK
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 9998
|
||||
icon: {fileID: 2800000, guid: 2631a18e2dd7844718dea7db8ecf6c03, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,89 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System;
|
||||
|
||||
namespace RootMotion.FinalIK {
|
||||
|
||||
/// <summary>
|
||||
/// BipedIK solver collection.
|
||||
/// </summary>
|
||||
[System.Serializable]
|
||||
public class BipedIKSolvers {
|
||||
/// <summary>
|
||||
/// The left foot
|
||||
/// </summary>
|
||||
public IKSolverLimb leftFoot = new IKSolverLimb(AvatarIKGoal.LeftFoot);
|
||||
/// <summary>
|
||||
/// The right foot.
|
||||
/// </summary>
|
||||
public IKSolverLimb rightFoot = new IKSolverLimb(AvatarIKGoal.RightFoot);
|
||||
/// <summary>
|
||||
/// The left hand.
|
||||
/// </summary>
|
||||
public IKSolverLimb leftHand = new IKSolverLimb(AvatarIKGoal.LeftHand);
|
||||
/// <summary>
|
||||
/// The right hand.
|
||||
/// </summary>
|
||||
public IKSolverLimb rightHand = new IKSolverLimb(AvatarIKGoal.RightHand);
|
||||
/// <summary>
|
||||
/// The spine.
|
||||
/// </summary>
|
||||
public IKSolverFABRIK spine = new IKSolverFABRIK();
|
||||
/// <summary>
|
||||
/// The Look At %IK.
|
||||
/// </summary>
|
||||
public IKSolverLookAt lookAt = new IKSolverLookAt();
|
||||
/// <summary>
|
||||
/// The Aim %IK. Rotates the spine to aim a transform's forward towards the target.
|
||||
/// </summary>
|
||||
public IKSolverAim aim = new IKSolverAim();
|
||||
/// <summary>
|
||||
/// %Constraints for manipulating the character's pelvis.
|
||||
/// </summary>
|
||||
public Constraints pelvis = new Constraints();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the array containing all the limbs.
|
||||
/// </summary>
|
||||
public IKSolverLimb[] limbs {
|
||||
get {
|
||||
if (_limbs == null || (_limbs != null && _limbs.Length != 4)) _limbs = new IKSolverLimb[4] { leftFoot, rightFoot, leftHand, rightHand };
|
||||
return _limbs;
|
||||
}
|
||||
}
|
||||
private IKSolverLimb[] _limbs;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the array containing all %IK solvers.
|
||||
/// </summary>
|
||||
public IKSolver[] ikSolvers {
|
||||
get {
|
||||
if (_ikSolvers == null || (_ikSolvers != null && _ikSolvers.Length != 7)) _ikSolvers = new IKSolver[7] { leftFoot, rightFoot, leftHand, rightHand, spine, lookAt, aim };
|
||||
return _ikSolvers;
|
||||
}
|
||||
}
|
||||
private IKSolver[] _ikSolvers;
|
||||
|
||||
public void AssignReferences(BipedReferences references) {
|
||||
// Assigning limbs from references
|
||||
leftHand.SetChain(references.leftUpperArm, references.leftForearm, references.leftHand, references.root);
|
||||
rightHand.SetChain(references.rightUpperArm, references.rightForearm, references.rightHand, references.root);
|
||||
leftFoot.SetChain(references.leftThigh, references.leftCalf, references.leftFoot, references.root);
|
||||
rightFoot.SetChain(references.rightThigh, references.rightCalf, references.rightFoot, references.root);
|
||||
|
||||
// Assigning spine bones from references
|
||||
spine.SetChain(references.spine, references.root);
|
||||
|
||||
// Assigning lookAt bones from references
|
||||
lookAt.SetChain(references.spine, references.head, references.eyes, references.root);
|
||||
|
||||
// Assigning Aim bones from references
|
||||
aim.SetChain(references.spine, references.root);
|
||||
|
||||
leftFoot.goal = AvatarIKGoal.LeftFoot;
|
||||
rightFoot.goal = AvatarIKGoal.RightFoot;
|
||||
leftHand.goal = AvatarIKGoal.LeftHand;
|
||||
rightHand.goal = AvatarIKGoal.RightHand;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 552b6be99351d42019784667c84a7d5a
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user