I’m trying to pre-render orthographic images of blocks via screenshotting for a project I’m working on, but have ran into two issues (I’ve read through the docs, maybe I’ve missed something and they aren’t bugs).
The first issue is that if I attempt to screenshot with a camera that isn’t the active camera, the resulting image is blank.
The second is that regardless of the width/height ratio I specify for size, the ratio of the screenshot seems to be that of the canvas. Try squashing the browser window and see how it turns out.
Well, your workaround does work I’ll give you that
I was hoping to have all the icons and whatnot be generated dynamically, so if I needed to add another ‘block’ in the future (you can probably guess at the nature of my project now!) I wouldn’t need to create any other assets.
By momentarily setting the active camera to the orthogonal preview one and changing the canvas ratio just before rendering, and restoring them after, I can get the result I want. Technically works, but feels very dodgy and doesn’t seem to match the description in the docs (why does screenshot have a parameter for camera if it’s only going to use the scene’s active one, and why allow setting a custom resolution if the ratio is fixed to that of the canvas, wouldn’t you then just use precision?)
The function you want to use is CreateScreenshotUsingRenderTarget.
CreateScreenshot uses camera only to get the aspect ratio if you don’t provide both width and height, but it is not used for the rendering: the function takes the current canvas to create the screenshot.
In my testings, the width/height you pass are correctly taken into account, but the screenshot is empty because of some delayed available resources it seems: when doing it in a setTimeout(…, 1000) it does work.
Anyway, just use CreateScreenshotUsingRenderTarget and it will work out of the box.
In my example I couldn’t get the width/height to work correctly, but no matter, the CreateScreenshotUsingRenderTarget method worked a treat! Thanks for explaining it