1
1
<script setup lang="ts">
2
2
import NodesCanvas from ' ../../Nodes.vue'
3
3
import DemoHeader from ' ../DemoHeader.vue' ;
4
- import { computed , ref } from ' vue'
4
+ import { ref } from ' vue'
5
5
import { useConnections } from ' ../../../hooks/useConnections' ;
6
- import type { ShaderGeneratorNode , Connection , Node } from ' ./types' ;
7
- import OutNode from ' ./nodes/Out.vue'
8
- import SourceNode from ' ./nodes/Source.vue'
9
- import ColorNode from ' ./nodes/Color.vue'
10
- import Fragment from ' ./nodes/Fragment.vue' ;
11
- import Vec4 from ' ./nodes/Vec4.vue'
12
- import Variable from ' ./nodes/Variable.vue'
13
- import Time from ' ./nodes/Time.vue'
14
- import MathFunction from ' ./nodes/MathFunction.vue'
6
+ import type { Connection , ShaderNode } from ' ./nodes' ;
7
+ import { createSourceNode , createTimeNode , createFragmentShaderNode , createVec4Node , createOutputNode , createMathNode } from ' ./nodes'
15
8
16
- const items = ref <ShaderGeneratorNode []>([
17
- {
18
- position: { x: 0 , y: 0 },
19
- type: ' out' ,
20
- title: ' Out' ,
21
- points: {
22
- input: {}
23
- }
24
- },
25
- {
26
- position: { x: 0 , y: 0 },
27
- type: ' source' ,
28
- title: ' Source' ,
29
- points: {
30
- input: {},
31
- out: {}
32
- }
33
- },
34
- {
35
- position: { x: - 100 , y: 0 },
36
- type: ' color' ,
37
- title: ' Color' ,
38
- points: {
39
- r: { default: 0 , value: 0 },
40
- g: { default: 0 , value: 0 },
41
- b: { default: 0 , value: 0 },
42
- out: {}
43
- }
44
- },
45
- {
46
- position: { x: 0 , y: 200 },
47
- type: ' fragment' ,
48
- title: ' Fragment Shader' ,
49
- points: {
50
- input: {},
51
- out: {}
52
- }
53
- },
54
- {
55
- position: { x: - 350 , y: 0 },
56
- type: ' vec4' ,
57
- title: ' Vec4' ,
58
- points: {
59
- x: { default: 0 , value: 0 },
60
- y: { default: 0 , value: 0 },
61
- z: { default: 0 , value: 0 },
62
- w: { default: 0 , value: 0 },
63
- out: {}
64
- }
65
- },
66
- {
67
- position: { x: 0 , y: 500 },
68
- type: ' variable' ,
69
- title: ' Var' ,
70
- variable: {
71
- value: 0 ,
72
- type: ' float'
73
- },
74
- points: {
75
- in: {},
76
- out: {}
77
- }
78
- },
79
- {
80
- position: { x: 0 , y: - 300 },
81
- type: ' time' ,
82
- title: ' Time' ,
83
- variable: {
84
- value: 0 ,
85
- },
86
- points: {
87
- in: {},
88
- out: {}
89
- }
90
- },
91
- {
92
- position: { x: - 200 , y: - 300 },
93
- type: ' math' ,
94
- title: ' Math function' ,
95
- function: ' sin' ,
96
- points: {
97
- in: {},
98
- out: {}
99
- }
100
- },
9
+ const items = ref <ShaderNode <any >[]>([
10
+ createTimeNode ({ x: - 300 , y: 0 }),
11
+ (() => {
12
+ const math = createMathNode ({ x: 0 , y: 0 })
13
+ math .value .fn = ' sin'
14
+ return math
15
+ })(),
16
+ (() => {
17
+ const math = createMathNode ({ x: 0 , y: 100 })
18
+ math .value .fn = ' cos'
19
+ return math
20
+ })(),
21
+ (() => {
22
+ const vec4 = createVec4Node ({ x: 300 , y: 0 })
23
+ vec4 .value .z = 1 ;
24
+ vec4 .value .w = 1 ;
25
+ return vec4
26
+ })(),
27
+ createFragmentShaderNode ({ x: - 300 , y: - 200 }),
28
+ createSourceNode ({ x: 100 , y: - 300 }),
29
+ createOutputNode ({ x: 500 , y: 300 })
101
30
])
102
31
103
- const connections = ref <Connection <ShaderGeneratorNode >[]>([])
32
+ const connections = ref <Connection <ShaderNode >[]>([
33
+ { start: { node: items .value [0 ], point: ' out' }, end: { node: items .value [1 ], point: ' in' }},
34
+ { start: { node: items .value [0 ], point: ' out' }, end: { node: items .value [2 ], point: ' in' }},
35
+ // Vec4
36
+ { start: { node: items .value [1 ], point: ' out' }, end: { node: items .value [3 ], point: ' x' }},
37
+ { start: { node: items .value [2 ], point: ' out' }, end: { node: items .value [3 ], point: ' y' }},
104
38
105
- const { registerPoint, connectFrom, connectTo } = useConnections <ShaderGeneratorNode >(connections )
39
+ { start: { node: items .value [3 ], point: ' out' }, end: { node: items .value [4 ], point: ' in' }},
40
+ { start: { node: items .value [4 ], point: ' out' }, end: { node: items .value [5 ], point: ' in' }},
106
41
107
- const shader = computed (() => ` precision highp float;
108
- void main() {
109
- gl_FragColor = vec4(sin(time), cos(time), sin(time), 1.0);
110
- }
111
- ` )
42
+ { start: { node: items .value [5 ], point: ' out' }, end: { node: items .value [6 ], point: ' in' }},
43
+ ])
44
+
45
+ const { connectFrom, connectTo, registerPoint } = useConnections (connections )
112
46
</script >
113
47
114
48
<template >
@@ -123,57 +57,13 @@ void main() {
123
57
124
58
<NodesCanvas v-model:nodes =" items" v-model:connections =" connections" >
125
59
<template #node-content =" { node } " >
126
- <OutNode
127
- v-if =" node.type === 'out'"
128
- :node =" (node as ShaderGeneratorNode)"
129
- :register-point =" registerPoint"
60
+ <component
61
+ :is =" (node as ShaderNode).component"
130
62
:connections =" connections"
131
- @circle-click =" connectFrom((node as ShaderGeneratorNode) , $event[0])"
132
- @connect-to =" connectTo((node as ShaderGeneratorNode), $event)"
133
- />
134
- <SourceNode
135
- v-if =" node.type === 'source'"
136
- :shader =" shader"
137
- :node =" (node as ShaderGeneratorNode)"
138
- :register-point =" registerPoint"
139
- :connections =" connections"
140
- @connect-to =" connectTo((node as ShaderGeneratorNode), $event)"
141
- @connect-from =" connectFrom((node as ShaderGeneratorNode), $event)"
142
- />
143
- <ColorNode
144
- v-if =" node.type === 'color'" :node =" (node as ShaderGeneratorNode)"
145
- :register-point =" registerPoint"
146
- @connect-from =" connectFrom((node as ShaderGeneratorNode), $event)"
147
- />
148
- <Fragment
149
- v-if =" node.type === 'fragment'" :node =" (node as ShaderGeneratorNode)"
150
- :register-point =" registerPoint"
151
- @connect-to =" connectTo((node as ShaderGeneratorNode), $event)"
152
- @connect-from =" connectFrom((node as ShaderGeneratorNode), $event)"
153
- />
154
- <Vec4
155
- v-if =" node.type === 'vec4'" :node =" (node as ShaderGeneratorNode)"
156
- :register-point =" registerPoint"
157
- @connect-to =" connectTo((node as ShaderGeneratorNode), $event)"
158
- @connect-from =" connectFrom((node as ShaderGeneratorNode), $event)"
159
- />
160
- <Variable
161
- v-if =" node.type === 'variable'" :node =" (node as ShaderGeneratorNode)"
162
- :register-point =" registerPoint"
163
- @connect-to =" connectTo((node as ShaderGeneratorNode), $event)"
164
- @connect-from =" connectFrom((node as ShaderGeneratorNode), $event)"
165
- />
166
- <Time
167
- v-if =" node.type === 'time'" :node =" (node as ShaderGeneratorNode)"
168
- :register-point =" registerPoint"
169
- @connect-to =" connectTo((node as ShaderGeneratorNode), $event)"
170
- @connect-from =" connectFrom((node as ShaderGeneratorNode), $event)"
171
- />
172
- <MathFunction
173
- v-if =" node.type === 'math'" :node =" (node as ShaderGeneratorNode)"
63
+ :node =" node"
174
64
:register-point =" registerPoint"
175
- @connect-to = " connectTo ((node as ShaderGeneratorNode) , $event)"
176
- @connect-from = " connectFrom ((node as ShaderGeneratorNode ), $event)"
65
+ @connect-from = " connectFrom ((node as ShaderNode) , $event)"
66
+ @connect-to = " connectTo ((node as ShaderNode ), $event)"
177
67
/>
178
68
</template >
179
69
</NodesCanvas >
0 commit comments