public override void UpdateTracking() { if (_animator.runtimeAnimatorController == null) { for (IKBone ikBone = 0; ikBone < IKBone.LastBone; ikBone++) { GetIKSolver(ikBone).ResetIKChain(); } } QuickIKSolver ikSolverHips = GetIKSolver(IKBone.Hips); QuickIKSolver ikSolverHead = GetIKSolver(IKBone.Head); //float chainLength = Vector3.Distance(_animator.GetBoneTransform(HumanBodyBones.Hips).position, _animator.GetBoneTransform(HumanBodyBones.Head).position); //Vector3 v = (ikSolverHips._targetLimb.position - ikSolverHead._targetLimb.position).normalized; //ikSolverHips._targetLimb.position = ikSolverHead._targetLimb.position + v * chainLength; //Update the IK for the body controllers ikSolverHips.UpdateIK(); ikSolverHead.UpdateIK(); GetIKSolver(IKBone.LeftHand).UpdateIK(); GetIKSolver(IKBone.RightHand).UpdateIK(); GetIKSolver(IKBone.LeftFoot).UpdateIK(); GetIKSolver(IKBone.RightFoot).UpdateIK(); //Update the IK for the fingers controllers UpdateIKFingers(); //Update the IK for the face controllers for (IKBone ikBone = IKBone.LeftEye; ikBone <= IKBone.RightEye; ikBone++) { GetIKSolver(ikBone).UpdateIK(); } }
public IKBone addBone(string name, float length, float width, float thickness) { IKBone newbone = IKBone.createBone(name, length, width, thickness, this.parentSkeleton); newbone.connectTo(this); return(newbone); }
public virtual void LoadPose() { for (IKBone ikBone = 0; ikBone < IKBone.LastBone; ikBone++) { GetIKSolver(ikBone).LoadPose(); } }
protected virtual QuickIKSolver CreateIKSolver(IKBone ikBone) { QuickIKSolver result; if (ikBone == IKBone.Hips) { result = CreateIKSolver <QuickIKSolverHips>(ikBone); } else if (ikBone == IKBone.Head) { result = CreateIKSolver <QuickIKSolverHead>(ikBone); } else if (ikBone == IKBone.LeftHand || ikBone == IKBone.RightHand) { result = CreateIKSolver <QuickIKSolverHand>(ikBone); } else if (ikBone == IKBone.LeftEye || ikBone == IKBone.RightEye) { result = CreateIKSolver <QuickIKSolverEye>(ikBone); } else { result = CreateIKSolver <QuickIKSolver>(ikBone); } return(result); }
// Spine Initialization public void CreateSpine() { spineCount = boneTransforms.Length; if (spineCount == 0) { Debug.LogError("IKBehavior has no bones. Coward."); this.enabled = false; return; } spine = new IKBone[spineCount]; for (int i = 0; i < spineCount; i++) { spine[i] = new IKBone(boneTransforms[i]); } for (int j = 0; j < spineCount - 1; j++) { spine[j].child = spine[j + 1]; } CalculateBoneLengths(); }
private void Start() { addTwoBoneIK(); if (false) { int arms = Random.Range(2, 6); for (int j = 0; j < arms; j++) { int joints = Random.Range(2, 6); int fork = Random.Range(1, joints - 1); for (int i = 0; i < joints; i++) { DEBUG_newestBone = DEBUG_newestBone.addBone("bone_" + "_" + j + "." + i, Random.Range(0.2f, 0.8f), Random.Range(0.1f, 0.3f), Random.Range(0.1f, 0.3f)); //IKBone[] bones = this.gameObject.GetComponentsInChildren<IKBone>(); //int r = Random.Range(0, bones.Length - 1); //newestBone = bones[r]; } for (int b = 0; b < fork; b++) { DEBUG_newestBone = DEBUG_newestBone.parentBone; } } } }
/* * public void addChain(string name, IKBone fork) * { * chains.Add(new IKChain(name, fork,this)); * Transform parent = fork.gameObject.transform.parent; * while(parent != null) * { * parent. * } * * } */ // Use this for initialization void Awake() { initSkeleton(); initRootBone(); DEBUG_newestBone = rootBone; }
protected void initRootBone() { this.rootBone = IKBone.createBone("Root", 0.0f, 0.0f, 0.0f, this); rootBone.transform.parent = this.gameObject.transform; rootBone.transform.localRotation = Quaternion.identity; rootBone.transform.localPosition = new Vector3(0.0f, stature.hipHeight, 0.0f); }
//constant time (e.g. Physics) void FixedUpdate() { if (DEBUG_trigger) { DEBUG_newestBone = DEBUG_newestBone.addBone("newBone", Random.Range(0.2f, 0.6f), Random.Range(0.1f, 0.3f), Random.Range(0.1f, 0.3f)); DEBUG_trigger = false; } }
protected override void DrawIKSolverProperties(IKBone ikBone) { _target.SetIKControl(ikBone, (QuickUnityVR.ControlType)EditorGUILayout.EnumPopup(ikBone.ToString(), _target.GetIKControl(ikBone))); if (_target.GetIKControl(ikBone) != QuickUnityVR.ControlType.Animation) { DrawIKSolverPropertiesBase(_target.GetIKSolver(ikBone)); } }
public virtual void UpdateIKTargets() { if (Application.isPlaying) { //1) Update all the IKTargets taking into consideration its ControlType. for (IKBone ikBone = IKBone.Hips; ikBone < IKBone.LastBone; ikBone++) { ControlType cType = GetIKControl(ikBone); HumanBodyBones boneID = ToHumanBodyBones(ikBone); GetIKSolver(ikBone)._enableIK = cType != ControlType.Animation; if (cType == ControlType.Tracking) { QuickVRNode node = _vrPlayArea.GetVRNode(boneID); if (node.IsTracked()) { //Update the QuickVRNode's position UpdateIKTargetPosFromUser(node, boneID); //Update the QuickVRNode's rotation UpdateIKTargetRotFromUser(node, boneID); if (boneID == HumanBodyBones.Head) { QuickIKSolver ikSolverHead = GetIKSolver(IKBone.Head); if (!_applyHeadPosition) { ikSolverHead._weightIKPos = 0; } if (!_applyHeadRotation) { ikSolverHead._weightIKRot = 0; } } else if (boneID == HumanBodyBones.LeftEye || boneID == HumanBodyBones.RightEye) { QuickIKSolverEye ikSolver = (QuickIKSolverEye)_animator.GetComponent <QuickIKManager>().GetIKSolver(boneID); ikSolver._weightBlink = ((QuickVRNodeEye)node).GetBlinkFactor(); } } } } //2) Special case. If the Hips is set to Tracking mode, we need to adjust the IKTarget position of the hips //in a way that the head will match the position of the camera provided by the HMD if (GetIKControl(IKBone.Hips) == ControlType.Tracking) { QuickIKSolver ikSolverHips = GetIKSolver(IKBone.Hips); QuickIKSolver ikSolverHead = GetIKSolver(IKBone.Head); float chainLength = Vector3.Distance(_animator.GetBoneTransform(HumanBodyBones.Hips).position, _animator.GetBoneTransform(HumanBodyBones.Head).position); Vector3 v = (ikSolverHips._targetLimb.position - ikSolverHead._targetLimb.position).normalized; ikSolverHips._targetLimb.position = ikSolverHead._targetLimb.position + v * chainLength; } UpdateVRCursors(); _footprints.gameObject.SetActive(_useFootprints); } }
public static IKTarget createTarget(string name, IKBone targetRoot) { GameObject go = new GameObject(name); IKTarget newTarget = go.AddComponent <IKTarget>(); newTarget.transform.parent = targetRoot.transform; newTarget.targetRoot = targetRoot; return(newTarget); }
protected virtual void DrawIKControls() { _ikManager._showControlsBody = FoldoutBolt(_ikManager._showControlsBody, "Body Controls"); if (_ikManager._showControlsBody) { EditorGUI.indentLevel++; for (IKBone ikBone = IKBone.Hips; ikBone <= IKBone.RightFoot; ikBone++) { EditorGUILayout.BeginVertical("box"); DrawIKSolverProperties(ikBone); EditorGUILayout.EndVertical(); } EditorGUI.indentLevel--; } _ikManager._showControlsFingersLeftHand = FoldoutBolt(_ikManager._showControlsFingersLeftHand, "Left Hand Fingers Controls"); if (_ikManager._showControlsFingersLeftHand) { EditorGUI.indentLevel++; for (IKBone ikBone = IKBone.LeftThumbDistal; ikBone <= IKBone.LeftLittleDistal; ikBone++) { EditorGUILayout.BeginVertical("box"); DrawIKSolverProperties(ikBone); EditorGUILayout.EndVertical(); } EditorGUI.indentLevel--; } _ikManager._showControlsFingersRightHand = FoldoutBolt(_ikManager._showControlsFingersRightHand, "Right Hand Fingers Controls"); if (_ikManager._showControlsFingersRightHand) { EditorGUI.indentLevel++; for (IKBone ikBone = IKBone.RightThumbDistal; ikBone <= IKBone.RightLittleDistal; ikBone++) { EditorGUILayout.BeginVertical("box"); DrawIKSolverProperties(ikBone); EditorGUILayout.EndVertical(); } EditorGUI.indentLevel--; } _ikManager._showControlsFace = FoldoutBolt(_ikManager._showControlsFace, "Face Controls"); if (_ikManager._showControlsFace) { EditorGUI.indentLevel++; for (IKBone ikBone = IKBone.LeftEye; ikBone <= IKBone.RightEye; ikBone++) { EditorGUILayout.BeginVertical("box"); DrawIKSolverProperties(ikBone); EditorGUILayout.EndVertical(); } EditorGUI.indentLevel--; } DrawPoseButtons(); }
public static IKBone ToIKBone(HumanBodyBones boneID) { if (_toIKBone.Count == 0) { for (IKBone b = 0; b < IKBone.LastBone; b++) { _toIKBone[QuickUtils.ParseEnum <HumanBodyBones>(b.ToString())] = b; } } return(_toIKBone[boneID]); }
public static HumanBodyBones ToHumanBodyBones(IKBone ikBone) { if (_toHumanBodyBones.Count == 0) { for (IKBone b = 0; b < IKBone.LastBone; b++) { _toHumanBodyBones.Add(QuickUtils.ParseEnum <HumanBodyBones>(b.ToString())); } } return(_toHumanBodyBones[(int)ikBone]); }
private void BackwardReach() { if (debug) { Debug.Log("BACKWARD REACHING..."); } forwardReachPositions.Reverse(); Vector3 desiredJointStart = this.joint.position; for (int i = 0; i < allBones.Count; i++) { IKBone boneOfInterest = allBones[i]; Vector3 firstJoint = desiredJointStart; Vector3 lastJoint = forwardReachPositions[i]; if (debug) { Debug.Log("First Joint: " + firstJoint); } if (debug) { Debug.Log("Last Joint: " + lastJoint); } Vector3 unitDir = (lastJoint - firstJoint).normalized; if (debug) { Debug.Log("Unit Direction: " + unitDir); } lastJoint = firstJoint + (unitDir * boneOfInterest.boneLength); if (debug) { Debug.Log("New End Point: " + lastJoint); } if (debugLines) { Debug.DrawLine(firstJoint, lastJoint, Color.green, Time.deltaTime); } desiredJointStart = lastJoint; boneOfInterest.UpdateJointRotation(lastJoint); boneOfInterest.UpdateJointPosition(firstJoint); } if (CalculateMarginOfError(forwardReachPositions[allBones.Count - 1], target.position) < marginOfError) { reachedTarget = true; } }
protected virtual void UpdateIKFingers() { for (IKBone ikBone = IKBone.LeftThumbDistal; ikBone <= IKBone.LeftLittleDistal; ikBone++) { GetIKSolver(ikBone).UpdateIK(); } for (IKBone ikBone = IKBone.RightThumbDistal; ikBone <= IKBone.RightLittleDistal; ikBone++) { GetIKSolver(ikBone).UpdateIK(); } }
private void StretchTowardTarget() { allBones[0].UpdateJointRotation(target.position); for (int i = 1; i < allBones.Count; i++) { IKBone boneOfInterest = allBones[i]; // the below line won't work for bones of varying length. boneOfInterest.transform.parent.localPosition = Vector3.right * i * boneOfInterest.boneLength; boneOfInterest.transform.parent.localRotation = Quaternion.Euler(0, 0, 0); } }
public IKSolverCircleIntersection(string name, IKBone chainRoot, IKBone targetRoot) : base(name, chainRoot, targetRoot) { bones = new List <IKBone>(); IKBone previous = chainRoot; for (int i = 0; i < 10; i++) { IKBone newbone = previous.addBone("bone_" + i, 0.3f, 0.1f, 0.1f); bones.Add(newbone); previous = newbone; } }
protected virtual void CopyHandPose(IKBone srcHandBoneID, IKBone dstHandBoneID) { //Copy the hand pose MirrorPose(GetIKSolver(srcHandBoneID), GetIKSolver(dstHandBoneID)); //Copy the fingers pose IKBone srcIKBoneStart = srcHandBoneID == IKBone.LeftHand? IKBone.LeftThumbDistal : IKBone.RightThumbDistal; IKBone dstIKBoneStart = dstHandBoneID == IKBone.LeftHand ? IKBone.LeftThumbDistal : IKBone.RightThumbDistal; for (int i = 0; i < 5; i++) { MirrorPose(GetIKSolver(srcIKBoneStart + i), GetIKSolver(dstIKBoneStart + i)); } }
public static IKBone createBone(string name, float length, float width, float thickness, IKSkeleton parentSkeleton) { GameObject boneGO = new GameObject(name); IKBone bone = boneGO.AddComponent <IKBone>(); bone.parentSkeleton = parentSkeleton; bone.length = length; bone.width = width; bone.thickness = thickness; bone.initPhysics(); bone.initAttachment(); return(bone); }
private void ForwardReach() { if (debug) { Debug.Log("FORWARD REACHING..."); } Vector3 desiredJointPos = target.position; forwardReachPositions.Clear(); for (int i = allBones.Count - 1; i >= 0; i--) { IKBone boneOfInterest = allBones[i]; forwardReachPositions.Add(desiredJointPos); Vector3 firstJoint = boneOfInterest.joint.position; Vector3 lastJoint = desiredJointPos; if (debug) { Debug.Log("First Joint: " + firstJoint); } if (debug) { Debug.Log("Last Joint: " + lastJoint); } //Debug.DrawLine(firstJoint, lastJoint, Color.magenta, 1000); Vector3 unitDir = (firstJoint - lastJoint).normalized; if (debug) { Debug.Log("Unit Direction: " + unitDir); } desiredJointPos = lastJoint + (unitDir * boneOfInterest.boneLength); if (debug) { Debug.Log("New End Point: " + desiredJointPos); } if (debugLines) { Debug.DrawLine(lastJoint, desiredJointPos, Color.yellow, Time.deltaTime); } } // if we didn't reach the start joint/root... BackwardReach(); }
private void refreshPosition(IKBone parentBone, bool hierarchy = false) { if (hierarchy) //set the previous bone as parent { this.transform.parent = parentBone.transform; this.transform.localRotation = Quaternion.identity * this.orientation; this.transform.localPosition = parentBone.getEndPointLocal() + this.offset; } else //set the root as parent { this.transform.parent = parentBone.parentSkeleton.rootBone.transform; this.transform.localRotation = Quaternion.identity * this.orientation; this.transform.localPosition = parentBone.getEndPointLocal() + this.offset; } }
public override void solve() { for (int i = 1; i < bones.Count - 1; i++) //iterate over n-2 { IKBone child = bones[i - 1]; //seems more like the parent //Call method currentNode.setCurrentRadius with ( (currentNode.getTotalRadius plus currentNode.getActiveRadius) is greater than distance) float radius = child.length; if (child.childBones[0] != null && child != null) { float childToCurrentRadius = child.length; } } }
public IKSolverTwoBone(string name, IKBone chainRoot, IKBone targetRoot, float length, float width, float thickness, float proportion) : base(name, chainRoot, targetRoot) { neutralDir = Vector3.right; hingeAxis = Vector3.up; upper = chainRoot.addBone(name + "_upper", length * proportion, width * proportion, thickness * proportion); float proportionInv = 1.0f - proportion; lower = upper.addBone(name + "_lower", length * proportionInv, width * proportionInv, thickness * proportionInv); float maxWT = Mathf.Max(width, thickness); end = lower.addBone(name + "_end", maxWT * proportionInv, maxWT * proportionInv, maxWT * proportionInv); target = IKTarget.createTarget(name + "_target", targetRoot); target.transform.position = upper.getStartPointWorld() + neutralDir * (upper.length + lower.length); }
public void Update() { IKBone.UpdateWorldMatrix(); for (int j = Childs.Length - 1; j >= 0; j--) { Childs[j].ChildBone.UpdateWorldMatrix(); } TargetBone.UpdateWorldMatrix(); for (int i = 0; i < 255; i++) { if (UpdateChildBones()) { return; } } }
public void connectTo(IKBone parentBone, bool hierarchy = true, bool ignoreCollisions = true, bool connectJoints = true) { this.parentBone = parentBone; parentBone.childBones.Add(this); refreshPosition(parentBone, hierarchy); if (connectJoints) { parentBone.physicsJoint.connectedBody = this.physicsRigidbody; } if (ignoreCollisions) { Physics.IgnoreCollision(parentBone.physicsCollider, this.physicsCollider); Physics.IgnoreCollision(parentBone.attachment.GetComponent <Collider>(), this.attachment.GetComponent <Collider>()); } }
protected virtual T CreateIKSolver <T>(IKBone ikBone) where T : QuickIKSolver { Transform ikSolversRoot = transform.CreateChild(IK_SOLVERS_ROOT_NAME); Transform t = ikSolversRoot.CreateChild(IK_SOLVER_PREFIX + ikBone.ToString()); T ikSolver = t.GetComponent <T>(); if (!ikSolver) { ikSolver = t.gameObject.AddComponent <T>(); //And configure it according to the bone HumanBodyBones boneLimb = ToHumanBodyBones(ikBone); ikSolver._boneUpper = GetBoneUpper(boneLimb); ikSolver._boneMid = GetBoneMid(boneLimb); ikSolver._boneLimb = _animator.GetBoneTransform((QuickHumanBodyBones)boneLimb); } return(ikSolver); }
Transform GetBoneTransform(IKBone bone) { switch (bone) { case IKBone.HEAD: return(animator.GetBoneTransform(HumanBodyBones.Head)); case IKBone.CHEST: return(animator.GetBoneTransform(HumanBodyBones.Chest)); case IKBone.LEFT_ARM: return(animator.GetBoneTransform(HumanBodyBones.LeftUpperArm)); case IKBone.RIGHT_ARM: return(animator.GetBoneTransform(HumanBodyBones.RightUpperArm)); default: return(null); } }
// Update is called once per frame void Update() { Vector2 direction = new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical")); direction.Normalize(); if (direction.magnitude < 0) { head.transform.rotation = Quaternion.LookRotation(direction); } if (leg /* && (rightleg.part2.SetDirection(false).AnchorRealPos() - rightlegdirection.transform.position).magnitude > 0.01f */) { //Debug.Log((rightleg.part2.SetDirection(false).AnchorRealPos() - rightlegdirection.transform.position).magnitude); Vector3 origin = leftlegdirection.transform.position; Vector3 objectif = rightlegdirection.transform.position; IKBone[] points = new IKBone[5]; points[0] = leftleg.part2.SetDirection(true); points[1] = leftleg.SetDirection(true); points[2] = torso.SetDirection(true); points[3] = rightleg.SetDirection(false); points[4] = rightleg.part2.SetDirection(false); FabrizioFull(points, origin, objectif); } else// if((leftleg.part2.SetDirection(false).AnchorRealPos() - leftlegdirection.transform.position).magnitude > 0.01f) { Vector3 origin = rightlegdirection.transform.position; Vector3 objectif = leftlegdirection.transform.position; IKBone[] points = new IKBone[5]; points[0] = rightleg.part2.SetDirection(true); points[1] = rightleg.SetDirection(true); points[2] = torso.SetDirection(true); points[3] = leftleg.SetDirection(false); points[4] = leftleg.part2.SetDirection(false); FabrizioFull(points, origin, objectif); } }