diff --git a/main/Scene.h b/main/Scene.h index 231b2d2..b039683 100644 --- a/main/Scene.h +++ b/main/Scene.h @@ -90,6 +90,7 @@ class Scene /* private data */ std::vector< refptr > m_shapes; + std::vector< refptr > m_shape_definitions; std::vector< refptr > m_lights; std::stack m_transforms; double m_view_plane_dist; diff --git a/parser/nodes.h b/parser/nodes.h index 67d802c..eb61491 100644 --- a/parser/nodes.h +++ b/parser/nodes.h @@ -288,6 +288,18 @@ class SceneNode : public Node { }; +class ShapeDefinitionNode : public IdentifierNode +{ + public: + ShapeDefinitionNode(const std::string & str) : IdentifierNode(str) {} +}; + +class ShapeRefNode : public IdentifierNode +{ + public: + ShapeRefNode(const std::string & str) : IdentifierNode(str) {} +}; + class ShininessNode : public NumberNode { public: diff --git a/parser/parser.lex b/parser/parser.lex index 0b7130a..8b7aa95 100644 --- a/parser/parser.lex +++ b/parser/parser.lex @@ -68,6 +68,7 @@ reflectance return REFLECTANCE; rotate return ROTATE; scale return SCALE; scene return SCENE; +shape return SHAPE; shininess return SHININESS; size return SIZE; specular return SPECULAR; diff --git a/parser/parser.yy b/parser/parser.yy index 7c2414f..4eefaba 100644 --- a/parser/parser.yy +++ b/parser/parser.yy @@ -87,6 +87,7 @@ static refptr parsed_scene_node; %token ROTATE; %token SCALE; %token SCENE; +%token SHAPE; %token SHININESS; %token SIZE; %token SPECULAR; @@ -435,6 +436,7 @@ scene_item: camera { $$ = $1; } | light { $$ = $1; } | transform_block { $$ = $1; } | material_definition { $$ = $1; } + | shape_definition { $$ = $1; } ; shape: plane { $$ = $1; } @@ -445,8 +447,18 @@ shape: plane { $$ = $1; } | intersect { $$ = $1; } | subtract { $$ = $1; } | extrude { $$ = $1; } + | shape_ref { $$ = $1; } ; +shape_definition: DEFINE SHAPE IDENTIFIER shape { + $$ = new ShapeDefinitionNode($3->getString()); + $$->addChild($4); + } + ; + +shape_ref: SHAPE IDENTIFIER { $$ = new ShapeRefNode($2->getString()); } + ; + shape_item: material { $$ = $1; } | material_ref { $$ = $1; } | transform { $$ = $1; } @@ -522,6 +534,7 @@ transform_block_items: /* empty */ transform_block_item: transform_block { $$ = $1; } | light { $$ = $1; } | shape { $$ = $1; } + | shape_definition { $$ = $1; } ; union: UNION LCURLY bool_items RCURLY {