private Vector3 GetBoneCoordinate(FinchBone bone) { switch (bone) { case FinchBone.LeftUpperArm: return(FinchCore.GetBoneCoordinate(FinchBone.LeftUpperArm)); case FinchBone.LeftLowerArm: return(elbowPositions[0]); case FinchBone.LeftHandCenter: return(wristPositions[0]); case FinchBone.LeftHand: return(GetHandPositionByControllerPosition(wristPositions[0], wristOrientations[0], Vector3.left, FinchCore.GetBoneLength(FinchBone.LeftHand))); case FinchBone.RightUpperArm: return(FinchCore.GetBoneCoordinate(FinchBone.RightUpperArm)); case FinchBone.RightLowerArm: return(elbowPositions[1]); case FinchBone.RightHand: return(GetHandPositionByControllerPosition(wristPositions[1], wristOrientations[1], Vector3.right, FinchCore.GetBoneLength(FinchBone.RightHand))); case FinchBone.RightHandCenter: return(wristPositions[1]); default: return(Vector3.zero); } }
private void HandleBone(FinchBone bone, bool isChestLike, bool onlyRotation) { HumanBodyBones avatarBone = (HumanBodyBones)bone; if (avatarBone >= HumanBodyBones.LastBone) { return; } if (!isChestLike && PlayerState.Bones[bone] == -1) { return; } Transform boneTransform = ModelAnimator.GetBoneTransform(avatarBone); if (boneTransform == null) { return; } Quaternion boneRotation = (isChestLike) ? state.GetRotation(FinchBone.Chest) : state.GetRotation(bone); boneTransform.rotation = GetRotationFromInnerCS(boneRotation); if (!onlyRotation && !isChestLike) { boneTransform.position = GetPositionFromInnerCS(state.GetPosition(bone)); } }
private void FillControllerState(PlayerState outState) { for (int index = 0; index < PlayerState.Bones.BoneCount; ++index) { FinchBone bone = PlayerState.Bones[index]; switch (bone) { case FinchBone.LeftUpperArm: case FinchBone.LeftLowerArm: case FinchBone.LeftHand: case FinchBone.LeftHandCenter: case FinchBone.RightUpperArm: case FinchBone.RightLowerArm: case FinchBone.RightHand: case FinchBone.RightHandCenter: { outState.Rotations[index] = GetBoneRotation(bone); outState.Positions[index] = GetBoneCoordinate(bone); outState.Available[index] = true; outState.BonesLengths[index] = FinchCore.GetBoneLength(bone); break; } default: { outState.Rotations[index] = FinchCore.GetBoneRotation(bone); outState.Positions[index] = FinchCore.GetBoneCoordinate(bone); outState.Available[index] = FinchCore.IsBoneAvailable(bone); outState.BonesLengths[index] = FinchCore.GetBoneLength(bone); break; } } } }
private float GetBoneAngleAboveHorizontInDegrees(FinchBone bone, FinchChirality chirality) { Quaternion rotation = state.GetRotation(bone); Vector3 localForward; switch (chirality) { case FinchChirality.Left: { localForward = Vector3.left; break; } case FinchChirality.Right: { localForward = Vector3.right; break; } default: { localForward = Vector3.forward; break; } } Vector3 forward = rotation * localForward; float cosAngle = Vector3.Dot(forward, Vector3.up); return(Mathf.Asin(cosAngle) * Mathf.Rad2Deg); //cos alpha = sin 90 - alpha }
private Quaternion GetBoneRotation(FinchBone bone) { switch (bone) { case FinchBone.LeftUpperArm: return(shoulderOrientations[0]); case FinchBone.LeftLowerArm: return(elbowOrientations[0]); case FinchBone.LeftHand: return(wristOrientations[0]); case FinchBone.LeftHandCenter: return(wristOrientations[0]); case FinchBone.RightUpperArm: return(shoulderOrientations[1]); case FinchBone.RightLowerArm: return(elbowOrientations[1]); case FinchBone.RightHand: return(wristOrientations[1]); case FinchBone.RightHandCenter: return(wristOrientations[1]); default: return(Quaternion.identity); } }
public static bool IsFingerBone(FinchBone bone) { foreach (FinchBone nonFingerBone in nonFingersBoneArray) { if (bone == nonFingerBone) { return(false); } } return(true); }
private static void UpdateCoordinates(PlayerState state, FinchBone[] boneChain, FinchVector3[] boneLocalPositions) { Vector3 position = Vector3.zero; for (int i = 1; i < boneChain.Length; ++i) { FinchBone parent = boneChain[i - 1]; FinchBone child = boneChain[i]; float length = state.BonesLengths[PlayerState.Bones[parent]]; Quaternion parentRot = state.Rotations[PlayerState.Bones[parent]]; position += length * (parentRot * boneLocalPositions[PlayerState.Bones[child]].ToUnity()); state.Positions[PlayerState.Bones[child]] = position; } }
public override void ReadState(PlayerState outState) { base.ReadState(outState); for (int i = 0; i < PlayerState.Bones.BoneCount; ++i) { FinchBone bone = PlayerState.Bones[i]; outState.Rotations[i] = FinchCore.GetBoneRotation(bone); outState.Positions[i] = FinchCore.GetBoneCoordinate(bone); outState.Available[i] = FinchCore.IsBoneAvailable(bone); outState.BonesLengths[i] = FinchCore.GetBoneLength(bone); } outState.Positions[PlayerState.Bones[FinchBone.Head]] = outState.Positions[PlayerState.Bones[FinchBone.Neck]] + outState.Rotations[PlayerState.Bones[FinchBone.Hips]] * Vector3.up * outState.BonesLengths[PlayerState.Bones[FinchBone.Neck]]; outState.Positions[PlayerState.Bones[FinchBone.RightEye]] = outState.Positions[PlayerState.Bones[FinchBone.Head]] + outState.Rotations[PlayerState.Bones[FinchBone.Head]] * Vector3.up * outState.BonesLengths[PlayerState.Bones[FinchBone.Head]] + outState.Rotations[PlayerState.Bones[FinchBone.Head]] * Vector3.forward * eyeForwardShift; }
/// <summary> /// Creates new instance of the FinchController with specified chirality. /// </summary> /// <param name="chirality">Right or left</param> public FinchController(FinchChirality chirality) { Chirality = chirality; switch (chirality) { case FinchChirality.Left: Bone = FinchBone.LeftHandCenter; NodeType = FinchNodeType.LeftHand; break; case FinchChirality.Right: Bone = FinchBone.RightHandCenter; NodeType = FinchNodeType.RightHand; break; default: Bone = FinchBone.Unknown; NodeType = FinchNodeType.Unknown; break; } }
public static extern FinchQuaternion FinchGetBoneFPoseRotation(FinchBone bone);
public static extern byte FinchIsBoneAvailable(FinchBone bone);
/// <summary> /// Returns the bone length skeletal model. /// </summary> /// <param name="bone"></param> /// <returns></returns> public static float GetBoneLength(FinchBone bone) { return(Interop.FinchGetBoneLength(bone)); }
/// <summary> /// Sets the value of the selected bone length. /// </summary> /// <param name="bone"></param> /// <param name="length"></param> public static void SetBoneLength(FinchBone bone, float length) { Interop.FinchSetBoneLength(bone, length); }
public static extern float FinchGetBoneLength(FinchBone bone);
public static extern FinchVector3 FinchGetBoneGlobalAngularVelocity(FinchBone bone);
private FinchController(FinchChirality chirality, FinchBone bone, FinchNodeType node) { Chirality = chirality; Node = node; Bone = bone; }
/// <summary> /// Returns true, if bone data is available. /// </summary> /// <param name="bone"></param> /// <returns></returns> public static bool IsBoneAvailable(FinchBone bone) { return(Interop.FinchIsBoneAvailable(bone) != 0); }
public void SetBoneLength(FinchBone bone, float length) { FinchCore.SetBoneLength(bone, length); }
/// <summary> /// Returns bone rotation. /// </summary> /// <param name="bone">Certain bone</param> /// <param name="fPose">Use fPose rotation</param> /// <returns>Bone rotation quaternion</returns> public static Quaternion GetBoneRotation(FinchBone bone, bool fPose = true) { return(FinchCore.GetBoneRotation(bone, fPose)); }
/// <summary> /// Returns bone position. /// </summary> /// <param name="bone">Certain bone</param> /// <returns>Position coordinates</returns> public static Vector3 GetBonePosition(FinchBone bone) { return(FinchCore.GetBonePosition(bone)); }
public void SetBoneLength(FinchBone bone, float lenhth) { WarningDummy("SetBoneLength"); }
public static extern FinchVector3 FinchGetBoneCoordinate(FinchBone bone);
public static extern FinchVector3 FinchGetBoneGlobalAcceleration(FinchBone bone);
/// <summary> /// Returns bone acceleration in local coordinate system. /// </summary> /// <param name="bone"></param> /// <returns></returns> public static Vector3 GetBoneGlobalAcceleration(FinchBone bone) { return(Interop.FinchGetBoneGlobalAcceleration(bone).ToUnity()); }
public static extern void FinchSetBoneLength(FinchBone bone, float length);
/// <summary> /// Returns bone angular velocity vector in local coordinate system. /// </summary> /// <param name="bone"></param> /// <returns></returns> public static Vector3 GetBoneGlobalAngularVelocity(FinchBone bone) { return(Interop.FinchGetBoneGlobalAngularVelocity(bone).ToUnity()); }
/// <summary> /// Returns bone current orientation in space, as a quaternion. /// </summary> /// <param name="bone"></param> /// <param name="fPose"></param> /// <returns></returns> public static Quaternion GetBoneRotation(FinchBone bone, bool fPose = false) { return(fPose ? Interop.FinchGetBoneFPoseRotation(bone).ToUnity() : Interop.FinchGetBoneTPoseRotation(bone).ToUnity()); }
public TrembleOptions(FinchBone finchBone) { bone = finchBone; }
protected void UpdateTransforms() { if (Model == ModelType.Default) { for (int i = 0; i < PlayerState.Bones.BoneCount; ++i) { HandleBone(PlayerState.Bones[i], false, OnlyRotations); } } else if (Model == ModelType.Babe) { for (int i = 0; i < PlayerState.Bones.BoneCount; ++i) { FinchBone currentBone = PlayerState.Bones[i]; switch (currentBone) { case FinchBone.LeftShoulder: case FinchBone.RightShoulder: { HandleBone(currentBone, false, OnlyRotations); break; } case FinchBone.LeftThumbProximal: case FinchBone.LeftThumbIntermediate: case FinchBone.LeftThumbDistal: case FinchBone.RightThumbProximal: case FinchBone.RightThumbIntermediate: case FinchBone.RightThumbDistal: { switch (Fingers) { case FingerMovement.Full: { HandleBone(currentBone, false, OnlyRotations); break; } case FingerMovement.OnlyRotations: { HumanBodyBones avatarBone = (HumanBodyBones)currentBone; Transform boneTransform = ModelAnimator.GetBoneTransform(avatarBone); if (boneTransform == null) { return; } Quaternion boneRotation = state.GetRotation(currentBone); Quaternion babeCrutchThumbDelta = new Quaternion(-0.707107f, 0.0f, 0.0f, 0.707107f); boneTransform.rotation = GetRotationFromInnerCS(boneRotation) * babeCrutchThumbDelta; break; } default: break; } break; } default: { if (PlayerState.BoneDictionary.IsFingerBone(currentBone)) { switch (Fingers) { case FingerMovement.Full: HandleBone(currentBone, false, OnlyRotations); break; case FingerMovement.OnlyRotations: HandleBone(currentBone, false, true); break; default: break; } } else { HandleBone(currentBone, false, OnlyRotations); } break; } } } } foreach (FinchBone b in ChestLikeBones) { HandleBone(b, true, OnlyRotations); } Vector3 headLocalPosition; if (FinchSettings.DeviceType == FinchControllerType.Dash) { headLocalPosition = state.GetPosition(FinchBone.Head); } else { headLocalPosition = state.GetPosition(FinchBone.RightEye); //Center position of both eyes } Quaternion headLocalRotation = state.GetRotation(FinchBone.Head); if (FinchSettings.HeadUpdateType != FinchHeadUpdateType.RotationAndPositionUpdate) { if (Camera != null && !OnlyRotations) { Camera.transform.position = GetPositionFromInnerCS(headLocalPosition); } if (HeadVisualTransform != null) { HeadVisualTransform.rotation = GetRotationFromInnerCS(headLocalRotation); } } else { if (HeadVisualTransform != null) { HeadVisualTransform.rotation = GetRotationFromInnerCS(headLocalRotation); } } }
/// <summary> /// Returns bone position relatively midpoint of left and right shoulders. /// </summary> /// <param name="bone"></param> /// <returns></returns> public static Vector3 GetBoneCoordinate(FinchBone bone) { return(Interop.FinchGetBoneCoordinate(bone).ToUnity()); }