Update app.py
Browse files
app.py
CHANGED
|
@@ -385,10 +385,10 @@ def get_mesh(image, depth, blur_data, loadall):
|
|
| 385 |
print('mesh - ok')
|
| 386 |
|
| 387 |
# Save as glb
|
| 388 |
-
glb_file = tempfile.NamedTemporaryFile(suffix='.glb', delete=False)
|
| 389 |
#o3d.io.write_triangle_mesh(glb_file.name, pcd)
|
| 390 |
-
print('file - ok')
|
| 391 |
-
return "./TriangleWithoutIndices.gltf",
|
| 392 |
|
| 393 |
def blur_image(image, depth, blur_data):
|
| 394 |
blur_a = blur_data.split()
|
|
@@ -657,7 +657,7 @@ async(c, o, p, d, n, m)=>{
|
|
| 657 |
mesh.dispose(false, true);
|
| 658 |
}
|
| 659 |
//BABYLON.Engine.LastCreatedScene.meshes[BABYLON.Engine.LastCreatedScene.meshes.length-1].material.needDepthPrePass = true;
|
| 660 |
-
|
| 661 |
BABYLON.Engine.LastCreatedScene.meshes[BABYLON.Engine.LastCreatedScene.meshes.length-1].alphaIndex = o_.length-j;
|
| 662 |
BABYLON.Engine.LastCreatedScene.meshes[BABYLON.Engine.LastCreatedScene.meshes.length-1].material.diffuseTexture.hasAlpha = true;
|
| 663 |
BABYLON.Engine.LastCreatedScene.meshes[BABYLON.Engine.LastCreatedScene.meshes.length-1].material.useAlphaFromDiffuseTexture = true;
|
|
@@ -975,7 +975,6 @@ with gr.Blocks(css=css, js=js) as demo:
|
|
| 975 |
coords = gr.Textbox(elem_id="coords", value=example_coords, label="Coordinates", interactive=False)
|
| 976 |
mesh_order = gr.Textbox(elem_id="order", value="", label="Order", interactive=False)
|
| 977 |
|
| 978 |
-
result_file = gr.File(elem_id="file3D", label="3D file", interactive=False)
|
| 979 |
html = gr.HTML(value="""<label for='zoom'>Zoom</label><input id='zoom' type='range' style='width:256px;height:1em;' value='0.8' min='0.157' max='1.57' step='0.001' oninput='
|
| 980 |
if (!BABYLON.Engine.LastCreatedScene.activeCamera.metadata) {
|
| 981 |
var evt = document.createEvent(\"Event\");
|
|
@@ -1024,43 +1023,6 @@ with gr.Blocks(css=css, js=js) as demo:
|
|
| 1024 |
BABYLON.Engine.LastCreatedScene.activeCamera.metadata.pipeline.imageProcessing.exposure = this.value;
|
| 1025 |
this.parentNode.childNodes[2].innerText = BABYLON.Engine.LastCreatedScene.activeCamera.metadata.pipeline.imageProcessing.exposure;
|
| 1026 |
'/><span>1.0</span>""")
|
| 1027 |
-
canvas = gr.HTML(value="""<a href='#' onclick='
|
| 1028 |
-
if (!BABYLON.Engine.LastCreatedScene.activeCamera.metadata) {
|
| 1029 |
-
var evt = document.createEvent(\"Event\");
|
| 1030 |
-
evt.initEvent(\"click\", true, false);
|
| 1031 |
-
document.getElementById(\"reset_cam\").dispatchEvent(evt);
|
| 1032 |
-
}
|
| 1033 |
-
BABYLON.Engine.LastCreatedScene.activeCamera.metadata.screenshot = true;
|
| 1034 |
-
|
| 1035 |
-
BABYLON.Engine.LastCreatedScene.getEngine().onEndFrameObservable.add(function() {
|
| 1036 |
-
if (BABYLON.Engine.LastCreatedScene.activeCamera.metadata.screenshot === true) {
|
| 1037 |
-
BABYLON.Engine.LastCreatedScene.activeCamera.metadata.screenshot = false;
|
| 1038 |
-
try {
|
| 1039 |
-
BABYLON.Tools.CreateScreenshotUsingRenderTarget(BABYLON.Engine.LastCreatedScene.getEngine(), BABYLON.Engine.LastCreatedScene.activeCamera,
|
| 1040 |
-
{ precision: 1.0 }, (durl) => {
|
| 1041 |
-
var cnvs = document.getElementById(\"model3D\").getElementsByTagName(\"canvas\")[0]; //.getContext(\"webgl2\");
|
| 1042 |
-
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\">
|
| 1043 |
-
<defs>
|
| 1044 |
-
<filter id=\"blur\" x=\"0\" y=\"0\" xmlns=\"http://www.w3.org/2000/svg\">
|
| 1045 |
-
<feGaussianBlur in=\"SourceGraphic\" stdDeviation=\"` + BABYLON.Engine.LastCreatedScene.getNodes()[1].material.pointSize/2.0*Math.sqrt(2.0) + `\" />
|
| 1046 |
-
</filter>
|
| 1047 |
-
</defs>
|
| 1048 |
-
<image filter=\"url(#blur)\" id=\"svg_img\" x=\"0\" y=\"0\" width=\"` + cnvs.width + `\" height=\"` + cnvs.height + `\" xlink:href=\"` + durl + `\"/>
|
| 1049 |
-
</svg>`;
|
| 1050 |
-
document.getElementById(\"cnv_out\").width = cnvs.width;
|
| 1051 |
-
document.getElementById(\"cnv_out\").height = cnvs.height;
|
| 1052 |
-
document.getElementById(\"img_out\").src = \"data:image/svg+xml;base64,\" + btoa(svgd);
|
| 1053 |
-
}
|
| 1054 |
-
);
|
| 1055 |
-
} catch(e) { alert(e); }
|
| 1056 |
-
// https://forum.babylonjs.com/t/best-way-to-save-to-jpeg-snapshots-of-scene/17663/11
|
| 1057 |
-
}
|
| 1058 |
-
});
|
| 1059 |
-
'/>snapshot</a><br/><img src='' id='img_out' onload='
|
| 1060 |
-
var ctxt = document.getElementById(\"cnv_out\").getContext(\"2d\");
|
| 1061 |
-
ctxt.drawImage(this, 0, 0);
|
| 1062 |
-
'/><br/>
|
| 1063 |
-
<canvas id='cnv_out'/>""")
|
| 1064 |
load_all = gr.Checkbox(label="Load all")
|
| 1065 |
render = gr.Button("Render")
|
| 1066 |
input_json.input(show_json, inputs=[input_json], outputs=[processed_video, processed_zip, output_frame, output_mask, output_depth, coords])
|
|
@@ -1105,7 +1067,7 @@ with gr.Blocks(css=css, js=js) as demo:
|
|
| 1105 |
|
| 1106 |
submit.click(on_submit, inputs=[input_video, model_type, blur_in, boffset, bsize, coords], outputs=[processed_video, processed_zip, output_frame, output_mask, output_depth, coords])
|
| 1107 |
render.click(None, inputs=[coords, mesh_order, output_frame, output_mask, selected, output_depth], outputs=None, js=load_model)
|
| 1108 |
-
render.click(partial(get_mesh), inputs=[output_frame, output_mask, blur_in, load_all], outputs=[result,
|
| 1109 |
|
| 1110 |
example_files = [["./examples/streetview.mp4", "vits", blurin, 1, 32, example_coords]]
|
| 1111 |
examples = gr.Examples(examples=example_files, fn=on_submit, cache_examples=True, inputs=[input_video, model_type, blur_in, boffset, bsize, coords], outputs=[processed_video, processed_zip, output_frame, output_mask, output_depth, coords])
|
|
|
|
| 385 |
print('mesh - ok')
|
| 386 |
|
| 387 |
# Save as glb
|
| 388 |
+
#glb_file = tempfile.NamedTemporaryFile(suffix='.glb', delete=False)
|
| 389 |
#o3d.io.write_triangle_mesh(glb_file.name, pcd)
|
| 390 |
+
#print('file - ok')
|
| 391 |
+
return "./TriangleWithoutIndices.gltf", ",".join(mesh_n)
|
| 392 |
|
| 393 |
def blur_image(image, depth, blur_data):
|
| 394 |
blur_a = blur_data.split()
|
|
|
|
| 657 |
mesh.dispose(false, true);
|
| 658 |
}
|
| 659 |
//BABYLON.Engine.LastCreatedScene.meshes[BABYLON.Engine.LastCreatedScene.meshes.length-1].material.needDepthPrePass = true;
|
| 660 |
+
BABYLON.Engine.LastCreatedScene.meshes[BABYLON.Engine.LastCreatedScene.meshes.length-1].scaling.z = -1;
|
| 661 |
BABYLON.Engine.LastCreatedScene.meshes[BABYLON.Engine.LastCreatedScene.meshes.length-1].alphaIndex = o_.length-j;
|
| 662 |
BABYLON.Engine.LastCreatedScene.meshes[BABYLON.Engine.LastCreatedScene.meshes.length-1].material.diffuseTexture.hasAlpha = true;
|
| 663 |
BABYLON.Engine.LastCreatedScene.meshes[BABYLON.Engine.LastCreatedScene.meshes.length-1].material.useAlphaFromDiffuseTexture = true;
|
|
|
|
| 975 |
coords = gr.Textbox(elem_id="coords", value=example_coords, label="Coordinates", interactive=False)
|
| 976 |
mesh_order = gr.Textbox(elem_id="order", value="", label="Order", interactive=False)
|
| 977 |
|
|
|
|
| 978 |
html = gr.HTML(value="""<label for='zoom'>Zoom</label><input id='zoom' type='range' style='width:256px;height:1em;' value='0.8' min='0.157' max='1.57' step='0.001' oninput='
|
| 979 |
if (!BABYLON.Engine.LastCreatedScene.activeCamera.metadata) {
|
| 980 |
var evt = document.createEvent(\"Event\");
|
|
|
|
| 1023 |
BABYLON.Engine.LastCreatedScene.activeCamera.metadata.pipeline.imageProcessing.exposure = this.value;
|
| 1024 |
this.parentNode.childNodes[2].innerText = BABYLON.Engine.LastCreatedScene.activeCamera.metadata.pipeline.imageProcessing.exposure;
|
| 1025 |
'/><span>1.0</span>""")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1026 |
load_all = gr.Checkbox(label="Load all")
|
| 1027 |
render = gr.Button("Render")
|
| 1028 |
input_json.input(show_json, inputs=[input_json], outputs=[processed_video, processed_zip, output_frame, output_mask, output_depth, coords])
|
|
|
|
| 1067 |
|
| 1068 |
submit.click(on_submit, inputs=[input_video, model_type, blur_in, boffset, bsize, coords], outputs=[processed_video, processed_zip, output_frame, output_mask, output_depth, coords])
|
| 1069 |
render.click(None, inputs=[coords, mesh_order, output_frame, output_mask, selected, output_depth], outputs=None, js=load_model)
|
| 1070 |
+
render.click(partial(get_mesh), inputs=[output_frame, output_mask, blur_in, load_all], outputs=[result, mesh_order])
|
| 1071 |
|
| 1072 |
example_files = [["./examples/streetview.mp4", "vits", blurin, 1, 32, example_coords]]
|
| 1073 |
examples = gr.Examples(examples=example_files, fn=on_submit, cache_examples=True, inputs=[input_video, model_type, blur_in, boffset, bsize, coords], outputs=[processed_video, processed_zip, output_frame, output_mask, output_depth, coords])
|