#include <QGLSceneNode>
( QObject * parent = 0 )
( const QGeometryData &geometry, QObject * parent = 0 )
virtual ()
void ( QGLSceneNode * node )
void ( const QList<QGLSceneNode *> & nodes )
void ( QGraphicsTransform3D *transform )
QList<QGLSceneNode *> () const
QGLSceneNode * ( const QString & name, QObject *parent = 0 ) const
QGLSceneNode * ( const QStringList & names, QObject * parent = 0 ) const
QGLMaterial * () const
int () const
QBox3D () const
QList<QGLSceneNode *> () const
QGLSceneNode * ( QObject * parent = 0 ) const
QGLSceneNode * ( QObject * parent = 0 ) const
int () const
virtual void ( QGLPainter * painter )
QGL::DrawingMode () const
qreal () const
QGL::StandardEffect () const
QGeometryData () const
bool () const
QMatrix4x4 () const
QGLMaterial * () const
int () const
QGLSceneNode * ( const QString & name, QObject *parent = 0 ) const
QGLSceneNode * ( const QStringList & names, QObject *parent = 0 ) const
QGLSceneNode::Options () const
QGLMaterialCollection * () const
QGLPickNode * () const
QVector3D () const
void ( QGLSceneNode * node )
void ( const QList<QGLSceneNode *> & nodes )
void ( QGLMaterial * material )
void ( int material )
void ( int count )
void ( QGL::DrawingMode mode)
void ( qreal width )
void ( QGL::StandardEffect effect )
void ( bool enabled )
void ( QGeometryData geometry )
void ( const QMatrix4x4 &transform )
void ( QGLMaterial * material )
void ( int material )
void ( QGLSceneNode::Option option, bool value )
void ( QGLSceneNode::Optionsoptions )
void ( QGLMaterialCollection * palette )
void ( QGLPickNode * node )
void ( const QVector3D & p )
void ( int start )
void ( const QList<QGraphicsTransform3D *> &transforms )
void ( QGLAbstractEffect * effect )
void ( qreal x )
void ( qreal y )
void ( qreal z )
int () const
QList<QGraphicsTransform3D *> () const
QGLAbstractEffect * () const
qreal () const
qreal () const
qreal () const
详细说明(Detailed Description)
QGLSceneNode这个类定义(defines)了在一个3D场景(scene)中的一个节点(node)。
QGLSceneNode represents one component of a scene. The QGLSceneNode class manages materials, effects and transformations for itself and for its child nodes.
As a general approach to 3D applications, a tree of QGLSceneNodes may be constructed, geometry added to them, materials and transformations applied, all during application initialization; and then by simply calling the () function the scene is easily rendered for each frame.
几何结构(Geometry)
Multiple QGLSceneNodes can reference the same geometry, whilst applying different transformations and treatments to it. Since QGLSceneNode is a QObject sub class it cannot be copied directly, so instead use the () function for this purpose.
A scene node allows referencing into sub-parts of geometry, via the start and count properties.
The start index is an offset into the geometry at which drawing will start. The default start index is 0, so that drawing will start from the beginning of the geometry. The count dictates how many vertices will be drawn. The default count is 0, which instructs the underlying geometry to draw all vertices.
A node may have no geometry, that is geometry().count() == 0. This is useful for example to have one node controlling or collecting together several child nodes to be manipulated as a unit.
材质(Materials)
Also a node may have a local material. This allows drawing the same geometry with different materials (which includes different textures).
When accessing a QGLSceneNode via QML, or for simple applications, the pointer based material functions are convenient and intuitive, saving the trouble of adding the material pointer to the correct palette:
material() setMaterial() backMaterial() setBackMaterial()
For more complex applications; for example building model loaders, or for larger scenes; where you need to explicitly manage materials via a palette, use the index based functions:
materialIndex() setMaterialIndex() backMaterialIndex()setBackMaterialIndex()
The behaviour of both with respect to faces is the same - if a () is specified but no () is specified, then the () is applied to both faces; if both () and () are non-null then they are applied to their specific faces.
变换(Transformations)
Typically the local transformation matrix is set by the process that constructed the node: in the case of an imported model, it is likely to have been specified by the model file. To make individual changes to the location or orientation of this node, use the () and () properties.
场景图(Scene Graph)
Use childNodes() to obtain the list of child nodes, and add and remove child nodes by the () and () methods. If a QGLSceneNode is constructed with a QGLSceneNode parent, then () will be called implicitly on the parent.
A child may be a child multiple times, a child may be under more than one parent, and several parents may reference the same child. There is however no protection against cycles, so a child must not be a parent of itself, even if indirectly.
A child node for the purposes of rendering means a child added via the() method. The default QGLSceneNode constructor will check to see if its parent is a QGLSceneNode and add itself via the () function if it is.
To help debug a scene, use the () function to get a printout on stderr of the entire structure of the scene below the argument node.
调试灯光法线(Debugging Lighting Normals)
The option is an advanced feature for use when inspecting and debugging models or geometry in a scene. The lighting normals are displayed as a straight line from the vertex pointing in the direction of the lighting normal. This is useful for example to show where normals are inverted or wrongly calculated.
The setting of the flag is not propagated to child nodes, instead set the flag to true for the node or nodes where its needed. To set the flag on all child nodes use code like:
foreach (QGLSceneNode *node, scene.allChildren()) node->setNormalViewEnabled(true);
See also .
Member Type Documentation
enum QGLSceneNode::Option flags QGLSceneNode::Options
This enum defines option flags for . By default the none of the flags are set, so the () function returns QGLSceneNode::NoOptions
常量(Constant) | 值(Value) | 描述(Description) |
---|---|---|
QGLSceneNode::NoOptions | 0x0000 | Do not enable any options. |
QGLSceneNode::CullBoundingBox | 0x0001 | Perform a cull using () before attempting to draw the(). |
QGLSceneNode::ViewNormals | 0x0002 | Enables the display of lighting normals for debugging purposes. |
QGLSceneNode::ReportCulling | 0x0004 | Send a signal when an object is displayed or culled. |
QGLSceneNode::HideNode | 0x0008 | Hide this node so it, and all its children, are excluded from rendering. |
The Options type is a typedef for <Option>. It stores an OR combination of Option values.
See also ().
Property Documentation
backMaterial : *
This property holds this property is a pointer to any QGLMaterial instance for this node's back faces.
This material is applied to the back faces, if non-null. The default value of this property is null. When this property is null, any non-null material set on the() property will be applied to front and back faces.
To apply a material to the front faces use the () property.
Getting this property is exactly equivalent to palette()->material(backMaterialIndex()).
Setting this property causes the material if not already in this nodes palette to be added, and then the corresponding index to be set for this scene node.
Setting this property is exactly equivalent to:
int index = d->palette->indexOf(material); if (index == -1) index = d->palette->addMaterial(material); (index);
Access functions:
QGLMaterial *
backMaterial () constvoid
setBackMaterial ( QGLMaterial * material )Notifier signal:
void
()material : *
This property holds this property is a pointer to a QGLMaterial instance for this node.
This material is applied to all faces if the () property is set to null, which is the default. If the () property is non-null then this material is only applied to the front faces.
To apply a material to the back faces use the () property.
Getting this property is exactly equivalent to palette()->material(materialIndex()).
Setting this property causes the material if not already in this nodes palette to be added, and then the corresponding index to be set for this scene node.
Setting this property is equivalent to:
int index = d->palette->indexOf(material); if (index == -1) index = d->palette->addMaterial(material); (index);
If setting this property, when no palette exists one is created, as a convenience - but this is suitable only for experimental code and for very small numbers of nodes. In debug mode a warning is printed in this case.
Generally one common palette should be created, and set on each node. This also allows nodes to share materials and their textures.
Access functions:
QGLMaterial *
material () constvoid
setMaterial ( QGLMaterial * material )Notifier signal:
void
()See also () and ().
options :
This property holds various option flags effecting rendering.
This property containst several flags that modify normal rendering and culling on a . See for a full description of the available flags.
Access functions:
QGLSceneNode::Options
options () constvoid
setOptions ( QGLSceneNode::Options options )Notifier signal:
void
()See also () and .
position : QVector3D
This property holds the amounts of x, y and z axis translation for this node.
Since most nodes are situated relative to (0, 0, 0) when imported as part of a model or constructed programatically, the translation is effectively the position of the model in the scene.
The x, y and z axis translations can also be specified individually as separate properties , , and
Access functions:
QVector3D
position () constvoid
setPosition ( const QVector3D & p )Notifier signal:
void
()See also (), (), and ().
x : qreal
This property holds the amount of x axis translation for this node.
Access functions:
qreal
x () constvoid
setX ( qreal x )Notifier signal:
void
()See also ().
y : qreal
This property holds the amount of y axis translation for this node.
Access functions:
qreal
y () constvoid
setY ( qreal y )Notifier signal:
void
()See also ().
z : qreal
This property holds the amount of z axis translation for this node.
Access functions:
qreal
z () constvoid
setZ ( qreal z )Notifier signal:
void
()See also ().
Member Function Documentation
QGLSceneNode::QGLSceneNode ( QObject * parent = 0 )
Constructs a new scene node and attaches it to parent. If parent is a then this node is added to it as a child.
QGLSceneNode::QGLSceneNode ( const &geometry, QObject * parent = 0 )
Constructs a new scene node referencing geometry and attaches it toparent. If parent is a then this node is added to it as a child.
QGLSceneNode::~QGLSceneNode () [virtual]
Destroys this scene node.
void QGLSceneNode::addNode ( QGLSceneNode * node )
Adds the node to the list of child nodes for this node.
This function does nothing if node is null or is already a child of this node. If the node is the node itself, a warning about an attempt to add a node to itself is printed, and no add takes place.
If the aim is to have the same geometry displayed several times under a given node, each time with different transformations, use the () call to create copies of the node and then apply the transformations to the copies.
Alternatively, create modifier nodes with the transformations and add the geometry bearing node to each with addNode():
builder; builder << CarWheel(5.0f); // some car wheel geometry wheel = builder.finalizedSceneNode(); frontLeft = new (m_sceneRoot); frontLeft->addNode(wheel); frontLeft->(QVector3D(1.0f, 2.0f, 0.0f)); frontRight = new (m_sceneRoot); frontRight->addNode(wheel); frontRight->(QVector3D(-1.0f, 2.0f, 0.0f)); backLeft = new (m_sceneRoot); backLeft->addNode(wheel); backLeft->(QVector3D(1.0f, -2.0f, 0.0f)); backRight = new (m_sceneRoot); backRight->addNode(wheel); backRight->(QVector3D(-1.0f, -2.0f, 0.0f));
Because a child node can be validly added to many different nodes, calling addNode() does not normally affect the QObject::parent() ownership. However, if node does not currently have a QObject::parent(), the parent will be set to this node.
See also (), (), and ().
void QGLSceneNode::addNodes ( const QList<QGLSceneNode *> & nodes )
Adds the members of nodes to the list of child nodes for this node.
See also () and ().
void QGLSceneNode::addTransform ( *transform )
Adds a single transform to this node, to be applied to the node after all current members of () have been applied.
In the mathematical sense, transform is applied to the modelview matrix before the current members of () are applied in reverse order.
See also () and ().
QList<QGLSceneNode *> QGLSceneNode::allChildren () const
Returns a list including recursively all child nodes under this node. Each child node only appears once, even if it is included multiple times in the scene graph.
See also ().
QGLSceneNode * QGLSceneNode::allExcept ( const QString &name, QObject * parent = 0 ) const
Creates a new that is a copy of this scene node, with parentas the parent of the new copy. If parent is NULL then parent is set to this nodes parent.
The copy will reference the same underlying geometry and have all effects, transforms and other properties copied from this node.
The copy returned will have the same child nodes, except all child nodes whose objectName() is equal to name.
See also () and ().
QGLSceneNode * QGLSceneNode::allExcept ( const QStringList& names, QObject * parent = 0 ) const
Creates a new that is a copy of this scene node, with parentas the parent of the new copy. If parent is NULL then parent is set to this nodes parent.
The copy will reference the same underlying geometry and have all effects, transforms and other properties copied from this node.
The copy returned will have the same child nodes, except all child nodes whose objectName() is in the list of names.
See also () and ().
int QGLSceneNode::backMaterialIndex () const
Returns the back material index for this scene node.
See also ().
QGLSceneNode::boundingBox () const
Returns a bounding box for the portion of the geometry referenced by this scene node. If the value of () is 0, and () is the same as()->size() then the bounding box will be the same as ()->boundingBox(). However if the scene node only references some part of the geometry, a bounding box for this section is calculated.
If this scene node has child nodes then the bounding box will be the calculated union of the bounding box for this nodes geometry (if any) and the bounding boxes of the children.
The calculated value is cached and returned on subsequent calls, but could be expensive to calculate initially.
QList<QGLSceneNode *> QGLSceneNode::children () const
Returns a list of the child nodes for this node. This list is not recursively generated, it includes only the nodes which are immediate children of this node.
See also ().
QGLSceneNode * QGLSceneNode::clone ( QObject * parent = 0 ) const
Creates a new that is a copy of this scene node, with parentas the parent of the new copy. If parent is NULL then parent is set to this nodes parent.
The copy will reference the same underlying geometry, child nodes, and have all effects, transforms and other properties copied from this node. The only property that is not copied is ().
See also ().
QGLSceneNode * QGLSceneNode::cloneNoChildren ( QObject *parent = 0 ) const
Creates a new that is a copy of this scene node, with parentas the parent of the new copy. If parent is NULL then parent is set to this nodes parent.
The copy will reference the same underlying geometry, and have all effects, transforms and other properties copied from this node. The () and pickNodes() are not cloned.
See also ().
int QGLSceneNode::count () const
Returns the count of the vertices to render from () for this scene node. The default is zero, meaning that this node uses all vertices from() up to the last logical vertex in the underlying ().
See also () and ().
void QGLSceneNode::culled () [signal]
Signals that the node was culled due to falling wholly outside the view frustum. This signal can only fire if both and options are both set.
void QGLSceneNode::displayed () [signal]
Signals that the node was displayed - or at least its geometry was sent to the GPU for rendering, since the GPU might still clip or occlude the node. This signal can only fire if both and options are both set.
void QGLSceneNode::draw ( * painter ) [virtual]
Draws this scene node and its children on the painter.
In detail this function:
- ensures the effect specified by () is current on the painter
- sets the nodes materials onto the painter, if valid materials are present
- moves the model-view to the x, y, z position
- applies any local () that may be set for this node
- calls draw() for all the child nodes
- calls draw(start, count) on this nodes geometry object (if any)
- restores the geometry's original materials if they were changed
- restores the model-view matrix if any local transform was applied
Note that the draw() method does not restore the effect. If the first step above results in a change to the current QGL::Standard effect then it will remain set to that effect. In general any painting method should ensure the effect it requires is current.
The way draw is implemented ensures that this nodes effects, materials and transformations will apply by default to its child nodes. Transformations are cumulative, but effects and materials override those of any parent node.
Note that if the option is set for this node, neither it nor its children will be drawn.
void QGLSceneNode::drawGeometry ( * painter )[virtual protected]
Draws the geometry of the node onto the painter.
This is the function which performs the actual drawing step in the draw function below.
- calls draw(start, count) on this nodes geometry object (if any)
Override this function to perform special processing on this node, after transformation & culling are applied and before sequencing of materials & effects are done; but just before (or after) the actual draw step.
This default implementation simply draws the nodes geometry onto the painter.
Example:
void MySpecialNode::geometryDraw( *painter) { // at this point the node has survived culling, the model-view // matrix is transformed into this nodes frame of reference, // materials & effects have been applied as this node appears // in its place in the render sequence doMySpecialProcessing(); // call parent implementation to do actual draw ::geometryDraw(painter); }
QGLSceneNode::drawingMode () const
Returns the drawing mode to use to render (). The default is.
See also ().
qreal QGLSceneNode::drawingWidth () const
Returns the drawing width for this node.
Drawing width is used only when drawing lines or points (ie. when the drawing mode is points, lines, line-strips, etc).
See also () and ().
QGLSceneNode::effect () const
Returns the local effect associated with this node. The default value is. If the value of () is false, then this the value of effect() is ignored.
See also () and ().
QGLSceneNode::geometry () const
Returns the geometry associated with this node, or a null if no geometry has been associated with it.
See also ().
bool QGLSceneNode::hasEffect () const
Returns true if the local effect on this node is enabled, otherwise returns false.
See also () and ().
QMatrix4x4 QGLSceneNode::localTransform () const
Returns the local transform associated with this node. If no local transform has been explicitly set, this method returns a QMatrix4x4 set to the identity matrix.
The local transform is typically set during model loading or geometry construction, and is a feature of the geometry.
In general to change the location or orientation of the node use the () or () properties instead.
See also (), (), and ().
int QGLSceneNode::materialIndex () const
Returns the material index for this scene node.
See also ().
QGLSceneNode * QGLSceneNode::only ( const QString & name,QObject * parent = 0 ) const
Creates a new that is a copy of this scene node, with parentas the parent of the new copy. If parent is NULL then parent is set to this nodes parent.
The copy will reference the same underlying geometry and have all effects, transforms and other properties copied from this node.
The copy returned will have only one child node. This child node will be the first child node of this one which has its objectName() equal to name.
See also () and ().
QGLSceneNode * QGLSceneNode::only ( const QStringList &names, QObject * parent = 0 ) const
Creates a new that is a copy of this scene node, with parentas the parent of the new copy. If parent is NULL then parent is set to this nodes parent.
The copy will reference the same underlying geometry and have all effects, transforms and other properties copied from this node.
The copy returned will have only the child nodes from this whose objectName() is in the list of names.
See also () and ().
* QGLSceneNode::palette () const
Returns the palette of materials used by this scene node, or NULL if no palette has been set.
See also ().
* QGLSceneNode::pickNode () const
Returns the pick node for this scene node, if one was set; otherwise NULL (0) is returned.
See also ().
void QGLSceneNode::removeNode ( QGLSceneNode * node )
Removes the child node matching node from this node.
If the QObject::parent() ownership of node was set to this node, then its parent will be changed to another parent node if it had multiple parents.
If node had only a single parent, then its parent will be set to null, effectively detaching it from the QObject ownership rules of the scene graph. The caller is then responsible for deleting node.
If the QObject::parent() of node was not a scene node parent, then it will be left unmodified.
See also () and ().
void QGLSceneNode::removeNodes ( const QList<QGLSceneNode*> & nodes )
Removes the members of nodes from the list of child nodes for this node.
See also () and ().
void QGLSceneNode::setBackMaterialIndex ( int material )
Sets the back material index for this scene node to material.
See also () and ().
void QGLSceneNode::setCount ( int count )
Sets the count of the vertices to render from () for this scene node.
See also () and ().
void QGLSceneNode::setDrawingMode ( mode )
Sets the drawing mode to use to render ().
Note: this function changes the drawing mode, but the underlying () still consists of the triangles that were added. Thus, this function is only useful for converting the drawing mode into to display the() as a point cloud instead of a triangle mesh. The other enums from will give unpredictable results.
See also ().
void QGLSceneNode::setDrawingWidth ( qreal width )
Sets the drawing width to the given value.
Drawing width is used only when drawing lines or points (ie. when the drawing mode is points, lines, line-strips, etc).
See also () and ().
void QGLSceneNode::setEffect ( effect )
Sets the local effect associated with this node to be effect. () will return true after calling this method.
The () function will ensure that effect is applied to the before drawing any geometry.
See also () and ().
void QGLSceneNode::setEffectEnabled ( bool enabled )
Sets whether the current value of () or () will be applied to the prior to drawing. If enabled is true, then the effect is applied, otherwise it is not.
See also (), (), and ().
void QGLSceneNode::setGeometry ( geometry )
Sets the geometry associated with this node to be geometry. Typically thegeometry will be some type of mesh object. The default implementation of the () method will call the geometry's () method.
See also ().
void QGLSceneNode::setLocalTransform ( const QMatrix4x4 &transform )
Sets the local transform associated with this node to be transform. The default implementation of the () method will apply this transform to the before drawing any geometry.
See also ().
void QGLSceneNode::setMaterialIndex ( int material )
Sets the material index for this scene node to material.
See also ().
void QGLSceneNode::setOption ( option,bool value )
Enables or disables option according to value.
See also () and ().
void QGLSceneNode::setPalette ( * palette)
Sets the palette of materials for this scene node to palette.
See also ().
void QGLSceneNode::setPickNode ( * node )
Sets the pick node for this scene node to node.
See also ().
void QGLSceneNode::setStart ( int start )
Sets the start index within () that should be used to render fragments for this scene node.
See also () and ().
void QGLSceneNode::setTransforms ( constQList< *> & transforms )
Sets the list of transformations to apply to this node to transforms.
The transformations are applied to the node itself, so a followed by a will first scale the node in its local co-ordinate system, and then translate the node a new location.
In the mathematical sense, the transformations are applied to the modelview matrix in the reverse order in which they appear in transforms.
The () is applied after all other transformations have been applied.
See also (), (), and ().
void QGLSceneNode::setUserEffect ( * effect )
Sets the local effect associated with this node to be the custom effect.() will return true after calling this method.
This custom effect will supersede any standard effect.
The default implementation of QGLSceneNode::apply() will set this effect during initialization of the model.
The default implementation of the () method will ensure that effect is applied to the before drawing any geometry.
See also () and ().
int QGLSceneNode::start () const
Returns the starting index within () that should be used to render fragments for this scene node. The default value is 0, indicating that the 0'th logical vertex in () is the start.
See also () and ().
QList< *> QGLSceneNode::transforms () const
Returns the list of transformations to apply to this node. The default is the empty list.
The transformations are applied to the node itself, so a followed by a will first scale the node in its local co-ordinate system, and then translate the node a new location.
In the mathematical sense, the transformations are applied to the modelview matrix in the reverse order in which they appear in this list.
The () is applied after all other transformations have been applied.
See also (), (), and ().
void QGLSceneNode::updated () [signal]
Signals that some property of this scene node, or one of its children, has changed in a manner that will require that the node be redrawn.
* QGLSceneNode::userEffect () const
Returns the user effect associated with this node, or NULL if one is not set. The default value is NULL. If the value of () is false, then this effect is ignored.
See also () and ().
Related Non-Members
void qDumpScene ( QGLSceneNode * node, bool detailed = true, int indent = 0, const QSet<QGLSceneNode *> & loop = QSet<QGLSceneNode *> () )
Print a description of node, and all its descendants, to the console. This function uses qDebug for its output, so in the case of Windows the output will go to the debug window. If QT_NO_DEBUG_OUTPUT or QT_NO_DEBUG has been defined, (as in release mode) this function will exit without doing anything.
If detailed is true (which it is by default) then all the properties of each node are printed, including materials, geometry and transforms.
If detailed is false, then just one line is printed with the name and some identifying information including a unique id for the node.
The indent and loop parameters are used internally.