File size: 1,686 Bytes
8fb6433 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | import {app} from "../../scripts/app.js";
import {sceneDataFieldPresentation} from "./h3_scene_data_core.mjs?v=0.6.2";
const NODE_NAME = "MiniMaxH3SceneDataExtract";
function fieldWidget(node) {
return node.widgets?.find((widget) => widget.name === "field") ?? null;
}
function refreshOutput(node) {
const output = node.outputs?.[0];
if (!output) return;
const presentation = sceneDataFieldPresentation(fieldWidget(node)?.value);
output.name = presentation.name;
output.label = presentation.name;
output.type = presentation.type;
node.setDirtyCanvas?.(true, true);
}
function install(node) {
const widget = fieldWidget(node);
if (!widget || widget._h3SceneDataWrapped) {
refreshOutput(node);
return;
}
widget._h3SceneDataWrapped = true;
const original = widget.callback;
widget.callback = function () {
const result = original?.apply(this, arguments);
refreshOutput(node);
return result;
};
refreshOutput(node);
}
app.registerExtension({
name: "minimax.h3.sceneDataExtract",
async beforeRegisterNodeDef(nodeType, nodeData) {
if (nodeData.name !== NODE_NAME) return;
const created = nodeType.prototype.onNodeCreated;
nodeType.prototype.onNodeCreated = function () {
const result = created?.apply(this, arguments);
install(this);
return result;
};
const configured = nodeType.prototype.onConfigure;
nodeType.prototype.onConfigure = function () {
const result = configured?.apply(this, arguments);
install(this);
return result;
};
},
});
|