From 3895b770481105ff5e2dafb7687c167c09078acb Mon Sep 17 00:00:00 2001 From: nofunstudio Date: Sat, 1 Feb 2025 23:21:07 -0700 Subject: [PATCH] working with Base64! --- __pycache__/iframe_view.cpython-312.pyc | Bin 7770 -> 8689 bytes iframe_view.py | 23 +++++++-- js/iframe_view.js | 59 ++++++++++++++++++++---- 3 files changed, 69 insertions(+), 13 deletions(-) diff --git a/__pycache__/iframe_view.cpython-312.pyc b/__pycache__/iframe_view.cpython-312.pyc index 86428959581a9fde8b69f4eeb84b832d956b3b8b..b1c277373ee7489751a219da4d375955bbba963c 100644 GIT binary patch delta 3456 zcmb7GU2Ggz6~41Gv-7jF|39|(&l@|DyKx*lt(`y8CYGH<4vUlEHj!~0d-1HB9qhH4 z8RNvvWYh9u5EV7|VG(JB9}q7os8J(Y2^B(>6eFT^11k}&ECdn{JRoo(C{ZdT?j7&U z&f4Xnv)XgdJ?GqW&b{~C@80T>PX;`{bGvzfz7YGPS2tp}Jb!Woo?`$g0hPdF{7C?= zveA7yp^}>d07T+uO-%p|D5q>1hoylpg<2gV2|o@c<8MaE&p z@)~81FFNn+^MaQ#AZ(;8JbN+RR|mb0$}BZS}-)K;xv&y3XV@R%68A&05jw z_6djV6OP!+H)2ir^OkQ2m#=ND$u9)>#^U2>rca;mhcm3mFC-fGr45o1Qhxol~~HJ7osVLE|0BMpai04KnU$?KHZ ziljz9HEGh2rfx9SLTrPAqDCws(9i{2m>rrRwjp=zH>^5GCF2?a?LggQrn(czA)U94 z3TymzaH9?x;B_DZoxjR25{uw6ISLkuE#pUYx7tz1p`Dt$(Sdr%3?>~$lT5&4p+pUY zx@|?{&>T~aQ5?*D)jd*c>p|1IhL;Y&H@T*^5j88TIWaXa&rRhNC0}?orRFZH3vw~QWUU_n48Wn%&5q=pv=js#k_hcrCiF+=MJadRk^%_=*Gi# z56sQZ&*ZlF&lgh9$i2PO&$yJ5o0=<#%HE~@MwI`!QcSW+srlI)j0mkx+HeVbg)Dqa z7>j!3CN%j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z-$^w}39TNL-p^w>OLWt+rf2kQuaeO-YAaSNH+rUp?BI}oRHH2mU$5L+-V1PrEDa1)_GD#=aM2~?jHsAdI6{@1QG`X4G`4%JHoyiCZkiuOJ=Gnnn}&knB`QV$=< zYFcl9LG=bPYqWolf*BD6%1IBz+o}g(7yhJrbuC3wh@f^-iDt@d)D)E{*@30_>Oif~ zFw+4=L7ttG!aL)i*DoRFX-EHIRiKj-^h5j;)0_|5U)ue+< WU@QFlCAb4Z`97fZUN=5i^VWZnkKEY+ diff --git a/iframe_view.py b/iframe_view.py index 8c2fe7c..0d0a857 100644 --- a/iframe_view.py +++ b/iframe_view.py @@ -28,9 +28,15 @@ def get_global_texture_value(unique_id, key): def process_texture_data(data): + start_time = time.time() + print("[process_texture_data] Started processing texture data.") + if not data: print("[process_texture_data] No texture data received.") - return torch.zeros((1, 64, 64, 3), dtype=torch.float32) + result = torch.zeros((1, 64, 64, 3), dtype=torch.float32) + print(f"[process_texture_data] Returning default tensor with shape: {result.shape}") + return result + try: print("Raw data received:") if isinstance(data, dict) and "data" in data: @@ -57,17 +63,22 @@ def process_texture_data(data): raise else: print("[process_texture_data] Data format not recognized, returning default.") - return torch.zeros((1, 64, 64, 3), dtype=torch.float32) + result = torch.zeros((1, 64, 64, 3), dtype=torch.float32) + print(f"[process_texture_data] Returning default tensor with shape: {result.shape}") + return result print(f"[process_texture_data] Post reshape image stats: shape={image.shape}, min={image.min()}, max={image.max()}") image = image.astype(np.float32) / 255.0 tensor = torch.from_numpy(image)[None,] print(f"[process_texture_data] Tensor shape: {tensor.shape}, range=[{tensor.min().item():.3f}, {tensor.max().item():.3f}]") + elapsed = time.time() - start_time + print(f"[process_texture_data] Completed processing in {elapsed:.4f} seconds.") return tensor except Exception as e: print(f"[process_texture_data] Error processing texture data: {e}") traceback.print_exc() - return torch.zeros((1, 64, 64, 3), dtype=torch.float32) + result = torch.zeros((1, 64, 64, 3), dtype=torch.float32) + return result class IframeView: @classmethod @@ -97,6 +108,8 @@ class IframeView: CATEGORY = "lth" async def _process_iframe_async(self, url, width, height, scene_state, unique_id, color=None, canny=None, depth=None, normal=None): + start_time = time.time() + print("[process_iframe] Starting asynchronous processing at", start_time) try: print("\n[process_iframe] Called with inputs:") print(" url:", url) @@ -126,7 +139,9 @@ class IframeView: canny_tensor = process_texture_data(canny) depth_tensor = process_texture_data(depth) normal_tensor = process_texture_data(normal) - + + elapsed = time.time() - start_time + print(f"[process_iframe] Asynchronous processing completed in {elapsed:.4f} seconds.") return (color_tensor, canny_tensor, depth_tensor, normal_tensor) except Exception as e: print(f"[process_iframe] Error: {e}") diff --git a/js/iframe_view.js b/js/iframe_view.js index 194febd..4df4f28 100644 --- a/js/iframe_view.js +++ b/js/iframe_view.js @@ -7,6 +7,8 @@ window.TEXTURE_STORE = window.TEXTURE_STORE || {}; // Function to create the iframe widget async function widgetIframe(node, nodeData, inputData, app) { + console.log("[widgetIframe] Initializing iframe widget for node:", node); + // Create iframe wrapper with some styling const iframeWrapper = $el("div.iframeWrapper", { style: { @@ -48,10 +50,10 @@ async function widgetIframe(node, nodeData, inputData, app) { if (event.source !== iframe.contentWindow) return; console.log("[messageHandler] Received message:", event.data); - const { type, data } = event.data; switch (type) { case "IFRAME_READY": + console.log("[messageHandler] IFRAME_READY received"); sendParamsToIframe(); break; case "TEXTURE_OUTPUT": @@ -64,6 +66,10 @@ async function widgetIframe(node, nodeData, inputData, app) { case "SCENE_STATE_UPDATED": if (data.state) { stateWidget.value = JSON.stringify(data.state, null, 2); + console.log( + "[messageHandler] Updated scene state:", + stateWidget.value + ); } break; default: @@ -72,6 +78,7 @@ async function widgetIframe(node, nodeData, inputData, app) { } // Attach the message handler + console.log("[widgetIframe] Attaching message event listener for iframe."); window.addEventListener("message", messageHandler, false); // Function to send parameters (width, height, scene state) to the iframe @@ -92,6 +99,12 @@ async function widgetIframe(node, nodeData, inputData, app) { }, }; + console.log( + "[sendParamsToIframe] Sending params at", + Date.now(), + ":", + params + ); if (iframe.contentWindow) { // If you know the target origin, replace '*' with that string iframe.contentWindow.postMessage(params, "*"); @@ -100,6 +113,14 @@ async function widgetIframe(node, nodeData, inputData, app) { // Function to handle texture output coming from the iframe async function handleTextureOutput(data) { + const startTime = performance.now(); + console.log( + "[handleTextureOutput] Processing texture output for node:", + node.unique_id, + "at", + startTime + ); + // Make sure the node has a valid unique_id if (!node.unique_id) { console.warn( @@ -122,7 +143,7 @@ async function widgetIframe(node, nodeData, inputData, app) { } }); console.log( - "[handleTextureOutput] Final global texture store for unique_id", + "[handleTextureOutput] Global texture store for unique_id", node.unique_id, window.TEXTURE_STORE[node.unique_id] ); @@ -132,21 +153,24 @@ async function widgetIframe(node, nodeData, inputData, app) { setTimeout(() => { if (node.unique_id && window.TEXTURE_STORE[node.unique_id]) { // You can conditionally delete or nullify large arrays after processing. - //delete window.TEXTURE_STORE[node.unique_id]; + delete window.TEXTURE_STORE[node.unique_id]; } - const topApp = - (window.top && window.top !== window && window.top.app) || - (window.parent && window.parent !== window && window.parent.app) || - app; - if (topApp && typeof topApp.queuePrompt === "function") { - topApp.queuePrompt(); + if (app) { + app.queuePrompt(); } else { console.error( "queuePrompt is not available in the current app context." ); } }, 50); + + const elapsedTime = performance.now() - startTime; + console.log( + "[handleTextureOutput] Processing completed in", + elapsedTime.toFixed(2), + "ms" + ); } // Create the DOM widget for this node and register cleanup @@ -169,6 +193,7 @@ async function widgetIframe(node, nodeData, inputData, app) { // Attach a reference to the iframe on the widget so we can access it later widget.iframe = iframe; + console.log("[widgetIframe] Widget created and registered."); // Handle resizing: update both node size and iframe dimensions, then re-send params node.onResize = function () { @@ -177,11 +202,13 @@ async function widgetIframe(node, nodeData, inputData, app) { node.size = [width, Math.max(height + 40, 140)]; iframe.style.width = width + "px"; iframe.style.height = height - 40 + "px"; + console.log("[onResize] Node resized to new dimensions:", width, height); sendParamsToIframe(); }; // When the URL widget changes, update the iframe's src urlWidget.callback = function () { + console.log("[URL Widget] Updating iframe src to:", this.value); iframe.src = this.value; }; @@ -195,6 +222,12 @@ async function widgetIframe(node, nodeData, inputData, app) { // Override the default setHiddenWidgetValue to also update our global TEXTURE_STORE. node.setHiddenWidgetValue = function (name, value) { + console.log( + "[setHiddenWidgetValue] Setting texture data for", + name, + "at", + Date.now() + ); let widgetEntry = this.widgets.find((w) => w.name === name); if (widgetEntry) { widgetEntry.value = value; @@ -222,6 +255,12 @@ async function widgetIframe(node, nodeData, inputData, app) { // When creating the widget node.cleanup = () => { + console.log( + "[cleanup] Cleanup triggered for node:", + node.unique_id, + "at", + Date.now() + ); window.removeEventListener("message", messageHandler, false); if (node.unique_id && window.TEXTURE_STORE[node.unique_id]) { delete window.TEXTURE_STORE[node.unique_id]; @@ -264,6 +303,7 @@ app.registerExtension({ const domWidget = this.widgets.find((w) => w.name === "iframe"); if (domWidget && domWidget.iframe) { const url = this.widgets.find((w) => w.name === "url").value; + console.log("[Extra Menu] Refreshing iframe with url:", url); domWidget.iframe.src = url; } }, @@ -273,6 +313,7 @@ app.registerExtension({ callback: () => { const domWidget = this.widgets.find((w) => w.name === "iframe"); if (domWidget?.iframe?.contentWindow) { + console.log("[Extra Menu] Triggering texture capture."); domWidget.iframe.contentWindow.postMessage( { type: "CAPTURE_TEXTURES" }, "*"