@luma.gl/engine 9.0.0-beta.4 → 9.0.0-beta.5

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.
Files changed (78) hide show
  1. package/dist/animation/key-frames.js +54 -54
  2. package/dist/animation/timeline.js +95 -100
  3. package/dist/animation-loop/animation-loop-template.js +17 -5
  4. package/dist/animation-loop/animation-loop.js +425 -356
  5. package/dist/animation-loop/animation-props.js +0 -1
  6. package/dist/animation-loop/make-animation-loop.js +27 -25
  7. package/dist/debug/copy-texture-to-image.js +39 -43
  8. package/dist/debug/debug-framebuffer.js +43 -39
  9. package/dist/debug/debug-shader-layout.js +24 -25
  10. package/dist/debug/pixel-data-utils.js +33 -36
  11. package/dist/dist.dev.js +3784 -8643
  12. package/dist/geometries/cone-geometry.js +12 -18
  13. package/dist/geometries/cube-geometry.js +189 -62
  14. package/dist/geometries/cylinder-geometry.js +10 -15
  15. package/dist/geometries/ico-sphere-geometry.js +142 -161
  16. package/dist/geometries/plane-geometry.js +94 -112
  17. package/dist/geometries/sphere-geometry.js +77 -96
  18. package/dist/geometries/truncated-cone-geometry.js +100 -118
  19. package/dist/geometry/geometry-table.js +0 -1
  20. package/dist/geometry/geometry-utils.js +35 -32
  21. package/dist/geometry/geometry.js +77 -71
  22. package/dist/geometry/gpu-geometry.js +80 -99
  23. package/dist/geometry/gpu-table.js +41 -1
  24. package/dist/index.cjs +80 -127
  25. package/dist/index.cjs.map +7 -0
  26. package/dist/index.js +27 -24
  27. package/dist/lib/clip-space.js +25 -30
  28. package/dist/lib/pipeline-factory.d.ts +1 -5
  29. package/dist/lib/pipeline-factory.d.ts.map +1 -1
  30. package/dist/lib/pipeline-factory.js +61 -68
  31. package/dist/model/model.d.ts +2 -2
  32. package/dist/model/model.d.ts.map +1 -1
  33. package/dist/model/model.js +539 -413
  34. package/dist/scenegraph/group-node.js +69 -84
  35. package/dist/scenegraph/model-node.js +32 -25
  36. package/dist/scenegraph/scenegraph-node.js +136 -124
  37. package/dist/shader-inputs.js +96 -58
  38. package/dist/transform/buffer-transform.js +65 -58
  39. package/dist/transform/texture-transform.d.ts.map +1 -1
  40. package/dist/transform/texture-transform.js +108 -115
  41. package/dist.min.js +2 -272
  42. package/package.json +10 -9
  43. package/src/lib/pipeline-factory.ts +8 -21
  44. package/src/model/model.ts +5 -5
  45. package/src/transform/buffer-transform.ts +3 -3
  46. package/src/transform/texture-transform.ts +0 -2
  47. package/dist/animation/key-frames.js.map +0 -1
  48. package/dist/animation/timeline.js.map +0 -1
  49. package/dist/animation-loop/animation-loop-template.js.map +0 -1
  50. package/dist/animation-loop/animation-loop.js.map +0 -1
  51. package/dist/animation-loop/animation-props.js.map +0 -1
  52. package/dist/animation-loop/make-animation-loop.js.map +0 -1
  53. package/dist/debug/copy-texture-to-image.js.map +0 -1
  54. package/dist/debug/debug-framebuffer.js.map +0 -1
  55. package/dist/debug/debug-shader-layout.js.map +0 -1
  56. package/dist/debug/pixel-data-utils.js.map +0 -1
  57. package/dist/geometries/cone-geometry.js.map +0 -1
  58. package/dist/geometries/cube-geometry.js.map +0 -1
  59. package/dist/geometries/cylinder-geometry.js.map +0 -1
  60. package/dist/geometries/ico-sphere-geometry.js.map +0 -1
  61. package/dist/geometries/plane-geometry.js.map +0 -1
  62. package/dist/geometries/sphere-geometry.js.map +0 -1
  63. package/dist/geometries/truncated-cone-geometry.js.map +0 -1
  64. package/dist/geometry/geometry-table.js.map +0 -1
  65. package/dist/geometry/geometry-utils.js.map +0 -1
  66. package/dist/geometry/geometry.js.map +0 -1
  67. package/dist/geometry/gpu-geometry.js.map +0 -1
  68. package/dist/geometry/gpu-table.js.map +0 -1
  69. package/dist/index.js.map +0 -1
  70. package/dist/lib/clip-space.js.map +0 -1
  71. package/dist/lib/pipeline-factory.js.map +0 -1
  72. package/dist/model/model.js.map +0 -1
  73. package/dist/scenegraph/group-node.js.map +0 -1
  74. package/dist/scenegraph/model-node.js.map +0 -1
  75. package/dist/scenegraph/scenegraph-node.js.map +0 -1
  76. package/dist/shader-inputs.js.map +0 -1
  77. package/dist/transform/buffer-transform.js.map +0 -1
  78. package/dist/transform/texture-transform.js.map +0 -1
