/* * protected override object LoadData(Stream stream) * { * * } * * protected override bool SaveData(object data, Stream stream) * { * // Haven't yet created this code. * return false; * } * * public override string[] FileTypes * { * * } * * public override string Filter * { * * } * * public override Type[] DataTypes * { * get {return new Type[] {typeof(Scene)};} * }*/ public Scene LoadData(string path) { // Create a null scene. Scene scene = null; // Open the file stream. using (var fileStream = new FileStream(path, FileMode.Open)) { using (var reader = new BinaryReader(fileStream, System.Text.Encoding.ASCII)) { // Create a new scene to load to. scene = new Scene(); // Peep the first chunk to make sure it's a 'main' chunk. if (MAXChunkHeader.Peep(reader).type != ChunkType.CHUNK_MAIN) { return(null); } // The first chunk is always the main chunk, so read it. MainChunk main = new MainChunk(); main.Read(scene, reader); } } // Return the scene. return(scene); }
public static MAXChunkHeader Peep(BinaryReader stream) { // Read a header. MAXChunkHeader header = new MAXChunkHeader(); header.Read(stream); // Go back. stream.BaseStream.Seek(-6, System.IO.SeekOrigin.Current); // Return the header. return header; }
public static MAXChunkHeader Peep(BinaryReader stream) { // Read a header. MAXChunkHeader header = new MAXChunkHeader(); header.Read(stream); // Go back. stream.BaseStream.Seek(-6, System.IO.SeekOrigin.Current); // Return the header. return(header); }
public override void ReadData(Scene scene, BinaryReader stream) { do { // Peep at the next chunk. MAXChunkHeader next = MAXChunkHeader.Peep(stream); // If it's an Trimesh Block, we can read that. if (next.type == ChunkType.CHUNK_TRIMESH) { TriangleMeshChunk chunk = new TriangleMeshChunk(); chunk.Read(scene, stream); } else { // We don't know what this chunk is, so just read the generic one. MAXChunk chunk = new MAXChunk(); chunk.Read(scene, stream); } } while (MoreChunks(stream)); }
public override void ReadData(Scene scene, BinaryReader stream) { // A triangle mesh is basicly a Polygon, so create it. Polygon poly = new Polygon(); Matrix matrix = new Matrix(Matrix.Identity(4)); do { // Peep at the next chunk. MAXChunkHeader next = MAXChunkHeader.Peep(stream); if (next.type == ChunkType.CHUNK_VERTLIST) { // Read the vertices. VertexListChunk chunk = new VertexListChunk(); chunk.Read(scene, stream); // Set them into the polygon. poly.Vertices = chunk.vertices; } else if (next.type == ChunkType.CHUNK_FACELIST) { // Read the faces. FaceListChunk chunk = new FaceListChunk(); chunk.Read(scene, stream); // Set them into the polygon. poly.Faces = chunk.faces; } else if (next.type == ChunkType.CHUNK_MAPLIST) { // Read the uvs. MapListChunk chunk = new MapListChunk(); chunk.Read(scene, stream); // Set them into the polygon. poly.UVs = chunk.uvs; } else if (next.type == ChunkType.CHUNK_TRMATRIX) { // Here we just read the matrix (we'll use it later). TrMatrixChunk chunk = new TrMatrixChunk(); chunk.Read(scene, stream); matrix = chunk.matrix; } else { // We don't know what this chunk is, so just read the generic one. MAXChunk chunk = new MAXChunk(); chunk.Read(scene, stream); } } while (MoreChunks(stream)); // Now we multiply each vertex by the matrix. for (int i = 0; i < poly.Vertices.Count; i++) { poly.Vertices[i] *= matrix; } // Add the poly to the scene. scene.SceneContainer.AddChild(poly); }