コード例 #1
0
ファイル: Visf.cs プロジェクト: Truthkey/OpenKH
 private void p1_Load(object sender, EventArgs e)
 {
     this.p3D = new Direct3D();
     this.alDeleter.Add(this.p3D);
     this.device = new Device(this.p3D, 0, DeviceType.Hardware, this.p1.Handle, CreateFlags.HardwareVertexProcessing, new PresentParameters[]
     {
         this.PP
     });
     this.alDeleter.Add(this.device);
     this.device.SetRenderState(RenderState.Lighting, false);
     this.device.SetRenderState(RenderState.ZEnable, true);
     this.device.SetRenderState(RenderState.AlphaTestEnable, true);
     this.device.SetRenderState(RenderState.AlphaRef, 2);
     this.device.SetRenderState<Compare>(RenderState.AlphaFunc, Compare.GreaterEqual);
     this.device.SetRenderState(RenderState.AlphaBlendEnable, true);
     this.device.SetRenderState<Blend>(RenderState.SourceBlend, Blend.SourceAlpha);
     this.device.SetRenderState<Blend>(RenderState.SourceBlendAlpha, Blend.SourceAlpha);
     this.device.SetRenderState<Blend>(RenderState.DestinationBlend, Blend.InverseSourceAlpha);
     this.device.SetRenderState<Blend>(RenderState.DestinationBlendAlpha, Blend.InverseSourceAlpha);
     this.device.SetRenderState<Cull>(RenderState.CullMode, Cull.Counterclockwise);
     this.device.SetRenderState(RenderState.FogColor, this.p1.BackColor.ToArgb());
     this.device.SetRenderState(RenderState.FogStart, 5f);
     this.device.SetRenderState(RenderState.FogEnd, 30000f);
     this.device.SetRenderState(RenderState.FogDensity, 0.0001f);
     this.device.SetRenderState<FogMode>(RenderState.FogVertexMode, FogMode.Exponential);
     this.p1.MouseWheel += new MouseEventHandler(this.p1_MouseWheel);
     List<CustomVertex.PositionColoredTextured> list = new List<CustomVertex.PositionColoredTextured>();
     foreach (DC current in this.aldc)
     {
         ToolStripButton toolStripButton = new ToolStripButton("Show " + current.name);
         toolStripButton.DisplayStyle = ToolStripItemDisplayStyle.Text;
         toolStripButton.CheckOnClick = true;
         toolStripButton.Tag = current.dcId;
         toolStripButton.Checked = true;
         toolStripButton.CheckedChanged += new EventHandler(this.tsiIfRender_CheckedChanged);
         this.toolStrip1.Items.Insert(this.toolStrip1.Items.IndexOf(this.tsbShowColl), toolStripButton);
     }
     this.alci.Clear();
     this.altex.Clear();
     int[] array = new int[4];
     int num = 0;
     foreach (DC current2 in this.aldc)
     {
         int count = this.altex.Count;
         Bitmap[] pics = current2.o7.pics;
         for (int i = 0; i < pics.Length; i++)
         {
             Bitmap bitmap = pics[i];
             MemoryStream memoryStream = new MemoryStream();
             bitmap.Save(memoryStream, ImageFormat.Png);
             memoryStream.Position = 0L;
             Texture item;
             this.altex.Add(item = Texture.FromStream(this.device, memoryStream));
             this.alDeleter.Add(item);
         }
         if (current2.o4Mdlx != null)
         {
             using (SortedDictionary<int, Parse4Mdlx.Model>.Enumerator enumerator3 = current2.o4Mdlx.dictModel.GetEnumerator())
             {
                 while (enumerator3.MoveNext())
                 {
                     KeyValuePair<int, Parse4Mdlx.Model> current3 = enumerator3.Current;
                     Visf.CI cI = new Visf.CI();
                     int count2 = list.Count;
                     Parse4Mdlx.Model value = current3.Value;
                     list.AddRange(value.alv);
                     List<uint> list2 = new List<uint>();
                     for (int j = 0; j < value.alv.Count; j++)
                     {
                         list2.Add((uint)(count2 + j));
                     }
                     cI.ali = list2.ToArray();
                     cI.texi = count + current3.Key;
                     cI.vifi = 0;
                     this.alci.Add(cI);
                 }
                 goto IL_75D;
             }
             goto IL_3C9;
         }
         goto IL_3C9;
         IL_75D:
         this.alalci.Add(this.alci.ToArray());
         this.alci.Clear();
         continue;
         IL_3C9:
         if (current2.o4Map != null)
         {
             for (int k = 0; k < current2.o4Map.alvifpkt.Count; k++)
             {
                 Vifpli vifpli = current2.o4Map.alvifpkt[k];
                 byte[] vifpkt = vifpli.vifpkt;
                 VU1Mem vu = new VU1Mem();
                 ParseVIF1 parseVIF = new ParseVIF1(vu);
                 parseVIF.Parse(new MemoryStream(vifpkt, false), 0);
                 foreach (byte[] current4 in parseVIF.almsmem)
                 {
                     Visf.CI cI2 = new Visf.CI();
                     MemoryStream memoryStream2 = new MemoryStream(current4, false);
                     BinaryReader binaryReader = new BinaryReader(memoryStream2);
                     binaryReader.ReadInt32();
                     binaryReader.ReadInt32();
                     binaryReader.ReadInt32();
                     binaryReader.ReadInt32();
                     int num2 = binaryReader.ReadInt32();
                     int num3 = binaryReader.ReadInt32();
                     binaryReader.ReadInt32();
                     binaryReader.ReadInt32();
                     binaryReader.ReadInt32();
                     int num4 = binaryReader.ReadInt32();
                     binaryReader.ReadInt32();
                     binaryReader.ReadInt32();
                     binaryReader.ReadInt32();
                     int num5 = binaryReader.ReadInt32();
                     List<uint> list3 = new List<uint>();
                     int count3 = list.Count;
                     for (int l = 0; l < num2; l++)
                     {
                         memoryStream2.Position = (long)(16 * (num3 + l));
                         int num6 = (int)binaryReader.ReadInt16();
                         binaryReader.ReadInt16();
                         int num7 = (int)binaryReader.ReadInt16();
                         binaryReader.ReadInt16();
                         int num8 = (int)binaryReader.ReadInt16();
                         binaryReader.ReadInt16();
                         int num9 = (int)binaryReader.ReadInt16();
                         binaryReader.ReadInt16();
                         memoryStream2.Position = (long)(16 * (num5 + num8));
                         Vector3 v;
                         v.X = -binaryReader.ReadSingle();
                         v.Y = binaryReader.ReadSingle();
                         v.Z = binaryReader.ReadSingle();
                         memoryStream2.Position = (long)(16 * (num4 + l));
                         int num10 = (int)((byte)binaryReader.ReadUInt32());
                         int num11 = (int)((byte)binaryReader.ReadUInt32());
                         int num12 = (int)((byte)binaryReader.ReadUInt32());
                         int num13 = (int)((byte)binaryReader.ReadUInt32());
                         if (num4 == 0)
                         {
                             num10 = 255;
                             num11 = 255;
                             num12 = 255;
                             num13 = 255;
                         }
                         array[num & 3] = count3 + l;
                         num++;
                         if (num9 != 0 && num9 != 16)
                         {
                             if (num9 == 32)
                             {
                                 list3.Add(Convert.ToUInt32(array[num - 1 & 3]));
                                 list3.Add(Convert.ToUInt32(array[num - 2 & 3]));
                                 list3.Add(Convert.ToUInt32(array[num - 3 & 3]));
                             }
                             else
                             {
                                 if (num9 == 48)
                                 {
                                     list3.Add(Convert.ToUInt32(array[num - 1 & 3]));
                                     list3.Add(Convert.ToUInt32(array[num - 3 & 3]));
                                     list3.Add(Convert.ToUInt32(array[num - 2 & 3]));
                                 }
                             }
                         }
                         Color color = Color.FromArgb((int)this.lm.al[num13], (int)this.lm.al[num10], (int)this.lm.al[num11], (int)this.lm.al[num12]);
                         CustomVertex.PositionColoredTextured item2 = new CustomVertex.PositionColoredTextured(v, color.ToArgb(), (float)num6 / 16f / 256f, (float)num7 / 16f / 256f);
                         list.Add(item2);
                     }
                     cI2.ali = list3.ToArray();
                     cI2.texi = count + vifpli.texi;
                     cI2.vifi = k;
                     this.alci.Add(cI2);
                 }
             }
             goto IL_75D;
         }
         goto IL_75D;
     }
     if (this.alalci.Count != 0)
     {
         this.alci.Clear();
         this.alci.AddRange(this.alalci[0]);
     }
     if (list.Count == 0)
     {
         list.Add(default(CustomVertex.PositionColoredTextured));
     }
     this.vb = new VertexBuffer(this.device, (this.cntVerts = list.Count) * CustomVertex.PositionColoredTextured.Size, Usage.Points, CustomVertex.PositionColoredTextured.Format, Pool.Managed);
     this.alDeleter.Add(this.vb);
     DataStream dataStream = this.vb.Lock(0, 0, LockFlags.None);
     try
     {
         foreach (CustomVertex.PositionColoredTextured current5 in list)
         {
             dataStream.Write<CustomVertex.PositionColoredTextured>(current5);
         }
     }
     finally
     {
         this.vb.Unlock();
     }
     this.lCntVert.Text = this.cntVerts.ToString("#,##0");
     int num14 = 0;
     this.alib.Clear();
     int num15 = 0;
     foreach (Visf.CI[] current6 in this.alalci)
     {
         Visf.CI[] array2 = current6;
         for (int i = 0; i < array2.Length; i++)
         {
             Visf.CI cI3 = array2[i];
             if (cI3.ali.Length != 0)
             {
                 IndexBuffer indexBuffer = new IndexBuffer(this.device, 4 * cI3.ali.Length, Usage.None, Pool.Managed, false);
                 num14 += cI3.ali.Length;
                 this.alDeleter.Add(indexBuffer);
                 DataStream dataStream2 = indexBuffer.Lock(0, 0, LockFlags.None);
                 try
                 {
                     uint[] ali = cI3.ali;
                     for (int m = 0; m < ali.Length; m++)
                     {
                         uint value2 = ali[m];
                         dataStream2.Write<uint>(value2);
                     }
                 }
                 finally
                 {
                     indexBuffer.Unlock();
                 }
                 Visf.RIB rIB = new Visf.RIB();
                 rIB.ib = indexBuffer;
                 rIB.cnt = cI3.ali.Length;
                 rIB.texi = cI3.texi;
                 rIB.vifi = cI3.vifi;
                 rIB.name = this.aldc[num15].name;
                 rIB.dcId = this.aldc[num15].dcId;
                 this.alib.Add(rIB);
             }
             else
             {
                 Visf.RIB rIB2 = new Visf.RIB();
                 rIB2.ib = null;
                 rIB2.cnt = 0;
                 rIB2.texi = cI3.texi;
                 rIB2.vifi = cI3.vifi;
                 rIB2.name = this.aldc[num15].name;
                 rIB2.dcId = this.aldc[num15].dcId;
                 this.alib.Add(rIB2);
             }
         }
         num15++;
     }
     this.lCntTris.Text = (num14 / 3).ToString("#,##0");
     foreach (Co2 current7 in this.coll.alCo2)
     {
         this.alpf.Add(this.putb.Add(current7));
     }
     if (this.putb.alv.Count != 0)
     {
         this.pvi = new Putvi(this.putb, this.device);
     }
     Console.Write("");
 }
