Exemplo n.º 1
0
        private static ThreeDSMesh.Material ParseMaterialData(DataReader3DS dataSegment)
        {
            DataReader3DS subSegment = dataSegment.GetNextSubSegment();

            ThreeDSMesh.Material mat = new ThreeDSMesh.Material();

            while (subSegment != null)
            {
                switch ((ChunkCodes)subSegment.Tag)
                {
                case ChunkCodes.MAT_NAME:       // Subsegment holds material name
                    mat.name = subSegment.GetString();
                    break;

                case ChunkCodes.MAT_AMBIENT:            // Subsegment holds ambient color
                    mat.ambient = ParseColorData(subSegment.GetNextSubSegment());
                    break;

                case ChunkCodes.MAT_DIFFUSE:            // Subsegment holds diffuse color (this is iffy...)
                    mat.diffuse = ParseColorData(subSegment.GetNextSubSegment());
                    break;

                case ChunkCodes.MAT_TEXMAP:     // Subsegment holds texture map info
                    /*ParseTextureWeight(*/ subSegment.GetNextSubSegment();
                    mat.texture = subSegment.GetNextSubSegment().GetString();
                    break;

                default:                // Ignore all other subsegment types
                    break;
                }
                subSegment = dataSegment.GetNextSubSegment();
            }

            // Check if this is a duplicate material entry (by name)
            // NOTE: Duplicate material name update should be in form materialname_submeshname

            /*if (materialDataStore.ContainsKey(currentMaterialData.name))
             * {
             *  // Select an "owning" submesh for the material
             *  referencingSubmeshes = (ArrayList)(submeshesUsingMaterials[currentMaterialData.name]);
             *  owningSubmesh = (SubmeshData3DS)(referencingSubmeshes[referencingSubmeshes.Count - 1]);
             *  // Qualify the material name with the submesh's name as well (see above note)
             *  currentMaterialData.name = currentMaterialData.name + "_" + owningSubmesh.name;
             *  owningSubmesh.materialUsed = currentMaterialData.name;
             *  // Clean up and update submesh reference lists
             *  referencingSubmeshes.RemoveAt(referencingSubmeshes.Count - 1);
             *  referencingSubmeshes = new ArrayList();
             *  referencingSubmeshes.Add(owningSubmesh);
             *  submeshesUsingMaterials.Add(currentMaterialData.name, referencingSubmeshes);
             * }*/

            return(mat);
        }
Exemplo n.º 2
0
        private static ThreeDSMesh.Material ReadMATERIAL(FileStream file, Chunk thischunk)
        {
            uint bytesRead = 6;

            ThreeDSMesh.Material material = new ThreeDSMesh.Material();

            while (bytesRead < thischunk.length)
            {
                Chunk chunk = ReadChunk(file);

                switch ((ChunkCodes)chunk.ID)
                {
                case ChunkCodes.BLANK:
                    break;

                case ChunkCodes.MAT_NAME:
                    uint size = 0;
                    while (file.ReadByte() != 0)
                    {
                        size++;
                    }
                    size++;
                    file.Seek(-size, SeekOrigin.Current);
                    byte[] buffer = new byte[size];
                    file.Read(buffer, 0, (int)size);
                    material.name = ASCIIEncoding.ASCII.GetString(buffer);
                    bytesRead    += size;
                    break;

                case ChunkCodes.MAT_DIFFUSE:
                    material.diffuse = ReadMATDIFFUSE(file, chunk);
                    break;

                case ChunkCodes.MAT_SHININESS:
                    file.Seek(chunk.length - 6, SeekOrigin.Current);
                    break;

                case ChunkCodes.MAT_AMBIENT:
                    material.ambient = ReadMATDIFFUSE(file, chunk);
                    break;

                case ChunkCodes.MAT_SPECULAR:
                    file.Seek(chunk.length - 6, SeekOrigin.Current);
                    break;

                case ChunkCodes.MAT_SHIN_STR:
                    file.Seek(chunk.length - 6, SeekOrigin.Current);
                    break;

                case ChunkCodes.MAT_SELF_ILLU:
                    file.Seek(chunk.length - 6, SeekOrigin.Current);
                    break;

                /*case ChunkCodes.MAT_TEXMAP:
                 *  ReadMATERIAL(file, chunk);
                 *  break;*/
                /*case ChunkCodes.MAT_TEXFLNM:
                 *  while (file.ReadByte() != 0) bytesRead++;
                 *  break;*/
                default:
                    file.Seek(chunk.length - 6, SeekOrigin.Current);
                    break;
                }

                bytesRead += chunk.length;
            }

            return(material);
        }
Exemplo n.º 3
0
        private static ThreeDSMesh.Material ParseMaterialData(DataReader3DS dataSegment)
        {
            DataReader3DS subSegment = dataSegment.GetNextSubSegment();
            ThreeDSMesh.Material mat = new ThreeDSMesh.Material();

            while (subSegment != null)
            {
                switch ((ChunkCodes)subSegment.Tag)
                {
                    case ChunkCodes.MAT_NAME:	// Subsegment holds material name
                        mat.name = subSegment.GetString();
                        break;
                    case ChunkCodes.MAT_AMBIENT:	// Subsegment holds ambient color
                        mat.ambient = ParseColorData(subSegment.GetNextSubSegment());
                        break;
                    case ChunkCodes.MAT_DIFFUSE:	// Subsegment holds diffuse color (this is iffy...)
                        mat.diffuse = ParseColorData(subSegment.GetNextSubSegment());
                        break;
                    case ChunkCodes.MAT_TEXMAP:	// Subsegment holds texture map info
                        /*ParseTextureWeight(*/subSegment.GetNextSubSegment();
                        mat.texture = subSegment.GetNextSubSegment().GetString();
                        break;
                    default:		// Ignore all other subsegment types
                        break;
                }
                subSegment = dataSegment.GetNextSubSegment();
            }

            // Check if this is a duplicate material entry (by name)
            // NOTE: Duplicate material name update should be in form materialname_submeshname
            /*if (materialDataStore.ContainsKey(currentMaterialData.name))
            {
                // Select an "owning" submesh for the material
                referencingSubmeshes = (ArrayList)(submeshesUsingMaterials[currentMaterialData.name]);
                owningSubmesh = (SubmeshData3DS)(referencingSubmeshes[referencingSubmeshes.Count - 1]);
                // Qualify the material name with the submesh's name as well (see above note)
                currentMaterialData.name = currentMaterialData.name + "_" + owningSubmesh.name;
                owningSubmesh.materialUsed = currentMaterialData.name;
                // Clean up and update submesh reference lists
                referencingSubmeshes.RemoveAt(referencingSubmeshes.Count - 1);
                referencingSubmeshes = new ArrayList();
                referencingSubmeshes.Add(owningSubmesh);
                submeshesUsingMaterials.Add(currentMaterialData.name, referencingSubmeshes);
            }*/

            return mat;
        }