UNPKG

@babylonjs/viewer

Version:

The Babylon Viewer aims to simplify a specific but common Babylon.js use case: loading, viewing, and interacting with a 3D model.

123 lines (119 loc) 4.92 kB
import { G as GetEnvInfo, U as UploadEnvSpherical, a as UploadEnvLevelsAsync } from './environmentTextureTools.pure-LdQWcyA7.esm.js'; import { C as CubeMapToSphericalPolynomialTools } from './cubemapToSphericalPolynomial-BG2bY9zZ.esm.js'; import { p as BaseTexture } from './index-MZPybX0H.esm.js'; import './sphericalPolynomial.pure-BJkHu_AG.esm.js'; import './thinEngine-DdOzAGi4.esm.js'; /** This file must only contain pure code and pure imports */ let _Registered = false; /** * Register side effects for baseTexturePolynomial. * Safe to call multiple times; only the first call has an effect. */ function RegisterBaseTexturePolynomial() { if (_Registered) { return; } _Registered = true; BaseTexture.prototype._sphericalPolynomialTargetSize = 0; BaseTexture.prototype.forceSphericalPolynomialsRecompute = function () { if (this._texture) { this._texture._sphericalPolynomial = null; this._texture._sphericalPolynomialPromise = null; this._texture._sphericalPolynomialComputed = false; } }; Object.defineProperty(BaseTexture.prototype, "sphericalPolynomial", { get: function () { if (this._texture) { if (this._texture._sphericalPolynomial || this._texture._sphericalPolynomialComputed) { return this._texture._sphericalPolynomial; } if (this._texture.isReady) { if (!this._texture._sphericalPolynomialPromise) { this._texture._sphericalPolynomialPromise = CubeMapToSphericalPolynomialTools.ConvertCubeMapTextureToSphericalPolynomial(this); if (this._texture._sphericalPolynomialPromise === null) { this._texture._sphericalPolynomialComputed = true; } else { // eslint-disable-next-line @typescript-eslint/no-floating-promises, github/no-then this._texture._sphericalPolynomialPromise.then((sphericalPolynomial) => { this._texture._sphericalPolynomial = sphericalPolynomial; this._texture._sphericalPolynomialComputed = true; }); } } return null; } } return null; }, set: function (value) { if (this._texture) { this._texture._sphericalPolynomial = value; } }, enumerable: true, configurable: true, }); } /** * Implementation of the ENV Texture Loader. * @internal */ // eslint-disable-next-line @typescript-eslint/naming-convention class _ENVTextureLoader { constructor() { /** * Defines whether the loader supports cascade loading the different faces. */ this.supportCascades = false; } /** * Uploads the cube texture data to the WebGL texture. It has already been bound. * @param data contains the texture data * @param texture defines the BabylonJS internal texture * @param createPolynomials will be true if polynomials have been requested * @param onLoad defines the callback to trigger once the texture is ready * @param onError defines the callback to trigger in case of error */ loadCubeData(data, texture, createPolynomials, onLoad, onError) { if (Array.isArray(data)) { return; } const info = GetEnvInfo(data); if (info) { texture.width = info.width; texture.height = info.width; try { RegisterBaseTexturePolynomial(); UploadEnvSpherical(texture, info); // eslint-disable-next-line github/no-then UploadEnvLevelsAsync(texture, data, info).then(() => { texture.isReady = true; texture.onLoadedObservable.notifyObservers(texture); texture.onLoadedObservable.clear(); if (onLoad) { onLoad(); } }, (reason) => { onError?.("Can not upload environment levels", reason); }); } catch (e) { onError?.("Can not upload environment file", e); } } else if (onError) { onError("Can not parse the environment file", null); } } /** * Uploads the 2D texture data to the WebGL texture. It has already been bound once in the callback. */ loadData() { // eslint-disable-next-line no-throw-literal throw ".env not supported in 2d."; } } export { _ENVTextureLoader }; //# sourceMappingURL=envTextureLoader-DP2RdHAG.esm.js.map