Пример #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;
            }
        }
Пример #2
0
        private void readWholeFile(StreamTokenizer lex, Scene scene)
        {
            while (!lex.EndOfStream)
            {
                while (lex.Word == "Transform")
                {
                    readTransformObject(lex, scene);
                }

                lex.NextWord();
            }
        }
Пример #3
0
        private void readTransformObject(StreamTokenizer lex, Scene scene)
        {
            int startLevel = lex.BracketLevel;
            while (!lex.EndOfStream)
            {
                lex.NextWord();
                // check to return immediately after reading word
                if (lex.BracketLevel <= startLevel)
                    return;

                // transform matrix
                Matrix ShapeMatrix = TransformMatrix;
                while (lex.Word == "Transform")
                {
                    // nested transforms
                    readTransformObject(lex, scene);
                }
                if (lex.Word == "translation")
                {
                    double tx = lex.ReadDouble();
                    double ty = lex.ReadDouble();
                    double tz = lex.ReadDouble();
                    ShapeMatrix = TransformMatrix.Translate(tx, ty, tz);
                }
                while (lex.Word == "Shape")
                {
                    readShapeObject(lex, scene, ShapeMatrix);
                }

                // must have chance to return immediately after returning,
                // because the word might be needed several levels higher
                if (lex.BracketLevel <= startLevel)
                    return;
            }
        }