Jean-Philippe Côté Posted January 14, 2018 Share Posted January 14, 2018 Hello amazing people! I'm using the following code to try to grab a screenshot of my scene and display it in an HTML <img> tag. It seems to be working because my <img> is the same size as my canvas (1280x800). BABYLON.Tools.CreateScreenshot(engine, camera, {precision: 1}, data => { var test = document.createElement('img'); test.src = data; document.body.appendChild(test); }) However, the image is empty (only transparent pixels). Does anyone have an idea of what might be going on? Or something I could try in order to troubleshoot the issue? Thanks. Quote Link to comment Share on other sites More sharing options...
brianzinn Posted January 15, 2018 Share Posted January 15, 2018 I've had better luck with CreateScreenshotUsingRenderTarget. Try without the last 2 params I have added in this snippet, but 16 is samples. BABYLON.Tools.CreateScreenshotUsingRenderTarget( engine, camera, { precision : 1 }, (data) => { ... = data; }, undefined, 16 ); Here is the official docs:https://doc.babylonjs.com/how_to/render_scene_on_a_png#createscreenshotusingrendertarget The last few parameters aren't on the docs page, but can be found here:https://github.com/BabylonJS/Babylon.js/blob/e5101a113cfbca77ed29e541d112ccb14f516573/src/Tools/babylon.tools.ts#L1017 Quote Link to comment Share on other sites More sharing options...
aWeirdo Posted January 15, 2018 Share Posted January 15, 2018 If same size as canvas, you can also just do canvas.toDataURL() var test = document.createElement('img'); test.src = renderCanvas.toDataURL("image/png"); document.body.appendChild(test); Quote Link to comment Share on other sites More sharing options...
Jean-Philippe Côté Posted January 15, 2018 Author Share Posted January 15, 2018 9 hours ago, brianzinn said: I've had better luck with CreateScreenshotUsingRenderTarget. Try without the last 2 params I have added in this snippet, but 16 is samples. Thanks a lot @brianzinn, CreateScreenshotUsingRenderTarget() did work for me. I'm not sure why the CreateScreenshot() method was not working, though. Also, thanks for pointing out the additional parameters. This is how I found the antialiasing flag which I needed. Can we contribute to the documentation? I'd be happy to fill in the blanks in cases such as this one. Cheers! Quote Link to comment Share on other sites More sharing options...
brianzinn Posted January 15, 2018 Share Posted January 15, 2018 Yes, you can contribute to the documentation!! It's a separate repo - here are instructions:https://github.com/BabylonJS/Documentation#how-to-contribute I would use an editor that supports markdown like VS Code. Quote Link to comment Share on other sites More sharing options...
Jean-Philippe Côté Posted January 15, 2018 Author Share Posted January 15, 2018 10 hours ago, aWeirdo said: If same size as canvas, you can also just do canvas.toDataURL() Thanks for you help. However, this is what I tried first and it wasn't working. Not sure why... probably because it's a WebGL canvas instead of the good old 2D canvas. Quote Link to comment Share on other sites More sharing options...
aWeirdo Posted January 15, 2018 Share Posted January 15, 2018 43 minutes ago, Jean-Philippe Côté said: Thanks for you help. However, this is what I tried first and it wasn't working. Not sure why... probably because it's a WebGL canvas instead of the good old 2D canvas. Odd, works fine for mehttp://playground.babylonjs.com/#8P4VBC#5 Pryme8 and Gijs 2 Quote Link to comment Share on other sites More sharing options...
Jean-Philippe Côté Posted January 15, 2018 Author Share Posted January 15, 2018 Hmm... that's strange. I just tried it gain and I couldn't make it work. I'll dig deeper if I get a minute... thanks. Quote Link to comment Share on other sites More sharing options...
Kesshi Posted January 16, 2018 Share Posted January 16, 2018 When you create the BABYLON.Engine the option "preserveDrawingBuffer" has to be enabled. Maybe that helps. Quote Link to comment Share on other sites More sharing options...
Jean-Philippe Côté Posted January 16, 2018 Author Share Posted January 16, 2018 7 hours ago, Kesshi said: When you create the BABYLON.Engine the option "preserveDrawingBuffer" has to be enabled. Maybe that helps. Yes, it does help. Thanks. However, it causes other strange things to happen. I guess you have to manually empty the buffer otherwise some stuff remains visible... That's probably why this option is not even mentioned in the documentation ;-). Anyway, I'm gonna stick to CreateScreenshotUsingRenderTarget() since it is working fine for me. Thanks a lot for your input. Quote Link to comment Share on other sites More sharing options...
Jean-Philippe Côté Posted January 16, 2018 Author Share Posted January 16, 2018 22 hours ago, brianzinn said: Yes, you can contribute to the documentation!! It's a separate repo - here are instructions:https://github.com/BabylonJS/Documentation#how-to-contribute I was thinking more of the API documentation. I stumbled upon a few errors that are bound to trip people up (like it did for me). As far as I can tell, the API doc is generated from source so I guess I'll just submit PRs. Thanks. brianzinn 1 Quote Link to comment Share on other sites More sharing options...
brianzinn Posted January 16, 2018 Share Posted January 16, 2018 public methods would ideally be documented like BABYLON.Tools.Mix(...). https://github.com/BabylonJS/Babylon.js/blob/master/src/Tools/babylon.tools.ts#L93 The docs then show up in the editor and should be generated online looks like by TypeDoc: ... instead of the less helpful CreateScreenshotUsingRenderTarget Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted January 16, 2018 Share Posted January 16, 2018 I wanted to use this thread to thanks all people kind enough to help documenting the API. This is clearly a weakness so far and it will require a big community effort to improve it..So thank you! Quote Link to comment Share on other sites More sharing options...
Jean-Philippe Côté Posted January 16, 2018 Author Share Posted January 16, 2018 4 hours ago, brianzinn said: ... instead of the less helpful CreateScreenshotUsingRenderTarget I thought I'd give a shot at fixing that! https://github.com/BabylonJS/Babylon.js/pull/3557 Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted January 16, 2018 Share Posted January 16, 2018 THANKS! Quote Link to comment Share on other sites More sharing options...
brianzinn Posted January 17, 2018 Share Posted January 17, 2018 https://doc.babylonjs.com/classes/3.0/tools https://doc.babylonjs.com/classes/3.1/tools I was just checking the currently generated "classes" and it looks as though they are no longer in the docs... (ie: was in 3.0?) Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted January 17, 2018 Share Posted January 17, 2018 The documentation is not updated live I will update it by end of week Quote Link to comment Share on other sites More sharing options...
brianzinn Posted January 17, 2018 Share Posted January 17, 2018 @Deltakosh - It's not the live update, but 3.1 is missing entirely most of the Tools functionality compared to 3.0 - even functionality available in 3.0... Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted January 17, 2018 Share Posted January 17, 2018 ouch..ping @Temechon Quote Link to comment Share on other sites More sharing options...
Temechon Posted January 18, 2018 Share Posted January 18, 2018 It's fixed... The documentation class parser is really outdated and should be updated. It's currently deploying, give it few minutes and it will be ok. Thank you ! brianzinn 1 Quote Link to comment Share on other sites More sharing options...
Wingnut Posted January 18, 2018 Share Posted January 18, 2018 It's @Temechon!! Holy crap! Howyadoon, long-time comrade? I hope well. Geez, you sure have been elusive. You must be working on a secret plan to take over the world! Cooooool. Good to see ya! Come visit for the fun of it, sometime, eh? You don't need to wait for a deltaPing to bring you in for coffee/lunch. You're not "out there" trying to "make a living", are ya? Yikes! Making a living is SO over-rated and 1980's. So is "out there". "In here" is lots better. Us's and we's are "in here". Them's and they's are "out there". (huh?) (From Wingy's new book - Bloody Stories from the US-THEM Wars) heh Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.