コード例 #1
0
ファイル: SceneView.cs プロジェクト: memogarcia/mac-samples
        public void LoadScene(string path)
        {
            NSError error;

            this.selectedMaterial = null;

            // Load the specified scene. First create a dictionary containing the options we want.
            var options = new SCNSceneLoadingOptions
            {
                // Create normals if absent.
                CreateNormalsIfAbsent = true,
                // Optimize the rendering by flattening the scene graph when possible. Note that this would prevent you from animating objects independantly.
                FlattenScene = true,
            };

            var scene = SCNScene.FromUrl(new NSUrl($"file://{path}"), options, out error);

            if (scene != null)
            {
                base.Scene = scene;
            }
            else
            {
                Console.WriteLine($"Problem loading scene from: {path}\n{error.LocalizedDescription}");
            }
        }
コード例 #2
0
        internal static SCNNode Load3DModel(NSUrl url)
        {
            var scene = SCNScene.FromUrl(url, new NSDictionary(), out var err);

            if (scene == null)
            {
                Console.WriteLine($"Error: failed to load 3D model from file {url}.");
                if (err != null)
                {
                    Console.WriteLine(err.ToString());
                }
                return(null);
            }

            var node = new SCNNode();

            foreach (var child in scene.RootNode.ChildNodes)
            {
                node.AddChildNode(child);
            }

            // If there are no light sources in the model, add some
            var lightNodes = node.ChildNodes.Where(child => child.Light != null);

            if (lightNodes.Count() == 0)
            {
                var ambientLight = new SCNLight
                {
                    LightType = SCNLightType.Ambient,
                    Intensity = 100
                };
                var ambientLightNode = new SCNNode();
                ambientLightNode.Light = ambientLight;
                node.AddChildNode(ambientLightNode);

                var directionLight = new SCNLight
                {
                    LightType = SCNLightType.Directional,
                    Intensity = 500
                };
                var directionalLightNode = new SCNNode();
                directionalLightNode.Light = directionLight;
                node.AddChildNode(directionalLightNode);
            }
            return(node);
        }
コード例 #3
0
ファイル: GameLevel.cs プロジェクト: zain-tariq/ios-samples
        public void Load()
        {
            // have to do this
            [email protected]();

            // only load once - can be called from preload on another thread, or regular load
            if (this.scene == null)
            {
                var sceneUrl = NSBundle.MainBundle.GetUrlForResource(this.Path, "scn");
                if (sceneUrl == null)
                {
                    throw new Exception($"Level {this.Path} not found");
                }

                var scene = SCNScene.FromUrl(sceneUrl, (SCNSceneLoadingOptions)null, out NSError error);
                if (error != null)
                {
                    throw new Exception($"Could not load level {sceneUrl}: {error.LocalizedDescription}");
                }

                // start with animations and physics paused until the board is placed
                // we don't want any animations or things falling over while ARSceneView
                // is driving SceneKit and the view.
                scene.Paused = true;

                // walk down the scenegraph and update the children
                scene.RootNode.FixMaterials();

                this.scene = scene;

                // this may not be the root, but lookup the identifier
                // will clone the tree done from this node
                this.levelNodeTemplate = this.scene.RootNode.FindChildNode("_" + Identifier, true);
            }

            [email protected]();
        }
コード例 #4
0
ファイル: SceneView.cs プロジェクト: zfs990/mac-samples
        public void LoadScene(string path)
        {
            NSError error;

            Scene = SCNScene.FromUrl(new NSUrl("file://" + path), (SCNSceneLoadingOptions)null, out error);
        }