@pmndrs/handle
Version:
framework agnostic expandable handle implementation for threejs
41 lines (40 loc) • 1.59 kB
JavaScript
import { Mesh, MeshBasicMaterial, SphereGeometry } from 'three';
import { handleXRayMaterialProperties, setupHandlesContextHoverMaterial } from '../material.js';
import { RegisteredHandle } from '../registered.js';
import { extractHandleTransformOptions } from '../utils.js';
export class PivotAxisScaleHandle extends RegisteredHandle {
constructor(context, axis, tagPrefix) {
super(context, axis, tagPrefix, () => ({
scale: this.options,
rotate: false,
translate: 'as-scale',
multitouch: false,
}));
}
bind(defaultColor, config) {
const { options, disabled } = extractHandleTransformOptions(this.axis, config);
if (options === false) {
return undefined;
}
this.options = options;
const material = new MeshBasicMaterial(handleXRayMaterialProperties);
const cleanupHover = setupHandlesContextHoverMaterial(this.context, material, this.tag, {
color: defaultColor,
hoverColor: 0xffff40,
disabled,
});
const mesh = new Mesh(new SphereGeometry(0.04), material);
mesh.renderOrder = Infinity;
mesh.pointerEventsOrder = Infinity;
mesh.position.x = 0.68;
const unregister = disabled ? undefined : this.context.registerHandle(this.store, mesh, this.tag);
this.add(mesh);
return () => {
material.dispose();
mesh.geometry.dispose();
unregister?.();
cleanupHover?.();
this.remove(mesh);
};
}
}