Update app.py
Browse files
app.py
CHANGED
|
@@ -749,6 +749,40 @@ function drawLine(x, y) {
|
|
| 749 |
window.drawLine = drawLine;
|
| 750 |
|
| 751 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 752 |
var intv_ = setInterval(function(){
|
| 753 |
if (document.getElementById("image_edit") && document.getElementById("image_edit").getElementsByTagName("canvas")) {
|
| 754 |
document.getElementById("image_edit").getElementsByTagName("canvas")[0].oncontextmenu = function(e){e.preventDefault();}
|
|
@@ -968,6 +1002,11 @@ with gr.Blocks(css=css, js=js, head=head) as demo:
|
|
| 968 |
BABYLON.Engine.LastCreatedScene.activeCamera.metadata.pipeline.imageProcessing.exposure = this.value;
|
| 969 |
this.parentNode.childNodes[2].innerText = BABYLON.Engine.LastCreatedScene.activeCamera.metadata.pipeline.imageProcessing.exposure;
|
| 970 |
'/><span>1.0</span>""")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 971 |
render = gr.Button("Render")
|
| 972 |
input_json.input(show_json, inputs=[input_json], outputs=[processed_video, processed_zip, output_frame, output_mask, output_depth, coords])
|
| 973 |
|
|
|
|
| 749 |
window.drawLine = drawLine;
|
| 750 |
|
| 751 |
|
| 752 |
+
window.screenshot = false;
|
| 753 |
+
|
| 754 |
+
function snapshot() {
|
| 755 |
+
if (BABYLON) {
|
| 756 |
+
screenshot = true;
|
| 757 |
+
BABYLON.Engine.LastCreatedScene.getEngine().onEndFrameObservable.add(function() {
|
| 758 |
+
if (screenshot === true) {
|
| 759 |
+
screenshot = false;
|
| 760 |
+
try {
|
| 761 |
+
BABYLON.Tools.CreateScreenshotUsingRenderTarget(BABYLON.Engine.LastCreatedScene.getEngine(), BABYLON.Engine.LastCreatedScene.activeCamera,
|
| 762 |
+
{ precision: 1.0 }, (durl) => {
|
| 763 |
+
var cnvs = document.getElementById("model3D").getElementsByTagName("canvas")[0]; //.getContext("webgl2");
|
| 764 |
+
var svgd = `<svg id="svg_out" viewBox="0 0 ` + cnvs.width + ` ` + cnvs.height + `" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
| 765 |
+
<defs>
|
| 766 |
+
<filter id="blur" x="0" y="0" xmlns="http://www.w3.org/2000/svg">
|
| 767 |
+
<feGaussianBlur in="SourceGraphic" stdDeviation="1" />
|
| 768 |
+
</filter>
|
| 769 |
+
</defs>
|
| 770 |
+
<image filter="url(#blur)" id="svg_img" x="0" y="0" width="` + cnvs.width + `" height="` + cnvs.height + `" xlink:href=\"` + durl + `\"/>
|
| 771 |
+
</svg>`;
|
| 772 |
+
document.getElementById("cnv_out").width = cnvs.width;
|
| 773 |
+
document.getElementById("cnv_out").height = cnvs.height;
|
| 774 |
+
document.getElementById("img_out").src = "data:image/svg+xml;base64," + btoa(svgd);
|
| 775 |
+
}
|
| 776 |
+
);
|
| 777 |
+
} catch(e) { alert(e); }
|
| 778 |
+
// https://forum.babylonjs.com/t/best-way-to-save-to-jpeg-snapshots-of-scene/17663/11
|
| 779 |
+
}
|
| 780 |
+
});
|
| 781 |
+
}
|
| 782 |
+
}
|
| 783 |
+
window.snapshot = snapshot;
|
| 784 |
+
|
| 785 |
+
|
| 786 |
var intv_ = setInterval(function(){
|
| 787 |
if (document.getElementById("image_edit") && document.getElementById("image_edit").getElementsByTagName("canvas")) {
|
| 788 |
document.getElementById("image_edit").getElementsByTagName("canvas")[0].oncontextmenu = function(e){e.preventDefault();}
|
|
|
|
| 1002 |
BABYLON.Engine.LastCreatedScene.activeCamera.metadata.pipeline.imageProcessing.exposure = this.value;
|
| 1003 |
this.parentNode.childNodes[2].innerText = BABYLON.Engine.LastCreatedScene.activeCamera.metadata.pipeline.imageProcessing.exposure;
|
| 1004 |
'/><span>1.0</span>""")
|
| 1005 |
+
snapshot = gr.HTML(value="""
|
| 1006 |
+
<a onclick='snapshot();'>Screenshot</a><br/>
|
| 1007 |
+
<img src='' id='img_out' onload='var ctxt = document.getElementById(\"cnv_out\").getContext(\"2d\");ctxt.drawImage(this, 0, 0);'/><br/>
|
| 1008 |
+
<canvas id='cnv_out'></canvas>
|
| 1009 |
+
""")
|
| 1010 |
render = gr.Button("Render")
|
| 1011 |
input_json.input(show_json, inputs=[input_json], outputs=[processed_video, processed_zip, output_frame, output_mask, output_depth, coords])
|
| 1012 |
|