@luma.gl/engine 10.0.0-alpha.10 → 10.0.0-alpha.12

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 (226) hide show
  1. package/dist/animation/node-animation-binding.cjs +10 -0
  2. package/dist/animation/node-animation-binding.d.ts +1 -1
  3. package/dist/animation/node-animation-binding.d.ts.map +1 -1
  4. package/dist/animation/node-animation-binding.js +10 -0
  5. package/dist/animation/node-animation-binding.js.map +1 -1
  6. package/dist/dist.dev.js +457 -206
  7. package/dist/dist.min.js +58 -58
  8. package/dist/gltf/gltf/animations/animations.d.ts +1 -1
  9. package/dist/gltf/gltf/animations/animations.d.ts.map +1 -1
  10. package/dist/gltf/gltf/create-scenegraph-from-gltf.cjs +80 -12
  11. package/dist/gltf/gltf/create-scenegraph-from-gltf.d.ts +8 -1
  12. package/dist/gltf/gltf/create-scenegraph-from-gltf.d.ts.map +1 -1
  13. package/dist/gltf/gltf/create-scenegraph-from-gltf.js +82 -14
  14. package/dist/gltf/gltf/create-scenegraph-from-gltf.js.map +1 -1
  15. package/dist/gltf/gltf/gltf-billboard.cjs +6 -1
  16. package/dist/gltf/gltf/gltf-billboard.d.ts.map +1 -1
  17. package/dist/gltf/gltf/gltf-billboard.js +6 -1
  18. package/dist/gltf/gltf/gltf-billboard.js.map +1 -1
  19. package/dist/gltf/gltf/gltf-extension-support.cjs +2 -2
  20. package/dist/gltf/gltf/gltf-extension-support.js +2 -2
  21. package/dist/gltf/gltf/gltf-extension-support.js.map +1 -1
  22. package/dist/gltf/index.cjs +2 -0
  23. package/dist/gltf/index.cjs.map +3 -3
  24. package/dist/gltf/index.d.ts +1 -1
  25. package/dist/gltf/index.d.ts.map +1 -1
  26. package/dist/gltf/index.js +1 -1
  27. package/dist/gltf/index.js.map +1 -1
  28. package/dist/gltf/parsers/parse-gltf-animations.cjs +8 -5
  29. package/dist/gltf/parsers/parse-gltf-animations.js +20 -5
  30. package/dist/gltf/parsers/parse-gltf-animations.js.map +1 -1
  31. package/dist/gltf/parsers/parse-gltf-lights.cjs +36 -72
  32. package/dist/gltf/parsers/parse-gltf-lights.d.ts +6 -2
  33. package/dist/gltf/parsers/parse-gltf-lights.d.ts.map +1 -1
  34. package/dist/gltf/parsers/parse-gltf-lights.js +34 -91
  35. package/dist/gltf/parsers/parse-gltf-lights.js.map +1 -1
  36. package/dist/gltf/parsers/parse-gltf-metadata.cjs +60 -0
  37. package/dist/gltf/parsers/parse-gltf-metadata.d.ts +5 -0
  38. package/dist/gltf/parsers/parse-gltf-metadata.d.ts.map +1 -0
  39. package/dist/gltf/parsers/parse-gltf-metadata.js +39 -0
  40. package/dist/gltf/parsers/parse-gltf-metadata.js.map +1 -0
  41. package/dist/gltf/parsers/parse-gltf.cjs +4 -1
  42. package/dist/gltf/parsers/parse-gltf.d.ts +4 -0
  43. package/dist/gltf/parsers/parse-gltf.d.ts.map +1 -1
  44. package/dist/gltf/parsers/parse-gltf.js +3 -0
  45. package/dist/gltf/parsers/parse-gltf.js.map +1 -1
  46. package/dist/gltf/pbr/pbr-environment.cjs +21 -3
  47. package/dist/gltf/pbr/pbr-environment.d.ts +3 -0
  48. package/dist/gltf/pbr/pbr-environment.d.ts.map +1 -1
  49. package/dist/gltf/pbr/pbr-environment.js +19 -1
  50. package/dist/gltf/pbr/pbr-environment.js.map +1 -1
  51. package/dist/graph/models/index.cjs.map +1 -1
  52. package/dist/graph/models/path/path-attribute-model.cjs +1 -1
  53. package/dist/graph/models/path/path-attribute-model.js +1 -1
  54. package/dist/graph/models/path/path-attribute-model.js.map +1 -1
  55. package/dist/graph/models/path/path-storage-model.cjs +1 -1
  56. package/dist/graph/models/path/path-storage-model.js +1 -1
  57. package/dist/graph/models/path/path-storage-model.js.map +1 -1
  58. package/dist/graph/physics/index.cjs.map +1 -1
  59. package/dist/graph/tables/index.cjs.map +1 -1
  60. package/dist/index.cjs +13 -0
  61. package/dist/index.cjs.map +3 -3
  62. package/dist/index.d.ts +4 -0
  63. package/dist/index.d.ts.map +1 -1
  64. package/dist/index.js +3 -0
  65. package/dist/index.js.map +1 -1
  66. package/dist/lighting/ambient-occlusion-pass.cjs +126 -0
  67. package/dist/lighting/ambient-occlusion-pass.d.ts +31 -0
  68. package/dist/lighting/ambient-occlusion-pass.d.ts.map +1 -0
  69. package/dist/lighting/ambient-occlusion-pass.js +108 -0
  70. package/dist/lighting/ambient-occlusion-pass.js.map +1 -0
  71. package/dist/lighting/clustered-light-grid.cjs +378 -0
  72. package/dist/lighting/clustered-light-grid.d.ts +94 -0
  73. package/dist/lighting/clustered-light-grid.d.ts.map +1 -0
  74. package/dist/lighting/clustered-light-grid.js +370 -0
  75. package/dist/lighting/clustered-light-grid.js.map +1 -0
  76. package/dist/lighting/contact-shadow-composite.cjs +80 -0
  77. package/dist/lighting/contact-shadow-composite.d.ts +6 -0
  78. package/dist/lighting/contact-shadow-composite.d.ts.map +1 -0
  79. package/dist/lighting/contact-shadow-composite.js +59 -0
  80. package/dist/lighting/contact-shadow-composite.js.map +1 -0
  81. package/dist/lighting/contact-shadow-pass.cjs +102 -0
  82. package/dist/lighting/contact-shadow-pass.d.ts +23 -0
  83. package/dist/lighting/contact-shadow-pass.d.ts.map +1 -0
  84. package/dist/lighting/contact-shadow-pass.js +85 -0
  85. package/dist/lighting/contact-shadow-pass.js.map +1 -0
  86. package/dist/lighting/index.cjs +118 -0
  87. package/dist/lighting/index.cjs.map +6 -0
  88. package/dist/lighting/index.d.ts +31 -0
  89. package/dist/lighting/index.d.ts.map +1 -0
  90. package/dist/lighting/index.js +20 -0
  91. package/dist/lighting/index.js.map +1 -0
  92. package/dist/lighting/lightmap-baker.cjs +238 -0
  93. package/dist/lighting/lightmap-baker.d.ts +62 -0
  94. package/dist/lighting/lightmap-baker.d.ts.map +1 -0
  95. package/dist/lighting/lightmap-baker.js +236 -0
  96. package/dist/lighting/lightmap-baker.js.map +1 -0
  97. package/dist/lighting/lightmap-data.cjs +117 -0
  98. package/dist/lighting/lightmap-data.d.ts +20 -0
  99. package/dist/lighting/lightmap-data.d.ts.map +1 -0
  100. package/dist/lighting/lightmap-data.js +110 -0
  101. package/dist/lighting/lightmap-data.js.map +1 -0
  102. package/dist/lighting/lightmap-environment.cjs +61 -0
  103. package/dist/lighting/lightmap-environment.d.ts +18 -0
  104. package/dist/lighting/lightmap-environment.d.ts.map +1 -0
  105. package/dist/lighting/lightmap-environment.js +46 -0
  106. package/dist/lighting/lightmap-environment.js.map +1 -0
  107. package/dist/lighting/pbr-environment.cjs +45 -0
  108. package/dist/lighting/pbr-environment.d.ts +25 -0
  109. package/dist/lighting/pbr-environment.d.ts.map +1 -0
  110. package/dist/lighting/pbr-environment.js +30 -0
  111. package/dist/lighting/pbr-environment.js.map +1 -0
  112. package/dist/lighting/pbr-material.cjs +75 -0
  113. package/dist/lighting/pbr-material.d.ts +33 -0
  114. package/dist/lighting/pbr-material.d.ts.map +1 -0
  115. package/dist/lighting/pbr-material.js +52 -0
  116. package/dist/lighting/pbr-material.js.map +1 -0
  117. package/dist/lighting/pbr-model.cjs +579 -0
  118. package/dist/lighting/pbr-model.d.ts +45 -0
  119. package/dist/lighting/pbr-model.d.ts.map +1 -0
  120. package/dist/lighting/pbr-model.js +545 -0
  121. package/dist/lighting/pbr-model.js.map +1 -0
  122. package/dist/lighting/pbr-surface-pass.cjs +116 -0
  123. package/dist/lighting/pbr-surface-pass.d.ts +35 -0
  124. package/dist/lighting/pbr-surface-pass.d.ts.map +1 -0
  125. package/dist/lighting/pbr-surface-pass.js +98 -0
  126. package/dist/lighting/pbr-surface-pass.js.map +1 -0
  127. package/dist/lighting/prefiltered-environment.cjs +275 -0
  128. package/dist/lighting/prefiltered-environment.d.ts +56 -0
  129. package/dist/lighting/prefiltered-environment.d.ts.map +1 -0
  130. package/dist/lighting/prefiltered-environment.js +264 -0
  131. package/dist/lighting/prefiltered-environment.js.map +1 -0
  132. package/dist/lighting/shadow-map-renderer.cjs +631 -0
  133. package/dist/lighting/shadow-map-renderer.d.ts +92 -0
  134. package/dist/lighting/shadow-map-renderer.d.ts.map +1 -0
  135. package/dist/lighting/shadow-map-renderer.js +622 -0
  136. package/dist/lighting/shadow-map-renderer.js.map +1 -0
  137. package/dist/lighting/shadow-quality.cjs +58 -0
  138. package/dist/lighting/shadow-quality.d.ts +13 -0
  139. package/dist/lighting/shadow-quality.d.ts.map +1 -0
  140. package/dist/lighting/shadow-quality.js +37 -0
  141. package/dist/lighting/shadow-quality.js.map +1 -0
  142. package/dist/material/material.cjs +3 -0
  143. package/dist/material/material.d.ts +2 -0
  144. package/dist/material/material.d.ts.map +1 -1
  145. package/dist/material/material.js +3 -0
  146. package/dist/material/material.js.map +1 -1
  147. package/dist/model/gpu-vector-model.cjs +11 -1
  148. package/dist/model/gpu-vector-model.d.ts +4 -2
  149. package/dist/model/gpu-vector-model.d.ts.map +1 -1
  150. package/dist/model/gpu-vector-model.js +12 -1
  151. package/dist/model/gpu-vector-model.js.map +1 -1
  152. package/dist/scenegraph/controllers/punctual-light-controller.cjs +121 -0
  153. package/dist/scenegraph/controllers/punctual-light-controller.d.ts +31 -0
  154. package/dist/scenegraph/controllers/punctual-light-controller.d.ts.map +1 -0
  155. package/dist/scenegraph/controllers/punctual-light-controller.js +117 -0
  156. package/dist/scenegraph/controllers/punctual-light-controller.js.map +1 -0
  157. package/dist/scenegraph/scene-metadata.cjs +43 -0
  158. package/dist/scenegraph/scene-metadata.d.ts +9 -0
  159. package/dist/scenegraph/scene-metadata.d.ts.map +1 -0
  160. package/dist/scenegraph/scene-metadata.js +21 -0
  161. package/dist/scenegraph/scene-metadata.js.map +1 -0
  162. package/dist/scenegraph/scenegraph-interaction.cjs +99 -0
  163. package/dist/scenegraph/scenegraph-interaction.d.ts +47 -0
  164. package/dist/scenegraph/scenegraph-interaction.d.ts.map +1 -0
  165. package/dist/scenegraph/scenegraph-interaction.js +79 -0
  166. package/dist/scenegraph/scenegraph-interaction.js.map +1 -0
  167. package/dist/scenegraph/scenegraph-node.cjs +10 -0
  168. package/dist/scenegraph/scenegraph-node.d.ts +10 -0
  169. package/dist/scenegraph/scenegraph-node.d.ts.map +1 -1
  170. package/dist/scenegraph/scenegraph-node.js +10 -0
  171. package/dist/scenegraph/scenegraph-node.js.map +1 -1
  172. package/dist/text/experimental.cjs.map +1 -1
  173. package/dist/text/fonts/atlas/text-utils.cjs +1 -1
  174. package/dist/text/fonts/atlas/text-utils.js +1 -1
  175. package/dist/text/fonts/atlas/text-utils.js.map +1 -1
  176. package/dist/text/fonts/index.cjs.map +1 -1
  177. package/dist/text/index.cjs.map +1 -1
  178. package/dist/text/text-2d/models/text-attribute-model.cjs +1 -1
  179. package/dist/text/text-2d/models/text-attribute-model.js +1 -1
  180. package/dist/text/text-2d/models/text-attribute-model.js.map +1 -1
  181. package/dist/text/text-2d/models/text-dictionary-model.cjs +1 -1
  182. package/dist/text/text-2d/models/text-dictionary-model.js +1 -1
  183. package/dist/text/text-2d/models/text-dictionary-model.js.map +1 -1
  184. package/dist/text/text-2d/models/text-storage-model.cjs +1 -1
  185. package/dist/text/text-2d/models/text-storage-model.js +1 -1
  186. package/dist/text/text-2d/models/text-storage-model.js.map +1 -1
  187. package/package.json +13 -8
  188. package/src/animation/node-animation-binding.ts +18 -1
  189. package/src/gltf/gltf/animations/animations.ts +8 -1
  190. package/src/gltf/gltf/create-scenegraph-from-gltf.ts +98 -17
  191. package/src/gltf/gltf/gltf-billboard.ts +6 -1
  192. package/src/gltf/gltf/gltf-extension-support.ts +2 -2
  193. package/src/gltf/index.ts +1 -0
  194. package/src/gltf/parsers/parse-gltf-animations.ts +22 -8
  195. package/src/gltf/parsers/parse-gltf-lights.ts +42 -130
  196. package/src/gltf/parsers/parse-gltf-metadata.ts +40 -0
  197. package/src/gltf/parsers/parse-gltf.ts +5 -0
  198. package/src/gltf/pbr/pbr-environment.ts +27 -1
  199. package/src/graph/models/path/path-attribute-model.ts +1 -1
  200. package/src/graph/models/path/path-storage-model.ts +1 -1
  201. package/src/index.ts +16 -0
  202. package/src/lighting/ambient-occlusion-pass.ts +130 -0
  203. package/src/lighting/clustered-light-grid.ts +481 -0
  204. package/src/lighting/contact-shadow-composite.ts +67 -0
  205. package/src/lighting/contact-shadow-pass.ts +107 -0
  206. package/src/lighting/index.ts +107 -0
  207. package/src/lighting/lightmap-baker.ts +306 -0
  208. package/src/lighting/lightmap-data.ts +138 -0
  209. package/src/lighting/lightmap-environment.ts +70 -0
  210. package/src/lighting/pbr-environment.ts +55 -0
  211. package/src/lighting/pbr-material.ts +85 -0
  212. package/src/lighting/pbr-model.ts +608 -0
  213. package/src/lighting/pbr-surface-pass.ts +122 -0
  214. package/src/lighting/prefiltered-environment.ts +354 -0
  215. package/src/lighting/shadow-map-renderer.ts +918 -0
  216. package/src/lighting/shadow-quality.ts +50 -0
  217. package/src/material/material.ts +3 -0
  218. package/src/model/gpu-vector-model.ts +18 -3
  219. package/src/scenegraph/controllers/punctual-light-controller.ts +172 -0
  220. package/src/scenegraph/scene-metadata.ts +23 -0
  221. package/src/scenegraph/scenegraph-interaction.ts +131 -0
  222. package/src/scenegraph/scenegraph-node.ts +12 -0
  223. package/src/text/fonts/atlas/text-utils.ts +1 -1
  224. package/src/text/text-2d/models/text-attribute-model.ts +1 -1
  225. package/src/text/text-2d/models/text-dictionary-model.ts +1 -1
  226. package/src/text/text-2d/models/text-storage-model.ts +1 -1
