Exemplo n.º 1
0
        public void ReadPrerequisites(string name)
        {
            using (BinaryReader reader = new BinaryReader(File.Open(name, FileMode.Open)))
            {
                ushort MeshFlags = reader.ReadUInt16();
                VertexDecleration = (VertexFlags)reader.ReadUInt32();

                int IndexSize = reader.ReadInt32();
                IndexBuffer = reader.ReadBytes(IndexSize);

                VertexCount = reader.ReadInt32();
                int VertexSize = reader.ReadInt32();
                VertexBuffer = reader.ReadBytes(VertexSize);
            }

            //VertexDecleration = (VertexFlags)134933;
            //Offset = new Vector3(-233.86592f, -642.7829f, -1.5614158f);
            //Scale = 0.013024263f;

            int vertexSize;
            Dictionary <VertexFlags, FrameLOD.VertexOffset> vertexOffsets = GetVertexOffsets(out vertexSize);

            int tempVertexSize = VertexBuffer.Length / VertexCount;

            Vertex[] Vertices = new Vertex[VertexCount];

            for (int x = 0; x != VertexCount; x++)
            {
                //declare data required and send to decompresser
                byte[] data = new byte[tempVertexSize];
                Array.Copy(VertexBuffer, (x * tempVertexSize), data, 0, tempVertexSize);
                Vertex decompressed = VertexTranslator.DecompressVertex(data, VertexDecleration, Vector3.Zero, 1.525879E-05f, vertexOffsets);
                Vertices[x] = decompressed;
            }

            Int3[] Triangles = new Int3[IndexBuffer.Length / 3];
            int    index     = 0;

            for (int y = 0; y != IndexBuffer.Length; y += 6)
            {
                int  X        = BitConverter.ToUInt16(IndexBuffer, y + 0);
                int  Y        = BitConverter.ToUInt16(IndexBuffer, y + 2);
                int  Z        = BitConverter.ToUInt16(IndexBuffer, y + 4);
                Int3 triangle = new Int3(X, Y, Z);
                Triangles[index] = triangle;
                index++;
            }

            File.WriteAllLines(name + ".obj", BuildMesh(Vertices, Triangles));
        }
Exemplo n.º 2
0
        public void ReadPrerequisites()
        {
            VertexDecleration = (VertexFlags)134933;
            Offset            = new Vector3(-233.86592f, -642.7829f, -1.5614158f);
            Scale             = 0.013024263f;

            int vertexSize;
            Dictionary <VertexFlags, FrameLOD.VertexOffset> vertexOffsets = GetVertexOffsets(out vertexSize);

            VertexBuffer = File.ReadAllBytes("M3/VertexBuffer.bin");
            IndexBuffer  = File.ReadAllBytes("M3/IndexBuffer.bin");

            int tempVertexSize = VertexBuffer.Length / VertexCount;

            Vertex[] Vertices = new Vertex[VertexCount];

            for (int x = 0; x != VertexCount; x++)
            {
                //declare data required and send to decompresser
                byte[] data = new byte[tempVertexSize];
                Array.Copy(VertexBuffer, (x * tempVertexSize), data, 0, tempVertexSize);
                Vertex decompressed = VertexTranslator.DecompressVertex(data, VertexDecleration, Vector3.Zero, 1.525879E-05f, vertexOffsets);
                Vertices[x] = decompressed;
            }

            Int3[] Triangles = new Int3[IndexBuffer.Length / 3];
            int    index     = 0;

            for (int y = 0; y != IndexBuffer.Length; y += 6)
            {
                Int3 triangle = new Int3();
                triangle.X       = BitConverter.ToUInt16(IndexBuffer, y + 0);
                triangle.Y       = BitConverter.ToUInt16(IndexBuffer, y + 2);
                triangle.Z       = BitConverter.ToUInt16(IndexBuffer, y + 4);
                Triangles[index] = triangle;
                index++;
            }

            File.WriteAllLines("Test.obj", BuildMesh(Vertices, Triangles));
        }
Exemplo n.º 3
0
        public bool ConvertFrameToRenderModel(FrameObjectSingleMesh mesh, FrameGeometry geom, FrameMaterial mats, IndexBuffer[] indexBuffers, VertexBuffer[] vertexBuffers)
        {
            if (mesh == null || geom == null || mats == null || indexBuffers[0] == null || vertexBuffers[0] == null)
            {
                return(false);
            }

            aoHash = mesh.OMTextureHash;
            SetTransform(mesh.WorldTransform);
            //DoRender = (mesh.SecondaryFlags == 4097 ? true : false);
            BoundingBox = mesh.Boundings;
            LODs        = new LOD[geom.NumLods];

            for (int i = 0; i != geom.NumLods; i++)
            {
                LOD lod = new LOD();
                lod.Indices    = indexBuffers[i].GetData();
                lod.ModelParts = new ModelPart[mats.LodMatCount[i]];

                for (int z = 0; z != mats.Materials[i].Length; z++)
                {
                    lod.ModelParts[z]              = new ModelPart();
                    lod.ModelParts[z].NumFaces     = (uint)mats.Materials[i][z].NumFaces;
                    lod.ModelParts[z].StartIndex   = (uint)mats.Materials[i][z].StartIndex;
                    lod.ModelParts[z].MaterialHash = mats.Materials[i][z].MaterialHash;
                    lod.ModelParts[z].Material     = MaterialsManager.LookupMaterialByHash(lod.ModelParts[z].MaterialHash);
                }

                lod.Vertices = new VertexLayouts.NormalLayout.Vertex[geom.LOD[i].NumVerts];
                int vertexSize;
                Dictionary <VertexFlags, FrameLOD.VertexOffset> vertexOffsets = geom.LOD[i].GetVertexOffsets(out vertexSize);
                try
                {
                    for (int x = 0; x != lod.Vertices.Length; x++)
                    {
                        VertexLayouts.NormalLayout.Vertex vertex = new VertexLayouts.NormalLayout.Vertex();

                        //declare data required and send to decompresser
                        byte[] data = new byte[vertexSize];
                        Array.Copy(vertexBuffers[i].Data, (x * vertexSize), data, 0, vertexSize);
                        Vertex decompressed = VertexTranslator.DecompressVertex(data, geom.LOD[i].VertexDeclaration, geom.DecompressionOffset, geom.DecompressionFactor, vertexOffsets);

                        //retrieve the data we require
                        vertex.Position  = decompressed.Position;
                        vertex.Normal    = decompressed.Normal;
                        vertex.Tangent   = decompressed.Tangent;
                        vertex.Binormal  = decompressed.Binormal;
                        vertex.TexCoord0 = decompressed.UVs[0];
                        vertex.TexCoord7 = decompressed.UVs[3];

                        lod.Vertices[x] = vertex;
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(string.Format("Error when creating renderable {1}!: \n{0}", ex.Message, mesh.Name.ToString()), "Toolkit");
                    return(false);
                }
                LODs[i] = lod;
            }

            SetupShaders();
            return(true);
        }