H3D API  2.4.1
IndexedFaceSet.h
Go to the documentation of this file.
1 // Copyright 2004-2019, SenseGraphics AB
3 //
4 // This file is part of H3D API.
5 //
6 // H3D API is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
10 //
11 // H3D API is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with H3D API; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 //
20 // A commercial license is also available. Please contact us at
21 // www.sensegraphics.com for more information.
22 //
23 //
27 //
29 #ifndef __INDEXEDFACESET_H__
30 #define __INDEXEDFACESET_H__
31 
33 #include <H3D/CoordBoundField.h>
35 #include <H3D/MFInt32.h>
36 #include <H3D/SFFloat.h>
37 
38 namespace H3D {
39 
162  class H3DAPI_API IndexedFaceSet :
163  public X3DComposedGeometryNode {
164  public:
165  H3D_VALUE_EXCEPTION( int, InvalidTexCoordIndex );
166  H3D_VALUE_EXCEPTION( int, InvalidNormalIndex );
167  H3D_VALUE_EXCEPTION( int, InvalidColorIndex );
168 
182 
183  class H3DAPI_API AutoNormal:
184  public TypedField< SFNormalNode,
185  Types< SFBool,
186  SFCoordinateNode,
187  MFInt32,
188  SFBool,
189  SFFloat > > {
190  virtual void update();
191 
192  public:
216  virtual X3DNormalNode *generateNormalsPerVertex(
217  X3DCoordinateNode *_coord,
218  const vector< int > &coord_index,
219  bool _ccw,
220  H3DFloat crease_angle );
221 
237  virtual X3DNormalNode *generateNormalsPerVertex(
238  X3DCoordinateNode *_coord,
239  const vector< int > &coord_index,
240  bool _ccw );
241 
258  virtual X3DNormalNode *generateNormalsPerFace(
259  X3DCoordinateNode *_coord,
260  const vector< int > &coord_index,
261  bool _ccw );
262 
263  };
264 
265 
278 
279  class H3DAPI_API AutoTangent:
280  public TypedField< MFVertexAttributeNode,
281  Types< SFBool, SFCoordinateNode, MFInt32, SFTextureCoordinateNode, MFInt32, SFFloat, SFBool > > {
282 
285  virtual void update();
286  public:
298  virtual void generateTangentsPerVertex(
299  X3DCoordinateNode *_coord,
300  X3DTextureCoordinateNode *tex_coord,
301  const vector< int > &coord_index,
302  const vector< int > &tex_coord_index,
303  FloatVertexAttribute *tangent,
304  FloatVertexAttribute *binormal
305  );
306 
331  virtual void generateTangentsPerVertex(
332  X3DCoordinateNode *_coord,
333  X3DTextureCoordinateNode *tex_coord,
334  const vector< int > &coord_index,
335  const vector< int > &tex_coord_index,
336  H3DFloat crease_angle,
337  bool _ccw,
338  FloatVertexAttribute *tangent,
339  FloatVertexAttribute *binormal
340  );
341 
355  virtual void generateTangentsPerFace(
356  X3DCoordinateNode *_coord,
357  X3DTextureCoordinateNode *tex_coord,
358  const vector< int > &coord_index,
359  const vector< int > &tex_coord_index,
360  bool normalize_values,
361  FloatVertexAttribute *tangent,
362  FloatVertexAttribute *binormal );
363 
367  Vec3f getTexCoord( X3DCoordinateNode *_coord,
368  X3DTextureCoordinateNode *tex_coord,
369  int index );
370 
375  void calculateTangent( const Vec3f &a, const Vec3f &b, const Vec3f &c,
376  const Vec3f &ta, const Vec3f &tb, const Vec3f &tc,
377  Vec3f &tangent, Vec3f &binormal );
378 
379  };
380 
383 
385  IndexedFaceSet( Inst< SFNode > _metadata = 0,
386  Inst< SFBound > _bound = 0,
387  Inst< DisplayList > _displayList = 0,
388  Inst< SFColorNode > _color = 0,
389  Inst< SFCoordinateNode > _coord = 0,
390  Inst< SFNormalNode > _normal = 0,
391  Inst< SFTextureCoordinateNode > _texCoord = 0,
392  Inst< SFBool > _ccw = 0,
393  Inst< SFBool > _colorPerVertex = 0,
394  Inst< SFBool > _normalPerVertex = 0,
395  Inst< SFBool > _solid = 0,
396  Inst< MFVertexAttributeNode > _attrib = 0,
397  Inst< AutoNormal > _autoNormal = 0,
398  Inst< SFBool > _convex = 0,
399  Inst< SFFloat > _creaseAngle = 0,
400  Inst< MFInt32 > _set_colorIndex = 0,
401  Inst< MFInt32 > _set_coordIndex = 0,
402  Inst< MFInt32 > _set_normalIndex = 0,
403  Inst< MFInt32 > _set_texCoordIndex = 0,
404  Inst< MFInt32 > _colorIndex = 0,
405  Inst< MFInt32 > _coordIndex = 0,
406  Inst< MFInt32 > _normalIndex = 0,
407  Inst< MFInt32 > _texCoordIndex = 0,
408  Inst< SFFogCoordinate > _fogCoord = 0);
409 
410  virtual X3DCoordinateNode *getCoord() {
411  return static_cast< X3DCoordinateNode * >( coord->getValue() );
412  }
413 
415  virtual void render();
416 
418  virtual int nrTriangles() {
419  return coordIndex->size();
420  }
421 
422  // Traverse the scenegraph. See X3DGeometryNode::traverseSG
423  // for more info.
424  virtual void traverseSG( TraverseInfo &ti );
425 
430  virtual bool supportsTangentAttributes() {
431  return true;
432  }
433 
438  H3DUniquePtr< MFInt32 > set_colorIndex;
439 
444  H3DUniquePtr< MFInt32 > set_coordIndex;
445 
450  H3DUniquePtr< MFInt32 > set_normalIndex;
451 
456  H3DUniquePtr< MFInt32 > set_texCoordIndex;
457 
466  H3DUniquePtr< MFInt32 > colorIndex;
467 
478  H3DUniquePtr< SFBool > convex;
479 
488  H3DUniquePtr< MFInt32 > coordIndex;
489 
502  H3DUniquePtr< SFFloat > creaseAngle;
503 
512  H3DUniquePtr< MFInt32 > normalIndex;
513 
522  H3DUniquePtr< MFInt32 > texCoordIndex;
523 
528  H3DUniquePtr< AutoNormal > autoNormal;
529 
534  H3DUniquePtr< AutoTangent > autoTangent;
535 
538 
539  protected:
543  };
544 }
545 
546 #endif
Header file for CoordBoundField, specialiced field class.
Header file for FloatVertexAttribute.
Contains the MFInt32 field class.
Contains the SFFloat field class.
Header file for X3DComposedGeometryNode, X3D scene-graph node.
The CoordBoundField is specialized update itself from a X3DCoordinateNode.
Definition: CoordBoundField.h:43
The FloatVertexAttribute node defines a set of per-vertex single precision floating point attributes.
Definition: FloatVertexAttribute.h:56
Specialized field for automatically generating normals from coordinates.
Definition: IndexedFaceSet.h:189
Specialized field for automatically generating two FloatVertexAttribute nodes representing the tangen...
Definition: IndexedFaceSet.h:281
The IndexedFaceSet node represents a 3D shape formed by constructing faces (polygons) from vertices l...
Definition: IndexedFaceSet.h:163
H3DUniquePtr< MFInt32 > texCoordIndex
Indices into the texCoord field.
Definition: IndexedFaceSet.h:522
bool render_tangents
This will be set to true in traverseSG if the render function is supposed to render tangent vertex at...
Definition: IndexedFaceSet.h:542
H3DUniquePtr< MFInt32 > set_coordIndex
Field for setting the value of the coordIndex field.
Definition: IndexedFaceSet.h:444
H3DUniquePtr< SFFloat > creaseAngle
The creaseAngle field affects how default normals are generated.
Definition: IndexedFaceSet.h:502
static H3DNodeDatabase database
The H3DNodeDatabase for this node.
Definition: IndexedFaceSet.h:537
CoordBoundField SFBound
The bound field for IndexedFaceSet is a CoordBoundField.
Definition: IndexedFaceSet.h:382
H3DUniquePtr< MFInt32 > normalIndex
Indices into the normal field.
Definition: IndexedFaceSet.h:512
H3DUniquePtr< AutoNormal > autoNormal
Auto-generated normals that are used if the normal field is NULL.
Definition: IndexedFaceSet.h:528
H3DUniquePtr< MFInt32 > coordIndex
Indices into the coord field.
Definition: IndexedFaceSet.h:488
virtual int nrTriangles()
An upper bound on the number of triangles.
Definition: IndexedFaceSet.h:418
H3DUniquePtr< MFInt32 > set_colorIndex
Field for setting the value of the colorIndex field.
Definition: IndexedFaceSet.h:438
H3DUniquePtr< MFInt32 > set_normalIndex
Field for setting the value of the normalIndex field.
Definition: IndexedFaceSet.h:450
H3DUniquePtr< MFInt32 > set_texCoordIndex
Field for setting the value of the texCoordIndex field.
Definition: IndexedFaceSet.h:456
H3DUniquePtr< AutoTangent > autoTangent
Auto-generated vertex attributes for tangents and binormals.
Definition: IndexedFaceSet.h:534
virtual bool supportsTangentAttributes()
Returns true if this geometry supports the automatic generation of tangents and binormals as FloatVer...
Definition: IndexedFaceSet.h:430
H3DUniquePtr< MFInt32 > colorIndex
Indices into the color field.
Definition: IndexedFaceSet.h:466
H3DUniquePtr< SFBool > convex
The convex field indicates whether all polygons in the shape are convex.
Definition: IndexedFaceSet.h:478
TraverseInfo is a structure that is passed along when traversing the scene graph.
Definition: TraverseInfo.h:57
A template modifier class for adding type checking on the routes to any Field class.
Definition: TypedField.h:84
This is the base node type for all composed 3D geometry in X3D.
Definition: X3DComposedGeometryNode.h:93
This is the base node type for all coordinate node types in X3D.
Definition: X3DCoordinateNode.h:47
This is the base node type for all normal node types in X3D.
Definition: X3DNormalNode.h:45
This abstract node type is the base type for all node types which specify texture coordinates.
Definition: X3DTextureCoordinateNode.h:55
float H3DFloat
H3D_VALUE_EXCEPTION(string, InvalidType)
An exception thrown when a field is of the wrong type when it is checked.
H3D API namespace.
Definition: Anchor.h:38
The H3DNodeDatabase contains a mapping between a name of a Node and the constructor for the Node with...
Definition: H3DNodeDatabase.h:194