@luma.gl/engine 9.3.0-alpha.4 → 9.3.0-alpha.8
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/dist/animation-loop/animation-loop.d.ts +8 -4
- package/dist/animation-loop/animation-loop.d.ts.map +1 -1
- package/dist/animation-loop/animation-loop.js +73 -43
- package/dist/animation-loop/animation-loop.js.map +1 -1
- package/dist/animation-loop/make-animation-loop.js +7 -1
- package/dist/animation-loop/make-animation-loop.js.map +1 -1
- package/dist/animation-loop/request-animation-frame.d.ts.map +1 -1
- package/dist/animation-loop/request-animation-frame.js +23 -6
- package/dist/animation-loop/request-animation-frame.js.map +1 -1
- package/dist/compute/computation.d.ts +3 -7
- package/dist/compute/computation.d.ts.map +1 -1
- package/dist/compute/computation.js +14 -12
- package/dist/compute/computation.js.map +1 -1
- package/dist/dist.dev.js +2310 -1638
- package/dist/dist.min.js +307 -360
- package/dist/dynamic-texture/dynamic-texture.d.ts +12 -5
- package/dist/dynamic-texture/dynamic-texture.d.ts.map +1 -1
- package/dist/dynamic-texture/dynamic-texture.js +222 -55
- package/dist/dynamic-texture/dynamic-texture.js.map +1 -1
- package/dist/dynamic-texture/texture-data.d.ts +8 -1
- package/dist/dynamic-texture/texture-data.d.ts.map +1 -1
- package/dist/dynamic-texture/texture-data.js +27 -2
- package/dist/dynamic-texture/texture-data.js.map +1 -1
- package/dist/geometries/cone-geometry.d.ts +3 -1
- package/dist/geometries/cone-geometry.d.ts.map +1 -1
- package/dist/geometries/cone-geometry.js.map +1 -1
- package/dist/geometries/cylinder-geometry.d.ts +2 -1
- package/dist/geometries/cylinder-geometry.d.ts.map +1 -1
- package/dist/geometries/cylinder-geometry.js.map +1 -1
- package/dist/geometry/gpu-geometry.d.ts.map +1 -1
- package/dist/geometry/gpu-geometry.js +8 -3
- package/dist/geometry/gpu-geometry.js.map +1 -1
- package/dist/index.cjs +2897 -2272
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +12 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -3
- package/dist/index.js.map +1 -1
- package/dist/material/material-factory.d.ts +73 -0
- package/dist/material/material-factory.d.ts.map +1 -0
- package/dist/material/material-factory.js +111 -0
- package/dist/material/material-factory.js.map +1 -0
- package/dist/material/material.d.ts +84 -0
- package/dist/material/material.d.ts.map +1 -0
- package/dist/material/material.js +176 -0
- package/dist/material/material.js.map +1 -0
- package/dist/model/model.d.ts +17 -7
- package/dist/model/model.d.ts.map +1 -1
- package/dist/model/model.js +80 -34
- package/dist/model/model.js.map +1 -1
- package/dist/model/split-uniforms-and-bindings.d.ts +4 -3
- package/dist/model/split-uniforms-and-bindings.d.ts.map +1 -1
- package/dist/model/split-uniforms-and-bindings.js +2 -2
- package/dist/model/split-uniforms-and-bindings.js.map +1 -1
- package/dist/models/billboard-texture-model.d.ts.map +1 -1
- package/dist/models/billboard-texture-model.js +10 -8
- package/dist/models/billboard-texture-model.js.map +1 -1
- package/dist/models/clip-space.js +7 -7
- package/dist/models/directional-light-model.d.ts +7 -0
- package/dist/models/directional-light-model.d.ts.map +1 -0
- package/dist/models/directional-light-model.js +23 -0
- package/dist/models/directional-light-model.js.map +1 -0
- package/dist/models/light-model-utils.d.ts +69 -0
- package/dist/models/light-model-utils.d.ts.map +1 -0
- package/dist/models/light-model-utils.js +395 -0
- package/dist/models/light-model-utils.js.map +1 -0
- package/dist/models/point-light-model.d.ts +7 -0
- package/dist/models/point-light-model.d.ts.map +1 -0
- package/dist/models/point-light-model.js +22 -0
- package/dist/models/point-light-model.js.map +1 -0
- package/dist/models/spot-light-model.d.ts +7 -0
- package/dist/models/spot-light-model.d.ts.map +1 -0
- package/dist/models/spot-light-model.js +23 -0
- package/dist/models/spot-light-model.js.map +1 -0
- package/dist/modules/picking/color-picking.d.ts +5 -9
- package/dist/modules/picking/color-picking.d.ts.map +1 -1
- package/dist/modules/picking/color-picking.js +122 -115
- package/dist/modules/picking/color-picking.js.map +1 -1
- package/dist/modules/picking/index-picking.d.ts +2 -2
- package/dist/modules/picking/index-picking.d.ts.map +1 -1
- package/dist/modules/picking/index-picking.js +36 -16
- package/dist/modules/picking/index-picking.js.map +1 -1
- package/dist/modules/picking/legacy-color-picking.d.ts +26 -0
- package/dist/modules/picking/legacy-color-picking.d.ts.map +1 -0
- package/dist/modules/picking/legacy-color-picking.js +7 -0
- package/dist/modules/picking/legacy-color-picking.js.map +1 -0
- package/dist/modules/picking/picking-manager.d.ts +29 -3
- package/dist/modules/picking/picking-manager.d.ts.map +1 -1
- package/dist/modules/picking/picking-manager.js +188 -41
- package/dist/modules/picking/picking-manager.js.map +1 -1
- package/dist/modules/picking/picking-uniforms.d.ts +12 -11
- package/dist/modules/picking/picking-uniforms.d.ts.map +1 -1
- package/dist/modules/picking/picking-uniforms.js +26 -13
- package/dist/modules/picking/picking-uniforms.js.map +1 -1
- package/dist/modules/picking/picking.d.ts +25 -0
- package/dist/modules/picking/picking.d.ts.map +1 -0
- package/dist/modules/picking/picking.js +18 -0
- package/dist/modules/picking/picking.js.map +1 -0
- package/dist/passes/get-fragment-shader.js +11 -30
- package/dist/passes/get-fragment-shader.js.map +1 -1
- package/dist/passes/shader-pass-renderer.d.ts +0 -2
- package/dist/passes/shader-pass-renderer.d.ts.map +1 -1
- package/dist/passes/shader-pass-renderer.js +4 -31
- package/dist/passes/shader-pass-renderer.js.map +1 -1
- package/dist/scenegraph/group-node.d.ts +5 -0
- package/dist/scenegraph/group-node.d.ts.map +1 -1
- package/dist/scenegraph/group-node.js +12 -0
- package/dist/scenegraph/group-node.js.map +1 -1
- package/dist/scenegraph/model-node.d.ts +2 -2
- package/dist/scenegraph/model-node.d.ts.map +1 -1
- package/dist/scenegraph/model-node.js.map +1 -1
- package/dist/scenegraph/scenegraph-node.d.ts +1 -1
- package/dist/scenegraph/scenegraph-node.d.ts.map +1 -1
- package/dist/scenegraph/scenegraph-node.js +23 -15
- package/dist/scenegraph/scenegraph-node.js.map +1 -1
- package/dist/shader-inputs.d.ts +9 -7
- package/dist/shader-inputs.d.ts.map +1 -1
- package/dist/shader-inputs.js +84 -4
- package/dist/shader-inputs.js.map +1 -1
- package/dist/utils/shader-module-utils.d.ts +7 -0
- package/dist/utils/shader-module-utils.d.ts.map +1 -0
- package/dist/utils/shader-module-utils.js +46 -0
- package/dist/utils/shader-module-utils.js.map +1 -0
- package/package.json +4 -4
- package/src/animation-loop/animation-loop.ts +78 -46
- package/src/animation-loop/make-animation-loop.ts +13 -5
- package/src/animation-loop/request-animation-frame.ts +32 -6
- package/src/compute/computation.ts +31 -17
- package/src/dynamic-texture/dynamic-texture.ts +301 -68
- package/src/dynamic-texture/texture-data.ts +39 -4
- package/src/geometries/cone-geometry.ts +6 -1
- package/src/geometries/cylinder-geometry.ts +5 -1
- package/src/geometry/gpu-geometry.ts +8 -3
- package/src/index.ts +29 -4
- package/src/material/material-factory.ts +157 -0
- package/src/material/material.ts +254 -0
- package/src/model/model.ts +122 -50
- package/src/model/split-uniforms-and-bindings.ts +8 -6
- package/src/models/billboard-texture-model.ts +10 -8
- package/src/models/clip-space.ts +7 -7
- package/src/models/directional-light-model.ts +32 -0
- package/src/models/light-model-utils.ts +587 -0
- package/src/models/point-light-model.ts +31 -0
- package/src/models/spot-light-model.ts +32 -0
- package/src/modules/picking/color-picking.ts +123 -122
- package/src/modules/picking/index-picking.ts +36 -16
- package/src/modules/picking/legacy-color-picking.ts +8 -0
- package/src/modules/picking/picking-manager.ts +252 -50
- package/src/modules/picking/picking-uniforms.ts +38 -23
- package/src/modules/picking/picking.ts +22 -0
- package/src/passes/get-fragment-shader.ts +11 -30
- package/src/passes/shader-pass-renderer.ts +4 -33
- package/src/scenegraph/group-node.ts +16 -0
- package/src/scenegraph/model-node.ts +2 -2
- package/src/scenegraph/scenegraph-node.ts +27 -16
- package/src/shader-inputs.ts +165 -15
- package/src/utils/shader-module-utils.ts +65 -0
- package/dist/dynamic-texture/mipmaps.d.ts +0 -6
- package/dist/dynamic-texture/mipmaps.d.ts.map +0 -1
- package/dist/dynamic-texture/mipmaps.js +0 -441
- package/dist/dynamic-texture/mipmaps.js.map +0 -1
- package/dist/factories/pipeline-factory.d.ts +0 -37
- package/dist/factories/pipeline-factory.d.ts.map +0 -1
- package/dist/factories/pipeline-factory.js +0 -181
- package/dist/factories/pipeline-factory.js.map +0 -1
- package/dist/factories/shader-factory.d.ts +0 -22
- package/dist/factories/shader-factory.d.ts.map +0 -1
- package/dist/factories/shader-factory.js +0 -89
- package/dist/factories/shader-factory.js.map +0 -1
- package/dist/types.d.ts +0 -7
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -5
- package/dist/types.js.map +0 -1
- package/src/dynamic-texture/mipmaps.ts +0 -517
- package/src/factories/pipeline-factory.ts +0 -225
- package/src/factories/shader-factory.ts +0 -105
- package/src/types.ts +0 -11
|
@@ -9,12 +9,12 @@ import {Model} from '../model/model';
|
|
|
9
9
|
export type ModelNodeProps = ScenegraphNodeProps & {
|
|
10
10
|
model: Model;
|
|
11
11
|
managedResources?: any[];
|
|
12
|
-
bounds?: [number
|
|
12
|
+
bounds?: [[number, number, number], [number, number, number]];
|
|
13
13
|
};
|
|
14
14
|
|
|
15
15
|
export class ModelNode extends ScenegraphNode {
|
|
16
16
|
readonly model: Model;
|
|
17
|
-
bounds: [number
|
|
17
|
+
bounds: [[number, number, number], [number, number, number]] | null = null;
|
|
18
18
|
managedResources: any[];
|
|
19
19
|
|
|
20
20
|
// TODO - is this used? override callbacks to make sure we call them with this
|
|
@@ -5,6 +5,12 @@
|
|
|
5
5
|
import {Vector3, Matrix4, NumericArray} from '@math.gl/core';
|
|
6
6
|
import {uid} from '../utils/uid';
|
|
7
7
|
|
|
8
|
+
function assert(condition: boolean, message?: string): asserts condition {
|
|
9
|
+
if (!condition) {
|
|
10
|
+
throw new Error(message);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
8
14
|
/** Properties for creating a new Scenegraph */
|
|
9
15
|
export type ScenegraphNodeProps = {
|
|
10
16
|
id?: string;
|
|
@@ -57,19 +63,19 @@ export class ScenegraphNode {
|
|
|
57
63
|
}
|
|
58
64
|
|
|
59
65
|
setPosition(position: any): this {
|
|
60
|
-
|
|
66
|
+
assert(position.length === 3, 'setPosition requires vector argument');
|
|
61
67
|
this.position = position;
|
|
62
68
|
return this;
|
|
63
69
|
}
|
|
64
70
|
|
|
65
71
|
setRotation(rotation: any): this {
|
|
66
|
-
|
|
72
|
+
assert(rotation.length === 3 || rotation.length === 4, 'setRotation requires vector argument');
|
|
67
73
|
this.rotation = rotation;
|
|
68
74
|
return this;
|
|
69
75
|
}
|
|
70
76
|
|
|
71
77
|
setScale(scale: any): this {
|
|
72
|
-
|
|
78
|
+
assert(scale.length === 3, 'setScale requires vector argument');
|
|
73
79
|
this.scale = scale;
|
|
74
80
|
return this;
|
|
75
81
|
}
|
|
@@ -105,19 +111,20 @@ export class ScenegraphNode {
|
|
|
105
111
|
}
|
|
106
112
|
|
|
107
113
|
updateMatrix(): this {
|
|
108
|
-
const pos = this.position;
|
|
109
|
-
const rot = this.rotation;
|
|
110
|
-
const scale = this.scale;
|
|
111
|
-
|
|
112
114
|
this.matrix.identity();
|
|
113
|
-
this.matrix.translate(
|
|
114
|
-
this.
|
|
115
|
-
|
|
115
|
+
this.matrix.translate(this.position);
|
|
116
|
+
if (this.rotation.length === 4) {
|
|
117
|
+
const rotationMatrix = new Matrix4().fromQuaternion(this.rotation);
|
|
118
|
+
this.matrix.multiplyRight(rotationMatrix);
|
|
119
|
+
} else {
|
|
120
|
+
this.matrix.rotateXYZ(this.rotation);
|
|
121
|
+
}
|
|
122
|
+
this.matrix.scale(this.scale);
|
|
123
|
+
|
|
116
124
|
return this;
|
|
117
125
|
}
|
|
118
126
|
|
|
119
|
-
update(
|
|
120
|
-
const {position, rotation, scale} = options;
|
|
127
|
+
update({position, rotation, scale}: {position?: any; rotation?: any; scale?: any} = {}): this {
|
|
121
128
|
if (position) {
|
|
122
129
|
this.setPosition(position);
|
|
123
130
|
}
|
|
@@ -127,7 +134,9 @@ export class ScenegraphNode {
|
|
|
127
134
|
if (scale) {
|
|
128
135
|
this.setScale(scale);
|
|
129
136
|
}
|
|
137
|
+
|
|
130
138
|
this.updateMatrix();
|
|
139
|
+
|
|
131
140
|
return this;
|
|
132
141
|
}
|
|
133
142
|
|
|
@@ -188,18 +197,20 @@ export class ScenegraphNode {
|
|
|
188
197
|
// this.display = props.display;
|
|
189
198
|
// }
|
|
190
199
|
|
|
191
|
-
if (
|
|
200
|
+
if (props?.position) {
|
|
192
201
|
this.setPosition(props.position);
|
|
193
202
|
}
|
|
194
|
-
if (
|
|
203
|
+
if (props?.rotation) {
|
|
195
204
|
this.setRotation(props.rotation);
|
|
196
205
|
}
|
|
197
|
-
if (
|
|
206
|
+
if (props?.scale) {
|
|
198
207
|
this.setScale(props.scale);
|
|
199
208
|
}
|
|
200
209
|
|
|
210
|
+
this.updateMatrix();
|
|
211
|
+
|
|
201
212
|
// Matrix overwrites other props
|
|
202
|
-
if (
|
|
213
|
+
if (props?.matrix) {
|
|
203
214
|
this.setMatrix(props.matrix);
|
|
204
215
|
}
|
|
205
216
|
|
package/src/shader-inputs.ts
CHANGED
|
@@ -2,16 +2,25 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
|
-
import type {Binding,
|
|
5
|
+
import type {Binding, CompositeShaderType} from '@luma.gl/core';
|
|
6
6
|
import {log} from '@luma.gl/core';
|
|
7
7
|
// import type {VariableShaderType, UniformValue, UniformFormat, UniformInfoDevice, Texture, Sampler} from '@luma.gl/core';
|
|
8
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
getShaderModuleDependencies,
|
|
10
|
+
ShaderModule,
|
|
11
|
+
ShaderModuleUniformValue
|
|
12
|
+
} from '@luma.gl/shadertools';
|
|
9
13
|
import {splitUniformsAndBindings} from './model/split-uniforms-and-bindings';
|
|
10
14
|
|
|
11
15
|
export type ShaderInputsOptions = {
|
|
12
16
|
disableWarnings?: boolean;
|
|
13
17
|
};
|
|
14
18
|
|
|
19
|
+
type ShaderInputsModule = Pick<
|
|
20
|
+
ShaderModule<any, any, any>,
|
|
21
|
+
'bindingLayout' | 'defaultUniforms' | 'dependencies' | 'getUniforms' | 'name' | 'uniformTypes'
|
|
22
|
+
>;
|
|
23
|
+
|
|
15
24
|
/**
|
|
16
25
|
* ShaderInputs holds uniform and binding values for one or more shader modules,
|
|
17
26
|
* - It can generate binary data for any uniform buffer
|
|
@@ -33,10 +42,10 @@ export class ShaderInputs<
|
|
|
33
42
|
* @todo should should this include the resolved dependencies?
|
|
34
43
|
*/
|
|
35
44
|
// @ts-ignore Fix typings
|
|
36
|
-
modules: Readonly<{[P in keyof ShaderPropsT]:
|
|
45
|
+
modules: Readonly<{[P in keyof ShaderPropsT]: ShaderInputsModule}>;
|
|
37
46
|
|
|
38
47
|
/** Stores the uniform values for each module */
|
|
39
|
-
moduleUniforms: Record<keyof ShaderPropsT, Record<string,
|
|
48
|
+
moduleUniforms: Record<keyof ShaderPropsT, Record<string, ShaderModuleUniformValue>>;
|
|
40
49
|
/** Stores the uniform bindings for each module */
|
|
41
50
|
moduleBindings: Record<keyof ShaderPropsT, Record<string, Binding>>;
|
|
42
51
|
/** Tracks if uniforms have changed */
|
|
@@ -48,14 +57,14 @@ export class ShaderInputs<
|
|
|
48
57
|
*/
|
|
49
58
|
constructor(
|
|
50
59
|
// @ts-ignore Fix typings
|
|
51
|
-
modules: {[P in keyof ShaderPropsT]?:
|
|
60
|
+
modules: {[P in keyof ShaderPropsT]?: ShaderInputsModule},
|
|
52
61
|
options?: ShaderInputsOptions
|
|
53
62
|
) {
|
|
54
63
|
Object.assign(this.options, options);
|
|
55
64
|
|
|
56
65
|
// Extract modules with dependencies
|
|
57
66
|
const resolvedModules = getShaderModuleDependencies(
|
|
58
|
-
Object.values(modules).filter(
|
|
67
|
+
Object.values(modules).filter(isShaderInputsModuleWithDependencies)
|
|
59
68
|
);
|
|
60
69
|
for (const resolvedModule of resolvedModules) {
|
|
61
70
|
// @ts-ignore
|
|
@@ -66,12 +75,19 @@ export class ShaderInputs<
|
|
|
66
75
|
|
|
67
76
|
// Store the module definitions and create storage for uniform values and binding values, per module
|
|
68
77
|
// @ts-ignore Fix typings
|
|
69
|
-
this.modules = modules as {[P in keyof ShaderPropsT]:
|
|
70
|
-
this.moduleUniforms = {} as Record<
|
|
78
|
+
this.modules = modules as {[P in keyof ShaderPropsT]: ShaderInputsModule};
|
|
79
|
+
this.moduleUniforms = {} as Record<
|
|
80
|
+
keyof ShaderPropsT,
|
|
81
|
+
Record<string, ShaderModuleUniformValue>
|
|
82
|
+
>;
|
|
71
83
|
this.moduleBindings = {} as Record<keyof ShaderPropsT, Record<string, Binding>>;
|
|
72
84
|
|
|
73
85
|
// Initialize the modules
|
|
74
86
|
for (const [name, module] of Object.entries(modules)) {
|
|
87
|
+
if (!module) {
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
|
|
75
91
|
this._addModule(module);
|
|
76
92
|
if (module.name && name !== module.name && !this.options.disableWarnings) {
|
|
77
93
|
log.warn(`Module name: ${name} vs ${module.name}`)();
|
|
@@ -98,13 +114,20 @@ export class ShaderInputs<
|
|
|
98
114
|
continue; // eslint-disable-line no-continue
|
|
99
115
|
}
|
|
100
116
|
|
|
101
|
-
const oldUniforms = this.moduleUniforms[moduleName]
|
|
117
|
+
const oldUniforms = this.moduleUniforms[moduleName];
|
|
102
118
|
const oldBindings = this.moduleBindings[moduleName];
|
|
103
119
|
const uniformsAndBindings =
|
|
104
120
|
module.getUniforms?.(moduleProps, oldUniforms) || (moduleProps as any);
|
|
105
121
|
|
|
106
|
-
const {uniforms, bindings} = splitUniformsAndBindings(
|
|
107
|
-
|
|
122
|
+
const {uniforms, bindings} = splitUniformsAndBindings(
|
|
123
|
+
uniformsAndBindings,
|
|
124
|
+
module.uniformTypes as Readonly<Record<string, CompositeShaderType>>
|
|
125
|
+
);
|
|
126
|
+
this.moduleUniforms[moduleName] = mergeModuleUniforms(
|
|
127
|
+
oldUniforms as Record<string, ShaderModuleUniformValue>,
|
|
128
|
+
uniforms,
|
|
129
|
+
module.uniformTypes as Readonly<Record<string, CompositeShaderType>>
|
|
130
|
+
);
|
|
108
131
|
this.moduleBindings[moduleName] = {...oldBindings, ...bindings};
|
|
109
132
|
// this.moduleUniformsChanged ||= moduleName;
|
|
110
133
|
|
|
@@ -117,11 +140,13 @@ export class ShaderInputs<
|
|
|
117
140
|
* @todo should should this include the resolved dependencies?
|
|
118
141
|
*/
|
|
119
142
|
getModules(): ShaderModule[] {
|
|
120
|
-
return Object.values(this.modules);
|
|
143
|
+
return Object.values(this.modules) as ShaderModule[];
|
|
121
144
|
}
|
|
122
145
|
|
|
123
146
|
/** Get all uniform values for all modules */
|
|
124
|
-
getUniformValues(): Partial<
|
|
147
|
+
getUniformValues(): Partial<
|
|
148
|
+
Record<keyof ShaderPropsT, Record<string, ShaderModuleUniformValue>>
|
|
149
|
+
> {
|
|
125
150
|
return this.moduleUniforms;
|
|
126
151
|
}
|
|
127
152
|
|
|
@@ -150,10 +175,135 @@ export class ShaderInputs<
|
|
|
150
175
|
return table;
|
|
151
176
|
}
|
|
152
177
|
|
|
153
|
-
_addModule(module:
|
|
178
|
+
_addModule(module: ShaderInputsModule): void {
|
|
154
179
|
const moduleName = module.name as keyof ShaderPropsT;
|
|
155
180
|
// Get default uniforms from module
|
|
156
|
-
this.moduleUniforms[moduleName] =
|
|
181
|
+
this.moduleUniforms[moduleName] = mergeModuleUniforms(
|
|
182
|
+
{},
|
|
183
|
+
(module.defaultUniforms || {}) as Record<string, ShaderModuleUniformValue>,
|
|
184
|
+
module.uniformTypes as Readonly<Record<string, CompositeShaderType>>
|
|
185
|
+
);
|
|
157
186
|
this.moduleBindings[moduleName] = {};
|
|
158
187
|
}
|
|
159
188
|
}
|
|
189
|
+
|
|
190
|
+
function mergeModuleUniforms(
|
|
191
|
+
currentUniforms: Record<string, ShaderModuleUniformValue> = {},
|
|
192
|
+
nextUniforms: Record<string, ShaderModuleUniformValue> = {},
|
|
193
|
+
uniformTypes: Readonly<Record<string, CompositeShaderType>> = {}
|
|
194
|
+
): Record<string, ShaderModuleUniformValue> {
|
|
195
|
+
const mergedUniforms = {...currentUniforms};
|
|
196
|
+
for (const [key, value] of Object.entries(nextUniforms)) {
|
|
197
|
+
if (value === undefined) {
|
|
198
|
+
continue;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
mergedUniforms[key] = mergeModuleUniformValue(currentUniforms[key], value, uniformTypes[key]);
|
|
202
|
+
}
|
|
203
|
+
return mergedUniforms;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
function mergeModuleUniformValue(
|
|
207
|
+
currentValue: ShaderModuleUniformValue | undefined,
|
|
208
|
+
nextValue: ShaderModuleUniformValue,
|
|
209
|
+
uniformType: CompositeShaderType | undefined
|
|
210
|
+
): ShaderModuleUniformValue {
|
|
211
|
+
if (!uniformType || typeof uniformType === 'string') {
|
|
212
|
+
return cloneModuleUniformValue(nextValue);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
if (Array.isArray(uniformType)) {
|
|
216
|
+
if (isPackedUniformArrayValue(nextValue) || !Array.isArray(nextValue)) {
|
|
217
|
+
return cloneModuleUniformValue(nextValue);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
const currentArray: Array<ShaderModuleUniformValue | undefined> =
|
|
221
|
+
Array.isArray(currentValue) && !isPackedUniformArrayValue(currentValue)
|
|
222
|
+
? [...currentValue]
|
|
223
|
+
: [];
|
|
224
|
+
const mergedArray = currentArray.slice();
|
|
225
|
+
for (let index = 0; index < nextValue.length; index++) {
|
|
226
|
+
const elementValue = nextValue[index];
|
|
227
|
+
if (elementValue === undefined) {
|
|
228
|
+
continue;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
mergedArray[index] = mergeModuleUniformValue(
|
|
232
|
+
currentArray[index],
|
|
233
|
+
elementValue,
|
|
234
|
+
uniformType[0] as CompositeShaderType
|
|
235
|
+
);
|
|
236
|
+
}
|
|
237
|
+
return mergedArray;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
if (!isPlainUniformObject(nextValue)) {
|
|
241
|
+
return cloneModuleUniformValue(nextValue);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
const uniformStruct = uniformType as Record<string, CompositeShaderType>;
|
|
245
|
+
const currentObject = isPlainUniformObject(currentValue) ? currentValue : {};
|
|
246
|
+
const mergedObject: Record<string, ShaderModuleUniformValue | undefined> = {...currentObject};
|
|
247
|
+
for (const [key, value] of Object.entries(nextValue)) {
|
|
248
|
+
if (value === undefined) {
|
|
249
|
+
continue;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
mergedObject[key] = mergeModuleUniformValue(currentObject[key], value, uniformStruct[key]);
|
|
253
|
+
}
|
|
254
|
+
return mergedObject as ShaderModuleUniformValue;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
function cloneModuleUniformValue(value: ShaderModuleUniformValue): ShaderModuleUniformValue {
|
|
258
|
+
if (ArrayBuffer.isView(value)) {
|
|
259
|
+
return Array.prototype.slice.call(value) as ShaderModuleUniformValue;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
if (Array.isArray(value)) {
|
|
263
|
+
if (isPackedUniformArrayValue(value)) {
|
|
264
|
+
return value.slice() as ShaderModuleUniformValue;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
const compositeArray = value as ReadonlyArray<ShaderModuleUniformValue | undefined>;
|
|
268
|
+
return compositeArray.map(element =>
|
|
269
|
+
element === undefined ? undefined : cloneModuleUniformValue(element)
|
|
270
|
+
) as ShaderModuleUniformValue;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
if (isPlainUniformObject(value)) {
|
|
274
|
+
return Object.fromEntries(
|
|
275
|
+
Object.entries(value).map(([key, nestedValue]) => [
|
|
276
|
+
key,
|
|
277
|
+
nestedValue === undefined ? undefined : cloneModuleUniformValue(nestedValue)
|
|
278
|
+
])
|
|
279
|
+
) as ShaderModuleUniformValue;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
return value;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
function isPackedUniformArrayValue(
|
|
286
|
+
value: unknown
|
|
287
|
+
): value is ReadonlyArray<number> | ArrayBufferView {
|
|
288
|
+
return (
|
|
289
|
+
ArrayBuffer.isView(value) ||
|
|
290
|
+
(Array.isArray(value) && (value.length === 0 || typeof value[0] === 'number'))
|
|
291
|
+
);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
function isPlainUniformObject(
|
|
295
|
+
value: unknown
|
|
296
|
+
): value is Record<string, ShaderModuleUniformValue | undefined> {
|
|
297
|
+
return (
|
|
298
|
+
Boolean(value) &&
|
|
299
|
+
typeof value === 'object' &&
|
|
300
|
+
!Array.isArray(value) &&
|
|
301
|
+
!ArrayBuffer.isView(value)
|
|
302
|
+
);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
function isShaderInputsModuleWithDependencies(
|
|
306
|
+
module: ShaderInputsModule | undefined
|
|
307
|
+
): module is ShaderInputsModule & {dependencies: NonNullable<ShaderInputsModule['dependencies']>} {
|
|
308
|
+
return Boolean(module?.dependencies);
|
|
309
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
import type {ComputeShaderLayout, ShaderLayout} from '@luma.gl/core';
|
|
6
|
+
import type {ShaderModule} from '@luma.gl/shadertools';
|
|
7
|
+
|
|
8
|
+
type AnyShaderLayout = ShaderLayout | ComputeShaderLayout;
|
|
9
|
+
|
|
10
|
+
export function mergeShaderModuleBindingsIntoLayout<TShaderLayout extends AnyShaderLayout>(
|
|
11
|
+
shaderLayout: TShaderLayout | null | undefined,
|
|
12
|
+
modules: ShaderModule[]
|
|
13
|
+
): TShaderLayout | null | undefined {
|
|
14
|
+
if (!shaderLayout || !modules.some(module => module.bindingLayout?.length)) {
|
|
15
|
+
return shaderLayout;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const mergedLayout = {
|
|
19
|
+
...shaderLayout,
|
|
20
|
+
bindings: shaderLayout.bindings.map(binding => ({...binding}))
|
|
21
|
+
} as TShaderLayout;
|
|
22
|
+
|
|
23
|
+
if ('attributes' in (shaderLayout || {})) {
|
|
24
|
+
(mergedLayout as ShaderLayout).attributes = (shaderLayout as ShaderLayout)?.attributes || [];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
for (const module of modules) {
|
|
28
|
+
for (const bindingLayout of module.bindingLayout || []) {
|
|
29
|
+
for (const relatedBindingName of getRelatedBindingNames(bindingLayout.name)) {
|
|
30
|
+
const binding = mergedLayout.bindings.find(
|
|
31
|
+
candidate => candidate.name === relatedBindingName
|
|
32
|
+
);
|
|
33
|
+
if (binding?.group === 0) {
|
|
34
|
+
binding.group = bindingLayout.group;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return mergedLayout;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function shaderModuleHasUniforms(module: ShaderModule): boolean {
|
|
44
|
+
return Boolean(module.uniformTypes && !isObjectEmpty(module.uniformTypes));
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Returns binding-name aliases that should share the module-declared bind group. */
|
|
48
|
+
function getRelatedBindingNames(bindingName: string): string[] {
|
|
49
|
+
const bindingNames = new Set<string>([bindingName, `${bindingName}Uniforms`]);
|
|
50
|
+
|
|
51
|
+
if (!bindingName.endsWith('Uniforms')) {
|
|
52
|
+
bindingNames.add(`${bindingName}Sampler`);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return [...bindingNames];
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function isObjectEmpty(obj: object): boolean {
|
|
59
|
+
// @ts-ignore key is intentionally unused
|
|
60
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
61
|
+
for (const key in obj) {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mipmaps.d.ts","sourceRoot":"","sources":["../../src/dynamic-texture/mipmaps.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAC,MAAM,EAAE,OAAO,EAAoC,MAAM,eAAe,CAAC;AAsBtF;;GAEG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI,CAwBrE"}
|