예제 #1
0
 public Loader3DSModel(String filePath)
 {
     if (filePath != null && File.Exists(filePath)) {
         this.filePath = filePath;
         this.stream = new FileStream(filePath, FileMode.Open, FileAccess.Read);
         BinaryReader byteExtractor = new BinaryReader(this.stream);
         this.dataReader = new DataReader3DS(byteExtractor.ReadBytes((int) this.stream.Length));
         this.meshDataStore = new Hashtable();
         this.materialDataStore = new Hashtable();
         this.currentMeshData = null;
         this.currentMaterialData = null;
     } else {
         throw new FileNotFoundException();
     }
 }
예제 #2
0
 public Loader3DSModel(String filePath)
 {
     if (filePath != null && File.Exists(filePath))
     {
         this.filePath = filePath;
         this.stream   = new FileStream(filePath, FileMode.Open, FileAccess.Read);
         BinaryReader byteExtractor = new BinaryReader(this.stream);
         this.dataReader          = new DataReader3DS(byteExtractor.ReadBytes((int)this.stream.Length));
         this.meshDataStore       = new Hashtable();
         this.materialDataStore   = new Hashtable();
         this.currentMeshData     = null;
         this.currentMaterialData = null;
     }
     else
     {
         throw new FileNotFoundException();
     }
 }
예제 #3
0
        /// <summary>
        /// Parses the material data from the current data segment.
        /// </summary>
        /// <param name="dataSegment">
        /// Contains the data to be parsed.
        /// </param>
        protected void ParseMaterialData(DataReader3DS dataSegment)
        {
            DataReader3DS subSegment = dataSegment.GetNextSubSegment();

            this.currentMaterialData = new MaterialData3DS();
            while (subSegment != null)
            {
                switch (subSegment.Tag)
                {
                case 0xa000:     // Subsegment holds material name
                    this.currentMaterialData.name = subSegment.GetString();
                    Console.WriteLine("Material is named: " + this.currentMaterialData.name);
                    break;

                case 0xa010:     // Subsegment holds ambient color
                    this.currentMaterialData.ambient = this.ParseColorData(subSegment.GetNextSubSegment());
                    break;

                case 0xa020:     // Subsegment holds diffuse color (this is iffy...)
                    this.currentMaterialData.diffuse = this.ParseColorData(subSegment.GetNextSubSegment());
                    break;

                case 0xa200:     // Subsegment holds texture map info
                    this.ParseTextureWeight(subSegment.GetNextSubSegment());
                    this.currentMaterialData.textureName = subSegment.GetNextSubSegment().GetString();
                    break;

                default:     // Ignore all other subsegment types
                    break;
                }
                subSegment = dataSegment.GetNextSubSegment();
            }
            // Store newly created material in data store and change name if another exists with its name
            while (this.materialDataStore.ContainsKey(this.currentMaterialData.name))
            {
                this.currentMaterialData.name += "X";
            }
            this.materialDataStore.Add(this.currentMaterialData.name, this.currentMaterialData);
        }
예제 #4
0
 /// <summary>
 /// Parses the material data from the current data segment.
 /// </summary>
 /// <param name="dataSegment">
 /// Contains the data to be parsed.
 /// </param>
 protected void ParseMaterialData(DataReader3DS dataSegment)
 {
     DataReader3DS subSegment = dataSegment.GetNextSubSegment();
     this.currentMaterialData = new MaterialData3DS();
     while (subSegment != null) {
         switch (subSegment.Tag) {
             case 0xa000: // Subsegment holds material name
                 this.currentMaterialData.name = subSegment.GetString();
                 Console.WriteLine("Material is named: " + this.currentMaterialData.name);
                 break;
             case 0xa010: // Subsegment holds ambient color
                 this.currentMaterialData.ambient = this.ParseColorData(subSegment.GetNextSubSegment());
                 break;
             case 0xa020: // Subsegment holds diffuse color (this is iffy...)
                 this.currentMaterialData.diffuse = this.ParseColorData(subSegment.GetNextSubSegment());
                 break;
             case 0xa200: // Subsegment holds texture map info
                 this.ParseTextureWeight(subSegment.GetNextSubSegment());
                 this.currentMaterialData.textureName = subSegment.GetNextSubSegment().GetString();
                 break;
             default: // Ignore all other subsegment types
                 break;
         }
         subSegment = dataSegment.GetNextSubSegment();
     }
     // Store newly created material in data store and change name if another exists with its name
     while (this.materialDataStore.ContainsKey(this.currentMaterialData.name)) {
         this.currentMaterialData.name += "X";
     }
     this.materialDataStore.Add(this.currentMaterialData.name, this.currentMaterialData);
 }