Ejemplo n.º 1
0
        public void ExportModel(string folderPath, DAE.ExportSettings settings)
        {
            foreach (LM3_Model mdl in Nodes)
            {
                List <STGenericMaterial> Materials = new List <STGenericMaterial>();
                foreach (STGenericObject mesh in mdl.RenderedMeshes)
                {
                    if (mesh.GetMaterial() != null)
                    {
                        Materials.Add(mesh.GetMaterial());
                    }
                }

                if (!mdl.loaded)
                {
                    mdl.UpdateVertexData();
                }

                var model = new STGenericModel();
                model.Materials = Materials;
                model.Objects   = mdl.RenderedMeshes;

                settings.SuppressConfirmDialog = true;

                DAE.Export($"{folderPath}/{mdl.Text}.dae", settings, model, new List <STGenericTexture>());
            }

            System.Windows.Forms.MessageBox.Show($"Exported models Successfuly!");
        }
Ejemplo n.º 2
0
        public override void OnClick()
        {
            if (loaded)
            {
                return;
            }

            STGenericModel model = new STGenericModel(Label);

            model.Skeleton = new SkeletonFormat();
            model.Meshes.Add(new STGenericMesh());

            if (DataParser.Version == DICT.GameVersion.LM2)
            {
                model.Skeleton = LM2.SkeletonChunk.Read(File.ChunkEntry.SubData);
            }
            if (DataParser.Version == DICT.GameVersion.LM3)
            {
                model.Skeleton = LM3.SkeletonChunk.Read(File.ChunkEntry.SubData);
            }

            Tag = new ModelFormat(model);

            foreach (var child in model.CreateTreeHiearchy().Children)
            {
                AddChild(child);
            }

            loaded = true;
        }
Ejemplo n.º 3
0
        private static STBone LoadBoneHiearchy(node daeNode, STGenericModel model,
                                               STBone boneParent, ref Matrix4 parentTransform)
        {
            STBone bone = new STBone(model.Skeleton, daeNode.name);

            model.Skeleton.Bones.Add(bone);

            var transform = DaeUtility.GetMatrix(daeNode.Items) * parentTransform;

            bone.Position = transform.ExtractTranslation();
            bone.Scale    = transform.ExtractScale();
            bone.Rotation = transform.ExtractRotation();
            bone.Parent   = boneParent;
            Console.WriteLine("NODE " + bone.Name + " " + bone.Transform);

            //Reset the parent transform for children. We only need to apply the parent root transform
            parentTransform = Matrix4.Identity;

            if (daeNode.node1 != null)
            {
                foreach (node child in daeNode.node1)
                {
                    bone.Children.Add(LoadBoneHiearchy(child, model, bone, ref parentTransform));
                }
            }
            return(bone);
        }
Ejemplo n.º 4
0
        private void ExportAction(object sender, EventArgs args)
        {
            SaveFileDialog sfd = new SaveFileDialog();

            sfd.Filter   = "Collada DAE |*.dae;";
            sfd.FileName = System.IO.Path.GetFileNameWithoutExtension(FileName);
            if (sfd.ShowDialog() == DialogResult.OK)
            {
                var model     = new STGenericModel();
                var materials = new List <STGenericMaterial>();
                var textures  = new List <STGenericTexture>();
                foreach (var mesh in Renderer.Meshes)
                {
                    materials.Add(mesh.GetMaterial());
                }
                foreach (var mesh in Renderer.Meshes)
                {
                    mesh.MaterialIndex = materials.IndexOf(mesh.GetMaterial());
                }
                foreach (var tex in Renderer.TextureList)
                {
                    textures.Add(tex);
                }

                model.Materials = materials;
                model.Objects   = Renderer.Meshes;

                ExportModelSettings exportDlg = new ExportModelSettings();
                if (exportDlg.ShowDialog() == DialogResult.OK)
                {
                    DAE.Export(sfd.FileName, exportDlg.Settings, model, textures, Skeleton);
                }
            }
        }
Ejemplo n.º 5
0
        public STGenericModel ToGeneric()
        {
            if (Model != null)
            {
                return(Model);
            }

            STGenericModel model = new STGenericModel(FileInfo.FileName);

            model.Skeleton = Skeleton;
            foreach (var mesh in GenericMeshes)
            {
                model.Meshes.Add(mesh);
            }

            foreach (var mesh in GenericMeshes)
            {
                model.Materials.AddRange(mesh.GetMaterials());
            }

            model.Textures.AddRange(GenericTextures);

            Model = model;
            return(model);
        }
