You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Bring the OBJ/MTL loader to parity with the glTF external-texture support added in #1504: when a material references a texture via map_Kd, load that image automatically (resolved relative to the .mtl folder) so the user no longer has to preload it separately.
Current behavior
preloadMTL parses the .mtl and stores map_Kd as a path string relative to the file, but never loads the image:
// packages/melonjs/src/loader/parsers/mtl.jscurrent.map_Kd=basePath+parts.slice(1).join(" ");// path only — not fetched
At mesh-build time resolveTextureAtlas(mat.map_Kd) → getImage(mat.map_Kd) is a lookup of an already-preloaded image, not a fetch. So today the user must preload all three pieces and either pass texture: explicitly or preload the image under the matching map_Kd key:
If the third line is forgotten, the mesh renders untextured (white-pixel fallback).
Desired behavior
The texture image preload becomes optional. With just the model + material preloaded, the map_Kd texture is auto-resolved relative to the .mtl and loaded:
loader.preload([{name: "fox",type: "obj",src: "fox.obj"},{name: "fox",type: "mtl",src: "fox.mtl"},// textures come for free]);newMesh(0,0,{model: "fox",material: "fox"});// no `texture:` needed
This mirrors the one-call glTF experience (preload the .glb, its external texture is fetched automatically).
Implementation sketch
In preloadMTL (mtl.js): after parsing, for each material with a map_Kd, kick off loading that image (the path is already resolved as basePath + filename), registering it in the loader cache so it's available when the mesh is built. Honor loader settings (crossOrigin / nocache), same as feat(gltf): node animation + Sprite-aligned animation API; Light3d as a world renderable #1504's glTF path.
The relative-resolution already exists; the missing piece is the fetch + registration (and making preloadMTL's returned resource count / onload await the textures, so the loader's progress + completion callback include them).
Mesh already falls back to mat.map_Kd when no explicit texture: is given (mesh.js) — once the image is registered under that key, auto-resolution just works.
Backward compatibility
Explicit settings.texture still wins (unchanged).
The existing "preload the image yourself" flow keeps working (the auto-load registers under the same map_Kd path key).
Summary
Bring the OBJ/MTL loader to parity with the glTF external-texture support added in #1504: when a material references a texture via
map_Kd, load that image automatically (resolved relative to the.mtlfolder) so the user no longer has to preload it separately.Current behavior
preloadMTLparses the.mtland storesmap_Kdas a path string relative to the file, but never loads the image:At mesh-build time
resolveTextureAtlas(mat.map_Kd)→getImage(mat.map_Kd)is a lookup of an already-preloaded image, not a fetch. So today the user must preload all three pieces and either passtexture:explicitly or preload the image under the matchingmap_Kdkey:If the third line is forgotten, the mesh renders untextured (white-pixel fallback).
Desired behavior
The texture image preload becomes optional. With just the model + material preloaded, the
map_Kdtexture is auto-resolved relative to the.mtland loaded:This mirrors the one-call glTF experience (preload the
.glb, its external texture is fetched automatically).Implementation sketch
preloadMTL(mtl.js): after parsing, for each material with amap_Kd, kick off loading that image (the path is already resolved asbasePath + filename), registering it in the loader cache so it's available when the mesh is built. Honor loadersettings(crossOrigin / nocache), same as feat(gltf): node animation + Sprite-aligned animation API; Light3d as a world renderable #1504's glTF path.preloadMTL's returned resource count / onload await the textures, so the loader's progress + completion callback include them).Meshalready falls back tomat.map_Kdwhen no explicittexture:is given (mesh.js) — once the image is registered under that key, auto-resolution just works.Backward compatibility
settings.texturestill wins (unchanged).map_Kdpath key).Cross-refs
.bin/image auto-fetch this mirrors (resolveURI/decodeImageingltf.js).