glre 0.22.0 → 0.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -18
- package/dist/index.d.ts +60 -220
- package/dist/index.js +35 -37
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +35 -37
- package/dist/index.mjs.map +1 -1
- package/dist/native.d.ts +49 -5
- package/dist/native.js +35 -37
- package/dist/native.js.map +1 -1
- package/dist/native.mjs +35 -37
- package/dist/native.mjs.map +1 -1
- package/dist/react.d.ts +1 -2
- package/dist/react.js +35 -37
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +35 -37
- package/dist/react.mjs.map +1 -1
- package/dist/solid.d.ts +1 -2
- package/dist/solid.js +35 -37
- package/dist/solid.js.map +1 -1
- package/dist/solid.mjs +35 -37
- package/dist/solid.mjs.map +1 -1
- package/package.json +5 -1
- package/src/code/glsl.ts +7 -45
- package/src/code/wgsl.ts +10 -46
- package/src/index.ts +31 -29
- package/src/native.ts +9 -4
- package/src/node/cache.ts +3 -10
- package/src/node/const.ts +2 -19
- package/src/node/conv.ts +6 -17
- package/src/node/index.ts +3 -6
- package/src/node/node.ts +8 -22
- package/src/node/uniform.ts +6 -13
- package/src/react.ts +0 -1
- package/src/solid.ts +0 -1
- package/src/types.ts +20 -21
- package/src/{utils.ts → utils/helpers.ts} +0 -9
- package/src/utils/pipeline.ts +128 -0
- package/src/utils/program.ts +94 -0
- package/src/webgl.ts +78 -0
- package/src/webgpu.ts +70 -0
- package/src/webgl/buffer.ts +0 -78
- package/src/webgl/index.ts +0 -79
- package/src/webgl/program.ts +0 -61
- package/src/webgl/shader.ts +0 -60
- package/src/webgl/texture.ts +0 -93
- package/src/webgpu/buffer.ts +0 -96
- package/src/webgpu/device.ts +0 -91
- package/src/webgpu/index.ts +0 -40
- package/src/webgpu/pipeline.ts +0 -94
- package/src/webgpu/texture.ts +0 -139
package/src/code/wgsl.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { is } from '../utils'
|
|
1
|
+
import { is } from '../utils/helpers'
|
|
2
2
|
import type { Node, NodeType, ConversionContext, X } from '../node'
|
|
3
3
|
|
|
4
4
|
// WGSLコード生成コンテキスト
|
|
@@ -7,10 +7,7 @@ interface WGSLContext extends ConversionContext {
|
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
// ノードからWGSLコードを生成
|
|
10
|
-
export const nodeToWGSL = (
|
|
11
|
-
nodeProxy: X,
|
|
12
|
-
context?: Partial<WGSLContext>
|
|
13
|
-
): string => {
|
|
10
|
+
export const nodeToWGSL = (nodeProxy: X, context?: Partial<WGSLContext>): string => {
|
|
14
11
|
const ctx: WGSLContext = {
|
|
15
12
|
target: 'webgpu',
|
|
16
13
|
nodes: new Map(),
|
|
@@ -25,16 +22,14 @@ export const nodeToWGSL = (
|
|
|
25
22
|
const generateWGSLExpression = (node: Node, context: WGSLContext): string => {
|
|
26
23
|
if (!node) return '0.0'
|
|
27
24
|
// 値ノード
|
|
28
|
-
if (node.value !== undefined)
|
|
29
|
-
return formatWGSLValue(node.value, node.type)
|
|
25
|
+
if (node.value !== undefined) return formatWGSLValue(node.value, node.type)
|
|
30
26
|
// プロパティアクセス(スウィズル)
|
|
31
27
|
if (node.property && node.parent) {
|
|
32
28
|
const parentExpr = generateWGSLExpression(node.parent, context)
|
|
33
29
|
return `${parentExpr}.${node.property}`
|
|
34
30
|
}
|
|
35
31
|
// 演算子ノード
|
|
36
|
-
if (node.operator && node.children && node.children.length >= 2)
|
|
37
|
-
return generateWGSLOperator(node, context)
|
|
32
|
+
if (node.operator && node.children && node.children.length >= 2) return generateWGSLOperator(node, context)
|
|
38
33
|
// 数学関数ノード
|
|
39
34
|
if (node.mathFunction && node.children && node.children.length >= 1)
|
|
40
35
|
return generateWGSLMathFunction(node, context)
|
|
@@ -90,44 +85,13 @@ const generateWGSLOperator = (node: Node, context: WGSLContext): string => {
|
|
|
90
85
|
const generateWGSLMathFunction = (node: Node, context: WGSLContext): string => {
|
|
91
86
|
if (!node.children || node.children.length < 1) return '0.0'
|
|
92
87
|
const fun = node.mathFunction
|
|
93
|
-
const args = node.children.map((child) =>
|
|
94
|
-
generateWGSLExpression(child, context)
|
|
95
|
-
)
|
|
88
|
+
const args = node.children.map((child) => generateWGSLExpression(child, context))
|
|
96
89
|
const [x, y, z] = args
|
|
97
|
-
//
|
|
98
|
-
if (
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
if (fun === 'atan') return `atan(${x})`
|
|
103
|
-
if (fun === 'ceil') return `ceil(${x})`
|
|
104
|
-
if (fun === 'cos') return `cos(${x})`
|
|
105
|
-
if (fun === 'floor') return `floor(${x})`
|
|
106
|
-
if (fun === 'fract') return `fract(${x})`
|
|
107
|
-
if (fun === 'length') return `length(${x})`
|
|
108
|
-
if (fun === 'normalize') return `normalize(${x})`
|
|
109
|
-
if (fun === 'sin') return `sin(${x})`
|
|
110
|
-
if (fun === 'sqrt') return `sqrt(${x})`
|
|
111
|
-
if (fun === 'tan') return `tan(${x})`
|
|
112
|
-
}
|
|
113
|
-
// 二項関数
|
|
114
|
-
if (args.length === 2) {
|
|
115
|
-
if (fun === 'atan2') return `atan2(${x}, ${y})`
|
|
116
|
-
if (fun === 'pow') return `pow(${x}, ${y})`
|
|
117
|
-
if (fun === 'min') return `min(${x}, ${y})`
|
|
118
|
-
if (fun === 'max') return `max(${x}, ${y})`
|
|
119
|
-
if (fun === 'dot') return `dot(${x}, ${y})`
|
|
120
|
-
if (fun === 'cross') return `cross(${x}, ${y})`
|
|
121
|
-
if (fun === 'distance') return `distance(${x}, ${y})`
|
|
122
|
-
if (fun === 'reflect') return `reflect(${x}, ${y})`
|
|
123
|
-
}
|
|
124
|
-
// 三項関数
|
|
125
|
-
if (args.length === 3) {
|
|
126
|
-
if (fun === 'mix') return `mix(${x}, ${y}, ${z})`
|
|
127
|
-
if (fun === 'clamp') return `clamp(${x}, ${y}, ${z})`
|
|
128
|
-
if (fun === 'smoothstep') return `smoothstep(${x}, ${y}, ${z})`
|
|
129
|
-
return x
|
|
130
|
-
}
|
|
90
|
+
// @TODO FIX
|
|
91
|
+
// if (fun === 'toVar') return x // toVarは変数化のヒントなので、そのまま返す
|
|
92
|
+
if (args.length === 1) return `${fun}(${x})`
|
|
93
|
+
if (args.length === 2) return `${fun}(${x}, ${y})`
|
|
94
|
+
if (args.length === 3) return `${fun}(${x}, ${y}, ${z})`
|
|
131
95
|
return x || '0.0'
|
|
132
96
|
}
|
|
133
97
|
|
package/src/index.ts
CHANGED
|
@@ -1,27 +1,37 @@
|
|
|
1
1
|
import { durable, event } from 'reev'
|
|
2
2
|
import { createFrame, createQueue } from 'refr'
|
|
3
|
-
import { webgl } from './webgl
|
|
4
|
-
import { webgpu } from './webgpu
|
|
5
|
-
import { is
|
|
3
|
+
import { webgl } from './webgl'
|
|
4
|
+
import { webgpu } from './webgpu'
|
|
5
|
+
import { is } from './utils/helpers'
|
|
6
6
|
import type { EventState } from 'reev'
|
|
7
7
|
import type { GL } from './types'
|
|
8
8
|
export * from './code/glsl'
|
|
9
9
|
export * from './code/wgsl'
|
|
10
10
|
export * from './node'
|
|
11
11
|
export * from './types'
|
|
12
|
-
export * from './utils'
|
|
12
|
+
export * from './utils/helpers'
|
|
13
|
+
export * from './utils/pipeline'
|
|
14
|
+
export * from './utils/program'
|
|
13
15
|
export * from './webgl'
|
|
14
16
|
export * from './webgpu'
|
|
15
17
|
|
|
16
|
-
let iTime = performance.now(),
|
|
17
|
-
iPrevTime = 0,
|
|
18
|
-
iDeltaTime = 0
|
|
19
|
-
|
|
20
18
|
export const isGL = (a: unknown): a is EventState<GL> => {
|
|
21
19
|
if (!is.obj(a)) return false
|
|
22
20
|
if ('isGL' in a) return true
|
|
23
21
|
return false
|
|
24
22
|
}
|
|
23
|
+
export const isServer = () => {
|
|
24
|
+
return typeof window === 'undefined'
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export const isWebGPUSupported = () => {
|
|
28
|
+
if (isServer()) return false
|
|
29
|
+
return 'gpu' in navigator
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
let iTime = performance.now(),
|
|
33
|
+
iPrevTime = 0,
|
|
34
|
+
iDeltaTime = 0
|
|
25
35
|
|
|
26
36
|
export const createGL = (props?: Partial<GL>) => {
|
|
27
37
|
const gl = event<Partial<GL>>({
|
|
@@ -31,16 +41,23 @@ export const createGL = (props?: Partial<GL>) => {
|
|
|
31
41
|
isGL: true,
|
|
32
42
|
size: [0, 0],
|
|
33
43
|
mouse: [0, 0],
|
|
34
|
-
count:
|
|
35
|
-
|
|
44
|
+
count: 3,
|
|
45
|
+
webgl: {},
|
|
46
|
+
webgpu: {},
|
|
36
47
|
}) as EventState<GL>
|
|
37
48
|
|
|
38
|
-
gl
|
|
49
|
+
gl.queue = createQueue()
|
|
50
|
+
gl.frame = createFrame()
|
|
51
|
+
|
|
52
|
+
gl.attribute = durable((k, v, i) => gl.queue(() => gl._attribute?.(k, v, i)))
|
|
53
|
+
gl.uniform = durable((k, v, i) => gl.queue(() => gl._uniform?.(k, v, i)))
|
|
54
|
+
gl.texture = durable((k, v) => gl.queue(() => gl._texture?.(k, v)))
|
|
55
|
+
|
|
56
|
+
gl('mount', async () => {
|
|
39
57
|
if (!isWebGPUSupported()) gl.isWebGL = true
|
|
40
58
|
if (gl.isWebGL) {
|
|
41
|
-
webgl(gl)
|
|
42
|
-
} else webgpu(gl)
|
|
43
|
-
gl.init()
|
|
59
|
+
await webgl(gl)
|
|
60
|
+
} else await webgpu(gl)
|
|
44
61
|
gl.resize()
|
|
45
62
|
gl.frame(() => {
|
|
46
63
|
gl.loop()
|
|
@@ -84,21 +101,6 @@ export const createGL = (props?: Partial<GL>) => {
|
|
|
84
101
|
gl.uniform('iMouse', gl.mouse)
|
|
85
102
|
})
|
|
86
103
|
|
|
87
|
-
gl.queue = createQueue()
|
|
88
|
-
gl.frame = createFrame()
|
|
89
|
-
|
|
90
|
-
gl.attribute = durable((key, value, iboValue) => {
|
|
91
|
-
gl.queue(() => void gl._attribute?.(key, value, iboValue))
|
|
92
|
-
})
|
|
93
|
-
|
|
94
|
-
gl.uniform = durable((key, value, isMatrix) => {
|
|
95
|
-
gl.queue(() => void gl._uniform?.(key, value, isMatrix))
|
|
96
|
-
})
|
|
97
|
-
|
|
98
|
-
gl.texture = durable((key, value) => {
|
|
99
|
-
gl.queue(() => void gl._texture?.(key, value))
|
|
100
|
-
})
|
|
101
|
-
|
|
102
104
|
return gl(props)
|
|
103
105
|
}
|
|
104
106
|
|
package/src/native.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useState } from 'react'
|
|
1
|
+
import { useState } from 'react' // @ts-ignore
|
|
2
2
|
import { Dimensions } from 'react-native'
|
|
3
3
|
import { createGL, isGL } from './index'
|
|
4
4
|
import type { GL } from './types'
|
|
@@ -8,8 +8,13 @@ export const useGL = (props: Partial<GL> = {}) => {
|
|
|
8
8
|
return useState(() => {
|
|
9
9
|
const gl = isGL(props) ? props : createGL(props)
|
|
10
10
|
gl.ref = (ctx: any) => {
|
|
11
|
-
gl.el = {}
|
|
12
|
-
gl
|
|
11
|
+
gl.el = {} as any
|
|
12
|
+
gl({
|
|
13
|
+
render() {
|
|
14
|
+
ctx.flush()
|
|
15
|
+
ctx.endFrameEXP()
|
|
16
|
+
},
|
|
17
|
+
})
|
|
13
18
|
gl.mount()
|
|
14
19
|
const resize = () => {
|
|
15
20
|
gl.width = ctx.drawingBufferWidth
|
|
@@ -19,6 +24,6 @@ export const useGL = (props: Partial<GL> = {}) => {
|
|
|
19
24
|
resize()
|
|
20
25
|
Dimensions.addEventListener('change', resize)
|
|
21
26
|
}
|
|
22
|
-
return gl
|
|
27
|
+
return gl({ isNative: true })
|
|
23
28
|
})[0]
|
|
24
29
|
}
|
package/src/node/cache.ts
CHANGED
|
@@ -43,10 +43,7 @@ export const findDuplicateNodes = (nodes: X[]): Map<string, X[]> => {
|
|
|
43
43
|
nodes.forEach((nodeProxy) => {
|
|
44
44
|
const signature = generateNodeSignature(nodeProxy)
|
|
45
45
|
if (signatures.has(signature)) {
|
|
46
|
-
if (!duplicates.has(signature))
|
|
47
|
-
duplicates.set(signature, [
|
|
48
|
-
signatures.get(signature)!,
|
|
49
|
-
])
|
|
46
|
+
if (!duplicates.has(signature)) duplicates.set(signature, [signatures.get(signature)!])
|
|
50
47
|
duplicates.get(signature)!.push(nodeProxy)
|
|
51
48
|
} else signatures.set(signature, nodeProxy)
|
|
52
49
|
})
|
|
@@ -55,13 +52,9 @@ export const findDuplicateNodes = (nodes: X[]): Map<string, X[]> => {
|
|
|
55
52
|
|
|
56
53
|
// ノードのシグネチャを生成
|
|
57
54
|
const generateNodeSignature = (nodeProxy: X): string => {
|
|
58
|
-
const parts = [
|
|
59
|
-
nodeProxy.type,
|
|
60
|
-
`${nodeProxy.value}`,
|
|
61
|
-
nodeProxy.property || '',
|
|
62
|
-
]
|
|
55
|
+
const parts = [nodeProxy.type, `${nodeProxy.value}`, nodeProxy.property || '']
|
|
63
56
|
return parts.join('|')
|
|
64
57
|
}
|
|
65
58
|
|
|
66
59
|
// 初期化を実行
|
|
67
|
-
initializeCache()
|
|
60
|
+
// initializeCache()
|
package/src/node/const.ts
CHANGED
|
@@ -25,26 +25,9 @@ export const TYPES = [
|
|
|
25
25
|
export type NodeType = (typeof TYPES)[number]
|
|
26
26
|
|
|
27
27
|
// スウィズル定数
|
|
28
|
-
export const SWIZZLES = [
|
|
29
|
-
'x',
|
|
30
|
-
'y',
|
|
31
|
-
'z',
|
|
32
|
-
'w',
|
|
33
|
-
'r',
|
|
34
|
-
'g',
|
|
35
|
-
'b',
|
|
36
|
-
'a',
|
|
37
|
-
's',
|
|
38
|
-
't',
|
|
39
|
-
'p',
|
|
40
|
-
'q',
|
|
41
|
-
] as const
|
|
28
|
+
export const SWIZZLES = ['x', 'y', 'z', 'w', 'r', 'g', 'b', 'a', 's', 't', 'p', 'q'] as const
|
|
42
29
|
|
|
43
|
-
type AllSwizzles<T extends string> =
|
|
44
|
-
| T
|
|
45
|
-
| `${T}${T}`
|
|
46
|
-
| `${T}${T}${T}`
|
|
47
|
-
| `${T}${T}${T}${T}`
|
|
30
|
+
type AllSwizzles<T extends string> = T | `${T}${T}` | `${T}${T}${T}` | `${T}${T}${T}${T}`
|
|
48
31
|
|
|
49
32
|
export type Swillzes =
|
|
50
33
|
| AllSwizzles<'x' | 'y' | 'z' | 'w'>
|
package/src/node/conv.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { node } from '.'
|
|
2
2
|
import { getCachedBool, getCachedInt, getCachedFloat } from './cache'
|
|
3
|
-
import { is } from '../utils'
|
|
3
|
+
import { is } from '../utils/helpers'
|
|
4
4
|
import type { X } from './types'
|
|
5
5
|
|
|
6
6
|
// JavaScript値をノードに変換
|
|
@@ -63,8 +63,7 @@ export const vec2 = (x?: any, y?: any): X => {
|
|
|
63
63
|
if (is.und(x)) return node('vec2', [0, 0])
|
|
64
64
|
if (is.und(y)) {
|
|
65
65
|
if (is.arr(x)) return node('vec2', x.slice(0, 2))
|
|
66
|
-
if (is.obj(x) && 'x' in x && 'y' in x)
|
|
67
|
-
return node('vec2', [x.x, x.y])
|
|
66
|
+
if (is.obj(x) && 'x' in x && 'y' in x) return node('vec2', [x.x, x.y])
|
|
68
67
|
return node('vec2', [Number(x), Number(x)])
|
|
69
68
|
}
|
|
70
69
|
return node('vec2', [Number(x), Number(y)])
|
|
@@ -74,8 +73,7 @@ export const vec3 = (x?: any, y?: any, z?: any): X => {
|
|
|
74
73
|
if (is.und(x)) return node('vec3', [0, 0, 0])
|
|
75
74
|
if (is.und(y)) {
|
|
76
75
|
if (is.arr(x)) return node('vec3', x.slice(0, 3))
|
|
77
|
-
if (is.obj(x) && 'x' in x && 'y' in x && 'z' in x)
|
|
78
|
-
return node('vec3', [x.x, x.y, x.z])
|
|
76
|
+
if (is.obj(x) && 'x' in x && 'y' in x && 'z' in x) return node('vec3', [x.x, x.y, x.z])
|
|
79
77
|
return node('vec3', [Number(x), Number(x), Number(x)])
|
|
80
78
|
}
|
|
81
79
|
if (z === undefined) {
|
|
@@ -88,8 +86,7 @@ export const vec4 = (x?: any, y?: any, z?: any, w?: any): X => {
|
|
|
88
86
|
if (is.und(x)) return node('vec4', [0, 0, 0, 1])
|
|
89
87
|
if (is.und(y)) {
|
|
90
88
|
if (is.arr(x)) return node('vec4', x.slice(0, 4))
|
|
91
|
-
if (is.obj(x) && 'x' in x && 'y' in x && 'z' in x && 'w' in x)
|
|
92
|
-
return node('vec4', [x.x, x.y, x.z, x.w])
|
|
89
|
+
if (is.obj(x) && 'x' in x && 'y' in x && 'z' in x && 'w' in x) return node('vec4', [x.x, x.y, x.z, x.w])
|
|
93
90
|
return node('vec4', [Number(x), Number(x), Number(x), 1])
|
|
94
91
|
}
|
|
95
92
|
return node('vec4', [Number(x), Number(y), Number(z), Number(w)])
|
|
@@ -102,20 +99,12 @@ export const color = (r?: any, g?: any, b?: any): X => {
|
|
|
102
99
|
if (is.str(r) && r.startsWith('#')) {
|
|
103
100
|
const hex = r.slice(1)
|
|
104
101
|
const num = parseInt(hex, 16)
|
|
105
|
-
return node('color', [
|
|
106
|
-
((num >> 16) & 255) / 255,
|
|
107
|
-
((num >> 8) & 255) / 255,
|
|
108
|
-
(num & 255) / 255,
|
|
109
|
-
])
|
|
102
|
+
return node('color', [((num >> 16) & 255) / 255, ((num >> 8) & 255) / 255, (num & 255) / 255])
|
|
110
103
|
}
|
|
111
104
|
|
|
112
105
|
// 数値カラーの処理
|
|
113
106
|
if (is.num(r) && g === undefined && b === undefined) {
|
|
114
|
-
return node('color', [
|
|
115
|
-
((r >> 16) & 255) / 255,
|
|
116
|
-
((r >> 8) & 255) / 255,
|
|
117
|
-
(r & 255) / 255,
|
|
118
|
-
])
|
|
107
|
+
return node('color', [((r >> 16) & 255) / 255, ((r >> 8) & 255) / 255, (r & 255) / 255])
|
|
119
108
|
}
|
|
120
109
|
|
|
121
110
|
return vec3(r, g, b)
|
package/src/node/index.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { float } from './conv'
|
|
1
2
|
import { node } from './node'
|
|
2
3
|
import { uniform } from './uniform'
|
|
3
|
-
import {
|
|
4
|
-
import { is } from '../utils'
|
|
4
|
+
import { is } from '../utils/helpers'
|
|
5
5
|
import type { X, FunctionNode, ConditionalNode } from './types'
|
|
6
6
|
export type { X, FunctionNode, ConditionalNode }
|
|
7
7
|
export * from './cache'
|
|
@@ -30,10 +30,7 @@ export const If = (condition: X, callback: () => void): ConditionalNode => {
|
|
|
30
30
|
callback()
|
|
31
31
|
|
|
32
32
|
const conditionalNode = {
|
|
33
|
-
ElseIf(
|
|
34
|
-
newCondition: X,
|
|
35
|
-
newCallback: () => void
|
|
36
|
-
): ConditionalNode {
|
|
33
|
+
ElseIf(newCondition: X, newCallback: () => void): ConditionalNode {
|
|
37
34
|
newCallback()
|
|
38
35
|
return conditionalNode
|
|
39
36
|
},
|
package/src/node/node.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { OPERATORS, FUNCTIONS, SWIZZLES
|
|
2
|
-
import { is } from '../utils'
|
|
1
|
+
import { OPERATORS, FUNCTIONS, SWIZZLES } from './const'
|
|
2
|
+
import { is } from '../utils/helpers'
|
|
3
|
+
import type { NodeType } from './const'
|
|
3
4
|
import type { Node, ProxyCallback, X } from './types'
|
|
4
5
|
|
|
5
6
|
let nodeIdCounter = 0
|
|
@@ -8,11 +9,7 @@ let nodeIdCounter = 0
|
|
|
8
9
|
const generateNodeId = () => `node_${++nodeIdCounter}`
|
|
9
10
|
|
|
10
11
|
// ノードを作成
|
|
11
|
-
export const createNode = (
|
|
12
|
-
type: NodeType,
|
|
13
|
-
value?: any,
|
|
14
|
-
options?: Partial<Node>
|
|
15
|
-
): Node => {
|
|
12
|
+
export const createNode = (type: NodeType, value?: any, options?: Partial<Node>): Node => {
|
|
16
13
|
return {
|
|
17
14
|
id: generateNodeId(),
|
|
18
15
|
type,
|
|
@@ -62,21 +59,10 @@ const createNodeProxy = (node: Node, callback?: (info: ProxyCallback) => X) => {
|
|
|
62
59
|
if (isMathMethod(key))
|
|
63
60
|
return (...args: any[]) => {
|
|
64
61
|
return createNodeProxy(
|
|
65
|
-
createNode(
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
),
|
|
70
|
-
undefined,
|
|
71
|
-
{
|
|
72
|
-
mathFunction:
|
|
73
|
-
key as any,
|
|
74
|
-
children: [
|
|
75
|
-
node,
|
|
76
|
-
...args,
|
|
77
|
-
],
|
|
78
|
-
}
|
|
79
|
-
),
|
|
62
|
+
createNode(getMathReturnType(key, node.type), undefined, {
|
|
63
|
+
mathFunction: key as any,
|
|
64
|
+
children: [node, ...args],
|
|
65
|
+
}),
|
|
80
66
|
callback
|
|
81
67
|
)
|
|
82
68
|
}
|
package/src/node/uniform.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { node } from './node'
|
|
2
|
-
import { is } from '../utils'
|
|
2
|
+
import { is } from '../utils/helpers'
|
|
3
3
|
import type { UniformNode } from './types'
|
|
4
4
|
import type { NodeType } from './const'
|
|
5
5
|
|
|
@@ -24,8 +24,7 @@ const inferUniformType = (value: any): NodeType => {
|
|
|
24
24
|
if (len === 9) return 'mat3'
|
|
25
25
|
if (len === 16) return 'mat4'
|
|
26
26
|
}
|
|
27
|
-
if (is.obj(value) && 'r' in value && 'g' in value && 'b' in value)
|
|
28
|
-
return 'color'
|
|
27
|
+
if (is.obj(value) && 'r' in value && 'g' in value && 'b' in value) return 'color'
|
|
29
28
|
return 'float'
|
|
30
29
|
}
|
|
31
30
|
|
|
@@ -33,10 +32,8 @@ const inferUniformType = (value: any): NodeType => {
|
|
|
33
32
|
export const uniform = (initialValue: any): UniformNode => {
|
|
34
33
|
const type = inferUniformType(initialValue)
|
|
35
34
|
let currentValue = initialValue
|
|
36
|
-
let objectUpdateCallback: ((context: UpdateContext) => any) | null =
|
|
37
|
-
|
|
38
|
-
let renderUpdateCallback: ((context: UpdateContext) => any) | null =
|
|
39
|
-
null
|
|
35
|
+
let objectUpdateCallback: ((context: UpdateContext) => any) | null = null
|
|
36
|
+
let renderUpdateCallback: ((context: UpdateContext) => any) | null = null
|
|
40
37
|
|
|
41
38
|
const baseNode = node(type, currentValue) as any
|
|
42
39
|
|
|
@@ -46,16 +43,12 @@ export const uniform = (initialValue: any): UniformNode => {
|
|
|
46
43
|
baseNode.value = value
|
|
47
44
|
}
|
|
48
45
|
// オブジェクト更新時のコールバックを設定
|
|
49
|
-
const onObjectUpdate = (
|
|
50
|
-
callback: (context: UpdateContext) => any
|
|
51
|
-
): UniformNode => {
|
|
46
|
+
const onObjectUpdate = (callback: (context: UpdateContext) => any): UniformNode => {
|
|
52
47
|
objectUpdateCallback = callback
|
|
53
48
|
return uniformNode
|
|
54
49
|
}
|
|
55
50
|
// レンダー更新時のコールバックを設定
|
|
56
|
-
const onRenderUpdate = (
|
|
57
|
-
callback: (context: UpdateContext) => any
|
|
58
|
-
): UniformNode => {
|
|
51
|
+
const onRenderUpdate = (callback: (context: UpdateContext) => any): UniformNode => {
|
|
59
52
|
renderUpdateCallback = callback
|
|
60
53
|
return uniformNode
|
|
61
54
|
}
|
package/src/react.ts
CHANGED
package/src/solid.ts
CHANGED
package/src/types.ts
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { X } from './node'
|
|
1
|
+
import { EventState } from 'reev'
|
|
3
2
|
import type { Fun, Queue, Frame } from 'refr'
|
|
3
|
+
import type { X } from './node'
|
|
4
4
|
export type { Fun, Queue, Frame }
|
|
5
|
+
export type GPUContext = any // GPUCanvasContext https://developer.mozilla.org/en-US/docs/Web/API/GPUCanvasContext
|
|
6
|
+
export type GPUDevice = any //
|
|
7
|
+
export type GPUBuffer = any //
|
|
8
|
+
export type GPUPipeline = any //
|
|
5
9
|
export type Uniform = number | number[]
|
|
6
10
|
export type Attribute = number[]
|
|
7
11
|
export type Attributes = Record<string, Attribute>
|
|
8
12
|
export type Uniforms = Record<string, Uniform>
|
|
9
13
|
export type PrecisionMode = 'highp' | 'mediump' | 'lowp'
|
|
10
|
-
|
|
11
14
|
export type GLClearMode = 'COLOR_BUFFER_BIT' | 'DEPTH_BUFFER_BIT' | 'STENCIL_BUFFER_BIT'
|
|
12
|
-
|
|
15
|
+
export type GLDrawType = 'UNSIGNED_BYTE' | 'UNSIGNED_SHORT' | 'UNSIGNED_INT'
|
|
13
16
|
export type GLDrawMode =
|
|
14
17
|
| 'POINTS'
|
|
15
18
|
| 'LINE_STRIP'
|
|
@@ -19,7 +22,16 @@ export type GLDrawMode =
|
|
|
19
22
|
| 'TRIANGLE_FAN'
|
|
20
23
|
| 'TRIANGLES'
|
|
21
24
|
|
|
22
|
-
export
|
|
25
|
+
export interface WebGLState {
|
|
26
|
+
context: WebGLRenderingContext
|
|
27
|
+
program: WebGLProgram
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface WebGPUState {
|
|
31
|
+
device: GPUDevice
|
|
32
|
+
context: GPUContext
|
|
33
|
+
pipeline: GPUPipeline
|
|
34
|
+
}
|
|
23
35
|
|
|
24
36
|
export type GL = EventState<{
|
|
25
37
|
/**
|
|
@@ -34,6 +46,7 @@ export type GL = EventState<{
|
|
|
34
46
|
size: [number, number]
|
|
35
47
|
mouse: [number, number]
|
|
36
48
|
count: number
|
|
49
|
+
el: HTMLCanvasElement
|
|
37
50
|
vs: string | X
|
|
38
51
|
fs: string | X
|
|
39
52
|
vert: string | X
|
|
@@ -41,27 +54,13 @@ export type GL = EventState<{
|
|
|
41
54
|
vertex: string | X
|
|
42
55
|
fragment: string | X
|
|
43
56
|
|
|
44
|
-
/**
|
|
45
|
-
* for webgl
|
|
46
|
-
*/
|
|
47
|
-
int: PrecisionMode
|
|
48
|
-
float: PrecisionMode
|
|
49
|
-
sampler2D: PrecisionMode
|
|
50
|
-
samplerCube: PrecisionMode
|
|
51
|
-
lastActiveUnit: number
|
|
52
|
-
|
|
53
57
|
/**
|
|
54
58
|
* core state
|
|
55
59
|
*/
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
el: any
|
|
60
|
+
webgpu: WebGPUState
|
|
61
|
+
webgl: WebGLState
|
|
59
62
|
queue: Queue
|
|
60
63
|
frame: Frame
|
|
61
|
-
stride: Nested<number>
|
|
62
|
-
location: Nested<any> // @TODO Nested<(key: string, value: number: number[], ibo: number[]) => number>
|
|
63
|
-
activeUnit: Nested<number>
|
|
64
|
-
default: any
|
|
65
64
|
|
|
66
65
|
/**
|
|
67
66
|
* events
|
|
@@ -13,15 +13,6 @@ export const is = {
|
|
|
13
13
|
nan: (a: unknown): a is number => typeof a === 'number' && Number.isNaN(a),
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
export const isServer = () => {
|
|
17
|
-
return typeof window === 'undefined'
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export const isWebGPUSupported = () => {
|
|
21
|
-
if (isServer()) return false
|
|
22
|
-
return 'gpu' in navigator
|
|
23
|
-
}
|
|
24
|
-
|
|
25
16
|
/**
|
|
26
17
|
* each
|
|
27
18
|
*/
|