From 4c2a2013a4e5a61242ea225821bf1c7ae58dd300 Mon Sep 17 00:00:00 2001 From: GeorgLegato Date: Sat, 15 Apr 2023 00:52:10 +0200 Subject: [PATCH] sendto panotab working --- javascript/pano_hints.js | 3 +- javascript/panoramaviewer-ext.js | 39 ++++++----- scripts/panorama-3dviewer.py | 13 ++-- scripts/tab_video.html | 108 +++++++++++++++++-------------- 4 files changed, 88 insertions(+), 75 deletions(-) diff --git a/javascript/pano_hints.js b/javascript/pano_hints.js index b2ee7e1..113b77f 100644 --- a/javascript/pano_hints.js +++ b/javascript/pano_hints.js @@ -6,7 +6,8 @@ pano_titles = { "🧊": "Switch between selected image and CubeMap view", "✜": "Convert current spherical map into cubemap (for better outpainting)", "💫": "Convert current cubemap to equirectangular map (for better upscaling)", - "❌": "Close current panorama viewer" + "❌": "Close current panorama viewer", + "Pano 🎦": "Send movie to the Panorama-Movie-Viewer-Tab" } diff --git a/javascript/panoramaviewer-ext.js b/javascript/panoramaviewer-ext.js index 8b1a0e7..f050cad 100644 --- a/javascript/panoramaviewer-ext.js +++ b/javascript/panoramaviewer-ext.js @@ -87,7 +87,7 @@ function panorama_here(phtml, mode, buttonId) { if (!galImage) return function getIndex() { - const basename= galImage.src.match(/\/([^\/]+)$/)[1] + const basename = galImage.src.match(/\/([^\/]+)$/)[1] for (var i = 0; i < galImagesAll.length; i++) { if (basename === galImagesAll[i].getAttribute('src').replace(/^.*[\\\/]/, '')) { return i @@ -95,7 +95,7 @@ function panorama_here(phtml, mode, buttonId) { } return 0 } - + const galImageIndex = getIndex() let parent = galImage.parentElement @@ -130,9 +130,9 @@ function panorama_send_video(dataURL, name = "Embed Resource") { } -function panorama_send_image(dataURL, name = "Embed Resource") { +function panorama_send_video(dataURL, name = "Embed Resource") { openpanorama.frame.contentWindow.postMessage({ - type: "panoramaviewer/set-panorama", + type: "panoramaviewer/set-video", image: { dataURL: dataURL, resourceName: name, @@ -189,19 +189,18 @@ async function panorama_get_image_from_gallery(warnOnNoSelect) { return button.src } -function panorama_send_gallery(name = "Embed Resource") { - panorama_get_image_from_gallery() - .then((dataURL) => { - // Send to panorama-viewer - console.info("[panorama viewer] Using URL: " + dataURL) - // Change Tab - panorama_gototab(); - panorama_send_image(dataURL, name); - }) - .catch((error) => { - console.warn("[panoramaviewer] No image selected to send to panorama viewer"); - }); +function panorama_send_infinitezoom(name = "Embed Resource") { + const vid = gradioApp().querySelector("#tab_iz_interface video") + if (vid) { + const dataURL = vid.src + // Send to panorama-viewer + console.info("[panorama viewer] Using movie URL: " + dataURL) + // Change Tab + panorama_gototab(); + panorama_send_video(dataURL, name); + + } } function openpanoramajs() { @@ -398,7 +397,7 @@ function convertto_equi() { onePx = document.createElement("canvas").getContext("2d").createImageData(1, 1); - for (let j = equiTexture.height-1; j >= 0; j--) { + for (let j = equiTexture.height - 1; j >= 0; j--) { // Rows start from the bottom v = 1 - (j / equiTexture.height); theta = v * Math.PI; @@ -551,7 +550,7 @@ function convertto_equi() { onePx = document.createElement("canvas").getContext("2d").createImageData(1, 1); - for (let j = equiTexture.height-1; j >= 0; j--) { + for (let j = equiTexture.height - 1; j >= 0; j--) { // Rows start from the bottom v = 1 - (j / equiTexture.height); theta = v * Math.PI; @@ -704,7 +703,7 @@ function convertto_equi() { onePx = document.createElement("canvas").getContext("2d").createImageData(1, 1); - for (let j = equiTexture.height-1; j >= 0; j--) { + for (let j = equiTexture.height - 1; j >= 0; j--) { // Rows start from the bottom v = 1 - (j / equiTexture.height); theta = v * Math.PI; @@ -867,7 +866,7 @@ function convertto_cubemap() { const data = ctx.getImageData(0, 0, width, height); outCanvas.width = width - outCanvas.height = height*1.5 + outCanvas.height = height * 1.5 processImage(data); }); } diff --git a/scripts/panorama-3dviewer.py b/scripts/panorama-3dviewer.py index 13a99fc..43984c3 100644 --- a/scripts/panorama-3dviewer.py +++ b/scripts/panorama-3dviewer.py @@ -55,13 +55,13 @@ def after_component(component, **kwargs): # Add our buttons after each "send to extras" button if kwargs.get("elem_id") == "extras_tab": -# with gr.Row(elem_id="pano_sendbox",variant="compact", css="justify-content: center; align-content: flex-end;"): - - # DISABLED until we get some functionality here, two button for Equi and Cubemap is currently enough - #send2tab_button = gr.Button ("Pano \U0001F440", elem_id=f"sendto_panorama_button") # 👀 - #send2tab_button.click(None, [], None, _js="() => panorama_send_gallery('WebUI Resource')") - #send2tab_button.__setattr__("class","gr-button") if (not component.parent.elem_id): return + + if (component.parent.elem_id == "image_buttons_infinit-zoom"): + send2tab_panomov_button = gr.Button ("Pano \U0001F3A6", elem_id=f"sendto_panorama_button") # 🎦 + send2tab_panomov_button.click(None, [], None, _js="() => panorama_send_infinitezoom('WebUI Resource')") + send2tab_panomov_button.__setattr__("class","gr-button") + if (component.parent.elem_id == "image_buttons_txt2img" or component.parent.elem_id == "image_buttons_img2img" or component.parent.elem_id == "image_buttons_extras"): suffix = component.parent.elem_id else: @@ -74,7 +74,6 @@ def after_component(component, **kwargs): view_gallery_button.click (None, [],None, _js="panorama_here(\""+iframesrc_gal+"\",\"\",\""+view_gallery_button.elem_id+"\")" ) view_cube_button.click (None, [],None, _js="panorama_here(\""+iframesrc_gal+"\",\"cubemap\",\""+view_cube_button.elem_id+"\")" ) - #╬═ conv_cubemap_gallery_button = gr.Button ("\U0000271C", variant="tool", elem_id="convertto_cubemap_button"+suffix) #✜ conv_cubemap_gallery_button.click (None, [],None, _js="convertto_cubemap" ) diff --git a/scripts/tab_video.html b/scripts/tab_video.html index 711ff3b..565159f 100644 --- a/scripts/tab_video.html +++ b/scripts/tab_video.html @@ -1,12 +1,13 @@ - - - + + + -< + @@ -20,49 +21,62 @@ \ No newline at end of file