Exemplo n.º 1
0
 void SetFingerPoints(GestureResultRaw hand, wvr.WVR_SingleFinger_t finger, int startIndex)
 {
     hand.points[startIndex]     = WaveVR_Utils.GetPosition(finger.joint1);
     hand.points[startIndex + 1] = WaveVR_Utils.GetPosition(finger.joint2);
     hand.points[startIndex + 2] = WaveVR_Utils.GetPosition(finger.joint3);
     hand.points[startIndex + 3] = WaveVR_Utils.GetPosition(finger.tip);
 }
Exemplo n.º 2
0
    IEnumerator SpawnRenderModel()
    {
        while (true)
        {
            if (modelResource != null)
            {
                if (modelResource.parserReady)
                {
                    break;
                }
            }
            PrintDebugLog("SpawnRenderModel is waiting");
            yield return(wfef);
        }

        PrintDebugLog("Start to spawn all meshes!");

        if (modelResource == null)
        {
            PrintDebugLog("modelResource is null, skipping spawn objects");
            mLoadingState = LoadingState.LoadingState_NOT_LOADED;
            yield return(null);
        }

        string meshName = "";

        for (uint i = 0; i < modelResource.sectionCount; i++)
        {
            meshName = Marshal.PtrToStringAnsi(modelResource.FBXInfo[i].meshName);
            meshCom  = null;
            meshGO   = null;

            bool meshAlready = false;

            for (uint j = 0; j < i; j++)
            {
                string tmp = Marshal.PtrToStringAnsi(modelResource.FBXInfo[j].meshName);

                if (tmp.Equals(meshName))
                {
                    meshAlready = true;
                }
            }

            if (meshAlready)
            {
                PrintDebugLog(meshName + " is created! skip.");
                continue;
            }

            if (mergeToOneBone && modelResource.SectionInfo[i]._active)
            {
                meshName = "Merge_" + meshName;
            }
            updateMesh = new Mesh();
            meshCom    = new GameObject();
            meshCom.AddComponent <MeshRenderer>();
            meshCom.AddComponent <MeshFilter>();
            meshGO = Instantiate(meshCom);
            meshGO.transform.parent = this.transform;
            meshGO.name             = meshName;

            Matrix4x4 t = WaveVR_Utils.RigidTransform.toMatrix44(modelResource.FBXInfo[i].matrix);

            Vector3 x = WaveVR_Utils.GetPosition(t);
            meshGO.transform.localPosition = new Vector3(x.x, x.y, -x.z);

            meshGO.transform.localRotation = WaveVR_Utils.GetRotation(t);
            Vector3 r = meshGO.transform.localEulerAngles;
            meshGO.transform.localEulerAngles = new Vector3(-r.x, r.y, r.z);
            meshGO.transform.localScale       = WaveVR_Utils.GetScale(t);

            PrintDebugLog("i = " + i + " MeshGO = " + meshName + ", localPosition: " + meshGO.transform.localPosition.x + ", " + meshGO.transform.localPosition.y + ", " + meshGO.transform.localPosition.z);
            PrintDebugLog("i = " + i + " MeshGO = " + meshName + ", localRotation: " + meshGO.transform.localEulerAngles);
            PrintDebugLog("i = " + i + " MeshGO = " + meshName + ", localScale: " + meshGO.transform.localScale);

            var meshfilter = meshGO.GetComponent <MeshFilter>();
            updateMesh.Clear();
            updateMesh.vertices = modelResource.SectionInfo[i]._vectice;
            updateMesh.uv       = modelResource.SectionInfo[i]._uv;
            updateMesh.uv2      = modelResource.SectionInfo[i]._uv;
            updateMesh.colors32 = colors.ToArray();
            updateMesh.normals  = modelResource.SectionInfo[i]._normal;
            updateMesh.SetIndices(modelResource.SectionInfo[i]._indice, MeshTopology.Triangles, 0);
            updateMesh.name = meshName;
            if (meshfilter != null)
            {
                meshfilter.mesh = updateMesh;
            }
            var meshRenderer = meshGO.GetComponent <MeshRenderer>();
            if (meshRenderer != null)
            {
                if (ImgMaterial == null)
                {
                    PrintDebugLog("ImgMaterial is null");
                }
                meshRenderer.material             = ImgMaterial;
                meshRenderer.material.mainTexture = modelResource.modelTexture;
                meshRenderer.enabled = true;
            }

            if (meshName.Equals(emitterMeshName))
            {
                PrintDebugLog(meshName + " is found, set " + meshName + " active: true");
                meshGO.SetActive(true);
            }
            else if (meshName.Equals("__CM__Battery"))
            {
                isBatteryIndicatorReady = false;
                if (modelResource.isBatterySetting)
                {
                    if (modelResource.batteryTextureList != null)
                    {
                        batteryMR = meshGO.GetComponent <MeshRenderer>();
                        var mat = Resources.Load("TransparentMat") as Material;
                        if (mat != null)
                        {
                            batteryMR.material = mat;
                        }

                        batteryMR.material.mainTexture = modelResource.batteryTextureList[0].batteryTexture;
                        batteryMR.enabled       = true;
                        isBatteryIndicatorReady = true;
                    }
                }
                meshGO.SetActive(false);
                PrintDebugLog(meshName + " is found, set " + meshName + " active: false (waiting for update");
                batteryGO = meshGO;
            }
            else if (meshName == "__CM__TouchPad_Touch")
            {
                PrintDebugLog(meshName + " is found, set " + meshName + " active: false");
                meshGO.SetActive(false);
            }
            else
            {
                PrintDebugLog("set " + meshName + " active: " + modelResource.SectionInfo[i]._active);
                meshGO.SetActive(modelResource.SectionInfo[i]._active);
            }

            yield return(wfef);
        }
        PrintDebugLog("send " + deviceType + " ADAPTIVE_CONTROLLER_READY ");
        WaveVR_Utils.Event.Send(WaveVR_Utils.Event.ADAPTIVE_CONTROLLER_READY, deviceType);

        Resources.UnloadUnusedAssets();
        mLoadingState = LoadingState.LoadingState_LOADED;
    }
    //private float positionLerp = 0.1f, rotationLerp = 0.1f;
    public override void Process()
    {
        if (!ValidateParameters())
        {
            return;
        }

        // Save previous raycasted object.
        prevRaycastedObject = GetRaycastedObject();


        // ------------------- Raycast Actions begins -------------------
        if ((mPointerEventData == null) ||
            (mPointerEventData != null && !mPointerEventData.dragging))
        {
            ResetPointerEventData();
            GraphicRaycast();
            PhysicsRaycast();
        }
        // ------------------- Raycast Actions ends -------------------


        GameObject curr_raycasted_object = GetRaycastedObject();


        // ------------------- Check if pinching begins -------------------
        hasHandPoseData = WaveVR_GestureManager.Instance.GetHandPoseData(ref handPoseData);
        if (hasHandPoseData)
        {
            currentGestureRight = handPoseData.right.state.type;
            currentGestureLeft  = handPoseData.left.state.type;
        }
        else
        {
            currentGestureRight = WVR_HandPoseType.WVR_HandPoseType_Invalid;
            currentGestureLeft  = WVR_HandPoseType.WVR_HandPoseType_Invalid;
        }

        if (WaveVR_GestureManager.GestureFocusHand == WaveVR_GestureManager.EGestureHand.RIGHT)
        {
            enableEvent = (WaveVR_Utils.GetPosition(handPoseData.right.pinch.origin) != Vector3.zero);

            // Switch the focus hand to left.
            if ((currentGestureLeft == WVR_HandPoseType.WVR_HandPoseType_Pinch) && (handPoseData.left.pinch.strength >= m_PinchOnThreshold))
            {
                WaveVR_GestureManager.GestureFocusHand = WaveVR_GestureManager.EGestureHand.LEFT;
                return;
            }

            if (hasHandPoseData && (this.RightPinchSelector != null))
            {
                //this.RightPinchSelector.transform.position = Vector3.Lerp(this.RightPinchSelector.transform.position, WaveVR_Utils.GetPosition(handPoseData.right.pinch.origin), positionLerp);
                //this.RightPinchSelector.transform.rotation = Quaternion.Lerp(this.RightPinchSelector.transform.rotation, Quaternion.LookRotation(WaveVR_Utils.GetPosition(handPoseData.right.pinch.direction)), rotationLerp);
                this.RightPinchSelector.transform.position = WaveVR_Utils.GetPosition(handPoseData.right.pinch.origin);
                this.RightPinchSelector.transform.rotation = Quaternion.LookRotation(WaveVR_Utils.GetPosition(handPoseData.right.pinch.direction));
            }

            if (!isPinch)
            {
                if ((currentGestureRight == WVR_HandPoseType.WVR_HandPoseType_Pinch) && (handPoseData.right.pinch.strength >= m_PinchOnThreshold))
                {
                    pinchFrame++;
                    if (pinchFrame > PINCH_FRAME_COUNT)
                    {
                        isPinch = true;
                        gestureBeam.SetEffectiveBeam(true);
                        gesturePointer.SetEffectivePointer(true);
                        unpinchFrame = 0;
                    }
                }
            }
            else
            {
                if ((currentGestureRight != WVR_HandPoseType.WVR_HandPoseType_Pinch) || (handPoseData.right.pinch.strength < m_PinchOffThreshold))
                {
                    unpinchFrame++;
                    if (unpinchFrame > PINCH_FRAME_COUNT)
                    {
                        DEBUG("Pinch is released. currentGestureRight: " + currentGestureRight + ", strength: " + handPoseData.right.pinch.strength);
                        isPinch = false;
                        gestureBeam.SetEffectiveBeam(false);
                        gesturePointer.SetEffectivePointer(false);
                        pinchFrame = 0;
                    }
                }
            }
        }
        else         // GestureFocusHand == LEFT
        {
            enableEvent = (WaveVR_Utils.GetPosition(handPoseData.left.pinch.origin) != Vector3.zero);

            // Switch the focus hand to right.
            if ((currentGestureRight == WVR_HandPoseType.WVR_HandPoseType_Pinch) && (handPoseData.right.pinch.strength >= m_PinchOnThreshold))
            {
                WaveVR_GestureManager.GestureFocusHand = WaveVR_GestureManager.EGestureHand.RIGHT;
                return;
            }

            if (hasHandPoseData && (this.LeftPinchSelector != null))
            {
                //this.LeftPinchSelector.transform.position = Vector3.Lerp(this.LeftPinchSelector.transform.position, WaveVR_Utils.GetPosition(handPoseData.left.pinch.origin), positionLerp);
                //this.LeftPinchSelector.transform.rotation = Quaternion.Lerp(this.LeftPinchSelector.transform.rotation, Quaternion.LookRotation(WaveVR_Utils.GetPosition(handPoseData.left.pinch.direction)), rotationLerp);
                this.LeftPinchSelector.transform.position = WaveVR_Utils.GetPosition(handPoseData.left.pinch.origin);
                this.LeftPinchSelector.transform.rotation = Quaternion.LookRotation(WaveVR_Utils.GetPosition(handPoseData.left.pinch.direction));
            }

            if (!isPinch)
            {
                if ((currentGestureLeft == WVR_HandPoseType.WVR_HandPoseType_Pinch) && (handPoseData.left.pinch.strength >= m_PinchOnThreshold))
                {
                    pinchFrame++;
                    if (pinchFrame > PINCH_FRAME_COUNT)
                    {
                        isPinch = true;
                        gestureBeam.SetEffectiveBeam(true);
                        gesturePointer.SetEffectivePointer(true);
                        unpinchFrame = 0;
                    }
                }
            }
            else
            {
                if ((currentGestureLeft != WVR_HandPoseType.WVR_HandPoseType_Pinch) || (handPoseData.left.pinch.strength < m_PinchOffThreshold))
                {
                    unpinchFrame++;
                    if (unpinchFrame > PINCH_FRAME_COUNT)
                    {
                        DEBUG("Pinch is released. currentGestureLeft: " + currentGestureLeft + ", strength: " + handPoseData.left.pinch.strength);
                        isPinch = false;
                        gestureBeam.SetEffectiveBeam(false);
                        gesturePointer.SetEffectivePointer(false);
                        pinchFrame = 0;
                    }
                }
            }
        }
        // ------------------- Check if pinching ends -------------------


        if (WaveVR_GestureManager.GestureFocusHand == WaveVR_GestureManager.EGestureHand.RIGHT)
        {
            ActivateBeamPointer(WaveVR_GestureManager.EGestureHand.LEFT, false);

            bool valid_pose = IWaveVR_BonePose.Instance.IsHandPoseValid(WaveVR_GestureManager.EGestureHand.RIGHT);
            ActivateBeamPointer(WaveVR_GestureManager.EGestureHand.RIGHT, valid_pose);
        }
        else
        {
            ActivateBeamPointer(WaveVR_GestureManager.EGestureHand.RIGHT, false);

            bool valid_pose = IWaveVR_BonePose.Instance.IsHandPoseValid(WaveVR_GestureManager.EGestureHand.LEFT);
            ActivateBeamPointer(WaveVR_GestureManager.EGestureHand.LEFT, valid_pose);
        }

        if (curr_raycasted_object != null)
        {
            gesturePointer.OnPointerEnter(curr_raycasted_object, Vector3.zero, false);
        }
        else
        {
            gesturePointer.OnPointerExit(prevRaycastedObject);
        }


        // ------------------- Event Handling begins -------------------
        if (enableEvent)
        {
            OnGraphicPointerEnterExit();
            OnPhysicsPointerEnterExit();

            OnPointerHover();

            if (!mPointerEventData.eligibleForClick)
            {
                if (isPinch)
                {
                    OnPointerDown();
                }
            }
            else if (mPointerEventData.eligibleForClick)
            {
                if (isPinch)
                {
                    // Down before, and receives the selected gesture continuously.
                    OnPointerDrag();
                }
                else
                {
                    DEBUG("Focus hand: " + WaveVR_GestureManager.GestureFocusHand
                          + ", right strength: " + handPoseData.right.pinch.strength
                          + ", left strength: " + handPoseData.left.pinch.strength);
                    // Down before, but not receive the selected gesture.
                    OnPointerUp();
                }
            }
        }
        // ------------------- Event Handling ends -------------------


        /*Vector3 intersection_position = GetIntersectionPosition (mPointerEventData.pointerCurrentRaycast);
         * if (WaveVR_GestureManager.GestureFocusHand == WaveVR_GestureManager.EGestureHand.RIGHT)
         *      WaveVR_RaycastResultProvider.Instance.SetRaycastResult(WaveVR_Controller.EDeviceType.Dominant, mPointerEventData.pointerCurrentRaycast.gameObject, intersection_position);
         * if (WaveVR_GestureManager.GestureFocusHand == WaveVR_GestureManager.EGestureHand.LEFT)
         *      WaveVR_RaycastResultProvider.Instance.SetRaycastResult(WaveVR_Controller.EDeviceType.NonDominant, mPointerEventData.pointerCurrentRaycast.gameObject, intersection_position);*/
    }
Exemplo n.º 4
0
    IEnumerator checkParams()
    {
        while (true)
        {
            if (!bLoadMesh)
            {
                yield return(wfef);
            }
            else
            {
                break;
            }
        }
        string meshName = "";

        for (uint i = 0; i < sectionCount; i++)
        {
            meshName   = Marshal.PtrToStringAnsi(FBXInfo[i].meshName);
            meshCom    = null;
            meshGO     = null;
            updateMesh = new Mesh();

            meshCom = Resources.Load("MeshComponent") as GameObject;
            meshGO  = Instantiate(meshCom);
            meshGO.transform.parent = this.transform;
            meshGO.name             = meshName;
            Matrix4x4 t = WaveVR_Utils.RigidTransform.toMatrix44(FBXInfo[i].matrix);

            Vector3 x = WaveVR_Utils.GetPosition(t);
            meshGO.transform.localPosition = new Vector3(-x.x, x.y, x.z);

            Log.d(LOG_TAG, " MeshGO = " + meshName + ", localPosition: " + meshGO.transform.localPosition.x + ", " + meshGO.transform.localPosition.y + ", " + meshGO.transform.localPosition.z);
            meshGO.transform.localRotation = WaveVR_Utils.GetRotation(t);

            float   a = 0f;
            Vector3 b = Vector3.zero;
            meshGO.transform.localRotation.ToAngleAxis(out a, out b);
            Log.d(LOG_TAG, " MeshGO = " + meshName + ", localRotation: " + b);
            //Log.d(LOG_TAG, " MeshGO = " + meshName + ", localRotation: " + meshGO.transform.localRotation);
            meshGO.transform.localScale = WaveVR_Utils.GetScale(t);
            Log.d(LOG_TAG, " MeshGO = " + meshName + ", localScale: " + meshGO.transform.localScale);

            meshGO.transform.Rotate(new Vector3(0, 180, 0));

            var meshfilter = meshGO.GetComponent <MeshFilter>();

            updateMesh.Clear();

            updateMesh.vertices = SectionInfo[i]._vectice;
            updateMesh.uv       = SectionInfo[i]._uv;
            updateMesh.uv2      = SectionInfo[i]._uv;
            updateMesh.colors32 = colors.ToArray();
            updateMesh.normals  = SectionInfo[i]._normal;
            updateMesh.SetIndices(SectionInfo[i]._indice, MeshTopology.Triangles, 0);
            updateMesh.name = meshName;

            meshfilter.mesh = updateMesh;

            var meshRenderer = meshGO.GetComponent <MeshRenderer>();
            meshRenderer.material.mainTexture = MatImage;
            meshRenderer.enabled = true;
        }

        WaveVR_Utils.Event.Send(WaveVR_Utils.Event.ADAPTIVE_CONTROLLER_READY, this.device);
        cleanNativeData();
        Resources.UnloadUnusedAssets();
    }
    private void UpdateRightHandTrackingData()
    {
        // Right wrist - RIGHT_WRIST
        rtWristRight.update(handSkeletonData.right.wrist.PoseMatrix);
        Vector3    RIGHT_WRIST_Pos = rtWristRight.pos;
        Quaternion RIGHT_WRIST_Rot = rtWristRight.rot;

        boneDatas [(int)Bones.RIGHT_WRIST].SetPosition(RIGHT_WRIST_Pos);
        boneDatas [(int)Bones.RIGHT_WRIST].SetRotation(RIGHT_WRIST_Rot);

        // Right thumb joint1 - RIGHT_THUMB_JOINT1
        Vector3    RIGHT_THUMB_JOINT1_Pos = WaveVR_Utils.GetPosition(handSkeletonData.right.thumb.joint1);
        Quaternion RIGHT_THUMB_JOINT1_Rot = Quaternion.LookRotation(RIGHT_THUMB_JOINT1_Pos - RIGHT_WRIST_Pos);

        boneDatas [(int)Bones.RIGHT_THUMB_JOINT1].SetPosition(RIGHT_THUMB_JOINT1_Pos);
        boneDatas [(int)Bones.RIGHT_THUMB_JOINT1].SetRotation(RIGHT_THUMB_JOINT1_Rot);

        // Right thumb joint2 - RIGHT_THUMB_JOINT2
        Vector3    RIGHT_THUMB_JOINT2_Pos = WaveVR_Utils.GetPosition(handSkeletonData.right.thumb.joint2);
        Quaternion RIGHT_THUMB_JOINT2_Rot = Quaternion.LookRotation(RIGHT_THUMB_JOINT2_Pos - RIGHT_THUMB_JOINT1_Pos);

        boneDatas [(int)Bones.RIGHT_THUMB_JOINT2].SetPosition(RIGHT_THUMB_JOINT2_Pos);
        boneDatas [(int)Bones.RIGHT_THUMB_JOINT2].SetRotation(RIGHT_THUMB_JOINT2_Rot);

        // Right thumb joint3 - RIGHT_THUMB_JOINT3
        Vector3    RIGHT_THUMB_JOINT3_Pos = WaveVR_Utils.GetPosition(handSkeletonData.right.thumb.joint3);
        Quaternion RIGHT_THUMB_JOINT3_Rot = Quaternion.LookRotation(RIGHT_THUMB_JOINT3_Pos - RIGHT_THUMB_JOINT2_Pos);

        boneDatas [(int)Bones.RIGHT_THUMB_JOINT3].SetPosition(RIGHT_THUMB_JOINT3_Pos);
        boneDatas [(int)Bones.RIGHT_THUMB_JOINT3].SetRotation(RIGHT_THUMB_JOINT3_Rot);

        // Right thumb tip - RIGHT_THUMB_TIP
        Vector3    RIGHT_THUMB_TIP_Pos = WaveVR_Utils.GetPosition(handSkeletonData.right.thumb.tip);
        Quaternion RIGHT_THUMB_TIP_Rot = Quaternion.LookRotation(RIGHT_THUMB_TIP_Pos - RIGHT_THUMB_JOINT3_Pos);

        boneDatas [(int)Bones.RIGHT_THUMB_TIP].SetPosition(RIGHT_THUMB_TIP_Pos);
        boneDatas [(int)Bones.RIGHT_THUMB_TIP].SetRotation(RIGHT_THUMB_TIP_Rot);

        // Right index joint1 - RIGHT_INDEX_JOINT1
        Vector3    RIGHT_INDEX_JOINT1_Pos = WaveVR_Utils.GetPosition(handSkeletonData.right.index.joint1);
        Quaternion RIGHT_INDEX_JOINT1_Rot = Quaternion.LookRotation(RIGHT_INDEX_JOINT1_Pos - RIGHT_WRIST_Pos);

        boneDatas [(int)Bones.RIGHT_INDEX_JOINT1].SetPosition(RIGHT_INDEX_JOINT1_Pos);
        boneDatas [(int)Bones.RIGHT_INDEX_JOINT1].SetRotation(RIGHT_INDEX_JOINT1_Rot);

        // Right index joint2 - RIGHT_INDEX_JOINT2
        Vector3    RIGHT_INDEX_JOINT2_Pos = WaveVR_Utils.GetPosition(handSkeletonData.right.index.joint2);
        Quaternion RIGHT_INDEX_JOINT2_Rot = Quaternion.LookRotation(RIGHT_INDEX_JOINT2_Pos - RIGHT_INDEX_JOINT1_Pos);

        boneDatas [(int)Bones.RIGHT_INDEX_JOINT2].SetPosition(RIGHT_INDEX_JOINT2_Pos);
        boneDatas [(int)Bones.RIGHT_INDEX_JOINT2].SetRotation(RIGHT_INDEX_JOINT2_Rot);

        // Right index joint3 - RIGHT_INDEX_JOINT3
        Vector3    RIGHT_INDEX_JOINT3_Pos = WaveVR_Utils.GetPosition(handSkeletonData.right.index.joint3);
        Quaternion RIGHT_INDEX_JOINT3_Rot = Quaternion.LookRotation(RIGHT_INDEX_JOINT3_Pos, RIGHT_INDEX_JOINT2_Pos);

        boneDatas [(int)Bones.RIGHT_INDEX_JOINT3].SetPosition(RIGHT_INDEX_JOINT3_Pos);
        boneDatas [(int)Bones.RIGHT_INDEX_JOINT3].SetRotation(RIGHT_INDEX_JOINT3_Rot);

        // Right index tip - RIGHT_INDEX_TIP
        Vector3    RIGHT_INDEX_TIP_Pos = WaveVR_Utils.GetPosition(handSkeletonData.right.index.tip);
        Quaternion RIGHT_INDEX_TIP_Rot = Quaternion.LookRotation(RIGHT_INDEX_TIP_Pos - RIGHT_INDEX_JOINT3_Pos);

        boneDatas [(int)Bones.RIGHT_INDEX_TIP].SetPosition(RIGHT_INDEX_TIP_Pos);
        boneDatas [(int)Bones.RIGHT_INDEX_TIP].SetRotation(RIGHT_INDEX_TIP_Rot);

        // Right middle joint1 - RIGHT_MIDDLE_JOINT1
        Vector3    RIGHT_MIDDLE_JOINT1_Pos = WaveVR_Utils.GetPosition(handSkeletonData.right.middle.joint1);
        Quaternion RIGHT_MIDDLE_JOINT1_Rot = Quaternion.LookRotation(RIGHT_MIDDLE_JOINT1_Pos - RIGHT_WRIST_Pos);

        boneDatas [(int)Bones.RIGHT_MIDDLE_JOINT1].SetPosition(RIGHT_MIDDLE_JOINT1_Pos);
        boneDatas [(int)Bones.RIGHT_MIDDLE_JOINT1].SetRotation(RIGHT_MIDDLE_JOINT1_Rot);

        // Right middle joint2 - RIGHT_MIDDLE_JOINT2
        Vector3    RIGHT_MIDDLE_JOINT2_Pos = WaveVR_Utils.GetPosition(handSkeletonData.right.middle.joint2);
        Quaternion RIGHT_MIDDLE_JOINT2_Rot = Quaternion.LookRotation(RIGHT_MIDDLE_JOINT2_Pos - RIGHT_MIDDLE_JOINT1_Pos);

        boneDatas [(int)Bones.RIGHT_MIDDLE_JOINT2].SetPosition(RIGHT_MIDDLE_JOINT2_Pos);
        boneDatas [(int)Bones.RIGHT_MIDDLE_JOINT2].SetRotation(RIGHT_MIDDLE_JOINT2_Rot);

        // Right middle joint3 - RIGHT_MIDDLE_JOINT3
        Vector3    RIGHT_MIDDLE_JOINT3_Pos = WaveVR_Utils.GetPosition(handSkeletonData.right.middle.joint3);
        Quaternion RIGHT_MIDDLE_JOINT3_Rot = Quaternion.LookRotation(RIGHT_MIDDLE_JOINT3_Pos - RIGHT_MIDDLE_JOINT2_Pos);

        boneDatas [(int)Bones.RIGHT_MIDDLE_JOINT3].SetPosition(RIGHT_MIDDLE_JOINT3_Pos);
        boneDatas [(int)Bones.RIGHT_MIDDLE_JOINT3].SetRotation(RIGHT_MIDDLE_JOINT3_Rot);

        // Right middle tip - RIGHT_MIDDLE_TIP
        Vector3    RIGHT_MIDDLE_TIP_Pos = WaveVR_Utils.GetPosition(handSkeletonData.right.middle.tip);
        Quaternion RIGHT_MIDDLE_TIP_Rot = Quaternion.LookRotation(RIGHT_MIDDLE_TIP_Pos - RIGHT_MIDDLE_JOINT3_Pos);

        boneDatas [(int)Bones.RIGHT_MIDDLE_TIP].SetPosition(RIGHT_MIDDLE_TIP_Pos);
        boneDatas [(int)Bones.RIGHT_MIDDLE_TIP].SetRotation(RIGHT_MIDDLE_TIP_Rot);

        // Right ring joint1 - RIGHT_RING_JOINT1
        Vector3    RIGHT_RING_JOINT1_Pos = WaveVR_Utils.GetPosition(handSkeletonData.right.ring.joint1);
        Quaternion RIGHT_RING_JOINT1_Rot = Quaternion.LookRotation(RIGHT_RING_JOINT1_Pos - RIGHT_WRIST_Pos);

        boneDatas [(int)Bones.RIGHT_RING_JOINT1].SetPosition(RIGHT_RING_JOINT1_Pos);
        boneDatas [(int)Bones.RIGHT_RING_JOINT1].SetRotation(RIGHT_RING_JOINT1_Rot);

        // Right ring joint2 - RIGHT_RING_JOINT2
        Vector3    RIGHT_RING_JOINT2_Pos = WaveVR_Utils.GetPosition(handSkeletonData.right.ring.joint2);
        Quaternion RIGHT_RING_JOINT2_Rot = Quaternion.LookRotation(RIGHT_RING_JOINT2_Pos - RIGHT_RING_JOINT1_Pos);

        boneDatas [(int)Bones.RIGHT_RING_JOINT2].SetPosition(RIGHT_RING_JOINT2_Pos);
        boneDatas [(int)Bones.RIGHT_RING_JOINT2].SetRotation(RIGHT_RING_JOINT2_Rot);

        // Right ring joint3 - RIGHT_RING_JOINT3
        Vector3    RIGHT_RING_JOINT3_Pos = WaveVR_Utils.GetPosition(handSkeletonData.right.ring.joint3);
        Quaternion RIGHT_RING_JOINT3_Rot = Quaternion.LookRotation(RIGHT_RING_JOINT3_Pos - RIGHT_RING_JOINT2_Pos);

        boneDatas [(int)Bones.RIGHT_RING_JOINT3].SetPosition(RIGHT_RING_JOINT3_Pos);
        boneDatas [(int)Bones.RIGHT_RING_JOINT3].SetRotation(RIGHT_RING_JOINT3_Rot);

        // Right ring tip - RIGHT_RING_TIP
        Vector3    RIGHT_RING_TIP_Pos = WaveVR_Utils.GetPosition(handSkeletonData.right.ring.tip);
        Quaternion RIGHT_RING_TIP_Rot = Quaternion.LookRotation(RIGHT_RING_TIP_Pos - RIGHT_RING_JOINT3_Pos);

        boneDatas [(int)Bones.RIGHT_RING_TIP].SetPosition(RIGHT_RING_TIP_Pos);
        boneDatas [(int)Bones.RIGHT_RING_TIP].SetRotation(RIGHT_RING_TIP_Rot);

        // Right pinky joint1 - RIGHT_PINKY_JOINT1
        Vector3    RIGHT_PINKY_JOINT1_Pos = WaveVR_Utils.GetPosition(handSkeletonData.right.pinky.joint1);
        Quaternion RIGHT_PINKY_JOINT1_Rot = Quaternion.LookRotation(RIGHT_PINKY_JOINT1_Pos - RIGHT_WRIST_Pos);

        boneDatas [(int)Bones.RIGHT_PINKY_JOINT1].SetPosition(RIGHT_PINKY_JOINT1_Pos);
        boneDatas [(int)Bones.RIGHT_PINKY_JOINT1].SetRotation(RIGHT_PINKY_JOINT1_Rot);

        // Right pinky joint2 - RIGHT_PINKY_JOINT2
        Vector3    RIGHT_PINKY_JOINT2_Pos = WaveVR_Utils.GetPosition(handSkeletonData.right.pinky.joint2);
        Quaternion RIGHT_PINKY_JOINT2_Rot = Quaternion.LookRotation(RIGHT_PINKY_JOINT2_Pos - RIGHT_PINKY_JOINT1_Pos);

        boneDatas [(int)Bones.RIGHT_PINKY_JOINT2].SetPosition(RIGHT_PINKY_JOINT2_Pos);
        boneDatas [(int)Bones.RIGHT_PINKY_JOINT2].SetRotation(RIGHT_PINKY_JOINT2_Rot);

        // Right pinky joint3 - RIGHT_PINKY_JOINT3
        Vector3    RIGHT_PINKY_JOINT3_Pos = WaveVR_Utils.GetPosition(handSkeletonData.right.pinky.joint3);
        Quaternion RIGHT_PINKY_JOINT3_Rot = Quaternion.LookRotation(RIGHT_PINKY_JOINT3_Pos - RIGHT_PINKY_JOINT2_Pos);

        boneDatas [(int)Bones.RIGHT_PINKY_JOINT3].SetPosition(RIGHT_PINKY_JOINT3_Pos);
        boneDatas [(int)Bones.RIGHT_PINKY_JOINT3].SetRotation(RIGHT_PINKY_JOINT3_Rot);

        // Right pinky tip - RIGHT_PINKY_TIP
        Vector3    RIGHT_PINKY_TIP_Pos = WaveVR_Utils.GetPosition(handSkeletonData.right.pinky.tip);
        Quaternion RIGHT_PINKY_TIP_Rot = Quaternion.LookRotation(RIGHT_PINKY_TIP_Pos - RIGHT_PINKY_JOINT3_Pos);

        boneDatas [(int)Bones.RIGHT_PINKY_TIP].SetPosition(RIGHT_PINKY_TIP_Pos);
        boneDatas [(int)Bones.RIGHT_PINKY_TIP].SetRotation(RIGHT_PINKY_TIP_Rot);
    }
