H3D API  2.4.1
IndexedTriangleSet.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 __INDEXEDTRIANGLESET_H__
30 #define __INDEXEDTRIANGLESET_H__
31 
34 #include <H3D/X3DCoordinateNode.h>
35 #include <H3D/X3DColorNode.h>
37 #include <H3D/CoordBoundField.h>
38 #include <H3D/MFInt32.h>
39 #include <H3D/SFInt32.h>
40 
41 
42 namespace H3D {
43 
78  class H3DAPI_API IndexedTriangleSet : public X3DComposedGeometryNode {
79  public:
80 
84 
88 
91 
98 
99  class H3DAPI_API AutoNormal:
100  public TypedField< SFNormalNode,
101  Types< SFBool, SFCoordinateNode, MFInt32, SFBool > > {
104  virtual void update();
105 
122  virtual X3DNormalNode *generateNormalsPerVertex(
123  X3DCoordinateNode *_coord,
124  const vector< int > &index,
125  bool _ccw );
126 
127 
144  virtual X3DNormalNode *generateNormalsPerFace(
145  X3DCoordinateNode *_coord,
146  const vector< int > &index,
147  bool _ccw );
148 
149  };
150 
160 
161  class H3DAPI_API AutoTangent:
162  public TypedField< MFVertexAttributeNode,
163  Types< SFBool, SFCoordinateNode, MFInt32, SFTextureCoordinateNode > > {
164 
167  virtual void update();
168 
175  virtual void generateTangentsPerVertex(
176  X3DCoordinateNode *_coord,
177  X3DTextureCoordinateNode *tex_coord,
178  const vector< int > &index,
179  FloatVertexAttribute *tangent,
180  FloatVertexAttribute *binormal
181  );
182 
183 
190  virtual void generateTangentsPerFace(
191  X3DCoordinateNode *_coord,
192  X3DTextureCoordinateNode *tex_coord,
193  const vector< int > &index,
194  FloatVertexAttribute *tangent,
195  FloatVertexAttribute *binormal );
196 
200  Vec3f getTexCoord( X3DCoordinateNode *_coord,
201  X3DTextureCoordinateNode *tex_coord,
202  int index );
203 
208  void calculateTangent( const Vec3f &a, const Vec3f &b, const Vec3f &c,
209  const Vec3f &ta, const Vec3f &tb, const Vec3f &tc,
210  Vec3f &tangent, Vec3f &binormal );
211 
212  };
213 
214  class SFInt32InstanceCount : public OnValueChangeSField< SFInt32 > {
215  protected:
216  virtual void onValueChange (const H3DInt32 &new_value) {
217  IndexedTriangleSet * its = static_cast< IndexedTriangleSet * >(getOwner());
218  if( new_value >= 0 ) {
219  if( its->displayList->getCacheMode() != H3DDisplayListObject::DisplayList::OFF ) {
221  }
222  } else {
223  if( its->displayList->getCacheMode() != H3DDisplayListObject::DisplayList::OPTIONS ) {
225  }
226  }
227  }
228  };
229 
231  IndexedTriangleSet( Inst< SFNode > _metadata = 0,
232  Inst< SFBound > _bound = 0,
233  Inst< DisplayList > _displayList = 0,
234  Inst< SFColorNode > _color = 0,
235  Inst< SFCoordinateNode > _coord = 0,
236  Inst< SFNormalNode > _normal = 0,
237  Inst< SFTextureCoordinateNode > _texCoord = 0,
238  Inst< SFBool > _ccw = 0,
239  Inst< SFBool > _colorPerVertex = 0,
240  Inst< SFBool > _normalPerVertex = 0,
241  Inst< SFBool > _solid = 0,
242  Inst< MFVertexAttributeNode > _attrib = 0,
243  Inst< AutoNormal > _autoNormal = 0,
244  Inst< MFInt32 > _set_index = 0,
245  Inst< MFInt32 > _index = 0,
246  Inst< SFFogCoordinate > _fogCoord = 0,
247  Inst< SFInt32InstanceCount > _instanceCount = 0 );
248 
250  virtual ~IndexedTriangleSet();
251 
252  // Traverse the scenegraph. See X3DGeometryNode::traverseSG
253  // for more info.
254  virtual void traverseSG( TraverseInfo &ti );
255 
257  virtual void render();
258 
260  virtual int nrTriangles() {
261  return index->size() / 3;
262  }
263 
268  virtual bool supportsTangentAttributes() {
269  return true;
270  }
271 
273  void setRenderPatches( bool _renderPatches ) {
274  render_patches = _renderPatches;
275  }
276 
279  return render_patches;
280  }
281 
282  virtual void glRender() {
283  bool previous_allow = allowingCulling();
284  bool prev_draw = draw_debug_options;
285  allowCulling( false );
286  draw_debug_options = false;
287  bool prev_patches = getRenderPatches();
288  if( prev_patches ) {
289  setRenderPatches( false );
290  render();
291  setRenderPatches( prev_patches );
292  } else
293  displayList->callList( false );
294 
295  draw_debug_options = prev_draw;
296  allowCulling( previous_allow );
297  }
298 
303  H3DUniquePtr< AutoNormal > autoNormal;
304 
309  H3DUniquePtr< AutoTangent > autoTangent;
310 
315  H3DUniquePtr< MFInt32 > set_index;
316 
327  H3DUniquePtr< MFInt32 > index;
328 
340  H3DUniquePtr< SFInt32InstanceCount > instanceCount;
341 
344  protected:
348 
355 
358  H3DUniquePtr< Field > vboFieldsUpToDate;
359  // The index for the vertex buffer object
360  GLuint *vbo_id;
361 
362  };
363 }
364 
365 #endif
Header file for CoordBoundField, specialiced field class.
Contains the DependentSFNode and DependentMFNode template classes.
Header file for FloatVertexAttribute.
Contains the MFInt32 field class.
Contains the SFInt32 field class.
Header file for X3DColorNode, X3D scene-graph node.
Header file for X3DComposedGeometryNode, X3D scene-graph node.
Header file for X3DCoordinateNode, 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
@ OFF
Caching is off.
Definition: H3DDisplayListObject.h:95
@ OPTIONS
Caching is depending on the GraphicalRenderingOptions in use.
Definition: H3DDisplayListObject.h:97
H3DUniquePtr< DisplayList > displayList
The DisplayList instance handling the OpenGL caching of this object.
Definition: H3DDisplayListObject.h:256
Specialized field for automatically generating normals from coordinates.
Definition: IndexedTriangleSet.h:101
Specialized field for automatically generating two FloatVertexAttribute nodes representing the tangen...
Definition: IndexedTriangleSet.h:163
Thrown if the number of colors in the color field is less than the number coordinates in the coord fi...
Definition: IndexedTriangleSet.h:83
Thrown if the number of texture coordinates in the color field is less than the number coordinates in...
Definition: IndexedTriangleSet.h:87
The IndexedTriangleSet node represents a 3D shape composed of a collection of individual triangles.
Definition: IndexedTriangleSet.h:78
virtual void glRender()
Function overridden from HAPIGLShape.
Definition: IndexedTriangleSet.h:282
H3DUniquePtr< MFInt32 > index
The index field is used to specify the vertices of each triangle from the coord field.
Definition: IndexedTriangleSet.h:327
H3DUniquePtr< Field > vboFieldsUpToDate
Internal field used to know if vertex buffer object can be created.
Definition: IndexedTriangleSet.h:358
bool getRenderPatches()
Returns true if rendering using patches for tessellation is enabled.
Definition: IndexedTriangleSet.h:278
H3DUniquePtr< MFInt32 > set_index
Field for setting the value of the index field.
Definition: IndexedTriangleSet.h:315
virtual int nrTriangles()
The number of triangles renderered in this geometry.
Definition: IndexedTriangleSet.h:260
virtual bool supportsTangentAttributes()
Returns true if this geometry supports the automatic generation of tangents and binormals as FloatVer...
Definition: IndexedTriangleSet.h:268
CoordBoundField SFBound
The bound field for IndexedFaceSet is a CoordBoundField.
Definition: IndexedTriangleSet.h:90
H3DUniquePtr< AutoTangent > autoTangent
Auto-generated vertex attributes for tangents and binormals.
Definition: IndexedTriangleSet.h:309
H3DUniquePtr< AutoNormal > autoNormal
Auto-generated normals that are used if the normal field is NULL.
Definition: IndexedTriangleSet.h:303
void setRenderPatches(bool _renderPatches)
Explicitly enable or disable the rendering of patches for tessellation.
Definition: IndexedTriangleSet.h:273
static H3DNodeDatabase database
The H3DNodeDatabase for this node.
Definition: IndexedTriangleSet.h:343
bool render_tangents
This will be set to true in traverseSG if the render function is supposed to render tangent vertex at...
Definition: IndexedTriangleSet.h:347
H3DUniquePtr< SFInt32InstanceCount > instanceCount
If 0 or greater, then instanced rendering is used to render instanceCount instances of the mesh.
Definition: IndexedTriangleSet.h:340
bool render_patches
This will be set to true in traverseSG if the render function is supposed to render GL_PATCHES instea...
Definition: IndexedTriangleSet.h:354
Template for adding the virtual function onValueChange that can be overridden in subclasses in order ...
Definition: FieldTemplates.h:49
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
int H3DInt32
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