Ejemplo n.º 1
0
        public void Combine(Mesh other)
        {
            uint vertexOffset   = (uint)Vertices.Count;
            uint triangleOffset = (uint)Triangles.Count;
            uint chunkOffset    = (uint)Chunks.Count;

            foreach (Vertex v in other.Vertices)
            {
                Vertices.Add(v);
            }

            foreach (Triangle t in other.Triangles)
            {
                Triangle triangle = new Triangle()
                {
                    V1 = t.V1 + vertexOffset, V2 = t.V2 + vertexOffset, V3 = t.V3 + vertexOffset
                };
                Triangles.Add(triangle);
            }

            foreach (MeshChunk c in other.Chunks)
            {
                MeshChunk chunk = new MeshChunk();
                chunk.Name           = c.Name;
                chunk.DiffuseTexture = c.DiffuseTexture;
                chunk.FaceCount      = c.FaceCount;
                chunk.FaceOffset     = c.FaceOffset + triangleOffset;
                chunk.FirstVertex    = c.FirstVertex + triangleOffset;
                chunk.LastVertex     = c.LastVertex + triangleOffset;
                chunk.Index          = c.Index + chunkOffset;
                Chunks.Add(chunk);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Reads the current mesh chunk
        /// </summary>
        /// <param name="index">Chunk index</param>
        /// <returns>Mesh chunk</returns>
        private MeshChunk ReadMeshChunk(uint index)
        {
            MeshChunk chunk = new MeshChunk();

            chunk.Name  = Common.GetFileName(Name);
            chunk.Index = index;

            ReadChunk(0x24);

            chunk.FirstVertex = ReadUint32();
            chunk.LastVertex  = ReadUint32();
            chunk.FaceOffset  = (ReadUint32() / 3);
            chunk.FaceCount   = ReadUint32();

            ReadChunk(0xC);

            Vector3 u1 = ReadVector3();
            Vector3 u2 = ReadVector3();

            ReadChunk(0x34);

            // Read texture names
            for (int j = 0; j < 9; j++)
            {
                string textureName = ReadString();
                if (j == 0)
                {
                    chunk.DiffuseTexture = textureName;
                }
            }

            ReadChunk(0x19);
            string reflMap = ReadString();

            ReadChunk(0x85);
            string unknownTexture = ReadString();

            ReadChunk(0x2B);
            string ssTexture = ReadString();

            ReadChunk(0x19);

            return(chunk);
        }
Ejemplo n.º 3
0
        public override bool Read(FileStream stream)
        {
            base.Read(stream);

            Name = ReadString();

            ReadChunk(0x6);               // Unknown

            Vector3 pos1 = ReadVector3(); // Min AABB?
            Vector3 pos2 = ReadVector3(); // Max AABB?

            ReadChunk(0x18);

            mesh = new Mesh();

            uint chunkCount = ReadUint32();

            for (uint i = 0; i < chunkCount; i++)
            {
                MeshChunk chunk = ReadMeshChunk(i);
                mesh.Chunks.Add(chunk);
            }

            ReadChunk(0x8);
            if (GetFileType() == 0xE)
            {
                uint unknownSize = ReadUint32(); // Size of chunk
                ReadChunk(0x8);
                ReadChunk(unknownSize);
            }
            else
            {
                // Alternating 0x8 and 0x0
                ReadPadding(5);
            }

            ReadMeta();
            ParseMeshData();

            return(true);
        }