@@ -0,0 +1,50 @@
1
+ // luma.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
+
5
+ export type ShadowQualitySettings = {
6
+ cascadeCount: number;
7
+ directionalMapSize: number;
8
+ spotMapSize: number;
9
+ pointMapSize: number;
10
+ blockerSampleCount: number;
11
+ filterSampleCount: number;
12
+ contactScale: number;
13
+ contactStepCount: number;
14
+ };
15
+
16
+ /** Fixed quality settings shared by shadow maps, PCSS and contact refinement. */
17
+ export const SHADOW_QUALITY_SETTINGS: Readonly<
18
+ Record<'low' | 'balanced' | 'cinematic', Readonly<ShadowQualitySettings>>
19
+ > = Object.freeze({
20
+ low: Object.freeze({
21
+ cascadeCount: 3,
22
+ directionalMapSize: 1024,
23
+ spotMapSize: 512,
24
+ pointMapSize: 256,
25
+ blockerSampleCount: 8,
26
+ filterSampleCount: 12,
27
+ contactScale: 0.5,
28
+ contactStepCount: 12
29
+ }),
30
+ balanced: Object.freeze({
31
+ cascadeCount: 4,
32
+ directionalMapSize: 1536,
33
+ spotMapSize: 1024,
34
+ pointMapSize: 512,
35
+ blockerSampleCount: 16,
36
+ filterSampleCount: 24,
37
+ contactScale: 0.75,
38
+ contactStepCount: 24
39
+ }),
40
+ cinematic: Object.freeze({
41
+ cascadeCount: 4,
42
+ directionalMapSize: 2048,
43
+ spotMapSize: 2048,
44
+ pointMapSize: 1024,
45
+ blockerSampleCount: 24,
46
+ filterSampleCount: 48,
47
+ contactScale: 1,
48
+ contactStepCount: 40
49
+ })
50
+ });
@@ -87,6 +87,8 @@ export class Material<
87
87
  > {
88
88
  /** Application-provided identifier. */
89
89
  readonly id: string;
90
+ /** Structured metadata associated with this material. */
91
+ metadata: Record<string, unknown> = {};
90
92
  /** Device that owns the material resources. */
91
93
  readonly device: Device;
92
94
  /** Factory that defines the material schema. */
@@ -156,6 +158,7 @@ export class Material<
156
158
  if (props.moduleProps) {
157
159
  material.setProps(props.moduleProps);
158
160
  }
161
+ material.metadata = {...this.metadata};
159
162
  material.updateShaderInputs();
160
163
  return material;
161
164
  }
