示例#1
0
    /// <summary>
    /// Sets the window title and minimum pane size
    /// </summary>
    public void Awake()
    {
        base.title   = TITLE;
        this.minSize = new Vector2(700f, 500f);

        mocapLogo = Resources.Load("Cinema Mocap") as Texture2D;
        if (mocapLogo == null)
        {
            UnityEngine.Debug.LogWarning("Cinema Mocap image missing from Resources folder.");
        }
        radarLogo = Resources.Load("Cinema Radar") as Texture2D;
        if (radarLogo == null)
        {
            UnityEngine.Debug.LogWarning("Cinema Radar image missing from Resources folder.");
        }
        recordingImage = Resources.Load("Recording") as Texture2D;
        if (recordingImage == null)
        {
            UnityEngine.Debug.LogWarning("Recording Image missing from Resources folder.");
        }

        cinema_mocap_humanoid_prefab = Resources.Load("Player") as GameObject;
        if (cinema_mocap_humanoid_prefab == null)
        {
            UnityEngine.Debug.LogError("Cinema_Mocap_Humanoid.dae is missing from the Resources folder. This item is required for the system.");
        }
        rigData     = ColladaUtility.ReadRigData(SOURCE_FILE);
        inputMapper = new NUIInputToRigMapper(rigData);

        workingResolution = ResolutionData.FromZigResolution(kinectCaptureResolution);
    }
示例#2
0
    /// <summary>
    /// Once capturing is complete, write out the animation file.
    /// </summary>
    private void StopRecording()
    {
        // Change to stopped state
        stopwatch.Stop();
        captureState = RecordingState.NotRecording;

        // Check if there is capture data
        if (captureData == null)
        {
            UnityEngine.Debug.LogWarning("No capture data was found.");
            return;
        }

        // Reload the rig data and mapper if necessary
        if (inputMapper == null)
        {
            rigData     = ColladaUtility.ReadRigData(SOURCE_FILE);
            inputMapper = new NUIInputToRigMapper(rigData);
        }

        // Map captured data to Collada data
        ColladaAnimationData data = inputMapper.GetColladaAnimation(captureData);

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

        if (System.IO.File.Exists(string.Format(FILE_DESTINATION, appendedFileName)))
        {
            newFileName = getNewFilename(appendedFileName);
            UnityEngine.Debug.LogWarning(string.Format(NAME_DUPLICATE_ERROR_MSG, appendedFileName, newFileName));
        }

        // Save
        if (transformationType == TransformationType.Matrix)
        {
            ColladaUtility.SaveAnimationData(data, SOURCE_FILE_MATRIX, string.Format(FILE_DESTINATION, newFileName), true);
        }
        else
        {
            ColladaUtility.SaveAnimationData(data, SOURCE_FILE, string.Format(FILE_DESTINATION, newFileName), false);
        }

        AssetDatabase.Refresh();
    }
示例#3
0
        public override void Initialize()
        {
            rigData = ColladaUtility.ReadRigData(SOURCE_FILE_PATH);

            cinema_mocap_humanoid_prefab = Resources.Load(SKELETON_NAME) as GameObject;
            if (cinema_mocap_humanoid_prefab == null)
            {
                UnityEngine.Debug.LogError(string.Format("{0} is missing from the Resources folder. This item is required for the system.", SOURCE_FILE));
            }

            // Try to find if the Skeleton exists in the scene already and assign the reference.
            HumanoidPoser[] previewSkeletons = GameObject.FindObjectsOfType <HumanoidPoser>();
            foreach (HumanoidPoser rhp in previewSkeletons)
            {
                if (rhp.gameObject.name == SKELETON_NAME)
                {
                    cinema_mocap_humanoid_instance = rhp.gameObject;
                }
            }

            LoadEditorPrefs();
        }
示例#4
0
    /// <summary>
    /// Once capturing is complete, write out the animation file.
    /// </summary>
    private void StopRecording()
    {
        // Change to stopped state
        stopwatch.Stop();
        captureState = RecordingState.NotRecording;

        // Check if there is capture data
        if (captureData == null)
        {
            UnityEngine.Debug.LogWarning("No capture data was found.");
            return;
        }

        // Reload the rig data and mapper if necessary
        if (inputMapper == null)
        {
            rigData = ColladaUtility.ReadRigData(SOURCE_FILE);
            inputMapper = new NUIInputToRigMapper(rigData);
        }

        // Map captured data to Collada data
        ColladaAnimationData data = inputMapper.GetColladaAnimation(captureData);

        // Check filename
        string appendedFileName = string.Format("MoCapHumanoid@{0}", fileName);
        string newFileName = appendedFileName;
        if (System.IO.File.Exists(string.Format(FILE_DESTINATION, appendedFileName)))
        {
            newFileName = getNewFilename(appendedFileName);
            UnityEngine.Debug.LogWarning(string.Format(NAME_DUPLICATE_ERROR_MSG, appendedFileName, newFileName));
        }

        // Save
        if (transformationType == TransformationType.Matrix)
        {
            ColladaUtility.SaveAnimationData(data, SOURCE_FILE_MATRIX, string.Format(FILE_DESTINATION, newFileName), true);
        }
        else
        {
            ColladaUtility.SaveAnimationData(data, SOURCE_FILE, string.Format(FILE_DESTINATION, newFileName), false);
        }
        
        AssetDatabase.Refresh();
    }
示例#5
0
    /// <summary>
    /// Sets the window title and minimum pane size
    /// </summary>
    public void Awake()
    {
        base.title = TITLE;
        this.minSize = new Vector2(700f, 500f);

        mocapLogo = Resources.Load("Cinema Mocap") as Texture2D;
        if (mocapLogo == null)
        {
            UnityEngine.Debug.LogWarning("Cinema Mocap image missing from Resources folder.");
        }
        radarLogo = Resources.Load("Cinema Radar") as Texture2D;
        if (radarLogo == null)
        {
            UnityEngine.Debug.LogWarning("Cinema Radar image missing from Resources folder.");
        }
        recordingImage = Resources.Load("Recording") as Texture2D;
        if (recordingImage == null)
        {
            UnityEngine.Debug.LogWarning("Recording Image missing from Resources folder.");
        }

        cinema_mocap_humanoid_prefab = Resources.Load("Player") as GameObject;
        if (cinema_mocap_humanoid_prefab == null)
        {
            UnityEngine.Debug.LogError("Cinema_Mocap_Humanoid.dae is missing from the Resources folder. This item is required for the system.");
        }
        rigData = ColladaUtility.ReadRigData(SOURCE_FILE);
        inputMapper = new NUIInputToRigMapper(rigData);
        
        workingResolution = ResolutionData.FromZigResolution(kinectCaptureResolution);
	}
示例#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);
        }