H3D API  2.4.1
X3DPrototypeInstance.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 __X3DPROTOTYPEINSTANCE_H__
30 #define __X3DPROTOTYPEINSTANCE_H__
31 
32 #include <H3D/X3DNode.h>
34 #include <H3D/H3DBoundedObject.h>
35 
36 // forward declaration for Bison VRML parser.
37 namespace yy {
38  class VrmlParser;
39  class location;
40 }
41 
42 class VrmlDriver;
43 
44 namespace H3D {
45 
46  // forward declaration.
47  namespace X3D {
48  class X3DSAX2Handlers;
49  }
50 
62  class H3DAPI_API X3DPrototypeInstance:
63  public X3DNode,
64  public H3DDynamicFieldsObject,
65  public H3DBoundedObject {
66  public:
67 
69  X3DPrototypeInstance( Inst< SFNode> _metadata = 0 );
70 
72  virtual void render();
73 
75  virtual void traverseSG( TraverseInfo &ti );
76 
78  virtual void setPrototypedNode( Node *n );
79 
81  virtual Node *getPrototypedNode() {
82  X3DPrototypeInstance *pi = dynamic_cast< X3DPrototypeInstance * >( prototyped_node.get() );
83  if( pi ) {
84  return pi->getPrototypedNode();
85  } else {
86  return prototyped_node.get();
87  }
88  }
89 
91  virtual void addPrototypedNodeExtra( Node *n ) {
92  prototyped_node_extras.push_back( n );
93  }
94 
96  virtual string defaultXMLContainerField() {
97  if( prototyped_node.get() )
98  return prototyped_node->defaultXMLContainerField();
99  else
101  }
102 
109  virtual bool lineIntersect(
110  const Vec3f &from,
111  const Vec3f &to,
112  LineIntersectResult &result ) {
113  if( prototyped_node.get() )
114  return prototyped_node->lineIntersect( from, to, result );
115  else return false;
116  }
117 
123  virtual void closestPoint( const Vec3f &p,
124  NodeIntersectResult &result ){
125  if( prototyped_node.get() )
126  return prototyped_node->closestPoint( p, result );
127  }
128 
137  virtual bool movingSphereIntersect( H3DFloat radius,
138  const Vec3f &from,
139  const Vec3f &to,
140  NodeIntersectResult &result ) {
141  if( prototyped_node.get() )
142  return prototyped_node->movingSphereIntersect( radius,
143  from, to, result );
144  else return false;
145  }
146 
149  virtual bool connectField( const string &proto_field_name,
150  Field *f );
151 
154 
155  protected:
156 
157  AutoRef< Node > prototyped_node;
158  AutoRefVector< Node > prototyped_node_extras;
159  };
160 }
161 
162 #endif
Header file for H3DBoundedObject.
Header file for H3DDynamicFieldsObject.
Header file for X3DNode, X3D scene-graph node.
The Field class.
Definition: Field.h:46
This abstract interface is the base class for all node types that include a bounding box.
Definition: H3DBoundedObject.h:42
This abstract interface class is the base class for all classes that specify arbitrary fields.
Definition: H3DDynamicFieldsObject.h:128
Node is the base class for all classes that can be part of the H3D scene-graph.
Definition: Node.h:46
virtual string defaultXMLContainerField()
Returns the default xml containerField attribute value.
Definition: Node.h:338
TraverseInfo is a structure that is passed along when traversing the scene graph.
Definition: TraverseInfo.h:57
This abstract node type is the base type for all nodes in the X3D system.
Definition: X3DNode.h:65
This abstract node type is the base type for all prototype instances in the X3D system.
Definition: X3DPrototypeInstance.h:65
virtual void addPrototypedNodeExtra(Node *n)
Set the node that is the internal scenegraph of the prototype.
Definition: X3DPrototypeInstance.h:91
virtual bool movingSphereIntersect(H3DFloat radius, const Vec3f &from, const Vec3f &to, NodeIntersectResult &result)
Detect collision between a moving sphere and the Node.
Definition: X3DPrototypeInstance.h:137
virtual Node * getPrototypedNode()
Get the node that is the internal scenegraph of the prototype.
Definition: X3DPrototypeInstance.h:81
virtual bool lineIntersect(const Vec3f &from, const Vec3f &to, LineIntersectResult &result)
Detect intersection between a line segment and the Node.
Definition: X3DPrototypeInstance.h:109
static H3DNodeDatabase database
The H3DNodeDatabase for this node.
Definition: X3DPrototypeInstance.h:153
virtual void closestPoint(const Vec3f &p, NodeIntersectResult &result)
Find closest point on Node to p.
Definition: X3DPrototypeInstance.h:123
virtual string defaultXMLContainerField()
Returns the default xml containerField attribute value.
Definition: X3DPrototypeInstance.h:96
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
Used as input to lineIntersect functions.
Definition: Node.h:224
Used as input to intersection functions.
Definition: Node.h:114