added material definitions to parser
git-svn-id: svn://anubis/fart/trunk@177 7f9b0f55-74a9-4bce-be96-3c2cd072584d
This commit is contained in:
parent
56a5fa6166
commit
fce4d82a73
@ -5,6 +5,7 @@
|
||||
#include "util/refptr.h"
|
||||
#include "util/Vector.h"
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
class Node
|
||||
{
|
||||
@ -21,6 +22,7 @@ class Node
|
||||
return refptr<Vector>(NULL);
|
||||
}
|
||||
virtual bool isShape() { return false; }
|
||||
virtual std::string getString() { return ""; }
|
||||
|
||||
protected:
|
||||
std::vector< refptr<Node> > m_children;
|
||||
@ -99,6 +101,18 @@ class HeightNode : public IntegerNode
|
||||
HeightNode(int i) : IntegerNode(i) {}
|
||||
};
|
||||
|
||||
class IdentifierNode : public Node
|
||||
{
|
||||
public:
|
||||
IdentifierNode(const std::string & str) { m_string = str; }
|
||||
std::string getString()
|
||||
{
|
||||
return m_string;
|
||||
}
|
||||
protected:
|
||||
std::string m_string;
|
||||
};
|
||||
|
||||
class IntersectNode : public Node
|
||||
{
|
||||
public:
|
||||
@ -123,6 +137,18 @@ class MaterialNode : public Node
|
||||
{
|
||||
};
|
||||
|
||||
class MaterialDefinitionNode : public IdentifierNode
|
||||
{
|
||||
public:
|
||||
MaterialDefinitionNode(const std::string & str) : IdentifierNode(str) {}
|
||||
};
|
||||
|
||||
class MaterialRefNode : public IdentifierNode
|
||||
{
|
||||
public:
|
||||
MaterialRefNode(const std::string & str) : IdentifierNode(str) {}
|
||||
};
|
||||
|
||||
class MultisampleNode : public IntegerNode
|
||||
{
|
||||
public:
|
||||
|
@ -44,6 +44,7 @@ box return BOX;
|
||||
camera return CAMERA;
|
||||
color return COLOR;
|
||||
cyl return CYL;
|
||||
define return DEFINE;
|
||||
diffuse return DIFFUSE;
|
||||
height return HEIGHT;
|
||||
intersect return INTERSECT;
|
||||
@ -70,6 +71,11 @@ up return UP;
|
||||
vfov return VFOV;
|
||||
width return WIDTH;
|
||||
|
||||
[a-zA-Z_][a-zA-Z_0-9]* {
|
||||
*yylval = new IdentifierNode(yytext);
|
||||
return IDENTIFIER;
|
||||
}
|
||||
|
||||
\n yylloc->first_line++; yylloc->last_line++;
|
||||
[ \t\v] /* ignore whitespace */
|
||||
|
||||
|
@ -63,6 +63,7 @@ static refptr<Node> parsed_scene_node;
|
||||
%token CAMERA;
|
||||
%token COLOR;
|
||||
%token CYL;
|
||||
%token DEFINE;
|
||||
%token DIFFUSE;
|
||||
%token HEIGHT;
|
||||
%token INTERSECT;
|
||||
@ -89,6 +90,8 @@ static refptr<Node> parsed_scene_node;
|
||||
%token VFOV;
|
||||
%token WIDTH;
|
||||
|
||||
%token IDENTIFIER;
|
||||
|
||||
%%
|
||||
|
||||
scene: SCENE LCURLY scene_items RCURLY {
|
||||
@ -236,6 +239,17 @@ material_item: COLOR vector {
|
||||
}
|
||||
;
|
||||
|
||||
material_definition: MATERIAL IDENTIFIER LCURLY material_items RCURLY {
|
||||
$$ = new MaterialDefinitionNode($2->getString());
|
||||
$$->addChildren($3);
|
||||
}
|
||||
;
|
||||
|
||||
material_ref: MATERIAL IDENTIFIER {
|
||||
$$ = new MaterialRefNode($2->getString());
|
||||
}
|
||||
;
|
||||
|
||||
number: DEC_NUMBER { $$ = $1; }
|
||||
| REAL_NUMBER { $$ = $1; }
|
||||
;
|
||||
@ -303,6 +317,7 @@ scene_item: camera { $$ = $1; }
|
||||
| options { $$ = $1; }
|
||||
| light { $$ = $1; }
|
||||
| transform_block { $$ = $1; }
|
||||
| material_definition { $$ = $1; }
|
||||
;
|
||||
|
||||
shape: plane { $$ = $1; }
|
||||
@ -323,6 +338,7 @@ shape_items: /* empty */
|
||||
;
|
||||
|
||||
shape_item: material { $$ = $1; }
|
||||
| material_ref { $$ = $1; }
|
||||
| transform { $$ = $1; }
|
||||
;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user