H3D API  2.4.1
X3DShapeNode.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 __X3DSHAPENODE_H__
30 #define __X3DSHAPENODE_H__
31 
32 #include <H3D/X3DChildNode.h>
33 #include <H3D/X3DBoundedObject.h>
34 #include <H3D/X3DAppearanceNode.h>
35 #include <H3D/X3DGeometryNode.h>
39 
40 namespace H3D {
47  class H3DAPI_API X3DShapeNode :
48  public X3DChildNode,
49  public X3DBoundedObject,
50  public H3DDisplayListObject {
51  public:
59  true >
61 
64 
73  public DependentSFNode< X3DGeometryNode,
74  FieldRef< H3DDisplayListObject,
75  H3DDisplayListObject::DisplayList,
76  &H3DDisplayListObject::displayList >, true > {
81  public:
82 
85  owner( NULL ) {}
86 
89  virtual ~SFGeometryNode() {
90  value = NULL;
91  }
92 
99  virtual void onAdd( Node *n ) {
100  BaseField::onAdd( n );
101  if( n && owner->use_geometry_bound ) {
102  X3DGeometryNode *g = static_cast< X3DGeometryNode * >( n );
103  g->bound->route( owner->bound );
104  }
105  }
106 
113  virtual void onRemove( Node *n ) {
114  BaseField::onRemove( n );
115  if( n && owner->use_geometry_bound ) {
116  X3DGeometryNode *g = static_cast< X3DGeometryNode * >( n );
117  g->bound->unroute( owner->bound );
118  }
119  }
120 
121  // the shape node that the instance of the SFGeometry field
122  // is in.
123  X3DShapeNode *owner;
124 
125  };
126 
132  class H3DAPI_API BugWorkaroundDisplayList:
139  virtual bool haveValidDisplayList();
140  };
141 
143  class H3DAPI_API DisplayList: public BugWorkaroundDisplayList {
144  public:
146  virtual void callList( bool build_list = true );
147  };
148 
149 
151 
153  X3DShapeNode( Inst< SFAppearanceNode > _appearance = 0,
154  Inst< SFGeometryNode > _geometry = 0,
155  Inst< SFHapticGeometry > _hapticGeometry = 0,
156  Inst< SFNode > _metadata = 0,
157  Inst< SFBound > _bound = 0,
158  Inst< SFVec3f > _bboxCenter = 0,
159  Inst< SFVec3f > _bboxSize = 0,
160  Inst< DisplayList > _displayList = 0
161  );
162 
167  virtual void initialize() {
168  const Vec3f &size = bboxSize->getValue();
169  if( size.x == -1 && size.y == -1 && size.z == -1 ) {
170  use_geometry_bound = true;
171  X3DGeometryNode *g =
172  static_cast< X3DGeometryNode * >( geometry->getValue() );
173  if( g ) {
174  g->bound->route( this->bound );
175  }
176  } else {
177  BoxBound *bb = new BoxBound();
178  bb->center->setValue( bboxCenter->getValue() );
179  bb->size->setValue( bboxSize->getValue() );
180  bound->setValue( bb );
181  }
183  }
184 
186  virtual void render();
187 
189  virtual void traverseSG( TraverseInfo &ti );
190 
198  virtual bool lineIntersect(
199  const Vec3f &from,
200  const Vec3f &to,
201  LineIntersectResult &result );
202 
208  virtual void closestPoint( const Vec3f &p,
209  NodeIntersectResult &result );
210 
219  virtual bool movingSphereIntersect( H3DFloat radius,
220  const Vec3f &from,
221  const Vec3f &to,
222  NodeIntersectResult &result );
223 
225  typedef enum {
235  ALL
236  } GeometryRenderMode;
237 
238  static GeometryRenderMode geometry_render_mode;
239 
246  H3DUniquePtr< SFAppearanceNode > appearance;
247 
253  H3DUniquePtr< SFGeometryNode > geometry;
254 
261  H3DUniquePtr< SFHapticGeometry > hapticGeometry;
262 
271  H3DUniquePtr< SFShadowObjectNode > shadowVolume;
272 
273  // if true a route will be set up between the bound field of the
274  // geometry node in this field and the bound field of the shape.
275  bool use_geometry_bound;
276 
279 
285  protected:
286 
287  // Adress of traverseInfo
288  // only interested in adress, what it points to will be invalid.
289  // It is needed to correctly set traverse_multipass_transparency
290  // if a X3DShapeNode is used in several places in the scene graph.
291  TraverseInfo *prev_travinfoadr;
292  // If the node is in several places in the scene graph it might
293  // use different values for setting multipass transparency in
294  // traverseSG. The last one is the one that will be used. This
295  // stores values during a traverseSG pass and "or" it with
296  // new values. If any of the pass returns true then multipass
297  // transparency should be used.
298  bool traverse_multipass_transparency;
299 
300  // The GlobalSettings node that was in used in last call to
301  // traverseSG
302  AutoRef<Node> last_global_settings;
303  };
304 }
305 
306 #endif
Contains the DependentSFNode and DependentMFNode template classes.
Header file for H3DDisplayListObject.
Header file for H3DShadowObjectNode.
Header file for X3DAppearanceNode, X3D scene-graph node.
Header file for X3DBoundedObject.
Header file for X3DChildNode, X3D scene-graph node.
Header file for X3DGeometryNode, X3D scene-graph node.
virtual void initialize()
The BoxBound is a Bound class that specifies the bound using an axis-aligned bounding box.
Definition: Bound.h:144
H3DUniquePtr< SFVec3f > center
The center point of the bounding box.
Definition: Bound.h:285
H3DUniquePtr< SFVec3f > size
The size of the bounding box.
Definition: Bound.h:287
DependentSFNode are modified TypedSFNode fields where the field dirty status is dependent on fields i...
Definition: DependentNodeFields.h:294
Class used for specifying a field member of a node in a DependentSFNode or DependentMFNode specificat...
Definition: DependentNodeFields.h:48
H3DUniquePtr< SFBound > bound
The field containing the bound object.
Definition: H3DBoundedObject.h:59
We use the Field's lazy evaluation mechanisms to manage the GL display lists for rendering,...
Definition: H3DDisplayListObject.h:60
This abstract interface class is the base class for all node types that wants to create an OpenGL dis...
Definition: H3DDisplayListObject.h:54
H3DUniquePtr< DisplayList > displayList
The DisplayList instance handling the OpenGL caching of this object.
Definition: H3DDisplayListObject.h:256
Node is the base class for all classes that can be part of the H3D scene-graph.
Definition: Node.h:46
TraverseInfo is a structure that is passed along when traversing the scene graph.
Definition: TraverseInfo.h:57
This is the base node type for all Appearance nodes.
Definition: X3DAppearanceNode.h:44
This X3D abstract interface type is basis for all X3D node types that have bounds specified as part o...
Definition: X3DBoundedObject.h:46
This abstract node type indicates that the concrete nodes which are instantiated based on it may be u...
Definition: X3DChildNode.h:42
This is the base node type for all geometry in X3D.
Definition: X3DGeometryNode.h:61
This is just a dummy class to get around a bug in Visual C++ 7.1 If the X3DGeometry::DisplayList inhe...
Definition: X3DShapeNode.h:133
Display list is extended in.
Definition: X3DShapeNode.h:143
SFGeometryNode is dependent on the displayList field of its encapsulated X3DGeometryNode node,...
Definition: X3DShapeNode.h:76
virtual void onAdd(Node *n)
This function will be called when the value of RefCountField changes.
Definition: X3DShapeNode.h:99
virtual void onRemove(Node *n)
This function will be called when the value of RefCountField changes.
Definition: X3DShapeNode.h:113
virtual ~SFGeometryNode()
Destructor.
Definition: X3DShapeNode.h:89
SFGeometryNode()
Constructor.
Definition: X3DShapeNode.h:84
This is the base node type for all Shape nodes.
Definition: X3DShapeNode.h:50
H3DUniquePtr< SFShadowObjectNode > shadowVolume
If specified, contains a H3DShadowObjectNode to be used for shadows.
Definition: X3DShapeNode.h:271
H3DUniquePtr< SFAppearanceNode > appearance
The field containing the X3DAppearance node to be used when rendering the shape.
Definition: X3DShapeNode.h:246
virtual void initialize()
Sets up the bound field using the bboxCenter and bboxSize fields.
Definition: X3DShapeNode.h:167
H3DUniquePtr< SFGeometryNode > geometry
Contains the X3DGeometryNode to be rendered.
Definition: X3DShapeNode.h:253
static bool disable_lighting_if_no_app
Set to true if lighting should be disabled when no Appearance or Material node has been specified as ...
Definition: X3DShapeNode.h:284
H3DUniquePtr< SFHapticGeometry > hapticGeometry
If specified, contains a X3DGeometryNode to be rendered haptically.
Definition: X3DShapeNode.h:261
DependentSFNode< X3DAppearanceNode, FieldRef< H3DDisplayListObject, H3DDisplayListObject::DisplayList, &H3DDisplayListObject::displayList >, true > SFAppearanceNode
SFAppearanceNode is dependent on the displayList field of its encapsulated X3DAppearanceNode node,...
Definition: X3DShapeNode.h:60
@ TRANSPARENT_ONLY
render only transparent objects
Definition: X3DShapeNode.h:227
@ SOLID
render only non-transparent objects
Definition: X3DShapeNode.h:233
@ TRANSPARENT_FRONT
render only the front face of transparent objects
Definition: X3DShapeNode.h:229
@ TRANSPARENT_BACK
render only the back face of transparent objects
Definition: X3DShapeNode.h:231
static H3DNodeDatabase database
The H3DNodeDatabase for this node.
Definition: X3DShapeNode.h:278
TypedSFNode< X3DGeometryNode > SFHapticGeometry
SFHapticGeometry contains a X3DGeometryNode.
Definition: X3DShapeNode.h:63
float H3DFloat
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