void ProcessChunk(ThreeDSChunk chunk) { while (chunk.BytesRead < chunk.Length) { ThreeDSChunk child = new ThreeDSChunk(reader); switch ((ThreeDSChunkType)child.ID) { case ThreeDSChunkType.CVersion: int version = reader.ReadInt32(); child.BytesRead += 4; Console.WriteLine("3DS File Version: {0}", version); break; case ThreeDSChunkType._3DEditorChunk: ThreeDSChunk obj_chunk = new ThreeDSChunk(reader); // not sure whats up with this chunk SkipChunk(obj_chunk); child.BytesRead += obj_chunk.BytesRead; ProcessChunk(child); break; case ThreeDSChunkType.EditorMaterial: ProcessMaterialChunk(child); //SkipChunk ( child ); break; case ThreeDSChunkType.ObjectBlock: //SkipChunk ( child ); string name = ProcessString(child); Console.WriteLine("OBJECT NAME: {0}", name); ThreeDSMesh e = ProcessObjectChunk(child); e.CalculateNormals(); model.Entities.Add(e); break; default: SkipChunk(child); break; } chunk.BytesRead += child.BytesRead; //Console.WriteLine ( "ID: {0} Length: {1} Read: {2}", chunk.ID.ToString("x"), chunk.Length , chunk.BytesRead ); } }
ThreeDSMesh ProcessObjectChunk(ThreeDSChunk chunk, ThreeDSMesh e) { while (chunk.BytesRead < chunk.Length) { ThreeDSChunk child = new ThreeDSChunk(reader); switch ((ThreeDSChunkType)child.ID) { case ThreeDSChunkType.TriangularMesh: ProcessObjectChunk(child, e); break; case ThreeDSChunkType.VerticesList: e.vertices = ReadVertices(child); break; case ThreeDSChunkType.FacesDescription: e.indices = ReadIndices(child); if (child.BytesRead < child.Length) { ProcessObjectChunk(child, e); } break; case ThreeDSChunkType.FacesMaterial: string name2 = ProcessString(child); Console.WriteLine(" Uses Material: {0}", name2); ThreeDSMaterial mat; if (materials.TryGetValue(name2, out mat)) { e.material = mat; } else { Console.WriteLine(" Warning: Material '{0}' not found. ", name2); } //throw new Exception ( "Material not found!" ); /* * int nfaces = reader.ReadUInt16 (); * child.BytesRead += 2; * Console.WriteLine ( nfaces ); * * for ( int ii=0; ii< nfaces+2; ii++) * { * Console.Write ( reader.ReadUInt16 () + " " ); * child.BytesRead += 2; * * } */ SkipChunk(child); break; case ThreeDSChunkType.MappingCoordinatesList: int cnt = reader.ReadUInt16(); child.BytesRead += 2; Console.WriteLine(" TexCoords: {0}", cnt); e.texcoords = new TexCoord[cnt]; for (int ii = 0; ii < cnt; ii++) { e.texcoords[ii] = new TexCoord(reader.ReadSingle(), reader.ReadSingle()); } child.BytesRead += (cnt * (4 * 2)); break; default: SkipChunk(child); break; } chunk.BytesRead += child.BytesRead; //Console.WriteLine ( " ID: {0} Length: {1} Read: {2}", chunk.ID.ToString("x"), chunk.Length , chunk.BytesRead ); } return(e); }
ThreeDSMesh ProcessObjectChunk(ThreeDSChunk chunk, ThreeDSMesh e) { while (chunk.BytesRead < chunk.Length) { ThreeDSChunk child = new ThreeDSChunk(reader); switch ((ThreeDSChunkType)child.ID) { case ThreeDSChunkType.TriangularMesh: ProcessObjectChunk(child, e); break; case ThreeDSChunkType.VerticesList: e.vertices = ReadVertices(child); break; case ThreeDSChunkType.FacesDescription: e.indices = ReadIndices(child); if (child.BytesRead < child.Length) ProcessObjectChunk(child, e); break; case ThreeDSChunkType.FacesMaterial: string name2 = ProcessString(child); Console.WriteLine(" Uses Material: {0}", name2); ThreeDSMaterial mat; if (materials.TryGetValue(name2, out mat)) e.material = mat; else Console.WriteLine(" Warning: Material '{0}' not found. ", name2); //throw new Exception ( "Material not found!" ); /* int nfaces = reader.ReadUInt16 (); child.BytesRead += 2; Console.WriteLine ( nfaces ); for ( int ii=0; ii< nfaces+2; ii++) { Console.Write ( reader.ReadUInt16 () + " " ); child.BytesRead += 2; } */ SkipChunk(child); break; case ThreeDSChunkType.MappingCoordinatesList: int cnt = reader.ReadUInt16(); child.BytesRead += 2; Console.WriteLine(" TexCoords: {0}", cnt); e.texcoords = new TexCoord[cnt]; for (int ii = 0; ii < cnt; ii++) e.texcoords[ii] = new TexCoord(reader.ReadSingle(), reader.ReadSingle()); child.BytesRead += (cnt * (4 * 2)); break; default: SkipChunk(child); break; } chunk.BytesRead += child.BytesRead; //Console.WriteLine ( " ID: {0} Length: {1} Read: {2}", chunk.ID.ToString("x"), chunk.Length , chunk.BytesRead ); } return e; }