// creates boundary plane for mr headsets private void CreateBoundaryPlane(Transform planeParent, Material planeMat, bool isCollider, PhysicMaterial colliderMat) { //if(boundaryPlane == null) { boundaryPlane = GameObject.CreatePrimitive(PrimitiveType.Plane); boundaryPlane.name = "Boundary"; boundaryPlane.layer = MultiARInterop.GetSurfaceLayer(); boundaryPlane.transform.SetParent(planeParent); } MeshRenderer meshRenderer = boundaryPlane.GetComponent <MeshRenderer>(); if (meshRenderer) { meshRenderer.enabled = planeMat != null; meshRenderer.material = planeMat; } MeshCollider meshCollider = boundaryPlane.GetComponent <MeshCollider>(); if (meshCollider) { meshCollider.enabled = isCollider; if (isCollider && colliderMat) { meshCollider.material = colliderMat; } } }
// invoked by AnchorAdded-event private void PlaneAnchorAdded(ARPlaneAnchor arPlaneAnchor) { Debug.Log("Plane added: " + arPlaneAnchor.identifier); GameObject go = null; // if(arManager.displayTrackedSurfaces) // { // go = UnityARUtility.CreatePlaneInScene(arPlaneAnchor); // go.AddComponent<DontDestroyOnLoad>(); // these GOs persist across scene loads // } ARPlaneAnchorGameObject arpag = new ARPlaneAnchorGameObject(); arpag.planeAnchor = arPlaneAnchor; arpag.gameObject = go; planeAnchorDict.Add(arPlaneAnchor.identifier, arpag); trackedPlanesTimestamp = GetLastFrameTimestamp(); // create overlay surfaces as needed if (arManager.useOverlaySurface != MultiARManager.SurfaceRenderEnum.None) { // estimate the material Material surfaceMat = arManager.GetSurfaceMaterial(); int surfaceLayer = MultiARInterop.GetSurfaceLayer(); MultiARInterop.MultiARData arData = arManager.GetARData(); string surfId = arPlaneAnchor.identifier; if (!arData.dictOverlaySurfaces.ContainsKey(surfId)) { GameObject overlaySurfaceObj = new GameObject(); overlaySurfaceObj.name = "surface-" + surfId; overlaySurfaceObj.layer = surfaceLayer; overlaySurfaceObj.transform.SetParent(arData.surfaceRendererRoot ? arData.surfaceRendererRoot.transform : null); // GameObject overlayCubeObj = GameObject.CreatePrimitive(PrimitiveType.Cube); // overlayCubeObj.name = "surface-cube-" + surfId; // overlayCubeObj.transform.localScale = new Vector3(0.2f, 0.2f, 0.2f); // overlayCubeObj.transform.SetParent(overlaySurfaceObj.transform); OverlaySurfaceUpdater overlaySurface = overlaySurfaceObj.AddComponent <OverlaySurfaceUpdater>(); overlaySurface.SetSurfaceMaterial(surfaceMat); overlaySurface.SetSurfaceCollider(arManager.surfaceCollider, arManager.colliderMaterial); arData.dictOverlaySurfaces.Add(surfId, overlaySurface); } // update the surface mesh UpdateOverlaySurface(arData.dictOverlaySurfaces[surfId], arPlaneAnchor); } }
/// <summary> /// Raycasts from screen point or camera to the world. /// </summary> /// <returns><c>true</c>, if a plane was hit, <c>false</c> otherwise.</returns> /// <param name="screenPos">Screen position.</param> /// <param name="hit">Hit data.</param> public bool RaycastToWorld(bool fromInputPos, out MultiARInterop.TrackableHit hit) { hit = new MultiARInterop.TrackableHit(); if (!isInitialized || !mainCamera) { return(false); } // ray-cast Ray camRay = GetCameraRay(); hit.rayPos = camRay.origin; hit.rayDir = camRay.direction; int surfaceLayer = MultiARInterop.GetSurfaceLayer(); // LayerMask.NameToLayer("SpatialSurface"); //Debug.Log("SpatialSurfaceLayer: " + surfaceLayer); int layerMask = 1 << surfaceLayer; RaycastHit[] rayHits = Physics.RaycastAll(camRay, MultiARInterop.MAX_RAYCAST_DIST, layerMask); for (int i = 0; i < rayHits.Length; i++) { RaycastHit rayHit = rayHits[i]; // check for child of SpatialMappingCollider //if(rayHit.transform.GetComponentInParent<SpatialMappingCollider>() != null) if (rayHit.collider != null) { hit.point = rayHit.point; hit.normal = rayHit.normal; hit.distance = rayHit.distance; hit.rotation = Quaternion.FromToRotation(Vector3.up, rayHit.normal); hit.psObject = rayHit; //Debug.Log(string.Format("Hit {0} at position {1}.", rayHit.collider.gameObject, rayHit.point)); return(true); } } return(false); }
void Update() { if (!isInitialized) { return; } // check for errors _QuitOnConnectionErrors(); // check for input (touch) CheckForInputAction(); // estimate the tracking state SessionStatus status = Session.Status; if (status.IsError() || status.IsNotInitialized()) { cameraTrackingState = TrackingState.Stopped; return; } else if (status == SessionStatus.Tracking) { cameraTrackingState = TrackingState.Tracking; } else { cameraTrackingState = TrackingState.Paused; } // get frame timestamp and light intensity lastFrameTimestamp = GetCurrentTimestamp(); if (Frame.LightEstimate.State == LightEstimateState.Valid) { // Normalize pixel intensity by middle gray in gamma space. const float middleGray = 0.466f; currentLightIntensity = Frame.LightEstimate.PixelIntensity / middleGray; } // get point cloud, if needed MultiARInterop.MultiARData arData = arManager.GetARData(); if (arManager.usePointCloudData) { if (Frame.PointCloud.PointCount > 0 && Frame.PointCloud.IsUpdatedThisFrame) { // Copy the point cloud points for (int i = 0; i < Frame.PointCloud.PointCount; i++) { PointCloudPoint point = Frame.PointCloud.GetPointAsStruct(i); arData.pointCloudData[i] = new Vector3(point.Position.x, point.Position.y, point.Position.z); } arData.pointCloudLength = Frame.PointCloud.PointCount; arData.pointCloudTimestamp = lastFrameTimestamp; } } // // display the tracked planes if needed // if(arManager.displayTrackedSurfaces && trackedPlanePrefab) // { // // get the new planes // Frame.GetNewPlanes(ref newTrackedPlanes); // // // Iterate over planes found in this frame and instantiate corresponding GameObjects to visualize them. // for (int i = 0; i < newTrackedPlanes.Count; i++) // { // // Instantiate a plane visualization prefab and set it to track the new plane. // GameObject planeObject = Instantiate(trackedPlanePrefab, Vector3.zero, Quaternion.identity); // planeObject.GetComponent<GoogleARCore.HelloAR.TrackedPlaneVisualizer>().SetTrackedPlane(newTrackedPlanes[i]); // // // Apply a random color and grid rotation. // planeObject.GetComponent<Renderer>().material.SetColor("_GridColor", planeColors[Random.Range(0, planeColors.Length - 1)]); // planeObject.GetComponent<Renderer>().material.SetFloat("_UvRotation", Random.Range(0.0f, 360.0f)); // } // } // get all tracked planes Session.GetTrackables <DetectedPlane>(allTrackedPlanes, TrackableQueryFilter.All); // create overlay surfaces as needed if (arManager.useOverlaySurface != MultiARManager.SurfaceRenderEnum.None) { alSurfacesToDelete.Clear(); alSurfacesToDelete.AddRange(arData.dictOverlaySurfaces.Keys); // estimate the material Material surfaceMat = arManager.GetSurfaceMaterial(); int surfaceLayer = MultiARInterop.GetSurfaceLayer(); for (int i = 0; i < allTrackedPlanes.Count; i++) { string surfId = allTrackedPlanes[i].m_TrackableNativeHandle.ToString(); if (!arData.dictOverlaySurfaces.ContainsKey(surfId)) { GameObject overlaySurfaceObj = new GameObject(); overlaySurfaceObj.name = "surface-" + surfId; overlaySurfaceObj.layer = surfaceLayer; overlaySurfaceObj.transform.SetParent(arData.surfaceRendererRoot ? arData.surfaceRendererRoot.transform : null); // GameObject overlayCubeObj = GameObject.CreatePrimitive(PrimitiveType.Cube); // overlayCubeObj.name = "surface-cube-" + surfId; // overlayCubeObj.transform.localScale = new Vector3(0.2f, 0.2f, 0.2f); // overlayCubeObj.transform.SetParent(overlaySurfaceObj.transform); OverlaySurfaceUpdater overlaySurface = overlaySurfaceObj.AddComponent <OverlaySurfaceUpdater>(); overlaySurface.SetSurfaceMaterial(surfaceMat); overlaySurface.SetSurfaceCollider(arManager.surfaceCollider, arManager.colliderMaterial); arData.dictOverlaySurfaces.Add(surfId, overlaySurface); } // update the surface mesh bool bValidSurface = UpdateOverlaySurface(arData.dictOverlaySurfaces[surfId], allTrackedPlanes[i]); if (bValidSurface && alSurfacesToDelete.Contains(surfId)) { alSurfacesToDelete.Remove(surfId); } } // delete not tracked surfaces foreach (string surfId in alSurfacesToDelete) { OverlaySurfaceUpdater overlaySurface = arData.dictOverlaySurfaces[surfId]; arData.dictOverlaySurfaces.Remove(surfId); Destroy(overlaySurface.gameObject); } } // check status of the anchors List <string> alAnchorsToRemove = new List <string>(); foreach (string anchorId in arData.allAnchorsDict.Keys) { List <GameObject> anchoredObjs = arData.allAnchorsDict[anchorId]; foreach (GameObject anchoredObj in anchoredObjs) { Transform parentTrans = anchoredObj.transform.parent; if (parentTrans == null) { if (!alAnchorsToRemove.Contains(anchorId)) { alAnchorsToRemove.Add(anchorId); } anchoredObj.SetActive(false); } else { Anchor anchor = parentTrans.GetComponent <Anchor>(); if (anchor == null || anchor.TrackingState == TrackingState.Stopped) { if (!alAnchorsToRemove.Contains(anchorId)) { alAnchorsToRemove.Add(anchorId); } anchoredObj.transform.parent = null; anchoredObj.SetActive(false); } } } } // remove the stopped anchors from our list foreach (string anchorId in alAnchorsToRemove) { arData.allAnchorsDict.Remove(anchorId); } // clean up alAnchorsToRemove.Clear(); // look for image anchors, if enabled if (arData.imageAnchorsEnabled) { // Get updated augmented images for this frame. Session.GetTrackables <AugmentedImage>(alTrackedAugmentedImages, TrackableQueryFilter.Updated); foreach (var image in alTrackedAugmentedImages) { string sImageName = image.Name; bool wasImageTracked = dictImageAnchors.ContainsKey(sImageName); if (!wasImageTracked && image.TrackingState == TrackingState.Tracking) { // Create an anchor to ensure that ARCore keeps tracking this augmented image. Anchor anchor = image.CreateAnchor(image.CenterPose); anchor.gameObject.name = "ImageAnchor-" + sImageName; DontDestroyOnLoad(anchor.gameObject); alImageAnchorNames.Add(sImageName); dictImageAnchors.Add(sImageName, anchor.gameObject); } else if (wasImageTracked && image.TrackingState == TrackingState.Stopped) { // remove the anchor GameObject anchorObj = dictImageAnchors[sImageName]; alImageAnchorNames.Remove(sImageName); dictImageAnchors.Remove(sImageName); GameObject.Destroy(anchorObj); } } } }
// -- // -- // -- // -- // -- // -- // -- // -- // -- // -- // void Start() { if (!isInterfaceEnabled) { return; } // determine if display is opaque or transparent isDisplayOpaque = HolographicSettings.IsDisplayOpaque; Debug.Log("Display: " + (isDisplayOpaque ? "Opaque" : "Transparent")); // modify the main camera in the scene Camera currentCamera = MultiARInterop.GetMainCamera(); if (!currentCamera) { GameObject currentCameraObj = new GameObject("Main Camera"); currentCameraObj.tag = "MainCamera"; currentCamera = currentCameraObj.AddComponent <Camera>(); } // reset camera position & rotation //currentCamera.transform.position = Vector3.zero; currentCamera.transform.rotation = Quaternion.identity; // set camera parameters currentCamera.clearFlags = CameraClearFlags.SolidColor; currentCamera.backgroundColor = new Color(0f, 0f, 0f, 0f); currentCamera.nearClipPlane = 0.5f; // HoloLens recommended currentCamera.farClipPlane = 100f; if (isDisplayOpaque) { currentCamera.clearFlags = CameraClearFlags.Skybox; } // set the fastest quality setting QualitySettings.SetQualityLevel((int)qualityLevel); Debug.Log("QualityLevel: " + QualitySettings.names[(int)qualityLevel]); // reference to the AR main camera mainCamera = currentCamera; // don't destroy the light between scenes DontDestroyOnLoad(currentCamera.gameObject); // // add camera parent // if(currentCamera.transform.parent == null) // { // GameObject cameraParent = new GameObject("CameraParent"); // currentCamera.transform.SetParent(cameraParent.transform); // } // modify the directional light Light currentLight = MultiARInterop.GetDirectionalLight(); if (!currentLight) { GameObject currentLightObj = new GameObject("Directional light"); currentLight = currentLightObj.AddComponent <Light>(); currentLight.type = LightType.Directional; } // reset light position & rotation currentLight.transform.position = Vector3.zero; currentLight.transform.rotation = Quaternion.Euler(40f, 40f, 0f); // set light parameters currentLight.color = new Color32(255, 254, 244, 255); // add the ar-light component //currentLight.gameObject.AddComponent<MultiARDirectionalLight>(); // reference to the AR directional light //directionalLight = currentLight; // don't destroy the light between scenes DontDestroyOnLoad(currentLight.gameObject); // there is no point cloud in WinMR MultiARInterop.MultiARData arData = arManager.GetARData(); // check for point cloud getter if (arManager.pointCloudPrefab != null) { arData.pointCloudData = new Vector3[0]; arData.pointCloudLength = 0; arData.pointCloudTimestamp = 0.0; } // set tracking state cameraTrackingState = WorldManager.state; WorldManager.OnPositionalLocatorStateChanged += WorldManager_OnPositionalLocatorStateChanged; // // set tracking space type // Debug.Log("Before: " + XRDevice.GetTrackingSpaceType()); // if(XRDevice.GetTrackingSpaceType() != TrackingSpaceType.Stationary) // { // if(!XRDevice.SetTrackingSpaceType(TrackingSpaceType.Stationary)) // { // Debug.LogError("Cannot set stationary space type!"); // } // } // create gesture input if (!isDisplayOpaque) { gestureRecognizer = new GestureRecognizer(); gestureRecognizer.SetRecognizableGestures(GestureSettings.Tap | GestureSettings.Hold | GestureSettings.NavigationX | GestureSettings.NavigationY | GestureSettings.NavigationZ); gestureRecognizer.Tapped += GestureRecognizer_Tapped; // gestureRecognizer.HoldStarted += GestureRecognizer_HoldStarted; // gestureRecognizer.HoldCompleted += GestureRecognizer_HoldCompleted; // gestureRecognizer.HoldCanceled += GestureRecognizer_HoldCanceled; gestureRecognizer.NavigationStarted += GestureRecognizer_NavigationStarted; gestureRecognizer.NavigationUpdated += GestureRecognizer_NavigationUpdated; gestureRecognizer.NavigationCompleted += GestureRecognizer_NavigationCompleted; gestureRecognizer.NavigationCanceled += GestureRecognizer_NavigationCanceled; gestureRecognizer.StartCapturingGestures(); Debug.Log("Gesture recognizer inited and started."); } //else { // init interaction manager // InteractionManager.InteractionSourcePressed += InteractionManager_InteractionSourcePressed; // InteractionManager.InteractionSourceUpdated += InteractionManager_InteractionSourceUpdated; // InteractionManager.InteractionSourceReleased += InteractionManager_InteractionSourceReleased; InteractionManager.InteractionSourceDetected += InteractionManager_InteractionSourceDetected; InteractionManager.InteractionSourceLost += InteractionManager_InteractionSourceLost; InteractionManager.InteractionSourceUpdated += InteractionManager_InteractionSourceUpdated; Debug.Log("Interaction manager inited."); } // create surface renderer if (arManager.useOverlaySurface != MultiARManager.SurfaceRenderEnum.None) { GameObject objRenderer = new GameObject(); objRenderer.name = "SurfaceRenderer"; objRenderer.layer = MultiARInterop.GetSurfaceLayer(); arData.surfaceRendererRoot = objRenderer; surfaceRootTransform = objRenderer.transform; DontDestroyOnLoad(objRenderer); if (!isDisplayOpaque) { // hololens surfaceRenderer = objRenderer.AddComponent <SpatialMappingRenderer>(); surfaceRenderer.surfaceParent = objRenderer; switch (arManager.useOverlaySurface) { case MultiARManager.SurfaceRenderEnum.None: surfaceRenderer.renderState = SpatialMappingRenderer.RenderState.None; break; case MultiARManager.SurfaceRenderEnum.Visualization: surfaceRenderer.renderState = SpatialMappingRenderer.RenderState.Visualization; break; case MultiARManager.SurfaceRenderEnum.Occlusion: case MultiARManager.SurfaceRenderEnum.OcclusionWithShadows: surfaceRenderer.renderState = SpatialMappingRenderer.RenderState.Occlusion; break; } if (arManager.useOverlaySurface != MultiARManager.SurfaceRenderEnum.None) { surfaceRenderer.visualMaterial = arManager.surfaceVisualizationMaterial; surfaceRenderer.occlusionMaterial = arManager.useOverlaySurface == MultiARManager.SurfaceRenderEnum.OcclusionWithShadows ? arManager.surfaceOcclusionWithShadowsMaterial : arManager.surfaceOcclusionMaterial; } } else { // use special surface material on opaque displays Material visualMaterial = arManager.GetSurfaceMaterial(); if (arManager.useOverlaySurface == MultiARManager.SurfaceRenderEnum.Visualization && vrSurfaceMaterial) { visualMaterial = vrSurfaceMaterial; } // mr headsets CreateBoundaryPlane(objRenderer.transform, visualMaterial, arManager.surfaceCollider, arManager.colliderMaterial); boundaryMgr = objRenderer.AddComponent <HoloToolkit.Unity.Boundary.BoundaryManager>(); boundaryMgr.FloorQuad = boundaryPlane; boundaryMgr.AwakeBoundaryManager(); } } // create surface collider if (arManager.surfaceCollider) { GameObject objCollider = new GameObject(); objCollider.name = "SurfaceCollider"; objCollider.layer = MultiARInterop.GetSurfaceLayer(); DontDestroyOnLoad(objCollider); if (!isDisplayOpaque) { // hololens surfaceCollider = objCollider.AddComponent <SpatialMappingCollider>(); surfaceCollider.surfaceParent = objCollider; surfaceCollider.lodType = SpatialMappingBase.LODType.Low; surfaceCollider.layer = MultiARInterop.GetSurfaceLayer(); if (arManager.colliderMaterial) { surfaceCollider.material = arManager.colliderMaterial; } } else { // mr headsets if (boundaryPlane == null) { // there was no boundary rendering CreateBoundaryPlane(objCollider.transform, null, true, arManager.colliderMaterial); boundaryMgr = objCollider.AddComponent <HoloToolkit.Unity.Boundary.BoundaryManager>(); boundaryMgr.FloorQuad = boundaryPlane; boundaryMgr.AwakeBoundaryManager(); } } } // // if camera is too near to the floor, lower the floor 1.5 meter below the camera // if(currentCamera && boundaryMgr) // { // if(currentCamera.transform.position.y < 0.1f) // { // boundaryMgr.CurrentFloorHeightOffset = currentCamera.transform.position.y - 1.5f; // Debug.Log(string.Format("FloorHeightOffset set below the camera at {0:F2}m.", boundaryMgr.CurrentFloorHeightOffset)); // } // } // starts co-routine to check rendered surfaces StartCoroutine(CheckSurfacesRoutine()); Debug.Log("TrackingSpaceType: " + XRDevice.GetTrackingSpaceType()); Debug.Log("Screen size: " + Screen.width + " x " + Screen.height); int surfaceLayer = MultiARInterop.GetSurfaceLayer(); // LayerMask.NameToLayer("SpatialSurface"); Debug.Log("SpatialSurfaceLayer: " + surfaceLayer); // interface is initialized isInitialized = true; }
// -- // -- // -- // -- // -- // -- // -- // -- // -- // -- // void Start() { if (!isInterfaceEnabled) { return; } if (!metaCameraRigPrefab) { Debug.LogError("Meta2-interface cannot start: MetaCameraRig-prefab is not set."); return; } // disable the main camera, if any Camera currentCamera = MultiARInterop.GetMainCamera(); if (currentCamera) { currentCamera.gameObject.SetActive(false); } // create ARCore-Device in the scene GameObject arCoreDeviceObj = Instantiate(metaCameraRigPrefab, Vector3.zero, Quaternion.identity); arCoreDeviceObj.name = "ARCore Device"; DontDestroyOnLoad(arCoreDeviceObj); // reference to the AR main camera mainCamera = arCoreDeviceObj.GetComponentInChildren <Camera>(); // // add camera parent // if(currentCamera.transform.parent == null) // { // GameObject cameraParent = new GameObject("CameraParent"); // currentCamera.transform.SetParent(cameraParent.transform); // } // modify the directional light Light currentLight = MultiARInterop.GetDirectionalLight(); if (!currentLight) { GameObject currentLightObj = new GameObject("Directional light"); currentLight = currentLightObj.AddComponent <Light>(); currentLight.type = LightType.Directional; } // reset light position & rotation currentLight.transform.position = Vector3.zero; currentLight.transform.rotation = Quaternion.Euler(40f, 40f, 0f); // set light parameters currentLight.color = new Color32(255, 254, 244, 255); // add the ar-light component //currentLight.gameObject.AddComponent<MultiARDirectionalLight>(); // reference to the AR directional light //directionalLight = currentLight; // don't destroy the light between scenes DontDestroyOnLoad(currentLight.gameObject); // there is no point cloud in WinMR MultiARInterop.MultiARData arData = arManager.GetARData(); // check for point cloud getter if (arManager.pointCloudPrefab != null) { arData.pointCloudData = new Vector3[0]; arData.pointCloudLength = 0; arData.pointCloudTimestamp = 0.0; } // set tracking state cameraTrackingState = WorldManager.state; WorldManager.OnPositionalLocatorStateChanged += WorldManager_OnPositionalLocatorStateChanged; // // set tracking space type // Debug.Log("Before: " + XRDevice.GetTrackingSpaceType()); // if(XRDevice.GetTrackingSpaceType() != TrackingSpaceType.Stationary) // { // if(!XRDevice.SetTrackingSpaceType(TrackingSpaceType.Stationary)) // { // Debug.LogError("Cannot set stationary space type!"); // } // } // create gesture input if (!isDisplayOpaque) { gestureRecognizer = new GestureRecognizer(); gestureRecognizer.SetRecognizableGestures(GestureSettings.Tap | GestureSettings.Hold | GestureSettings.NavigationX | GestureSettings.NavigationY | GestureSettings.NavigationZ); gestureRecognizer.Tapped += GestureRecognizer_Tapped; // gestureRecognizer.HoldStarted += GestureRecognizer_HoldStarted; // gestureRecognizer.HoldCompleted += GestureRecognizer_HoldCompleted; // gestureRecognizer.HoldCanceled += GestureRecognizer_HoldCanceled; gestureRecognizer.NavigationStarted += GestureRecognizer_NavigationStarted; gestureRecognizer.NavigationUpdated += GestureRecognizer_NavigationUpdated; gestureRecognizer.NavigationCompleted += GestureRecognizer_NavigationCompleted; gestureRecognizer.NavigationCanceled += GestureRecognizer_NavigationCanceled; gestureRecognizer.StartCapturingGestures(); Debug.Log("Gesture recognizer inited and started."); } else { InteractionManager.InteractionSourcePressed += InteractionManager_InteractionSourcePressed; InteractionManager.InteractionSourceUpdated += InteractionManager_InteractionSourceUpdated; InteractionManager.InteractionSourceReleased += InteractionManager_InteractionSourceReleased; Debug.Log("Interaction manager inited."); } // create surface renderer if (arManager.useOverlaySurface != MultiARManager.SurfaceRenderEnum.None) { GameObject objRenderer = new GameObject(); objRenderer.name = "SurfaceRenderer"; objRenderer.layer = MultiARInterop.GetSurfaceLayer(); arData.surfaceRendererRoot = objRenderer; surfaceRootTransform = objRenderer.transform; DontDestroyOnLoad(objRenderer); if (!isDisplayOpaque) { // hololens surfaceRenderer = objRenderer.AddComponent <SpatialMappingRenderer>(); surfaceRenderer.surfaceParent = objRenderer; surfaceRenderer.renderState = (SpatialMappingRenderer.RenderState)arManager.useOverlaySurface; if (arManager.useOverlaySurface != MultiARManager.SurfaceRenderEnum.None) { surfaceRenderer.visualMaterial = arManager.surfaceVisualizationMaterial; surfaceRenderer.occlusionMaterial = arManager.surfaceOcclusionMaterial; } } else { // mr headsets CreateBoundaryPlane(objRenderer.transform, arManager.GetSurfaceMaterial(), arManager.surfaceCollider, arManager.colliderMaterial); boundaryMgr = objRenderer.AddComponent <HoloToolkit.Unity.Boundary.BoundaryManager>(); boundaryMgr.FloorQuad = boundaryPlane; boundaryMgr.AwakeBoundaryManager(); } } // create surface collider if (arManager.surfaceCollider) { GameObject objCollider = new GameObject(); objCollider.name = "SurfaceCollider"; objCollider.layer = MultiARInterop.GetSurfaceLayer(); DontDestroyOnLoad(objCollider); if (!isDisplayOpaque) { // hololens surfaceCollider = objCollider.AddComponent <SpatialMappingCollider>(); surfaceCollider.surfaceParent = objCollider; surfaceCollider.lodType = SpatialMappingBase.LODType.Low; surfaceCollider.layer = MultiARInterop.GetSurfaceLayer(); if (arManager.colliderMaterial) { surfaceCollider.material = arManager.colliderMaterial; } } else { // mr headsets if (boundaryPlane == null) { // there was no boundary rendering CreateBoundaryPlane(objCollider.transform, null, true, arManager.colliderMaterial); boundaryMgr = objCollider.AddComponent <HoloToolkit.Unity.Boundary.BoundaryManager>(); boundaryMgr.FloorQuad = boundaryPlane; boundaryMgr.AwakeBoundaryManager(); } } } // // if camera is too near to the floor, lower the floor 1.5 meter below the camera // if(currentCamera && boundaryMgr) // { // if(currentCamera.transform.position.y < 0.1f) // { // boundaryMgr.CurrentFloorHeightOffset = currentCamera.transform.position.y - 1.5f; // Debug.Log(string.Format("FloorHeightOffset set below the camera at {0:F2}m.", boundaryMgr.CurrentFloorHeightOffset)); // } // } // starts co-routine to check rendered surfaces StartCoroutine(CheckSurfacesRoutine()); Debug.Log("TrackingSpaceType: " + XRDevice.GetTrackingSpaceType()); Debug.Log("Screen size: " + Screen.width + " x " + Screen.height); int surfaceLayer = MultiARInterop.GetSurfaceLayer(); // LayerMask.NameToLayer("SpatialSurface"); Debug.Log("SpatialSurfaceLayer: " + surfaceLayer); // interface is initialized isInitialized = true; }