示例#1
0
        private SCNNode LoadRedPandaModel()
        {
            var sceneURL      = NSBundle.MainBundle.GetUrlForResource("max", "scn", "art.scnassets");
            var referenceNode = SCNReferenceNode.CreateFromUrl(sceneURL);

            referenceNode.Load();

            return(referenceNode);
        }
示例#2
0
        private void InitializeVirtualObjectModel()
        {
            var sceneUrl = NSBundle.MainBundle.GetUrlForResource("sphere", "scn", "art.scnassets/sphere");

            if (sceneUrl != null)
            {
                var referenceNode = SCNReferenceNode.CreateFromUrl(sceneUrl);
                if (referenceNode != null)
                {
                    referenceNode.Load();
                    this.virtualObjectModel = referenceNode;
                }
            }

            if (this.virtualObjectModel == null)
            {
                throw new Exception("can't load virtual object");
            }
        }
示例#3
0
        public static SCNNode LoadSCNAsset(string modelFileName)
        {
            var assetPaths = new string[]
            {
                "art.scnassets/models/",
                "art.scnassets/blocks/",
                "art.scnassets/projectiles/",
                "art.scnassets/catapults/",
                "art.scnassets/levels/",
                "art.scnassets/effects/"
            };

            var assetExtensions = new string[] { "scn", "scnp" };

            SCNReferenceNode nodeRefSearch = null;

            foreach (var path in assetPaths)
            {
                foreach (var ext in assetExtensions)
                {
                    var url = NSBundle.MainBundle.GetUrlForResource(path + modelFileName, ext);
                    if (url != null)
                    {
                        nodeRefSearch = SCNReferenceNode.CreateFromUrl(url);
                        if (nodeRefSearch != null)
                        {
                            break;
                        }
                    }
                }

                if (nodeRefSearch != null)
                {
                    break;
                }
            }

            if (nodeRefSearch != null)
            {
                // this does the load, default policy is load immediate
                nodeRefSearch.Load();

                // log an error if geo not nested under a physics shape
                var node = nodeRefSearch.ChildNodes.FirstOrDefault();
                if (node == null)
                {
                    throw new Exception($"model {modelFileName} has no child nodes");
                }

                if (nodeRefSearch.ChildNodes.Count() > 1)
                {
                    //os_log(.error, "model %s should have a single root node", modelFileName)
                }

                // walk down the scenegraph and update all children
                node.FixMaterials();

                return(node);
            }
            else
            {
                throw new Exception($"couldn't load {modelFileName}");
            }
        }