public static MoCapKinectBone Mecanim2Kinect(MoCapMecanimBone bone) { if (!IsValidMecanimBone(bone)) { return(MoCapKinectBone.Unknown); } return(Mecanim2KinectMapping[(int)bone]); }
private static void SetAnimationCurvesForBody(Animator animator, GameObject rootObject, TransformTime[] transforms, AnimationClip animationClip, MoCapMecanimBone bone, bool setPosition, bool setRotation, bool setScale) { if (animator == null) { throw new Exception("Animator can not be null!"); } if (rootObject == null) { throw new Exception("Root object can not be null!"); } if (transforms == null || transforms.Length == 0) { throw new Exception("Transforms can not be empty!"); } if (animationClip == null) { throw new Exception("Animation clip can not be null!"); } if (!MoCapBoneMapper.IsValidMecanimBone(bone)) { throw new Exception("Invalid Mecanim bone!"); } var relativeTransform = animator.GetBoneTransform((HumanBodyBones)bone); var relativePath = AnimationUtility.CalculateTransformPath(relativeTransform, rootObject.transform); var keyframesTransformPositionX = new Keyframe[transforms.Length]; var keyframesTransformPositionY = new Keyframe[transforms.Length]; var keyframesTransformPositionZ = new Keyframe[transforms.Length]; var keyframesTransformRotationX = new Keyframe[transforms.Length]; var keyframesTransformRotationY = new Keyframe[transforms.Length]; var keyframesTransformRotationZ = new Keyframe[transforms.Length]; var keyframesTransformRotationW = new Keyframe[transforms.Length]; var keyframesTransformScaleX = new Keyframe[transforms.Length]; var keyframesTransformScaleY = new Keyframe[transforms.Length]; var keyframesTransformScaleZ = new Keyframe[transforms.Length]; for (var i = 0; i < transforms.Length; i++) { var transform = transforms[i]; keyframesTransformPositionX[i] = new Keyframe(transform.Time, transform.Position.X); keyframesTransformPositionY[i] = new Keyframe(transform.Time, transform.Position.Y); keyframesTransformPositionZ[i] = new Keyframe(transform.Time, transform.Position.Z); keyframesTransformRotationX[i] = new Keyframe(transform.Time, transform.Rotation.X); keyframesTransformRotationY[i] = new Keyframe(transform.Time, transform.Rotation.Y); keyframesTransformRotationZ[i] = new Keyframe(transform.Time, transform.Rotation.Z); keyframesTransformRotationW[i] = new Keyframe(transform.Time, transform.Rotation.W); keyframesTransformScaleX[i] = new Keyframe(transform.Time, transform.Scale.X); keyframesTransformScaleY[i] = new Keyframe(transform.Time, transform.Scale.Y); keyframesTransformScaleZ[i] = new Keyframe(transform.Time, transform.Scale.Z); } var animationCurvePositionX = new AnimationCurve(keyframesTransformPositionX); var animationCurvePositionY = new AnimationCurve(keyframesTransformPositionY); var animationCurvePositionZ = new AnimationCurve(keyframesTransformPositionZ); if (setPosition) { animationClip.SetCurve(relativePath, typeof(Transform), "localPosition.x", animationCurvePositionX); animationClip.SetCurve(relativePath, typeof(Transform), "localPosition.y", animationCurvePositionY); animationClip.SetCurve(relativePath, typeof(Transform), "localPosition.z", animationCurvePositionZ); } var animationCurveRotationX = new AnimationCurve(keyframesTransformRotationX); var animationCurveRotationY = new AnimationCurve(keyframesTransformRotationY); var animationCurveRotationZ = new AnimationCurve(keyframesTransformRotationZ); var animationCurveRotationW = new AnimationCurve(keyframesTransformRotationW); if (setRotation) { animationClip.SetCurve(relativePath, typeof(Transform), "localRotation.x", animationCurveRotationX); animationClip.SetCurve(relativePath, typeof(Transform), "localRotation.y", animationCurveRotationY); animationClip.SetCurve(relativePath, typeof(Transform), "localRotation.z", animationCurveRotationZ); animationClip.SetCurve(relativePath, typeof(Transform), "localRotation.w", animationCurveRotationW); } var animationCurveScaleX = new AnimationCurve(keyframesTransformScaleX); var animationCurveScaleY = new AnimationCurve(keyframesTransformScaleY); var animationCurveScaleZ = new AnimationCurve(keyframesTransformScaleZ); if (setScale) { animationClip.SetCurve(relativePath, typeof(Transform), "localScale.x", animationCurveScaleX); animationClip.SetCurve(relativePath, typeof(Transform), "localScale.y", animationCurveScaleY); animationClip.SetCurve(relativePath, typeof(Transform), "localScale.z", animationCurveScaleZ); } }
public static bool IsValidMecanimBone(MoCapMecanimBone bone) { return(bone != MoCapMecanimBone.Unknown && bone != MoCapMecanimBone.LastBone); }
public static MoCapKinectBone Mecanim2Kinect(MoCapMecanimBone bone) { if (!IsValidMecanimBone(bone)) return MoCapKinectBone.Unknown; return Mecanim2KinectMapping[(int) bone]; }
public static bool IsValidMecanimBone(MoCapMecanimBone bone) { return bone != MoCapMecanimBone.Unknown && bone != MoCapMecanimBone.LastBone; }
private static void SetAnimationCurvesForBody(Animator animator, GameObject rootObject, TransformTime[] transforms, AnimationClip animationClip, MoCapMecanimBone bone, bool setPosition, bool setRotation, bool setScale) { if (animator == null) throw new Exception("Animator can not be null!"); if (rootObject == null) throw new Exception("Root object can not be null!"); if (transforms == null || transforms.Length == 0) throw new Exception("Transforms can not be empty!"); if (animationClip == null) throw new Exception("Animation clip can not be null!"); if (!MoCapBoneMapper.IsValidMecanimBone(bone)) throw new Exception("Invalid Mecanim bone!"); var relativeTransform = animator.GetBoneTransform((HumanBodyBones) bone); var relativePath = AnimationUtility.CalculateTransformPath(relativeTransform, rootObject.transform); var keyframesTransformPositionX = new Keyframe[transforms.Length]; var keyframesTransformPositionY = new Keyframe[transforms.Length]; var keyframesTransformPositionZ = new Keyframe[transforms.Length]; var keyframesTransformRotationX = new Keyframe[transforms.Length]; var keyframesTransformRotationY = new Keyframe[transforms.Length]; var keyframesTransformRotationZ = new Keyframe[transforms.Length]; var keyframesTransformRotationW = new Keyframe[transforms.Length]; var keyframesTransformScaleX = new Keyframe[transforms.Length]; var keyframesTransformScaleY = new Keyframe[transforms.Length]; var keyframesTransformScaleZ = new Keyframe[transforms.Length]; for (var i = 0; i < transforms.Length; i++) { var transform = transforms[i]; keyframesTransformPositionX[i] = new Keyframe(transform.Time, transform.Position.X); keyframesTransformPositionY[i] = new Keyframe(transform.Time, transform.Position.Y); keyframesTransformPositionZ[i] = new Keyframe(transform.Time, transform.Position.Z); keyframesTransformRotationX[i] = new Keyframe(transform.Time, transform.Rotation.X); keyframesTransformRotationY[i] = new Keyframe(transform.Time, transform.Rotation.Y); keyframesTransformRotationZ[i] = new Keyframe(transform.Time, transform.Rotation.Z); keyframesTransformRotationW[i] = new Keyframe(transform.Time, transform.Rotation.W); keyframesTransformScaleX[i] = new Keyframe(transform.Time, transform.Scale.X); keyframesTransformScaleY[i] = new Keyframe(transform.Time, transform.Scale.Y); keyframesTransformScaleZ[i] = new Keyframe(transform.Time, transform.Scale.Z); } var animationCurvePositionX = new AnimationCurve(keyframesTransformPositionX); var animationCurvePositionY = new AnimationCurve(keyframesTransformPositionY); var animationCurvePositionZ = new AnimationCurve(keyframesTransformPositionZ); if (setPosition) { animationClip.SetCurve(relativePath, typeof (Transform), "localPosition.x", animationCurvePositionX); animationClip.SetCurve(relativePath, typeof (Transform), "localPosition.y", animationCurvePositionY); animationClip.SetCurve(relativePath, typeof (Transform), "localPosition.z", animationCurvePositionZ); } var animationCurveRotationX = new AnimationCurve(keyframesTransformRotationX); var animationCurveRotationY = new AnimationCurve(keyframesTransformRotationY); var animationCurveRotationZ = new AnimationCurve(keyframesTransformRotationZ); var animationCurveRotationW = new AnimationCurve(keyframesTransformRotationW); if (setRotation) { animationClip.SetCurve(relativePath, typeof (Transform), "localRotation.x", animationCurveRotationX); animationClip.SetCurve(relativePath, typeof (Transform), "localRotation.y", animationCurveRotationY); animationClip.SetCurve(relativePath, typeof (Transform), "localRotation.z", animationCurveRotationZ); animationClip.SetCurve(relativePath, typeof (Transform), "localRotation.w", animationCurveRotationW); } var animationCurveScaleX = new AnimationCurve(keyframesTransformScaleX); var animationCurveScaleY = new AnimationCurve(keyframesTransformScaleY); var animationCurveScaleZ = new AnimationCurve(keyframesTransformScaleZ); if (setScale) { animationClip.SetCurve(relativePath, typeof (Transform), "localScale.x", animationCurveScaleX); animationClip.SetCurve(relativePath, typeof (Transform), "localScale.y", animationCurveScaleY); animationClip.SetCurve(relativePath, typeof (Transform), "localScale.z", animationCurveScaleZ); } }