Exemplo n.º 1
0
        private static Dictionary <TEX0.DictTexData> GetDictTexData(Imd imd)
        {
            var dict = new Dictionary <TEX0.DictTexData>();

            foreach (var tex in imd.Body.TexImageArray.TexImages)
            {
                var imgFormat = Textures.ImageFormat.NONE;
                switch (tex.Format)
                {
                case "tex4x4":
                    imgFormat = Textures.ImageFormat.COMP4x4;
                    break;

                case "palette4":
                    imgFormat = Textures.ImageFormat.PLTT4;
                    break;

                case "palette16":
                    imgFormat = Textures.ImageFormat.PLTT16;
                    break;

                case "palette256":
                    imgFormat = Textures.ImageFormat.PLTT256;
                    break;

                case "direct":
                    imgFormat = Textures.ImageFormat.DIRECT;
                    break;

                case "a3i5":
                    imgFormat = Textures.ImageFormat.A3I5;
                    break;

                case "a5i3":
                    imgFormat = Textures.ImageFormat.A5I3;
                    break;
                }

                var data = new TEX0.DictTexData
                {
                    Data             = tex.Bitmap.Bytes,
                    Data4x4          = tex.Tex4x4PaletteIndex?.Bytes,
                    Fmt              = imgFormat,
                    S                = (ushort)tex.Width,
                    T                = (ushort)tex.Height,
                    TransparentColor = tex.Color0Mode != null && tex.Color0Mode == "transparency"
                };


                dict.Add(tex.Name.Length > 16 ? tex.Name.Substring(0, 16) : tex.Name, data);
            }

            return(dict);
        }
Exemplo n.º 2
0
        private static Dictionary <TEX0.DictTexData> GetDictTexData(List <Texture.Texture> textures)
        {
            var dict = new Dictionary <TEX0.DictTexData>();

            foreach (var tex in textures)
            {
                var imgFormat = Textures.ImageFormat.NONE;
                switch (tex.Format)
                {
                case "tex4x4":
                    imgFormat = Textures.ImageFormat.COMP4x4;
                    break;

                case "palette4":
                    imgFormat = Textures.ImageFormat.PLTT4;
                    break;

                case "palette16":
                    imgFormat = Textures.ImageFormat.PLTT16;
                    break;

                case "palette256":
                    imgFormat = Textures.ImageFormat.PLTT256;
                    break;

                case "direct":
                    imgFormat = Textures.ImageFormat.DIRECT;
                    break;

                case "a3i5":
                    imgFormat = Textures.ImageFormat.A3I5;
                    break;

                case "a5i3":
                    imgFormat = Textures.ImageFormat.A5I3;
                    break;
                }

                var data = new TEX0.DictTexData
                {
                    Data             = tex.RawTexelData,
                    Data4x4          = tex.RawPlttIdxData,
                    Fmt              = imgFormat,
                    S                = (ushort)tex.Width,
                    T                = (ushort)tex.Height,
                    TransparentColor = tex.Color0Transparent
                };


                dict.Add(tex.TextureName.Length > 16 ? tex.TextureName.Substring(0, 16) : tex.TextureName, data);
            }

            return(dict);
        }
 private void LoadTex()
 {
     try
     {
         TEX0 tt;
         if (mod.TexPlttSet != null)
         {
             tt = mod.TexPlttSet;
         }
         else if (tex != null)
         {
             tt = tex.TexPlttSet;
         }
         else
         {
             return;
         }
         for (int i = 0; i < mod.ModelSet.models.Length; i++)
         {
             for (int j = 0; j < mod.ModelSet.models[i].materials.materials.Length; j++)
             {
                 TEX0.DictTexData t = null;
                 for (int k = 0; k < mod.ModelSet.models[i].materials.dictTexToMatList.numEntry; k++)
                 {
                     if (mod.ModelSet.models[i].materials.dictTexToMatList[k].Value.Materials.Contains((byte)j))
                     {
                         int texid = k;
                         for (int l = 0; l < tt.dictTex.numEntry; l++)
                         {
                             if (tt.dictTex[l].Key == mod.ModelSet.models[i].materials.dictTexToMatList[k].Key)
                             {
                                 texid = l; break;
                             }
                         }
                         t = tt.dictTex[texid].Value;
                         break;
                     }
                 }
                 if (t == null)
                 {
                     continue;
                 }
                 mod.ModelSet.models[i].materials.materials[j].Fmt        = t.Fmt;
                 mod.ModelSet.models[i].materials.materials[j].origHeight = t.T;
                 mod.ModelSet.models[i].materials.materials[j].origWidth  = t.S;
                 TEX0.DictPlttData p = null;
                 if (t.Fmt != Textures.ImageFormat.DIRECT)
                 {
                     for (int k = 0; k < mod.ModelSet.models[i].materials.dictPlttToMatList.numEntry; k++)
                     {
                         if (mod.ModelSet.models[i].materials.dictPlttToMatList[k].Value.Materials.Contains((byte)j))
                         {
                             int palid = k;
                             for (int l = 0; l < tt.dictPltt.numEntry; l++)
                             {
                                 if (tt.dictPltt[l].Key == mod.ModelSet.models[i].materials.dictPlttToMatList[k].Key)
                                 {
                                     palid = l; break;
                                 }
                             }
                             p = tt.dictPltt[palid].Value;
                             break;
                         }
                     }
                 }
                 UploadTex(t.ToBitmap(p), mod.ModelSet.models[i].materials.materials[j], j + 1);                        //+ offset);
             }
         }
     }
     catch { }
 }