@@ -1,94 +1,79 @@
1
1
  import { Matrix4, Vector3 } from '@math.gl/core';
2
2
  import { log } from '@luma.gl/core';
3
- import { ScenegraphNode } from "./scenegraph-node.js";
3
+ import { ScenegraphNode } from './scenegraph-node';
4
4
  export class GroupNode extends ScenegraphNode {
5
- constructor() {
6
- let props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
7
- props = Array.isArray(props) ? {
8
- children: props
9
- } : props;
10
- const {
11
- children = []
12
- } = props;
13
- log.assert(children.every(child => child instanceof ScenegraphNode), 'every child must an instance of ScenegraphNode');
14
- super(props);
15
- this.children = void 0;
16
- this.children = children;
17
- }
18
- getBounds() {
19
- const result = [[Infinity, Infinity, Infinity], [-Infinity, -Infinity, -Infinity]];
20
- this.traverse((node, _ref) => {
21
- let {
22
- worldMatrix
23
- } = _ref;
24
- const bounds = node.getBounds();
25
- if (!bounds) {
26
- return;
27
- }
28
- const [min, max] = bounds;
29
- const center = new Vector3(min).add(max).divide([2, 2, 2]);
30
- worldMatrix.transformAsPoint(center, center);
31
- const halfSize = new Vector3(max).subtract(min).divide([2, 2, 2]);
32
- worldMatrix.transformAsVector(halfSize, halfSize);
33
- for (let v = 0; v < 8; v++) {
34
- const position = new Vector3(v & 0b001 ? -1 : 1, v & 0b010 ? -1 : 1, v & 0b100 ? -1 : 1).multiply(halfSize).add(center);
35
- for (let i = 0; i < 3; i++) {
36
- result[0][i] = Math.min(result[0][i], position[i]);
37
- result[1][i] = Math.max(result[1][i], position[i]);
5
+ children;
6
+ constructor(props = {}) {
7
+ props = Array.isArray(props) ? { children: props } : props;
8
+ const { children = [] } = props;
9
+ log.assert(children.every((child) => child instanceof ScenegraphNode), 'every child must an instance of ScenegraphNode');
10
+ super(props);
11
+ this.children = children;
12
+ }
13
+ getBounds() {
14
+ const result = [[Infinity, Infinity, Infinity], [-Infinity, -Infinity, -Infinity]];
15
+ this.traverse((node, { worldMatrix }) => {
16
+ const bounds = node.getBounds();
17
+ if (!bounds) {
18
+ return;
19
+ }
20
+ const [min, max] = bounds;
21
+ const center = new Vector3(min).add(max).divide([2, 2, 2]);
22
+ worldMatrix.transformAsPoint(center, center);
23
+ const halfSize = new Vector3(max).subtract(min).divide([2, 2, 2]);
24
+ worldMatrix.transformAsVector(halfSize, halfSize);
25
+ for (let v = 0; v < 8; v++) {
26
+ // Test all 8 corners of the box
27
+ const position = new Vector3(v & 0b001 ? -1 : 1, v & 0b010 ? -1 : 1, v & 0b100 ? -1 : 1).multiply(halfSize).add(center);
28
+ for (let i = 0; i < 3; i++) {
29
+ result[0][i] = Math.min(result[0][i], position[i]);
30
+ result[1][i] = Math.max(result[1][i], position[i]);
31
+ }
32
+ }
33
+ });
34
+ if (!Number.isFinite(result[0][0])) {
35
+ return null;
38
36
  }
39
- }
40
- });
41
- if (!Number.isFinite(result[0][0])) {
42
- return null;
37
+ return result;
43
38
  }
44
- return result;
45
- }
46
- destroy() {
47
- this.children.forEach(child => child.destroy());
48
- this.removeAll();
49
- super.destroy();
50
- }
51
- add() {
52
- for (var _len = arguments.length, children = new Array(_len), _key = 0; _key < _len; _key++) {
53
- children[_key] = arguments[_key];
39
+ destroy() {
40
+ this.children.forEach((child) => child.destroy());
41
+ this.removeAll();
42
+ super.destroy();
43
+ }
44
+ // Unpacks arrays and nested arrays of children
45
+ add(...children) {
46
+ for (const child of children) {
47
+ if (Array.isArray(child)) {
48
+ this.add(...child);
49
+ }
50
+ else {
51
+ this.children.push(child);
52
+ }
53
+ }
54
+ return this;
54
55
  }
55
- for (const child of children) {
56
- if (Array.isArray(child)) {
57
- this.add(...child);
58
- } else {
59
- this.children.push(child);
60
- }
56
+ remove(child) {
57
+ const children = this.children;
58
+ const indexOf = children.indexOf(child);
59
+ if (indexOf > -1) {
60
+ children.splice(indexOf, 1);
61
+ }
62
+ return this;
61
63
  }
62
- return this;
63
- }
64
- remove(child) {
65
- const children = this.children;
66
- const indexOf = children.indexOf(child);
67
- if (indexOf > -1) {
68
- children.splice(indexOf, 1);
64
+ removeAll() {
65
+ this.children = [];
66
+ return this;
69
67
  }
70
- return this;
71
- }
72
- removeAll() {
73
- this.children = [];
74
- return this;
75
- }
76
- traverse(visitor) {
77
- let {
78
- worldMatrix = new Matrix4()
79
- } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
80
- const modelMatrix = new Matrix4(worldMatrix).multiplyRight(this.matrix);
81
- for (const child of this.children) {
82
- if (child instanceof GroupNode) {
83
- child.traverse(visitor, {
84
- worldMatrix: modelMatrix
85
- });
86
- } else {
87
- visitor(child, {
88
- worldMatrix: modelMatrix
89
- });
90
- }
68
+ traverse(visitor, { worldMatrix = new Matrix4() } = {}) {
69
+ const modelMatrix = new Matrix4(worldMatrix).multiplyRight(this.matrix);
70
+ for (const child of this.children) {
71
+ if (child instanceof GroupNode) {
72
+ child.traverse(visitor, { worldMatrix: modelMatrix });
73
+ }
74
+ else {
75
+ visitor(child, { worldMatrix: modelMatrix });
76
+ }
77
+ }
91
78
  }
92
- }
93
79
  }
94
- //# sourceMappingURL=group-node.js.map
@@ -1,28 +1,35 @@
1
- import { ScenegraphNode } from "./scenegraph-node.js";
1
+ import { ScenegraphNode } from './scenegraph-node';
2
2
  export class ModelNode extends ScenegraphNode {
3
- constructor(props) {
4
- super(props);
5
- this.model = void 0;
6
- this.bounds = null;
7
- this.managedResources = void 0;
8
- this.model = props.model;
9
- this.managedResources = props.managedResources || [];
10
- this.bounds = props.bounds || null;
11
- this.setProps(props);
12
- }
13
- getBounds() {
14
- return this.bounds;
15
- }
16
- destroy() {
17
- if (this.model) {
18
- this.model.destroy();
19
- this.model = null;
3
+ model;
4
+ bounds = null;
5
+ managedResources;
6
+ // TODO - is this used? override callbacks to make sure we call them with this
7
+ // onBeforeRender = null;
8
+ // onAfterRender = null;
9
+ // AfterRender = null;
10
+ constructor(props) {
11
+ super(props);
12
+ // Create new Model or used supplied Model
13
+ this.model = props.model;
14
+ this.managedResources = props.managedResources || [];
15
+ this.bounds = props.bounds || null;
16
+ this.setProps(props);
17
+ }
18
+ getBounds() {
19
+ return this.bounds;
20
+ }
21
+ destroy() {
22
+ if (this.model) {
23
+ this.model.destroy();
24
+ // @ts-expect-error
25
+ this.model = null;
26
+ }
27
+ this.managedResources.forEach((resource) => resource.destroy());
28
+ this.managedResources = [];
29
+ }
30
+ // Expose model methods
31
+ draw(renderPass) {
32
+ // Return value indicates if something was actually drawn
33
+ return this.model.draw(renderPass);
20
34
  }
21
- this.managedResources.forEach(resource => resource.destroy());
22
- this.managedResources = [];
23
- }
24
- draw(renderPass) {
25
- return this.model.draw(renderPass);
26
- }
27
35
  }
28
- //# sourceMappingURL=model-node.js.map
@@ -1,141 +1,153 @@
1
1
  import { assert, uid } from '@luma.gl/core';
2
2
  import { Vector3, Matrix4 } from '@math.gl/core';
3
3
  export class ScenegraphNode {
4
- constructor() {
5
- let props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
6
- this.id = void 0;
7
- this.matrix = new Matrix4();
8
- this.display = true;
9
- this.position = new Vector3();
10
- this.rotation = new Vector3();
11
- this.scale = new Vector3(1, 1, 1);
12
- this.userData = {};
13
- this.props = {};
14
- const {
15
- id
16
- } = props;
17
- this.id = id || uid(this.constructor.name);
18
- this._setScenegraphNodeProps(props);
19
- }
20
- getBounds() {
21
- return null;
22
- }
23
- destroy() {}
24
- delete() {
25
- this.destroy();
26
- }
27
- setProps(props) {
28
- this._setScenegraphNodeProps(props);
29
- return this;
30
- }
31
- toString() {
32
- return `{type: ScenegraphNode, id: ${this.id})}`;
33
- }
34
- setPosition(position) {
35
- assert(position.length === 3, 'setPosition requires vector argument');
36
- this.position = position;
37
- return this;
38
- }
39
- setRotation(rotation) {
40
- assert(rotation.length === 3, 'setRotation requires vector argument');
41
- this.rotation = rotation;
42
- return this;
43
- }
44
- setScale(scale) {
45
- assert(scale.length === 3, 'setScale requires vector argument');
46
- this.scale = scale;
47
- return this;
48
- }
49
- setMatrix(matrix) {
50
- let copyMatrix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
51
- if (copyMatrix) {
52
- this.matrix.copy(matrix);
53
- } else {
54
- this.matrix = matrix;
4
+ id;
5
+ matrix = new Matrix4();
6
+ display = true;
7
+ position = new Vector3();
8
+ rotation = new Vector3();
9
+ scale = new Vector3(1, 1, 1);
10
+ userData = {};
11
+ props = {};
12
+ constructor(props = {}) {
13
+ const { id } = props;
14
+ this.id = id || uid(this.constructor.name);
15
+ this._setScenegraphNodeProps(props);
55
16
  }
56
- }
57
- setMatrixComponents(components) {
58
- const {
59
- position,
60
- rotation,
61
- scale,
62
- update = true
63
- } = components;
64
- if (position) {
65
- this.setPosition(position);
17
+ getBounds() {
18
+ return null;
66
19
  }
67
- if (rotation) {
68
- this.setRotation(rotation);
20
+ destroy() { }
21
+ /** @deprecated use .destroy() */
22
+ delete() {
23
+ this.destroy();
69
24
  }
70
- if (scale) {
71
- this.setScale(scale);
25
+ setProps(props) {
26
+ this._setScenegraphNodeProps(props);
27
+ return this;
72
28
  }
73
- if (update) {
74
- this.updateMatrix();
29
+ toString() {
30
+ return `{type: ScenegraphNode, id: ${this.id})}`;
75
31
  }
76
- return this;
77
- }
78
- updateMatrix() {
79
- const pos = this.position;
80
- const rot = this.rotation;
81
- const scale = this.scale;
82
- this.matrix.identity();
83
- this.matrix.translate(pos);
84
- this.matrix.rotateXYZ(rot);
85
- this.matrix.scale(scale);
86
- return this;
87
- }
88
- update() {
89
- let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
90
- const {
91
- position,
92
- rotation,
93
- scale
94
- } = options;
95
- if (position) {
96
- this.setPosition(position);
32
+ setPosition(position) {
33
+ assert(position.length === 3, 'setPosition requires vector argument');
34
+ this.position = position;
35
+ return this;
97
36
  }
98
- if (rotation) {
99
- this.setRotation(rotation);
37
+ setRotation(rotation) {
38
+ assert(rotation.length === 3, 'setRotation requires vector argument');
39
+ this.rotation = rotation;
40
+ return this;
100
41
  }
101
- if (scale) {
102
- this.setScale(scale);
42
+ setScale(scale) {
43
+ assert(scale.length === 3, 'setScale requires vector argument');
44
+ this.scale = scale;
45
+ return this;
103
46
  }
104
- this.updateMatrix();
105
- return this;
106
- }
107
- getCoordinateUniforms(viewMatrix, modelMatrix) {
108
- assert(viewMatrix);
109
- modelMatrix = modelMatrix || this.matrix;
110
- const worldMatrix = new Matrix4(viewMatrix).multiplyRight(modelMatrix);
111
- const worldInverse = worldMatrix.invert();
112
- const worldInverseTranspose = worldInverse.transpose();
113
- return {
114
- viewMatrix,
115
- modelMatrix,
116
- objectMatrix: modelMatrix,
117
- worldMatrix,
118
- worldInverseMatrix: worldInverse,
119
- worldInverseTransposeMatrix: worldInverseTranspose
120
- };
121
- }
122
- _setScenegraphNodeProps(props) {
123
- if ('display' in props) {
124
- this.display = props.display;
47
+ setMatrix(matrix, copyMatrix = true) {
48
+ if (copyMatrix) {
49
+ this.matrix.copy(matrix);
50
+ }
51
+ else {
52
+ this.matrix = matrix;
53
+ }
125
54
  }
126
- if ('position' in props) {
127
- this.setPosition(props.position);
55
+ setMatrixComponents(components) {
56
+ const { position, rotation, scale, update = true } = components;
57
+ if (position) {
58
+ this.setPosition(position);
59
+ }
60
+ if (rotation) {
61
+ this.setRotation(rotation);
62
+ }
63
+ if (scale) {
64
+ this.setScale(scale);
65
+ }
66
+ if (update) {
67
+ this.updateMatrix();
68
+ }
69
+ return this;
128
70
  }
129
- if ('rotation' in props) {
130
- this.setRotation(props.rotation);
71
+ updateMatrix() {
72
+ const pos = this.position;
73
+ const rot = this.rotation;
74
+ const scale = this.scale;
75
+ this.matrix.identity();
76
+ this.matrix.translate(pos);
77
+ this.matrix.rotateXYZ(rot);
78
+ this.matrix.scale(scale);
79
+ return this;
131
80
  }
132
- if ('scale' in props) {
133
- this.setScale(props.scale);
81
+ update(options = {}) {
82
+ const { position, rotation, scale } = options;
83
+ if (position) {
84
+ this.setPosition(position);
85
+ }
86
+ if (rotation) {
87
+ this.setRotation(rotation);
88
+ }
89
+ if (scale) {
90
+ this.setScale(scale);
91
+ }
92
+ this.updateMatrix();
93
+ return this;
134
94
  }
135
- if ('matrix' in props) {
136
- this.setMatrix(props.matrix);
95
+ getCoordinateUniforms(viewMatrix, modelMatrix) {
96
+ // TODO - solve multiple class problem
97
+ // assert(viewMatrix instanceof Matrix4);
98
+ assert(viewMatrix);
99
+ modelMatrix = modelMatrix || this.matrix;
100
+ const worldMatrix = new Matrix4(viewMatrix).multiplyRight(modelMatrix);
101
+ const worldInverse = worldMatrix.invert();
102
+ const worldInverseTranspose = worldInverse.transpose();
103
+ return {
104
+ viewMatrix,
105
+ modelMatrix,
106
+ objectMatrix: modelMatrix,
107
+ worldMatrix,
108
+ worldInverseMatrix: worldInverse,
109
+ worldInverseTransposeMatrix: worldInverseTranspose
110
+ };
111
+ }
112
+ // TODO - copied code, not yet vetted
113
+ /*
114
+ transform() {
115
+ if (!this.parent) {
116
+ this.endPosition.set(this.position);
117
+ this.endRotation.set(this.rotation);
118
+ this.endScale.set(this.scale);
119
+ } else {
120
+ const parent = this.parent;
121
+ this.endPosition.set(this.position.add(parent.endPosition));
122
+ this.endRotation.set(this.rotation.add(parent.endRotation));
123
+ this.endScale.set(this.scale.add(parent.endScale));
124
+ }
125
+
126
+ const ch = this.children;
127
+ for (let i = 0; i < ch.length; ++i) {
128
+ ch[i].transform();
129
+ }
130
+
131
+ return this;
132
+ }
133
+ */
134
+ _setScenegraphNodeProps(props) {
135
+ if ('display' in props) {
136
+ this.display = props.display;
137
+ }
138
+ if ('position' in props) {
139
+ this.setPosition(props.position);
140
+ }
141
+ if ('rotation' in props) {
142
+ this.setRotation(props.rotation);
143
+ }
144
+ if ('scale' in props) {
145
+ this.setScale(props.scale);
146
+ }
147
+ // Matrix overwrites other props
148
+ if ('matrix' in props) {
149
+ this.setMatrix(props.matrix);
150
+ }
151
+ Object.assign(this.props, props);
137
152
  }
138
- Object.assign(this.props, props);
139
- }
140
153
  }
141
- //# sourceMappingURL=scenegraph-node.js.map
@@ -1,66 +1,104 @@
1
1
  import { log } from '@luma.gl/core';
2
+ // import type {ShaderUniformType, UniformValue, UniformFormat, UniformInfoDevice, Texture, Sampler} from '@luma.gl/core';
2
3
  import { _resolveModules } from '@luma.gl/shadertools';
4
+ /**
5
+ * ShaderInputs holds uniform and binding values for one or more shader modules,
6
+ * - It can generate binary data for any uniform buffer
7
+ * - It can manage a uniform buffer for each block
8
+ * - It can update managed uniform buffers with a single call
9
+ * - It performs some book keeping on what has changed to minimize unnecessary writes to uniform buffers.
10
+ */
3
11
  export class ShaderInputs {
4
- constructor(modules) {
5
- this.modules = void 0;
6
- this.moduleUniforms = void 0;
7
- this.moduleBindings = void 0;
8
- this.moduleUniformsChanged = void 0;
9
- const allModules = _resolveModules(Object.values(modules));
10
- log.log(1, 'Creating ShaderInputs with modules', allModules.map(m => m.name))();
11
- this.modules = modules;
12
- this.moduleUniforms = {};
13
- this.moduleBindings = {};
14
- for (const [name, module] of Object.entries(modules)) {
15
- const moduleName = name;
16
- this.moduleUniforms[moduleName] = module.defaultUniforms || {};
17
- this.moduleBindings[moduleName] = {};
12
+ /**
13
+ * The map of modules
14
+ * @todo should should this include the resolved dependencies?
15
+ */
16
+ modules;
17
+ /** Stores the uniform values for each module */
18
+ moduleUniforms;
19
+ /** Stores the uniform bindings for each module */
20
+ moduleBindings;
21
+ /** Tracks if uniforms have changed */
22
+ moduleUniformsChanged;
23
+ /**
24
+ * Create a new UniformStore instance
25
+ * @param modules
26
+ */
27
+ constructor(modules) {
28
+ // TODO - get all dependencies from modules
29
+ const allModules = _resolveModules(Object.values(modules));
30
+ log.log(1, 'Creating ShaderInputs with modules', allModules.map(m => m.name))();
31
+ // Store the module definitions and create storage for uniform values and binding values, per module
32
+ this.modules = modules;
33
+ this.moduleUniforms = {};
34
+ this.moduleBindings = {};
35
+ // Initialize the modules
36
+ for (const [name, module] of Object.entries(modules)) {
37
+ const moduleName = name;
38
+ // Get default uniforms from module
39
+ this.moduleUniforms[moduleName] = module.defaultUniforms || {};
40
+ this.moduleBindings[moduleName] = {};
41
+ }
18
42
  }
19
- }
20
- destroy() {}
21
- setProps(props) {
22
- for (const name of Object.keys(props)) {
23
- var _module$getUniforms;
24
- const moduleName = name;
25
- const moduleProps = props[moduleName];
26
- const module = this.modules[moduleName];
27
- if (!module) {
28
- log.warn(`Module ${name} not found`)();
29
- continue;
30
- }
31
- const oldUniforms = this.moduleUniforms[moduleName];
32
- const uniforms = ((_module$getUniforms = module.getUniforms) === null || _module$getUniforms === void 0 ? void 0 : _module$getUniforms.call(module, moduleProps, this.moduleUniforms[moduleName])) || moduleProps;
33
- this.moduleUniforms[moduleName] = {
34
- ...oldUniforms,
35
- ...uniforms
36
- };
43
+ /** Destroy */
44
+ destroy() { }
45
+ /**
46
+ * Set module props
47
+ */
48
+ setProps(props) {
49
+ for (const name of Object.keys(props)) {
50
+ const moduleName = name;
51
+ const moduleProps = props[moduleName];
52
+ const module = this.modules[moduleName];
53
+ if (!module) {
54
+ // Ignore props for unregistered modules
55
+ log.warn(`Module ${name} not found`)();
56
+ continue; // eslint-disable-line no-continue
57
+ }
58
+ const oldUniforms = this.moduleUniforms[moduleName];
59
+ const uniforms = module.getUniforms?.(moduleProps, this.moduleUniforms[moduleName]) || moduleProps;
60
+ // console.error(uniforms)
61
+ this.moduleUniforms[moduleName] = { ...oldUniforms, ...uniforms };
62
+ // this.moduleUniformsChanged ||= moduleName;
63
+ // console.log(`setProps(${String(moduleName)}`, moduleName, this.moduleUniforms[moduleName])
64
+ // TODO - Get Module bindings
65
+ // const bindings = module.getBindings?.(moduleProps);
66
+ // this.moduleUniforms[moduleName] = bindings;
67
+ }
37
68
  }
38
- }
39
- getModules() {
40
- return Object.values(this.modules);
41
- }
42
- getUniformValues() {
43
- return this.moduleUniforms;
44
- }
45
- getBindings() {
46
- const bindings = {};
47
- for (const moduleBindings of Object.values(this.moduleBindings)) {
48
- Object.assign(bindings, moduleBindings);
69
+ /** Merges all bindings for the shader (from the various modules) */
70
+ // getUniformBlocks(): Record<string, Texture | Sampler> {
71
+ // return this.moduleUniforms;
72
+ // }
73
+ /**
74
+ * Return the map of modules
75
+ * @todo should should this include the resolved dependencies?
76
+ */
77
+ getModules() {
78
+ return Object.values(this.modules);
49
79
  }
50
- return bindings;
51
- }
52
- getDebugTable() {
53
- const table = {};
54
- for (const [moduleName, module] of Object.entries(this.moduleUniforms)) {
55
- for (const [key, value] of Object.entries(module)) {
56
- var _this$modules$moduleN;
57
- table[`${moduleName}.${key}`] = {
58
- type: (_this$modules$moduleN = this.modules[moduleName].uniformTypes) === null || _this$modules$moduleN === void 0 ? void 0 : _this$modules$moduleN[key],
59
- value: String(value)
60
- };
61
- }
80
+ /** Get all uniform values for all modules */
81
+ getUniformValues() {
82
+ return this.moduleUniforms;
83
+ }
84
+ /** Merges all bindings for the shader (from the various modules) */
85
+ getBindings() {
86
+ const bindings = {};
87
+ for (const moduleBindings of Object.values(this.moduleBindings)) {
88
+ Object.assign(bindings, moduleBindings);
89
+ }
90
+ return bindings;
91
+ }
92
+ getDebugTable() {
93
+ const table = {};
94
+ for (const [moduleName, module] of Object.entries(this.moduleUniforms)) {
95
+ for (const [key, value] of Object.entries(module)) {
96
+ table[`${moduleName}.${key}`] = {
97
+ type: this.modules[moduleName].uniformTypes?.[key],
98
+ value: String(value)
99
+ };
100
+ }
101
+ }
102
+ return table;
62
103
  }
63
- return table;
64
- }
65
104
  }
66
- //# sourceMappingURL=shader-inputs.js.map