Skip to content

TransformControlsPlugin

Plugin wrapper around TransformControlsService for translate, rotate, and scale gizmos on a target object.

Usage

ts
import { ViewerCore, TransformControlsPlugin } from "@optellix/xviewr-sdk";

const viewer = new ViewerCore(container, config);
await viewer.ready();
await viewer.loadPlugin(new TransformControlsPlugin());

const transform = viewer.pluginManager.getPlugin("transformControls") as TransformControlsPlugin;
transform.attachToObject(someMesh);
transform.setMode("rotate");
transform.enable();

Service dependencies: transformcontrols.

Public API

Lifecycle

MethodDescription
enable()Activate the service.
disable()Deactivate the service.
isActive()Boolean.

Mode and space

MethodDescription
setMode(mode)"translate" | "rotate" | "scale".
getMode()Current TransformMode.
setSpace(space)"world" | "local".
getSpace()Current TransformSpace.

Gizmo settings

MethodDescription
setSize(size)Gizmo size multiplier.
getSize()Current size.
setAxisVisibility("x" | "y" | "z", visible)Toggle a single axis handle.

Snapping

MethodDescription
setTranslationSnap(snap | null)World-unit snap, null to disable.
setRotationSnap(snap | null)Radian snap.
setScaleSnap(snap | null)Scalar snap.

Object management

MethodDescription
attachToObject(object)Attach gizmo to a THREE.Object3D.
detachFromObject()Detach.
getCurrentTarget()Currently attached object or null.

Transform data

MethodDescription
getTransformData()Snapshot of current position/rotation/scale.
applyTransformData(data)Apply a previously captured snapshot.
resetTransform()Reset the target to its original transform.

Configuration

MethodDescription
updateConfig(config)Partial update of service config.
getConfig()Current service config.

Events

The plugin does not emit its own events. Subscribe to transformcontrols:changed, transformcontrols:dragging-changed, and transformcontrols:object-changed on the event bus.

Example

ts
const transform = viewer.pluginManager.getPlugin("transformControls") as TransformControlsPlugin;

transform.enable();
transform.attachToObject(targetMesh);
transform.setMode("translate");
transform.setTranslationSnap(0.1);

viewer.eventBus.on("transformcontrols:dragging-changed", ({ dragging }) => {
  if (!dragging) console.log("done", transform.getTransformData());
});

XViewr SDK and xConvert CLI documentation.