@pmndrs/uikit
Version:
Build performant 3D user interfaces with Three.js and yoga.
47 lines (46 loc) • 1.75 kB
JavaScript
import { Box3, Mesh, PlaneGeometry, Sphere } from 'three';
import { computeWorldToGlobalMatrix } from '../../utils.js';
export class InstancedGlyphMesh extends Mesh {
root;
instanceMatrix;
instanceRGBA;
instanceUV;
instanceClipping;
count = 0;
isInstancedMesh = true;
instanceColor = null;
morphTexture = null;
boundingBox = new Box3();
boundingSphere = new Sphere();
customUpdateMatrixWorld = () => computeWorldToGlobalMatrix(this.root, this.matrixWorld);
constructor(root, instanceMatrix, instanceRGBA, instanceUV, instanceClipping, material) {
const planeGeometry = new PlaneGeometry();
planeGeometry.translate(0.5, -0.5, 0);
super(planeGeometry, material);
this.root = root;
this.instanceMatrix = instanceMatrix;
this.instanceRGBA = instanceRGBA;
this.instanceUV = instanceUV;
this.instanceClipping = instanceClipping;
this.pointerEvents = 'none';
planeGeometry.attributes.instanceUVOffset = instanceUV;
planeGeometry.attributes.instanceRGBA = instanceRGBA;
planeGeometry.attributes.instanceClipping = instanceClipping;
this.frustumCulled = false;
root.onUpdateMatrixWorldSet.add(this.customUpdateMatrixWorld);
}
copy() {
throw new Error('copy not implemented');
}
dispose() {
this.root.onUpdateMatrixWorldSet.delete(this.customUpdateMatrixWorld);
this.dispatchEvent({ type: 'dispose' });
this.geometry.dispose();
}
//functions not needed because intersection (and morphing) is intenionally disabled
computeBoundingBox() { }
computeBoundingSphere() { }
updateMorphTargets() { }
raycast() { }
spherecast() { }
}