コード例 #2
0
ファイル: Visf.cs プロジェクト: Truthkey/OpenKH
 private void tsbExpBlenderpy_Click(object sender, EventArgs e)
 {
     Directory.CreateDirectory("bpyexp");
     DataStream dataStream = this.vb.Lock(0, 0, LockFlags.ReadOnly);
     try
     {
         CustomVertex.PositionColoredTextured[] array = new CustomVertex.PositionColoredTextured[this.cntVerts];
         for (int i = 0; i < this.cntVerts; i++)
         {
             array[i] = dataStream.Read<CustomVertex.PositionColoredTextured>();
         }
         int num = 0;
         for (int j = 0; j < this.alalci.Count; j++)
         {
             Visf.Mkbpy mkbpy = new Visf.Mkbpy();
             mkbpy.StartTex();
             string text = "bpyexp\\" + this.aldc[j].name;
             Directory.CreateDirectory(text);
             int num2 = 0;
             DC dC = this.aldc[j];
             Bitmap[] pics = dC.o7.pics;
             for (int k = 0; k < pics.Length; k++)
             {
                 Bitmap bitmap = pics[k];
                 string str = string.Format("t{0:000}.png", num2);
                 bitmap.Save(text + "\\" + str, ImageFormat.Png);
                 mkbpy.AddTex(Path.GetFullPath(text + "\\" + str), string.Format("Tex{0:000}", num2), string.Format("Mat{0:000}", num2));
                 num2++;
             }
             mkbpy.EndTex();
             Visf.CI[] array2 = this.alalci[j];
             for (int l = 0; l < array2.Length; l++)
             {
                 Visf.CI cI = array2[l];
                 mkbpy.StartMesh();
                 for (int m = 0; m < cI.ali.Length / 3; m++)
                 {
                     mkbpy.AddV(array[(int)((UIntPtr)cI.ali[m * 3])]);
                     mkbpy.AddV(array[(int)((UIntPtr)cI.ali[m * 3 + 2])]);
                     mkbpy.AddV(array[(int)((UIntPtr)cI.ali[m * 3 + 1])]);
                     mkbpy.AddColorVtx(new Color[]
                     {
                         Color.FromArgb(array[(int)((UIntPtr)cI.ali[m * 3])].Color),
                         Color.FromArgb(array[(int)((UIntPtr)cI.ali[m * 3 + 2])].Color),
                         Color.FromArgb(array[(int)((UIntPtr)cI.ali[m * 3 + 1])].Color)
                     });
                     mkbpy.AddTuv((cI.texi & 65535) - num, array[(int)((UIntPtr)cI.ali[m * 3])].Tu, 1f - array[(int)((UIntPtr)cI.ali[m * 3])].Tv, array[(int)((UIntPtr)cI.ali[m * 3 + 2])].Tu, 1f - array[(int)((UIntPtr)cI.ali[m * 3 + 2])].Tv, array[(int)((UIntPtr)cI.ali[m * 3 + 1])].Tu, 1f - array[(int)((UIntPtr)cI.ali[m * 3 + 1])].Tv);
                 }
                 mkbpy.EndMesh(cI.vifi);
             }
             mkbpy.Finish();
             File.WriteAllText(text + "\\mesh.py", mkbpy.ToString(), Encoding.ASCII);
             num += num2;
         }
     }
     finally
     {
         this.vb.Unlock();
     }
     Process.Start("explorer.exe", " bpyexp");
 }