Пример #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();
            }
        }
    }
Пример #2
0
        private void LoadMotion(string path)
        {
            try
            {
                // Trigger BVH
                _bvhLoadingTrigger = true;
                // Save current path
                _bvhPathLocal = path;
                var previous_motion = _bvhMotion;
                if (previous_motion != null)
                {
                    Destroy(previous_motion.Root);
                }

                var context = new UniHumanoid.BvhImporterContext();
                _bvhMotion = context;
                context.Parse(path);
                context.Load();
                if (context.Avatar == null || context.Avatar.isValid == false)
                {
                    if (context.Root != null)
                    {
                        Destroy(context.Root);
                    }
                    throw new Exception("BVH importer failed");
                }

                // Send BVH
                _informationUpdate.SetBVH(_bvhMotion.Root);

                SetMotion(context.Root.GetComponent <HumanPoseTransfer>());
            }
            catch (Exception e)
            {
                if (_bvhMotion.Root == true)
                {
                    Destroy(_bvhMotion.Root);
                }
                _errorMessagePanel.SetMessage(MultipleLanguageSupport.BvhLoadErrorMessage + "\nError message: " + e.Message);
                throw;
            }
        }
Пример #3
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();
            }
        }
    }