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 glm::mat4& abs_transform){}
91 class VrmlSFNode :
public VrmlNode{
104 class VrmlGroup :
public VrmlSFNode{
108 virtual ~VrmlGroup();
110 void AddChild(VrmlNode* newChild){
111 children.push_back(newChild);
113 std::vector<VrmlNode*> GetChildren()
const{
return children; }
116 return (
int) children.size();
119 virtual std::ostream& ToString(std::ostream& str)
const;
121 virtual void PushVertices(std::vector<glm::vec3> &vert,
122 std::vector<glm::vec3> &col,
123 glm::mat4& abs_transform);
126 std::vector<VrmlNode*> children;
141 class VrmlTransform :
public VrmlGroup{
147 void SetTranslation(glm::vec3
const& vec){ translation=vec; }
148 glm::vec3 GetTranslation()
const {
return translation; }
150 void SetRotationAxis(glm::vec3
const& vec){ rotation_axis=vec; }
151 glm::vec3 GetRotationAxis()
const {
return rotation_axis; }
153 void SetRotationAngle(
float const& v){ rotation_angle=v; }
154 float GetRotationAngle()
const {
return rotation_angle; }
156 void SetScale(glm::vec3
const& vec){ scale=vec; }
157 glm::vec3 GetScale()
const {
return scale; }
159 virtual std::ostream& ToString(std::ostream& str)
const;
161 virtual void PushVertices(std::vector<glm::vec3> &vert,
162 std::vector<glm::vec3> &col,
163 glm::mat4& abs_transform);
167 glm::vec3 translation;
168 glm::vec3 rotation_axis;
169 float rotation_angle;
182 class VrmlMaterial:
public VrmlSFNode{
186 void SetDiffuseColor(glm::vec3
const& vec){ diffuseColor=vec; }
187 glm::vec3 GetDiffuseColor()
const {
return diffuseColor; }
189 void SetEmissiveColor(glm::vec3
const& vec){ emissiveColor=vec; }
190 glm::vec3 GetEmissiveColor()
const {
return emissiveColor; }
192 void SetSpecularColor(glm::vec3
const& vec){ specularColor=vec; }
193 glm::vec3 GetSpecularColor()
const {
return specularColor; }
195 void SetShininess(
float v){shininess = v; }
196 float GetShininess()
const{
return shininess;}
197 void SetTransparency(
float v){ transparency = v;}
198 float GetTransparency()
const{
return transparency;}
199 void SetAmbientIntensity(
float v){ ambientIntensity = v;}
200 float GetAmbientIntensity()
const{
return ambientIntensity;}
203 glm::vec3 diffuseColor;
204 glm::vec3 emissiveColor;
205 glm::vec3 specularColor;
208 float ambientIntensity;
221 class VrmlAppearance:
public VrmlSFNode{
227 void SetMaterial(VrmlMaterial* mat) { material = mat; }
228 VrmlMaterial& GetMaterial()
const{
return (*material); }
231 VrmlMaterial *material;
246 virtual ~VrmlGeometry(){}
248 virtual void PushVertices(std::vector<glm::vec3> &vert,
249 std::vector<glm::vec3> &col,
250 glm::mat4& abs_transform,
251 glm::vec3 curColor) = 0;
253 virtual std::ostream& ToString(std::ostream& str)
const =0;
262 class VrmlSphere :
public VrmlGeometry{
265 virtual ~VrmlSphere(){}
267 virtual void PushVertices(std::vector<glm::vec3> &vert,
268 std::vector<glm::vec3> &col,
269 glm::mat4& abs_transform,
272 virtual std::ostream& ToString(std::ostream& str)
const;
274 void SetRadius(
float r){radius = r;}
287 class VrmlCone :
public VrmlGeometry{
290 virtual ~VrmlCone(){}
292 virtual void PushVertices(std::vector<glm::vec3> &vert,
293 std::vector<glm::vec3> &col,
294 glm::mat4& abs_transform,
297 virtual std::ostream& ToString(std::ostream& str)
const;
299 void SetBottomRadius(
float r){bottomRadius = r;}
300 void SetHeight(
float h){height = h;}
312 class VrmlCylinder :
public VrmlGeometry{
315 virtual ~VrmlCylinder(){}
317 virtual void PushVertices(std::vector<glm::vec3> &vert,
318 std::vector<glm::vec3> &col,
319 glm::mat4& abs_transform,
322 virtual std::ostream& ToString(std::ostream& str)
const;
324 void SetRadius(
float r){radius = r;}
325 void SetHeight(
float h){height = h;}
337 class VrmlBox :
public VrmlGeometry{
342 virtual void PushVertices(std::vector<glm::vec3> &vert,
343 std::vector<glm::vec3> &col,
344 glm::mat4& abs_transform,
347 virtual std::ostream& ToString(std::ostream& str)
const;
349 void SetSize(glm::vec3
const& s){size = s;}
368 class VrmlIndexedFaceSet:
public VrmlGeometry{
371 VrmlIndexedFaceSet();
372 virtual ~VrmlIndexedFaceSet();
374 virtual std::ostream& ToString(std::ostream& str)
const;
376 virtual void PushVertices(std::vector<glm::vec3> &vert,
377 std::vector<glm::vec3> &col,
378 glm::mat4& abs_transform,
381 void SetSolid(
bool b){ solid = b;}
382 bool GetSolid() {
return solid;}
384 void SetNormalPerVertex(
bool b){ normalPerVertex = b;}
385 bool GetNormalPerVertex() {
return normalPerVertex;}
387 void SetColorPerVertex(
bool b){ colorPerVertex = b;}
388 bool GetColorPerVertex() {
return colorPerVertex;}
390 void SetCreaseAngle(
float v){ creaseAngle = v;}
391 float GetCreaseAngle() {
return creaseAngle;}
393 void SetVertexCoordInds(std::vector<std::vector<int> >& vec){ face_indices = vec;}
394 void SetNormalInds(std::vector<std::vector<int> >& vec){ normal_indices=vec; }
395 void SetColorInds(std::vector<int>& vec){ color_indices=vec; }
397 void SetVertexCoords(std::vector<glm::vec3>& vec){ vert_coords=vec;}
398 void SetNormals(std::vector<glm::vec3>& vec){ normals=vec; }
399 void SetColors(std::vector<glm::vec3>
const& vec){ colors=vec; }
403 bool normalPerVertex;
406 std::vector<glm::vec3> vert_coords;
407 std::vector<glm::vec3> normals;
408 std::vector<glm::vec3> colors;
409 std::vector<std::vector<int> > face_indices;
410 std::vector<std::vector<int> > normal_indices;
411 std::vector<int> color_indices;
425 class VrmlShape:
public VrmlSFNode{
427 virtual ~VrmlShape();
429 void SetGeometry(VrmlGeometry* geom){ geometry = geom; }
430 void SetAppearance(VrmlAppearance* app){ appearance = app; }
432 virtual void PushVertices(std::vector<glm::vec3> &vert,
433 std::vector<glm::vec3> &col,
434 glm::mat4& abs_transform);
436 virtual std::ostream& ToString(std::ostream& str)
const;
440 VrmlGeometry* geometry;
441 VrmlAppearance* appearance;
457 int ParseVRML(std::string vrml_file);
459 int PushVertices(std::vector<glm::vec3> &vert, std::vector<glm::vec3> &col);
462 VrmlGroup* ParseGroup();
463 VrmlTransform* ParseTransform();
464 VrmlShape* ParseShape();
465 VrmlAppearance* ParseAppearance();
466 VrmlMaterial* ParseMaterial();
467 VrmlSphere* ParseSphere();
468 VrmlCone* ParseCone();
469 VrmlCylinder* ParseCylinder();
471 VrmlIndexedFaceSet* ParseIndexedFaceSet();
472 void ParseChildren(VrmlGroup* group);
474 void SearchClosingBracket();
475 void ParseNode(VrmlGroup* group);
477 std::vector<glm::vec3>* ParseCoordinates();
478 std::vector<std::vector<int> >* ParseIndexListForFace();
479 std::vector<int>* ParseIndexListForPt();
482 void ParseIgnoredToken();
483 bool ParseBoolToken();
484 float ParseFloatToken();
486 glm::vec3 ParseFloatVec3();
488 void SkipToClosingBrac(
char openBrac,
char closingBrac);
490 void CheckSaveName();
491 void CheckOpeningBracket(
char brac);
493 void Error(
const char* message);
494 void Warning(
const char* message);
495 void EndParseElemMsg(
const char* node_type,
const char* add_msg);
496 void StartParseElemMsg(
const char* node_type,
const char* add_msg);
500 std::string vrml_file;
501 std::string cur_line;
514 #endif //_VRML_LOADER_HH_