Exemplo n.º 1
0
Arquivo: File.cs Projeto: tpb3d/TPB3D
		public File(string fileName)
		{
			this.fileName = fileName;
		
			using(FileStream file = System.IO.File.OpenRead(fileName))
			{
				using(BinaryReader r = new BinaryReader(file))
				{
						this.header = new Header(r);
			
						ushort numVertices = r.ReadUInt16();
						this.vertices = new Vertex[numVertices];
						
						for(int i = 0; i < numVertices; i++)
						{
							vertices[i] = new Vertex(r);
						}
						
						ushort numTriangles = r.ReadUInt16();
						this.triangles = new Triangle[numTriangles];
						for (int i = 0; i < numTriangles; i++) 
						{
							triangles[i] = new Triangle(r);
						}
					
						ushort numGroups = r.ReadUInt16();
						this.groups = new Group[numGroups];
						for (int i = 0; i < numGroups; i++) 
						{
							groups[i] = new Group(r);
						}
						
						ushort numMaterials = r.ReadUInt16();
						this.materials = new Material[numMaterials];
						for (int i = 0; i < numMaterials; i++)
						{
							materials[i] = new Material(r);
						}
						
						this.animationFPS = r.ReadSingle();
						this.currentTime = r.ReadSingle();
						this.totalFrames = r.ReadInt32();
						
						ushort numJoints = r.ReadUInt16();
						this.joints = new Joint[numJoints];
						for (int i = 0; i < numJoints; i++)
						{
							joints[i] = new Joint(r);
						}	

						try
						{
							int commentSubversion = r.ReadInt32();
							if(commentSubversion != 1) throw new Exception("Unsupported comments sub version");
						}
						catch (EndOfStreamException ex)
						{
							ex.ToString();
							return;
						}
						
						uint numGroupComments = r.ReadUInt32();				
						this.groupComments = ReadComments(r, (int)numGroupComments);

						int numMaterialComments = r.ReadInt32();
						this.materialComments = ReadComments(r, numMaterialComments);

						int numJointComments = r.ReadInt32();
						this.jointComments = ReadComments(r, numJointComments);
						
						int numModelComments = r.ReadInt32();
						this.modelComments = ReadComments(r, numModelComments);

						int vertexSubVersion = r.ReadInt32();
						if (vertexSubVersion > 2) throw new Exception(string.Format("Unsupported extended vertex sub version. Found {0}. Expected 1 or 2", vertexSubVersion));
						
						for(int i = 0; i < numVertices; i++)
						{
							vertices[i] = new Vertex(r, vertices[i], vertexSubVersion);
						}

						// int jointSubVersion = r.ReadInt32();
						// if (jointSubVersion != 1) throw new Exception(string.Format("Unsupported extended joint sub version. Found {0}. Expected 1", jointSubVersion));

						// I stopped parsing early because I don't think I need the rest of the data.			
				}
			}		
		}
Exemplo n.º 2
0
        public Vertex(BinaryReader r, Vertex v, int subVersion)
        {
            flags = v.flags;
            vertex = v.vertex;
            boneId0 = v.boneId0;
            referenceCount = v.referenceCount;

            boneId1 = r.ReadSByte();
            boneId2 = r.ReadSByte();
            boneId3 = r.ReadSByte();

            weight0 = r.ReadByte() / 255.0f;
            weight1 = r.ReadByte() / 255.0f;
            weight2 = r.ReadByte() / 255.0f;

            if (subVersion == 1) return;

            r.ReadUInt32(); // extra data subversion 2+
        }