freealise commited on
Commit
3bb651f
1 Parent(s): afe5230

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -9
app.py CHANGED
@@ -376,15 +376,17 @@ with gr.Blocks(css=css) as demo:
376
  }
377
  var cntxt = document.getElementsByClassName(\"model3D\")[0].getElementsByTagName(\"canvas\")[0].getContext(\"webgl2\");
378
  this.innerText = cntxt;
379
-
380
- BABYLON.Engine.LastCreatedScene.getEngine().onEndFrameObservable.add(function() {
381
- if (BABYLON.Engine.LastCreatedScene.activeCamera.metadata.screenshot === true) {
382
- BABYLON.Engine.LastCreatedScene.activeCamera.metadata.screenshot = false;
383
- try {
384
- BABYLON.Tools.CreateScreenshotUsingRenderTarget(BABYLON.Engine.LastCreatedScene.getEngine(), BABYLON.Engine.LastCreatedScene.activeCamera, { width: 310 }, (durl) => { document.getElementById(\"img_out\").src = durl; });
385
- } catch(e) { alert(e); }
386
- }
387
- });
 
 
388
  '/>webgl2</a><br/><img src='' id='img_out'/>""")
389
  render = gr.Button("Render")
390
 
 
376
  }
377
  var cntxt = document.getElementsByClassName(\"model3D\")[0].getElementsByTagName(\"canvas\")[0].getContext(\"webgl2\");
378
  this.innerText = cntxt;
379
+ BABYLON.Engine.LastCreatedScene.activeCamera.metadata.screenshot = true;
380
+
381
+ BABYLON.Engine.LastCreatedScene.getEngine().onEndFrameObservable.add(function() {
382
+ if (BABYLON.Engine.LastCreatedScene.activeCamera.metadata.screenshot === true) {
383
+ BABYLON.Engine.LastCreatedScene.activeCamera.metadata.screenshot = false;
384
+ try {
385
+ BABYLON.Tools.CreateScreenshotUsingRenderTarget(BABYLON.Engine.LastCreatedScene.getEngine(), BABYLON.Engine.LastCreatedScene.activeCamera, { width: 310 }, (durl) => { document.getElementById(\"img_out\").src = durl; });
386
+ } catch(e) { alert(e); }
387
+ // https://forum.babylonjs.com/t/best-way-to-save-to-jpeg-snapshots-of-scene/17663/11
388
+ }
389
+ });
390
  '/>webgl2</a><br/><img src='' id='img_out'/>""")
391
  render = gr.Button("Render")
392