Skip to content

GridPlugin

Show/hide and configure the scene grid. Thin wrapper over GridService with helpers for auto-fitting the grid to scene contents.

Usage

ts
const viewer = new ViewerCore(container, {
  plugins: [{ name: "grid", enabled: true }],
});
await viewer.ready();

const grid = viewer.pluginManager.getPlugin("grid") as GridPlugin;
grid.show();

Or:

ts
await viewer.loadPlugin(new GridPlugin());

Service dependency: grid. Deactivating the plugin hides the grid but does not destroy the service.

Public API

MethodDescription
show(config?: Partial<GridConfig>)Create (if needed) and show the grid. Optional config patch.
hide()Hide the grid.
isVisible()true if the grid is currently shown.
autoFitGrid(target: THREE.Object3D)Bind the grid to a target and ensure it is visible.
enableAutoFit(enabled?)Toggle the auto-fit flag in GridConfig.
setTargetObject(object)Set the object the grid follows.
setOrientation(orientation: GridOrientation)xy, xz, or yz (see GridService).
updateConfig(config: Partial<GridConfig>)Patch grid configuration (size, divisions, colors, etc.).
fitGridToScene()Fit the grid bounds to the full scene.
fitGridToObject(object)Fit grid bounds to a specific object.

See GridService for GridConfig and GridOrientation definitions.

Example

ts
const grid = viewer.pluginManager.getPlugin("grid") as GridPlugin;

grid.show({ size: 10, divisions: 20 });
grid.setOrientation("xz");
grid.fitGridToObject(loadedModel);
grid.enableAutoFit(true);

XViewr SDK and xConvert CLI documentation.