Ejemplo n.º 6
0
        public STGenericModel ToGeneric()
        {
            if (CachedModel != null)
            {
                return(CachedModel);
            }

            var model = new STGenericModel(FileInfo.FileName);

            foreach (var mdl in Header.Models)
            {
                foreach (var obj in mdl.Objects)
                {
                    if (obj.Type == ObjectBlock.ObjectType.Mesh)
                    {
                        model.Meshes.Add(LoadMesh(mdl, obj, obj.MeshData));
                    }
                }
            }
            foreach (var tex in Header.Textures)
            {
                foreach (var image in tex.Images)
                {
                    model.Textures.Add(new HBDFTexture(image));
                }
            }

            CachedModel = model;
            return(model);
        }
Ejemplo n.º 7
0
        public void ExportModel(string fileName, DAE.ExportSettings settings)
        {
            List <STGenericMaterial> Materials = new List <STGenericMaterial>();

            foreach (var mesh in Renderer.Meshes)
            {
                if (mesh.GetMaterial() != null)
                {
                    Materials.Add(mesh.GetMaterial());
                }
            }

            var textures = new List <STGenericTexture>();

            foreach (var tex in PluginRuntime.stikersTextures)
            {
                textures.Add(tex);
            }

            var model = new STGenericModel();

            model.Materials = Materials;
            model.Objects   = Renderer.Meshes;

            STSkeleton skeleton = null;

            if (DrawableContainer.Drawables.Count > 1)
            {
                skeleton = (STSkeleton)DrawableContainer.Drawables[1];
            }

            DAE.Export(fileName, settings, model, textures, skeleton);
        }
Ejemplo n.º 8
0
        public STGenericModel ToGeneric()
        {
            if (Model != null)
            {
                return(Model);
            }

            var model = new STGenericModel(FileInfo.FileName);

            /*     var msh = new STGenericMesh() { Name = $"Mesh0" };
             *   model.Meshes.Add(msh);
             *
             *   List<STVertex> verts = new List<STVertex>();
             *   for (int v = 0; v < MorphData.Positions.Count; v++)
             *   {
             *       STVertex vertex = new STVertex();
             *       vertex.Position = MorphData.Positions[v];
             *       verts.Add(vertex);
             *   }
             *
             *   STPolygonGroup group = new STPolygonGroup();
             *   group.PrimitiveType = STPrimitiveType.Points;
             *   msh.PolygonGroups.Add(group);
             *
             *   msh.Vertices.AddRange(verts);
             *   msh.Optmize(group);
             */

            for (int i = 0; i < MorphData.MorphGroups.Count; i++)
            {
                var mesh = new STGenericMesh()
                {
                    Name = $"Mesh{i}"
                };
                model.Meshes.Add(mesh);

                var morphData = MorphData.MorphGroups[i];

                STPolygonGroup group = new STPolygonGroup();
                group.PrimitiveType = STPrimitiveType.Triangles;
                mesh.PolygonGroups.Add(group);

                List <STVertex> verts = new List <STVertex>();
                for (int v = 0; v < morphData.Positions.Count; v++)
                {
                    STVertex vertex = new STVertex();
                    vertex.Position = morphData.Positions[v];
                    verts.Add(vertex);
                }

                verts = ConvertTriStrips(verts);
                mesh.Vertices.AddRange(verts);

                mesh.Optmize(group);
            }

            Model = model;
            return(model);
        }
Ejemplo n.º 9
0
        public void ExportModel(string fileName, DAE.ExportSettings settings)
        {
            var model = new STGenericModel();

            model.Materials = new List <STGenericMaterial>();
            model.Objects   = Renderer.Meshes;

            DAE.Export(fileName, settings, model, new List <STGenericTexture>(), new STSkeleton());
        }
Ejemplo n.º 10
0
        public void ExportModel(string fileName, DAE.ExportSettings settings)
        {
            var model = new STGenericModel();

            model.Materials = Materials;
            model.Objects   = Shapes;

            DAE.Export(fileName, settings, model, BcresParent.GetTextures(), Skeleton.Renderable);
        }
