Class SoMultipleInstance

  • All Implemented Interfaces:
    SafeDisposable

    public class SoMultipleInstance
    extends SoMultipleInstanceBase
    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.

    • "OivShapeInstanceTranslation":
      Data is an array of SbVec3f translation values (3 floats) to apply to the instances.
    • "OivShapeInstanceScale":
      Data is an array of SbVec3f scale factor values (3 floats) to apply to the instances.
    • "OivShapeInstanceRotation":
      Data is an array of SbRotation values (4 floats representing a quaternion) to apply to the instances.
    • "OivShapeInstanceColor":
      Data is an array of SbColor values (3 floats) to apply to the instances.
    • "OivShapeInstanceTransparency":
      Data is an array of float values to apply to the instances.
    • "OivShapeInstanceVisibility":
      Data is an array of unsigned int32 values to apply to the instances.

    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 OivInstanceMatrix() 
    If no instance parameters were set, the identity matrix is returned

    The OivShapeInstanceColor and OivShapeInstanceTransparency parameters affect, respectively, the diffuse color and the transparency of each instance. Note that when one of these parameters is defined, it overrides the diffuse color or the transparency value of a SoMaterial node.

    Notes:

    • The number of elements in each SoVertexShaderParameter must be greater than or equal to numInstances * SoVertexShaderParameter.instanceDivisor. If not, the attributes will be ignored with warning messages in debug mode.
    • Traversing the Nth child sets the current switch value to N , for use with inherited switch values (see SoSwitch).
    • Although SoMultipleInstance is derived from SoGroup, it behaves like an SoSeparator (traversal state is pushed and popped).

    Limitations:

    File format/default:

    MultipleInstance {

      numInstances 1
      numBatches 1
      parameters
    }

    Since:
    Open Inventor 9.5

    See Also:
    SoInstanceParameter, SoVertexShaderParameter, SoBufferedShape, SoAlgebraicShape, SoShaderProgram, SoMultipleCopy, SoArray, SoSwitch
    • Field Detail

      • numInstances

        public final SoSFUInt32 numInstances
        Number of shape instances to render. Default is 1.
      • numBatches

        public final SoSFUInt32 numBatches
        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.

        Limitation: When numBatches is greater than 1, only instance parameters with a divisor equal to 1 are supported.

        Default is 1.

      • parameters

        public final SoMFInstanceParameter parameters
        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: Handles an array of vec3f translation to apply to vertices of each instance.
        • OivShapeInstanceScale: Handles an array of vec3f scale factor applied to vertices of each instance.
        • OivShapeInstanceRotation: Handles an array of rotation vec4f to apply to vertices of each instance.
        • OivShapeInstanceColor: Handles an array of vec3f color applied to vertices of each instance.
        • OivShapeInstanceTransparency: Handles an array of float transparency applied to vertices of each instance.

        OivShapeInstanceTranslation, OivShapeInstanceScale, OivShapeInstanceRotation are combined together to create an equivalent matrix available in GLSL shaders with the function

         mat4 OivInstanceMatrix() 
        If no parameters are present then an identity matrix is returned.

        OivShapeInstanceColor affects the diffuse color of each instance.

    • Constructor Detail

      • SoMultipleInstance

        public SoMultipleInstance()
        Creates a multiple instance node with default settings.