GLTF ReflectionTexture (CubeTexture) DDS

Yo @bghgary is there a system in place to load CubeTexture .dds files as matieral.reflectionTexture… Maybe something like loadTextureInfoAsync

Does loadMaterialPropertiesAsync work? If not, can you provide a bit more context?

So are you saying that ** loadMaterialPropertiesAsync** already loads material.reflectionTexture with a BABYLON.CubeTexture ?

I dont see that support… So i basically am asking how (if possible) would i use loadTextureInfoAsync to load a prefiltered CubeTexure .dds file as material.reflectionTexture ?

hopefully something like this:

promises.push(this.loadTextureInfoAsync(`${context}/reflectionTexture`, material.reflectionTexture, (texture) => {
  texture.name = `${babylonMaterial.name} (Reflection)`;
  babylonMaterial.reflectionTexture = texture;
}));

Ahh, no, I misunderstood your question. No, there is currently no function that can load a CubeTexture. The function that is called eventually is _createTextureAsync which always creates a BABYLON.Texture right now.

So @bghgary how would you suggest i load a .dds or .env as a material.reflectionTexture within my GLTF Loader extension.

I dont think CubeTexture have a updateURL that take an arrybuffer like the texture.updateUrl does…

i would love to able to load a .dds/.env and have its progress reflected in the the loader.onProgress…
Any help on how i would handle this would be great :slight_smile:

If you need to load an env like environment, you can just use the EXT_lights_image_based extension.

Spec: glTF/README.md at master · KhronosGroup/glTF · GitHub

Implementation: Babylon.js/EXT_lights_image_based.ts at master · BabylonJS/Babylon.js (github.com)

Sample: Babylon.js - EnvironmentTest.gltf

What i am actually trying to do is set the material.reflectionTexture from .dds or .env

The stuff above is for lighting… Is there some kind of way to set the CubeTexture with the ArrayBuffer data from internal file loader

loader._parent._loadFile(url, loader._babylonScene, (data) => {
  if (!loader._disposed) {
    loader.log(`${context}: Loaded ${uri} (${(data as ArrayBuffer).byteLength} bytes)`);
    resolve(new Uint8Array(data as ArrayBuffer));
 }
}, true, (request) => {
  reject(new BABYLON.LoadFileError(`${context}: Failed to load '${uri}'${request ? ": " + request.status + " " + request.statusText : ""}`, request));
});

Then try and create a CubeTexture with the blob url or something like that…???

const textureBlobUrl = URL.createObjectURL(new Blob([data]));

If you look at the links I sent, it creates a RawCubeTexture which supports loading data directly without a url.

Yo @bghgary

We must be on a different page with each other. But basically the RawCubeTexture approach seems to me that somewhere some extension decoded the individual faces of the cube texture and RGBD packed images directly in the GLTF.

What i have is a url to a DDS or ENV … the DDS was generated at design time with CMFT.
I wanna use the single file DDS or the compressed ENV version of the cube texture as a material.reflectionTexture

So the approach above would not work WITHOUT actually re-encoding the dds into some EXT_light_ext format for cube faces image data in the GLTF

But i think i came up with my own solution that seems to work fine… THUS FAR

First off all… I created my own version of the loadUriAsync that i call loadDataUrlAsync whose job is just to take a url and download the raw arraybuffer data using the loader._parent._loadFile

Now that allow me to easily download ANY content from a valid url and have its progress accounted for in the scene loader on progress event

I then use createObjectURL and the cubeTexture.updateURL then to assign the raw data to an instance of cubeTexture and store that on material.reflectionTexture from within my custom updateCustomMaterialPropertiesAsync in my custom GLTF Loader like so:

Seems to working so far… I still keep working on and hopefully this approach works out :slight_smile:

@bghgary

That would be sweet if we can make the cubeTexture update itself with the single blob data representing the entire dds file by making the updateURLWithData(urlForShow, data, …) like the texture.UpdateURL(url, data) … I could save some resources by not having to createObjectURL and revokeObjectURL for the blob data, but just pass the arraybuffer data directly cubeTexture.updateURL

Seems like a good idea. Would you be interested in making this change?