glre 0.26.0 → 0.28.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 +10 -9
- package/dist/index.cjs +66 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +547 -0
- package/dist/index.js +39 -21
- package/dist/index.js.map +1 -1
- package/dist/native.cjs +66 -0
- package/dist/native.cjs.map +1 -0
- package/dist/native.d.cts +53 -0
- package/dist/native.js +39 -21
- package/dist/native.js.map +1 -1
- package/dist/react.cjs +66 -0
- package/dist/react.cjs.map +1 -0
- package/dist/react.d.cts +8 -0
- package/dist/react.js +40 -22
- package/dist/react.js.map +1 -1
- package/dist/solid.cjs +66 -0
- package/dist/solid.cjs.map +1 -0
- package/dist/solid.d.cts +8 -0
- package/dist/solid.js +40 -22
- package/dist/solid.js.map +1 -1
- package/package.json +2 -1
- package/src/index.ts +0 -2
- package/src/native.ts +2 -2
- package/src/node/code.ts +103 -0
- package/src/node/const.ts +158 -98
- package/src/node/index.ts +109 -82
- package/src/node/infer.ts +93 -0
- package/src/node/node.ts +43 -92
- package/src/node/scope.ts +121 -0
- package/src/node/types.ts +120 -86
- package/src/node/utils.ts +95 -0
- package/src/utils/pipeline.ts +4 -5
- package/src/utils/program.ts +13 -9
- package/src/webgl.ts +1 -1
- package/src/webgpu.ts +2 -2
- package/dist/index.d.ts +0 -399
- package/dist/index.mjs +0 -48
- package/dist/index.mjs.map +0 -1
- package/dist/native.d.ts +0 -53
- package/dist/native.mjs +0 -48
- package/dist/native.mjs.map +0 -1
- package/dist/react.d.ts +0 -8
- package/dist/react.mjs +0 -48
- package/dist/react.mjs.map +0 -1
- package/dist/solid.d.ts +0 -8
- package/dist/solid.mjs +0 -48
- package/dist/solid.mjs.map +0 -1
- package/src/code/glsl.ts +0 -148
- package/src/code/wgsl.ts +0 -134
- package/src/node/cache.ts +0 -60
- package/src/node/conv.ts +0 -111
- package/src/node/uniform.ts +0 -92
package/src/node/conv.ts
DELETED
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import { node } from '.'
|
|
2
|
-
import { getCachedBool, getCachedInt, getCachedFloat } from './cache'
|
|
3
|
-
import { is } from '../utils/helpers'
|
|
4
|
-
import type { X } from './types'
|
|
5
|
-
|
|
6
|
-
// JavaScript値をノードに変換
|
|
7
|
-
export const convertToNode = (x: unknown): X => {
|
|
8
|
-
if (is.bol(x)) return getCachedBool(x)
|
|
9
|
-
if (is.num(x)) {
|
|
10
|
-
if (is.int(x)) return getCachedInt(x)
|
|
11
|
-
return getCachedFloat(x)
|
|
12
|
-
}
|
|
13
|
-
if (is.arr(x)) return convertArrayToNode(x)
|
|
14
|
-
if (is.obj(x)) return convertObjectToNode(x)
|
|
15
|
-
return node('float', 0)
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
// 配列をベクトル/行列ノードに変換
|
|
19
|
-
const convertArrayToNode = (array: number[]): X => {
|
|
20
|
-
const len = array.length
|
|
21
|
-
if (len === 2) return node('vec2', array)
|
|
22
|
-
if (len === 3) return node('vec3', array)
|
|
23
|
-
if (len === 4) return node('vec4', array)
|
|
24
|
-
if (len === 9) return node('mat3', array)
|
|
25
|
-
if (len === 16) return node('mat4', array)
|
|
26
|
-
return node('float', array[0])
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// オブジェクトをノードに変換
|
|
30
|
-
const convertObjectToNode = (obj: any): X => {
|
|
31
|
-
// カラーオブジェクトの検出
|
|
32
|
-
if ('r' in obj && 'g' in obj && 'b' in obj) {
|
|
33
|
-
const arr = [obj.r, obj.g, obj.b]
|
|
34
|
-
if ('a' in obj) arr.push(obj.a)
|
|
35
|
-
return node('color', arr)
|
|
36
|
-
}
|
|
37
|
-
// ベクトルライクオブジェクトの検出
|
|
38
|
-
if ('x' in obj && 'y' in obj) {
|
|
39
|
-
const arr = [obj.x, obj.y]
|
|
40
|
-
if ('z' in obj) arr.push(obj.z)
|
|
41
|
-
if ('w' in obj) arr.push(obj.w)
|
|
42
|
-
return convertArrayToNode(arr)
|
|
43
|
-
}
|
|
44
|
-
return node('float', 0)
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
// 型変換関数
|
|
48
|
-
export const float = (x: unknown): X => {
|
|
49
|
-
if (is.num(x)) return getCachedFloat(x)
|
|
50
|
-
return node('float', Number(x))
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export const int = (x: unknown): X => {
|
|
54
|
-
if (is.num(x) && Number.isInteger(x)) return getCachedInt(x)
|
|
55
|
-
return node('int', Math.floor(Number(x)))
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export const bool = (x: unknown): X => {
|
|
59
|
-
return getCachedBool(Boolean(x))
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export const vec2 = (x?: any, y?: any): X => {
|
|
63
|
-
if (is.und(x)) return node('vec2', [0, 0])
|
|
64
|
-
if (is.und(y)) {
|
|
65
|
-
if (is.arr(x)) return node('vec2', x.slice(0, 2))
|
|
66
|
-
if (is.obj(x) && 'x' in x && 'y' in x) return node('vec2', [x.x, x.y])
|
|
67
|
-
return node('vec2', [Number(x), Number(x)])
|
|
68
|
-
}
|
|
69
|
-
return node('vec2', [Number(x), Number(y)])
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
export const vec3 = (x?: any, y?: any, z?: any): X => {
|
|
73
|
-
if (is.und(x)) return node('vec3', [0, 0, 0])
|
|
74
|
-
if (is.und(y)) {
|
|
75
|
-
if (is.arr(x)) return node('vec3', x.slice(0, 3))
|
|
76
|
-
if (is.obj(x) && 'x' in x && 'y' in x && 'z' in x) return node('vec3', [x.x, x.y, x.z])
|
|
77
|
-
return node('vec3', [Number(x), Number(x), Number(x)])
|
|
78
|
-
}
|
|
79
|
-
if (z === undefined) {
|
|
80
|
-
return node('vec3', [Number(x), Number(y), 0])
|
|
81
|
-
}
|
|
82
|
-
return node('vec3', [Number(x), Number(y), Number(z)])
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
export const vec4 = (x?: any, y?: any, z?: any, w?: any): X => {
|
|
86
|
-
if (is.und(x)) return node('vec4', [0, 0, 0, 1])
|
|
87
|
-
if (is.und(y)) {
|
|
88
|
-
if (is.arr(x)) return node('vec4', x.slice(0, 4))
|
|
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])
|
|
90
|
-
return node('vec4', [Number(x), Number(x), Number(x), 1])
|
|
91
|
-
}
|
|
92
|
-
return node('vec4', [Number(x), Number(y), Number(z), Number(w)])
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
export const color = (r?: any, g?: any, b?: any): X => {
|
|
96
|
-
if (r === undefined) return node('color', [1, 1, 1])
|
|
97
|
-
|
|
98
|
-
// 16進数カラーの処理
|
|
99
|
-
if (is.str(r) && r.startsWith('#')) {
|
|
100
|
-
const hex = r.slice(1)
|
|
101
|
-
const num = parseInt(hex, 16)
|
|
102
|
-
return node('color', [((num >> 16) & 255) / 255, ((num >> 8) & 255) / 255, (num & 255) / 255])
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
// 数値カラーの処理
|
|
106
|
-
if (is.num(r) && g === undefined && b === undefined) {
|
|
107
|
-
return node('color', [((r >> 16) & 255) / 255, ((r >> 8) & 255) / 255, (r & 255) / 255])
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
return vec3(r, g, b)
|
|
111
|
-
}
|
package/src/node/uniform.ts
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import { node } from './node'
|
|
2
|
-
import { is } from '../utils/helpers'
|
|
3
|
-
import type { UniformNode } from './types'
|
|
4
|
-
import type { NodeType } from './const'
|
|
5
|
-
|
|
6
|
-
// ユニフォーム更新コンテキスト
|
|
7
|
-
interface UpdateContext {
|
|
8
|
-
object?: any
|
|
9
|
-
camera?: any
|
|
10
|
-
renderer?: any
|
|
11
|
-
scene?: any
|
|
12
|
-
time?: number
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
// ユニフォーム値の型を推定
|
|
16
|
-
const inferUniformType = (value: any): NodeType => {
|
|
17
|
-
if (is.num(value)) return 'float'
|
|
18
|
-
if (is.bol(value)) return 'bool'
|
|
19
|
-
if (is.arr(value)) {
|
|
20
|
-
const len = value.length
|
|
21
|
-
if (len === 2) return 'vec2'
|
|
22
|
-
if (len === 3) return 'vec3'
|
|
23
|
-
if (len === 4) return 'vec4'
|
|
24
|
-
if (len === 9) return 'mat3'
|
|
25
|
-
if (len === 16) return 'mat4'
|
|
26
|
-
}
|
|
27
|
-
if (is.obj(value) && 'r' in value && 'g' in value && 'b' in value) return 'color'
|
|
28
|
-
return 'float'
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// ユニフォーム変数を作成
|
|
32
|
-
export const uniform = (initialValue: any): UniformNode => {
|
|
33
|
-
const type = inferUniformType(initialValue)
|
|
34
|
-
let currentValue = initialValue
|
|
35
|
-
let objectUpdateCallback: ((context: UpdateContext) => any) | null = null
|
|
36
|
-
let renderUpdateCallback: ((context: UpdateContext) => any) | null = null
|
|
37
|
-
|
|
38
|
-
const baseNode = node(type, currentValue) as any
|
|
39
|
-
|
|
40
|
-
// 値を設定
|
|
41
|
-
const set = (value: any) => {
|
|
42
|
-
currentValue = value
|
|
43
|
-
baseNode.value = value
|
|
44
|
-
}
|
|
45
|
-
// オブジェクト更新時のコールバックを設定
|
|
46
|
-
const onObjectUpdate = (callback: (context: UpdateContext) => any): UniformNode => {
|
|
47
|
-
objectUpdateCallback = callback
|
|
48
|
-
return uniformNode
|
|
49
|
-
}
|
|
50
|
-
// レンダー更新時のコールバックを設定
|
|
51
|
-
const onRenderUpdate = (callback: (context: UpdateContext) => any): UniformNode => {
|
|
52
|
-
renderUpdateCallback = callback
|
|
53
|
-
return uniformNode
|
|
54
|
-
}
|
|
55
|
-
// 内部更新関数(外部から呼び出される)
|
|
56
|
-
const _updateFromContext = (context: UpdateContext) => {
|
|
57
|
-
if (objectUpdateCallback) {
|
|
58
|
-
const newValue = objectUpdateCallback(context)
|
|
59
|
-
if (newValue !== undefined) set(newValue)
|
|
60
|
-
}
|
|
61
|
-
if (renderUpdateCallback) {
|
|
62
|
-
const newValue = renderUpdateCallback(context)
|
|
63
|
-
if (newValue !== undefined) set(newValue)
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
// UniformNodeインターフェースを実装
|
|
67
|
-
const uniformNode = Object.create(baseNode)
|
|
68
|
-
uniformNode.set = set
|
|
69
|
-
uniformNode.onObjectUpdate = onObjectUpdate
|
|
70
|
-
uniformNode.onRenderUpdate = onRenderUpdate
|
|
71
|
-
uniformNode._updateFromContext = _updateFromContext
|
|
72
|
-
uniformNode.isUniform = true
|
|
73
|
-
return uniformNode as UniformNode
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
// 組み込みユニフォーム変数
|
|
77
|
-
export const iTime = uniform(0.0)
|
|
78
|
-
export const iPrevTime = uniform(0.0)
|
|
79
|
-
export const iDeltaTime = uniform(0.0)
|
|
80
|
-
export const iResolution = uniform([1920, 1080])
|
|
81
|
-
export const iMouse = uniform([0, 0])
|
|
82
|
-
|
|
83
|
-
// ユニフォーム変数の更新(レンダーループで呼び出される)
|
|
84
|
-
export const updateUniforms = (context: UpdateContext) => {
|
|
85
|
-
// 時間の更新
|
|
86
|
-
if (context.time !== undefined) {
|
|
87
|
-
const prevTime = iTime.value || 0
|
|
88
|
-
iTime.set(context.time)
|
|
89
|
-
iPrevTime.set(prevTime)
|
|
90
|
-
iDeltaTime.set(context.time - prevTime)
|
|
91
|
-
}
|
|
92
|
-
}
|