@@ -116,8 +116,8 @@ export type ModelDrawOptions = {
116
116
  parameters?: {
117
117
  /** Viewport [x, y, width, height, minDepth?, maxDepth?]. */
118
118
  viewport?: NumberArray4 | NumberArray6;
119
- /** Scissor rectangle [x, y, width, height]. */
120
- scissorRect?: NumberArray4;
119
+ /** Scissor rectangle [x, y, width, height], or null to disable clipping. */
120
+ scissorRect?: NumberArray4 | null;
121
121
  /** Blend color used by constant blend factors. */
122
122
  blendConstant?: NumberArray4;
123
123
  /** Value used for stencil comparison and replacement. */
@@ -685,11 +685,26 @@ export class GPUVectorModel {
685
685
  */
686
686
  draw(renderPass: RenderPass, options?: ModelDrawOptions): boolean {
687
687
  if (options?.parameters) {
688
- return renderPass.withParameters(options.parameters, () => this._draw(renderPass));
688
+ return this._withDrawParameters(renderPass, options.parameters, () => this._draw(renderPass));
689
689
  }
690
690
  return this._draw(renderPass);
691
691
  }
692
692
 
693
+ /** Applies draw overrides around the complete model batch, including failure paths. */
694
+ protected _withDrawParameters<T>(
695
+ renderPass: RenderPass,
696
+ parameters: NonNullable<ModelDrawOptions['parameters']>,
697
+ draw: () => T
698
+ ): T {
699
+ const state = renderPass.getParameters();
700
+ try {
701
+ renderPass.setParameters(parameters);
702
+ return draw();
703
+ } finally {
704
+ renderPass.setParameters(state);
705
+ }
706
+ }
707
+
693
708
  private _draw(renderPass: RenderPass): boolean {
694
709
  if (this.indexVector?.length === 0) {
695
710
  this._lastDrawTimestamp = this.device.timestamp;
@@ -0,0 +1,172 @@
1
+ // luma.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
+
5
+ import {Matrix4} from '@math.gl/core';
6
+ import {
7
+ normalizeByteColor3,
8
+ type DirectionalLight,
9
+ type Light,
10
+ type PointLight,
11
+ type SpotLight
12
+ } from '@luma.gl/shaders';
13
+ import type {ScenegraphNode} from '../scenegraph-node';
14
+
15
+ /** Light parameters in local space with normalized RGB color. */
16
+ export type PunctualLightDefinition = {
17
+ type: 'directional' | 'point' | 'spot';
18
+ color?: [number, number, number];
19
+ intensity?: number;
20
+ range?: number;
21
+ spot?: {innerConeAngle?: number; outerConeAngle?: number};
22
+ };
23
+
24
+ /** A light and its root-to-light scenegraph path. */
25
+ export type PunctualLightBinding = {
26
+ path: readonly ScenegraphNode[];
27
+ definition: PunctualLightDefinition;
28
+ };
29
+
30
+ /** Projects bound lights using live node transforms and inherited visibility. */
31
+ export class PunctualLightController {
32
+ readonly lights: Light[] = [];
33
+
34
+ constructor(
35
+ private readonly bindings: readonly PunctualLightBinding[],
36
+ private readonly useByteColors = true
37
+ ) {
38
+ this.update();
39
+ }
40
+
41
+ /** Refreshes the stable light array after node or light properties change. */
42
+ update(): void {
43
+ this.lights.length = 0;
44
+ for (const {path, definition} of this.bindings) {
45
+ if (!path.length || path.some(node => !node.display)) continue;
46
+ const worldMatrix = new Matrix4();
47
+ for (const node of path) worldMatrix.multiplyRight(node.matrix);
48
+ const light = makePunctualLight(definition, worldMatrix, this.useByteColors);
49
+ if (light) this.lights.push(light);
50
+ }
51
+ }
52
+ }
53
+
54
+ /** Projects a local light definition into the shader's world-space light format. */
55
+ export function makePunctualLight(
56
+ definition: PunctualLightDefinition,
57
+ worldMatrix: Matrix4,
58
+ useByteColors: boolean
59
+ ): Light | undefined {
60
+ const color = normalizePunctualLightColor(definition.color || [1, 1, 1], useByteColors);
61
+ const intensity = definition.intensity ?? 1;
62
+ switch (definition.type) {
63
+ case 'directional':
64
+ return makeDirectionalLight(worldMatrix, color, intensity);
65
+ case 'point':
66
+ return makePointLight(worldMatrix, color, intensity, definition.range);
67
+ case 'spot':
68
+ return makeSpotLight(worldMatrix, color, intensity, definition.range, definition.spot);
69
+ default:
70
+ return undefined;
71
+ }
72
+ }
73
+
74
+ /**
75
+ * Converts normalized colors from the 0-1 spec range to the configured luma light convention.
76
+ */
77
+ function normalizePunctualLightColor(
78
+ color: [number, number, number],
79
+ useByteColors: boolean
80
+ ): [number, number, number] {
81
+ if (useByteColors) {
82
+ return color.map(component => component * 255) as [number, number, number];
83
+ }
84
+ return normalizeByteColor3(color, false) as [number, number, number];
85
+ }
86
+
87
+ /**
88
+ * Converts a punctual light attached to a node into a point light.
89
+ */
90
+ function makePointLight(
91
+ worldMatrix: Matrix4,
92
+ color: [number, number, number],
93
+ intensity: number,
94
+ range?: number
95
+ ): PointLight {
96
+ const position = getLightPosition(worldMatrix);
97
+
98
+ let attenuation: Readonly<[number, number, number]> = [1, 0, 0];
99
+ if (range !== undefined && range > 0) {
100
+ attenuation = [1, 0, 1 / (range * range)] as [number, number, number];
101
+ }
102
+
103
+ return {
104
+ type: 'point',
105
+ position,
106
+ color,
107
+ intensity,
108
+ attenuation
109
+ };
110
+ }
111
+
112
+ /**
113
+ * Converts a punctual light attached to a node into a directional light.
114
+ */
115
+ function makeDirectionalLight(
116
+ worldMatrix: Matrix4,
117
+ color: [number, number, number],
118
+ intensity: number
119
+ ): DirectionalLight {
120
+ const direction = getLightDirection(worldMatrix);
121
+
122
+ return {
123
+ type: 'directional',
124
+ direction,
125
+ color,
126
+ intensity
127
+ };
128
+ }
129
+
130
+ /**
131
+ * Converts a punctual light attached to a node into a spot light.
132
+ */
133
+ function makeSpotLight(
134
+ worldMatrix: Matrix4,
135
+ color: [number, number, number],
136
+ intensity: number,
137
+ range?: number,
138
+ spot: {innerConeAngle?: number; outerConeAngle?: number} = {}
139
+ ): SpotLight {
140
+ const position = getLightPosition(worldMatrix);
141
+ const direction = getLightDirection(worldMatrix);
142
+
143
+ let attenuation: Readonly<[number, number, number]> = [1, 0, 0];
144
+ if (range !== undefined && range > 0) {
145
+ attenuation = [1, 0, 1 / (range * range)] as [number, number, number];
146
+ }
147
+
148
+ return {
149
+ type: 'spot',
150
+ position,
151
+ direction,
152
+ color,
153
+ intensity,
154
+ attenuation,
155
+ innerConeAngle: spot.innerConeAngle ?? 0,
156
+ outerConeAngle: spot.outerConeAngle ?? Math.PI / 4
157
+ };
158
+ }
159
+
160
+ /**
161
+ * Resolves the world-space position of a light node.
162
+ */
163
+ function getLightPosition(worldMatrix: Matrix4): [number, number, number] {
164
+ return worldMatrix.transformAsPoint([0, 0, 0]) as [number, number, number];
165
+ }
166
+
167
+ /**
168
+ * Resolves the world-space forward direction of a light node.
169
+ */
170
+ function getLightDirection(worldMatrix: Matrix4): [number, number, number] {
171
+ return worldMatrix.transformAsVector([0, 0, -1]) as [number, number, number];
172
+ }
@@ -0,0 +1,23 @@
1
+ // luma.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
+
5
+ /** A collection of source metadata associated with indexed scene resources. */
6
+ export class SceneMetadata {
7
+ private readonly entries = new Map<string, Map<number, Readonly<Record<string, unknown>>>>();
8
+
9
+ /** Associates metadata with a resource category and its source index. */
10
+ set(category: string, index: number, metadata: Readonly<Record<string, unknown>>): void {
11
+ let categoryEntries = this.entries.get(category);
12
+ if (!categoryEntries) {
13
+ categoryEntries = new Map();
14
+ this.entries.set(category, categoryEntries);
15
+ }
16
+ categoryEntries.set(index, metadata);
17
+ }
18
+
19
+ /** Returns metadata for a resource, or undefined when none was supplied. */
20
+ get(category: string, index = 0): Readonly<Record<string, unknown>> | undefined {
21
+ return this.entries.get(category)?.get(index);
22
+ }
23
+ }
@@ -0,0 +1,131 @@
1
+ // luma.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
+
5
+ import type {ScenegraphNode} from './scenegraph-node';
6
+
7
+ /** Action whose authored subtree eligibility is being evaluated. */
8
+ export type ScenegraphInteractionKind = 'select' | 'hover';
9
+
10
+ /** A hit with its particular root-to-target path, ordered nearest to farthest by the caller. */
11
+ export type ScenegraphInteractionHit = {
12
+ /** Root-to-target path, including the hit node; distinguishes shared instances. */
13
+ path: readonly ScenegraphNode[];
14
+ /** Optional intersection point in world coordinates. */
15
+ point?: readonly [number, number, number];
16
+ /** Optional world-space ray origin. */
17
+ rayOrigin?: readonly [number, number, number];
18
+ /** Application-specific picking information. */
19
+ data?: unknown;
20
+ };
21
+
22
+ /** Returns whether all nodes on an instance path permit the specified action. */
23
+ export function isScenegraphInteractionEnabled(
24
+ path: readonly ScenegraphNode[],
25
+ kind: ScenegraphInteractionKind
26
+ ): boolean {
27
+ return (
28
+ path.length > 0 && path.every(node => (kind === 'select' ? node.selectable : node.hoverable))
29
+ );
30
+ }
31
+
32
+ /** Finds the first eligible hit without letting an ineligible hit occlude later candidates. */
33
+ export function getFirstScenegraphInteractionHit<Hit extends ScenegraphInteractionHit>(
34
+ hits: readonly Hit[],
35
+ kind: ScenegraphInteractionKind
36
+ ): Hit | undefined {
37
+ return hits.find(hit => isScenegraphInteractionEnabled(hit.path, kind));
38
+ }
39
+
40
+ /** One bubbled host interaction event. */
41
+ export type ScenegraphInteractionEvent = {
42
+ type: 'select' | 'hover-in' | 'hover-out';
43
+ /** Target object where the interaction began or ended. */
44
+ target: ScenegraphNode;
45
+ /** Node receiving this step of the event's upward propagation. */
46
+ currentTarget: ScenegraphNode;
47
+ /** Identifies the pointer or controller. */
48
+ controllerIndex: number;
49
+ /** The original host hit associated with this event. */
50
+ hit: ScenegraphInteractionHit;
51
+ };
52
+
53
+ /** Caller-owned hit testing with per-controller hover tracking and subtree event propagation. */
54
+ export class ScenegraphInteractionManager {
55
+ private readonly hoveredHits = new Map<number, ScenegraphInteractionHit>();
56
+ private readonly pendingHover = new Map<number, (ScenegraphInteractionHit | undefined)[]>();
57
+ private readonly onEvent: (event: ScenegraphInteractionEvent) => void;
58
+
59
+ /** Creates a controller that reports bubbled selection and hover events. */
60
+ constructor(onEvent: (event: ScenegraphInteractionEvent) => void) {
61
+ this.onEvent = onEvent;
62
+ }
63
+
64
+ /** Selects the first eligible nearest-first hit and bubbles from target to root. */
65
+ select<Hit extends ScenegraphInteractionHit>(
66
+ hits: readonly Hit[],
67
+ controllerIndex = 0
68
+ ): Hit | undefined {
69
+ const hit = getFirstScenegraphInteractionHit(hits, 'select');
70
+ if (!hit) return undefined;
71
+ this.emitPath('select', hit, 0, controllerIndex);
72
+ return hit;
73
+ }
74
+
75
+ /** Updates hover from current hits; call after pointer, camera, object, or flag changes. */
76
+ updateHover<Hit extends ScenegraphInteractionHit>(
77
+ hits: readonly Hit[],
78
+ controllerIndex = 0
79
+ ): Hit | undefined {
80
+ const hit = getFirstScenegraphInteractionHit(hits, 'hover');
81
+ const queuedHit = hit ? {...hit, path: [...hit.path]} : undefined;
82
+ const activeQueue = this.pendingHover.get(controllerIndex);
83
+ if (activeQueue) {
84
+ activeQueue.push(queuedHit);
85
+ return hit;
86
+ }
87
+ const queue = [queuedHit];
88
+ this.pendingHover.set(controllerIndex, queue);
89
+ try {
90
+ while (queue.length) {
91
+ const next = queue.shift();
92
+ const previous = this.hoveredHits.get(controllerIndex);
93
+ const previousPath = previous?.path || [];
94
+ const nextPath = next?.path || [];
95
+ let shared = 0;
96
+ while (
97
+ shared < previousPath.length &&
98
+ shared < nextPath.length &&
99
+ previousPath[shared] === nextPath[shared]
100
+ )
101
+ shared++;
102
+ if (next) this.hoveredHits.set(controllerIndex, next);
103
+ else this.hoveredHits.delete(controllerIndex);
104
+ if (previous) this.emitPath('hover-out', previous, shared, controllerIndex);
105
+ if (next) this.emitPath('hover-in', next, shared, controllerIndex);
106
+ }
107
+ } finally {
108
+ this.pendingHover.delete(controllerIndex);
109
+ }
110
+ return hit;
111
+ }
112
+
113
+ /** Emits exits for one controller and drops its tracked hover path. */
114
+ clearHover(controllerIndex = 0): void {
115
+ this.updateHover([], controllerIndex);
116
+ }
117
+
118
+ /** Emits events from the target towards the first ancestor outside the shared subtree. */
119
+ private emitPath(
120
+ type: ScenegraphInteractionEvent['type'],
121
+ hit: ScenegraphInteractionHit,
122
+ first: number,
123
+ controllerIndex: number
124
+ ): void {
125
+ const {path} = hit;
126
+ const target = path[path.length - 1];
127
+ for (let index = path.length - 1; index >= first; index--) {
128
+ this.onEvent({type, target, currentTarget: path[index], controllerIndex, hit});
129
+ }
130
+ }
131
+ }
@@ -14,6 +14,10 @@ function assert(condition: boolean, message?: string): asserts condition {
14
14
  /** Properties for creating a new Scenegraph */
15
15
  export type ScenegraphNodeProps = {
16
16
  id?: string;
17
+ /** Local selection eligibility; ancestors can disable their entire subtree. */
18
+ selectable?: boolean;
19
+ /** Local hover eligibility; ancestors can disable their entire subtree. */
20
+ hoverable?: boolean;
17
21
  /** whether to display the object at all */
18
22
  display?: boolean;
19
23
  matrix?: NumericArray;
@@ -28,9 +32,15 @@ export class ScenegraphNode {
28
32
  matrix: Matrix4 = new Matrix4();
29
33
 
30
34
  display = true;
35
+ /** Local selection eligibility, independent of visibility. */
36
+ selectable = true;
37
+ /** Local hover eligibility, independent of visibility. */
38
+ hoverable = true;
31
39
  position = new Vector3();
32
40
  rotation = new Vector3();
33
41
  scale = new Vector3(1, 1, 1);
42
+ /** Structured metadata associated with this scene node. */
43
+ metadata: Record<string, unknown> = {};
34
44
  userData: Record<string, unknown> = {};
35
45
 
36
46
  props: ScenegraphNodeProps = {};
@@ -193,6 +203,8 @@ export class ScenegraphNode {
193
203
  */
194
204
 
195
205
  _setScenegraphNodeProps(props: ScenegraphNodeProps): void {
206
+ if (props.selectable !== undefined) this.selectable = props.selectable;
207
+ if (props.hoverable !== undefined) this.hoverable = props.hoverable;
196
208
  if (props.display !== undefined) {
197
209
  this.display = props.display;
198
210
  }
@@ -141,6 +141,6 @@ export function buildMapping({
141
141
  xOffset: x,
142
142
  yOffsetMin: yMin,
143
143
  yOffsetMax: yMax,
144
- canvasHeight: nextPowOfTwo(yMax)
144
+ canvasHeight: Math.max(1, nextPowOfTwo(yMax))
145
145
  };
146
146
  }
@@ -103,7 +103,7 @@ export class TextAttributeModel extends GPUTableModel {
103
103
  /** Draws each generated glyph render batch against the supplied render pass. */
104
104
  override draw(renderPass: RenderPass, options?: ModelDrawOptions): boolean {
105
105
  return options?.parameters
106
- ? renderPass.withParameters(options.parameters, () =>
106
+ ? this._withDrawParameters(renderPass, options.parameters, () =>
107
107
  this.drawTextAttributeModelBatches(renderPass)
108
108
  )
109
109
  : this.drawTextAttributeModelBatches(renderPass);
@@ -79,7 +79,7 @@ export class TextDictionaryModel extends Model {
79
79
  /** Draws each compressed dictionary text render batch against the supplied render pass. */
80
80
  override draw(renderPass: RenderPass, options?: ModelDrawOptions): boolean {
81
81
  return options?.parameters
82
- ? renderPass.withParameters(options.parameters, () =>
82
+ ? this._withDrawParameters(renderPass, options.parameters, () =>
83
83
  this.drawTextDictionaryModelBatches(renderPass)
84
84
  )
85
85
  : this.drawTextDictionaryModelBatches(renderPass);
@@ -86,7 +86,7 @@ export class TextStorageModel extends Model {
86
86
  /** Draws each generated storage text render batch against the supplied render pass. */
87
87
  override draw(renderPass: RenderPass, options?: ModelDrawOptions): boolean {
88
88
  return options?.parameters
89
- ? renderPass.withParameters(options.parameters, () =>
89
+ ? this._withDrawParameters(renderPass, options.parameters, () =>
90
90
  this.drawTextStorageModelBatches(renderPass)
91
91
  )
92
92
  : this.drawTextStorageModelBatches(renderPass);