Taking Screenshot with Create Screenshot Using Render Target

Hi all,

My scene is a complex scene.
To get a screenshot using CreateScreenshotUsingRenderTarget, we need to wait for the scene to be fully rendered. I tried with the below two approaches but none of them are working as expected. I am getting only the background in the image.

Please help me.
Thanks in advance.

CameraHelper.TakeScreenshotInMemory1 = function (camera, callback) {
            var scene = camera.getScene();
            var engine = scene.getEngine();

            var current = scene.afterRender;
            scene.afterRender = function () {
                scene.afterRender = current;
                BABYLON.Tools.CreateScreenshotUsingRenderTarget(engine, camera, { precision: 1 }, callback);
            };
            scene.render();
        };

        CameraHelper.TakeScreenshotInMemory2 = function (camera, callback) {
            var scene = camera.getScene();
            var engine = scene.getEngine();
            
            var func = function () {
                scene.unregisterAfterRender(func);
                BABYLON.Tools.CreateScreenshotUsingRenderTarget(engine, camera, { precision: 1 }, callback);
            };
            scene.registerAfterRender(func);
            scene.render();
        };

And if you use a setTimeout does it work? Just to make sure that the problem is timing

if this is the case you may want to use scene.executeWhenReady()

I am calling these methods in executeWhenReady() only. No luck

and if you add a setTimeout?

It works with setTimeout

It works with setTimeout but it approach is not proper. We need to hardcode a value. I need a good solution.

sure it was just to be sure that is was a timing issue :wink:

can you tell me more about the scene? are you using shadows? PBR, special effects?

The scene is an apartment designed in maya and exported to Babylon. No PBR, No Shadows, No Special effects.

Hum…I need to see it then to understand why something is not ready for the screen capture.
Can you share a repro somewhere?

If you remember, Few days back I have sent you a personal message in which I shared you link of my model. (My gdrive). Will you be able to download my model using that link?

Woot here? I feel sorry but I did not see it

Is that on this forum messaging system?

btw I do not need the model but a running page that I can debug :slight_smile: