Ejemplo n.º 1
0
        private bool loadMaterials(Scene scene)
        {
            bool success = true;
            int nextToken = 0;
            bool haveNext = false;

            int materialCount;

            readBlockStart();

            if (scanner.yylex() != (int)TokenType.Node)
                Console.Error.WriteLine("Expected a node");
            if (!scanner.yytext.Equals("*MATERIAL_COUNT"))
                Console.Error.WriteLine("Expected a *MATERIAL_COUNT node");

            readInt(out materialCount);

            while (haveNext || (nextToken = scanner.yylex()) != (int)TokenType.BlockEnd)
            {
                if (nextToken != (int)TokenType.Node)
                {
                    Console.Error.WriteLine("Expected a node");
                }
                haveNext = false;

                if (scanner.yytext.Equals("*MATERIAL"))
                {
                    int m;
                    if (!readInt(out m))
                    {
                        success = false;
                        continue;
                    }
                    if (m >= materialCount)
                    {
                        Console.Error.WriteLine("File refered to non-existant submaterial");
                        continue;
                    }
                    Material material = new Material();
                    if (scene.materials == null) scene.materials = new List<Material>();
                    if (!loadMaterial(out material)) success = false;
                    scene.materials.Add(material);
                }
                else
                {
                    if ((nextToken = skip()) == (int)TokenType.BlockEnd || nextToken < 1) break;
                    haveNext = true;
                }
            }
            return success;
        }
Ejemplo n.º 2
0
        private bool loadMaterial(out Material material)
        {
            bool success = true;
            int nextToken = 0;
            bool haveNext = false;

            int numSubMaterials = 0;

            material = new Material();

            readBlockStart();

            while (haveNext || (nextToken = scanner.yylex()) != (int)TokenType.BlockEnd)
            {
                if (nextToken != (int)TokenType.Node)
                {
                    Console.Error.WriteLine("Expected a node");
                }
                haveNext = false;

                string str = scanner.yytext;
                if (str.Equals("*MATERIAL_NAME"))
                {
                    if (!readString(out material.name)) success = false;
                }
                else if (str.Equals("*MATERIAL_CLASS"))
                {
                    if (!readString(out material.matclass)) success = false;
                }
                else if (str.Equals("*MATERIAL_AMBIENT"))
                {
                    if (!readRGB(out material.ambient)) success = false;
                }
                else if (str.Equals("*MATERIAL_DIFFUSE"))
                {
                    if (!readRGB(out material.diffuse)) success = false;
                }
                else if (str.Equals("*MATERIAL_SPECULAR"))
                {
                    if (!readRGB(out material.specular)) success = false;
                }
                else if (str.Equals("*MATERIAL_SHINE"))
                {
                    if (!readFloat(out material.shine)) success = false;
                }
                else if (str.Equals("*MATERIAL_SHINESTRENGTH"))
                {
                    if (!readFloat(out material.shineStrength)) success = false;
                }
                else if (str.Equals("*MATERIAL_TRANSPARENCY"))
                {
                    if (!readFloat(out material.transparency)) success = false;
                }
                else if (str.Equals("*MATERIAL_WIRESIZE"))
                {
                    if (!readFloat(out material.wiresize)) success = false;
                }
                else if (str.Equals("*MATERIAL_SHADING"))
                {
                    if (!readSymbol(out material.shading)) success = false;
                }
                else if (str.Equals("*MATERIAL_XP_FALLOFF"))
                {
                    if (!readFloat(out material.xpFalloff)) success = false;
                }
                else if (str.Equals("*MATERIAL_SELFILLUM"))
                {
                    if (!readFloat(out material.selfIllum)) success = false;
                }
                else if (str.Equals("*MATERIAL_FALLOFF"))
                {
                    if (!readSymbol(out material.falloff)) success = false;
                }
                else if (str.Equals("*MATERIAL_XP_TYPE"))
                {
                    if (!readSymbol(out material.xpType)) success = false;
                }
                else if (str.Equals("*MAP_DIFFUSE"))
                {
                    if (!loadMaterialMap(out material.diffuseMaterialMap)) success = false;
                }
                else if (str.Equals("*NUMSUBMTLS"))
                {
                    if (!readInt(out numSubMaterials)) success = false;
                }
                else if (str.Equals("*SUBMATERIAL"))
                {
                    int which;
                    if (!readInt(out which))
                    {
                        success = false;
                        continue;
                    }
                    if (which >= numSubMaterials)
                    {
                        Console.Error.WriteLine("File refered to non-existant submaterial");
                        continue;
                    }
                    if (material.subMaterials == null) material.subMaterials = new List<Material>();
                    Material subMaterial = new Material();
                    if (!loadMaterial(out subMaterial)) success = false;
                    material.subMaterials.Add(subMaterial);
                }
                else
                {
                    if ((nextToken = skip()) == (int)TokenType.BlockEnd || nextToken < 1) break;
                    haveNext = true;
                }
            }
            return success;
        }