exportGraphics Method

Beta Waiting for feedback from community before finalizing.

Export meshes suitable for graphics APIs from arbitrary geometry in elements in this IModelDb.

  • Requests can be slow when processing many elements so it is expected that this function be used on a dedicated backend.
  • Vertices are exported in the IModelDb's world coordinate system, which is right-handed with Z pointing up.
  • The results of changing ExportGraphicsProps during the ExportGraphicsProps.onGraphics callback are not defined.

Example that prints the mesh for element 1 to stdout in OBJ format

const onGraphics: ExportGraphicsFunction = (info: ExportGraphicsInfo) => {
  const mesh: ExportGraphicsMesh = info.mesh;
  for (let i = 0; i < mesh.points.length; i += 3) {
    process.stdout.write(`v ${mesh.points[i]} ${mesh.points[i + 1]} ${mesh.points[i + 2]}\n`);
    process.stdout.write(`vn ${mesh.normals[i]} ${mesh.normals[i + 1]} ${mesh.normals[i + 2]}\n`);
  }

  for (let i = 0; i < mesh.params.length; i += 2) {
    process.stdout.write(`vt ${mesh.params[i]} ${mesh.params[i + 1]}\n`);
  }

  for (let i = 0; i < mesh.indices.length; i += 3) {
    const p1 = mesh.indices[i];
    const p2 = mesh.indices[i + 1];
    const p3 = mesh.indices[i + 2];
    process.stdout.write(`f ${p1}/${p1}/${p1} ${p2}/${p2}/${p2} ${p3}/${p3}/${p3}\n`);
  }
};

iModel.exportGraphics(({ onGraphics, elementIdArray: ["0x1"] }));

exportGraphics(exportProps: ExportGraphicsProps): DbResult

Parameter Type Description
exportProps ExportGraphicsProps  

Returns - 0 if successful, status otherwise

Defined in

Last Updated: 13 May, 2019