public static bool GetBounds(Size size, ref ChaperoneSoftBoundsInfo_t pInfo) { if (size == Size.Calibrated) { var error = HmdError.None; if (!SteamVR.active) { OpenVR.Init(ref error); if (error != HmdError.None) return false; } var pChaperone = OpenVR.GetGenericInterface(OpenVR.IVRChaperone_Version, ref error); if (pChaperone == System.IntPtr.Zero || error != HmdError.None) { if (!SteamVR.active) OpenVR.Shutdown(); return false; } var chaperone = new CVRChaperone(pChaperone); bool success = chaperone.GetSoftBoundsInfo(ref pInfo); if (!success) Debug.LogWarning("Failed to get Calibrated Play Area bounds! Make sure you have tracking first, and that your space is calibrated."); if (!SteamVR.active) OpenVR.Shutdown(); return success; } else { try { var str = size.ToString().Substring(1); var arr = str.Split(new char[] {'x'}, 2); // convert to half size in meters (from cm) var x = float.Parse(arr[0]) / 200; var z = float.Parse(arr[1]) / 200; pInfo.quadCorners.vCorners = new HmdVector3_t[4]; pInfo.quadCorners.vCorners[0].v = new float[3] { x, 0, z }; pInfo.quadCorners.vCorners[1].v = new float[3] { x, 0, -z }; pInfo.quadCorners.vCorners[2].v = new float[3] { -x, 0, -z }; pInfo.quadCorners.vCorners[3].v = new float[3] { -x, 0, z }; return true; } catch {} } return false; }
internal static extern bool VR_IVRChaperone_GetSoftBoundsInfo(IntPtr instancePtr, ref ChaperoneSoftBoundsInfo_t pInfo);
internal static extern void VR_IVRChaperoneSetup_SetWorkingSoftBoundsInfo(IntPtr instancePtr, ref ChaperoneSoftBoundsInfo_t pInfo);
public void BuildMesh() { var bounds = new ChaperoneSoftBoundsInfo_t(); if (!GetBounds(size, ref bounds)) return; var corners = bounds.quadCorners.vCorners; vertices = new Vector3[corners.Length * 2]; for (int i = 0; i < corners.Length; i++) { var v = corners[i].v; vertices[i] = new Vector3(v[0], 0.01f, v[2]); } if (borderThickness == 0.0f) { GetComponent<MeshFilter>().mesh = null; return; } for (int i = 0; i < corners.Length; i++) { int next = (i + 1) % corners.Length; int prev = (i + corners.Length - 1) % corners.Length; var nextSegment = (vertices[next] - vertices[i]).normalized; var prevSegment = (vertices[prev] - vertices[i]).normalized; var vert = vertices[i]; vert += Vector3.Cross(nextSegment, Vector3.up) * borderThickness; vert += Vector3.Cross(prevSegment, Vector3.down) * borderThickness; vertices[corners.Length + i] = vert; } var triangles = new int[] { 0, 1, 4, 1, 5, 4, 1, 2, 5, 2, 6, 5, 2, 3, 6, 3, 7, 6, 3, 0, 7, 0, 4, 7 }; var uv = new Vector2[] { new Vector2(0.0f, 0.0f), new Vector2(1.0f, 0.0f), new Vector2(0.0f, 0.0f), new Vector2(1.0f, 0.0f), new Vector2(0.0f, 1.0f), new Vector2(1.0f, 1.0f), new Vector2(0.0f, 1.0f), new Vector2(1.0f, 1.0f) }; var colors = new Color[] { color, color, color, color, new Color(color.r, color.g, color.b, 0.0f), new Color(color.r, color.g, color.b, 0.0f), new Color(color.r, color.g, color.b, 0.0f), new Color(color.r, color.g, color.b, 0.0f) }; var mesh = new Mesh(); GetComponent<MeshFilter>().mesh = mesh; mesh.vertices = vertices; mesh.uv = uv; mesh.colors = colors; mesh.triangles = triangles; var renderer = GetComponent<MeshRenderer>(); renderer.material = Resources.GetBuiltinResource<Material>("Sprites-Default.mat"); renderer.reflectionProbeUsage = UnityEngine.Rendering.ReflectionProbeUsage.Off; renderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off; renderer.receiveShadows = false; renderer.useLightProbes = false; }
public override void SetWorkingSoftBoundsInfo(ref ChaperoneSoftBoundsInfo_t pInfo) { CheckIfUsable(); VRNativeEntrypoints.VR_IVRChaperoneSetup_SetWorkingSoftBoundsInfo(m_pVRChaperoneSetup,ref pInfo); }
public override bool GetWorkingSoftBoundsInfo(ref ChaperoneSoftBoundsInfo_t pInfo) { CheckIfUsable(); bool result = VRNativeEntrypoints.VR_IVRChaperoneSetup_GetWorkingSoftBoundsInfo(m_pVRChaperoneSetup,ref pInfo); return result; }
public abstract void SetWorkingSoftBoundsInfo(ref ChaperoneSoftBoundsInfo_t pInfo);
public abstract bool GetWorkingSoftBoundsInfo(ref ChaperoneSoftBoundsInfo_t pInfo);