diff --git a/src/components/gltf-model-plus.js b/src/components/gltf-model-plus.js index 0d621a6216..77cae07d37 100644 --- a/src/components/gltf-model-plus.js +++ b/src/components/gltf-model-plus.js @@ -8,6 +8,7 @@ import { disposeNode, cloneObject3D } from "../utils/three-utils"; import HubsTextureLoader from "../loaders/HubsTextureLoader"; import { KTX2Loader } from "three/examples/jsm/loaders/KTX2Loader"; import { RGBELoader } from "three/examples/jsm/loaders/RGBELoader"; +import { EXRLoader } from "three/examples/jsm/loaders/EXRLoader"; THREE.Mesh.prototype.raycast = acceleratedRaycast; @@ -591,6 +592,36 @@ class GLTFMozTextureRGBE { } } +class GLTFMozTextureEXR { + constructor(parser, loader) { + this.parser = parser; + this.loader = loader; + this.name = "MOZ_texture_exr"; + } + + loadTexture(textureIndex) { + const parser = this.parser; + const json = parser.json; + const textureDef = json.textures[textureIndex]; + + if (!textureDef.extensions || !textureDef.extensions[this.name]) { + return null; + } + + const extensionDef = textureDef.extensions[this.name]; + const source = json.images[extensionDef.source]; + return parser.loadTextureImage(textureIndex, source, this.loader).then(t => { + // TODO pretty severe artifacting when using mipmaps, disable for now (assumption copied from GLTFMozTextureRGBE) + if (t.minFilter == THREE.NearestMipmapNearestFilter || t.minFilter == THREE.NearestMipmapLinearFilter) { + t.minFilter = THREE.NearestFilter; + } else if (t.minFilter == THREE.LinearMipmapNearestFilter || t.minFilter == THREE.LinearMipmapLinearFilter) { + t.minFilter = THREE.LinearFilter; + } + return t; + }); + } +} + export async function loadGLTF(src, contentType, onProgress, jsonPreprocessor) { let gltfUrl = src; let fileMap; @@ -608,7 +639,8 @@ export async function loadGLTF(src, contentType, onProgress, jsonPreprocessor) { .register(parser => new GLTFHubsPlugin(parser, jsonPreprocessor)) .register(parser => new GLTFHubsLightMapExtension(parser)) .register(parser => new GLTFHubsTextureBasisExtension(parser)) - .register(parser => new GLTFMozTextureRGBE(parser, new RGBELoader().setDataType(THREE.HalfFloatType))); + .register(parser => new GLTFMozTextureRGBE(parser, new RGBELoader().setDataType(THREE.HalfFloatType))) + .register(parser => new GLTFMozTextureEXR(parser, new EXRLoader().setDataType(THREE.HalfFloatType))); // TODO some models are loaded before the renderer exists. This is likely things like the camera tool and loading cube. // They don't currently use KTX textures but if they did this would be an issue. Fixing this is hard but is part of