2

I am trying to take a 'snapshot' of a babylon3d scene ... in other words: I am trying to clone a babylon3d canvas when a user presses a button, and then append the new <canvas> to the <body> .. Sometimes it works, but other times it does not.

However, if I use a simple canvas (ie. by using fillRect), the cloning/appending always works as expected.

I have set up a test on plunker to demonstrate my problem: plunker: press the button over and over again to see how sporadic it behaves when there is a babylon scene. AND NOTE: You can toggle between the simple canvas and the babylon canvas from within the _jquery(document).ready(...) handler.

thanks, Shannon
dsdsdsdsd
  • 2,880
  • 6
  • 41
  • 56

1 Answers1

0

This is because from version 2.3.0 of Babylonjs :

Engine now initialize WebGL with preserveDrawingBuffer = false by default.

You need to initialize the Engine by passing a {preserveDrawingBuffer: true} object as third parameter.

Forked plnkr

But this will unfortunately kill your canvas' performances.

See more about it here.

I'm not really a specialist of Babylonjs, and I didn't find a way to make a call from scene.render method where we could use the flag method proposed by @CapsE. But there is a BABYLON.Tools.CreateScreenshot(engine, camera, size) method, which will make a downloadable png from your scene ; maybe this could help you.

Community
  • 1
  • 1
Kaiido
  • 123,334
  • 13
  • 219
  • 285