コード例 #1
0
ファイル: VTXReader.cs プロジェクト: maesse/CubeHags
        public static VTXMesh ReadMesh(BinaryReader br, int offset, int lodNum, int vertexOffset, MDLMesh mdlmesh)
        {
            br.BaseStream.Seek(offset, SeekOrigin.Begin);
            VTXMesh mesh = new VTXMesh();
            mesh.num_strip_groups = br.ReadInt32();
            mesh.strip_group_offset = br.ReadInt32();
            mesh.mesh_flags = br.ReadByte();
            mesh.StripGroups = new VTXStripGroup[mesh.num_strip_groups];
            for (int i = 0; i < mesh.num_strip_groups; i++)
            {
                mesh.StripGroups[i] = ReadStripGroup(br, offset + mesh.strip_group_offset + (i * VTXStripGroup.VTX_STRIP_GROUP_SIZE), lodNum, vertexOffset, mdlmesh);
            }

            return mesh;
        }
コード例 #2
0
ファイル: MDLReader.cs プロジェクト: maesse/CubeHags
        private static MDLMesh ReadMesh(BinaryReader br, int offset)
        {
            br.BaseStream.Seek(offset, SeekOrigin.Begin);
            MDLMesh_t mesh_t = new MDLMesh_t();
            mesh_t.material_index = br.ReadInt32();
            mesh_t.model_index = br.ReadInt32();

            mesh_t.num_vertices = br.ReadInt32();
            mesh_t.vertex_offset = br.ReadInt32();

            mesh_t.num_flexes = br.ReadInt32();
            mesh_t.flex_offset = br.ReadInt32();

            mesh_t.material_type = br.ReadInt32();
            mesh_t.material_param = br.ReadInt32();

            mesh_t.mesh_id = br.ReadInt32();

            mesh_t.mesh_center = new Vector3(br.ReadSingle(), br.ReadSingle(), br.ReadSingle());
            mesh_t.vertex_data = new MDLMeshVertexData();
            mesh_t.vertex_data.model_vertex_data_ptr = br.ReadInt32();
            mesh_t.vertex_data.num_lod_vertices = new int[8];
            for (int i = 0; i < 8; i++)
            {
                mesh_t.vertex_data.num_lod_vertices[i] = br.ReadInt32();
            }

            mesh_t.unused_array = new int[8]; // 8
            for (int i = 0; i < 8; i++)
            {
                mesh_t.unused_array[i] = br.ReadInt32();
            }

            MDLMesh mesh = new MDLMesh(mesh_t, srcModel, materials[mesh_t.material_index]);
            return mesh;
        }
コード例 #3
0
ファイル: VTXReader.cs プロジェクト: maesse/CubeHags
        public static VTXStripGroup ReadStripGroup(BinaryReader br, int offset, int lodNum, int vertexOffset, MDLMesh mesh)
        {
            br.BaseStream.Seek(offset, SeekOrigin.Begin);
            VTXStripGroup strGroup = new VTXStripGroup();
            strGroup.num_vertices  = br.ReadInt32();
            strGroup.vertex_offset = br.ReadInt32();
            strGroup.num_indices = br.ReadInt32();
            strGroup.index_offset = br.ReadInt32();
            strGroup.num_strips = br.ReadInt32();
            strGroup.strip_offset = br.ReadInt32();
            strGroup.strip_group_flags = br.ReadByte();

            // Fill vertex arrays
            List<Vector3> vertexArray = new List<Vector3>();
            List<Vector3> normalArray = new List<Vector3>();
            List<Vector2> texcoordArray = new List<Vector2>();
            List<VertexPositonNormalColorTexture> verts = new List<VertexPositonNormalColorTexture>();
            br.BaseStream.Seek(strGroup.vertex_offset + offset, SeekOrigin.Begin);
            for (int i = 0; i < strGroup.num_vertices; i++)
            {
                VTXVertex vertex = ReadVertex(br);
                int vertexID = vertex.orig_mesh_vertex_id + vertexOffset;

                // Get vvd info
                VVDVertex vvdVertex = VVDReader.vertex_buffer[lodNum][vertexID];
                vertexArray.Add(vvdVertex.vertex_position);
                normalArray.Add(vvdVertex.vertex_normal);
                texcoordArray.Add(vvdVertex.vertex_texcoord);
                verts.Add(new VertexPositonNormalColorTexture(vvdVertex.vertex_position, vvdVertex.vertex_normal, new Color4(Color.Blue), vvdVertex.vertex_texcoord));
            }
            strGroup.Verts = vertexArray;
            strGroup.Normals = normalArray;
            strGroup.Coords = texcoordArray;
            // Fill index array
            br.BaseStream.Seek(offset + strGroup.index_offset, SeekOrigin.Begin);
            List<uint> indexArray = new List<uint>();
            for (int i = 0; i < strGroup.num_indices; i++)
            {
                indexArray.Add((uint)br.ReadUInt16());
            }
            strGroup.Indices = indexArray;
            // Create SourceModel
            RenderItem stripitem = new RenderItem(mesh, mesh.material);
            stripitem.verts = verts;
            stripitem.nVerts = verts.Count;

            // Set IB
            stripitem.indices = indexArray;
            // Create VB
            //stripitem.vb = new HagsVertexBuffer();
            //int vertexBytes = verts.Count * VertexPositonNormalColorTexture.SizeInBytes;
            //stripitem.vb.SetVB<VertexPositonNormalColorTexture>(verts.ToArray(), vertexBytes, VertexPositonNormalColorTexture.Format, Usage.WriteOnly);
            //stripitem.DontOptimize = true;
            //stripitem.GenerateIndexBuffer();
            strGroup.Strips = new VTXStrip[strGroup.num_strips];
            // Process strips
            for (int i = 0; i < strGroup.num_strips; i++)
            {
                RenderItem item = new RenderItem(stripitem, null);
                VTXStrip strip = ReadStrip(br, offset + strGroup.strip_offset + (i* VTXStrip.VTX_STRIP_SIZE), indexArray);
                item.nVerts = strip.num_vertices;
                item.nIndices = strip.num_indices;
                item.IndiceStartIndex = strip.index_offset;
                item.vertexStartIndex = strip.vertex_offset;
                item.DontOptimize = true;
                if (strip.strip_flags == 0x02)
                    item.Type = PrimitiveType.TriangleStrip;

                stripitem.items.Add(item);
            }
            mesh.items.Add(stripitem);

            return strGroup;
        }