@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.
Files changed (177) hide show
  1. package/dist/animation-loop/animation-loop.d.ts +8 -4
  2. package/dist/animation-loop/animation-loop.d.ts.map +1 -1
  3. package/dist/animation-loop/animation-loop.js +73 -43
  4. package/dist/animation-loop/animation-loop.js.map +1 -1
  5. package/dist/animation-loop/make-animation-loop.js +7 -1
  6. package/dist/animation-loop/make-animation-loop.js.map +1 -1
  7. package/dist/animation-loop/request-animation-frame.d.ts.map +1 -1
  8. package/dist/animation-loop/request-animation-frame.js +23 -6
  9. package/dist/animation-loop/request-animation-frame.js.map +1 -1
  10. package/dist/compute/computation.d.ts +3 -7
  11. package/dist/compute/computation.d.ts.map +1 -1
  12. package/dist/compute/computation.js +14 -12
  13. package/dist/compute/computation.js.map +1 -1
  14. package/dist/dist.dev.js +2310 -1638
  15. package/dist/dist.min.js +307 -360
  16. package/dist/dynamic-texture/dynamic-texture.d.ts +12 -5
  17. package/dist/dynamic-texture/dynamic-texture.d.ts.map +1 -1
  18. package/dist/dynamic-texture/dynamic-texture.js +222 -55
  19. package/dist/dynamic-texture/dynamic-texture.js.map +1 -1
  20. package/dist/dynamic-texture/texture-data.d.ts +8 -1
  21. package/dist/dynamic-texture/texture-data.d.ts.map +1 -1
  22. package/dist/dynamic-texture/texture-data.js +27 -2
  23. package/dist/dynamic-texture/texture-data.js.map +1 -1
  24. package/dist/geometries/cone-geometry.d.ts +3 -1
  25. package/dist/geometries/cone-geometry.d.ts.map +1 -1
  26. package/dist/geometries/cone-geometry.js.map +1 -1
  27. package/dist/geometries/cylinder-geometry.d.ts +2 -1
  28. package/dist/geometries/cylinder-geometry.d.ts.map +1 -1
  29. package/dist/geometries/cylinder-geometry.js.map +1 -1
  30. package/dist/geometry/gpu-geometry.d.ts.map +1 -1
  31. package/dist/geometry/gpu-geometry.js +8 -3
  32. package/dist/geometry/gpu-geometry.js.map +1 -1
  33. package/dist/index.cjs +2897 -2272
  34. package/dist/index.cjs.map +4 -4
  35. package/dist/index.d.ts +12 -3
  36. package/dist/index.d.ts.map +1 -1
  37. package/dist/index.js +8 -3
  38. package/dist/index.js.map +1 -1
  39. package/dist/material/material-factory.d.ts +73 -0
  40. package/dist/material/material-factory.d.ts.map +1 -0
  41. package/dist/material/material-factory.js +111 -0
  42. package/dist/material/material-factory.js.map +1 -0
  43. package/dist/material/material.d.ts +84 -0
  44. package/dist/material/material.d.ts.map +1 -0
  45. package/dist/material/material.js +176 -0
  46. package/dist/material/material.js.map +1 -0
  47. package/dist/model/model.d.ts +17 -7
  48. package/dist/model/model.d.ts.map +1 -1
  49. package/dist/model/model.js +80 -34
  50. package/dist/model/model.js.map +1 -1
  51. package/dist/model/split-uniforms-and-bindings.d.ts +4 -3
  52. package/dist/model/split-uniforms-and-bindings.d.ts.map +1 -1
  53. package/dist/model/split-uniforms-and-bindings.js +2 -2
  54. package/dist/model/split-uniforms-and-bindings.js.map +1 -1
  55. package/dist/models/billboard-texture-model.d.ts.map +1 -1
  56. package/dist/models/billboard-texture-model.js +10 -8
  57. package/dist/models/billboard-texture-model.js.map +1 -1
  58. package/dist/models/clip-space.js +7 -7
  59. package/dist/models/directional-light-model.d.ts +7 -0
  60. package/dist/models/directional-light-model.d.ts.map +1 -0
  61. package/dist/models/directional-light-model.js +23 -0
  62. package/dist/models/directional-light-model.js.map +1 -0
  63. package/dist/models/light-model-utils.d.ts +69 -0
  64. package/dist/models/light-model-utils.d.ts.map +1 -0
  65. package/dist/models/light-model-utils.js +395 -0
  66. package/dist/models/light-model-utils.js.map +1 -0
  67. package/dist/models/point-light-model.d.ts +7 -0
  68. package/dist/models/point-light-model.d.ts.map +1 -0
  69. package/dist/models/point-light-model.js +22 -0
  70. package/dist/models/point-light-model.js.map +1 -0
  71. package/dist/models/spot-light-model.d.ts +7 -0
  72. package/dist/models/spot-light-model.d.ts.map +1 -0
  73. package/dist/models/spot-light-model.js +23 -0
  74. package/dist/models/spot-light-model.js.map +1 -0
  75. package/dist/modules/picking/color-picking.d.ts +5 -9
  76. package/dist/modules/picking/color-picking.d.ts.map +1 -1
  77. package/dist/modules/picking/color-picking.js +122 -115
  78. package/dist/modules/picking/color-picking.js.map +1 -1
  79. package/dist/modules/picking/index-picking.d.ts +2 -2
  80. package/dist/modules/picking/index-picking.d.ts.map +1 -1
  81. package/dist/modules/picking/index-picking.js +36 -16
  82. package/dist/modules/picking/index-picking.js.map +1 -1
  83. package/dist/modules/picking/legacy-color-picking.d.ts +26 -0
  84. package/dist/modules/picking/legacy-color-picking.d.ts.map +1 -0
  85. package/dist/modules/picking/legacy-color-picking.js +7 -0
  86. package/dist/modules/picking/legacy-color-picking.js.map +1 -0
  87. package/dist/modules/picking/picking-manager.d.ts +29 -3
  88. package/dist/modules/picking/picking-manager.d.ts.map +1 -1
  89. package/dist/modules/picking/picking-manager.js +188 -41
  90. package/dist/modules/picking/picking-manager.js.map +1 -1
  91. package/dist/modules/picking/picking-uniforms.d.ts +12 -11
  92. package/dist/modules/picking/picking-uniforms.d.ts.map +1 -1
  93. package/dist/modules/picking/picking-uniforms.js +26 -13
  94. package/dist/modules/picking/picking-uniforms.js.map +1 -1
  95. package/dist/modules/picking/picking.d.ts +25 -0
  96. package/dist/modules/picking/picking.d.ts.map +1 -0
  97. package/dist/modules/picking/picking.js +18 -0
  98. package/dist/modules/picking/picking.js.map +1 -0
  99. package/dist/passes/get-fragment-shader.js +11 -30
  100. package/dist/passes/get-fragment-shader.js.map +1 -1
  101. package/dist/passes/shader-pass-renderer.d.ts +0 -2
  102. package/dist/passes/shader-pass-renderer.d.ts.map +1 -1
  103. package/dist/passes/shader-pass-renderer.js +4 -31
  104. package/dist/passes/shader-pass-renderer.js.map +1 -1
  105. package/dist/scenegraph/group-node.d.ts +5 -0
  106. package/dist/scenegraph/group-node.d.ts.map +1 -1
  107. package/dist/scenegraph/group-node.js +12 -0
  108. package/dist/scenegraph/group-node.js.map +1 -1
  109. package/dist/scenegraph/model-node.d.ts +2 -2
  110. package/dist/scenegraph/model-node.d.ts.map +1 -1
  111. package/dist/scenegraph/model-node.js.map +1 -1
  112. package/dist/scenegraph/scenegraph-node.d.ts +1 -1
  113. package/dist/scenegraph/scenegraph-node.d.ts.map +1 -1
  114. package/dist/scenegraph/scenegraph-node.js +23 -15
  115. package/dist/scenegraph/scenegraph-node.js.map +1 -1
  116. package/dist/shader-inputs.d.ts +9 -7
  117. package/dist/shader-inputs.d.ts.map +1 -1
  118. package/dist/shader-inputs.js +84 -4
  119. package/dist/shader-inputs.js.map +1 -1
  120. package/dist/utils/shader-module-utils.d.ts +7 -0
  121. package/dist/utils/shader-module-utils.d.ts.map +1 -0
  122. package/dist/utils/shader-module-utils.js +46 -0
  123. package/dist/utils/shader-module-utils.js.map +1 -0
  124. package/package.json +4 -4
  125. package/src/animation-loop/animation-loop.ts +78 -46
  126. package/src/animation-loop/make-animation-loop.ts +13 -5
  127. package/src/animation-loop/request-animation-frame.ts +32 -6
  128. package/src/compute/computation.ts +31 -17
  129. package/src/dynamic-texture/dynamic-texture.ts +301 -68
  130. package/src/dynamic-texture/texture-data.ts +39 -4
  131. package/src/geometries/cone-geometry.ts +6 -1
  132. package/src/geometries/cylinder-geometry.ts +5 -1
  133. package/src/geometry/gpu-geometry.ts +8 -3
  134. package/src/index.ts +29 -4
  135. package/src/material/material-factory.ts +157 -0
  136. package/src/material/material.ts +254 -0
  137. package/src/model/model.ts +122 -50
  138. package/src/model/split-uniforms-and-bindings.ts +8 -6
  139. package/src/models/billboard-texture-model.ts +10 -8
  140. package/src/models/clip-space.ts +7 -7
  141. package/src/models/directional-light-model.ts +32 -0
  142. package/src/models/light-model-utils.ts +587 -0
  143. package/src/models/point-light-model.ts +31 -0
  144. package/src/models/spot-light-model.ts +32 -0
  145. package/src/modules/picking/color-picking.ts +123 -122
  146. package/src/modules/picking/index-picking.ts +36 -16
  147. package/src/modules/picking/legacy-color-picking.ts +8 -0
  148. package/src/modules/picking/picking-manager.ts +252 -50
  149. package/src/modules/picking/picking-uniforms.ts +38 -23
  150. package/src/modules/picking/picking.ts +22 -0
  151. package/src/passes/get-fragment-shader.ts +11 -30
  152. package/src/passes/shader-pass-renderer.ts +4 -33
  153. package/src/scenegraph/group-node.ts +16 -0
  154. package/src/scenegraph/model-node.ts +2 -2
  155. package/src/scenegraph/scenegraph-node.ts +27 -16
  156. package/src/shader-inputs.ts +165 -15
  157. package/src/utils/shader-module-utils.ts +65 -0
  158. package/dist/dynamic-texture/mipmaps.d.ts +0 -6
  159. package/dist/dynamic-texture/mipmaps.d.ts.map +0 -1
  160. package/dist/dynamic-texture/mipmaps.js +0 -441
  161. package/dist/dynamic-texture/mipmaps.js.map +0 -1
  162. package/dist/factories/pipeline-factory.d.ts +0 -37
  163. package/dist/factories/pipeline-factory.d.ts.map +0 -1
  164. package/dist/factories/pipeline-factory.js +0 -181
  165. package/dist/factories/pipeline-factory.js.map +0 -1
  166. package/dist/factories/shader-factory.d.ts +0 -22
  167. package/dist/factories/shader-factory.d.ts.map +0 -1
  168. package/dist/factories/shader-factory.js +0 -89
  169. package/dist/factories/shader-factory.js.map +0 -1
  170. package/dist/types.d.ts +0 -7
  171. package/dist/types.d.ts.map +0 -1
  172. package/dist/types.js +0 -5
  173. package/dist/types.js.map +0 -1
  174. package/src/dynamic-texture/mipmaps.ts +0 -517
  175. package/src/factories/pipeline-factory.ts +0 -225
  176. package/src/factories/shader-factory.ts +0 -105
  177. 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[], 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[], number[]] | null = null;
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
- // assert(position.length === 3, 'setPosition requires vector argument');
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
- // assert(rotation.length === 3, 'setRotation requires vector argument');
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
- // assert(scale.length === 3, 'setScale requires vector argument');
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(pos);
114
- this.matrix.rotateXYZ(rot);
115
- this.matrix.scale(scale);
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(options: {position?: any; rotation?: any; scale?: any} = {}): this {
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 ('position' in props) {
200
+ if (props?.position) {
192
201
  this.setPosition(props.position);
193
202
  }
194
- if ('rotation' in props) {
203
+ if (props?.rotation) {
195
204
  this.setRotation(props.rotation);
196
205
  }
197
- if ('scale' in props) {
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 ('matrix' in props) {
213
+ if (props?.matrix) {
203
214
  this.setMatrix(props.matrix);
204
215
  }
205
216
 
@@ -2,16 +2,25 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
- import type {Binding, UniformValue} from '@luma.gl/core';
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 {getShaderModuleDependencies, ShaderModule} from '@luma.gl/shadertools';
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]: ShaderModule<ShaderPropsT[P]>}>;
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, UniformValue>>;
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]?: ShaderModule<ShaderPropsT[P], any>},
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(module => module.dependencies)
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]: ShaderModule<ShaderPropsT[P]>};
70
- this.moduleUniforms = {} as Record<keyof ShaderPropsT, Record<string, UniformValue>>;
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] as (typeof module)['uniforms'];
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(uniformsAndBindings);
107
- this.moduleUniforms[moduleName] = {...oldUniforms, ...uniforms};
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<Record<keyof ShaderPropsT, Record<string, UniformValue>>> {
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: ShaderModule): void {
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] = module.defaultUniforms || {};
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,6 +0,0 @@
1
- import type { Device, Texture } from '@luma.gl/core';
2
- /**
3
- * Generates mip levels from level 0 to the last mip for an existing texture.
4
- */
5
- export declare function generateMipmap(device: Device, texture: Texture): void;
6
- //# sourceMappingURL=mipmaps.d.ts.map
@@ -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"}