Ignore file extension of external glTF buffers#2615
Ignore file extension of external glTF buffers#2615javagl wants to merge 1 commit intojMonkeyEngine:masterfrom
Conversation
|
Conceptually it's ok, but i wonder if this could cause unexpected issues since it is faking the file extension. |
That's what I've been wondering about, but it's hard (for me) to find a definite answer to that - I'm not familar with the asset manager and loader code, and from a quick dive and a short debuggstepping, it seemed to be a reasonable solution. To my understanding, the
I considered to add If the current change is considered to be "too dangerous" (in terms of side-effects), then this could be an option. |
|
I'd like to hear others' opinion on this @jMonkeyEngine/contributors . |
|
I don't have strong opinions here (due to my lack of background knowledge). But regarding this:
One reason for using a However, it's certainly not the most important fix, because I'll have another look at other glTF-related issues (e.g. models failing to load), maybe there are a few "simple" ones to tackle first. |
Already mentioned in #2118 (comment) :
A
.gltffile may refer to arbitrary external (binary) data, using a URI. The specification recommends to give these files a.binor.glbinextension, but this is not required.Right now, trying to load a file where such an external buffer does not have a
.binfile extension will cause a crash.This PR changes the behavior: It causes the actual file extension to be ignored.
I'm not entirely sure whether the approach here is the "right" one (or what the "best" approach is). What I gathered so far:
AssetKeyextensionAssetKey, there is a lookup mechanism for loaders, based on the file extensionGeneral.cfgestablishes the mapping ofLOADER com.jme3.scene.plugins.gltf.BinLoader : binto use that
BinLoaderfor assets with thebinextensionThe main change here now is that the existing
BinDataKeythat was used for external glTF buffer references sets itsextensiontobin, regardless of the actual extension.I've tested it with these files:
TriangleWithDifferentExternalExtensions-2026-02-15.zip
They can be loaded from the
TestGltfLoadingclass, by putting them into the example data, and loading them with either ofMore generally: Trying to determine a file type based on a file extension is usually brittle and not sufficient in many cases. But... I know that everything that is going beyond that can be tricky. Many files have "magic bytes" that can be used for identifying the file type. But eventually, loaders may have to differentiate between different JSON files, and at this point, there is no way around parsing the whole thing and making guesses (!) based on the presence of absence of certain properties. I think that for the case of the glTF
.binfiles, the current approach should be OK. One could consider changing the registration and extension toLOADER com.jme3.scene.plugins.gltf.BinLoader : glbin,because
glbinis ait more specific thanbin, but that can be done at any point in time now.