Table Of Contents

Previous topic

21.22. The Geometry Object

Next topic

21.24. The IndexBufferManager Object

This Page

21.23. The GeometryInstance Object

The GeometryInstance is the standard implementation of the Renderable Interface.

It owns a reference to a Geometry object and is usually attached to a SceneNode, either automatically during loading or via SceneNode.addRenderable().

Required scripts

The GeometryInstance object requires:

/*{{ javascript("jslib/geometry.js") }}*/
/*{{ javascript("jslib/utilities.js") }}*/

It also requires that a GraphicsDevice has been created before calling the GeometryInstance constructor.

21.23.1. Constructor

21.23.1.1. create

Summary

Creates and returns a GeometryInstance object with passed in Geometry.

Syntax

var geometryInstance = GeometryInstance.create(geometry,
                                               surface,
                                               sharedMaterial);
geometry
The geometry to reference.
surface
Which one of the geometry’s surfaces to render.
sharedMaterial
The material to apply on the geometry. This can be shared between multiple geometries.

21.23.2. Methods

21.23.2.1. clone

Summary

Creates a GeometryInstance by cloning an existing GeometryInstance.

Syntax

var newGeometryInstance = geometryInstance.clone();

21.23.2.2. getWorldExtents

Summary

Get the world extents of the GeometryInstance.

This is only valid when attached to a SceneNode and the node has been updated.

Syntax

var extents = geometryInstance.getWorldExtents();

Returns an extents array.

21.23.2.3. addCustomWorldExtents

Summary

User defined extents that replace the ones calculated from the Geometry and the SceneNode’s world transform.

Syntax

var customExtents = geometryInstance.getWorldExtents().slice();
var padding = 10;
customExtents[0] -= padding;
customExtents[1] -= padding;
customExtents[2] -= padding;
customExtents[3] += padding;
customExtents[4] += padding;
customExtents[5] += padding;
geometryInstance.addCustomWorldExtents(customExtents);
customExtents
The custom extents to use instead of the default.

The GeometryInstance must be attached to a SceneNode. Even if the SceneNode moves the extents will not be recalculated. This can be used as an optimization for animated objects that are constrained to a location.

21.23.2.4. removeCustomWorldExtents

Summary

Remove previously attached custom world extents.

Syntax

geometryInstance.removeCustomWorldExtents();

21.23.2.5. getCustomWorldExtents

Summary

Get previously attached world extents. Maybe undefined.

Syntax

var extents = geometryInstance.getCustomWorldExtents();

Returns an extents array.

21.23.2.6. hasCustomWorldExtents

Summary

Returns a whether the object has custom world extents.

Syntax

if (geometryInstance.hasCustomWorldExtents())
{
    //...
}

21.23.2.7. getNode

Summary

Get the SceneNode the GeometryInstance is attached to.

Syntax

var node = geometryInstance.getNode();

21.23.2.8. setMaterial

Summary

Set the material.

Syntax

geometryInstance.setMaterial(material);
material
Material to set.

21.23.2.9. getMaterial

Summary

Get the material.

Syntax

var material = geometryInstance.getMaterial();

21.23.2.10. destroy

Summary

Free the resources attached to the object. GeometryInstance attached to a SceneNode are destroyed when it is destroyed.

Syntax

geometryInstance.destroy();

21.23.3. Properties

21.23.3.1. techniqueParameters

Summary

The TechniqueParameters object for this particular instance.

Syntax

geometryInstance.techniqueParameters.materialColor = color;