예제 #1
0
        public override void SaveAnimation(NUIHumanoidAnimation animation)
        {
            // Check if there is capture data
            if (animation == null)
            {
                UnityEngine.Debug.LogWarning("No capture data was found.");
                return;
            }

            // Map captured data to Collada data
            ColladaAnimationData data = GetColladaAnimation(animation);

            // Check filename
            string appendedFileName = string.Format("MoCapHumanoid@{0}", fileName);
            string newFileName      = appendedFileName;

            if (BaseSystem.IO.File.Exists(string.Format(SAVE_DESTINATION_FORMAT, animSaveDestination, newFileName)))
            {
                newFileName = CinemaMocapHelper.GetNewFilename(animSaveDestination, appendedFileName, "dae");
                UnityEngine.Debug.LogWarning(string.Format(NAME_DUPLICATE_ERROR_MSG, appendedFileName, newFileName));
            }

            // Save
            if (transformationType == TransformationType.Matrix)
            {
                ColladaUtility.SaveAnimationData(data, SOURCE_FILE_MATRIX_PATH, string.Format(SAVE_DESTINATION_FORMAT, animSaveDestination, newFileName), true);
            }
            else
            {
                ColladaUtility.SaveAnimationData(data, SOURCE_FILE_PATH, string.Format(SAVE_DESTINATION_FORMAT, animSaveDestination, newFileName), false);
            }
        }
예제 #2
0
    /// <summary>
    /// Begin capturing the motion from the user.
    /// </summary>
    private void BeginRecording()
    {
        captureState = RecordingState.Recording;
        captureData  = new NUIHumanoidAnimation();

        stopwatch.Stop();
        stopwatch.Reset();
        stopwatch.Start();
    }
예제 #3
0
        public override NUIHumanoidAnimation MapAnimation(NUIHumanoidAnimation animation)
        {
            NUIHumanoidAnimation mappedAnimation = new NUIHumanoidAnimation();

            foreach (NUIAnimationKeyframe kf in animation.Keyframes)
            {
                NUISkeleton mappedSkeleton = MapSkeleton(kf.Skeleton);

                NUIAnimationKeyframe newKF = new NUIAnimationKeyframe(mappedSkeleton, kf.ElapsedTime);

                mappedAnimation.AddKeyframe(newKF);
            }

            return(mappedAnimation);
        }
        public override NUIHumanoidAnimation MapAnimation(NUIHumanoidAnimation animation)
        {
            NUIHumanoidAnimation mappedAnimation = new NUIHumanoidAnimation();

            foreach (NUIAnimationKeyframe kf in animation.Keyframes)
            {
                Vector3 position = GetHipPosition(kf.Skeleton);

                NUISkeleton mappedSkeleton = MapSkeleton(kf.Skeleton);

                mappedSkeleton.Joints[NUIJointType.SpineBase].Position = position;
                NUIAnimationKeyframe newKF = new NUIAnimationKeyframe(mappedSkeleton, kf.ElapsedTime);

                mappedAnimation.AddKeyframe(newKF);
            }

            return(mappedAnimation);
        }
예제 #5
0
    /// <summary>
    /// Begin capturing the motion from the user.
    /// </summary>
    private void BeginRecording()
    {
        captureState = RecordingState.Recording;
        captureData = new NUIHumanoidAnimation();

        stopwatch.Stop();
        stopwatch.Reset();
		stopwatch.Start();
    }
