36 #ifndef _VRML_LOADER_HH_
37 #define _VRML_LOADER_HH_
41 #define deg2rad(x) x*(3.141592f/180.0f)
44 #ifndef GLM_FORCE_RADIANS
45 #define GLM_FORCE_RADIANS
71 void SetName(std::string n){}
73 virtual std::ostream& ToString(std::ostream& str)
const;
75 virtual void PushVertices(std::vector<glm::vec3> &vert,
76 std::vector<glm::vec3> &col,
77 std::vector<glm::vec3> &line_vert,
78 std::vector<glm::vec3> &line_col,
79 glm::mat4& abs_transform){}
93 class VrmlSFNode :
public VrmlNode{
106 class VrmlGroup :
public VrmlSFNode{
110 virtual ~VrmlGroup();
112 void AddChild(VrmlNode* newChild){
113 children.push_back(newChild);
115 std::vector<VrmlNode*> GetChildren()
const{
return children; }
118 return (
int) children.size();
121 virtual std::ostream& ToString(std::ostream& str)
const;
123 virtual void PushVertices(std::vector<glm::vec3> &vert,
124 std::vector<glm::vec3> &col,
125 std::vector<glm::vec3> &line_vert,
126 std::vector<glm::vec3> &line_col,
127 glm::mat4& abs_transform);
130 std::vector<VrmlNode*> children;
145 class VrmlTransform :
public VrmlGroup{
151 void SetTranslation(glm::vec3
const& vec){ translation=vec; }
152 glm::vec3 GetTranslation()
const {
return translation; }
154 void SetRotationAxis(glm::vec3
const& vec){ rotation_axis=vec; }
155 glm::vec3 GetRotationAxis()
const {
return rotation_axis; }
157 void SetRotationAngle(
float const& v){ rotation_angle=v; }
158 float GetRotationAngle()
const {
return rotation_angle; }
160 void SetScale(glm::vec3
const& vec){ scale=vec; }
161 glm::vec3 GetScale()
const {
return scale; }
163 virtual std::ostream& ToString(std::ostream& str)
const;
165 virtual void PushVertices(std::vector<glm::vec3> &vert,
166 std::vector<glm::vec3> &col,
167 std::vector<glm::vec3> &line_vert,
168 std::vector<glm::vec3> &line_col,
169 glm::mat4& abs_transform);
173 glm::vec3 translation;
174 glm::vec3 rotation_axis;
175 float rotation_angle;
188 class VrmlMaterial:
public VrmlSFNode{
192 void SetDiffuseColor(glm::vec3
const& vec){ diffuseColor=vec; }
193 glm::vec3 GetDiffuseColor()
const {
return diffuseColor; }
195 void SetEmissiveColor(glm::vec3
const& vec){ emissiveColor=vec; }
196 glm::vec3 GetEmissiveColor()
const {
return emissiveColor; }
198 void SetSpecularColor(glm::vec3
const& vec){ specularColor=vec; }
199 glm::vec3 GetSpecularColor()
const {
return specularColor; }
201 void SetShininess(
float v){shininess = v; }
202 float GetShininess()
const{
return shininess;}
203 void SetTransparency(
float v){ transparency = v;}
204 float GetTransparency()
const{
return transparency;}
205 void SetAmbientIntensity(
float v){ ambientIntensity = v;}
206 float GetAmbientIntensity()
const{
return ambientIntensity;}
209 glm::vec3 diffuseColor;
210 glm::vec3 emissiveColor;
211 glm::vec3 specularColor;
214 float ambientIntensity;
227 class VrmlAppearance:
public VrmlSFNode{
233 void SetMaterial(VrmlMaterial* mat) { material = mat; }
234 VrmlMaterial& GetMaterial()
const{
return (*material); }
237 VrmlMaterial *material;
252 virtual ~VrmlGeometry(){}
254 virtual void PushVertices(std::vector<glm::vec3> &vert,
255 std::vector<glm::vec3> &col,
256 std::vector<glm::vec3> &line_vert,
257 std::vector<glm::vec3> &line_col,
258 glm::mat4& abs_transform,
259 glm::vec3 curColor) = 0;
261 virtual std::ostream& ToString(std::ostream& str)
const =0;
270 class VrmlSphere :
public VrmlGeometry{
273 virtual ~VrmlSphere(){}
275 virtual void PushVertices(std::vector<glm::vec3> &vert,
276 std::vector<glm::vec3> &col,
277 std::vector<glm::vec3> &line_vert,
278 std::vector<glm::vec3> &line_col,
279 glm::mat4& abs_transform,
282 virtual std::ostream& ToString(std::ostream& str)
const;
284 void SetRadius(
float r){radius = r;}
297 class VrmlCone :
public VrmlGeometry{
300 virtual ~VrmlCone(){}
302 virtual void PushVertices(std::vector<glm::vec3> &vert,
303 std::vector<glm::vec3> &col,
304 std::vector<glm::vec3> &line_vert,
305 std::vector<glm::vec3> &line_col,
306 glm::mat4& abs_transform,
309 virtual std::ostream& ToString(std::ostream& str)
const;
311 void SetBottomRadius(
float r){bottomRadius = r;}
312 void SetHeight(
float h){height = h;}
324 class VrmlCylinder :
public VrmlGeometry{
327 virtual ~VrmlCylinder(){}
329 virtual void PushVertices(std::vector<glm::vec3> &vert,
330 std::vector<glm::vec3> &col,
331 std::vector<glm::vec3> &line_vert,
332 std::vector<glm::vec3> &line_col,
333 glm::mat4& abs_transform,
336 virtual std::ostream& ToString(std::ostream& str)
const;
338 void SetRadius(
float r){radius = r;}
339 void SetHeight(
float h){height = h;}
351 class VrmlBox :
public VrmlGeometry{
356 virtual void PushVertices(std::vector<glm::vec3> &vert,
357 std::vector<glm::vec3> &col,
358 std::vector<glm::vec3> &line_vert,
359 std::vector<glm::vec3> &line_col,
360 glm::mat4& abs_transform,
363 virtual std::ostream& ToString(std::ostream& str)
const;
365 void SetSize(glm::vec3
const& s){size = s;}
384 class VrmlIndexedFaceSet:
public VrmlGeometry{
387 VrmlIndexedFaceSet();
388 virtual ~VrmlIndexedFaceSet();
390 virtual std::ostream& ToString(std::ostream& str)
const;
392 virtual void PushVertices(std::vector<glm::vec3> &vert,
393 std::vector<glm::vec3> &col,
394 std::vector<glm::vec3> &line_vert,
395 std::vector<glm::vec3> &line_col,
396 glm::mat4& abs_transform,
399 void SetSolid(
bool b){ solid = b;}
400 bool GetSolid() {
return solid;}
402 void SetNormalPerVertex(
bool b){ normalPerVertex = b;}
403 bool GetNormalPerVertex() {
return normalPerVertex;}
405 void SetColorPerVertex(
bool b){ colorPerVertex = b;}
406 bool GetColorPerVertex() {
return colorPerVertex;}
408 void SetCreaseAngle(
float v){ creaseAngle = v;}
409 float GetCreaseAngle() {
return creaseAngle;}
411 void SetVertexCoordInds(std::vector<std::vector<int> >& vec){ face_indices = vec;}
412 void SetNormalInds(std::vector<std::vector<int> >& vec){ normal_indices=vec; }
413 void SetColorInds(std::vector<int>& vec){ color_indices=vec; }
415 void SetVertexCoords(std::vector<glm::vec3>& vec){ vert_coords=vec;}
416 void SetNormals(std::vector<glm::vec3>& vec){ normals=vec; }
417 void SetColors(std::vector<glm::vec3>
const& vec){ colors=vec; }
421 bool normalPerVertex;
424 std::vector<glm::vec3> vert_coords;
425 std::vector<glm::vec3> normals;
426 std::vector<glm::vec3> colors;
427 std::vector<std::vector<int> > face_indices;
428 std::vector<std::vector<int> > normal_indices;
429 std::vector<int> color_indices;
443 class VrmlIndexedLineSet:
public VrmlGeometry{
446 VrmlIndexedLineSet();
447 virtual ~VrmlIndexedLineSet();
449 virtual std::ostream& ToString(std::ostream& str)
const;
451 virtual void PushVertices(std::vector<glm::vec3> &vert,
452 std::vector<glm::vec3> &col,
453 std::vector<glm::vec3> &line_vert,
454 std::vector<glm::vec3> &line_col,
455 glm::mat4& abs_transform,
458 void SetColorPerVertex(
bool b){ colorPerVertex = b;}
459 bool GetColorPerVertex() {
return colorPerVertex;}
461 void SetVertexCoordInds(std::vector<std::vector<int> >& vec){ line_indices = vec;}
462 void SetColorInds(std::vector<int>& vec){ color_indices=vec; }
464 void SetVertexCoords(std::vector<glm::vec3>& vec){ vert_coords=vec;}
465 void SetColors(std::vector<glm::vec3>
const& vec){ colors=vec; }
469 std::vector<glm::vec3> vert_coords;
470 std::vector<glm::vec3> colors;
471 std::vector<std::vector<int> > line_indices;
472 std::vector<int> color_indices;
486 class VrmlShape:
public VrmlSFNode{
488 virtual ~VrmlShape();
490 void SetGeometry(VrmlGeometry* geom){ geometry = geom; }
491 void SetAppearance(VrmlAppearance* app){ appearance = app; }
493 virtual void PushVertices(std::vector<glm::vec3> &vert,
494 std::vector<glm::vec3> &col,
495 std::vector<glm::vec3> &line_vert,
496 std::vector<glm::vec3> &line_col,
497 glm::mat4& abs_transform);
499 virtual std::ostream& ToString(std::ostream& str)
const;
503 VrmlGeometry* geometry;
504 VrmlAppearance* appearance;
520 int ParseVRML(std::string vrml_file);
522 int PushVertices(std::vector<glm::vec3> &vert, std::vector<glm::vec3> &col,
523 std::vector<glm::vec3> &line_vert, std::vector<glm::vec3> &line_col);
526 VrmlGroup* ParseGroup();
527 VrmlTransform* ParseTransform();
528 VrmlShape* ParseShape();
529 VrmlAppearance* ParseAppearance();
530 VrmlMaterial* ParseMaterial();
531 VrmlSphere* ParseSphere();
532 VrmlCone* ParseCone();
533 VrmlCylinder* ParseCylinder();
535 VrmlIndexedFaceSet* ParseIndexedFaceSet();
536 VrmlIndexedLineSet* ParseIndexedLineSet();
537 void ParseChildren(VrmlGroup* group);
539 void SearchClosingBracket();
540 void ParseNode(VrmlGroup* group);
542 std::vector<glm::vec3>* ParseCoordinates();
543 std::vector<std::vector<int> >* ParseIndexListForFace();
544 std::vector<int>* ParseIndexListForPt();
547 void ParseIgnoredToken();
548 bool ParseBoolToken();
549 float ParseFloatToken();
551 glm::vec3 ParseFloatVec3();
553 void SkipToClosingBrac(
char openBrac,
char closingBrac);
555 void CheckSaveName();
556 void CheckOpeningBracket(
char brac);
558 void Error(
const char* message);
559 void Warning(
const char* message);
560 void EndParseElemMsg(
const char* node_type,
const char* add_msg);
561 void StartParseElemMsg(
const char* node_type,
const char* add_msg);
565 std::string vrml_file;
566 std::string cur_line;
579 #endif //_VRML_LOADER_HH_