UNPKG

@polygonjs/polygonjs

Version:

node-based WebGL 3D engine https://polygonjs.com

53 lines (52 loc) 1.39 kB
"use strict"; import { SCENE_EVENT_CREATED_EVENT_CONTEXT, SCENE_EVENT_READY_EVENT_CONTEXT } from "./events/SceneEventsController"; export class LoadingController { constructor(scene) { this.scene = scene; this._loadingState = true; this._autoUpdating = false; } markAsLoading() { this._setLoadingState(true); } markAsLoaded() { this.scene.missingExpressionReferencesController.resolveMissingReferences(); this._setLoadingState(false); this._triggerLoadedEvent(); } dispatchReadyEvent() { if (globalThis.Event) { this.scene.eventsDispatcher.sceneEventsController.dispatch(SCENE_EVENT_READY_EVENT_CONTEXT); } } _triggerLoadedEvent() { if (globalThis.Event) { this.scene.eventsDispatcher.sceneEventsController.dispatch(SCENE_EVENT_CREATED_EVENT_CONTEXT); } } _setLoadingState(state) { this._loadingState = state; this.setAutoUpdate(!this._loadingState); this.scene.cooker.unblock(); } isLoading() { return this._loadingState; } loaded() { return !this._loadingState; } autoUpdating() { return this._autoUpdating; } setAutoUpdate(newState) { if (this._autoUpdating !== newState) { this._autoUpdating = newState; if (this._autoUpdating) { const root = this.scene.root(); if (root) { root.processQueue(); } } } } }