Group node that renders multiple instances of its children. More...
#include <Inventor/nodes/SoMultipleInstance.h>
Public Member Functions | |
virtual SoType | getTypeId () const |
SoMultipleInstance () | |
Static Public Member Functions | |
static SoType | getClassTypeId () |
Public Attributes | |
SoSFUInt32 | numInstances |
SoSFUInt32 | numBatches |
SoMFInstanceParameter | parameters |
Group node that renders multiple instances of its children.
This group node renders its children multiple times applying different per-instance attributes.
This node issues a single multi-instance OpenGL draw call that automatically applies per-instance parameters (SoInstanceParameter objects) set in the parameters field. Some predefined parameter names can be used for common instance parameters like position, rotation, scale factor, or color. Parameter objects with these names are automatically managed and are recognized and used by the default shaders. Applications can define additional parameter objects to be used by custom shaders. Custom shaders can also be used to set per-instance colors and so on.
The predefined instance parameters are typically set by the application to position the instances in space. The application does not need to set predefined instance parameter values if the default values are OK. For example, you may not need to set per-instance rotations. In that case you can just set the desired parameters for translating and/or scaling instances. If the application does not set any instance parameters, all the instances will be drawn at the same 3D position without any rotation or scaling factor applied.
Some methods are provided by SoInstanceParameter to create these per-instance parameters: see the SoInstanceParameter and SoMFInstanceParameter documentation.
The predefined names for the SoInstanceParameter name field are the following. However we recommend using the SoInstanceParameter static method getPredefinedParameterName() to ensure future compatibility.
The OivShapeInstanceTranslation, OivShapeInstanceScale and OivShapeInstanceRotation parameters (if present) are combined together to create an equivalent matrix. This matrix is available to application shader programs using the GLSL function
mat4 OivGetShapeInstanceMatrix()
If no instance parameters were set, the identity matrix is returned
The OivShapeInstanceColor parameter affects the diffuse color of each instance.
Notes:
Limitations:
// Geometry to be instanced. SoAlgebraicCone* geometry = new SoAlgebraicCone(); // Position data for multiple instances. int numPositions = 4; SoCpuBufferObject* positionBuffer = new SoCpuBufferObject(); positionBuffer->setSize( numPositions * sizeof(SbVec3f) ); SbVec3f* positions = (SbVec3f*)positionBuffer->map( SoBufferObject::SET ); positions[0].setValue( -2, -2, 0 ); positions[1].setValue( 2, -2, 0 ); positions[2].setValue( 2, 2, 0 ); positions[3].setValue( -2, 2, 0 ); positionBuffer->unmap(); // Parameter object for multiple instance positions. SoInstanceParameter* positionParam = SoInstanceParameter::createPredefinedParameter( SoInstanceParameter::TRANSLATION, positionBuffer ); // Multiple instance node. SoMultipleInstance* multiInstance = new SoMultipleInstance(); multiInstance->numInstances = numPositions; multiInstance->parameters = positionParam; multiInstance->addChild( geometry ); // Add to scene graph root->addChild( multiInstance );
numInstances | 1 |
numBatches | 1 |
parameters |
SoInstanceParameter, SoVertexShaderParameter, SoBufferedShape, SoAlgebraicShape, SoShaderProgram, SoMultipleCopy, SoArray, SoSwitch
NOTE: node available since Open Inventor 9.5MultiInstancingAlgebraicShapes, MultiInstancingBufferedShape
SoMultipleInstance::SoMultipleInstance | ( | ) |
Creates a multiple instance node with default settings.
static SoType SoMultipleInstance::getClassTypeId | ( | ) | [static] |
Returns the type identifier for this class.
Reimplemented from SoMultipleInstanceBase.
virtual SoType SoMultipleInstance::getTypeId | ( | ) | const [virtual] |
Returns the type identifier for this specific instance.
Reimplemented from SoMultipleInstanceBase.
When this field is set to 1 (default), all the instances are rendered in one batch.
When greater than 1, rendering will be done in numBatches passes, in order to spend less time in the driver code. This is useful when rendering GPU costly shapes (complex shader, big number of vertices...), because the process may spend too much time in the driver leading to a driver timeout on Windows systems. Default is 1.
Number of shape instances to render.
Default is 1.
List of per-instance attributes of type SoVertexShaderParameters.
The predefined names can be queried using SoInstanceParameter::getPredefinedParameterName().
The number of elements in each SoVertexShaderParameter must be greater than or equal to numInstances * SoInstanceParameter::divisor, if not, the attributes will be ignored with warning messages in debug mode.
Some predefined SoVertexShaderParameter::name are automaticly managed/interpreted:
OivShapeInstanceTranslation, OivShapeInstanceScale, OivShapeInstanceRotation are combined together to create an equivalent matrix available in GLSL shaders with the function
mat4 OivGetShapeInstanceMatrix()
If no parameters are present then an identity matrix is returned.
OivShapeInstanceColor affects the diffuse color of each instance.