|
1 | | -import type { NodeCreateOptions, NodePart, Socket } from "../mod.ts"; |
| 1 | +import type { NodeCreateOptions, NodePart, Socket, SocketDirection } from "../mod.ts"; |
2 | 2 | import { createNumberInputField, type NodeFactory, type WgslContext, WgslNode } from "./nodes.base.ts"; |
3 | 3 |
|
4 | 4 | interface GeneratedNodeClass<T = object> { |
@@ -26,6 +26,7 @@ export class ConstF32Node extends WgslNode { |
26 | 26 | static readonly factory: NodeFactory<ConstF32Node> = { |
27 | 27 | name: "Scalar", |
28 | 28 | type: ConstF32Node, |
| 29 | + initials: [{ id: "constant", direction: "out", type: "f32", name: "Constant" }], |
29 | 30 | populatePartInterface: (node, part) => { |
30 | 31 | const div = document.createElement("div"); |
31 | 32 | if (part != node.uiPart) return div; |
@@ -64,6 +65,7 @@ export function constantVectorNode(dim: number, dtype: string, name: string): Ge |
64 | 65 | static readonly factory: NodeFactory<ConstantVectorNode> = { |
65 | 66 | name, |
66 | 67 | type: ConstantVectorNode, |
| 68 | + initials: [{ id: "constant", direction: "out", type: dtype, name: "Constant" }], |
67 | 69 | populatePartInterface: (node, part) => { |
68 | 70 | const div = document.createElement("div"); |
69 | 71 | if (part != node.uiPart) return div; |
@@ -115,7 +117,19 @@ export function splitVectorNode(components: [string, string][], dtype: string, n |
115 | 117 | return `${ctx.nameOf("input")}.${components[idx][0]}`; |
116 | 118 | } |
117 | 119 |
|
118 | | - static readonly factory: NodeFactory<SplitVectorNode> = { name, type: SplitVectorNode }; |
| 120 | + static readonly factory: NodeFactory<SplitVectorNode> = { |
| 121 | + name, |
| 122 | + type: SplitVectorNode, |
| 123 | + initials: [ |
| 124 | + { id: "input", direction: "in", type: dtype, name: "Vector" }, |
| 125 | + ...components.map(([id, label]) => ({ |
| 126 | + id, |
| 127 | + direction: "out" as SocketDirection, |
| 128 | + type: "f32", |
| 129 | + name: label, |
| 130 | + })), |
| 131 | + ], |
| 132 | + }; |
119 | 133 | }; |
120 | 134 | } |
121 | 135 |
|
@@ -155,7 +169,19 @@ export function mergeVectorNode(components: [string, string][], dtype: string, n |
155 | 169 | throw new Error("Invalid socket"); |
156 | 170 | } |
157 | 171 |
|
158 | | - static readonly factory: NodeFactory<MergeVectorNode> = { name, type: MergeVectorNode }; |
| 172 | + static readonly factory: NodeFactory<MergeVectorNode> = { |
| 173 | + name, |
| 174 | + type: MergeVectorNode, |
| 175 | + initials: [ |
| 176 | + { id: "output", direction: "out", type: dtype, name: "Vector" }, |
| 177 | + ...components.map(([id, label]) => ({ |
| 178 | + id, |
| 179 | + direction: "in" as SocketDirection, |
| 180 | + type: "f32", |
| 181 | + name: label, |
| 182 | + })), |
| 183 | + ], |
| 184 | + }; |
159 | 185 | }; |
160 | 186 | } |
161 | 187 |
|
@@ -204,6 +230,11 @@ export function mathNode(dtype: string, name: string): GeneratedNodeClass { |
204 | 230 | static readonly factory: NodeFactory<MathNode> = { |
205 | 231 | name, |
206 | 232 | type: MathNode, |
| 233 | + initials: [ |
| 234 | + { id: "a", direction: "in", type: dtype, name: "A" }, |
| 235 | + { id: "b", direction: "in", type: dtype, name: "B" }, |
| 236 | + { id: "output", direction: "out", type: dtype, name: "Output" }, |
| 237 | + ], |
207 | 238 | populatePartInterface: (node) => { |
208 | 239 | const select = document.createElement("select"); |
209 | 240 | select.style.width = "100%"; |
|
0 commit comments