SetDeviceIndex() public method

public SetDeviceIndex ( int index ) : void
index int
return void
        public virtual void OnHandInitialized(int deviceIndex)
        {
            // Debug.LogError("hand initialized ");

            controllerRenderModel.SetInputSource(inputSource);
            controllerRenderModel.SetDeviceIndex(deviceIndex);
        }
Example #2
0
        protected override void OnAwake()
        {
            var sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);

            sphere.transform.SetParent(transform, false);
            var sphere2 = GameObject.CreatePrimitive(PrimitiveType.Sphere);

            sphere2.transform.SetParent(transform, false);

            transform.localScale = 0.3f * Vector3.one;
            transform.localScale = new Vector3(0.2f, 0.2f, 0.4f);

            sphere.transform.localScale     = Vector3.one * 0.3f;
            sphere.transform.localPosition  = Vector3.forward * 0.5f;
            sphere2.transform.localScale    = Vector3.one * 0.3f;
            sphere2.transform.localPosition = Vector3.up * 0.5f;

            GetComponent <Collider>().isTrigger = true;

            // Disable head camera, which is usually used for screen output
            model = new GameObject("Model").AddComponent <SteamVR_RenderModel>();
            model.transform.SetParent(VR.Camera.SteamCam.head, false);
            model.shader = VR.Context.Materials.StandardShader;
            model.SetDeviceIndex((int)OpenVR.k_unTrackedDeviceIndex_Hmd);
            model.gameObject.layer = LayerMask.NameToLayer(VR.Context.InvisibleLayer);

            var cam = gameObject.AddComponent <Camera>();

            cam.depth         = 1;
            cam.nearClipPlane = 0.3f;
            cam.cullingMask   = int.MaxValue & ~VR.Context.UILayerMask;

            transform.position = S_Position;
            transform.rotation = S_Rotation;
        }
	void OnHandInitialized( int deviceIndex )
	{
		renderModel = new GameObject( "SteamVR_RenderModel" ).AddComponent<SteamVR_RenderModel>();
		renderModel.transform.parent = transform;
		renderModel.transform.localPosition = Vector3.zero;
		renderModel.transform.localRotation = Quaternion.identity;
		renderModel.SetDeviceIndex( deviceIndex );
		renderModel.gameObject.SetActive( false );
	}
 void OnHandInitialized(int deviceIndex)
 {
     renderModel = new GameObject("SteamVR_RenderModel").AddComponent <SteamVR_RenderModel>();
     renderModel.transform.parent        = transform;
     renderModel.transform.localPosition = Vector3.zero;
     renderModel.transform.localRotation = Quaternion.identity;
     renderModel.SetDeviceIndex(deviceIndex);
     renderModel.gameObject.SetActive(false);
 }
Example #5
0
            protected override void OnStart()
            {
                DontDestroyOnLoad(this);

                transform.localScale = Vector3.zero;

                _Model = gameObject.AddComponent <SteamVR_RenderModel>();
                //model.transform.SetParent(VR.Camera.SteamCam.head, false);
                _Model.shader = VR.Context.Materials.StandardShader;
                gameObject.AddComponent <SteamVR_TrackedObject>();

                _Model.SetDeviceIndex((int)OpenVR.k_unTrackedDeviceIndex_Hmd);
            }
 public void UpdateRenderModel()
 {
     if (ChangeProp.Set(ref m_currentDeviceIndex, GetCurrentDeviceIndex()))
     {
         if (!ViveRole.IsValidIndex(m_currentDeviceIndex))
         {
             m_renderModel.gameObject.SetActive(false);
         }
         else
         {
             m_renderModel.gameObject.SetActive(true);
             m_renderModel.SetDeviceIndex((int)m_currentDeviceIndex);
         }
     }
 }
        private void UpdateSteamVRModel()
        {
            if (ChangeProp.Set(ref m_currentDeviceIndex, GetCurrentDeviceIndex()))
            {
                if (VRModule.IsValidDeviceIndex(m_currentDeviceIndex))
                {
                    if (m_modelObj != null && m_renderModel == null)
                    {
                        CleanUpModelObj();
                    }

                    if (m_modelObj == null)
                    {
                        // find SteamVR_RenderModel in child object
                        for (int i = 0, imax = transform.childCount; i < imax; ++i)
                        {
                            if ((m_renderModel = GetComponentInChildren <SteamVR_RenderModel>()) != null)
                            {
                                m_modelObj = m_renderModel.gameObject;
                                break;
                            }
                        }
                        // create SteamVR_RenderModel in child object if not found
                        if (m_renderModel == null)
                        {
                            m_modelObj = new GameObject("Model");
                            m_modelObj.transform.SetParent(transform, false);
                            m_renderModel = m_modelObj.AddComponent <SteamVR_RenderModel>();
                        }

                        if (m_overrideShader != null)
                        {
                            m_renderModel.shader = m_overrideShader;
                        }
                    }

                    m_modelObj.SetActive(true);
                    m_renderModel.SetDeviceIndex((int)m_currentDeviceIndex);
                }
                else
                {
                    if (m_modelObj != null)
                    {
                        m_modelObj.SetActive(false);
                    }
                }
            }
        }
        //-------------------------------------------------
        // Gets called when the hand has been initialized and a render model has been set
        //-------------------------------------------------
        private void OnHandInitialized(int deviceIndex)
        {
            //Create a new render model for the controller hints
            renderModel = new GameObject("SteamVR_RenderModel").AddComponent <SteamVR_RenderModel>();
            renderModel.transform.parent        = transform;
            renderModel.transform.localPosition = Vector3.zero;
            renderModel.transform.localRotation = Quaternion.identity;
            renderModel.transform.localScale    = Vector3.one;
            renderModel.SetDeviceIndex(deviceIndex);

            if (!initialized)
            {
                //The controller hint render model needs to be active to get accurate transforms for all the individual components
                renderModel.gameObject.SetActive(true);
            }
        }
