GLTF And RGBD Texture Settings

Yo @bghgary and @Deltakosh (maybe @sebavan ) … I got a situation where i am exporting HDR Lightmaps (Packed as RGBD 8-Bit PNG)… I need to set the Texture.isRGBD = true from the GLTF Parse… The problem is… Textures use an Internal Texture called _texture that is not available UNTIL the the texture is actually READY

So setting texture.isRGBD = true does nothing until then… So how would i set the isRGBD since there is not Texture.OnReady observable i can hook into…

How can i handle that in GLTF… Can we add a Texture.OnReadyObservable

FYI… I am using loader.loadTextureInfoAsync to load the actual lightmap Texture like this

                    promises.push(this._loader.loadTextureInfoAsync(context + "/lightmapTexture", commonConstant.lightmapTexture, (texture) => {
                        texture.name = `${sourceMaterial.name} (Light Map)`;
                        texture.level = (commonConstant.lightmapLevel) ? commonConstant.lightmapLevel : 1;
                        texture.gammaSpace = false;
                        commonMaterial.lightmapTexture = texture;
                        commonMaterial.useLightmapAsShadowmap = true;
                        if (BABYLON.Utilities.HasOwnProperty(commonMaterial, "ambientColor")) {
                            commonMaterial.ambientColor = BABYLON.Color3.White();
                        }
                        if (this._textureList != null) this._textureList.push(texture);
                    }));

There is an onLoadObservable on texture. Does that work?

I will check… But i seem to remeber the isRgbd flag wrapping under a _texture.isReady call

I think that worked…

                    promises.push(this._loader.loadTextureInfoAsync(context + "/lightmapTexture", commonConstant.lightmapTexture, (texture) => {
                        texture.name = `${sourceMaterial.name} (Light Map)`;
                        texture.level = (commonConstant.lightmapLevel) ? commonConstant.lightmapLevel : 1;
                        texture.gammaSpace = false;
                        // ..
                        // Setup HDR Lightmap Flag On Loaded
                        // ..
                        const realTexture:BABYLON.Texture = texture as BABYLON.Texture;
                        realTexture.onLoadObservable.addOnce(()=>{
                            if (realTexture.isReady()) {
                                realTexture.isRGBD = true;
                            } else {
                                BABYLON.Tools.Warn("Failed to register texture as RGBD: " + realTexture.name);
                            }
                        });
                        commonMaterial.lightmapTexture = texture;
                        commonMaterial.useLightmapAsShadowmap = true;
                        if (BABYLON.Utilities.HasOwnProperty(commonMaterial, "ambientColor")) {
                            commonMaterial.ambientColor = BABYLON.Color3.White();
                        }
                        if (this._textureList != null) this._textureList.push(texture);
                    }));
2 Likes