Ejemplo n.º 11
0
        public static Node LoadHiearchy(Node parent, node daeNode,
                                        STGenericModel model, ColladaScene colladaScene)
        {
            Node node = new Node(parent);

            node.Name      = daeNode.name;
            node.Type      = daeNode.type;
            node.Transform = DaeUtility.GetMatrix(daeNode.Items) * parent.Transform;

            if (daeNode.instance_geometry != null)
            {
                geometry geom = DaeUtility.FindGeoemertyFromNode(daeNode, colladaScene.geometries);
                model.Meshes.Add(LoadMeshData(colladaScene, node, geom, colladaScene.materials));
            }
            if (daeNode.instance_controller != null)
            {
                controller controller = DaeUtility.FindControllerFromNode(daeNode, colladaScene.controllers);
                geometry   geom       = DaeUtility.FindGeoemertyFromController(controller, colladaScene.geometries);
                model.Meshes.Add(LoadMeshData(colladaScene, node, geom, colladaScene.materials, controller));
            }

            try
            {
            }
            catch (Exception ex)
            {
                throw new Exception($"Failed to convert mesh {daeNode.name} \n {ex.ToString()}");
            }

            //Find the root bone
            if (node.Type == NodeType.JOINT)
            {
                //Apply axis rotation
                Matrix4 boneTransform = Matrix4.Identity;
                if (colladaScene.UpAxisType == UpAxisType.Y_UP)
                {
                    //  boneTransform = Matrix4.CreateRotationX(MathHelper.DegreesToRadians(90));
                }
                if (colladaScene.UintSize != null && colladaScene.UintSize.meter != 1)
                {
                    var scale = ApplyUintScaling(colladaScene, new Vector3(1));
                    boneTransform *= Matrix4.CreateScale(scale);
                }

                LoadBoneHiearchy(daeNode, model, null, ref boneTransform);
            }
            else if (daeNode.node1 != null)
            {
                foreach (node child in daeNode.node1)
                {
                    node.Children.Add(LoadHiearchy(node, child, model, colladaScene));
                }
            }

            return(node);
        }
Ejemplo n.º 12
0
        public ModelRenderer(STGenericModel model)
        {
            Model = model;

            foreach (var mesh in Model.Meshes)
            {
                Meshes.Add(new MeshRender(mesh, this));
            }

            SkeletonRender = new SkeletonRenderer(model);
        }
Ejemplo n.º 13
0
        public ModelRenderer(STGenericModel model)
        {
            Scene = new STGenericScene();
            Scene.Models.Add(model);

            foreach (var mesh in model.Meshes)
            {
                Meshes.Add(new MeshRender(mesh, this));
            }

            SkeletonRender = new SkeletonRenderer(model);
        }
Ejemplo n.º 14
0
        private void ExportModel(string FileName)
        {
            AssimpSaver         assimp   = new AssimpSaver();
            ExportModelSettings settings = new ExportModelSettings();

            var model = new STGenericModel();

            model.Materials = new List <STGenericMaterial>();
            model.Objects   = Renderer.Meshes;

            assimp.SaveFromModel(model, FileName, new List <STGenericTexture>(), new STSkeleton());
        }
Ejemplo n.º 15
0
        public void ExportModel(string fileName, DAE.ExportSettings settings)
        {
            List <STGenericMaterial> Materials = new List <STGenericMaterial>();
            //  foreach (var msh in DataDictionary.Renderer.Meshes)
            //    Materials.Add(msh.GetMaterial());

            var model = new STGenericModel();

            model.Materials = Materials;
            model.Objects   = RenderedMeshes;

            DAE.Export(fileName, settings, model, new List <STGenericTexture>(), new STSkeleton());
        }
Ejemplo n.º 16
0
        public override void Export(string FileName)
        {
            AssimpSaver         assimp   = new AssimpSaver();
            ExportModelSettings settings = new ExportModelSettings();

            var model = new STGenericModel();

            model.Materials = Materials;
            model.Objects   = Shapes;


            assimp.SaveFromModel(model, FileName, BcresParent.GetTextures(), Skeleton.Renderable);
        }
Ejemplo n.º 17
0
        public static Node LoadScene(visual_scene visualScene,
                                     STGenericModel model, ColladaScene colladaScene)
        {
            Node node = new Node(null);

            node.Name = visualScene.name;

            foreach (node child in visualScene.node)
            {
                node.Children.Add(LoadHiearchy(node, child, model, colladaScene));
            }
            return(node);
        }
Ejemplo n.º 18
0
        public void FromGeneric(STGenericScene scene)
        {
            Header = HSFModelImporter.Import(scene, new HSFModelImporter.ImportSettings());
            Model  = null;

            return;

            LoadSkeleton();
            LoadMeshes();
            LoadTextures();
            LoadAnimations();

            HSFRenderer = new HSF_Renderer(this, ToGeneric());
        }
