Cannot capture screenshot (thumbnail) from drag'n'dropped file

Hi, I am trying to get the below PG to work but cannot get the image data from screenshot. No errors, the container from dropped GLB looks fine, but no callback with image data after calling ‘CreateScreenshotUsingRenderTarget’

Where does it go wrong?

This is because CreateScreenshotUsingRenderTarget depends on engine.onEndFrameObservable being triggered, and because you don’t setup a render loop for the sub-engine, that observable is not raised.

You could manually notify it after calling CreateScreenshotUsingRenderTarget, but there’s an additional difficulty because you set antialias to true. Because of that, a Fxaa post-process is created, which may (will) not be ready in the current frame, so the observer won’t be pushed to engine.onEndFrameObservable in the current frame an calling engine.onEndFrameObservable.notifyObservers will have no effect.

You need to actively check that the observer has been added to the observable, by doing something like:

Also, note that scene.clearColor is a color4, not a color3.

3 Likes