public NxrLaserPointer GetControllerLaser(InteractionManager.NACTION_HAND_TYPE hAND_TYPE)
 {
     if (DualCtrlDeviceDict.ContainsKey(hAND_TYPE))
     {
         NxrTrackedDevice nxrTrackedDevice = DualCtrlDeviceDict[hAND_TYPE];
         return(nxrTrackedDevice.GetLaserPointer());
     }
     return(null);
 }
Example #2
0
 // Use this for initialization
 void OnEnable()
 {
     trackedDevice = GetComponentInParent <NxrTrackedDevice>();
     touchpad      = transform.Find("buttons/button_touchpad");
     menu          = transform.Find("buttons/button_menu");
     system        = transform.Find("buttons/button_system");
     grip_left     = transform.Find("buttons/button_grip_left");
     grip_right    = transform.Find("buttons/button_grip_right");
     trigger       = transform.Find("buttons/button_trigger");
 }
        private void LoadDefaultCtrl(string prefabName)
        {
            GameObject obj = GameObject.Find(prefabName);

            if (!obj)
            {
                GameObject objPrefab = (GameObject)Resources.Load(string.Concat("CustomModelPrefabs/", prefabName));
                if (!objPrefab)
                {
                    Debug.LogError("The prefab was not created successfully");
                }
                GameObject mGameObject =
                    (GameObject)Instantiate(objPrefab, Vector3.zero, Quaternion.identity);
                var leftObj = mGameObject.transform.GetChild(0).gameObject;
                leftObj.name = "LeftModel";
                var rightObj = Instantiate(leftObj, mGameObject.transform) as GameObject;
                rightObj.name = "RightModel";
                NxrTrackedDevice trackedDeviceLeft = leftObj.GetComponent <NxrTrackedDevice>();
                trackedDeviceLeft.deviceType = NxrInstantNativeApi.HoloeverDeviceType.LeftController;
                NxrTrackedDevice trackedDeviceRight = rightObj.GetComponent <NxrTrackedDevice>();
                trackedDeviceLeft.deviceType = NxrInstantNativeApi.HoloeverDeviceType.RightController;
                if (!DualCtrlDeviceDict.ContainsKey(InteractionManager.NACTION_HAND_TYPE.HAND_LEFT))
                {
                    DualCtrlDeviceDict.Add(InteractionManager.NACTION_HAND_TYPE.HAND_LEFT, trackedDeviceLeft);
                }
                else
                {
                    DualCtrlDeviceDict[InteractionManager.NACTION_HAND_TYPE.HAND_LEFT] = trackedDeviceLeft;
                }

                if (!DualCtrlDeviceDict.ContainsKey(InteractionManager.NACTION_HAND_TYPE.HAND_RIGHT))
                {
                    DualCtrlDeviceDict.Add(InteractionManager.NACTION_HAND_TYPE.HAND_RIGHT, trackedDeviceRight);
                }
                else
                {
                    DualCtrlDeviceDict[InteractionManager.NACTION_HAND_TYPE.HAND_RIGHT] = trackedDeviceRight;
                }

                NxrViewer.Instance.SwitchControllerMode(true);
            }
        }
        private void CreateControllerModel(NxrInstantNativeApi.HoloeverDeviceType deviceType, string objName,
                                           InteractionManager.ControllerConfig mControllerConfig)
        {
            string objPath = mControllerConfig.objPath;

            if (deviceType == NxrInstantNativeApi.HoloeverDeviceType.LeftController)
            {
                objPath = mControllerConfig.leftCtrlObjPath;
            }
            else if (deviceType == NxrInstantNativeApi.HoloeverDeviceType.RightController)
            {
                objPath = mControllerConfig.rightCtrlObjPath;
            }

            if (objPath == null)
            {
                Debug.LogError("CreateControllerModel failed, objPath is null......" + objName);
                return;
            }

            GameObject      go = new GameObject(objName);
            NxrLaserPointer mNxrLaserPointer = go.AddComponent <NxrLaserPointer>();

            mNxrLaserPointer.deviceType = deviceType;
            go.transform.SetParent(transformCache);
            go.transform.localScale    = Vector3.one;
            go.transform.localPosition = new Vector3(0, 0, 0);
            go.transform.localRotation = new Quaternion(0, 0, 0, 1);

            GameObject modelGOParent = new GameObject("model_P");

            modelGOParent.transform.localScale    = new Vector3(-1, 1, 1);
            modelGOParent.transform.localPosition = new Vector3(0, 0, 0);
            modelGOParent.transform.localRotation = new Quaternion(0, 0, 0, 1);
            modelGOParent.transform.SetParent(go.transform);

            GameObject modelGO = new GameObject("model");

            modelGO.transform.SetParent(modelGOParent.transform);
            modelGO.transform.localScale = new Vector3(mControllerConfig.modelScale[0]
                                                       , mControllerConfig.modelScale[1], mControllerConfig.modelScale[2]);
            modelGO.transform.localRotation = Quaternion.Euler(mControllerConfig.modelRotation[0],
                                                               mControllerConfig.modelRotation[1], mControllerConfig.modelRotation[2]);
            modelGO.transform.localPosition = new Vector3(mControllerConfig.modelPosition[0]
                                                          , mControllerConfig.modelPosition[1], mControllerConfig.modelPosition[2]);
            modelGO.AddComponent <NxrControllerModel>();

            //  string objPath = "/system/etc/Objs/housing_bott.obj";
            Debug.Log("objPath=" + objPath);

            ObjModelLoader mObjModelLoader = go.GetComponent <ObjModelLoader>();

            if (mObjModelLoader == null)
            {
                go.AddComponent <ObjMaterial>();
                mObjModelLoader = go.AddComponent <ObjModelLoader>();
            }

            mObjModelLoader.LoadObjFile(objPath, modelGO.transform);

            GameObject powerGO = new GameObject("Power");

            powerGO.transform.SetParent(go.transform);

            MeshRenderer powerMeshRenderer = powerGO.AddComponent <MeshRenderer>();
            Mesh         quadMesh          = new Mesh();

            quadMesh.name = "QUAD";
            float quadSize = 0.5f;

            quadMesh.vertices = new Vector3[]
            {
                new Vector3(-1 * quadSize, -1 * quadSize, 0),
                new Vector3(-1 * quadSize, 1 * quadSize, 0),
                new Vector3(1 * quadSize, 1 * quadSize, 0),
                new Vector3(1 * quadSize, -1 * quadSize, 0)
            };
            quadMesh.uv = new Vector2[]
            {
                new Vector2(0, 0),
                new Vector2(0, 1),
                new Vector2(1, 1),
                new Vector2(1, 0)
            };
            int[] triangles = { 0, 1, 2, 0, 2, 3 };
            quadMesh.triangles = triangles;

            powerGO.AddComponent <MeshFilter>().mesh = quadMesh;
            powerGO.AddComponent <MeshCollider>();
            powerGO.AddComponent <HoloeverControllerPower>();

            powerGO.transform.localPosition = new Vector3(mControllerConfig.batteryPosition[0],
                                                          mControllerConfig.batteryPosition[1]
                                                          , mControllerConfig.batteryPosition[2]);
            powerGO.transform.localRotation = Quaternion.Euler(mControllerConfig.batteryRotation[0],
                                                               mControllerConfig.batteryRotation[1]
                                                               , mControllerConfig.batteryRotation[2]);
            powerGO.transform.localScale = new Vector3(mControllerConfig.batteryScale[0],
                                                       mControllerConfig.batteryScale[1]
                                                       , mControllerConfig.batteryScale[2]);

            // 射线起点
            mNxrLaserPointer.SetHolderLocalPosition(new Vector3(mControllerConfig.rayStartPosition[0],
                                                                mControllerConfig.rayStartPosition[1],
                                                                mControllerConfig.rayStartPosition[2]));

            NxrTrackedDevice trackedDevice = go.AddComponent <NxrTrackedDevice>();

            if (trackedDevice != null)
            {
                trackedDevice.ReloadLaserPointer(mNxrLaserPointer);
                trackedDevice.deviceType = deviceType;
                InteractionManager.NACTION_HAND_TYPE mHandType =
                    deviceType == NxrInstantNativeApi.HoloeverDeviceType.LeftController
                        ? InteractionManager.NACTION_HAND_TYPE.HAND_LEFT
                        : InteractionManager.NACTION_HAND_TYPE.HAND_RIGHT;

                if (!DualCtrlDeviceDict.ContainsKey(mHandType))
                {
                    DualCtrlDeviceDict.Add(mHandType, trackedDevice);
                }
                else
                {
                    DualCtrlDeviceDict[mHandType] = trackedDevice;
                }
            }

            if (deviceType == NxrInstantNativeApi.HoloeverDeviceType.LeftController)
            {
                leftObj     = go;
                leftModelGo = modelGO;
            }
            else if (deviceType == NxrInstantNativeApi.HoloeverDeviceType.RightController)
            {
                rightObj     = go;
                rightModelGo = modelGO;
            }

            //close
            NxrViewer.Instance.SwitchControllerMode(true);
            Debug.Log("HideGaze.ForceUseReticle3");
        }