@spearwolf/twopoint5d
Version:
Create 2.5D realtime graphics and pixelart with WebGL and three.js
45 lines • 1.52 kB
JavaScript
import { Box3, Box3Helper, Color, Vector3 } from 'three/webgpu';
import { HelpersManager } from './HelpersManager.js';
export class RectangularVisibilityAreaHelpers {
#viewRect;
#show;
#helpers;
constructor(visibilityArea) {
this.viewRectHelperHeight = 20;
this.viewRectHelperColor = new Color(0xffffff);
this.#viewRect = undefined;
this.#show = false;
this.#helpers = new HelpersManager();
this.visibilityArea = visibilityArea;
}
get show() {
return this.#show;
}
set show(show) {
if (this.#show && !show) {
this.#helpers.remove();
}
else if (!this.#show && show) {
this.update();
}
this.#show = show;
}
add(scene) {
this.#helpers.scene = scene;
}
remove(scene) {
this.#helpers.removeFromScene(scene);
}
update() {
const halfWidth = this.visibilityArea.width / 2;
const halfHeight = this.visibilityArea.height / 2;
const viewRectHelperHalfHeight = this.viewRectHelperHeight / 2;
this.#viewRect = new Box3(new Vector3(-halfWidth, -viewRectHelperHalfHeight, -halfHeight), new Vector3(halfWidth, viewRectHelperHalfHeight, halfHeight));
this.#helpers.remove();
if (this.#viewRect) {
const helper = new Box3Helper(this.#viewRect, this.viewRectHelperColor);
this.#helpers.add(helper);
}
}
}
//# sourceMappingURL=RectangularVisibilityAreaHelpers.js.map