diff --git a/src/plugins/three/gltf/metadata/utilities/TextureReadUtility.js b/src/plugins/three/gltf/metadata/utilities/TextureReadUtility.js index be9d43305..df1f5da31 100644 --- a/src/plugins/three/gltf/metadata/utilities/TextureReadUtility.js +++ b/src/plugins/three/gltf/metadata/utilities/TextureReadUtility.js @@ -4,7 +4,7 @@ import { FullScreenQuad } from 'three/examples/jsm/postprocessing/Pass.js'; const _box = /* @__PURE__ */ new Box2(); // Utility for reading sets of individual pixel values from textures -export const TextureReadUtility = new ( class { +class _TextureReadUtility { constructor() { @@ -88,4 +88,32 @@ export const TextureReadUtility = new ( class { } +} + +// Create a wrapper class to defer instantiation of the WebGLRenderer until it's needed +// See NASA-AMMOS/3DTilesRendererJS#905 +export const TextureReadUtility = /* @__PURE__ */ new ( class { + + constructor() { + + let reader = null; + Object + .getOwnPropertyNames( _TextureReadUtility.prototype ) + .forEach( key => { + + if ( key !== 'constructor' ) { + + this[ key ] = ( ...args ) => { + + reader = reader || new _TextureReadUtility(); + return reader[ key ]( ...args ); + + }; + + } + + } ); + + } + } )();