Example #9
0
    /// <summary>
    /// Makes the controller update its model based on the specified controller index.
    /// This index is the actual tracked object index in SteamVR, and in Oculus, corresponds to
    /// ChooseTrackedObjectMenu.TOUCH_INDEX_LEFT and _RIGHT.
    /// </summary>
    public void SetRenderModelIndex(int newindex)
    {
#if ZED_STEAM_VR
        if (!renderModel)
        {
            renderModel = gameObject.AddComponent <SteamVR_RenderModel>();
        }

        renderModel.SetDeviceIndex(newindex);
#elif ZED_OCULUS
        if (newindex == ChooseTrackedObjectMenu.TOUCH_INDEX_LEFT)
        {
            //if(controllerModel != null && controllerModel.name != "TouchControl_L")
            if (controllerModel != null)
            {
                Destroy(controllerModel);
                controllerModel = null;
            }
            GameObject lcontrolprefab = Resources.Load <GameObject>("TouchControl_L");
            controllerModel = Instantiate(lcontrolprefab, transform, false);
        }
        else if (newindex == ChooseTrackedObjectMenu.TOUCH_INDEX_RIGHT)
        {
            //if (controllerModel != null && controllerModel.name != "TouchControl_R")
            if (controllerModel != null)
            {
                Destroy(controllerModel);
                controllerModel = null;
            }
            GameObject rcontrolprefab = Resources.Load <GameObject>("TouchControl_R");
            controllerModel = Instantiate(rcontrolprefab, transform, false);
        }
        else
        {
            Debug.LogError("Passed invalid index to SetControllerSkin: Valid options are " + ChooseTrackedObjectMenu.TOUCH_INDEX_LEFT +
                           " (left controller) or " + ChooseTrackedObjectMenu.TOUCH_INDEX_RIGHT + " (right controller).");
        }
#endif
    }
Example #10
0
    //The new pads are registered and created. The preview is also created
    public void CreateNewPads()
    {
        poseData.Clear();
        foreach (DelayedPad o in delayedPads.Values)
        {
            Destroy(o.o);
        }
        delayedPads.Clear();

        foreach (SteamVR_Controller.Device d in devices)
        {
            if (poseData.ContainsKey((int)d.index))
            {
                continue;
            }
            DelayedPad p = new DelayedPad();
            if (modelToReplaceVivePads == null)
            {
                p.o       = new GameObject();
                p.o.name  = "VirtualDelayedPad_" + (int)d.index;
                p.o.layer = sl.ZEDCamera.Tag;
                SteamVR_RenderModel m = p.o.AddComponent <SteamVR_RenderModel>();
                m.modelOverride = "vr_controller_vive_1_5";

                m.SetDeviceIndex((int)d.index);
            }
            else
            {
                p.o = Instantiate(modelToReplaceVivePads);
            }
            p.d = d;

            poseData.Add((int)d.index, new List <TimedPoseData>());
            delayedPads.Add((int)d.index, p);
        }
    }
Example #11
0
 public virtual void OnHandInitialized(int deviceIndex)
 {
     controllerRenderModel.SetInputSource(inputSource);
     controllerRenderModel.SetDeviceIndex(deviceIndex);
 }
 //-------------------------------------------------
 public void Initialize(int deviceIndex)
 {
     renderModel = gameObject.AddComponent <SteamVR_RenderModel>();
     renderModel.SetDeviceIndex(deviceIndex);
     renderModel.updateDynamically = false;
 }