예제 #6
0
        public ColladaAnimationData GetColladaAnimation(NUIHumanoidAnimation animation)
        {
            NUISkeleton outputStructure = GetTargetStructure();

            ColladaAnimationData colladaAnimation = new ColladaAnimationData(rigData);
            List <float>         elapsedTimes     = new List <float>();

            Vector3 startingPosition    = Vector3.zero;
            Vector3 rigStartingPosition = rigData.GetJoint("SpineBase").Translation;


            int frameRate = 0;

            switch (selectedFrameRateIndex)
            {
            case 0:
                frameRate = 30;
                break;

            case 1:
                frameRate = 60;
                break;
            }

            NUIHumanoidAnimation animationConstrained = animation.ConstrainFramerate(frameRate);

            for (int k = 0; k < animationConstrained.Keyframes.Count; k++)
            {
                NUIAnimationKeyframe keyframe = animationConstrained.Keyframes[k];

                elapsedTimes.Add(keyframe.ElapsedTime);

                ColladaRigData   currentRig  = new ColladaRigData();
                ColladaJointData parentJoint = rigData.GetJoint("SpineBase");
                currentRig.Add(parentJoint.Id, parentJoint);

                foreach (KeyValuePair <string, ColladaJointData> jointData in rigData.JointData)
                {
                    ColladaJointData colladaJointData = rigData.GetJoint(jointData.Key);

                    if (colladaJointData.Id == "SpineBase")
                    {
                        Vector3 hipPosition = keyframe.Skeleton.Joints[NUIJointType.SpineBase].Position * 100;
                        hipPosition.x *= -1;
                        if (startingPosition == Vector3.zero)
                        {
                            startingPosition = hipPosition;
                        }
                        colladaJointData.Translation = (hipPosition - startingPosition) + rigStartingPosition;
                    }
                    colladaAnimation.jointTranslateX[jointData.Key] += string.Format(cultureUS, "{0} ", colladaJointData.Translation.x);
                    colladaAnimation.jointTranslateY[jointData.Key] += string.Format(cultureUS, "{0} ", colladaJointData.Translation.y);
                    colladaAnimation.jointTranslateZ[jointData.Key] += string.Format(cultureUS, "{0} ", colladaJointData.Translation.z);
                }

                foreach (KeyValuePair <NUIJointType, NUIJoint> kvp in keyframe.Skeleton.Joints)
                {
                    // For parent joints
                    Quaternion rotation = kvp.Value.Rotation;

                    string           id = NUIJointToColladaMapping(kvp.Key);
                    ColladaJointData colladaJointData = rigData.GetJoint(id);

                    if (!outputStructure.Structure.IsJointAnExtremity(kvp.Key))
                    {
                        Vector3 revert    = QuaternionHelper.ToEulerAnglesXYZ(rotation);
                        Vector3 corrected = new Vector3(revert.x, -revert.y, -revert.z);

                        colladaAnimation.jointRotateX[id] += string.Format(cultureUS, "{0} ", corrected.x);
                        colladaAnimation.jointRotateY[id] += string.Format(cultureUS, "{0} ", corrected.y);
                        colladaAnimation.jointRotateZ[id] += string.Format(cultureUS, "{0} ", corrected.z);

                        Matrix4x4 transformation = Matrix4x4.TRS(colladaJointData.Translation, QuaternionHelper.FromEulerAnglesXYZ(corrected), Vector3.one);
                        colladaAnimation.jointValues[id] += string.Format(cultureUS, "{0} ", transformation.ToString());
                    }
                    else
                    {
                        // Extremeties
                        colladaAnimation.jointRotateX[id] += string.Format(cultureUS, "{0} ", colladaJointData.RotationVector.x);
                        colladaAnimation.jointRotateY[id] += string.Format(cultureUS, "{0} ", colladaJointData.RotationVector.y);
                        colladaAnimation.jointRotateZ[id] += string.Format(cultureUS, "{0} ", colladaJointData.RotationVector.z);

                        Matrix4x4 transformation = Matrix4x4.TRS(colladaJointData.Translation, colladaJointData.Rotation, Vector3.one);
                        colladaAnimation.jointValues[id] += string.Format(cultureUS, "{0} ", transformation.ToString());
                    }
                }
            }

            colladaAnimation.frameTimelapse = elapsedTimes;
            return(colladaAnimation);
        }
예제 #7
0
        /// <summary>
        /// Once capture is complete, request the OutputProfile to save the animation.
        /// </summary>
        protected void saveAnimation(MocapSession session)
        {
            if (OutputProfile == null)
            {
                Debug.LogWarning("No Output method was found. Animation was not saved");
                return;
            }
            if (MappingProfile == null)
            {
                Debug.LogWarning("No Mapping method was found. Animation was not saved");
                return;
            }
            if (session == null)
            {
                return;
            }

            var animation = new NUIHumanoidAnimation();
            var cache     = new CaptureCache();

            foreach (MocapSessionKeyframe keyframe in session.CaptureData)
            {
                var elapsedTime = keyframe.ElapsedMilliseconds;
                var skeleton    = NUICaptureHelper.GetNUISkeleton(keyframe.Skeleton);

                cache.AddNewFrame(skeleton, elapsedTime);

                // Filter the raw input with enabled filters.
                NUISkeleton filtered = skeleton;
                foreach (MocapFilter filter in preMapFilters)
                {
                    if (filter.Enabled)
                    {
                        filtered = filter.Filter(cache);
                        cache.AddFiltered(filter.Name, filtered);
                    }
                }

                // Convert the input skeleton to the normalized skeleton (Unity)
                NUISkeleton mapped = MappingProfile.MapSkeleton(filtered);
                cache.AddMapped(mapped);

                // Apply any post-mapped filters selected by the user.
                filtered = mapped;
                foreach (MocapFilter filter in postMapFilters)
                {
                    if (filter.Enabled)
                    {
                        filtered = filter.Filter(cache);
                        cache.AddFiltered(filter.Name, filtered);
                    }
                }
                cache.AddResult(filtered);

                filtered.Joints[NUIJointType.SpineBase].Position = skeleton.Joints[NUIJointType.SpineBase].Position;
                animation.AddKeyframe(filtered, keyframe.ElapsedMilliseconds);
            }

            // Save the session
            if (saveSession)
            {
                string newFileName = fileName;
                if (BaseSystem.IO.File.Exists(string.Format(SAVE_DESTINATION_FORMAT, sessionSaveDestination, newFileName)))
                {
                    newFileName = CinemaMocapHelper.GetNewFilename(sessionSaveDestination, fileName, "asset");
                    UnityEngine.Debug.LogWarning(string.Format(NAME_DUPLICATE_ERROR_MSG, fileName, newFileName));
                }

                AssetDatabase.CreateAsset(session, string.Format(SAVE_DESTINATION_FORMAT, sessionSaveDestination, newFileName));
                AssetDatabase.SaveAssets();
            }

            // Save the animation
            OutputProfile.SaveAnimation(animation);
            AssetDatabase.Refresh();
        }
예제 #8
0
 public abstract NUIHumanoidAnimation MapAnimation(NUIHumanoidAnimation animation);
예제 #9
0
 /// <summary>
 /// Save an animation based on the mocap data.
 /// </summary>
 /// <param name="animation">The animation captured.</param>
 public abstract void SaveAnimation(NUIHumanoidAnimation animation);