• wiseglove數據手套驅動unity3D遊戲角色右手模型關節

    2017/2/20      點擊(jī):

    目前unity3D遊戲引擎已經廣泛的(de)用(yòng)於遊戲開發(fā),而且unity3d在國內發展(zhǎn)比較迅速,已經成為了主(zhǔ)流的遊戲開發引擎之一。隨(suí)著越來(lái)越多的(de)開發(fā)人員開始使用unity3D,網絡上unity3D的中文學習資(zī)料也逐漸豐富。為了方便(biàn)客戶使用wiseglove數據手套,我們專門(mén)組織編寫了在Unity3D環境(jìng)下調用wiseglove數據手(shǒu)套SDK開發包,用數據手套的實時(shí)數據(jù)來驅動unity3d中的角色右手(shǒu)模型的demo程序。

    Unity3D的(de)新版動畫係統Mecanim已經(jīng)對人類類(lèi)型的角色支援設計了一(yī)套殊的工(gōng)作流程(chéng)。用戶將3dsmax或者maya中導入的人形角色導入unity3d後,需要為角色創建Avatar,本質上就是分析導入資源的骨(gǔ)骼結(jié)構,並對其進行標(biāo)識(shí),從而(ér)轉化成Mecanim可以識別的骨骼結(jié)構,或者說轉化成通用的骨骼結構,這也是(shì)為什麽在資源(yuán)準備時在骨骼的創建及(jí)命(mìng)名(míng)要遵循一定的規範(fàn)的原因,這樣方便mecanim對(duì)骨骼的識(shí)別。

    在導入的資源都具有通用的骨骼結構時,就可以實現(xiàn)動(dòng)畫的共用。

    在這裏我們用wiseGlove數據手(shǒu)套驅(qū)動(dòng)右手模型時也使用了unity標準的avatar映射的(de)人手關節模型,這樣(yàng)方便我們對不同的角色的右(yòu)手模型(xíng)進行驅動。

    下麵是用於驅動人手模型的代(dài)碼,需要將(jiāng)這段代碼掛載在場景中的角色身上:

     

    using System.Collections;

    using System.Collections.Generic;

    using UnityEngine;


    public class RightHand : MonoBehaviour {

        Animator animator;

        Transform rightThumbProximal; //This is the right thumb 1st phalange.

        Transform rightThumbIntermediate; // This is the right thumb 2nd phalange.

        Transform rightThumbDistal;    //This is the right thumb 3rd phalange.

        Transform rightIndexProximal; // This is the right index 1st phalange.

        Transform rightIndexIntermediate; // This is the right index 2nd phalange.

        Transform rightIndexDistal; // This is the right index 3rd phalange.

        Transform rightMiddleProximal; // This is the right middle 1st phalange.

        Transform rightMiddleIntermediate;// This is the right middle 2nd phalange.

        Transform rightMiddleDistal;// This is the right middle 3rd phalange.

        Transform rightRingProximal;// This is the right ring 1st phalange.

        Transform rightRingIntermediate;// This is the right ring 2nd phalange.

        Transform rightRingDistal;// This is the right ring 3rd phalange.

        Transform rightLittleProximal;// This is the right little 1st phalange.

        Transform rightLittleIntermediate;// This is the right little 2nd phalange.

        Transform rightLittleDistal;// This is the right little 3rd phalange.


        //將從數據手套獲取到(dào)的各(gè)個手指關節的Rotation賦值給下麵對應的Quaternion類型的公用變量,

        //就可以實現手指關節(jiē)的(de)運動

        public Quaternion R_Thumb_P_rotation; //R-right,T-Thumb,P-Proximal

        public Quaternion R_Thumb_I_rotation;

        public Quaternion R_Thumb_D_roatation;

        public Quaternion R_Index_P_rotation; //R-right,I-Index,P-Proximal

        public Quaternion R_Index_I_rotation;

        public Quaternion R_Index_D_roatation;

        public Quaternion R_Middle_P_rotation; //R-right,M-Middle,P-Proximal

        public Quaternion R_Middle_I_rotation;

        public Quaternion R_Middle_D_roatation;

        public Quaternion R_Ring_P_rotation; //R-right,R-Ring,P-Proximal

        public Quaternion R_Ring_I_rotation;

        public Quaternion R_Ring_D_roatation;

        public Quaternion R_Little_P_rotation; //R-right,L-Little,P-Proximal

        public Quaternion R_Little_I_rotation;

        public Quaternion R_Little_D_roatation;


        // Use this for initialization

        void Start () {

            //獲取角色的Animator組(zǔ)件

            animator = transform.GetComponent();

            //通過Animator組件獲取右手(shǒu)手指的各個關節

            rightThumbProximal = animator.GetBoneTransform(HumanBodyBones.RightThumbProximal); 

            rightThumbIntermediate = animator.GetBoneTransform(HumanBodyBones.RightThumbIntermediate);

            rightThumbDistal = animator.GetBoneTransform(HumanBodyBones.RightThumbDistal);

            rightIndexProximal = animator.GetBoneTransform(HumanBodyBones.RightIndexProximal);

            rightIndexIntermediate = animator.GetBoneTransform(HumanBodyBones.RightIndexIntermediate);

            rightIndexDistal = animator.GetBoneTransform(HumanBodyBones.RightIndexDistal);

            rightMiddleProximal = animator.GetBoneTransform(HumanBodyBones.RightMiddleProximal);

            rightMiddleIntermediate = animator.GetBoneTransform(HumanBodyBones.RightMiddleIntermediate);

            rightMiddleDistal = animator.GetBoneTransform(HumanBodyBones.RightMiddleDistal);

            rightRingProximal = animator.GetBoneTransform(HumanBodyBones.RightRingProximal);

            rightRingIntermediate = animator.GetBoneTransform(HumanBodyBones.RightRingIntermediate);

            rightRingDistal = animator.GetBoneTransform(HumanBodyBones.RightRingDistal);

            rightLittleProximal = animator.GetBoneTransform(HumanBodyBones.RightLittleProximal);

            rightLittleIntermediate = animator.GetBoneTransform(HumanBodyBones.RightLittleIntermediate);

            rightLittleDistal = animator.GetBoneTransform(HumanBodyBones.RightLittleDistal);

        }


        // Update is called once per frame

        void Update () {

            //將(jiāng)從數據手(shǒu)套獲取到的旋轉量賦值給相應的手指關節的localRotaion就可以了

            rightThumbProximal.localRotation= R_Thumb_P_rotation;

            rightThumbIntermediate.localRotation = R_Thumb_I_rotation;

            rightThumbDistal.localRotation = R_Thumb_D_roatation;

            rightIndexProximal.localRotation = R_Index_P_rotation;

            rightIndexIntermediate.localRotation = R_Index_I_rotation;

            rightIndexDistal.localRotation = R_Index_D_roatation;

            rightMiddleProximal.localRotation = R_Middle_P_rotation;

            rightMiddleIntermediate.localRotation = R_Middle_I_rotation;

            rightMiddleDistal.localRotation = R_Middle_D_roatation;

            rightRingProximal.localRotation = R_Ring_P_rotation;

            rightRingIntermediate.localRotation = R_Ring_I_rotation;

            rightRingDistal.localRotation = R_Ring_D_roatation;

            rightLittleProximal.localRotation = R_Little_P_rotation;

            rightLittleIntermediate.localRotation = R_Little_I_rotation;

            rightLittleDistal.localRotation = R_Little_D_roatation;


        }

    }

     

    AV永久天堂网_奇米狠狠色_亚洲欧美日韩动漫_欧美日韩视频在线观看免费一区二区_日韩精品一二三区_国产AV网站18禁止人_久久久久久精品人妻免费网站不卡_国产最新视频_另类免费视频在线视频二区_久久精品免视国产