Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenEXR support #4706

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion src/components/gltf-model-plus.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect this was to do with decoding the RGBM which shouldn't be a factor here, the mips should blend more smoothly here since EXR actually uses float values from the start. Didn't test it obviously.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. I'll remove and check.

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;
Expand All @@ -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
Expand Down