@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
22 lines (19 loc) • 722 B
text/typescript
import {BufferGeometry} from 'three';
interface TextGeometryOffsetParams {
geometry: BufferGeometry;
previousGeometry: BufferGeometry;
lineHeight: number;
}
export function textGeometryOffset(params: TextGeometryOffsetParams) {
params.previousGeometry.computeBoundingBox();
params.geometry.computeBoundingBox();
const previousBbox = params.previousGeometry.boundingBox;
const currentBbox = params.geometry.boundingBox;
if (!(previousBbox && currentBbox)) {
return;
}
// const previousHeight = Math.abs(previousBbox.max.y - previousBbox.min.y);
const currentHeight = Math.abs(currentBbox.max.y - currentBbox.min.y);
const offset = previousBbox.min.y - (currentHeight + params.lineHeight);
return offset;
}