/// <summary> /// Parses the polygonal data from the current data segment. /// </summary> /// <param name="dataSegment"> /// Contains the data to be parsed. /// </param> protected void ParsePolygonalData(DataReader3DS dataSegment) { int i; // counter DataReader3DS subSegment = dataSegment.GetNextSubSegment(); // working data subsegment while (subSegment != null) { switch (subSegment.Tag) { case 0x4110: // Subsegment contains vertex information this.currentMeshData.Vertices = new Point3D[subSegment.GetUShort()]; for (i = 0; i < this.currentMeshData.Vertices.Length; i++) { this.currentMeshData.Vertices[i].X = subSegment.GetFloat(); this.currentMeshData.Vertices[i].Y = subSegment.GetFloat(); this.currentMeshData.Vertices[i].Z = subSegment.GetFloat(); } break; case 0x4160: // Subsegment contains translation matrix info (ignore for now) break; case 0x4120: // Subsegment contains face information this.ParseFaceData(subSegment); break; case 0x4140: // Subsegment contains texture mapping information this.currentMeshData.TextureCoordinates = new Point2D[subSegment.GetUShort()]; //HACK: This is because the above array allocation doesn't automatically //HACK: create each element. for (i = 0; i < this.currentMeshData.TextureCoordinates.Length; i++) { this.currentMeshData.TextureCoordinates[i] = new Point2D(); } //HACK: End hack. if (this.currentMeshData.TextureCoordinates.Length != this.currentMeshData.Vertices.Length) { Console.WriteLine("WARNING: Possible errors in texture coordinate mapping!"); } for (i = 0; i < this.currentMeshData.TextureCoordinates.Length; i++) { this.currentMeshData.TextureCoordinates[i].X = subSegment.GetFloat(); this.currentMeshData.TextureCoordinates[i].Y = subSegment.GetFloat(); } break; } subSegment = dataSegment.GetNextSubSegment(); } // Also use face data to calculate vertex normals this.CalculateVertexNormals(); }
/// <summary> /// Parses color data from the current data segment. /// </summary> /// <param name="dataSegment"> /// Contains the data to be parsed. /// </param> /// <returns> /// Returns the color that was parsed. /// </returns> protected RGBColor ParseColorData(DataReader3DS dataSegment) { RGBColor result = RGBColor.Black; switch (dataSegment.Tag) { case 0x0010: // Color is in float format result.R = dataSegment.GetFloat(); result.G = dataSegment.GetFloat(); result.B = dataSegment.GetFloat(); break; case 0x0011: // Color is in byte format result.R = dataSegment.GetByte() / 255.0f; result.G = dataSegment.GetByte() / 255.0f; result.B = dataSegment.GetByte() / 255.0f; break; default: // If there are any other formats, then we ignore them break; } return(result); }
/// <summary> /// Parses the texture weight from the current data segment. /// </summary> /// <param name="dataSegment"> /// Contains the data to be parsed. /// </param> protected void ParseTextureWeight(DataReader3DS dataSegment) { switch (dataSegment.Tag) { case 0x0030: // Percentage is in short format this.currentMaterialData.textureWeight = ((float)dataSegment.GetUShort()) / (float)100.0; break; case 0x0031: // Percentage is in float format this.currentMaterialData.textureWeight = dataSegment.GetFloat(); break; default: // There should be no other formats, but if there are then we ignore break; } }
/// <summary> /// Parses the texture weight from the current data segment. /// </summary> /// <param name="dataSegment"> /// Contains the data to be parsed. /// </param> protected void ParseTextureWeight(DataReader3DS dataSegment) { switch (dataSegment.Tag) { case 0x0030: // Percentage is in short format this.currentMaterialData.textureWeight = ((float) dataSegment.GetUShort()) / (float) 100.0; break; case 0x0031: // Percentage is in float format this.currentMaterialData.textureWeight = dataSegment.GetFloat(); break; default: // There should be no other formats, but if there are then we ignore break; } }
/// <summary> /// Parses color data from the current data segment. /// </summary> /// <param name="dataSegment"> /// Contains the data to be parsed. /// </param> /// <returns> /// Returns the color that was parsed. /// </returns> protected RGBColor ParseColorData(DataReader3DS dataSegment) { RGBColor result = RGBColor.Black; switch (dataSegment.Tag) { case 0x0010: // Color is in float format result.R = dataSegment.GetFloat(); result.G = dataSegment.GetFloat(); result.B = dataSegment.GetFloat(); break; case 0x0011: // Color is in byte format result.R = dataSegment.GetByte() / 255.0f; result.G = dataSegment.GetByte() / 255.0f; result.B = dataSegment.GetByte() / 255.0f; break; default: // If there are any other formats, then we ignore them break; } return result; }