예제 #1
0
        /// <summary>
        /// Parses the face-specific polygonal data from the current data segment.
        /// </summary>
        /// <param name="dataSegment">
        /// Contains the data to be parsed.
        /// </param>
        protected void ParseFaceData(DataReader3DS dataSegment)
        {
            int           i;          // counter
            DataReader3DS subSegment; // will be used to read other subsegments (do not initialize yet)

            this.currentMeshData.Faces = new MeshData3DS.FaceData3DS[dataSegment.GetUShort()];
            // Read face data
            for (i = 0; i < this.currentMeshData.Faces.Length; i++)
            {
                this.currentMeshData.Faces[i].Vertex1 = dataSegment.GetUShort();
                this.currentMeshData.Faces[i].Vertex2 = dataSegment.GetUShort();
                this.currentMeshData.Faces[i].Vertex3 = dataSegment.GetUShort();
                this.currentMeshData.Faces[i].Flags   = dataSegment.GetUShort();
            }
            // Read other subsegments
            subSegment = dataSegment.GetNextSubSegment();
            while (subSegment != null)
            {
                switch (subSegment.Tag)
                {
                case 0x4130:     // Name of material used
                    this.currentMeshData.MaterialUsed = subSegment.GetString();
                    break;
                }
                subSegment = dataSegment.GetNextSubSegment();
            }
        }
예제 #2
0
        /// <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();
        }
예제 #3
0
        public void Load()
        {
            DataReader3DS dataSubSegment = null;

            //Validate that the 3DS file is good
            if ((this.dataReader != null) && (this.dataReader.Tag == 0x4D4D))
            {
                dataSubSegment = this.dataReader.GetNextSubSegment();
            }
            else
            {
                throw new FileLoadException("3DS file is either corrupted or otherwise not recognizable.");
            }
            // Check to see what kind of data is contained in the current data subsegment
            while (dataSubSegment != null)
            {
                // Check the tag to see what sort of data is in this subsegment (or "chunk")
                switch (dataSubSegment.Tag)
                {
                case 0x0002:                                        // Subsegment contains 3DS version
                    ushort version3DS = dataSubSegment.GetUShort(); //This is the 3DS version
                    this.version = version3DS.ToString();
                    break;

                case 0x3D3D:     // Subsegment contains 3DS data
                    this.ParseData(dataSubSegment);
                    break;
                }
                dataSubSegment = this.dataReader.GetNextSubSegment();
            }
            //// Attempt to write mesh data to the .mesh.xml file
            //if (meshDataStore.Count > 0) {
            //    try {
            //        WriteMeshFile(meshFileName);
            //    } catch (Exception anyException) {
            //        System.Console.WriteLine("Error writing mesh XML file. See below for error...");
            //        System.Console.WriteLine(anyException.Message);
            //    }
            //}
            //// Attempt to write material data to the .material file
            //if (materialDataStore.Count > 0) {
            //    try {
            //        WriteMaterialFile(materialFileName);
            //    } catch (Exception anyException) {
            //        System.Console.WriteLine("Error writing material file. See below for error...");
            //        System.Console.WriteLine(anyException.Message);
            //    }
            //}
        }
예제 #4
0
        /// <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;
            }
        }
예제 #5
0
 /// <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;
     }
 }
예제 #6
0
 /// <summary>
 /// Parses the face-specific polygonal data from the current data segment.
 /// </summary>
 /// <param name="dataSegment">
 /// Contains the data to be parsed.
 /// </param>
 protected void ParseFaceData(DataReader3DS dataSegment)
 {
     int i; // counter
     DataReader3DS subSegment; // will be used to read other subsegments (do not initialize yet)
     this.currentMeshData.Faces = new MeshData3DS.FaceData3DS[dataSegment.GetUShort()];
     // Read face data
     for (i = 0; i < this.currentMeshData.Faces.Length; i++) {
         this.currentMeshData.Faces[i].Vertex1 = dataSegment.GetUShort();
         this.currentMeshData.Faces[i].Vertex2 = dataSegment.GetUShort();
         this.currentMeshData.Faces[i].Vertex3 = dataSegment.GetUShort();
         this.currentMeshData.Faces[i].Flags = dataSegment.GetUShort();
     }
     // Read other subsegments
     subSegment = dataSegment.GetNextSubSegment();
     while (subSegment != null) {
         switch (subSegment.Tag) {
             case 0x4130: // Name of material used
                 this.currentMeshData.MaterialUsed = subSegment.GetString();
                 break;
         }
         subSegment = dataSegment.GetNextSubSegment();
     }
 }