app
Adom 3D Viewer
Public Made by Adomby adom
The Babylon 9.5 engine behind every component page's 3D tab on wiki.adom.inc. Versioned ESM bundle with GLB loading, view cube, layers toolbar, ground shadows, and Z-up CAD framing.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
import type { ILoadingScreen } from '@babylonjs/core';
import { ADOM_LOGO_BASE64 } from '../assets/adomLogo';
export class ResizableLoadingScreen implements ILoadingScreen {
private _renderingCanvas: HTMLCanvasElement;
private _loadingDiv: HTMLDivElement | null = null;
private _resizeObserver: ResizeObserver | null = null;
public loadingUIText: string;
public loadingUIBackgroundColor: string;
constructor(
renderingCanvas: HTMLCanvasElement,
loadingText: string = 'Loading...',
loadingDivBackgroundColor: string = '#bfbfbf'
) {
this._renderingCanvas = renderingCanvas;
this.loadingUIText = loadingText;
this.loadingUIBackgroundColor = loadingDivBackgroundColor;
}
public displayLoadingUI(): void {
if (this._loadingDiv) return;
this._loadingDiv = document.createElement('div');
this._loadingDiv.id = 'babylonjsLoadingDiv';
this._loadingDiv.style.cssText = `
position: absolute; top: 0; left: 0;
width: 100%; height: 100%;
background-color: ${this.loadingUIBackgroundColor};
display: flex; flex-direction: column;
justify-content: center; align-items: center;
z-index: 1000; pointer-events: none;
`;
const logoImg = document.createElement('img');
logoImg.src = ADOM_LOGO_BASE64;
logoImg.style.cssText = `
max-width: 15%; max-height: 15%;
object-fit: contain; margin-bottom: 20px;
`;
const textDiv = document.createElement('div');
textDiv.innerText = this.loadingUIText;
textDiv.style.cssText = `
color: white; font-size: 14px;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
`;
this._loadingDiv.appendChild(logoImg);
this._loadingDiv.appendChild(textDiv);
const canvasParent = this._renderingCanvas.parentElement;
if (canvasParent) {
canvasParent.appendChild(this._loadingDiv);
this._resizeObserver = new ResizeObserver(() => this._updateSize());
this._resizeObserver.observe(canvasParent);
}
}
public hideLoadingUI(): void {
this._loadingDiv?.remove();
this._loadingDiv = null;
this._resizeObserver?.disconnect();
this._resizeObserver = null;
}
private _updateSize(): void {
if (this._loadingDiv && this._renderingCanvas.parentElement) {
const p = this._renderingCanvas.parentElement;
this._loadingDiv.style.width = `${p.clientWidth}px`;
this._loadingDiv.style.height = `${p.clientHeight}px`;
}
}
}