/// <summary> /// Runs the session with a new AR configuration to change modes or reset the experience. /// </summary> private void ResetTracking(bool changeTextureMode = false) { var configuration = new ARWorldTrackingConfiguration(); configuration.PlaneDetection = ARPlaneDetection.Horizontal; configuration.EnvironmentTexturing = this.currentTexturingMode; var session = this.sceneView.Session; if (changeTextureMode) { // Remove existing environment probe anchors. if (session.CurrentFrame?.Anchors != null) { foreach (var anchor in session.CurrentFrame.Anchors) { session.RemoveAnchor(anchor); } } // Don't reset tracking when changing modes in the same session. session.Run(configuration); } else { session.Run(configuration, ARSessionRunOptions.ResetTracking | ARSessionRunOptions.RemoveExistingAnchors); } this.isEnvironmentTextureAvailable = false; this.sceneEnvironmentProbeAnchor?.Dispose(); this.sceneEnvironmentProbeAnchor = null; configuration.Dispose(); session.Dispose(); }
void EnvironmentProbeAnchorUpdated(AREnvironmentProbeAnchor anchorData) { if (probeAnchorMap.ContainsKey(anchorData.identifier)) { probeAnchorMap [anchorData.identifier].UpdateEnvironmentProbe(anchorData); } }
void EnvironmentProbeAnchorRemoved(AREnvironmentProbeAnchor anchorData) { if (probeAnchorMap.ContainsKey(anchorData.identifier)) { ReflectionProbeGameObject rpgo = probeAnchorMap [anchorData.identifier]; GameObject.Destroy(rpgo.gameObject); probeAnchorMap.Remove(anchorData.identifier); } }
private void UpdateSceneEnvironmentProbe(ARFrame frame) { if (this.sceneEnvironmentProbeAnchor == null && this.currentTexturingMode == AREnvironmentTexturing.Manual) { // Create an environment probe anchor with room-sized extent to act as fallback when the probe anchor of // an object is removed and added during translation and scaling this.sceneEnvironmentProbeAnchor = new AREnvironmentProbeAnchor("sceneProbe", OpenTK.NMatrix4.Identity, new OpenTK.NVector3(5f, 5f, 5f)); this.sceneView.Session.AddAnchor(this.sceneEnvironmentProbeAnchor); } }
public void MarshallingTest2() { var probeAnchorWithName = new AREnvironmentProbeAnchor("My Anchor", MatrixFloat4x4.Identity, new VectorFloat3(1, 1, 1)); Assert.AreEqual(MatrixFloat4x4.Identity, probeAnchorWithName.Transform, "Transform"); // broken since xcode 12 beta 1 on simulator (only) if ((Runtime.Arch == Arch.DEVICE) || !TestRuntime.CheckXcodeVersion(12, 0)) { Assert.AreEqual(new VectorFloat3(1, 1, 1), probeAnchorWithName.Extent, "Extent"); } }
public void MarshallingTest() { var probeAnchor = new AREnvironmentProbeAnchor(MatrixFloat4x4.Identity, new VectorFloat3(1, 1, 1)); Assert.AreEqual(MatrixFloat4x4.Identity, probeAnchor.Transform, "Transform"); Assert.AreEqual(new VectorFloat3(1, 1, 1), probeAnchor.Extent, "Extent"); var probeAnchorWithName = new AREnvironmentProbeAnchor("My Anchor", MatrixFloat4x4.Identity, new VectorFloat3(1, 1, 1)); Assert.AreEqual(MatrixFloat4x4.Identity, probeAnchorWithName.Transform, "Transform"); Assert.AreEqual(new VectorFloat3(1, 1, 1), probeAnchorWithName.Extent, "Extent"); }
void EnvironmentProbeAnchorAdded(AREnvironmentProbeAnchor anchorData) { ReflectionProbeGameObject go = GameObject.Instantiate <ReflectionProbeGameObject> (m_ReflectionProbePrefab); if (go != null) { //do coordinate conversion from ARKit to Unity go.transform.position = UnityARMatrixOps.GetPosition(anchorData.transform); go.transform.rotation = UnityARMatrixOps.GetRotation(anchorData.transform); probeAnchorMap [anchorData.identifier] = go; go.UpdateEnvironmentProbe(anchorData); } }
partial void ChangeTextureMode(UISegmentedControl sender) { if (sender.SelectedSegment == 0) { this.currentTexturingMode = AREnvironmentTexturing.Automatic; this.environmentProbeAnchor?.Dispose(); this.environmentProbeAnchor = null; } else { this.currentTexturingMode = AREnvironmentTexturing.Manual; this.requiresProbeRefresh = true; } // Remove anchors and change texturing mode this.ResetTracking(true); }
private void UpdateEnvironmentProbe(double time) { // Update the probe only if the object has been moved or scaled, // only when manually placed, not too often. if (this.virtualObject != null && this.currentTexturingMode == AREnvironmentTexturing.Manual && time - this.lastProbeAnchorUpdateTime >= 1d && this.requiresProbeRefresh) { // Remove existing probe anchor, if any. var probeAnchor = this.environmentProbeAnchor; if (probeAnchor != null) { this.sceneView.Session.RemoveAnchor(probeAnchor); this.environmentProbeAnchor.Dispose(); this.environmentProbeAnchor = null; } // Make sure the probe encompasses the object and provides some surrounding area to appear in reflections. var extent = SCNVector3.Multiply(this.virtualObject.GetExtents(), this.virtualObject.Scale); extent.X *= 3; // Reflect an area 3x the width of the object. extent.Z *= 3; // Reflect an area 3x the depth of the object. // Also include some vertical area around the object, but keep the bottom of the probe at the // bottom of the object so that it captures the real-world surface underneath. var verticalOffset = new SCNVector3(0, extent.Y, 0); var transform = NMatrix4Extensions.CreateTranslation(this.virtualObject.Position + verticalOffset); extent.Y *= 2; // Create the new environment probe anchor and add it to the session. probeAnchor = new AREnvironmentProbeAnchor(transform, new OpenTK.NVector3(extent.X, extent.Y, extent.Z)); this.sceneView.Session.AddAnchor(probeAnchor); // Remember state to prevent updating the environment probe too often. this.environmentProbeAnchor = probeAnchor; this.lastProbeAnchorUpdateTime = CoreAnimation.CAAnimation.CurrentMediaTime(); this.requiresProbeRefresh = false; } }
public void UpdateEnvironmentProbe(AREnvironmentProbeAnchor environmentProbeAnchor) { transform.position = UnityARMatrixOps.GetPosition(environmentProbeAnchor.transform); Quaternion rot = UnityARMatrixOps.GetRotation(environmentProbeAnchor.transform); //rot.z = -rot.z; //rot.w = -rot.w; transform.rotation = rot; if (reflectionProbe != null) { reflectionProbe.size = environmentProbeAnchor.Extent; } if (debugExtentGO != null) { debugExtentGO.transform.localScale = environmentProbeAnchor.Extent; } latchedTexture = environmentProbeAnchor.Cubemap; latchUpdate = true; }