コード例 #1
0
        public static STGenericScene Read(string fileName, DAE.ImportSettings settings = null)
        {
            if (settings == null)
            {
                settings = new ImportSettings();
            }
            settings.FolderPath = Path.GetDirectoryName(fileName);

            return(ColladaReader.Read(fileName, settings));
        }
コード例 #2
0
            public ColladaScene(COLLADA collada, DAE.ImportSettings settings)
            {
                Settings    = settings;
                geometries  = FindLibraryItem <library_geometries>(collada.Items);
                images      = FindLibraryItem <library_images>(collada.Items);
                scenes      = FindLibraryItem <library_visual_scenes>(collada.Items);
                effects     = FindLibraryItem <library_effects>(collada.Items);
                controllers = FindLibraryItem <library_controllers>(collada.Items);
                materials   = FindLibraryItem <library_materials>(collada.Items);

                if (effects != null)
                {
                    for (int i = 0; i < effects.effect.Length; i++)
                    {
                        effectLookup.Add(effects.effect[i].id, effects.effect[i]);
                    }
                }

                if (collada.asset != null)
                {
                    UpAxisType = collada.asset.up_axis;
                    UintSize   = collada.asset.unit;
                }
            }
コード例 #3
0
        static STGenericScene Read(COLLADA collada, DAE.ImportSettings settings)
        {
            if (settings == null)
            {
                settings = new DAE.ImportSettings();
            }

            Stopwatch sw = new Stopwatch();

            sw.Start();

            STGenericScene Scene        = new STGenericScene();
            ColladaScene   colladaScene = new ColladaScene(collada, settings);

            //Usually there is only one scene, but it can be possible some tools use multiple per model
            //Each one contains node hiearchies for bones and meshes
            foreach (var scene in colladaScene.scenes.visual_scene)
            {
                var  model = new STGenericModel(scene.name);
                Node Root  = LoadScene(scene, model, colladaScene);
                Scene.Models.Add(model);

                if (colladaScene.materials != null)
                {
                    foreach (var mat in colladaScene.materials.material)
                    {
                        model.Materials.Add(LoadMaterial(colladaScene, mat));
                    }
                }
                else
                {
                    model.Materials.Add(new STGenericMaterial()
                    {
                        Name = "Dummy"
                    });
                }

                if (model.Skeleton.Bones.Count == 0)
                {
                    model.Skeleton.Bones.Add(new STBone(model.Skeleton, "root"));
                }

                if (settings.FixDuplicateNames)
                {
                    //Adjust duplicate names

                    /*    foreach (var mesh in model.Meshes)
                     *  {
                     *      var names = model.Meshes.Select(x => x.Name).ToList();
                     *      mesh.Name = Utility.RenameDuplicateString(names, mesh.Name, 0, 2);
                     *  }
                     *
                     *  foreach (var mat in model.Materials)
                     *  {
                     *      var names = model.Materials.Select(x => x.Name).ToList();
                     *      mat.Name = Utility.RenameDuplicateString(names, mat.Name, 0, 2);
                     *  }
                     *
                     *  foreach (var bone in model.Skeleton.Bones)
                     *  {
                     *      var names = model.Skeleton.Bones.Select(x => x.Name).ToList();
                     *      bone.Name = Utility.RenameDuplicateString(names, bone.Name, 0, 2);
                     *  }*/
                }
            }

            sw.Stop();
            Console.WriteLine("Elapsed={0}", sw.Elapsed);

            return(Scene);
        }
コード例 #4
0
 public static STGenericScene Read(System.IO.Stream stream, DAE.ImportSettings settings = null)
 {
     return(Read(COLLADA.Load(stream), settings));
 }
コード例 #5
0
 public static STGenericScene Read(string fileName, DAE.ImportSettings settings = null)
 {
     return(Read(COLLADA.Load(fileName), settings));
 }
