Пример #1
0
        /// <summary>
        /// Loads Collada Data from File
        /// </summary>
        /// <param name="fileName"></param>
        /// <returns></returns>
        public static Collada LoadFromFile(string fileName)
        {
            try
            {
                Collada collada = null;

                XmlSerializer serializer = new XmlSerializer(typeof(Collada));
                using (TextReader stream = new StreamReader(fileName))
                    collada = (Collada)(serializer.Deserialize(stream));

                return(collada);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.ToString());
                return(null);
            }
        }
Пример #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="filePath"></param>
        /// <returns></returns>
        public IOScene GetScene(string filePath)
        {
            // generate a new scene
            IOScene scene = new IOScene();


            // load collada file
            _collada = Collada.LoadFromFile(filePath);

            // failed to load collada file
            if (_collada == null)
            {
                return(scene);
            }

            // load material library's to scene
            if (_collada.Library_Materials != null)
            {
                foreach (var mat in _collada.Library_Materials.Material)
                {
                    scene.Materials.Add(LoadMaterial(mat));
                }
            }


            // look through all visual scene
            foreach (var colscene in _collada.Library_Visual_Scene.Visual_Scene)
            {
                // treat each scene as a "model"
                IOModel model = new IOModel()
                {
                    Name = colscene.Name
                };

                // scan skeletons
                List <string> skelIDs = new List <string>();
                foreach (var v in colscene.Node)
                {
                    if (GetSkeletonReferences(v, out List <string> joints))
                    {
                        foreach (var j in joints)
                        {
                            if (!skelIDs.Contains(j))
                            {
                                skelIDs.Add(j);
                            }
                        }
                    }
                }

                // load nodes
                foreach (var v in colscene.Node)
                {
                    LoadNodes(v, null, model, skelIDs);
                }

                // add model
                scene.Models.Add(model);
            }


            // cleanup
            _collada = null;


            // done
            return(scene);
        }