Ejemplo n.º 19
0
        public void ExportModel(IExportableModel exportableModel, string fileName, DAE.ExportSettings settings)
        {
            var model = new STGenericModel();

            model.Materials = exportableModel.ExportableMaterials;
            model.Objects   = exportableModel.ExportableMeshes;
            var textures = new List <STGenericTexture>();

            foreach (var tex in exportableModel.ExportableTextures)
            {
                textures.Add(tex);
            }

            DAE.Export(fileName, settings, model, textures, exportableModel.ExportableSkeleton);
        }
Ejemplo n.º 20
0
        private void ExportModel(string FileName)
        {
            AssimpSaver         assimp   = new AssimpSaver();
            ExportModelSettings settings = new ExportModelSettings();

            List <STGenericMaterial> Materials = new List <STGenericMaterial>();
            //  foreach (var msh in DataDictionary.Renderer.Meshes)
            //    Materials.Add(msh.GetMaterial());

            var model = new STGenericModel();

            model.Materials = Materials;
            model.Objects   = DataDictionary.Renderer.Meshes;

            assimp.SaveFromModel(model, FileName, new List <STGenericTexture>(), new STSkeleton());
        }
Ejemplo n.º 21
0
        public void ExportModel(string fileName, DAE.ExportSettings settings)
        {
            List <STGenericMaterial> Materials = new List <STGenericMaterial>();

            foreach (STGenericMaterial mat in Nodes[0].Nodes)
            {
                Materials.Add(mat);
            }

            var model = new STGenericModel();

            model.Materials = Materials;
            model.Objects   = ((GenericModelRenderer)DrawableContainer.Drawables[1]).Meshes;

            DAE.Export(fileName, settings, model, new List <STGenericTexture>(), ((STSkeleton)DrawableContainer.Drawables[0]));
        }
Ejemplo n.º 22
0
        public static Node LoadScene(visual_scene visualScene,
                                     STGenericModel model, ColladaScene colladaScene)
        {
            Node node = new Node(null);

            node.Name = visualScene.name;

            foreach (node child in visualScene.node)
            {
                node.Children.Add(LoadHiearchy(node, child, model, colladaScene));
            }

            //Transform all meshes by node transform
            //TODO //   foreach (var child in node.Children)
            //  TransformMeshInstanced(model, child);

            NodeInstanceTransform.Clear();
            return(node);
        }
Ejemplo n.º 23
0
        public void ExportModel(string fileName, DAE.ExportSettings settings)
        {
            List <STGenericMaterial> Materials = new List <STGenericMaterial>();

            foreach (STGenericObject mesh in RenderedMeshes)
            {
                if (mesh.GetMaterial() != null)
                {
                    Materials.Add(mesh.GetMaterial());
                }
            }

            var model = new STGenericModel();

            model.Materials = Materials;
            model.Objects   = RenderedMeshes;

            DAE.Export(fileName, settings, model, new List <STGenericTexture>());
        }
Ejemplo n.º 24
0
        private void ExportModel(string FileName)
        {
            AssimpSaver         assimp   = new AssimpSaver();
            ExportModelSettings settings = new ExportModelSettings();

            List <STGenericMaterial> Materials = new List <STGenericMaterial>();

            foreach (STGenericMaterial mat in Nodes[0].Nodes)
            {
                Materials.Add(mat);
            }

            var model = new STGenericModel();

            model.Materials = Materials;
            model.Objects   = ((GenericModelRenderer)DrawableContainer.Drawables[1]).Meshes;

            assimp.SaveFromModel(model, FileName, new List <STGenericTexture>(), ((STSkeleton)DrawableContainer.Drawables[0]));
        }
Ejemplo n.º 25
0
        public STGenericModel ToGeneric()
        {
            if (CachedModel != null)
            {
                return(CachedModel);
            }

            STGenericModel model = new STGenericModel("Model");

            foreach (var shape in Meshes)
            {
                foreach (var meshGroup in shape.Groups)
                {
                    var genericMesh = new STGenericMesh();
                    genericMesh.Name = $"Mesh{model.Meshes.Count}";
                    genericMesh.Vertices.AddRange(meshGroup.Vertices);

                    var group = new STPolygonGroup();
                    genericMesh.PolygonGroups.Add(group);

                    var mat = new STGenericMaterial();
                    mat.DiffuseColor = meshGroup.Color;
                    group.Material   = mat;
                    if (meshGroup.TextureIndex != -1)
                    {
                        var texMap = new STGenericTextureMap()
                        {
                            Name = $"Texture{meshGroup.TextureIndex}",
                            Type = STTextureType.Diffuse,
                        };
                        mat.TextureMaps.Add(texMap);
                    }

                    genericMesh.Optmize(group);
                    model.Meshes.Add(genericMesh);
                }
            }

            CachedModel = model;
            return(model);
        }
