Example #1
0
    /// <summary>
    /// Load the motion from a BVH file.
    /// </summary>
    /// <param name="path"></param>
    private void LoadMotion(string path)
    {
        if (!File.Exists(path))
        {
            Debug.Log("Motion " + path + " is not exits.");
            return;
        }

        GameObject newMotionObject = null;

        try
        {
            BvhImporterContext context = new BvhImporterContext();
            //Debug.Log("Loading motion : " + path);

            context.Parse(path);
            context.Load();
            newMotionObject = context.Root;

            // Hide the motion model
            Renderer renderer = newMotionObject.GetComponent <Renderer>();
            if (renderer)
            {
                renderer.enabled = false;
            }

            if (uiController)
            {
                uiController.enableRandomMotion = false;    // ランダムモーションは強制的にオフにする
            }
        }
        catch (Exception ex)
        {
            if (uiController)
            {
                uiController.SetWarning("Motion load failed.");
            }
            Debug.LogError("Failed loading " + path);
            Debug.LogError(ex);
            return;
        }

        if (newMotionObject)
        {
            if (motion)
            {
                GameObject.Destroy(motion.gameObject);
            }

            motion = newMotionObject.GetComponent <HumanPoseTransfer>();
            SetMotion(motion, model, meta);

            // Play loaded audio if available
            if (audioSource && audioSource.clip && audioSource.clip.loadState == AudioDataLoadState.Loaded)
            {
                audioSource.Stop();
                audioSource.Play();
            }
        }
    }
Example #2
0
    /// <summary>
    /// Load the motion from a BVH file.
    /// </summary>
    /// <param name="path"></param>
    private void LoadMotion(string path)
    {
        if (!File.Exists(path))
        {
            Debug.Log("Motion " + path + " is not exits.");
            return;
        }

        var        characterController = model.GetComponent <VrmCharacterBehaviour>();
        GameObject newMotionObject     = null;

        try
        {
            BvhImporterContext context = new BvhImporterContext();
            //Debug.Log("Loading motion : " + path);

            context.Parse(path);
            context.Load();
            newMotionObject = context.Root;

            // Hide the motion model
            Renderer renderer = newMotionObject.GetComponent <Renderer>();
            if (renderer)
            {
                renderer.enabled = false;
            }
        }
        catch (Exception ex)
        {
            if (uiController)
            {
                uiController.motionMode = VrmCharacterBehaviour.MotionMode.Default;
                uiController.ShowWarning("Motion load failed.");
            }
            Debug.LogError("Failed loading " + path);
            Debug.LogError(ex);
            return;
        }

        if (newMotionObject)
        {
            if (motion)
            {
                GameObject.Destroy(motion.gameObject);
            }

            motion = newMotionObject.GetComponent <HumanPoseTransfer>();

            // 読み込みが成功したら、モーションの選択肢はBVHとする
            _motionMode = VrmCharacterBehaviour.MotionMode.Bvh;
            SetMotion(motion, model, meta);

            if (uiController)
            {
                uiController.motionMode = VrmCharacterBehaviour.MotionMode.Bvh;
            }

            // Play loaded audio if available
            if (audioSource && audioSource.clip && audioSource.clip.loadState == AudioDataLoadState.Loaded)
            {
                audioSource.Stop();
                audioSource.Play();
            }
        }
    }