Kinect虚拟试衣


Kinect虚拟试衣_第1张图片


这个案例实现也比较简单


要做kinect开发,首先必须挂kinectManger这个类


因为开发中涉及到手势,因此需要挂上kinectGestures这个类


接下来就是一个类CategorySelector.cs,这个类需要实现KinectGestures.GestureListenerInterface这个接口,这个接口实现中监视某个手势和手势识别完成后


监视哪些手势:
Kinect虚拟试衣_第2张图片


手势完成后干什么(具体的业务都写在这)
Kinect虚拟试衣_第3张图片


下面几张截图来自:ModelSelector.cs这个类,这个类主要负责换模型


Kinect虚拟试衣_第4张图片


Kinect虚拟试衣_第5张图片


一定要注意,衣服身上需要挂AvatarController和AvatarScaler 组件,如果衣服预设体身上没有挂则需要通过程序动态的Add上

    private void LoadModel(string modelDir)
    {
        string modelPath = modelCategory + "/" + modelDir + "/model";
        print(modelPath);
        UnityEngine.Object modelPrefab = Resources.Load(modelPath, typeof(GameObject));
        if(modelPrefab == null)
            return;      
        if(selModel != null) 
        {
            GameObject.Destroy(selModel);
        }
        selModel = (GameObject)GameObject.Instantiate(modelPrefab, Vector3.zero, Quaternion.Euler(0, 180f, 0));
        selModel.name = "Model" + modelDir;

        AvatarController ac = selModel.GetComponent();
        if (ac == null) 
        {
            ac = selModel.AddComponent();
            ac.playerIndex = playerIndex;

            ac.mirroredMovement = true;
            ac.verticalMovement = true;
            ac.smoothFactor = 0f;
        }

        ac.posRelativeToCamera = modelRelativeToCamera;
        ac.posRelOverlayColor = (foregroundCamera != null);

        KinectManager km = KinectManager.Instance;
        //ac.Awake();

        long userId = km.GetUserIdByIndex(playerIndex);
        if(userId != 0)
        {
            ac.SuccessfulCalibration(userId);
        }

        km.avatarControllers.Clear(); // = new List();
        km.avatarControllers.Add(ac);

        AvatarScaler scaler = selModel.GetComponent();
        if (scaler == null) 
        {
            scaler = selModel.AddComponent();
            scaler.playerIndex = playerIndex;
            scaler.mirroredAvatar = true;
            scaler.bodyScaleFactor = bodyScaleFactor;
            scaler.continuousScaling = continuousScaling;
        }

        scaler.foregroundCamera = foregroundCamera;
        //scaler.debugText = debugText;
        //scaler.Start();
    }

Kinect虚拟试衣_第6张图片




FR:海涛高软(QQ技术交流群:386476712)

你可能感兴趣的:(kinect2-0)