Beispiel #1
0
        public MeshRenderObject(DAILibWV.Frostbite.Mesh m)
        {
            mesh = m;
            foreach (DAILibWV.Frostbite.Mesh.MeshLOD lod in mesh.header.LODs)
            {
                if (lod.Sections == null || lod.Sections.Count == 0 || lod.Sections[0].VertexBuffer == null)
                {
                    continue;
                }
                RawTriangles = new List <CustomVertex.PositionTextured[]>();
                foreach (DAILibWV.Frostbite.Mesh.MeshSection sec in lod.Sections)
                {
                    List <CustomVertex.PositionTextured> list = new List <CustomVertex.PositionTextured>();
                    for (int i = 0; i < sec.TriangleCount; i++)
                    {
                        list.Add(DAI2DX(sec.VertexBuffer[sec.IndexBuffer[i].i0]));
                        list.Add(DAI2DX(sec.VertexBuffer[sec.IndexBuffer[i].i1]));
                        list.Add(DAI2DX(sec.VertexBuffer[sec.IndexBuffer[i].i2]));
                    }
                    RawTriangles.Add(list.ToArray());
                }
                break;
            }
            float inf = 10000000000f;

            min = new Vector3(inf, inf, inf);
            max = new Vector3(-inf, -inf, -inf);
            foreach (CustomVertex.PositionTextured[] list in RawTriangles)
            {
                foreach (CustomVertex.PositionTextured v in list)
                {
                    if (v.X > max.X)
                    {
                        max.X = v.X;
                    }
                    if (v.Y > max.Y)
                    {
                        max.Y = v.Y;
                    }
                    if (v.Z > max.Z)
                    {
                        max.Z = v.Z;
                    }
                    if (v.X < min.X)
                    {
                        min.X = v.X;
                    }
                    if (v.Y < min.Y)
                    {
                        min.Y = v.Y;
                    }
                    if (v.Z < min.Z)
                    {
                        min.Z = v.Z;
                    }
                }
            }
            center = (max + min) * 0.5f;
        }
 public MeshRenderObject(DAILibWV.Frostbite.Mesh m)
 {
     mesh = m;
     foreach (DAILibWV.Frostbite.Mesh.MeshLOD lod in mesh.header.LODs)
     {
         if (lod.Sections == null || lod.Sections.Count == 0 || lod.Sections[0].VertexBuffer == null)
             continue;
         RawTriangles = new List<CustomVertex.PositionTextured[]>();
         foreach (DAILibWV.Frostbite.Mesh.MeshSection sec in lod.Sections)
         {
             List<CustomVertex.PositionTextured> list = new List<CustomVertex.PositionTextured>();
             for (int i = 0; i < sec.TriangleCount; i++)
             {
                 list.Add(DAI2DX(sec.VertexBuffer[sec.IndexBuffer[i].i0]));
                 list.Add(DAI2DX(sec.VertexBuffer[sec.IndexBuffer[i].i1]));
                 list.Add(DAI2DX(sec.VertexBuffer[sec.IndexBuffer[i].i2]));
             }
             RawTriangles.Add(list.ToArray());
         }
         break;
     }
     float inf = 10000000000f;
     min = new Vector3(inf, inf, inf);
     max = new Vector3(-inf, -inf, -inf);
     foreach (CustomVertex.PositionTextured[] list in RawTriangles)
     {
         foreach (CustomVertex.PositionTextured v in list)
         {
             if (v.X > max.X) max.X = v.X;
             if (v.Y > max.Y) max.Y = v.Y;
             if (v.Z > max.Z) max.Z = v.Z;
             if (v.X < min.X) min.X = v.X;
             if (v.Y < min.Y) min.Y = v.Y;
             if (v.Z < min.Z) min.Z = v.Z;
         }
     }
     center = (max + min) * 0.5f;
 }
Beispiel #3
0
 private void RefreshPreview()
 {
     try
     {
         int n = listBox2.SelectedIndex;
         if (n == -1)
             return;
         status.Text = "Getting header infos from db...";
         Application.DoEvents();
         DBAccess.RESInformation ti = ttprevlist[n];
         DBAccess.BundleInformation buni = DBAccess.GetBundleInformationById(ti.bundlepath)[0];
         DBAccess.TOCInformation toci = DBAccess.GetTocInformationByIndex(buni.tocIndex);
         BinaryBundle b = new BinaryBundle();
         byte[] resdata = new byte[0];
         if (toci.incas)
         {
             status.Text = "Getting header data from sha1...";
             Application.DoEvents();
             resdata = SHA1Access.GetDataBySha1(Helpers.HexStringToByteArray(ti.sha1));
         }
         else
         {
             status.Text = "Getting header data from binary bundle...";
             Application.DoEvents();
             TOCFile toc = new TOCFile(toci.path);
             byte[] bundledata = toc.ExportBundleDataByPath(buni.bundlepath);
             b = new BinaryBundle(new MemoryStream(bundledata));
             foreach (BinaryBundle.ResEntry res in b.ResList)
                 if (res._name == ti.resname)
                 {
                     resdata = res._data;
                     break;
                 }
         }
         hb2.ByteProvider = new DynamicByteProvider(resdata);
         Mesh mesh = new Mesh(new MemoryStream(resdata));
         foreach (Mesh.MeshLOD lod in mesh.header.LODs)
         {
             byte[] id = lod.ChunkID;
             byte[] data = new byte[0];
             if (toci.incas)
             {
                 DBAccess.ChunkInformation ci = DBAccess.GetChunkInformationById(id);
                 if (ci.sha1 == null)
                     continue;
                 data = SHA1Access.GetDataBySha1(ci.sha1);
             }
             else
             {
                 byte t = id[0];
                 id[0] = id[3];
                 id[3] = t;
                 t = id[1];
                 id[1] = id[2];
                 id[2] = t;
                 t = id[6];
                 id[6] = id[7];
                 id[7] = t;
                 t = id[4];
                 id[4] = id[5];
                 id[5] = t;
                 foreach (BinaryBundle.ChunkEntry c in b.ChunkList)
                     if (Helpers.ByteArrayCompare(id, c.id))
                         data = c._data;
                 if (data.Length == 0)
                 {
                     DBAccess.ChunkInformation ci = DBAccess.GetChunkInformationById(id);
                     if (ci.sha1 == null)
                         continue;
                     data = SHA1Access.GetDataBySha1(ci.sha1);
                 }
             }
             mesh.LoadChunkData(lod, new MemoryStream(data));
         }
         MeshRenderObject mro = new MeshRenderObject(mesh);
         renderer.list.Clear();
         renderer.list.Add(mro);
         renderer.worldoffset = -mro.center;
         renderer.CamDistance = mro.min.Length() + mro.max.Length();
         status.Text = "Ready";
     }
     catch (Exception ex)
     {
         status.Text = "General error, after state '" + status.Text + "' : " + ex.Message;
     }
 }