Example #1
0
        private void ReadUVs(List <string> uvList, bool bTriangle)
        {
            fs.Seek(24, SeekOrigin.Current);
            TIM parametersOnly = new TIM($"{Path.GetDirectoryName(path)}\\{Path.GetFileNameWithoutExtension(path)}_{whichTextureID}.tim", 0, true);

            TIM.Texture paramTex   = parametersOnly.GetParameters;
            int         terminator = bTriangle ? 3 : 4;

            for (int i = 0; i < terminator; i++)
            {
                double u = br.ReadByte() / (float)paramTex.Width;
                double v = 1.0f - br.ReadByte() / (float)paramTex.Height;
                uvList.Add(
                    $"vt {u.ToString().Replace(',', '.')} {v.ToString().Replace(',', '.')}");
            }
            if (bTriangle)
            {
                br.ReadByte();
                br.ReadByte();
            }
            uvs = uvList.ToArray();
        }
 private void packedbinaryFileforceDrawToolStripMenuItem_Click(object sender, EventArgs e)
 {
     OpenFileDialog ofd = new OpenFileDialog { Filter = "Tim Texture (.*)|*.*" };
     if (ofd.ShowDialog() != DialogResult.OK) return;
     FileInfo fi = new FileInfo(ofd.FileName);
     if (fi.Length >= Math.Pow(1024, 3)/4)
     {
         Console.WriteLine("File is too big!");
         ofd.Dispose();
         return;
     }
     TIM tim = new TIM(fi.FullName, 1);
     Bitmap bmp = tim.DrawRaw();
     pictureBox1.Image = bmp;
     ofd.Dispose();
 }
 private void normalTIMToolStripMenuItem_Click(object sender, EventArgs e)
 {
     OpenFileDialog ofd = new OpenFileDialog {Filter= "Tim Texture (.TIM)|*.TIM"};
     TIM tim;
     if (ofd.ShowDialog() == DialogResult.OK)
     {
         tim = new TIM(ofd.FileName);
         Bitmap bmp = tim.GetBitmap;
         if (bmp != null)
             pictureBox1.Image = bmp;
         else Console.WriteLine("TIM: TIM normal class returned null bitmap??");
     }
     ofd.Dispose();
 }
Example #4
0
        private void ReadMCH()
        {
            List <uint> texoffsets = new List <uint>();

            while (true)
            {
                uint offset = br.ReadUInt32();
                if (offset == 0xFFFFFFFF)
                {
                    textureoffsets = texoffsets.ToArray();
                    break;
                }
                texoffsets.Add((offset << 8) >> 8);
            }
            modeloffset = br.ReadUInt32();
            ulong rememberposition = (ulong)fs.Position;

            string[] texPaths = new string[textureoffsets.Length];
            for (int i = 0; i < textureoffsets.Length; i++) //USEMTL for multiTextures
            {
                byte[] buf;
                if (i == textureoffsets.Length - 1)
                {
                    uint size = modeloffset - textureoffsets[i];
                    buf = new byte[size];
                    fs.Seek(textureoffsets[i], SeekOrigin.Begin);
                    buf         = br.ReadBytes(buf.Length);
                    texPaths[i] = $"{Path.GetDirectoryName(path)}\\{Path.GetFileNameWithoutExtension(path)}_{i}.tim";
                    File.WriteAllBytes(texPaths[i], buf);
                }
                else
                {
                    uint size = textureoffsets[i + 1] - textureoffsets[i];

                    buf = new byte[size];
                    fs.Seek(textureoffsets[i], SeekOrigin.Begin);
                    buf         = br.ReadBytes(buf.Length);
                    texPaths[i] = $"{Path.GetDirectoryName(path)}\\{Path.GetFileNameWithoutExtension(path)}_{i}.tim";
                    File.WriteAllBytes(texPaths[i], buf);
                }
                fs.Position = (long)rememberposition;
                TIM    tim     = new TIM(texPaths[i]);
                Bitmap texture = tim.GetBitmap;
                texture.Save($"{texPaths[i]}.png");
            }
            fs.Seek(modeloffset + 4, SeekOrigin.Begin);
            numofverts = br.ReadUInt32();
            br.ReadUInt32();
            numoffaces = br.ReadUInt32();
            fs.Seek(modeloffset + 0x1C, SeekOrigin.Begin);
            triangles = br.ReadUInt16();
            quads     = br.ReadUInt16();
            fs.Seek(modeloffset + 0x24, SeekOrigin.Begin);
            vertsoffset = br.ReadUInt32();
            fs.Seek(4, SeekOrigin.Current);
            facesoffset = br.ReadUInt32();

            ReadVertices();
            ReadFaces();
            ConstructOBJ();
        }
