feat: some stuff
This commit is contained in:
@ -111,7 +111,8 @@
|
||||
if (!node?.inputs) {
|
||||
return 5;
|
||||
}
|
||||
const height = 5 + 10 * Object.keys(node.inputs).length;
|
||||
const height =
|
||||
5 + 10 * Object.keys(node.inputs).filter((i) => i !== "seed").length;
|
||||
nodeHeightCache[nodeTypeId] = height;
|
||||
return height;
|
||||
}
|
||||
@ -385,6 +386,17 @@
|
||||
|
||||
function handleMouseDown(event: MouseEvent) {
|
||||
if (mouseDown) return;
|
||||
|
||||
if (event.target instanceof HTMLElement) {
|
||||
if (
|
||||
event.target.nodeName !== "CANVAS" &&
|
||||
!event.target.classList.contains("node") &&
|
||||
!event.target.classList.contains("content")
|
||||
) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
mouseDown = [event.clientX, event.clientY];
|
||||
cameraDown[0] = cameraPosition[0];
|
||||
cameraDown[1] = cameraPosition[1];
|
||||
|
@ -23,7 +23,9 @@
|
||||
|
||||
const type = node?.tmp?.type;
|
||||
|
||||
const parameters = Object.entries(type?.inputs || {});
|
||||
const parameters = Object.entries(type?.inputs || {}).filter(
|
||||
(p) => p[1].type !== "seed",
|
||||
);
|
||||
|
||||
let ref: HTMLDivElement;
|
||||
let meshRef: Mesh;
|
||||
|
@ -71,7 +71,7 @@
|
||||
{#key id && graphId}
|
||||
{#if node?.tmp?.type?.inputs?.[id]?.external !== true}
|
||||
<div class="content" class:disabled={$inputSockets.has(socketId)}>
|
||||
<NodeInput {node} {input} {id} label={input.title} />
|
||||
<NodeInput {node} {input} {id} label={input.label} />
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
|
@ -20,8 +20,8 @@ export function grid(width: number, height: number) {
|
||||
visible: false,
|
||||
},
|
||||
position: [x * 30, y * 40],
|
||||
props: i == 0 ? { value: 0 } : { op_type: 1, a: 2, b: i },
|
||||
type: i == 0 ? "max/plantarium/input-float" : "max/plantarium/math",
|
||||
props: i == 0 ? { value: 0 } : { op_type: 2, a: 2, b: 2 },
|
||||
type: i == 0 ? "max/plantarium/float" : "max/plantarium/math",
|
||||
});
|
||||
|
||||
graph.edges.push([i, 0, i + 1, i === amount - 1 ? "input" : "a",]);
|
||||
|
@ -1,11 +1,10 @@
|
||||
import type { NodeRegistry, NodeType } from "@nodes/types";
|
||||
|
||||
import * as d from "plantarium-nodes-math";
|
||||
import { createLogger } from "./helpers";
|
||||
|
||||
const nodeTypes: NodeType[] = [
|
||||
{
|
||||
id: "max/plantarium/input-float",
|
||||
id: "max/plantarium/float",
|
||||
inputs: {
|
||||
"value": { type: "float", value: 0.1, internal: true },
|
||||
},
|
||||
@ -48,6 +47,8 @@ export class RemoteNodeRegistry implements NodeRegistry {
|
||||
|
||||
async load(nodeIds: string[]) {
|
||||
const a = performance.now();
|
||||
nodeIds.push("max/plantarium/random");
|
||||
nodeIds.push("max/plantarium/float");
|
||||
for (const id of nodeIds) {
|
||||
const nodeUrl = `${this.url}/n/${id}`;
|
||||
const response = await fetch(nodeUrl);
|
||||
@ -70,10 +71,7 @@ wasm = val;`);
|
||||
throw new Error(`Failed to load node ${id}`);
|
||||
}
|
||||
const node = await response.json();
|
||||
node.execute = (...args) => {
|
||||
console.log("Executing", id, args);
|
||||
return wasmWrapper.execute(...args)
|
||||
};
|
||||
node.execute = wasmWrapper.execute;
|
||||
this.nodes.set(id, node);
|
||||
}
|
||||
|
||||
|
@ -101,7 +101,6 @@ export class MemoryRuntimeExecutor implements RuntimeExecutor {
|
||||
// we execute the nodes from the bottom up
|
||||
const sortedNodes = nodes.sort((a, b) => (b.tmp?.depth || 0) - (a.tmp?.depth || 0));
|
||||
|
||||
|
||||
// here we store the intermediate results of the nodes
|
||||
const results: Record<string, string | boolean | number> = {};
|
||||
|
||||
@ -110,6 +109,11 @@ export class MemoryRuntimeExecutor implements RuntimeExecutor {
|
||||
const inputs: Record<string, string | number | boolean> = {};
|
||||
for (const [key, input] of Object.entries(node.tmp.type.inputs || {})) {
|
||||
|
||||
if (input.type === "seed") {
|
||||
inputs[key] = Math.floor(Math.random() * 100000000);
|
||||
continue;
|
||||
}
|
||||
|
||||
// check if the input is connected to another node
|
||||
const inputNode = node.tmp.inputNodes?.[key];
|
||||
if (inputNode) {
|
||||
@ -122,6 +126,7 @@ export class MemoryRuntimeExecutor implements RuntimeExecutor {
|
||||
|
||||
// if the input is not connected to another node, we use the value from the node itself
|
||||
inputs[key] = node.props?.[key] ?? input?.value;
|
||||
|
||||
}
|
||||
|
||||
// execute the node and store the result
|
||||
|
@ -39,9 +39,14 @@
|
||||
<br />
|
||||
<button
|
||||
on:click={() =>
|
||||
graphManager.load(graphManager.createTemplate("grid", 3, 3))}
|
||||
graphManager.load(graphManager.createTemplate("grid", 10, 10))}
|
||||
>load grid</button
|
||||
>
|
||||
<button
|
||||
on:click={() =>
|
||||
graphManager.load(graphManager.createTemplate("grid", 2, 2))}
|
||||
>load small grid</button
|
||||
>
|
||||
<br />
|
||||
<br />
|
||||
<JsonView json={debug} />
|
||||
|
Reference in New Issue
Block a user