Files
PozzettiAndrea feb273ad0a Isolation-clean frontend: delete dead JS, guard listeners, leave shared DOM
- Delete 7 dead-squat widgets (registered UI only for other packs' nodes:
  UniRig/SAM3D/Mocap/FBXPreview/BVH/pointcloud) + their 6 orphaned viewer
  HTMLs + the entire unused js/viewer tree (21 files, imported by nothing;
  only ui/styles.css survives) + unused utils barrel.
- Rename namespace geompack -> geometrypack (= DisplayName, lowercased);
  all 17 surviving extensions now geometrypack.*.
- Add event.source provenance guards to every message listener (2 inline,
  2 factory handlers via new iframe param).
- Stop touching document.body: upload file input stays detached (click()
  works detached in modern browsers); folder autocomplete dropdown becomes
  a manual popover inside the widget's own DOM (top layer escapes canvas
  transforms without shared-DOM appends).

Passes comfy-test's javascript isolation lint with 0 errors.
2026-08-13 14:31:51 +02:00

73 lines
3.1 KiB
JavaScript

// Preview Mesh Boundaries: interactive VTK.js viewer in the node. On execute the
// Python node writes a .vtp (surface + thresholded boundary edges) to temp; here
// we mount viewer_vtk.html and postMessage it the file URL to load.
import { app } from "../../../scripts/app.js";
const TAG = "[PreviewMeshBoundaries]";
console.log(`${TAG} script loaded`);
const EXTENSION_FOLDER = (() => {
const m = import.meta.url.match(/\/extensions\/([^/]+)\//);
return m ? m[1] : "ComfyUI-GeometryPack";
})();
// Build a /view URL from a payload filename. Handles bare temp names and
// type-prefixed relative paths (output/.. input/.. temp/..).
function viewUrl(name) {
const norm = String(name).replace(/\\/g, "/");
const m = norm.match(/(?:^|\/)(output|input|temp)\/(.+)$/);
if (m) {
const [, type, rel] = m;
const parts = rel.split("/");
const fname = parts.pop();
return `/view?filename=${encodeURIComponent(fname)}&type=${type}&subfolder=${encodeURIComponent(parts.join("/"))}`;
}
return `/view?filename=${encodeURIComponent(norm.split("/").pop())}&type=temp&subfolder=`;
}
app.registerExtension({
name: "geometrypack.previewmeshboundaries",
async beforeRegisterNodeDef(nodeType, nodeData) {
if (nodeData.name !== "GeomPackPreviewMeshBoundaries") return;
console.log(`${TAG} registering for GeomPackPreviewMeshBoundaries`);
const onCreated = nodeType.prototype.onNodeCreated;
nodeType.prototype.onNodeCreated = function () {
const r = onCreated?.apply(this, arguments);
const node = this;
const iframe = document.createElement("iframe");
iframe.style.cssText = "width:100%;height:100%;border:none;background:#2a2a2a;aspect-ratio:1;";
iframe.src = `/extensions/${EXTENSION_FOLDER}/viewer_vtk.html?v=` + Date.now();
const widget = node.addDOMWidget("preview", "MESH_PREVIEW", iframe, {
getValue() { return ""; }, setValue() { },
});
widget.computeSize = (w) => [w || 512, w || 512];
node.size = [Math.max(node.size?.[0] || 0, 380), Math.max(node.size?.[1] || 0, 420)];
node._gpBoundIframe = iframe;
return r;
};
const onExecuted = nodeType.prototype.onExecuted;
nodeType.prototype.onExecuted = function (message) {
onExecuted?.apply(this, arguments);
const iframe = this._gpBoundIframe;
const name = message?.mesh_file?.[0];
if (!iframe || !name) {
console.warn(`${TAG} no mesh_file in payload`, message && Object.keys(message));
return;
}
const url = viewUrl(name);
const send = () => {
if (iframe.contentWindow) {
console.log(`${TAG} loading ${url}`);
iframe.contentWindow.postMessage(
{ type: "LOAD_MESH", filepath: url, timestamp: Date.now() }, "*");
}
};
setTimeout(send, 250); // give the iframe time if just mounted
};
},
});