Пример #1
0
        private void readShapeObject(StreamTokenizer lex, Scene scene, Matrix shapeMatrix)
        {
            int startLevel = lex.BracketLevel;
            List<Vector> shapeVertices = null;
            Material shapeMaterial = new Material(Color.Black, 0, 0);
            while (!lex.EndOfStream)
            {
                lex.NextWord();
                if (lex.BracketLevel <= startLevel)
                    return;

                if (lex.Word == "diffuseColor")
                {
                    double r = lex.ReadDouble();
                    double g = lex.ReadDouble();
                    double b = lex.ReadDouble();
                    shapeMaterial.Color = new Color(r, g, b, 1.0);
                }

                if (lex.Word == "transparency")
                {
                    Color shapeColor = shapeMaterial.Color;
                    shapeColor.A = 1 - lex.ReadDouble();
                    shapeMaterial.Color = shapeColor;
                }

                if (lex.Word == "shininess")
                {
                    shapeMaterial.Reflectance = lex.ReadDouble();
                    shapeMaterial.Specular = shapeMaterial.Reflectance;
                }

                if (lex.Word == "point")
                {
                    shapeVertices = readShapeVertices(lex);
                }

                if (lex.Word == "coordIndex")
                {
                    scene.addMaterial(shapeMaterial);
                    readPolygons(lex, scene, shapeVertices, shapeMaterial, shapeMatrix);
                }

                if (lex.BracketLevel <= startLevel)
                    return;
            }
        }