public static void ConvertToNsbmd(string infile, string outfile)
        {
            OBJ obj = OBJ.FixNitroUV(new OBJ(infile));

            if (obj == null)
            {
                return;
            }
            MLT           mlt           = new MLT(obj.MLTName);
            NSBMDSettings nsbmdSettings = new NSBMDSettings();
            int           num1          = (int)nsbmdSettings.ShowDialog();
            List <string> stringList    = new List <string>();
            float         scale1        = nsbmdSettings.Scale;
            bool          createNsbtx   = nsbmdSettings.CreateNSBTX;
            Vector3       vector3_1     = new Vector3(float.PositiveInfinity, float.PositiveInfinity, float.PositiveInfinity);
            Vector3       vector3_2     = new Vector3(float.NegativeInfinity, float.NegativeInfinity, float.NegativeInfinity);

            for (int index = 0; index < obj.Vertices.Count; ++index)
            {
                obj.Vertices[index] = Vector3.Multiply(obj.Vertices[index], scale1);
                if ((double)obj.Vertices[index].X < (double)vector3_1.X)
                {
                    vector3_1.X = obj.Vertices[index].X;
                }
                if ((double)obj.Vertices[index].X > (double)vector3_2.X)
                {
                    vector3_2.X = obj.Vertices[index].X;
                }
                if ((double)obj.Vertices[index].Y < (double)vector3_1.Y)
                {
                    vector3_1.Y = obj.Vertices[index].Y;
                }
                if ((double)obj.Vertices[index].Y > (double)vector3_2.Y)
                {
                    vector3_2.Y = obj.Vertices[index].Y;
                }
                if ((double)obj.Vertices[index].Z < (double)vector3_1.Z)
                {
                    vector3_1.Z = obj.Vertices[index].Z;
                }
                if ((double)obj.Vertices[index].Z > (double)vector3_2.Z)
                {
                    vector3_2.Z = obj.Vertices[index].Z;
                }
            }
            Vector3 vector3_3 = vector3_2 - vector3_1;
            float   num2      = Helpers.max(vector3_3.X, vector3_3.Y, vector3_3.Z);
            float   scale2    = 1f;
            int     num3      = 0;

            for (; (double)num2 > 7.999755859375; num2 /= 2f)
            {
                ++num3;
                scale2 /= 2f;
            }
            for (int index = 0; index < obj.Vertices.Count; ++index)
            {
                obj.Vertices[index] = Vector3.Multiply(obj.Vertices[index], scale2);
            }
            NSBMD nsbmd = new NSBMD(!createNsbtx);

            nsbmd.modelSet = new NSBMD.ModelSet();
            string Name1 = Path.GetFileNameWithoutExtension(infile);

            if (Name1.Length > 16)
            {
                Name1 = Name1.Remove(16);
            }
            nsbmd.modelSet.dict = new Dictionary <NSBMD.ModelSet.MDL0Data>();
            nsbmd.modelSet.dict.Add(Name1, new NSBMD.ModelSet.MDL0Data());
            nsbmd.modelSet.models                 = new NSBMD.ModelSet.Model[1];
            nsbmd.modelSet.models[0]              = new NSBMD.ModelSet.Model();
            nsbmd.modelSet.models[0].info         = new NSBMD.ModelSet.Model.ModelInfo();
            nsbmd.modelSet.models[0].info.numNode = (byte)1;
            foreach (OBJ.Face face in obj.Faces)
            {
                if (!stringList.Contains(face.MaterialName))
                {
                    stringList.Add(face.MaterialName);
                }
                ++nsbmd.modelSet.models[0].info.numTriangle;
            }
            nsbmd.modelSet.models[0].info.numMat = (byte)stringList.Count;
            nsbmd.modelSet.models[0].info.numShp = (byte)stringList.Count;
            nsbmd.modelSet.models[0].info.firstUnusedMtxStackID = (byte)1;
            nsbmd.modelSet.models[0].info.posScale       = (float)(1 << num3);
            nsbmd.modelSet.models[0].info.invPosScale    = 1f / nsbmd.modelSet.models[0].info.posScale;
            nsbmd.modelSet.models[0].info.numVertex      = (ushort)(byte)obj.Vertices.Count;
            nsbmd.modelSet.models[0].info.numPolygon     = (ushort)(byte)obj.Faces.Count;
            nsbmd.modelSet.models[0].info.boxX           = vector3_1.X * scale2;
            nsbmd.modelSet.models[0].info.boxY           = vector3_1.Y * scale2;
            nsbmd.modelSet.models[0].info.boxZ           = vector3_1.Z * scale2;
            nsbmd.modelSet.models[0].info.boxW           = vector3_3.X * scale2;
            nsbmd.modelSet.models[0].info.boxH           = vector3_3.Y * scale2;
            nsbmd.modelSet.models[0].info.boxD           = vector3_3.Z * scale2;
            nsbmd.modelSet.models[0].info.boxPosScale    = (float)(1 << num3);
            nsbmd.modelSet.models[0].info.boxInvPosScale = 1f / nsbmd.modelSet.models[0].info.boxPosScale;
            nsbmd.modelSet.models[0].nodes      = new NSBMD.ModelSet.Model.NodeSet();
            nsbmd.modelSet.models[0].nodes.dict = new Dictionary <NSBMD.ModelSet.Model.NodeSet.NodeSetData>();
            nsbmd.modelSet.models[0].nodes.dict.Add("world_root", new NSBMD.ModelSet.Model.NodeSet.NodeSetData());
            nsbmd.modelSet.models[0].nodes.data                  = new NSBMD.ModelSet.Model.NodeSet.NodeData[1];
            nsbmd.modelSet.models[0].nodes.data[0]               = new NSBMD.ModelSet.Model.NodeSet.NodeData();
            nsbmd.modelSet.models[0].nodes.data[0].flag          = (ushort)7;
            nsbmd.modelSet.models[0].materials                   = new NSBMD.ModelSet.Model.MaterialSet();
            nsbmd.modelSet.models[0].materials.dictTexToMatList  = new Dictionary <NSBMD.ModelSet.Model.MaterialSet.TexToMatData>();
            nsbmd.modelSet.models[0].materials.dictPlttToMatList = new Dictionary <NSBMD.ModelSet.Model.MaterialSet.PlttToMatData>();
            nsbmd.modelSet.models[0].materials.dict              = new Dictionary <NSBMD.ModelSet.Model.MaterialSet.MaterialSetData>();
            nsbmd.modelSet.models[0].materials.materials         = new NSBMD.ModelSet.Model.MaterialSet.Material[stringList.Count];
            int index1 = 0;
            int index2 = 0;

            foreach (string Name2 in stringList)
            {
                MLT.Material materialByName = mlt.GetMaterialByName(Name2);
                if (materialByName.DiffuseMap != null)
                {
                    nsbmd.modelSet.models[0].materials.dictTexToMatList.Add(index1.ToString() + "_t", new NSBMD.ModelSet.Model.MaterialSet.TexToMatData());
                    nsbmd.modelSet.models[0].materials.dictPlttToMatList.Add(index1.ToString() + "_p", new NSBMD.ModelSet.Model.MaterialSet.PlttToMatData());
                    nsbmd.modelSet.models[0].materials.dictTexToMatList[index2].Value.NrMat     = (byte)1;
                    nsbmd.modelSet.models[0].materials.dictTexToMatList[index2].Value.Materials = new int[1]
                    {
                        index1
                    };
                    KeyValuePair <string, NSBMD.ModelSet.Model.MaterialSet.PlttToMatData> dictPlttToMat = nsbmd.modelSet.models[0].materials.dictPlttToMatList[index2];
                    dictPlttToMat.Value.NrMat     = (byte)1;
                    dictPlttToMat                 = nsbmd.modelSet.models[0].materials.dictPlttToMatList[index2];
                    dictPlttToMat.Value.Materials = new int[1]
                    {
                        index1
                    };
                    ++index2;
                }
                nsbmd.modelSet.models[0].materials.dict.Add(index1.ToString() + "_m", new NSBMD.ModelSet.Model.MaterialSet.MaterialSetData());
                nsbmd.modelSet.models[0].materials.materials[index1] = new NSBMD.ModelSet.Model.MaterialSet.Material();
                NSBMD.ModelSet.Model.MaterialSet.Material material1 = nsbmd.modelSet.models[0].materials.materials[index1];
                Color color = Color.Black;
                int   num4  = (Graphic.encodeColor(color.ToArgb()) & (int)short.MaxValue) << 16 | 32768;
                int   argb;
                if (materialByName.DiffuseMap == null)
                {
                    argb = materialByName.DiffuseColor.ToArgb();
                }
                else
                {
                    color = Color.FromArgb(200, 200, 200);
                    argb  = color.ToArgb();
                }
                int num5 = Graphic.encodeColor(argb) & (int)short.MaxValue;
                int num6 = num4 | num5;
                material1.diffAmb = (uint)num6;
                NSBMD.ModelSet.Model.MaterialSet.Material material2 = nsbmd.modelSet.models[0].materials.materials[index1];
                color = Color.Black;
                int num7 = (Graphic.encodeColor(color.ToArgb()) & (int)short.MaxValue) << 16;
                color = Color.Black;
                int num8 = Graphic.encodeColor(color.ToArgb()) & (int)short.MaxValue;
                int num9 = num7 | num8;
                material2.specEmi = (uint)num9;
                uint num10 = (uint)((double)materialByName.Alpha * 31.0);
                nsbmd.modelSet.models[0].materials.materials[index1].polyAttr          = 0U;
                nsbmd.modelSet.models[0].materials.materials[index1].polyAttr         |= 192U;
                nsbmd.modelSet.models[0].materials.materials[index1].polyAttr         |= num10 << 16;
                nsbmd.modelSet.models[0].materials.materials[index1].polyAttrMask      = 1059059967U;
                nsbmd.modelSet.models[0].materials.materials[index1].texImageParam     = 196608U;
                nsbmd.modelSet.models[0].materials.materials[index1].texImageParamMask = uint.MaxValue;
                nsbmd.modelSet.models[0].materials.materials[index1].texPlttBase       = (ushort)0;
                nsbmd.modelSet.models[0].materials.materials[index1].flag = NSBMD.ModelSet.Model.MaterialSet.Material.NNS_G3D_MATFLAG.NNS_G3D_MATFLAG_TEXMTX_SCALEONE | NSBMD.ModelSet.Model.MaterialSet.Material.NNS_G3D_MATFLAG.NNS_G3D_MATFLAG_TEXMTX_ROTZERO | NSBMD.ModelSet.Model.MaterialSet.Material.NNS_G3D_MATFLAG.NNS_G3D_MATFLAG_TEXMTX_TRANSZERO | NSBMD.ModelSet.Model.MaterialSet.Material.NNS_G3D_MATFLAG.NNS_G3D_MATFLAG_DIFFUSE | NSBMD.ModelSet.Model.MaterialSet.Material.NNS_G3D_MATFLAG.NNS_G3D_MATFLAG_AMBIENT | NSBMD.ModelSet.Model.MaterialSet.Material.NNS_G3D_MATFLAG.NNS_G3D_MATFLAG_VTXCOLOR | NSBMD.ModelSet.Model.MaterialSet.Material.NNS_G3D_MATFLAG.NNS_G3D_MATFLAG_SPECULAR | NSBMD.ModelSet.Model.MaterialSet.Material.NNS_G3D_MATFLAG.NNS_G3D_MATFLAG_EMISSION | NSBMD.ModelSet.Model.MaterialSet.Material.NNS_G3D_MATFLAG.NNS_G3D_MATFLAG_SHININESS;
                if (materialByName.DiffuseMap != null)
                {
                    nsbmd.modelSet.models[0].materials.materials[index1].origWidth  = (ushort)materialByName.DiffuseMap.Width;
                    nsbmd.modelSet.models[0].materials.materials[index1].origHeight = (ushort)materialByName.DiffuseMap.Height;
                }
                nsbmd.modelSet.models[0].materials.materials[index1].magW = 1f;
                nsbmd.modelSet.models[0].materials.materials[index1].magH = 1f;
                ++index1;
            }
            nsbmd.modelSet.models[0].shapes       = new NSBMD.ModelSet.Model.ShapeSet();
            nsbmd.modelSet.models[0].shapes.dict  = new Dictionary <NSBMD.ModelSet.Model.ShapeSet.ShapeSetData>();
            nsbmd.modelSet.models[0].shapes.shape = new NSBMD.ModelSet.Model.ShapeSet.Shape[stringList.Count];
            int index3 = 0;

            foreach (string Name2 in stringList)
            {
                int          num4           = 1;
                int          num5           = 1;
                MLT.Material materialByName = mlt.GetMaterialByName(Name2);
                List <Color> colorList      = (List <Color>)null;
                if (materialByName.DiffuseMap != null)
                {
                    num4 = materialByName.DiffuseMap.Width;
                    num5 = -materialByName.DiffuseMap.Height;
                }
                else
                {
                    colorList = new List <Color>();
                }
                nsbmd.modelSet.models[0].shapes.dict.Add(index3.ToString() + "_py", new NSBMD.ModelSet.Model.ShapeSet.ShapeSetData());
                List <Vector3> vector3List1 = new List <Vector3>();
                List <Vector2> vector2List  = new List <Vector2>();
                List <Vector3> vector3List2 = new List <Vector3>();
                foreach (OBJ.Face face in obj.Faces)
                {
                    if (face.MaterialName == Name2)
                    {
                        vector3List1.AddRange((IEnumerable <Vector3>) new Vector3[3]
                        {
                            obj.Vertices[face.VertexIndieces[0]],
                            obj.Vertices[face.VertexIndieces[1]],
                            obj.Vertices[face.VertexIndieces[2]]
                        });
                        Vector2[] vector2Array = new Vector2[3]
                        {
                            obj.TexCoords[face.TexCoordIndieces[0]],
                            obj.TexCoords[face.TexCoordIndieces[1]],
                            obj.TexCoords[face.TexCoordIndieces[2]]
                        };
                        vector2Array[0].X *= (float)num4;
                        vector2Array[0].Y *= (float)num5;
                        vector2Array[1].X *= (float)num4;
                        vector2Array[1].Y *= (float)num5;
                        vector2Array[2].X *= (float)num4;
                        vector2Array[2].Y *= (float)num5;
                        vector2List.AddRange((IEnumerable <Vector2>)vector2Array);
                        if (face.NormalIndieces.Count != 0)
                        {
                            vector3List2.AddRange((IEnumerable <Vector3>) new Vector3[3]
                            {
                                obj.Normals[face.NormalIndieces[0]],
                                obj.Normals[face.NormalIndieces[1]],
                                obj.Normals[face.NormalIndieces[2]]
                            });
                        }
                        colorList?.AddRange((IEnumerable <Color>) new Color[3]
                        {
                            materialByName.DiffuseColor,
                            materialByName.DiffuseColor,
                            materialByName.DiffuseColor
                        });
                    }
                }
                nsbmd.modelSet.models[0].shapes.shape[index3]        = new NSBMD.ModelSet.Model.ShapeSet.Shape();
                nsbmd.modelSet.models[0].shapes.shape[index3].DL     = GlNitro.GenerateDl(vector3List1.ToArray(), vector2List.ToArray(), vector3List2.ToArray(), colorList?.ToArray());
                nsbmd.modelSet.models[0].shapes.shape[index3].sizeDL = (uint)nsbmd.modelSet.models[0].shapes.shape[index3].DL.Length;
                nsbmd.modelSet.models[0].shapes.shape[index3].flag   = NSBMD.ModelSet.Model.ShapeSet.Shape.NNS_G3D_SHPFLAG.NNS_G3D_SHPFLAG_USE_NORMAL | NSBMD.ModelSet.Model.ShapeSet.Shape.NNS_G3D_SHPFLAG.NNS_G3D_SHPFLAG_USE_COLOR | NSBMD.ModelSet.Model.ShapeSet.Shape.NNS_G3D_SHPFLAG.NNS_G3D_SHPFLAG_USE_TEXCOORD;
                ++index3;
            }
            Obj2Nsbmd.SBCWriter sbcWriter = new Obj2Nsbmd.SBCWriter();
            sbcWriter.NODEDESC((byte)0, (byte)0, false, false, 0, -1);
            sbcWriter.NODE((byte)0, true);
            sbcWriter.POSSCALE(true);
            for (int index4 = 0; index4 < stringList.Count; ++index4)
            {
                sbcWriter.MAT((byte)index4);
                sbcWriter.SHP((byte)index4);
            }
            sbcWriter.POSSCALE(false);
            sbcWriter.RET();
            sbcWriter.NOP();
            nsbmd.modelSet.models[0].sbc = sbcWriter.GetData();
            NSBTX.TexplttSet texplttSet = new NSBTX.TexplttSet();
            texplttSet.TexInfo    = new NSBTX.TexplttSet.texInfo();
            texplttSet.Tex4x4Info = new NSBTX.TexplttSet.tex4x4Info();
            texplttSet.PlttInfo   = new NSBTX.TexplttSet.plttInfo();
            texplttSet.dictTex    = new Dictionary <NSBTX.TexplttSet.DictTexData>();
            texplttSet.dictPltt   = new Dictionary <NSBTX.TexplttSet.DictPlttData>();
            int num11  = 0;
            int index5 = 0;

            foreach (string Name2 in stringList)
            {
                MLT.Material materialByName = mlt.GetMaterialByName(Name2);
                if (materialByName.DiffuseMap != null)
                {
                    BitmapData   bitmapdata = materialByName.DiffuseMap.LockBits(new Rectangle(0, 0, materialByName.DiffuseMap.Width, materialByName.DiffuseMap.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
                    List <Color> source     = new List <Color>();
                    bool         flag       = false;
                    for (int index4 = 0; index4 < materialByName.DiffuseMap.Width * materialByName.DiffuseMap.Height; ++index4)
                    {
                        source.Add(Color.FromArgb(Marshal.ReadInt32(bitmapdata.Scan0, index4 * 4)));
                        Color color = source.Last <Color>();
                        int   num4;
                        if (color.A != (byte)0)
                        {
                            color = source.Last <Color>();
                            if (color.A != byte.MaxValue)
                            {
                                num4 = flag ? 1 : 0;
                                goto label_74;
                            }
                        }
                        num4 = 1;
label_74:
                        if (num4 == 0)
                        {
                            flag = true;
                        }
                    }
                    materialByName.DiffuseMap.UnlockBits(bitmapdata);
                    List <Color> list = source.Distinct <Color>().ToList <Color>();
                    texplttSet.dictTex.Add(num11.ToString() + "_t", new NSBTX.TexplttSet.DictTexData());
                    texplttSet.dictPltt.Add(num11.ToString() + "_p", new NSBTX.TexplttSet.DictPlttData());
                    KeyValuePair <string, NSBTX.TexplttSet.DictTexData> keyValuePair = texplttSet.dictTex[index5];
                    keyValuePair.Value.S = (ushort)materialByName.DiffuseMap.Width;
                    keyValuePair         = texplttSet.dictTex[index5];
                    keyValuePair.Value.T = (ushort)materialByName.DiffuseMap.Height;
                    if (flag && list.Count <= 8)
                    {
                        keyValuePair           = texplttSet.dictTex[index5];
                        keyValuePair.Value.Fmt = Graphic.GXTexFmt.GX_TEXFMT_A5I3;
                    }
                    else if (flag)
                    {
                        keyValuePair           = texplttSet.dictTex[index5];
                        keyValuePair.Value.Fmt = Graphic.GXTexFmt.GX_TEXFMT_A3I5;
                    }
                    else if (list.Count <= 16)
                    {
                        keyValuePair           = texplttSet.dictTex[index5];
                        keyValuePair.Value.Fmt = Graphic.GXTexFmt.GX_TEXFMT_PLTT16;
                    }
                    else
                    {
                        keyValuePair           = texplttSet.dictTex[index5];
                        keyValuePair.Value.Fmt = Graphic.GXTexFmt.GX_TEXFMT_COMP4x4;
                    }
                    System.Drawing.Bitmap diffuseMap = materialByName.DiffuseMap;
                    keyValuePair = texplttSet.dictTex[index5];
                    ref byte[] local1 = ref keyValuePair.Value.Data;
                    ref byte[] local2 = ref texplttSet.dictPltt[index5].Value.Data;
                    keyValuePair = texplttSet.dictTex[index5];
                    ref byte[] local3 = ref keyValuePair.Value.Data4x4;
Exemple #2
0
        public static void GenerateNSBMD(string obj_path, float scale, bool has_texture, out byte[] nsbmd, out byte[] nsbtx)
        {
            var oBJ = FixNitroUV(new OBJ(obj_path));

            if (oBJ == null)
            {
                throw new Exception();
            }
            MLT           mLT   = new MLT(oBJ.MLTName);
            List <string> list  = new List <string>();
            Vector3       right = new Vector3(float.PositiveInfinity, float.PositiveInfinity, float.PositiveInfinity);
            Vector3       left  = new Vector3(float.NegativeInfinity, float.NegativeInfinity, float.NegativeInfinity);
            int           i;

            for (i = 0; i < oBJ.Vertices.Count; i++)
            {
                oBJ.Vertices[i] = Vector3.Multiply(oBJ.Vertices[i], scale);
                if (oBJ.Vertices[i].X < right.X)
                {
                    right.X = oBJ.Vertices[i].X;
                }
                if (oBJ.Vertices[i].X > left.X)
                {
                    left.X = oBJ.Vertices[i].X;
                }
                if (oBJ.Vertices[i].Y < right.Y)
                {
                    right.Y = oBJ.Vertices[i].Y;
                }
                if (oBJ.Vertices[i].Y > left.Y)
                {
                    left.Y = oBJ.Vertices[i].Y;
                }
                if (oBJ.Vertices[i].Z < right.Z)
                {
                    right.Z = oBJ.Vertices[i].Z;
                }
                if (oBJ.Vertices[i].Z > left.Z)
                {
                    left.Z = oBJ.Vertices[i].Z;
                }
            }
            Vector3 vector = left - right;
            float   num    = HelpersMax(vector.X, vector.Y, vector.Z);
            float   num2   = 1f;
            int     num3   = 0;

            while (num > 7.999756f)
            {
                num3++;
                num2 /= 2f;
                num  /= 2f;
            }
            for (i = 0; i < oBJ.Vertices.Count; i++)
            {
                oBJ.Vertices[i] = Vector3.Multiply(oBJ.Vertices[i], num2);
            }
            NSBMD nSBMD = new NSBMD(!has_texture);

            nSBMD.modelSet = new NSBMD.ModelSet();
            string text = Path.GetFileNameWithoutExtension(obj_path);

            if (text.Length > 16)
            {
                text = text.Remove(16);
            }
            nSBMD.modelSet.dict = new Dictionary <NSBMD.ModelSet.MDL0Data>();
            nSBMD.modelSet.dict.Add(text, new NSBMD.ModelSet.MDL0Data());
            nSBMD.modelSet.models                 = new NSBMD.ModelSet.Model[1];
            nSBMD.modelSet.models[0]              = new NSBMD.ModelSet.Model();
            nSBMD.modelSet.models[0].info         = new NSBMD.ModelSet.Model.ModelInfo();
            nSBMD.modelSet.models[0].info.numNode = 1;
            foreach (OBJ.Face face in oBJ.Faces)
            {
                if (!list.Contains(face.MaterialName))
                {
                    list.Add(face.MaterialName);
                }
                nSBMD.modelSet.models[0].info.numTriangle++;
            }
            nSBMD.modelSet.models[0].info.numMat = (byte)list.Count;
            nSBMD.modelSet.models[0].info.numShp = (byte)list.Count;
            nSBMD.modelSet.models[0].info.firstUnusedMtxStackID = 1;
            nSBMD.modelSet.models[0].info.posScale       = 1 << num3;
            nSBMD.modelSet.models[0].info.invPosScale    = 1f / nSBMD.modelSet.models[0].info.posScale;
            nSBMD.modelSet.models[0].info.numVertex      = (byte)oBJ.Vertices.Count;
            nSBMD.modelSet.models[0].info.numPolygon     = (byte)oBJ.Faces.Count;
            nSBMD.modelSet.models[0].info.boxX           = right.X * num2;
            nSBMD.modelSet.models[0].info.boxY           = right.Y * num2;
            nSBMD.modelSet.models[0].info.boxZ           = right.Z * num2;
            nSBMD.modelSet.models[0].info.boxW           = vector.X * num2;
            nSBMD.modelSet.models[0].info.boxH           = vector.Y * num2;
            nSBMD.modelSet.models[0].info.boxD           = vector.Z * num2;
            nSBMD.modelSet.models[0].info.boxPosScale    = 1 << num3;
            nSBMD.modelSet.models[0].info.boxInvPosScale = 1f / nSBMD.modelSet.models[0].info.boxPosScale;
            nSBMD.modelSet.models[0].nodes      = new NSBMD.ModelSet.Model.NodeSet();
            nSBMD.modelSet.models[0].nodes.dict = new Dictionary <NSBMD.ModelSet.Model.NodeSet.NodeSetData>();
            nSBMD.modelSet.models[0].nodes.dict.Add("world_root", new NSBMD.ModelSet.Model.NodeSet.NodeSetData());
            nSBMD.modelSet.models[0].nodes.data                  = new NSBMD.ModelSet.Model.NodeSet.NodeData[1];
            nSBMD.modelSet.models[0].nodes.data[0]               = new NSBMD.ModelSet.Model.NodeSet.NodeData();
            nSBMD.modelSet.models[0].nodes.data[0].flag          = 7;
            nSBMD.modelSet.models[0].materials                   = new NSBMD.ModelSet.Model.MaterialSet();
            nSBMD.modelSet.models[0].materials.dictTexToMatList  = new Dictionary <NSBMD.ModelSet.Model.MaterialSet.TexToMatData>();
            nSBMD.modelSet.models[0].materials.dictPlttToMatList = new Dictionary <NSBMD.ModelSet.Model.MaterialSet.PlttToMatData>();
            nSBMD.modelSet.models[0].materials.dict              = new Dictionary <NSBMD.ModelSet.Model.MaterialSet.MaterialSetData>();
            nSBMD.modelSet.models[0].materials.materials         = new NSBMD.ModelSet.Model.MaterialSet.Material[list.Count];
            i = 0;
            int num4 = 0;

            foreach (string item in list)
            {
                MLT.Material materialByName = mLT.GetMaterialByName(item);
                if (materialByName.DiffuseMap != null)
                {
                    nSBMD.modelSet.models[0].materials.dictTexToMatList.Add(i.ToString() + "_t", new NSBMD.ModelSet.Model.MaterialSet.TexToMatData());
                    nSBMD.modelSet.models[0].materials.dictPlttToMatList.Add(i.ToString() + "_p", new NSBMD.ModelSet.Model.MaterialSet.PlttToMatData());
                    nSBMD.modelSet.models[0].materials.dictTexToMatList[num4].Value.NrMat     = 1;
                    nSBMD.modelSet.models[0].materials.dictTexToMatList[num4].Value.Materials = new int[1]
                    {
                        i
                    };
                    nSBMD.modelSet.models[0].materials.dictPlttToMatList[num4].Value.NrMat     = 1;
                    nSBMD.modelSet.models[0].materials.dictPlttToMatList[num4].Value.Materials = new int[1]
                    {
                        i
                    };
                    num4++;
                }
                nSBMD.modelSet.models[0].materials.dict.Add(i.ToString() + "_m", new NSBMD.ModelSet.Model.MaterialSet.MaterialSetData());
                nSBMD.modelSet.models[0].materials.materials[i]         = new NSBMD.ModelSet.Model.MaterialSet.Material();
                nSBMD.modelSet.models[0].materials.materials[i].diffAmb = (uint)(((Graphic.encodeColor(Color.Black.ToArgb()) & 0x7FFF) << 16) | 0x8000 | (Graphic.encodeColor((materialByName.DiffuseMap != null) ? Color.FromArgb(200, 200, 200).ToArgb() : materialByName.DiffuseColor.ToArgb()) & 0x7FFF));
                nSBMD.modelSet.models[0].materials.materials[i].specEmi = (uint)(((Graphic.encodeColor(Color.Black.ToArgb()) & 0x7FFF) << 16) | (Graphic.encodeColor(Color.Black.ToArgb()) & 0x7FFF));
                uint num5 = (uint)(materialByName.Alpha * 31f);
                nSBMD.modelSet.models[0].materials.materials[i].polyAttr          = 0u;
                nSBMD.modelSet.models[0].materials.materials[i].polyAttr         |= 192u;
                nSBMD.modelSet.models[0].materials.materials[i].polyAttr         |= num5 << 16;
                nSBMD.modelSet.models[0].materials.materials[i].polyAttrMask      = 1059059967u;
                nSBMD.modelSet.models[0].materials.materials[i].texImageParam     = 196608u;
                nSBMD.modelSet.models[0].materials.materials[i].texImageParamMask = uint.MaxValue;
                nSBMD.modelSet.models[0].materials.materials[i].texPlttBase       = 0;
                nSBMD.modelSet.models[0].materials.materials[i].flag = (NSBMD.ModelSet.Model.MaterialSet.Material.NNS_G3D_MATFLAG.NNS_G3D_MATFLAG_TEXMTX_SCALEONE | NSBMD.ModelSet.Model.MaterialSet.Material.NNS_G3D_MATFLAG.NNS_G3D_MATFLAG_TEXMTX_ROTZERO | NSBMD.ModelSet.Model.MaterialSet.Material.NNS_G3D_MATFLAG.NNS_G3D_MATFLAG_TEXMTX_TRANSZERO | NSBMD.ModelSet.Model.MaterialSet.Material.NNS_G3D_MATFLAG.NNS_G3D_MATFLAG_DIFFUSE | NSBMD.ModelSet.Model.MaterialSet.Material.NNS_G3D_MATFLAG.NNS_G3D_MATFLAG_AMBIENT | NSBMD.ModelSet.Model.MaterialSet.Material.NNS_G3D_MATFLAG.NNS_G3D_MATFLAG_VTXCOLOR | NSBMD.ModelSet.Model.MaterialSet.Material.NNS_G3D_MATFLAG.NNS_G3D_MATFLAG_SPECULAR | NSBMD.ModelSet.Model.MaterialSet.Material.NNS_G3D_MATFLAG.NNS_G3D_MATFLAG_EMISSION | NSBMD.ModelSet.Model.MaterialSet.Material.NNS_G3D_MATFLAG.NNS_G3D_MATFLAG_SHININESS);
                if (materialByName.DiffuseMap != null)
                {
                    nSBMD.modelSet.models[0].materials.materials[i].origWidth  = (ushort)materialByName.DiffuseMap.Width;
                    nSBMD.modelSet.models[0].materials.materials[i].origHeight = (ushort)materialByName.DiffuseMap.Height;
                }
                nSBMD.modelSet.models[0].materials.materials[i].magW = 1f;
                nSBMD.modelSet.models[0].materials.materials[i].magH = 1f;
                i++;
            }
            nSBMD.modelSet.models[0].shapes       = new NSBMD.ModelSet.Model.ShapeSet();
            nSBMD.modelSet.models[0].shapes.dict  = new Dictionary <NSBMD.ModelSet.Model.ShapeSet.ShapeSetData>();
            nSBMD.modelSet.models[0].shapes.shape = new NSBMD.ModelSet.Model.ShapeSet.Shape[list.Count];
            i = 0;
            foreach (string item2 in list)
            {
                int          num6           = 1;
                int          num7           = 1;
                MLT.Material materialByName = mLT.GetMaterialByName(item2);
                List <Color> list2          = null;
                if (materialByName.DiffuseMap != null)
                {
                    num6 = materialByName.DiffuseMap.Width;
                    num7 = -materialByName.DiffuseMap.Height;
                }
                else
                {
                    list2 = new List <Color>();
                }
                nSBMD.modelSet.models[0].shapes.dict.Add(i.ToString() + "_py", new NSBMD.ModelSet.Model.ShapeSet.ShapeSetData());
                List <Vector3> list3 = new List <Vector3>();
                List <Vector2> list4 = new List <Vector2>();
                List <Vector3> list5 = new List <Vector3>();
                foreach (OBJ.Face face2 in oBJ.Faces)
                {
                    if (face2.MaterialName == item2)
                    {
                        list3.AddRange(new Vector3[3]
                        {
                            oBJ.Vertices[face2.VertexIndieces[0]],
                            oBJ.Vertices[face2.VertexIndieces[1]],
                            oBJ.Vertices[face2.VertexIndieces[2]]
                        });
                        Vector2[] array = new Vector2[3]
                        {
                            oBJ.TexCoords[face2.TexCoordIndieces[0]],
                            oBJ.TexCoords[face2.TexCoordIndieces[1]],
                            oBJ.TexCoords[face2.TexCoordIndieces[2]]
                        };
                        array[0].X *= num6;
                        array[0].Y *= num7;
                        array[1].X *= num6;
                        array[1].Y *= num7;
                        array[2].X *= num6;
                        array[2].Y *= num7;
                        list4.AddRange(array);
                        if (face2.NormalIndieces.Count != 0)
                        {
                            list5.AddRange(new Vector3[3]
                            {
                                oBJ.Normals[face2.NormalIndieces[0]],
                                oBJ.Normals[face2.NormalIndieces[1]],
                                oBJ.Normals[face2.NormalIndieces[2]]
                            });
                        }
                        list2?.AddRange(new Color[3]
                        {
                            materialByName.DiffuseColor,
                            materialByName.DiffuseColor,
                            materialByName.DiffuseColor
                        });
                    }
                }
                nSBMD.modelSet.models[0].shapes.shape[i]        = new NSBMD.ModelSet.Model.ShapeSet.Shape();
                nSBMD.modelSet.models[0].shapes.shape[i].DL     = GlNitro.GenerateDl(list3.ToArray(), list4.ToArray(), list5.ToArray(), list2?.ToArray());
                nSBMD.modelSet.models[0].shapes.shape[i].sizeDL = (uint)nSBMD.modelSet.models[0].shapes.shape[i].DL.Length;
                nSBMD.modelSet.models[0].shapes.shape[i].flag   = (NSBMD.ModelSet.Model.ShapeSet.Shape.NNS_G3D_SHPFLAG.NNS_G3D_SHPFLAG_USE_NORMAL | NSBMD.ModelSet.Model.ShapeSet.Shape.NNS_G3D_SHPFLAG.NNS_G3D_SHPFLAG_USE_COLOR | NSBMD.ModelSet.Model.ShapeSet.Shape.NNS_G3D_SHPFLAG.NNS_G3D_SHPFLAG_USE_TEXCOORD);
                i++;
            }
            var sBCWriter = new Obj2Nsbmd.SBCWriter();

            sBCWriter.NODEDESC(0, 0, S: false, P: false, 0);
            sBCWriter.NODE(0, V: true);
            sBCWriter.POSSCALE(OPT: true);
            for (i = 0; i < list.Count; i++)
            {
                sBCWriter.MAT((byte)i);
                sBCWriter.SHP((byte)i);
            }
            sBCWriter.POSSCALE(OPT: false);
            sBCWriter.RET();
            sBCWriter.NOP();
            nSBMD.modelSet.models[0].sbc = sBCWriter.GetData();
            NSBTX.TexplttSet texplttSet = new NSBTX.TexplttSet();
            texplttSet.TexInfo    = new NSBTX.TexplttSet.texInfo();
            texplttSet.Tex4x4Info = new NSBTX.TexplttSet.tex4x4Info();
            texplttSet.PlttInfo   = new NSBTX.TexplttSet.plttInfo();
            texplttSet.dictTex    = new Dictionary <NSBTX.TexplttSet.DictTexData>();
            texplttSet.dictPltt   = new Dictionary <NSBTX.TexplttSet.DictPlttData>();
            i    = 0;
            num4 = 0;
            foreach (string item3 in list)
            {
                MLT.Material materialByName = mLT.GetMaterialByName(item3);
                if (materialByName.DiffuseMap != null)
                {
                    BitmapData   bitmapData = materialByName.DiffuseMap.LockBits(new Rectangle(0, 0, materialByName.DiffuseMap.Width, materialByName.DiffuseMap.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
                    List <Color> list6      = new List <Color>();
                    bool         flag       = false;
                    for (int j = 0; j < materialByName.DiffuseMap.Width * materialByName.DiffuseMap.Height; j++)
                    {
                        list6.Add(Color.FromArgb(Marshal.ReadInt32(bitmapData.Scan0, j * 4)));
                        if (list6.Last().A != 0 && list6.Last().A != byte.MaxValue && !flag)
                        {
                            flag = true;
                        }
                    }
                    materialByName.DiffuseMap.UnlockBits(bitmapData);
                    list6 = list6.Distinct().ToList();
                    texplttSet.dictTex.Add(i.ToString() + "_t", new NSBTX.TexplttSet.DictTexData());
                    texplttSet.dictPltt.Add(i.ToString() + "_p", new NSBTX.TexplttSet.DictPlttData());
                    texplttSet.dictTex[num4].Value.S = (ushort)materialByName.DiffuseMap.Width;
                    texplttSet.dictTex[num4].Value.T = (ushort)materialByName.DiffuseMap.Height;
                    if (flag && list6.Count <= 8)
                    {
                        texplttSet.dictTex[num4].Value.Fmt = Graphic.GXTexFmt.GX_TEXFMT_A5I3;
                    }
                    else if (flag)
                    {
                        texplttSet.dictTex[num4].Value.Fmt = Graphic.GXTexFmt.GX_TEXFMT_A3I5;
                    }
                    else if (list6.Count <= 16)
                    {
                        texplttSet.dictTex[num4].Value.Fmt = Graphic.GXTexFmt.GX_TEXFMT_PLTT16;
                    }
                    else
                    {
                        texplttSet.dictTex[num4].Value.Fmt = Graphic.GXTexFmt.GX_TEXFMT_COMP4x4;
                    }
                    Graphic.ConvertBitmap(materialByName.DiffuseMap, out texplttSet.dictTex[num4].Value.Data, out texplttSet.dictPltt[num4].Value.Data, out texplttSet.dictTex[num4].Value.Data4x4, texplttSet.dictTex[num4].Value.Fmt, Graphic.NNSG2dCharacterFmt.NNS_G2D_CHARACTER_FMT_BMP, out texplttSet.dictTex[num4].Value.TransparentColor);
                    num4++;
                }
                i++;
            }
            nsbtx = null;
            if (!has_texture)
            {
                nSBMD.TexPlttSet = texplttSet;
            }
            else
            {
                var nSBTX = new NSBTX
                {
                    TexPlttSet = texplttSet
                };
                nsbtx = nSBTX.Write();
            }
            nsbmd = nSBMD.Write();
        }