Example #1
0
        /// <summary>
        ///
        /// </summary>
        public static void ExportTextures(HSD_JOBJ jobj)
        {
            var folder = Tools.FileIO.OpenFolder();

            if (!string.IsNullOrEmpty(folder))
            {
                HashSet <int> textures = new HashSet <int>();

                // get all tobjs
                foreach (var j in jobj.BreathFirstList)
                {
                    if (j.Dobj != null)
                    {
                        foreach (var dobj in j.Dobj.List)
                        {
                            if (dobj.Mobj != null && dobj.Mobj.Textures != null)
                            {
                                foreach (var tobj in dobj.Mobj.Textures.List)
                                {
                                    // generate hashes and export textures and formatting

                                    var hash = ComputeHash(tobj.GetDecodedImageData());

                                    if (!textures.Contains(hash))
                                    {
                                        using (var bmp = TOBJConverter.ToBitmap(tobj))
                                            bmp.Save(System.IO.Path.Combine(folder, TOBJConverter.FormatName(hash.ToString("X8"), tobj) + ".png"));

                                        textures.Add(hash);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Example #2
0
        /// <summary>
        ///
        /// </summary>
        private void WriteDOBJNodes(ModelExportSettings settings)
        {
            var jIndex = 0;

            foreach (var j in Jobjs)
            {
                var dIndex = 0;
                if (j.Dobj != null)
                {
                    foreach (var dobj in j.Dobj.List)
                    {
                        Node dobjNode = new Node();
                        dobjNode.Name = $"JOBJ_{jIndex}_DOBJ_{dIndex}";

                        if (dobj.Pobj != null)
                        {
                            var pindex = 0;
                            foreach (var pobj in dobj.Pobj.List)
                            {
                                dobjNode.MeshIndices.Add(Scene.Meshes.Count);
                                var mesh = ProcessPOBJ(pobj, j, pobj.SingleBoundJOBJ);
                                mesh.Name          = dobjNode.Name + "_POBJ_" + pindex++;
                                mesh.MaterialIndex = Scene.MaterialCount;
                                Scene.Meshes.Add(mesh);
                            }
                        }

                        // process and export textures

                        Material m = new Material();
                        m.Name      = $"JOBJ_{jIndex}_DOBJ_{dIndex}_MOBJ_{dIndex}";
                        m.Shininess = dobj.Mobj.Material.Shininess;
                        m.Opacity   = dobj.Mobj.Material.Alpha;

                        if (dobj.Mobj.Textures != null)
                        {
                            foreach (var t in dobj.Mobj.Textures.List)
                            {
                                if (t.ImageData != null && t.ImageData.ImageData != null && !imageToName.ContainsKey(t.ImageData.ImageData))
                                {
                                    var name = $"TOBJ_{imageToName.Count}";
                                    using (Bitmap img = TOBJConverter.ToBitmap(t))
                                        img.Save(settings.Directory + name + ".png");
                                    imageToName.Add(t.ImageData.ImageData, name);
                                }
                            }

                            var dif = new TextureSlot();
                            dif.TextureType  = TextureType.Diffuse;
                            dif.UVIndex      = 0;
                            dif.FilePath     = imageToName[dobj.Mobj.Textures.ImageData.ImageData];
                            m.TextureDiffuse = dif;
                        }
                        Scene.Materials.Add(m);

                        RootNode.Children.Add(dobjNode);
                        dIndex++;
                    }
                }
                jIndex++;
            }
        }