コード例 #1
0
    public override void OnInspectorGUI()
    {
        DrawDefaultInspector();

        BVHRecorder bvhRecorder = (BVHRecorder)target;

        if (GUILayout.Button("Detect bones"))
        {
            bvhRecorder.getBones();
            Debug.Log("Bone detection done.");
        }

        if (GUILayout.Button("Remove empty entries from bone list"))
        {
            bvhRecorder.cleanupBones();
            Debug.Log("Cleaned up bones.");
        }

        if (GUILayout.Button("Clear recorded motion data"))
        {
            bvhRecorder.clearCapture();
            Debug.Log("Cleared motion data.");
        }

        if (GUILayout.Button("Save motion to BVH file"))
        {
            try {
                bvhRecorder.saveBVH();
            } catch (Exception ex) {
                Debug.LogError("An error has occurred while saving the BVH file: " + ex);
            }
        }
    }
コード例 #2
0
    public override void OnInspectorGUI()
    {
        DrawDefaultInspector();

        BVHRecorder bvhRecorder = (BVHRecorder)target;

        if (GUILayout.Button("Detect bones"))
        {
            bvhRecorder.getBones();
            Debug.Log("Bone detection done.");
        }

        if (GUILayout.Button("Remove empty entries from bone list"))
        {
            bvhRecorder.cleanupBones();
            Debug.Log("Cleaned up bones.");
        }

        if (GUILayout.Button("Clear recorded motion data"))
        {
            bvhRecorder.clearCapture();
            Debug.Log("Cleared motion data.");
        }

        if (GUILayout.Button("Save motion to BVH file"))
        {
            try {
                bvhRecorder.saveBVH();
            } catch {
                Debug.LogError("Motion data can only be saved while the scene is running.");
            }
        }
    }
コード例 #3
0
    // Update is called once per frame
    void Update()
    {
        //Debug.Log(animator != null);
        //Debug.Log(videoPlayer != null);
        //Debug.Log(videoPlayer.frame);
        //Debug.Log(animator.GetCurrentAnimatorStateInfo(0).length);
        if (has_begun_playing)
        {
            //if (animator != null)
            //    Debug.Log("HII");
            //if (!AnimatorIsPlaying() && !has_saved)
            //    {
            //        Debug.Log("Stopped!");
            //        recorder.capturing = false;
            //        recorder.saveBVH();
            //        has_saved = true;
            //    }
            //else if (videoPlayer != null)
            if (videoPlayer != null)
            {
                //Debug.Log(videoPlayer.frame);
                //Debug.Log(videoPlayer.frameCount);
                //Debug.Log(VideoHasStopped());
                //Debug.Log(has_saved);
                //Debug.Log(VideoHasStopped() && !has_saved);
                if (VideoHasStopped() && !has_saved)
                {
                    Debug.Log("Stopped!");
                    recorder.capturing = false;
                    recorder.saveBVH();
                    has_saved = true;
                }
            }

            if (has_saved)
            {
                Application.Quit();
            }
        }
    }
コード例 #4
0
    public void onRecord()
    {
        if (isRecording == false)
        {
            recorder = gameObject.AddComponent <BVHRecorder>();
            var setting = AvatarList[avatars.value];
            recorder.targetAvatar = setting.Avatar.GetComponent <Animator>();
            recorder.scripted     = true;

            recorder.blender = configurationSetting.Blender == 1;
            recorder.enforceHumanoidBones = configurationSetting.EnforceHumanoidBones == 1;
            recorder.getBones();
            recorder.rootBone = setting.Avatar.JointPoints[PositionIndex.hip.Int()].Transform;
            recorder.buildSkeleton();
            recorder.genHierarchy();
            recorder.capturing = configurationSetting.Capturing == 1;
            if (configurationSetting.Capturing == 1)
            {
                recorder.frameRate = configurationSetting.CapturingFPS;
            }
            recorder.catchUp      = configurationSetting.CatchUp == 1;
            isRecording           = true;
            btnRecord.image.color = Color.red;
            btnRecord.GetComponentInChildren <Text>().text  = "Recording";
            btnRecord.GetComponentInChildren <Text>().color = Color.white;
        }
        else
        {
            isRecording        = false;
            recorder.capturing = false;

            var extensions = new[]
            {
                new ExtensionFilter("BVH Files", "bvh"),
            };
            var path = StandaloneFileBrowser.SaveFilePanel("SaveFile", "", "motion.bvh", extensions);

            if (path.Length != 0)
            {
                FileInfo fi = new FileInfo(path);
                recorder.directory = fi.DirectoryName;
                recorder.filename  = fi.Name;
                recorder.saveBVH();
            }
            recorder.clearCapture();
            recorder = null;
            btnRecord.image.color = Color.white;
            btnRecord.GetComponentInChildren <Text>().text  = "Record BVH";
            btnRecord.GetComponentInChildren <Text>().color = Color.black;
        }
    }
コード例 #5
0
    void Update()
    {
        if (pos == null || boneT[0] == null)
        {
            return;
        }
        playTime += Time.deltaTime;

        if (saveMotion && recorder != null)
        {
            // ファイル出力の場合は1フレームずつ進める
            frame += 1;
        }
        else
        {
            frame = sFrame + (int)(playTime * 30.0f);              // pos.txtは30fpsを想定
        }
        if (frame > eFrame)
        {
            if (saveMotion && recorder != null)
            {
                if (!bvhSaved)
                {
                    bvhSaved = true;
                    if (saveBVHFilename != "")
                    {
                        string fullpath = Path.GetFullPath(saveBVHFilename);
                        // recorder.directory = Path.GetDirectoryName(fullpath);
                        // recorder.filename = Path.GetFileName(fullpath);
                        recorder.directory = "";
                        recorder.filename  = fullpath;
                        recorder.overwrite = overwrite;
                        recorder.saveBVH();
                        Debug.Log("Saved Motion(BVH) to " + recorder.lastSavedFile);
                    }
                    else
                    {
                        Debug.Log("<color=blue>Error! Save BVH Filename is empty.</color>");
                    }
                }
            }
            return;
        }
        nowFrame_readonly = frame;         // Inspector表示用

        if (showDebugCube)
        {
            UpdateCube(frame);             // デバッグ用Cubeを表示する
        }

        Vector3[] nowPos = pos[frame];

        // センターの移動と回転
        Vector3 posForward = TriangleNormal(nowPos[7], nowPos[4], nowPos[1]);

        this.transform.position = rootRotation * nowPos[0] * scaleRatio + rootPosition + new Vector3(0, upPosition - hipHeight, 0);
        boneT[0].rotation       = rootRotation * Quaternion.LookRotation(posForward) * initInv[0] * initRot[0];

        // 各ボーンの回転
        for (int i = 0; i < bones.Length; i++)
        {
            int b  = bones[i];
            int cb = childBones[i];
            boneT[b].rotation = rootRotation * Quaternion.LookRotation(nowPos[b] - nowPos[cb], posForward) * initInv[b] * initRot[b];
        }

        // 顔の向きを上げる調整。両肩を結ぶ線を軸として回転
        boneT[8].rotation = Quaternion.AngleAxis(headAngle, boneT[11].position - boneT[14].position) * boneT[8].rotation;

        if (saveMotion && recorder != null)
        {
            recorder.captureFrame();
        }
    }