Skip to content

Commit b33253a

Browse files
committed
Add refresh button and docs screenshots
1 parent 61dcdf1 commit b33253a

File tree

6 files changed

+69
-0
lines changed

6 files changed

+69
-0
lines changed

Figure1.png

233 KB
Loading

Figure2.png

260 KB
Loading

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ git clone https://github.com/XuanYu-github/comfyui-PlyPreview.git
3232
2) 连接 Preview Gaussian,执行后 iframe 显示控制条(Scale、Reset View、Screenshot)和信息面板。
3333
3) 若启用透明度过滤,会在源旁生成 `_opacity{threshold}.ply`
3434

35+
示例:
36+
37+
![Sharp → PlyPreview 工作流示例](Figure1.png)
38+
39+
![加载与刷新 PLY 列表示例](Figure2.png)
40+
3541
## 依赖
3642
- ComfyUI(默认已启用 DOM widgets)。
3743
- Python:`plyfile``numpy`(缺失时 `pip install plyfile numpy`)。

__init__.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@
77
from .load_gaussian_ply_path import LoadGaussianPLYPath
88
from .process_gaussian_ply import ProcessGaussianPLY
99
from .preview_gaussian import PreviewGaussianNode
10+
from aiohttp import web
11+
12+
try:
13+
from server import PromptServer
14+
except Exception as e: # pragma: no cover - ComfyUI runtime only
15+
PromptServer = None
16+
print(f"[PlyPreview] Warning: server import failed: {e}")
1017

1118
WEB_DIRECTORY = "web"
1219

@@ -24,6 +31,18 @@
2431
"PlyPreviewPreviewGaussianEnhance": "Preview Gaussian Enhance",
2532
}
2633

34+
# Lightweight API to let the frontend refresh PLY dropdowns without restarting ComfyUI
35+
if PromptServer is not None:
36+
async def plypreview_list_ply_files(request): # pragma: no cover - runtime route
37+
files = LoadGaussianPLY._get_ply_files()
38+
return web.json_response({"files": files})
39+
40+
try:
41+
PromptServer.instance.routes.get("/plypreview/files")(plypreview_list_ply_files)
42+
print("[PlyPreview] Registered /plypreview/files refresh endpoint")
43+
except Exception as e: # pragma: no cover
44+
print(f"[PlyPreview] Warning: failed to register refresh endpoint: {e}")
45+
2746
__all__ = [
2847
"NODE_CLASS_MAPPINGS",
2948
"NODE_DISPLAY_NAME_MAPPINGS",

web/js/gaussian_preview.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55

66
import { app } from "../../../scripts/app.js";
7+
import { api } from "../../../scripts/api.js";
78

89
// Auto-detect extension folder name (handles comfyui-PlyPreview or other folder names)
910
const EXTENSION_FOLDER = (() => {
@@ -18,6 +19,43 @@ app.registerExtension({
1819
name: "plypreview.gaussianpreview",
1920

2021
async beforeRegisterNodeDef(nodeType, nodeData, app) {
22+
// Auto-refresh PLY dropdown list for the file selector node
23+
if (nodeData.name === "PlyPreviewLoadGaussianPLYEnhance") {
24+
const onNodeCreated = nodeType.prototype.onNodeCreated;
25+
nodeType.prototype.onNodeCreated = function() {
26+
const r = onNodeCreated ? onNodeCreated.apply(this, arguments) : undefined;
27+
28+
const widget = (this.widgets || []).find(w => w.name === "ply_file");
29+
30+
const refreshList = async () => {
31+
try {
32+
const resp = await api.fetchApi("/plypreview/files");
33+
const json = await resp.json();
34+
const files = Array.isArray(json.files) && json.files.length > 0 ? json.files : ["No PLY files found"];
35+
if (widget) {
36+
widget.options.values = files;
37+
widget.value = files[0];
38+
this.setDirtyCanvas(true);
39+
app.graph.setDirtyCanvas(true, true);
40+
}
41+
} catch (e) {
42+
console.warn("[PlyPreview] Failed to refresh PLY list", e);
43+
}
44+
};
45+
46+
this.refreshPlyList = refreshList;
47+
refreshList();
48+
49+
// Add in-node refresh button instead of relying on context menu
50+
this.addWidget("button", "Refresh PLY list", () => this.refreshPlyList && this.refreshPlyList(), {
51+
serialize: false,
52+
width: 180,
53+
});
54+
55+
return r;
56+
};
57+
}
58+
2159
if (nodeData.name === "PlyPreviewPreviewGaussianEnhance") {
2260
console.log("[PlyPreview Gaussian] Registering Preview Gaussian Enhance node");
2361

web/viewer_gaussian.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,12 @@
143143
const infoPanel = document.getElementById('infoPanel');
144144
const infoContent = document.getElementById('infoContent');
145145

146+
// Make canvas focusable so keyboard controls (WASD/arrows) work after clicking the viewer
147+
canvas.tabIndex = 0;
148+
canvas.style.outline = "none";
149+
const focusCanvas = () => canvas.focus({ preventScroll: true });
150+
canvas.addEventListener('pointerdown', focusCanvas);
151+
146152
// gsplat.js components
147153
let scene = null;
148154
let camera = null;

0 commit comments

Comments
 (0)