convex-pixel
Version:
The library for creating pseudo 3d interactive scenes based on webgl
57 lines • 2.3 kB
JavaScript
import * as PIXI from "pixi.js";
import { P3DCameraProcessor } from "../../core/camera-processor";
import * as DisplayUtils from "../../utils/display";
import * as SonarUtils from "../../utils/sonar";
import { BaseContainer } from "./base-container";
export class BaseRoom extends BaseContainer {
constructor(appContext, options) {
super(appContext);
this._roomBound = new PIXI.Rectangle();
this._resizeSonarHandler = () => {
this.resetScaleFactor();
};
this._autosize = options.autosize || DisplayUtils.RatioFitTypes.NONE;
// Create a camera
this._camera = new options.camera.class(this, options.camera.viewport, options.camera.config);
for (const controller of options.camera.controllers) {
if (!this._camera.controllers) {
continue;
}
this._camera.controllers.add(new controller(appContext));
}
this._cameraProcessor = new P3DCameraProcessor(this);
this._sonarResize = new SonarUtils.SonarDebounce();
this._sonarResize.addListener(SonarUtils.SonarEventTypes.CHANGE, this._resizeSonarHandler);
// this._dispatcher.addEventListener("resize", this._resizeHandler);
// this._dispatcher.addEventListener("recalculate-pov", this._recalculatePOVHandler);
}
get camera() {
return this._camera;
}
get roomBound() {
return this._roomBound;
}
recalculateCameraPOV() {
this._cameraProcessor.updatePOV(this);
}
setViewport(width, height) {
this._camera.viewport.width = width;
this._camera.viewport.height = height;
this.resetScaleFactor();
}
setSize(width, height) {
this._roomBound.width = width;
this._roomBound.height = height;
this.resetScaleFactor();
}
destroy() {
this._sonarResize.destroy();
this._cameraProcessor.destroy();
this._camera.destroy();
super.destroy();
}
resetScaleFactor() {
this._camera.maxZoom = DisplayUtils.getRatio(this._roomBound.width, this._roomBound.height, this._camera.viewport.width, this._camera.viewport.height, this._autosize);
}
}
//# sourceMappingURL=base-room.js.map