private Transform ConfigureEyeAnchor(Transform root, VR.VRNode eye) { string eyeName = (eye == VR.VRNode.CenterEye) ? "Center" : (eye == VR.VRNode.LeftEye) ? "Left" : "Right"; string name = eyeName + eyeAnchorName; Transform anchor = transform.Find(root.name + "/" + name); if (anchor == null) { anchor = transform.Find(name); } if (anchor == null) { string legacyName = legacyEyeAnchorName + eye.ToString(); anchor = transform.Find(legacyName); } if (anchor == null) { anchor = new GameObject(name).transform; } anchor.name = name; anchor.parent = root; anchor.localScale = Vector3.one; anchor.localPosition = Vector3.zero; anchor.localRotation = Quaternion.identity; return(anchor); }
/// <summary> /// Use this function to set texture and texNativePtr when app is running /// GetNativeTexturePtr is a slow behavior, the value should be pre-cached /// </summary> public void OverrideOverlayTextureInfo(Texture srcTexture, IntPtr nativePtr, VR.VRNode node) { int index = (node == VR.VRNode.RightEye) ? 1 : 0; textures[index] = srcTexture; cachedTextures[index] = srcTexture; texNativePtrs[index] = nativePtr; }
/// <summary> /// Returns a productId match based solely on handness. This is all the 'data' we have when using Unity 5 (MRTP) builds and the Unity Input.Tracking APIs. Avoid this combination when possible. /// NOTE: This method will not return a product id for models not yet cached. /// </summary> /// <param name="node">XRNode </param> /// <returns>Controller productId hash</returns> public string GetProductId(XRNode node) { if (node == XRNode.LeftHand || node == XRNode.RightHand) { string handedness = (node == XRNode.LeftHand) ? Constants.LeftHandness : Constants.RightHandeness; foreach (var key in cachedModels.Keys) { if (key.ToLower().Contains(handedness)) { return(key); } } } return(string.Empty); }
private void ConfigureEyeDesc(VR.VRNode eye) { if (!OVRManager.isHmdPresent) { return; } OVRPlugin.Sizei size = OVRPlugin.GetEyeTextureSize((OVRPlugin.Eye)eye); OVRPlugin.Frustumf frust = OVRPlugin.GetEyeFrustum((OVRPlugin.Eye)eye); eyeDescs[(int)eye] = new EyeRenderDesc() { resolution = new Vector2(size.w, size.h), fov = Mathf.Rad2Deg * new Vector2(frust.fovX, frust.fovY), }; }
private IEnumerator Attach(GameObject target, Transform parent, XRNode nodeType) { yield return(ControllerHelpers.AttachModel(target, parent, nodeType, GLTFMaterial, GLTFMaterial)); if (ShowDebugAxis) { if (nodeType == XRNode.LeftHand) { axisRendererLeft = target.AddComponent <AxisRenderer>(); } else { axisRendererRight = target.AddComponent <AxisRenderer>(); } } }
void CreateControllerVisual(XRNode nodeType) { #if UNITY_5 var position = InputTracking.GetLocalPosition(nodeType); if (position == Vector3.zero) { TraceHelper.LogDiff("Not creating controller for " + nodeType.ToString(), TraceCacheGrouping.IgnoreController); return; } #endif GameObject go = new GameObject(); go.transform.parent = ControllersRoot; go.name = "Controller" + nodeType.ToString(); uDevices[nodeType] = go.transform; var coroutine = StartCoroutine(Attach(go, ControllersRoot, nodeType)); }
/// <summary> /// Returns model data based solely on handness. This is all the 'data' we have when using Unity 5 (MRTP) builds and the Unity Input.Tracking APIs. Avoid this combination when possible. /// </summary> /// <param name="node">XRNode </param> /// <returns>GLTF Controller model as byte[] </returns> public byte[] GetModelData(XRNode node) { string handedness = string.Empty; if (node == XRNode.LeftHand || node == XRNode.RightHand) { handedness = (node == XRNode.LeftHand) ? Constants.LeftHandness : Constants.RightHandeness; foreach (var key in cachedModels.Keys) { if (key.ToLower().Contains(handedness)) { return(GetModelData(key)); } } } return(null); }
/// <summary> /// Use this function to set texture and texNativePtr when app is running /// GetNativeTexturePtr is a slow behavior, the value should be pre-cached /// </summary> public void OverrideOverlayTextureInfo(Texture srcTexture, IntPtr nativePtr, VR.VRNode node) { int index = (node == VR.VRNode.RightEye) ? 1 : 0; if (textures.Length <= index) { return; } stageCount = 3; CreateLayerTextures(true, new OVRPlugin.Sizei() { w = srcTexture.width, h = srcTexture.height }, false); textures[index] = srcTexture; layerTextures[index].appTexture = srcTexture; layerTextures[index].appTexturePtr = nativePtr; }
OpenvrJoystickFrame UpdateNode(UnityEngine.VR.VRNode Node, string Name, KeyCode TriggerButton, KeyCode TouchpadButton, KeyCode TouchpadClickButton, KeyCode AppButton, string AxisX, string AxisY) #endif { var JoyInput = new OpenvrJoystickFrame(); #if UNITY_2017_2_OR_NEWER JoyInput.Position = UnityEngine.XR.InputTracking.GetLocalPosition(Node); JoyInput.Rotation = UnityEngine.XR.InputTracking.GetLocalRotation(Node); #else JoyInput.Position = UnityEngine.VR.InputTracking.GetLocalPosition(Node); JoyInput.Rotation = UnityEngine.VR.InputTracking.GetLocalRotation(Node); #endif JoyInput.TriggerIsDown = Input.GetKey(TriggerButton); JoyInput.TriggerPressed = Input.GetKeyDown(TriggerButton); JoyInput.TriggerReleased = Input.GetKeyUp(TriggerButton); // throws if not setup try { JoyInput.TouchpadAxis = new Vector2(Input.GetAxis(AxisX), Input.GetAxis(AxisY)); } catch { JoyInput.TouchpadAxis = Vector2.zero; } JoyInput.TouchpadIsDown = Input.GetKey(TouchpadButton); JoyInput.TouchpadPressed = Input.GetKeyDown(TouchpadButton); JoyInput.TouchpadReleased = Input.GetKeyUp(TouchpadButton); JoyInput.TouchpadClickIsDown = Input.GetKey(TouchpadClickButton); JoyInput.TouchpadClickPressed = Input.GetKeyDown(TouchpadClickButton); JoyInput.TouchpadClickReleased = Input.GetKeyUp(TouchpadClickButton); JoyInput.AppButtonIsDown = Input.GetKey(AppButton); JoyInput.AppButtonPressed = Input.GetKeyDown(AppButton); JoyInput.AppButtonReleased = Input.GetKeyUp(AppButton); return(JoyInput); }
internal ControllerState GetController(XRNode nodeType, bool preserveState = false) { if (nodeType == XRNode.LeftHand) { if (!preserveState) { Left = new ControllerState(); Left.IsLeftHand = true; } return(Left); } else { if (!preserveState) { Right = new ControllerState(); Right.IsRightHand = true; } return(Right); } }
private void RemoveDevice(string name) { if (this.trackedControllers.ContainsKey(name)) { XRNode nodeType = this.trackedControllers[name]; if (uDevices.ContainsKey(nodeType)) { Destroy(uDevices[nodeType].gameObject); uDevices.Remove(nodeType); Debug.Log("Removed device " + name); } else { Debug.Log("Tracked controller: " + name + " not on devices list!"); } trackedControllers.Remove(name); } InputState.Current.DetectedControllers = this.uDevices.Keys.Count; }
public void OverrideOverlayTextureInfo(Texture srcTexture, IntPtr nativePtr, VR.VRNode node) #endif { #if UNITY_2017_2_OR_NEWER int index = (node == UnityEngine.XR.XRNode.RightEye) ? 1 : 0; #else int index = (node == VR.VRNode.RightEye) ? 1 : 0; #endif if (textures.Length <= index) { return; } stageCount = 3; CreateLayerTextures(true, new OVRPlugin.Sizei() { w = srcTexture.width, h = srcTexture.height }, false); textures[index] = srcTexture; layerTextures[index].appTexture = srcTexture; layerTextures[index].appTexturePtr = nativePtr; }
/// <summary> /// This override is used to determine the correct XRNode type for this device. /// </summary> public override void ApplyDefaultData(HapticSystemAttribute hapticSystemInfo) { base.ApplyDefaultData(hapticSystemInfo); // the first entry in additional data is true if this is the right hand and false otherwise handNodeType = (bool)hapticSystemInfo.AdditionalData[0] ? XRNode.RightHand : XRNode.LeftHand; }
/// <summary> /// Gets the resolution and field of view for the given eye. /// </summary> public EyeRenderDesc GetEyeRenderDesc(VR.VRNode eye) { return(eyeDescs[(int)eye]); }
public bool Contains(XRNode node) { string id = GetProductId(node); return(cachedModels.ContainsKey(id)); }