示例#1
0
        public void DidAddNode(ISCNSceneRenderer renderer, SCNNode node, ARAnchor anchor)
        {
            // Place content only for anchors found by plane detection.
            if (anchor is ARPlaneAnchor && this.previewNode != null)
            {
                // Stop showing a preview version of the object to be placed.
                this.cupNode.RemoveFromParentNode();

                this.previewNode?.RemoveFromParentNode();
                this.previewNode?.Dispose();
                this.previewNode = null;

                // Add the cupNode to the scene's root node using the anchor's position.
                var cameraTransform = this.sceneView.Session.CurrentFrame?.Camera?.Transform;
                if (cameraTransform.HasValue)
                {
                    this.SetNewVirtualObjectToAnchor(this.cupNode, anchor, cameraTransform.Value);
                    this.sceneView.Scene.RootNode.AddChildNode(this.cupNode);

                    // Disable plane detection after the model has been added.
                    var configuration = new ARWorldTrackingConfiguration {
                        PlaneDetection = ARPlaneDetection.Horizontal
                    };
                    this.sceneView.Session.Run(configuration, default(ARSessionRunOptions));

                    // Set up positional audio to play in case the object moves offscreen.
                    this.PlaySound();
                }
            }
        }
示例#2
0
        /// <summary>
        /// Loads the cup model (`cupNode`) that is used for the duration of the app.
        /// Initializes a `PreviewNode` that contains the `cupNode` and adds it to the node hierarchy.
        /// </summary>
        private void SetupPreviewNode()
        {
            if (this.cupNode.FindChildNode("candle", false) == null)
            {
                // Load the cup scene from the bundle only once.
                var modelScene = SCNScene.FromFile("art.scnassets/candle/candle.scn");
                // Get a handle to the cup model.
                var cup = modelScene.RootNode.FindChildNode("candle", true);
                // Set the cup model onto `cupNode`.
                this.cupNode.AddChildNode(cup);
            }

            // Initialize `previewNode` to display the cup model.
            this.previewNode = new PreviewNode(this.cupNode);
            // Add `previewNode` to the node hierarchy.
            this.sceneView.Scene.RootNode.AddChildNode(this.previewNode);
        }
示例#3
0
        private void ResetTracking()
        {
            var configuration = new ARWorldTrackingConfiguration {
                PlaneDetection = ARPlaneDetection.Horizontal
            };

            this.sceneView.Session.Run(configuration, ARSessionRunOptions.ResetTracking | ARSessionRunOptions.RemoveExistingAnchors);

            // Reset preview state.
            this.cupNode.RemoveFromParentNode();
            this.cupNode.Dispose();
            this.cupNode = new SCNNode();

            this.previewNode?.RemoveFromParentNode();
            this.previewNode?.Dispose();
            this.previewNode = null;

            this.PlaySound();
        }