Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -344,32 +344,6 @@ 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='-1' max='1' step='0.001' oninput='
|
348 |
-
if (!BABYLON.Engine.LastCreatedScene.activeCamera.metadata) {
|
349 |
-
BABYLON.Engine.LastCreatedScene.activeCamera.metadata = {
|
350 |
-
screenshot: true,
|
351 |
-
pipeline: new BABYLON.DefaultRenderingPipeline(\"default\", true, BABYLON.Engine.LastCreatedScene, [BABYLON.Engine.LastCreatedScene.activeCamera])
|
352 |
-
}
|
353 |
-
}
|
354 |
-
BABYLON.Engine.LastCreatedScene.activeCamera.metadata.pipeline.samples = 4;
|
355 |
-
document.getElementsByClassName(\"model3D\")[0].getElementsByTagName(\"canvas\")[0].onpointerdown = function() {
|
356 |
-
BABYLON.Engine.LastCreatedScene.activeCamera.setTarget(BABYLON.Engine.LastCreatedScene.activeCamera.metadata.zero);
|
357 |
-
BABYLON.Engine.LastCreatedScene.activeCamera.radius = 0;
|
358 |
-
}
|
359 |
-
try {
|
360 |
-
var x = -255 * Math.cos(BABYLON.Engine.LastCreatedScene.activeCamera.alpha) * Math.sin(BABYLON.Engine.LastCreatedScene.activeCamera.beta)
|
361 |
-
var y = -255 * Math.cos(BABYLON.Engine.LastCreatedScene.activeCamera.beta)
|
362 |
-
var z = -255 * Math.sin(BABYLON.Engine.LastCreatedScene.activeCamera.alpha) * Math.sin(BABYLON.Engine.LastCreatedScene.activeCamera.beta)
|
363 |
-
|
364 |
-
BABYLON.Engine.LastCreatedScene.activeCamera.metadata.zero = new BABYLON.Vector3(0,0,0);
|
365 |
-
BABYLON.Engine.LastCreatedScene.activeCamera.metadata.CoR_At = new BABYLON.Vector3(x, y, z);
|
366 |
-
|
367 |
-
BABYLON.Engine.LastCreatedScene.activeCamera.setTarget(BABYLON.Engine.LastCreatedScene.activeCamera.metadata.CoR_At);
|
368 |
-
BABYLON.Engine.LastCreatedScene.activeCamera.radius = 255;
|
369 |
-
BABYLON.Engine.LastCreatedScene.activeCamera.alpha = this.value;
|
370 |
-
this.parentNode.childNodes[2].innerText = BABYLON.Engine.LastCreatedScene.activeCamera.alpha;
|
371 |
-
} catch(e) {alert(e);}
|
372 |
-
'/><span>0.0</span>""")
|
373 |
camera = gr.HTML(value="<a href='#' onclick=\"BABYLON.Engine.LastCreatedScene.activeCamera.radius=0;\">reset camera</a>")
|
374 |
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='
|
375 |
if (!BABYLON.Engine.LastCreatedScene.activeCamera.metadata) {
|
@@ -400,8 +374,8 @@ with gr.Blocks(css=css) as demo:
|
|
400 |
pipeline: new BABYLON.DefaultRenderingPipeline(\"default\", true, BABYLON.Engine.LastCreatedScene, [BABYLON.Engine.LastCreatedScene.activeCamera])
|
401 |
}
|
402 |
}
|
403 |
-
var cntxt = document.getElementsByClassName(\"model3D\")[0].getElementsByTagName(\"canvas\")[0].getContext(\"webgl2\");
|
404 |
-
this.innerText = cntxt;
|
405 |
BABYLON.Engine.LastCreatedScene.activeCamera.metadata.screenshot = true;
|
406 |
|
407 |
BABYLON.Engine.LastCreatedScene.getEngine().onEndFrameObservable.add(function() {
|
@@ -410,6 +384,7 @@ with gr.Blocks(css=css) as demo:
|
|
410 |
try {
|
411 |
BABYLON.Tools.CreateScreenshotUsingRenderTarget(BABYLON.Engine.LastCreatedScene.getEngine(), BABYLON.Engine.LastCreatedScene.activeCamera,
|
412 |
{ precision: 1.0 }, (durl) => {
|
|
|
413 |
document.getElementById(\"img_out\").onload = function() {
|
414 |
var svgd = `<svg id=\"svg_out\" viewBox=\"0 0 ` + document.getElementById(\"img_out\").width + ` ` + document.getElementById(\"img_out\").height + `\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">
|
415 |
<defs>
|
@@ -419,14 +394,13 @@ with gr.Blocks(css=css) as demo:
|
|
419 |
</defs>
|
420 |
<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 + `\"/>
|
421 |
</svg>`;
|
|
|
422 |
document.getElementById(\"img_out\").onload = function() {
|
423 |
document.getElementById(\"cnv_out\").width = document.getElementById(\"img_out\").width;
|
424 |
document.getElementById(\"cnv_out\").height = document.getElementById(\"img_out\").height;
|
425 |
document.getElementById(\"cnv_out\").getContext(\"2d\").drawImage(img_out, 0, 0);
|
426 |
}
|
427 |
-
document.getElementById(\"img_out\").src = \"data:image/svg+xml;base64,\" + btoa(svgd);
|
428 |
}
|
429 |
-
document.getElementById(\"img_out\").src = durl;
|
430 |
}
|
431 |
);
|
432 |
} catch(e) { alert(e); }
|
|
|
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 |
camera = gr.HTML(value="<a href='#' onclick=\"BABYLON.Engine.LastCreatedScene.activeCamera.radius=0;\">reset camera</a>")
|
348 |
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='
|
349 |
if (!BABYLON.Engine.LastCreatedScene.activeCamera.metadata) {
|
|
|
374 |
pipeline: new BABYLON.DefaultRenderingPipeline(\"default\", true, BABYLON.Engine.LastCreatedScene, [BABYLON.Engine.LastCreatedScene.activeCamera])
|
375 |
}
|
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() {
|
|
|
384 |
try {
|
385 |
BABYLON.Tools.CreateScreenshotUsingRenderTarget(BABYLON.Engine.LastCreatedScene.getEngine(), BABYLON.Engine.LastCreatedScene.activeCamera,
|
386 |
{ precision: 1.0 }, (durl) => {
|
387 |
+
document.getElementById(\"img_out\").src = durl;
|
388 |
document.getElementById(\"img_out\").onload = function() {
|
389 |
var svgd = `<svg id=\"svg_out\" viewBox=\"0 0 ` + document.getElementById(\"img_out\").width + ` ` + document.getElementById(\"img_out\").height + `\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">
|
390 |
<defs>
|
|
|
394 |
</defs>
|
395 |
<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 + `\"/>
|
396 |
</svg>`;
|
397 |
+
document.getElementById(\"img_out\").src = \"data:image/svg+xml;base64,\" + btoa(svgd);
|
398 |
document.getElementById(\"img_out\").onload = function() {
|
399 |
document.getElementById(\"cnv_out\").width = document.getElementById(\"img_out\").width;
|
400 |
document.getElementById(\"cnv_out\").height = document.getElementById(\"img_out\").height;
|
401 |
document.getElementById(\"cnv_out\").getContext(\"2d\").drawImage(img_out, 0, 0);
|
402 |
}
|
|
|
403 |
}
|
|
|
404 |
}
|
405 |
);
|
406 |
} catch(e) { alert(e); }
|