@luma.gl/engine 10.0.0-alpha.10 → 10.0.0-alpha.11
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/node-animation-binding.cjs +10 -0
- package/dist/animation/node-animation-binding.d.ts +1 -1
- package/dist/animation/node-animation-binding.d.ts.map +1 -1
- package/dist/animation/node-animation-binding.js +10 -0
- package/dist/animation/node-animation-binding.js.map +1 -1
- package/dist/dist.dev.js +325 -80
- package/dist/dist.min.js +58 -58
- package/dist/gltf/gltf/animations/animations.d.ts +1 -1
- package/dist/gltf/gltf/animations/animations.d.ts.map +1 -1
- package/dist/gltf/gltf/create-scenegraph-from-gltf.cjs +80 -12
- package/dist/gltf/gltf/create-scenegraph-from-gltf.d.ts +8 -1
- package/dist/gltf/gltf/create-scenegraph-from-gltf.d.ts.map +1 -1
- package/dist/gltf/gltf/create-scenegraph-from-gltf.js +82 -14
- package/dist/gltf/gltf/create-scenegraph-from-gltf.js.map +1 -1
- package/dist/gltf/gltf/gltf-billboard.cjs +6 -1
- package/dist/gltf/gltf/gltf-billboard.d.ts.map +1 -1
- package/dist/gltf/gltf/gltf-billboard.js +6 -1
- package/dist/gltf/gltf/gltf-billboard.js.map +1 -1
- package/dist/gltf/gltf/gltf-extension-support.cjs +2 -2
- package/dist/gltf/gltf/gltf-extension-support.js +2 -2
- package/dist/gltf/gltf/gltf-extension-support.js.map +1 -1
- package/dist/gltf/index.cjs +2 -0
- package/dist/gltf/index.cjs.map +3 -3
- package/dist/gltf/index.d.ts +1 -1
- package/dist/gltf/index.d.ts.map +1 -1
- package/dist/gltf/index.js +1 -1
- package/dist/gltf/index.js.map +1 -1
- package/dist/gltf/parsers/parse-gltf-animations.cjs +8 -5
- package/dist/gltf/parsers/parse-gltf-animations.js +20 -5
- package/dist/gltf/parsers/parse-gltf-animations.js.map +1 -1
- package/dist/gltf/parsers/parse-gltf-lights.cjs +36 -72
- package/dist/gltf/parsers/parse-gltf-lights.d.ts +6 -2
- package/dist/gltf/parsers/parse-gltf-lights.d.ts.map +1 -1
- package/dist/gltf/parsers/parse-gltf-lights.js +34 -91
- package/dist/gltf/parsers/parse-gltf-lights.js.map +1 -1
- package/dist/gltf/parsers/parse-gltf-metadata.cjs +60 -0
- package/dist/gltf/parsers/parse-gltf-metadata.d.ts +5 -0
- package/dist/gltf/parsers/parse-gltf-metadata.d.ts.map +1 -0
- package/dist/gltf/parsers/parse-gltf-metadata.js +39 -0
- package/dist/gltf/parsers/parse-gltf-metadata.js.map +1 -0
- package/dist/gltf/parsers/parse-gltf.cjs +4 -1
- package/dist/gltf/parsers/parse-gltf.d.ts +4 -0
- package/dist/gltf/parsers/parse-gltf.d.ts.map +1 -1
- package/dist/gltf/parsers/parse-gltf.js +3 -0
- package/dist/gltf/parsers/parse-gltf.js.map +1 -1
- package/dist/gltf/pbr/pbr-environment.cjs +21 -3
- package/dist/gltf/pbr/pbr-environment.d.ts +3 -0
- package/dist/gltf/pbr/pbr-environment.d.ts.map +1 -1
- package/dist/gltf/pbr/pbr-environment.js +19 -1
- package/dist/gltf/pbr/pbr-environment.js.map +1 -1
- package/dist/graph/models/index.cjs.map +1 -1
- package/dist/graph/models/path/path-attribute-model.cjs +1 -1
- package/dist/graph/models/path/path-attribute-model.js +1 -1
- package/dist/graph/models/path/path-attribute-model.js.map +1 -1
- package/dist/graph/models/path/path-storage-model.cjs +1 -1
- package/dist/graph/models/path/path-storage-model.js +1 -1
- package/dist/graph/models/path/path-storage-model.js.map +1 -1
- package/dist/graph/physics/index.cjs.map +1 -1
- package/dist/graph/tables/index.cjs.map +1 -1
- package/dist/index.cjs +13 -0
- package/dist/index.cjs.map +3 -3
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/lighting/ambient-occlusion-pass.cjs +126 -0
- package/dist/lighting/ambient-occlusion-pass.d.ts +31 -0
- package/dist/lighting/ambient-occlusion-pass.d.ts.map +1 -0
- package/dist/lighting/ambient-occlusion-pass.js +108 -0
- package/dist/lighting/ambient-occlusion-pass.js.map +1 -0
- package/dist/lighting/clustered-light-grid.cjs +378 -0
- package/dist/lighting/clustered-light-grid.d.ts +94 -0
- package/dist/lighting/clustered-light-grid.d.ts.map +1 -0
- package/dist/lighting/clustered-light-grid.js +370 -0
- package/dist/lighting/clustered-light-grid.js.map +1 -0
- package/dist/lighting/contact-shadow-composite.cjs +80 -0
- package/dist/lighting/contact-shadow-composite.d.ts +6 -0
- package/dist/lighting/contact-shadow-composite.d.ts.map +1 -0
- package/dist/lighting/contact-shadow-composite.js +59 -0
- package/dist/lighting/contact-shadow-composite.js.map +1 -0
- package/dist/lighting/contact-shadow-pass.cjs +102 -0
- package/dist/lighting/contact-shadow-pass.d.ts +23 -0
- package/dist/lighting/contact-shadow-pass.d.ts.map +1 -0
- package/dist/lighting/contact-shadow-pass.js +85 -0
- package/dist/lighting/contact-shadow-pass.js.map +1 -0
- package/dist/lighting/index.cjs +98 -0
- package/dist/lighting/index.cjs.map +6 -0
- package/dist/lighting/index.d.ts +23 -0
- package/dist/lighting/index.d.ts.map +1 -0
- package/dist/lighting/index.js +16 -0
- package/dist/lighting/index.js.map +1 -0
- package/dist/lighting/pbr-environment.cjs +45 -0
- package/dist/lighting/pbr-environment.d.ts +25 -0
- package/dist/lighting/pbr-environment.d.ts.map +1 -0
- package/dist/lighting/pbr-environment.js +30 -0
- package/dist/lighting/pbr-environment.js.map +1 -0
- package/dist/lighting/pbr-material.cjs +75 -0
- package/dist/lighting/pbr-material.d.ts +33 -0
- package/dist/lighting/pbr-material.d.ts.map +1 -0
- package/dist/lighting/pbr-material.js +52 -0
- package/dist/lighting/pbr-material.js.map +1 -0
- package/dist/lighting/pbr-model.cjs +509 -0
- package/dist/lighting/pbr-model.d.ts +41 -0
- package/dist/lighting/pbr-model.d.ts.map +1 -0
- package/dist/lighting/pbr-model.js +475 -0
- package/dist/lighting/pbr-model.js.map +1 -0
- package/dist/lighting/pbr-surface-pass.cjs +116 -0
- package/dist/lighting/pbr-surface-pass.d.ts +35 -0
- package/dist/lighting/pbr-surface-pass.d.ts.map +1 -0
- package/dist/lighting/pbr-surface-pass.js +98 -0
- package/dist/lighting/pbr-surface-pass.js.map +1 -0
- package/dist/lighting/prefiltered-environment.cjs +275 -0
- package/dist/lighting/prefiltered-environment.d.ts +56 -0
- package/dist/lighting/prefiltered-environment.d.ts.map +1 -0
- package/dist/lighting/prefiltered-environment.js +264 -0
- package/dist/lighting/prefiltered-environment.js.map +1 -0
- package/dist/lighting/shadow-map-renderer.cjs +627 -0
- package/dist/lighting/shadow-map-renderer.d.ts +92 -0
- package/dist/lighting/shadow-map-renderer.d.ts.map +1 -0
- package/dist/lighting/shadow-map-renderer.js +617 -0
- package/dist/lighting/shadow-map-renderer.js.map +1 -0
- package/dist/lighting/shadow-quality.cjs +58 -0
- package/dist/lighting/shadow-quality.d.ts +13 -0
- package/dist/lighting/shadow-quality.d.ts.map +1 -0
- package/dist/lighting/shadow-quality.js +37 -0
- package/dist/lighting/shadow-quality.js.map +1 -0
- package/dist/material/material.cjs +3 -0
- package/dist/material/material.d.ts +2 -0
- package/dist/material/material.d.ts.map +1 -1
- package/dist/material/material.js +3 -0
- package/dist/material/material.js.map +1 -1
- package/dist/model/gpu-vector-model.cjs +11 -1
- package/dist/model/gpu-vector-model.d.ts +4 -2
- package/dist/model/gpu-vector-model.d.ts.map +1 -1
- package/dist/model/gpu-vector-model.js +12 -1
- package/dist/model/gpu-vector-model.js.map +1 -1
- package/dist/scenegraph/controllers/punctual-light-controller.cjs +121 -0
- package/dist/scenegraph/controllers/punctual-light-controller.d.ts +31 -0
- package/dist/scenegraph/controllers/punctual-light-controller.d.ts.map +1 -0
- package/dist/scenegraph/controllers/punctual-light-controller.js +117 -0
- package/dist/scenegraph/controllers/punctual-light-controller.js.map +1 -0
- package/dist/scenegraph/scene-metadata.cjs +43 -0
- package/dist/scenegraph/scene-metadata.d.ts +9 -0
- package/dist/scenegraph/scene-metadata.d.ts.map +1 -0
- package/dist/scenegraph/scene-metadata.js +21 -0
- package/dist/scenegraph/scene-metadata.js.map +1 -0
- package/dist/scenegraph/scenegraph-interaction.cjs +99 -0
- package/dist/scenegraph/scenegraph-interaction.d.ts +47 -0
- package/dist/scenegraph/scenegraph-interaction.d.ts.map +1 -0
- package/dist/scenegraph/scenegraph-interaction.js +79 -0
- package/dist/scenegraph/scenegraph-interaction.js.map +1 -0
- package/dist/scenegraph/scenegraph-node.cjs +10 -0
- package/dist/scenegraph/scenegraph-node.d.ts +10 -0
- package/dist/scenegraph/scenegraph-node.d.ts.map +1 -1
- package/dist/scenegraph/scenegraph-node.js +10 -0
- package/dist/scenegraph/scenegraph-node.js.map +1 -1
- package/dist/text/experimental.cjs.map +1 -1
- package/dist/text/fonts/atlas/text-utils.cjs +1 -1
- package/dist/text/fonts/atlas/text-utils.js +1 -1
- package/dist/text/fonts/atlas/text-utils.js.map +1 -1
- package/dist/text/fonts/index.cjs.map +1 -1
- package/dist/text/index.cjs.map +1 -1
- package/dist/text/text-2d/models/text-attribute-model.cjs +1 -1
- package/dist/text/text-2d/models/text-attribute-model.js +1 -1
- package/dist/text/text-2d/models/text-attribute-model.js.map +1 -1
- package/dist/text/text-2d/models/text-dictionary-model.cjs +1 -1
- package/dist/text/text-2d/models/text-dictionary-model.js +1 -1
- package/dist/text/text-2d/models/text-dictionary-model.js.map +1 -1
- package/dist/text/text-2d/models/text-storage-model.cjs +1 -1
- package/dist/text/text-2d/models/text-storage-model.js +1 -1
- package/dist/text/text-2d/models/text-storage-model.js.map +1 -1
- package/package.json +13 -8
- package/src/animation/node-animation-binding.ts +18 -1
- package/src/gltf/gltf/animations/animations.ts +8 -1
- package/src/gltf/gltf/create-scenegraph-from-gltf.ts +98 -17
- package/src/gltf/gltf/gltf-billboard.ts +6 -1
- package/src/gltf/gltf/gltf-extension-support.ts +2 -2
- package/src/gltf/index.ts +1 -0
- package/src/gltf/parsers/parse-gltf-animations.ts +22 -8
- package/src/gltf/parsers/parse-gltf-lights.ts +42 -130
- package/src/gltf/parsers/parse-gltf-metadata.ts +40 -0
- package/src/gltf/parsers/parse-gltf.ts +5 -0
- package/src/gltf/pbr/pbr-environment.ts +27 -1
- package/src/graph/models/path/path-attribute-model.ts +1 -1
- package/src/graph/models/path/path-storage-model.ts +1 -1
- package/src/index.ts +16 -0
- package/src/lighting/ambient-occlusion-pass.ts +130 -0
- package/src/lighting/clustered-light-grid.ts +481 -0
- package/src/lighting/contact-shadow-composite.ts +67 -0
- package/src/lighting/contact-shadow-pass.ts +107 -0
- package/src/lighting/index.ts +88 -0
- package/src/lighting/pbr-environment.ts +55 -0
- package/src/lighting/pbr-material.ts +85 -0
- package/src/lighting/pbr-model.ts +531 -0
- package/src/lighting/pbr-surface-pass.ts +122 -0
- package/src/lighting/prefiltered-environment.ts +354 -0
- package/src/lighting/shadow-map-renderer.ts +909 -0
- package/src/lighting/shadow-quality.ts +50 -0
- package/src/material/material.ts +3 -0
- package/src/model/gpu-vector-model.ts +18 -3
- package/src/scenegraph/controllers/punctual-light-controller.ts +172 -0
- package/src/scenegraph/scene-metadata.ts +23 -0
- package/src/scenegraph/scenegraph-interaction.ts +131 -0
- package/src/scenegraph/scenegraph-node.ts +12 -0
- package/src/text/fonts/atlas/text-utils.ts +1 -1
- package/src/text/text-2d/models/text-attribute-model.ts +1 -1
- package/src/text/text-2d/models/text-dictionary-model.ts +1 -1
- package/src/text/text-2d/models/text-storage-model.ts +1 -1
|
@@ -4,13 +4,46 @@
|
|
|
4
4
|
|
|
5
5
|
import {Matrix4} from '@math.gl/core';
|
|
6
6
|
import type {GLTFNodePostprocessed, GLTFPostprocessed} from '../types/gltf-postprocessed-schema';
|
|
7
|
+
import type {Light} from '@luma.gl/shaders';
|
|
7
8
|
import {
|
|
8
|
-
|
|
9
|
-
type
|
|
10
|
-
type
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
makePunctualLight,
|
|
10
|
+
type PunctualLightBinding,
|
|
11
|
+
type PunctualLightDefinition
|
|
12
|
+
} from '../../scenegraph/controllers/punctual-light-controller';
|
|
13
|
+
import type {ScenegraphNode} from '../../scenegraph/scenegraph-node';
|
|
14
|
+
|
|
15
|
+
/** Resolves source light references to paths of runtime nodes during import. */
|
|
16
|
+
export function bindGLTFPunctualLights(
|
|
17
|
+
nodes: GLTFNodePostprocessed[],
|
|
18
|
+
runtimeNodes: ReadonlyMap<string, ScenegraphNode>,
|
|
19
|
+
definitions: readonly PunctualLightDefinition[]
|
|
20
|
+
): PunctualLightBinding[] {
|
|
21
|
+
if (!definitions.length) return [];
|
|
22
|
+
const parents = createParentNodeMap(nodes);
|
|
23
|
+
const bindings: PunctualLightBinding[] = [];
|
|
24
|
+
for (const node of nodes) {
|
|
25
|
+
const lightIndex = getLightIndex(node);
|
|
26
|
+
const definition = lightIndex === undefined ? undefined : definitions[lightIndex];
|
|
27
|
+
if (!definition) continue;
|
|
28
|
+
const path: ScenegraphNode[] = [];
|
|
29
|
+
let source: GLTFNodePostprocessed | undefined = node;
|
|
30
|
+
while (source && path.length < nodes.length) {
|
|
31
|
+
const runtime = runtimeNodes.get(source.id);
|
|
32
|
+
if (!runtime) break;
|
|
33
|
+
path.push(runtime);
|
|
34
|
+
source = parents.get(source.id);
|
|
35
|
+
}
|
|
36
|
+
if (!source) bindings.push({path: path.reverse(), definition});
|
|
37
|
+
}
|
|
38
|
+
return bindings;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function getLightIndex(node: GLTFNodePostprocessed): number | undefined {
|
|
42
|
+
return (
|
|
43
|
+
(node as GLTFNodePostprocessed & {light?: number}).light ??
|
|
44
|
+
node.extensions?.['KHR_lights_punctual']?.light
|
|
45
|
+
);
|
|
46
|
+
}
|
|
14
47
|
|
|
15
48
|
export type ParseGLTFLightsOptions = {
|
|
16
49
|
/** Restricts authored lights to nodes belonging to the selected scene hierarchy. */
|
|
@@ -46,9 +79,7 @@ export function parseGLTFLights(
|
|
|
46
79
|
continue;
|
|
47
80
|
}
|
|
48
81
|
|
|
49
|
-
const lightIndex =
|
|
50
|
-
(node as GLTFNodePostprocessed & {light?: number}).light ??
|
|
51
|
-
node.extensions?.KHR_lights_punctual?.light;
|
|
82
|
+
const lightIndex = getLightIndex(node);
|
|
52
83
|
if (
|
|
53
84
|
typeof lightIndex !== 'number' ||
|
|
54
85
|
(options.nodeIdentifiers && !options.nodeIdentifiers.has(node.id))
|
|
@@ -62,28 +93,9 @@ export function parseGLTFLights(
|
|
|
62
93
|
continue;
|
|
63
94
|
}
|
|
64
95
|
|
|
65
|
-
const color = normalizeGLTFLightColor(
|
|
66
|
-
(gltfLight.color || [1, 1, 1]) as [number, number, number],
|
|
67
|
-
options.useByteColors ?? true
|
|
68
|
-
);
|
|
69
|
-
const intensity = gltfLight.intensity ?? 1;
|
|
70
|
-
const range = gltfLight.range;
|
|
71
96
|
const worldMatrix = getNodeWorldMatrix(node, parentNodeById, worldMatrixByNodeId);
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
case 'directional':
|
|
75
|
-
lights.push(parseDirectionalLight(worldMatrix, color, intensity));
|
|
76
|
-
break;
|
|
77
|
-
case 'point':
|
|
78
|
-
lights.push(parsePointLight(worldMatrix, color, intensity, range));
|
|
79
|
-
break;
|
|
80
|
-
case 'spot':
|
|
81
|
-
lights.push(parseSpotLight(worldMatrix, color, intensity, range, gltfLight.spot));
|
|
82
|
-
break;
|
|
83
|
-
default:
|
|
84
|
-
// Unsupported light type
|
|
85
|
-
break;
|
|
86
|
-
}
|
|
97
|
+
const light = makePunctualLight(gltfLight, worldMatrix, options.useByteColors ?? true);
|
|
98
|
+
if (light) lights.push(light);
|
|
87
99
|
}
|
|
88
100
|
|
|
89
101
|
return lights;
|
|
@@ -110,92 +122,6 @@ function isNodeVisible(
|
|
|
110
122
|
return true;
|
|
111
123
|
}
|
|
112
124
|
|
|
113
|
-
/**
|
|
114
|
-
* Converts glTF colors from the 0-1 spec range to the configured luma light convention.
|
|
115
|
-
*/
|
|
116
|
-
function normalizeGLTFLightColor(
|
|
117
|
-
color: [number, number, number],
|
|
118
|
-
useByteColors: boolean
|
|
119
|
-
): [number, number, number] {
|
|
120
|
-
if (useByteColors) {
|
|
121
|
-
return color.map(component => component * 255) as [number, number, number];
|
|
122
|
-
}
|
|
123
|
-
return normalizeByteColor3(color, false) as [number, number, number];
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* Converts a glTF punctual light attached to a node into a point light.
|
|
128
|
-
*/
|
|
129
|
-
function parsePointLight(
|
|
130
|
-
worldMatrix: Matrix4,
|
|
131
|
-
color: [number, number, number],
|
|
132
|
-
intensity: number,
|
|
133
|
-
range?: number
|
|
134
|
-
): PointLight {
|
|
135
|
-
const position = getLightPosition(worldMatrix);
|
|
136
|
-
|
|
137
|
-
let attenuation: Readonly<[number, number, number]> = [1, 0, 0];
|
|
138
|
-
if (range !== undefined && range > 0) {
|
|
139
|
-
attenuation = [1, 0, 1 / (range * range)] as [number, number, number];
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
return {
|
|
143
|
-
type: 'point',
|
|
144
|
-
position,
|
|
145
|
-
color,
|
|
146
|
-
intensity,
|
|
147
|
-
attenuation
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* Converts a glTF punctual light attached to a node into a directional light.
|
|
153
|
-
*/
|
|
154
|
-
function parseDirectionalLight(
|
|
155
|
-
worldMatrix: Matrix4,
|
|
156
|
-
color: [number, number, number],
|
|
157
|
-
intensity: number
|
|
158
|
-
): DirectionalLight {
|
|
159
|
-
const direction = getLightDirection(worldMatrix);
|
|
160
|
-
|
|
161
|
-
return {
|
|
162
|
-
type: 'directional',
|
|
163
|
-
direction,
|
|
164
|
-
color,
|
|
165
|
-
intensity
|
|
166
|
-
};
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
/**
|
|
170
|
-
* Converts a glTF punctual light attached to a node into a spot light.
|
|
171
|
-
*/
|
|
172
|
-
function parseSpotLight(
|
|
173
|
-
worldMatrix: Matrix4,
|
|
174
|
-
color: [number, number, number],
|
|
175
|
-
intensity: number,
|
|
176
|
-
range?: number,
|
|
177
|
-
spot: {innerConeAngle?: number; outerConeAngle?: number} = {}
|
|
178
|
-
): SpotLight {
|
|
179
|
-
const position = getLightPosition(worldMatrix);
|
|
180
|
-
const direction = getLightDirection(worldMatrix);
|
|
181
|
-
|
|
182
|
-
let attenuation: Readonly<[number, number, number]> = [1, 0, 0];
|
|
183
|
-
if (range !== undefined && range > 0) {
|
|
184
|
-
attenuation = [1, 0, 1 / (range * range)] as [number, number, number];
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
return {
|
|
188
|
-
type: 'spot',
|
|
189
|
-
position,
|
|
190
|
-
direction,
|
|
191
|
-
color,
|
|
192
|
-
intensity,
|
|
193
|
-
attenuation,
|
|
194
|
-
innerConeAngle: spot.innerConeAngle ?? 0,
|
|
195
|
-
outerConeAngle: spot.outerConeAngle ?? Math.PI / 4
|
|
196
|
-
};
|
|
197
|
-
}
|
|
198
|
-
|
|
199
125
|
/**
|
|
200
126
|
* Builds a parent lookup so punctual lights can be resolved in world space.
|
|
201
127
|
*/
|
|
@@ -260,17 +186,3 @@ function getNodeLocalMatrix(node: GLTFNodePostprocessed): Matrix4 {
|
|
|
260
186
|
|
|
261
187
|
return matrix;
|
|
262
188
|
}
|
|
263
|
-
|
|
264
|
-
/**
|
|
265
|
-
* Resolves the world-space position of a glTF light node.
|
|
266
|
-
*/
|
|
267
|
-
function getLightPosition(worldMatrix: Matrix4): [number, number, number] {
|
|
268
|
-
return worldMatrix.transformAsPoint([0, 0, 0]) as [number, number, number];
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
/**
|
|
272
|
-
* Resolves the world-space forward direction of a glTF light node.
|
|
273
|
-
*/
|
|
274
|
-
function getLightDirection(worldMatrix: Matrix4): [number, number, number] {
|
|
275
|
-
return worldMatrix.transformAsVector([0, 0, -1]) as [number, number, number];
|
|
276
|
-
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
import {SceneMetadata} from '@luma.gl/engine';
|
|
6
|
+
import type {GLTFPostprocessed} from '../types/gltf-postprocessed-schema';
|
|
7
|
+
|
|
8
|
+
/** Populates shared scene metadata from glTF XMP packet references. */
|
|
9
|
+
export function parseGLTFMetadata(gltf: GLTFPostprocessed): SceneMetadata {
|
|
10
|
+
const metadata = new SceneMetadata();
|
|
11
|
+
const rootExtension = gltf.extensions?.['KHR_xmp_json_ld'] as {packets?: unknown[]} | undefined;
|
|
12
|
+
const packets = rootExtension?.packets || [];
|
|
13
|
+
const categories: [string, readonly unknown[]][] = [
|
|
14
|
+
['asset', [gltf.asset]],
|
|
15
|
+
['scene', gltf.scenes || []],
|
|
16
|
+
['node', gltf.nodes || []],
|
|
17
|
+
['mesh', gltf.meshes || []],
|
|
18
|
+
['material', gltf.materials || []],
|
|
19
|
+
['image', gltf.images || []],
|
|
20
|
+
['animation', gltf.animations || []]
|
|
21
|
+
];
|
|
22
|
+
for (const [category, objects] of categories) {
|
|
23
|
+
objects.forEach((object, index) => {
|
|
24
|
+
const reference = (object as {extensions?: Record<string, {packet?: number}>} | undefined)
|
|
25
|
+
?.extensions?.['KHR_xmp_json_ld'];
|
|
26
|
+
if (!reference) return;
|
|
27
|
+
const packetIndex = reference.packet;
|
|
28
|
+
// A packet reference must point to an object in the document's packet array.
|
|
29
|
+
if (!Number.isInteger(packetIndex) || packetIndex! < 0 || packetIndex! >= packets.length) {
|
|
30
|
+
throw new Error(`glTF: invalid XMP packet index ${packetIndex}`);
|
|
31
|
+
}
|
|
32
|
+
const packet = packets[packetIndex!];
|
|
33
|
+
if (!packet || typeof packet !== 'object' || Array.isArray(packet)) {
|
|
34
|
+
throw new Error(`glTF: invalid XMP packet ${packetIndex}`);
|
|
35
|
+
}
|
|
36
|
+
metadata.set(category, index, packet as Record<string, unknown>);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
return metadata;
|
|
40
|
+
}
|
|
@@ -61,6 +61,8 @@ export type ParseGLTFOptions = {
|
|
|
61
61
|
useByteColors?: boolean;
|
|
62
62
|
/** Leave Gaussian primitives for a caller-managed splat renderer instead of creating mesh models. */
|
|
63
63
|
excludeGaussianSplatPrimitives?: boolean;
|
|
64
|
+
/** Resolve supported billboard attachments into an engine controller during scene creation. */
|
|
65
|
+
billboards?: {allowLegacyYAxis?: boolean} | null;
|
|
64
66
|
/** Reject documents whose required extensions have no complete runtime implementation. */
|
|
65
67
|
strictExtensions?: boolean;
|
|
66
68
|
};
|
|
@@ -75,6 +77,7 @@ type ParseGLTFInternalOptions = Required<ParseGLTFOptions> & {
|
|
|
75
77
|
|
|
76
78
|
const defaultOptions: Required<ParseGLTFOptions> = {
|
|
77
79
|
properties: null,
|
|
80
|
+
billboards: null,
|
|
78
81
|
publishedTransforms: null,
|
|
79
82
|
modelOptions: {},
|
|
80
83
|
pbrDebug: false,
|
|
@@ -302,6 +305,8 @@ function createNodeForGLTFNode(
|
|
|
302
305
|
children: [],
|
|
303
306
|
matrix: gltfNode.matrix,
|
|
304
307
|
display: gltfNode.extensions?.['KHR_node_visibility']?.visible !== false,
|
|
308
|
+
selectable: gltfNode.extensions?.['KHR_node_selectability']?.selectable !== false,
|
|
309
|
+
hoverable: gltfNode.extensions?.['KHR_node_hoverability']?.hoverable !== false,
|
|
305
310
|
position: gltfNode.translation,
|
|
306
311
|
rotation: gltfNode.rotation,
|
|
307
312
|
scale: gltfNode.scale
|
|
@@ -3,6 +3,11 @@
|
|
|
3
3
|
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
5
|
import {Device, SamplerProps} from '@luma.gl/core';
|
|
6
|
+
import {
|
|
7
|
+
getPBREnvironmentBindings,
|
|
8
|
+
type PBRLightingEnvironment,
|
|
9
|
+
type PBRLightingEnvironmentOptions
|
|
10
|
+
} from '../../lighting/pbr-environment';
|
|
6
11
|
import {
|
|
7
12
|
DynamicTexture,
|
|
8
13
|
type Texture2DData,
|
|
@@ -75,7 +80,8 @@ export function loadPBREnvironment(device: Device, props: PBREnvironmentProps):
|
|
|
75
80
|
sampler: {
|
|
76
81
|
addressModeU: 'clamp-to-edge',
|
|
77
82
|
addressModeV: 'clamp-to-edge',
|
|
78
|
-
minFilter: 'linear',
|
|
83
|
+
minFilter: 'linear',
|
|
84
|
+
mipmapFilter: 'linear',
|
|
79
85
|
magFilter: 'linear'
|
|
80
86
|
} as const satisfies SamplerProps
|
|
81
87
|
});
|
|
@@ -128,3 +134,23 @@ function makeCube(
|
|
|
128
134
|
data
|
|
129
135
|
});
|
|
130
136
|
}
|
|
137
|
+
|
|
138
|
+
/** Resolves a loaded environment into borrowed lighting resources after every upload completes. */
|
|
139
|
+
export async function resolveLoadedPBREnvironment(
|
|
140
|
+
environment: PBREnvironment,
|
|
141
|
+
options: PBRLightingEnvironmentOptions = {}
|
|
142
|
+
): Promise<PBRLightingEnvironment> {
|
|
143
|
+
await Promise.all([
|
|
144
|
+
environment.diffuseEnvSampler.ready,
|
|
145
|
+
environment.specularEnvSampler.ready,
|
|
146
|
+
environment.brdfLutTexture.ready
|
|
147
|
+
]);
|
|
148
|
+
const lightingEnvironment = {
|
|
149
|
+
diffuseTexture: environment.diffuseEnvSampler.texture,
|
|
150
|
+
specularTexture: environment.specularEnvSampler.texture,
|
|
151
|
+
brdfLUTTexture: environment.brdfLutTexture.texture,
|
|
152
|
+
...options
|
|
153
|
+
};
|
|
154
|
+
getPBREnvironmentBindings(lightingEnvironment);
|
|
155
|
+
return lightingEnvironment;
|
|
156
|
+
}
|
|
@@ -254,7 +254,7 @@ export class PathAttributeModel extends GPUTableModel {
|
|
|
254
254
|
/** Draws each generated path render batch against the supplied render pass. */
|
|
255
255
|
override draw(renderPass: RenderPass, options?: ModelDrawOptions): boolean {
|
|
256
256
|
return options?.parameters
|
|
257
|
-
?
|
|
257
|
+
? this._withDrawParameters(renderPass, options.parameters, () =>
|
|
258
258
|
this.drawPathAttributeModelBatches(renderPass)
|
|
259
259
|
)
|
|
260
260
|
: this.drawPathAttributeModelBatches(renderPass);
|
|
@@ -435,7 +435,7 @@ export class PathStorageModel extends Model {
|
|
|
435
435
|
/** Draws each generated storage path render batch against the supplied render pass. */
|
|
436
436
|
override draw(renderPass: RenderPass, options?: ModelDrawOptions): boolean {
|
|
437
437
|
return options?.parameters
|
|
438
|
-
?
|
|
438
|
+
? this._withDrawParameters(renderPass, options.parameters, () =>
|
|
439
439
|
this.drawPathStorageModelBatches(renderPass)
|
|
440
440
|
)
|
|
441
441
|
: this.drawPathStorageModelBatches(renderPass);
|
package/src/index.ts
CHANGED
|
@@ -79,6 +79,17 @@ export {DirectionalLightModel} from './models/directional-light-model';
|
|
|
79
79
|
|
|
80
80
|
// Scenegraph Core nodes
|
|
81
81
|
export {ScenegraphNode} from './scenegraph/scenegraph-node';
|
|
82
|
+
export {
|
|
83
|
+
isScenegraphInteractionEnabled,
|
|
84
|
+
getFirstScenegraphInteractionHit,
|
|
85
|
+
ScenegraphInteractionManager
|
|
86
|
+
} from './scenegraph/scenegraph-interaction';
|
|
87
|
+
export type {
|
|
88
|
+
ScenegraphInteractionKind,
|
|
89
|
+
ScenegraphInteractionHit,
|
|
90
|
+
ScenegraphInteractionEvent
|
|
91
|
+
} from './scenegraph/scenegraph-interaction';
|
|
92
|
+
export {SceneMetadata} from './scenegraph/scene-metadata';
|
|
82
93
|
export type {ScenegraphBounds} from './scenegraph/scenegraph-bounds';
|
|
83
94
|
export type {
|
|
84
95
|
DepthSortedTraversalContext,
|
|
@@ -238,6 +249,11 @@ export {
|
|
|
238
249
|
type BillboardDrawEntry,
|
|
239
250
|
type BillboardControllerProps
|
|
240
251
|
} from './scenegraph/controllers/billboard-controller';
|
|
252
|
+
export {
|
|
253
|
+
PunctualLightController,
|
|
254
|
+
type PunctualLightBinding,
|
|
255
|
+
type PunctualLightDefinition
|
|
256
|
+
} from './scenegraph/controllers/punctual-light-controller';
|
|
241
257
|
export {
|
|
242
258
|
AreaLightController,
|
|
243
259
|
type AreaLightDefinition,
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
3
|
+
|
|
4
|
+
import {assert, type Device, type Texture} from '@luma.gl/core';
|
|
5
|
+
import type {CompositeShaderPass} from '@luma.gl/shaders';
|
|
6
|
+
import {Matrix4, type NumberArray16} from '@math.gl/core';
|
|
7
|
+
import {ShaderPassRenderer} from '../passes/shader-pass-renderer';
|
|
8
|
+
import {ssaoEvaluate} from '../effects/passes/screen-space/ssao';
|
|
9
|
+
import {gtaoEvaluate} from '../effects/passes/screen-space/gtao';
|
|
10
|
+
import {depthAwareBlur} from '../effects/passes/screen-space/depth-aware-blur';
|
|
11
|
+
|
|
12
|
+
export type AmbientOcclusionMode = 'none' | 'ssao' | 'gtao';
|
|
13
|
+
export type AmbientOcclusionPassProps = {
|
|
14
|
+
mode?: AmbientOcclusionMode;
|
|
15
|
+
resolutionScale?: number;
|
|
16
|
+
};
|
|
17
|
+
export type AmbientOcclusionRenderOptions = {
|
|
18
|
+
depthTexture: Texture;
|
|
19
|
+
normalTexture: Texture;
|
|
20
|
+
projectionMatrix: Readonly<Matrix4 | NumberArray16>;
|
|
21
|
+
near: number;
|
|
22
|
+
far: number;
|
|
23
|
+
/** SSAO uses pixels; GTAO uses view-space scene units. */
|
|
24
|
+
radius?: number;
|
|
25
|
+
bias?: number;
|
|
26
|
+
intensity?: number;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/** Reuses the effects evaluators to produce ambient visibility, without color composition or history. */
|
|
30
|
+
export class AmbientOcclusionPass {
|
|
31
|
+
readonly device: Device;
|
|
32
|
+
readonly mode: AmbientOcclusionMode;
|
|
33
|
+
private readonly renderer: ShaderPassRenderer | null;
|
|
34
|
+
private readonly unoccluded: Texture;
|
|
35
|
+
private destroyed = false;
|
|
36
|
+
|
|
37
|
+
constructor(device: Device, props: AmbientOcclusionPassProps = {}) {
|
|
38
|
+
this.device = device;
|
|
39
|
+
this.mode = props.mode ?? 'gtao';
|
|
40
|
+
// Existing SSAO/GTAO evaluators support WebGPU. Callers can explicitly select none elsewhere.
|
|
41
|
+
assert(this.mode === 'none' || device.type === 'webgpu');
|
|
42
|
+
const scale = props.resolutionScale ?? 0.5;
|
|
43
|
+
// Resolution scale must describe a positive fractional input resolution.
|
|
44
|
+
assert(scale > 0 && scale <= 1);
|
|
45
|
+
this.unoccluded = device.createTexture({
|
|
46
|
+
width: 1,
|
|
47
|
+
height: 1,
|
|
48
|
+
data: new Uint8Array([255, 255, 255, 255])
|
|
49
|
+
});
|
|
50
|
+
if (this.mode === 'none') {
|
|
51
|
+
this.renderer = null;
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
const evaluate = this.mode === 'ssao' ? ssaoEvaluate : gtaoEvaluate;
|
|
55
|
+
const shaderPass: CompositeShaderPass<'ambientOcclusionRaw' | 'ambientOcclusionScratch'> = {
|
|
56
|
+
name: 'ambientOcclusionVisibility',
|
|
57
|
+
renderTargets: {
|
|
58
|
+
ambientOcclusionRaw: {scale: [scale, scale], format: 'rgba8unorm'},
|
|
59
|
+
ambientOcclusionScratch: {scale: [scale, scale], format: 'rgba8unorm'}
|
|
60
|
+
},
|
|
61
|
+
steps: [
|
|
62
|
+
{shaderPass: evaluate, inputs: {sourceTexture: 'original'}, output: 'ambientOcclusionRaw'},
|
|
63
|
+
{
|
|
64
|
+
shaderPass: depthAwareBlur,
|
|
65
|
+
inputs: {sourceTexture: 'ambientOcclusionRaw'},
|
|
66
|
+
output: 'ambientOcclusionScratch',
|
|
67
|
+
uniforms: {direction: [1, 0]}
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
shaderPass: depthAwareBlur,
|
|
71
|
+
inputs: {sourceTexture: 'ambientOcclusionScratch'},
|
|
72
|
+
output: 'previous',
|
|
73
|
+
uniforms: {direction: [0, 1]}
|
|
74
|
+
}
|
|
75
|
+
]
|
|
76
|
+
};
|
|
77
|
+
this.renderer = new ShaderPassRenderer(device, {
|
|
78
|
+
shaderPasses: [shaderPass],
|
|
79
|
+
colorFormat: 'rgba8unorm'
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** Borrows same-camera WebGPU hardware depth and encoded view normals; never submits. */
|
|
84
|
+
render(options: AmbientOcclusionRenderOptions): Texture {
|
|
85
|
+
// Even disabled passes must not be used after destruction.
|
|
86
|
+
assert(!this.destroyed);
|
|
87
|
+
if (!this.renderer) return this.unoccluded;
|
|
88
|
+
const {depthTexture, normalTexture} = options;
|
|
89
|
+
// Inputs must share the device and physical resolution.
|
|
90
|
+
assert(depthTexture.device === this.device && normalTexture.device === this.device);
|
|
91
|
+
assert(
|
|
92
|
+
depthTexture.width === normalTexture.width && depthTexture.height === normalTexture.height
|
|
93
|
+
);
|
|
94
|
+
const projectionMatrix = new Matrix4(options.projectionMatrix);
|
|
95
|
+
this.renderer.resize([normalTexture.width, normalTexture.height]);
|
|
96
|
+
const controls = {
|
|
97
|
+
...(options.radius === undefined ? {} : {radius: options.radius}),
|
|
98
|
+
...(options.bias === undefined ? {} : {bias: options.bias}),
|
|
99
|
+
...(options.intensity === undefined ? {} : {intensity: options.intensity})
|
|
100
|
+
};
|
|
101
|
+
const result = this.renderer.renderToTexture({
|
|
102
|
+
sourceTexture: normalTexture,
|
|
103
|
+
bindings: {depthTexture, normalTexture},
|
|
104
|
+
uniforms: {
|
|
105
|
+
ssaoEvaluate: {
|
|
106
|
+
...controls,
|
|
107
|
+
nearPlane: options.near,
|
|
108
|
+
farPlane: options.far,
|
|
109
|
+
useNormalTexture: 1
|
|
110
|
+
},
|
|
111
|
+
gtaoEvaluate: {
|
|
112
|
+
...controls,
|
|
113
|
+
projectionMatrix,
|
|
114
|
+
inverseProjectionMatrix: new Matrix4(projectionMatrix).invert(),
|
|
115
|
+
frameIndex: 0
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
// Concrete inputs always produce a texture; deferred uploads are not accepted.
|
|
120
|
+
assert(result);
|
|
121
|
+
return result;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
destroy(): void {
|
|
125
|
+
if (this.destroyed) return;
|
|
126
|
+
this.destroyed = true;
|
|
127
|
+
this.renderer?.destroy();
|
|
128
|
+
this.unoccluded.destroy();
|
|
129
|
+
}
|
|
130
|
+
}
|