Ejemplo n.º 26
0
        public void ExportModel(string fileName, DAE.ExportSettings settings)
        {
            var model = new STGenericModel();

            model.Materials = Model.GenericMaterials;
            model.Objects   = Model.GenericMeshes;
            var textures = new List <STGenericTexture>();

            foreach (var bntx in PluginRuntime.bntxContainers)
            {
                foreach (var tex in bntx.Textures.Values)
                {
                    if (Model.Textures.Contains(tex.Text))
                    {
                        textures.Add(tex);
                    }
                }
            }

            DAE.Export(fileName, settings, model, textures, Model.Skeleton);
        }
Ejemplo n.º 27
0
        public STGenericModel ToGeneric()
        {
            if (CachedModel != null) return CachedModel;

            STGenericModel model = new STGenericModel(FileName);
            foreach (var shape in Meshes)
            {
                foreach (var meshGroup in shape.Groups)
                {
                    var genericMesh = new STGenericMesh();
                    genericMesh.Name = $"Mesh{model.Meshes.Count}";
                    genericMesh.Vertices.AddRange(meshGroup.Vertices);

                    var group = new STPolygonGroup();
                    genericMesh.PolygonGroups.Add(group);

                    genericMesh.Optmize(group);
                    model.Meshes.Add(genericMesh);

                    var mat = new STGenericMaterial();
                    group.Material = mat;
               //     group.IsTransparentPass = true;
                    if (TextureContainer.Textures.Count > 0)
                    {
                        var texMap = new STGenericTextureMap()
                        {
                            Name = $"Texture{meshGroup.TextureIndex}",
                            Type = STTextureType.Diffuse,
                        };
                        mat.TextureMaps.Add(texMap);
                    }
                }
            }
            foreach (var tex in TextureContainer.Textures)
                model.Textures.Add(tex);

            CachedModel = model;
            return model;
        }
Ejemplo n.º 28
0
        private static STBone LoadBoneHiearchy(node daeNode, STGenericModel model,
                                               STBone boneParent, ref Matrix4 parentTransform)
        {
            STBone bone = new STBone(model.Skeleton, daeNode.name);

            model.Skeleton.Bones.Add(bone);

            bone.Transform = DaeUtility.GetMatrix(daeNode.Items) * parentTransform;
            bone.Parent    = boneParent;
            Console.WriteLine("NODE " + bone.Name + " " + bone.Transform);

            parentTransform = Matrix4.Identity;

            if (daeNode.node1 != null)
            {
                foreach (node child in daeNode.node1)
                {
                    bone.Children.Add(LoadBoneHiearchy(child, model, bone, ref parentTransform));
                }
            }
            return(bone);
        }
Ejemplo n.º 29
0
        static void TransformMeshInstanced(STGenericModel model, Node parent)
        {
            if (NodeInstanceTransform.Any(x => x.Value == $"#{parent.ID}"))
            {
                foreach (var node in NodeInstanceTransform.Where(x => x.Value == $"#{parent.ID}"))
                {
                    var index = node.Key;
                    for (int v = 0; v < model.Meshes[index].Vertices.Count; v++)
                    {
                        model.Meshes[index].Vertices[v].Position = Vector3.TransformPosition(
                            model.Meshes[index].Vertices[v].Position, parent.Transform);

                        model.Meshes[index].Vertices[v].Normal = Vector3.TransformNormal(
                            model.Meshes[index].Vertices[v].Normal, parent.Transform);
                    }
                }
            }

            foreach (var child in parent.Children)
            {
                TransformMeshInstanced(model, child);
            }
        }
Ejemplo n.º 30
0
        private void ExportModel(string FileName)
        {
            var model = new STGenericModel();
            List <STGenericMaterial> Materials = new List <STGenericMaterial>();

            foreach (STGenericObject mesh in DataDictionary.Renderer.Meshes)
            {
                if (mesh.GetMaterial() != null)
                {
                    Materials.Add(mesh.GetMaterial());
                }
            }

            model.Materials = Materials;
            model.Objects   = DataDictionary.Renderer.Meshes;

            ExportModelSettings settings = new ExportModelSettings();

            if (settings.ShowDialog() == DialogResult.OK)
            {
                DAE.Export(FileName, settings.Settings, model, new List <STGenericTexture>());
            }
        }