コード例 #6
0
        static STGenericScene Read(COLLADA collada, DAE.ImportSettings settings)
        {
            if (settings == null)
            {
                settings = new DAE.ImportSettings();
            }

            string    folder = settings.FolderPath;
            Stopwatch sw     = new Stopwatch();

            sw.Start();

            STGenericScene Scene        = new STGenericScene();
            ColladaScene   colladaScene = new ColladaScene(collada, settings);

            BoneNameIds.Clear();

            //Usually there is only one scene, but it can be possible some tools use multiple per model
            //Each one contains node hiearchies for bones and meshes
            foreach (var scene in colladaScene.scenes.visual_scene)
            {
                var model = new STGenericModel(scene.name);
                model.Textures = LoadTextures(folder, colladaScene).OrderBy(x => x.Name).ToList();
                Node Root = LoadScene(scene, model, colladaScene);
                Scene.Models.Add(model);

                if (colladaScene.materials != null)
                {
                    foreach (var mat in colladaScene.materials.material)
                    {
                        model.Materials.Add(LoadMaterial(colladaScene, mat));
                    }
                }
                else
                {
                    model.Materials.Add(new STGenericMaterial()
                    {
                        Name = "Dummy"
                    });
                }

                if (model.Skeleton.Bones.Count == 0)
                {
                    model.Skeleton.Bones.Add(new STBone(model.Skeleton, "root"));
                }

                //Setup bone indices
                foreach (var mesh in model.Meshes)
                {
                    for (int v = 0; v < mesh.Vertices.Count; v++)
                    {
                        for (int j = 0; j < mesh.Vertices[v].BoneNames.Count; j++)
                        {
                            string sid  = mesh.Vertices[v].BoneNames[j];
                            string name = BoneNameIds.ContainsKey(sid) ? BoneNameIds[sid] : sid;
                            mesh.Vertices[v].BoneNames[j] = name;

                            int index = model.Skeleton.Bones.FindIndex(x => x.Name == name);
                            if (index != -1)
                            {
                                mesh.Vertices[v].BoneIndices.Add(index);
                            }
                        }
                    }

                    foreach (var group in mesh.PolygonGroups)
                    {
                        if (group.MaterialIndex < model.Materials.Count && group.MaterialIndex != -1)
                        {
                            group.Material = model.Materials[group.MaterialIndex];
                        }
                    }

                    if (colladaScene.UpAxisType == UpAxisType.Z_UP)
                    {
                        for (int v = 0; v < mesh.Vertices.Count; v++)
                        {
                            mesh.Vertices[v].Position = new Vector3(
                                mesh.Vertices[v].Position.X,
                                mesh.Vertices[v].Position.Z,
                                -mesh.Vertices[v].Position.Y);
                            mesh.Vertices[v].Normal = new Vector3(
                                mesh.Vertices[v].Normal.X,
                                mesh.Vertices[v].Normal.Z,
                                -mesh.Vertices[v].Normal.Y);
                        }
                    }
                }

                if (settings.FixDuplicateNames)
                {
                    //Adjust duplicate names

                    /*    foreach (var mesh in model.Meshes)
                     *  {
                     *      var names = model.Meshes.Select(x => x.Name).ToList();
                     *      mesh.Name = Utility.RenameDuplicateString(names, mesh.Name, 0, 2);
                     *  }
                     *
                     *  foreach (var mat in model.Materials)
                     *  {
                     *      var names = model.Materials.Select(x => x.Name).ToList();
                     *      mat.Name = Utility.RenameDuplicateString(names, mat.Name, 0, 2);
                     *  }
                     *
                     *  foreach (var bone in model.Skeleton.Bones)
                     *  {
                     *      var names = model.Skeleton.Bones.Select(x => x.Name).ToList();
                     *      bone.Name = Utility.RenameDuplicateString(names, bone.Name, 0, 2);
                     *  }*/
                }
            }

            BoneNameIds.Clear();

            sw.Stop();
            Console.WriteLine("DAE Elapsed={0}", sw.Elapsed);

            return(Scene);
        }
コード例 #7
0
ファイル: DAE.cs プロジェクト: KillzXGaming/Toolbox.Core
 public static STGenericScene Read(string fileName, DAE.ImportSettings settings = null)
 {
     return(ColladaReader.Read(fileName, settings));
 }
コード例 #8
0
ファイル: DAE.cs プロジェクト: KillzXGaming/Toolbox.Core
 public static STGenericScene Read(System.IO.Stream stream, DAE.ImportSettings settings = null)
 {
     return(ColladaReader.Read(stream, settings));
 }