protected void Start() { haptionDriver = MiddleVR.VRKernel.GetObject("Haption Driver"); if (haptionDriver == null) { MiddleVRTools.Log(0, "TrackHaptionDeviceButtonsStatus: No driver Haption found!"); enabled = false; return; } }
protected void Init() { if (RenderMaterial == null) { RenderMaterial = Resources.Load("OVRLensCorrectionMat", typeof(Material)) as Material; if (RenderMaterial == null) { MiddleVRTools.Log(-1, "[RiftCamera] Failed to load OVRLensCorrectionMat."); } } vrObject oculusDriver = MiddleVR.VRKernel.GetObject("OculusRift Tracker Driver"); if (oculusDriver == null) { MiddleVRTools.Log(0, "[RiftCamera] No Oculus Rift driver found!"); return; } float DistortionScale = oculusDriver.GetProperty("DistortionScale").GetFloat(); float AR = oculusDriver.GetProperty("AspectRatio").GetFloat(); float K0 = oculusDriver.GetProperty("K0").GetFloat(); float K1 = oculusDriver.GetProperty("K1").GetFloat(); float K2 = oculusDriver.GetProperty("K2").GetFloat(); float K3 = oculusDriver.GetProperty("K3").GetFloat(); float OffsetLensLeft = oculusDriver.GetProperty("OffsetLensLeft").GetFloat(); float OffsetLensRight = oculusDriver.GetProperty("OffsetLensRight").GetFloat(); //print("DistortionScale: " + DistortionScale); //print("AspectRatio: " + AR); //float LensSeparationDistance = oculusDriver.GetProperty("LensSeparationDistance").GetFloat(); // Get the distortion scale and aspect ratio to use when calculating distortion shader float distortionScale = 1.0f / DistortionScale; float aspectRatio = AR; float LensOffsetLeft = OffsetLensLeft; float LensOffsetRight = OffsetLensRight; // These values are different in the SDK World Demo; Unity renders each camera to a buffer // that is normalized, so we will respect this rule when calculating the distortion inputs float NormalizedWidth = 1.0f; float NormalizedHeight = 1.0f; _Scale.x = (NormalizedWidth / 2.0f) * distortionScale; _Scale.y = (NormalizedHeight / 2.0f) * distortionScale * aspectRatio; _ScaleIn.x = (2.0f / NormalizedWidth); _ScaleIn.y = (2.0f / NormalizedHeight) / aspectRatio; _HmdWarpParam.x = K0; _HmdWarpParam.y = K1; _HmdWarpParam.z = K2; _HmdWarpParam.w = K3; if (name.Contains("Left")) { float lensOffset = 0.5f + (LensOffsetLeft * 0.5f); _Center.x = lensOffset; } if (name.Contains("Right")) { float lensOffset = 0.5f + (LensOffsetRight * 0.5f); _Center.x = lensOffset; } _Center.y = 0.5f; if (RenderMaterial != null) { SetMaterialProperties(); } else { print("NOMAT"); } IsInit = true; }
public override void OnNetDestroyObject(vrObject iObject) { vrNode3D mvrNode = vrNode3D.Cast(iObject); if (mvrNode != null) { GameObject unityObject = MVRNodesMapper.Instance.GetNode(mvrNode); if (unityObject != null) { VRNode3DComponent nodeComponent = unityObject.GetComponent<VRNode3DComponent>(); if (nodeComponent != null) { nodeComponent.Node3D = null; nodeComponent.SyncDirection = MVRNodesMapper.ENodesSyncDirection.NoSynchronization; } // Destroys the object later this frame, before rendering UnityEngine.Object.Destroy(unityObject); } } }
public override void OnNetCreateObject(vrObject iObject) { vrNode3D node = vrNode3D.Cast(iObject); if (node == null) { // We only care about node3Ds return; } GameObject unityObject = new GameObject(node.GetName()); vrProperty prop = node.GetProperty("Prefab"); if (prop != null) { UnityEngine.Object res = Resources.Load(prop.GetString(), typeof(GameObject)); if (res != null) { GameObject gameObjectPrefab = UnityEngine.Object.Instantiate(res) as GameObject; if (gameObjectPrefab != null) { gameObjectPrefab.name = res.name; gameObjectPrefab.transform.parent = unityObject.transform; } } } vrNode3D parentNode = node.GetParent(); if (parentNode != null) { GameObject parentGameObject = MVRNodesMapper.Instance.GetNode(parentNode); if (parentGameObject != null) { unityObject.transform.parent = parentGameObject.transform; } } VRNode3DComponent nodeComponent = unityObject.GetComponent<VRNode3DComponent>(); if (nodeComponent == null) { nodeComponent = unityObject.AddComponent<VRNode3DComponent>(); } nodeComponent.SyncDirection = MVRNodesMapper.ENodesSyncDirection.MiddleVRToUnity; nodeComponent.Node3D = node; }
public override void OnNetChangeOwnership(vrObject iObject, ulong iNewOwner) { vrNode3D node = vrNode3D.Cast(iObject); if (node == null) { // We only care about node3Ds return; } GameObject unityObject = MVRNodesMapper.Instance.GetNode(node); if (unityObject != null) { unityObject.SendMessage("OnMVRNetChangeOwnership", iNewOwner, SendMessageOptions.DontRequireReceiver); } }