Example #5
0
 private void ReadUVs(List<string> uvList, bool bTriangle )
 {
     fs.Seek(24, SeekOrigin.Current);
     TIM parametersOnly = new TIM($"{Path.GetDirectoryName(path)}\\{Path.GetFileNameWithoutExtension(path)}_{whichTextureID}.tim",0,true);
     TIM.Texture paramTex = parametersOnly.GetParameters;
     int terminator = bTriangle ? 3 : 4;
     for (int i = 0; i < terminator; i++)
     {
         double u = br.ReadByte() / (float)paramTex.Width;
         double v = 1.0f - br.ReadByte() / (float)paramTex.Height;
         uvList.Add(
             $"vt {u.ToString().Replace(',', '.')} {v.ToString().Replace(',', '.')}");
     }
     if (bTriangle)
     {
         br.ReadByte();
         br.ReadByte();
     }
     uvs = uvList.ToArray();
 }
Example #6
0
        private void ReadMCH()
        {
            List<uint> texoffsets = new List<uint>();
            while (true)
            {
                uint offset = br.ReadUInt32();
                if (offset == 0xFFFFFFFF)
                {
                    textureoffsets = texoffsets.ToArray();
                    break;
                }
                texoffsets.Add((offset << 8)>>8);
            }
            modeloffset = br.ReadUInt32();
            ulong rememberposition = (ulong) fs.Position;
            string[] texPaths = new string[textureoffsets.Length];
            for (int i = 0; i < textureoffsets.Length; i++) //USEMTL for multiTextures
            {
                byte[] buf;
                if (i == textureoffsets.Length - 1)
                {
                    uint size = modeloffset - textureoffsets[i];
                    buf = new byte[size];
                    fs.Seek(textureoffsets[i], SeekOrigin.Begin);
                    buf = br.ReadBytes(buf.Length);
                    texPaths[i] = $"{Path.GetDirectoryName(path)}\\{Path.GetFileNameWithoutExtension(path)}_{i}.tim";
                    File.WriteAllBytes(texPaths[i], buf);
                }
                else
                {
                    uint size = textureoffsets[i + 1] - textureoffsets[i];

                    buf= new byte[size];
                    fs.Seek(textureoffsets[i], SeekOrigin.Begin);
                    buf = br.ReadBytes(buf.Length);
                    texPaths[i] = $"{Path.GetDirectoryName(path)}\\{Path.GetFileNameWithoutExtension(path)}_{i}.tim";
                    File.WriteAllBytes(texPaths[i], buf);
                }
                fs.Position = (long) rememberposition;
                TIM tim = new TIM(texPaths[i]);
                Bitmap texture = tim.GetBitmap;
                texture.Save($"{texPaths[i]}.png");
            }
            fs.Seek(modeloffset+4, SeekOrigin.Begin);
            numofverts = br.ReadUInt32();
            br.ReadUInt32();
            numoffaces = br.ReadUInt32();
            fs.Seek(modeloffset + 0x1C, SeekOrigin.Begin);
            triangles = br.ReadUInt16();
            quads = br.ReadUInt16();
            fs.Seek(modeloffset + 0x24, SeekOrigin.Begin);
            vertsoffset = br.ReadUInt32();
            fs.Seek(4, SeekOrigin.Current);
            facesoffset = br.ReadUInt32();

            ReadVertices();
            ReadFaces();
            ConstructOBJ();
        }