@inweb/viewer-visualize
Version:
JavaScript library for rendering CAD and BIM files in a browser using VisualizeJS
38 lines (30 loc) • 848 B
text/typescript
import { Viewer } from "../Viewer";
const DELAY_TIME_MULTIPLEXER = 2.0;
const START_UPDATE_TIME = 1000;
export enum UpdateType {
kDelay,
kNormal,
kForce,
}
export class UpdaterController {
private lastUpdate: number;
private viewer: Viewer;
public delayUpdateTime: number;
constructor() {
this.lastUpdate = 0;
this.delayUpdateTime = START_UPDATE_TIME;
}
initialize(viewer: Viewer) {
this.viewer = viewer;
this.lastUpdate = performance.now();
}
update(type: UpdateType) {
const isNeedUpdate = type !== UpdateType.kDelay || performance.now() - this.lastUpdate >= this.delayUpdateTime;
const isForce = type === UpdateType.kForce;
if (isNeedUpdate) {
this.viewer.update(isForce);
this.lastUpdate = performance.now();
this.delayUpdateTime *= DELAY_TIME_MULTIPLEXER;
}
}
}