MONOGRID / gainmap-js

A Javascript (TypeScript) Port of Adobe Gainmap Technology for storing HDR Images using an SDR Image + a gainmap
https://monogrid.github.io/gainmap-js/
MIT License
82 stars 5 forks source link

.setRenderer(gl) on the LoaderBase class #33

Closed drcmda closed 6 months ago

drcmda commented 6 months ago

Would it be possible to make the gl inject optional + an additional .setRenderer(gl) method on the loader (the LoaderBase class to be exact)? so that the end user can do:

const loader = new HDRJPGLoader()
loader.setRenderer(gl)

the THREE.Loader interface doesn't have a common interface because three lacks types, but it can generally be assumed that it is no parameters on the constructor + set functions, that's how most (all?) loaders worked. for instance:

const gltf = new GLTFLoader()
gltf.setDRACOLoader(new DRACOLoader())

this becomes important once you have loader managing layers that rely on uniform structure. one such example is react-three-fibers useLoader, but tresjs, threlte etc will run into the same problems.

current workaround: https://codesandbox.io/p/sandbox/sleepy-jackson-hqct6n?file=%2Fsrc%2FApp.js%3A35%2C3-35%2C101

const quad = useLoader(HDRJPGLoader, 'spruit_sunrise_4k.jpg', (loader) => (loader._renderer = gl))

we would like to add a shortcut/helper to drei but we can't rely on internals for that, it would be too risky. if we can rely on the api users would then be able to just do

<Environment files="spruit_sunrise_4k.jpg" />
daniele-pelagatti commented 6 months ago

@drcmda let me know if #34 solved your issue, thanks!