private float RotationCost(MotionJointPoint frameBone, MotionJointPoint currentBone) { var bonePosRotation = Quaternion.Inverse(frameBone.LocalRotation) * currentBone.LocalRotation; var rotationCost = Mathf.Abs(bonePosRotation.x) + Mathf.Abs(bonePosRotation.x) + Mathf.Abs(bonePosRotation.y) + (1 - Mathf.Abs(bonePosRotation.w)); return(rotationCost); }
//frameBone is the bone we look at, which is from animation clips private float BoneCost(MotionJointPoint frameBone, MotionJointPoint currentBone, PlayerSetting playerSetting) { var rotationCost = RotationCost(frameBone, currentBone); var posCost = PosCost(frameBone, currentBone); return(playerSetting.BoneRotFactor * rotationCost + playerSetting.BonePosFactor * posCost); }
private MotionJointPoint MakeMotionJoint(AnimationJointPoint current, AnimationJointPoint last) { var motionJointPoint = new MotionJointPoint { LocalPosition = current.Position, LocalRotation = current.Rotation, Rotation = current.Rotation, Name = current.Name, Position = current.Position, Velocity = current.Position - last.Position }; return(motionJointPoint); }
private void ApplyJointPointToJoint(MotionJointPoint jointPoint, Transform joint) { // Based on negative joint var newEulerRot = jointPoint.Rotation * Quaternion.Inverse(jointPoint.BaseRotation); //var newEulerRot = jointPoint.Rotation * jointPoint.BaseRotation; //joint.rotation = newEulerRot; joint.rotation = Skeleton.rotation * jointPoint.LocalRotation; //joint.rotation = Skeleton.rotation * (newEulerRot); joint.position = Skeleton.position + jointPoint.Position; //joint.SetPositionAndRotation(jointPoint.Position, jointPoint.Rotation); }
private float PosCost(MotionJointPoint frameBone, MotionJointPoint currentBone) { var posCost = (frameBone.LocalPosition - currentBone.LocalPosition).sqrMagnitude; return(posCost); }