Exemplo n.º 6
0
    void spawnMesh()
    {
        if (!bLoadMesh)
        {
            PrintDebugLog("bLoadMesh is false, skipping spawn objects");
            return;
        }
        string meshName = "";

        for (uint i = 0; i < sectionCount; i++)
        {
            meshName = Marshal.PtrToStringAnsi(FBXInfo[i].meshName);
            meshCom  = null;
            meshGO   = null;

            updateMesh = new Mesh();
            meshCom    = new GameObject();
            meshCom.AddComponent <MeshRenderer>();
            meshCom.AddComponent <MeshFilter>();
            //      meshCom = Resources.Load("MeshComponent") as GameObject;
            meshGO = Instantiate(meshCom);
            meshGO.transform.parent = this.transform;
            meshGO.name             = meshName;
            Matrix4x4 t = WaveVR_Utils.RigidTransform.toMatrix44(FBXInfo[i].matrix);

            Vector3 x = WaveVR_Utils.GetPosition(t);
            meshGO.transform.localPosition = new Vector3(-x.x, x.y, x.z);

            PrintDebugLog("i = " + i + " MeshGO = " + meshName + ", localPosition: " + meshGO.transform.localPosition.x + ", " + meshGO.transform.localPosition.y + ", " + meshGO.transform.localPosition.z);
            meshGO.transform.localRotation = WaveVR_Utils.GetRotation(t);

            float   a = 0f;
            Vector3 b = Vector3.zero;
            meshGO.transform.localRotation.ToAngleAxis(out a, out b);
            PrintDebugLog("i = " + i + " MeshGO = " + meshName + ", localRotation: " + b);
            //PrintDebugLog(" MeshGO = " + meshName + ", localRotation: " + meshGO.transform.localRotation);
            meshGO.transform.localScale = WaveVR_Utils.GetScale(t);
            PrintDebugLog("i = " + i + " MeshGO = " + meshName + ", localScale: " + meshGO.transform.localScale);
            meshGO.transform.Rotate(new Vector3(0, 180, 0));

            var meshfilter = meshGO.GetComponent <MeshFilter>();

            updateMesh.Clear();
            updateMesh.vertices = SectionInfo[i]._vectice;
            updateMesh.uv       = SectionInfo[i]._uv;
            updateMesh.uv2      = SectionInfo[i]._uv;
            updateMesh.colors32 = colors.ToArray();
            updateMesh.normals  = SectionInfo[i]._normal;
            updateMesh.SetIndices(SectionInfo[i]._indice, MeshTopology.Triangles, 0);
            updateMesh.name = meshName;
            if (meshfilter != null)
            {
                meshfilter.mesh = updateMesh;
            }

            var meshRenderer = meshGO.GetComponent <MeshRenderer>();
            if (meshRenderer != null)
            {
                meshRenderer.material             = ImgMaterial;
                meshRenderer.material.mainTexture = MatImage;
                meshRenderer.enabled = true;
            }

            if (meshName == "__CM__TouchPad_Touch")
            {
                meshGO.SetActive(false);
            }
        }
        WaveVR_Utils.Event.Send(WaveVR_Utils.Event.ADAPTIVE_CONTROLLER_READY, deviceType);

        cleanNativeData();
        Resources.UnloadUnusedAssets();
    }