Exemplo n.º 1
0
 private void PrepareLodForExport(MeshAsset mesh, int n)
 {
     LoadRawLodBuffer(mesh, n);
     if (rawLodBuffer != null)
     {
         mesh.lods[n].LoadVertexData(new MemoryStream(rawLodBuffer));
         if (flipUToolStripMenuItem.Checked || flipVToolStripMenuItem.Checked)
         {
             for (int i = 0; i < mesh.lods[n].sections.Count; i++)
             {
                 MeshLodSection sec = mesh.lods[n].sections[i];
                 for (int j = 0; j < sec.vertices.Count; j++)
                 {
                     for (int uvInd = 0; uvInd < Vertex.UV_SLOTS; uvInd++)
                     {
                         if (sec.vertices[i].texCoords[uvInd].members.Length == 2)
                         {
                             if (flipUToolStripMenuItem.Checked)
                             {
                                 sec.vertices[i].texCoords[uvInd].members[0] = 1 - sec.vertices[i].texCoords[uvInd].members[0];
                             }
                             if (flipVToolStripMenuItem.Checked)
                             {
                                 sec.vertices[i].texCoords[uvInd].members[1] = 1 - sec.vertices[i].texCoords[uvInd].members[1];
                             }
                         }
                     }
                 }
                 mesh.lods[n].sections[i] = sec;
             }
         }
     }
 }
Exemplo n.º 2
0
        private void toolStripComboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            int n = toolStripComboBox1.SelectedIndex;

            byte[] id  = mesh.lods[n].chunkID;
            string sid = Helpers.ByteArrayToHexString(id);

            rawLodBuffer     = null;
            hb2.ByteProvider = new DynamicByteProvider(new byte[0]);
            LoadRawLodBuffer(mesh, n);
            if (rawLodBuffer != null)
            {
                hb2.ByteProvider = new DynamicByteProvider(rawLodBuffer);
                mesh.lods[n].LoadVertexData(new MemoryStream(rawLodBuffer));
                timer1.Enabled = false;
                List <RawVector3> verts = new List <RawVector3>();
                for (int i = 0; i < mesh.lods[n].sections.Count; i++)
                {
                    MeshLodSection sec = mesh.lods[n].sections[i];
                    foreach (ushort idx in sec.indicies)
                    {
                        Vertex v = sec.vertices[idx];
                        if (v.position.members.Length == 3)
                        {
                            verts.Add(new RawVector3(v.position.members[0], v.position.members[1], v.position.members[2]));
                        }
                    }
                }
                RawVector3 min = new RawVector3(10000, 10000, 10000);
                RawVector3 max = new RawVector3(-10000, -10000, -10000);
                foreach (RawVector3 v in verts)
                {
                    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;
                    }
                    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;
                    }
                }
                mid             = new RawVector3((min.X + max.X) / 2f, (min.Y + max.Y) / 2f, (min.Z + max.Z) / 2f);
                DXHelper.CamDis = (float)Math.Sqrt(Math.Pow(max.X - mid.X, 2) + Math.Pow(max.Y - mid.Y, 2) + Math.Pow(max.Z - mid.Z, 2)) * 1.5f;
                if (DXHelper.CamDis < 1f)
                {
                    DXHelper.CamDis = 1f;
                }
                for (int i = 0; i < verts.Count; i++)
                {
                    RawVector3 v = verts[i];
                    v.X     -= mid.X;
                    v.Y     -= mid.Y;
                    v.Z     -= mid.Z;
                    verts[i] = v;
                }
                RenderObject ro = new RenderObject(DXHelper.device, RenderObject.RenderType.TriListWire, DXHelper.pixelShader);
                ro.vertices = verts.ToArray();
                ro.InitGeometry();
                DXHelper.objects = new List <RenderObject>();
                DXHelper.objects.Add(ro);
                if (skeleton != null)
                {
                    RenderObject skel = MakeSkeletonMesh(skeleton);
                    for (int i = 0; i < skel.vertices.Length; i++)
                    {
                        skel.vertices[i].X -= mid.X;
                        skel.vertices[i].Y -= mid.Y;
                        skel.vertices[i].Z -= mid.Z;
                    }
                    skel.InitGeometry();
                    DXHelper.objects.Add(skel);
                }
                timer1.Enabled = true;
            }
        }
Exemplo n.º 3
0
        private void toolStripButton5_Click(object sender, EventArgs e)
        {
            int n = toolStripComboBox1.SelectedIndex;

            byte[] id  = mesh.lods[n].chunkID;
            string sid = Helpers.ByteArrayToHexString(id);

            rawLodBuffer     = null;
            hb2.ByteProvider = new DynamicByteProvider(new byte[0]);
            foreach (ChunkInfo chunk in chunks)
            {
                if (chunk.id == sid)
                {
                    rawLodBuffer     = main.Host.getDataBySha1(chunk.sha1);
                    hb2.ByteProvider = new DynamicByteProvider(rawLodBuffer);
                    break;
                }
            }
            if (rawLodBuffer == null)
            {
                foreach (ChunkInfo chunk in tocChunks[currToc])
                {
                    if (chunk.id == sid)
                    {
                        rawLodBuffer     = main.Host.getDataBySha1(chunk.sha1);
                        hb2.ByteProvider = new DynamicByteProvider(rawLodBuffer);
                        return;
                    }
                }
            }
            if (rawLodBuffer != null)
            {
                mesh.lods[n].LoadVertexData(new MemoryStream(rawLodBuffer));
                if (flipUToolStripMenuItem.Checked || flipVToolStripMenuItem.Checked)
                {
                    for (int i = 0; i < mesh.lods[n].sections.Count; i++)
                    {
                        MeshLodSection sec = mesh.lods[n].sections[i];
                        for (int j = 0; j < sec.vertices.Count; j++)
                        {
                            if (sec.vertices[i].texCoords.members.Length == 2)
                            {
                                if (flipUToolStripMenuItem.Checked)
                                {
                                    sec.vertices[i].texCoords.members[0] = 1 - sec.vertices[i].texCoords.members[0];
                                }
                                if (flipVToolStripMenuItem.Checked)
                                {
                                    sec.vertices[i].texCoords.members[1] = 1 - sec.vertices[i].texCoords.members[1];
                                }
                            }
                        }
                        mesh.lods[n].sections[i] = sec;
                    }
                }
                SaveFileDialog saveFileDiag = new SaveFileDialog();
                saveFileDiag.Title    = "Save as...";
                saveFileDiag.Filter   = "*.obj|*.obj|*.psk|*.psk|*.fbx|*.fbx";
                saveFileDiag.FileName = mesh.header.shortName;
                if (saveFileDiag.ShowDialog() == DialogResult.OK)
                {
                    string extension  = Path.GetExtension(saveFileDiag.FileName);
                    string targetFile = saveFileDiag.FileName;
                    var    exporter   = MeshExporter.GetExporterByExtension(extension, skeleton);
                    if (exporter != null)
                    {
                        exporter.ExportLod(mesh, n, targetFile);
                        MessageBox.Show("Done.");
                    }
                    else
                    {
                        MessageBox.Show("Unknown extension " + extension);
                    }
                }
            }
        }