freealise commited on
Commit
a88f03a
1 Parent(s): 28281af

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -25
app.py CHANGED
@@ -344,7 +344,7 @@ with gr.Blocks(css=css) as demo:
344
  this.parentNode.childNodes[2].innerText = BABYLON.Engine.LastCreatedScene.activeCamera.fov;
345
  document.getElementsByClassName(\"model3D\")[0].getElementsByTagName(\"canvas\")[0].style.filter = \"blur(\" + BABYLON.Engine.LastCreatedScene.getNodes()[1].material.pointSize/Math.sqrt(2.0) + \"px)\";
346
  '/><span>0.8</span>""")
347
- parallax = gr.HTML(value="""<label for='parallax'>Parallax</label><input id='parallax' type='range' style='width:256px;height:1em;' min='-8' max='8' step='0.001' oninput='
348
  if (!BABYLON.Engine.LastCreatedScene.activeCamera.metadata) {
349
  BABYLON.Engine.LastCreatedScene.activeCamera.metadata = {
350
  screenshot: true,
@@ -352,15 +352,15 @@ with gr.Blocks(css=css) as demo:
352
  }
353
  }
354
  BABYLON.Engine.LastCreatedScene.activeCamera.metadata.pipeline.samples = 4;
355
- try {
356
- var camera = BABYLON.Engine.LastCreatedScene.activeCamera;
357
-
358
- BABYLON.Engine.LastCreatedScene.getNodes()[1].position.z = this.value * Math.cos(camera.alpha) * Math.sin(camera.beta);
359
  BABYLON.Engine.LastCreatedScene.getNodes()[1].position.y = 0;
360
- BABYLON.Engine.LastCreatedScene.getNodes()[1].position.x = this.value * Math.sin(camera.alpha) * Math.sin(camera.beta);
361
-
362
- this.parentNode.childNodes[2].innerText = this.value;
363
- } catch(e) {alert(e);}
 
 
364
  '/><span>0.0</span>""")
365
  camera = gr.HTML(value="<a href='#' onclick=\"BABYLON.Engine.LastCreatedScene.activeCamera.radius=0;\">reset camera</a>")
366
  contrast = gr.HTML(value="""<label for='contrast'>Contrast</label><input id='contrast' type='range' style='width:256px;height:1em;' min='0' max='2' step='0.001' oninput='
@@ -394,7 +394,6 @@ with gr.Blocks(css=css) as demo:
394
  }
395
  var cntxt = document.getElementsByClassName(\"model3D\")[0].getElementsByTagName(\"canvas\")[0].getContext(\"webgl2\");
396
  this.innerText = cntxt;
397
- var ctx = document.getElementById(\"cnv_out\").getContext(\"2d\");
398
  BABYLON.Engine.LastCreatedScene.activeCamera.metadata.screenshot = true;
399
 
400
  BABYLON.Engine.LastCreatedScene.getEngine().onEndFrameObservable.add(function() {
@@ -404,26 +403,29 @@ with gr.Blocks(css=css) as demo:
404
  BABYLON.Tools.CreateScreenshotUsingRenderTarget(BABYLON.Engine.LastCreatedScene.getEngine(), BABYLON.Engine.LastCreatedScene.activeCamera,
405
  { precision: 1.0 }, (durl) => {
406
  document.getElementById(\"img_out\").onload = function() {
407
- document.getElementById(\"cnv_out\").width = document.getElementById(\"img_out\").width;
408
- document.getElementById(\"cnv_out\").height = document.getElementById(\"img_out\").height;
409
- ctx.drawImage(img_out, 0, 0);
 
 
 
 
 
 
 
 
 
 
 
410
  }
411
- var svgd = `<svg id=\"svg_out\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">
412
- <defs>
413
- <filter id=\"blur\" x=\"0\" y=\"0\" xmlns=\"http://www.w3.org/2000/svg\">
414
- <feGaussianBlur in=\"SourceGraphic\" stdDeviation=\"` + BABYLON.Engine.LastCreatedScene.getNodes()[1].material.pointSize/Math.sqrt(2.0) + `\" />
415
- </filter>
416
- </defs>
417
- <image filter=\"url(#blur)\" id=\"svg_img\" x=\"0\" y=\"0\" width=\"` + document.getElementById(\"img_out\").width + `\" height=\"` + document.getElementById(\"img_out\").height + `\" xlink:href=\"` + durl + `\"/>
418
- </svg>`;
419
- document.getElementById(\"img_out\").src = \"data:image/svg+xml;base64,\" + btoa(svgd);
420
- });
421
  } catch(e) { alert(e); }
422
  // https://forum.babylonjs.com/t/best-way-to-save-to-jpeg-snapshots-of-scene/17663/11
423
  }
424
  });
425
- '/>webgl2</a><br/><img src='' id='img_out'/>
426
- <div id='svg_div'></div>
427
  <canvas id='cnv_out'/>""")
428
  render = gr.Button("Render")
429
 
 
344
  this.parentNode.childNodes[2].innerText = BABYLON.Engine.LastCreatedScene.activeCamera.fov;
345
  document.getElementsByClassName(\"model3D\")[0].getElementsByTagName(\"canvas\")[0].style.filter = \"blur(\" + BABYLON.Engine.LastCreatedScene.getNodes()[1].material.pointSize/Math.sqrt(2.0) + \"px)\";
346
  '/><span>0.8</span>""")
347
+ parallax = gr.HTML(value="""<label for='parallax'>Parallax</label><input id='parallax' type='range' style='width:256px;height:1em;' min='-16' max='16' step='0.001' oninput='
348
  if (!BABYLON.Engine.LastCreatedScene.activeCamera.metadata) {
349
  BABYLON.Engine.LastCreatedScene.activeCamera.metadata = {
350
  screenshot: true,
 
352
  }
353
  }
354
  BABYLON.Engine.LastCreatedScene.activeCamera.metadata.pipeline.samples = 4;
355
+ document.getElementsByClassName(\"model3D\")[0].getElementsByTagName(\"canvas\")[0].onfocus = function() {
356
+ BABYLON.Engine.LastCreatedScene.getNodes()[1].position.z = 0;
 
 
357
  BABYLON.Engine.LastCreatedScene.getNodes()[1].position.y = 0;
358
+ BABYLON.Engine.LastCreatedScene.getNodes()[1].position.x = 0;
359
+ }
360
+ BABYLON.Engine.LastCreatedScene.getNodes()[1].position.z = this.value * Math.cos(BABYLON.Engine.LastCreatedScene.activeCamera.alpha) * Math.sin(BABYLON.Engine.LastCreatedScene.activeCamera.beta);
361
+ BABYLON.Engine.LastCreatedScene.getNodes()[1].position.y = 0;
362
+ BABYLON.Engine.LastCreatedScene.getNodes()[1].position.x = this.value * Math.sin(BABYLON.Engine.LastCreatedScene.activeCamera.alpha) * Math.sin(BABYLON.Engine.LastCreatedScene.activeCamera.beta);
363
+ this.parentNode.childNodes[2].innerText = this.value;
364
  '/><span>0.0</span>""")
365
  camera = gr.HTML(value="<a href='#' onclick=\"BABYLON.Engine.LastCreatedScene.activeCamera.radius=0;\">reset camera</a>")
366
  contrast = gr.HTML(value="""<label for='contrast'>Contrast</label><input id='contrast' type='range' style='width:256px;height:1em;' min='0' max='2' step='0.001' oninput='
 
394
  }
395
  var cntxt = document.getElementsByClassName(\"model3D\")[0].getElementsByTagName(\"canvas\")[0].getContext(\"webgl2\");
396
  this.innerText = cntxt;
 
397
  BABYLON.Engine.LastCreatedScene.activeCamera.metadata.screenshot = true;
398
 
399
  BABYLON.Engine.LastCreatedScene.getEngine().onEndFrameObservable.add(function() {
 
403
  BABYLON.Tools.CreateScreenshotUsingRenderTarget(BABYLON.Engine.LastCreatedScene.getEngine(), BABYLON.Engine.LastCreatedScene.activeCamera,
404
  { precision: 1.0 }, (durl) => {
405
  document.getElementById(\"img_out\").onload = function() {
406
+ var svgd = `<svg id=\"svg_out\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">
407
+ <defs>
408
+ <filter id=\"blur\" x=\"0\" y=\"0\" xmlns=\"http://www.w3.org/2000/svg\">
409
+ <feGaussianBlur in=\"SourceGraphic\" stdDeviation=\"` + BABYLON.Engine.LastCreatedScene.getNodes()[1].material.pointSize/Math.sqrt(2.0) + `\" />
410
+ </filter>
411
+ </defs>
412
+ <image filter=\"url(#blur)\" id=\"svg_img\" x=\"0\" y=\"0\" width=\"` + document.getElementById(\"img_out\").width + `\" height=\"` + document.getElementById(\"img_out\").height + `\" xlink:href=\"` + durl + `\"/>
413
+ </svg>`;
414
+ document.getElementById(\"img_out\").onload = function() {
415
+ document.getElementById(\"cnv_out\").width = document.getElementById(\"img_out\").width;
416
+ document.getElementById(\"cnv_out\").height = document.getElementById(\"img_out\").height;
417
+ document.getElementById(\"cnv_out\").getContext(\"2d\").drawImage(img_out, 0, 0);
418
+ }
419
+ document.getElementById(\"img_out\").src = \"data:image/svg+xml;base64,\" + btoa(svgd);
420
  }
421
+ document.getElementById(\"img_out\").src = durl;
422
+ }
423
+ );
 
 
 
 
 
 
 
424
  } catch(e) { alert(e); }
425
  // https://forum.babylonjs.com/t/best-way-to-save-to-jpeg-snapshots-of-scene/17663/11
426
  }
427
  });
428
+ '/>webgl2</a><br/><img src='' id='img_out'/><br/>
 
429
  <canvas id='cnv_out'/>""")
430
  render = gr.Button("Render")
431