RenderInstances Interface
Contains the WebGL resources necessary to draw multiple Instances of a GraphicTemplate using instanced rendering. Use createRenderInstances to create one. The instances may be associated with Features, in which case those features override any defined in the template itself. Example usage:
/** Create a graphic that renders multiple instances of a glTF model. */
export async function instanceGltfModel(gltf: Uint8Array | object, positions: Point3d[], iModel: IModelConnection): Promise<RenderGraphic> {
// Decode the raw glTF as an instanceable template.
const template = (await readGltfTemplate({ gltf, iModel }))?.template;
if (!template) {
throw new Error("Failed to decode glTF model.");
}
// Generate an Id for a "model" to contain the instances.
const modelId = iModel.transientIds.getNext();
// Define multiple instances, one at each of the specified positions.
const instancesBuilder = RenderInstancesParamsBuilder.create({ modelId });
for (const position of positions) {
instancesBuilder.add({
// Translate to the specified position.
transform: Transform.createTranslation(position),
// Assign a unique pickable Id.
feature: iModel.transientIds.getNext(),
});
}
const instancesParams = instancesBuilder.finish();
const instances = IModelApp.renderSystem.createRenderInstances(instancesParams);
// Create a graphic that associates the instances with the template.
return IModelApp.renderSystem.createGraphicFromTemplate({ template, instances });
}
Defined in
Last Updated: 17 December, 2024
Found something wrong, missing, or unclear on this page?Raise an issue in our repo.