@luma.gl/gltf 9.3.0-alpha.6 → 9.3.0-alpha.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dist.dev.js +942 -141
- package/dist/dist.min.js +4 -4
- package/dist/gltf/create-gltf-model.d.ts +9 -1
- package/dist/gltf/create-gltf-model.d.ts.map +1 -1
- package/dist/gltf/create-gltf-model.js +58 -4
- package/dist/gltf/create-gltf-model.js.map +1 -1
- package/dist/gltf/create-scenegraph-from-gltf.d.ts +22 -1
- package/dist/gltf/create-scenegraph-from-gltf.d.ts.map +1 -1
- package/dist/gltf/create-scenegraph-from-gltf.js +63 -1
- package/dist/gltf/create-scenegraph-from-gltf.js.map +1 -1
- package/dist/gltf/gltf-extension-support.d.ts +10 -0
- package/dist/gltf/gltf-extension-support.d.ts.map +1 -0
- package/dist/gltf/gltf-extension-support.js +173 -0
- package/dist/gltf/gltf-extension-support.js.map +1 -0
- package/dist/index.cjs +899 -114
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/parsers/parse-gltf-animations.d.ts.map +1 -1
- package/dist/parsers/parse-gltf-animations.js +34 -12
- package/dist/parsers/parse-gltf-animations.js.map +1 -1
- package/dist/parsers/parse-gltf-lights.d.ts.map +1 -1
- package/dist/parsers/parse-gltf-lights.js +86 -20
- package/dist/parsers/parse-gltf-lights.js.map +1 -1
- package/dist/parsers/parse-gltf.d.ts +3 -1
- package/dist/parsers/parse-gltf.d.ts.map +1 -1
- package/dist/parsers/parse-gltf.js +41 -9
- package/dist/parsers/parse-gltf.js.map +1 -1
- package/dist/parsers/parse-pbr-material.d.ts +69 -1
- package/dist/parsers/parse-pbr-material.d.ts.map +1 -1
- package/dist/parsers/parse-pbr-material.js +429 -42
- package/dist/parsers/parse-pbr-material.js.map +1 -1
- package/dist/pbr/pbr-environment.d.ts.map +1 -1
- package/dist/pbr/pbr-environment.js +14 -12
- package/dist/pbr/pbr-environment.js.map +1 -1
- package/dist/pbr/pbr-material.d.ts +8 -3
- package/dist/pbr/pbr-material.d.ts.map +1 -1
- package/dist/webgl-to-webgpu/convert-webgl-sampler.d.ts +5 -5
- package/dist/webgl-to-webgpu/convert-webgl-sampler.d.ts.map +1 -1
- package/dist/webgl-to-webgpu/convert-webgl-sampler.js +12 -12
- package/dist/webgl-to-webgpu/convert-webgl-sampler.js.map +1 -1
- package/dist/webgl-to-webgpu/convert-webgl-topology.d.ts +1 -10
- package/dist/webgl-to-webgpu/convert-webgl-topology.d.ts.map +1 -1
- package/dist/webgl-to-webgpu/convert-webgl-topology.js +1 -15
- package/dist/webgl-to-webgpu/convert-webgl-topology.js.map +1 -1
- package/dist/webgl-to-webgpu/gltf-webgl-constants.d.ts +27 -0
- package/dist/webgl-to-webgpu/gltf-webgl-constants.d.ts.map +1 -0
- package/dist/webgl-to-webgpu/gltf-webgl-constants.js +34 -0
- package/dist/webgl-to-webgpu/gltf-webgl-constants.js.map +1 -0
- package/package.json +5 -6
- package/src/gltf/create-gltf-model.ts +113 -5
- package/src/gltf/create-scenegraph-from-gltf.ts +97 -6
- package/src/gltf/gltf-extension-support.ts +214 -0
- package/src/index.ts +10 -1
- package/src/parsers/parse-gltf-animations.ts +39 -15
- package/src/parsers/parse-gltf-lights.ts +114 -25
- package/src/parsers/parse-gltf.ts +86 -19
- package/src/parsers/parse-pbr-material.ts +664 -69
- package/src/pbr/pbr-environment.ts +29 -16
- package/src/pbr/pbr-material.ts +13 -3
- package/src/webgl-to-webgpu/convert-webgl-sampler.ts +29 -29
- package/src/webgl-to-webgpu/convert-webgl-topology.ts +1 -15
- package/src/webgl-to-webgpu/gltf-webgl-constants.ts +35 -0
|
@@ -3,16 +3,26 @@
|
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
5
|
import {Device, type PrimitiveTopology} from '@luma.gl/core';
|
|
6
|
-
import {Geometry, GeometryAttribute, GroupNode, ModelNode, type ModelProps} from '@luma.gl/engine';
|
|
7
6
|
import {
|
|
7
|
+
Geometry,
|
|
8
|
+
GeometryAttribute,
|
|
9
|
+
GroupNode,
|
|
10
|
+
Material,
|
|
11
|
+
MaterialFactory,
|
|
12
|
+
ModelNode,
|
|
13
|
+
type ModelProps
|
|
14
|
+
} from '@luma.gl/engine';
|
|
15
|
+
import {
|
|
16
|
+
type GLTFMaterialPostprocessed,
|
|
8
17
|
type GLTFMeshPostprocessed,
|
|
9
18
|
type GLTFNodePostprocessed,
|
|
10
19
|
type GLTFPostprocessed
|
|
11
20
|
} from '@loaders.gl/gltf';
|
|
21
|
+
import {pbrMaterial} from '@luma.gl/shadertools';
|
|
12
22
|
|
|
13
23
|
import {type PBREnvironment} from '../pbr/pbr-environment';
|
|
14
24
|
import {convertGLDrawModeToTopology} from '../webgl-to-webgpu/convert-webgl-topology';
|
|
15
|
-
import {createGLTFModel} from '../gltf/create-gltf-model';
|
|
25
|
+
import {createGLTFMaterial, createGLTFModel} from '../gltf/create-gltf-model';
|
|
16
26
|
|
|
17
27
|
import {parsePBRMaterial} from './parse-pbr-material';
|
|
18
28
|
|
|
@@ -49,6 +59,8 @@ export function parseGLTF(
|
|
|
49
59
|
): {
|
|
50
60
|
/** Scene roots generated from `gltf.scenes`. */
|
|
51
61
|
scenes: GroupNode[];
|
|
62
|
+
/** Materials aligned with the source `gltf.materials` array. */
|
|
63
|
+
materials: Material[];
|
|
52
64
|
/** Map from glTF mesh ids to generated mesh group nodes. */
|
|
53
65
|
gltfMeshIdToNodeMap: Map<string, GroupNode>;
|
|
54
66
|
/** Map from glTF node indices to generated scenegraph nodes. */
|
|
@@ -57,10 +69,37 @@ export function parseGLTF(
|
|
|
57
69
|
gltfNodeIdToNodeMap: Map<string, GroupNode>;
|
|
58
70
|
} {
|
|
59
71
|
const combinedOptions = {...defaultOptions, ...options};
|
|
72
|
+
const materialFactory = new MaterialFactory(device, {modules: [pbrMaterial]});
|
|
73
|
+
const materials = (gltf.materials || []).map((gltfMaterial, materialIndex) =>
|
|
74
|
+
createGLTFMaterial(device, {
|
|
75
|
+
id: getGLTFMaterialId(gltfMaterial, materialIndex),
|
|
76
|
+
parsedPPBRMaterial: parsePBRMaterial(
|
|
77
|
+
device,
|
|
78
|
+
gltfMaterial as any,
|
|
79
|
+
{},
|
|
80
|
+
{
|
|
81
|
+
...combinedOptions,
|
|
82
|
+
gltf,
|
|
83
|
+
validateAttributes: false
|
|
84
|
+
}
|
|
85
|
+
),
|
|
86
|
+
materialFactory
|
|
87
|
+
})
|
|
88
|
+
);
|
|
89
|
+
const gltfMaterialIdToMaterialMap = new Map<string, Material>();
|
|
90
|
+
(gltf.materials || []).forEach((gltfMaterial, materialIndex) => {
|
|
91
|
+
gltfMaterialIdToMaterialMap.set(gltfMaterial.id, materials[materialIndex]);
|
|
92
|
+
});
|
|
60
93
|
|
|
61
94
|
const gltfMeshIdToNodeMap = new Map<string, GroupNode>();
|
|
62
95
|
gltf.meshes.forEach((gltfMesh, idx) => {
|
|
63
|
-
const newMesh = createNodeForGLTFMesh(
|
|
96
|
+
const newMesh = createNodeForGLTFMesh(
|
|
97
|
+
device,
|
|
98
|
+
gltfMesh,
|
|
99
|
+
gltf,
|
|
100
|
+
gltfMaterialIdToMaterialMap,
|
|
101
|
+
combinedOptions
|
|
102
|
+
);
|
|
64
103
|
gltfMeshIdToNodeMap.set(gltfMesh.id, newMesh);
|
|
65
104
|
});
|
|
66
105
|
|
|
@@ -107,7 +146,7 @@ export function parseGLTF(
|
|
|
107
146
|
});
|
|
108
147
|
});
|
|
109
148
|
|
|
110
|
-
return {scenes, gltfMeshIdToNodeMap, gltfNodeIdToNodeMap, gltfNodeIndexToNodeMap};
|
|
149
|
+
return {scenes, materials, gltfMeshIdToNodeMap, gltfNodeIdToNodeMap, gltfNodeIndexToNodeMap};
|
|
111
150
|
}
|
|
112
151
|
|
|
113
152
|
/** Creates a `GroupNode` for one glTF node transform. */
|
|
@@ -130,11 +169,21 @@ function createNodeForGLTFNode(
|
|
|
130
169
|
function createNodeForGLTFMesh(
|
|
131
170
|
device: Device,
|
|
132
171
|
gltfMesh: GLTFMeshPostprocessed,
|
|
172
|
+
gltf: GLTFPostprocessed,
|
|
173
|
+
gltfMaterialIdToMaterialMap: Map<string, Material>,
|
|
133
174
|
options: Required<ParseGLTFOptions>
|
|
134
175
|
): GroupNode {
|
|
135
176
|
const gltfPrimitives = gltfMesh.primitives || [];
|
|
136
177
|
const primitives = gltfPrimitives.map((gltfPrimitive, i) =>
|
|
137
|
-
createNodeForGLTFPrimitive(
|
|
178
|
+
createNodeForGLTFPrimitive({
|
|
179
|
+
device,
|
|
180
|
+
gltfPrimitive,
|
|
181
|
+
primitiveIndex: i,
|
|
182
|
+
gltfMesh,
|
|
183
|
+
gltf,
|
|
184
|
+
gltfMaterialIdToMaterialMap,
|
|
185
|
+
options
|
|
186
|
+
})
|
|
138
187
|
);
|
|
139
188
|
const mesh = new GroupNode({
|
|
140
189
|
id: gltfMesh.name || gltfMesh.id,
|
|
@@ -144,15 +193,28 @@ function createNodeForGLTFMesh(
|
|
|
144
193
|
return mesh;
|
|
145
194
|
}
|
|
146
195
|
|
|
196
|
+
/** Input options for creating one renderable glTF primitive model node. */
|
|
197
|
+
type CreateNodeForGLTFPrimitiveOptions = {
|
|
198
|
+
device: Device;
|
|
199
|
+
gltfPrimitive: any;
|
|
200
|
+
primitiveIndex: number;
|
|
201
|
+
gltfMesh: GLTFMeshPostprocessed;
|
|
202
|
+
gltf: GLTFPostprocessed;
|
|
203
|
+
gltfMaterialIdToMaterialMap: Map<string, Material>;
|
|
204
|
+
options: Required<ParseGLTFOptions>;
|
|
205
|
+
};
|
|
206
|
+
|
|
147
207
|
/** Creates a renderable model node for one glTF primitive. */
|
|
148
|
-
function createNodeForGLTFPrimitive(
|
|
149
|
-
device
|
|
150
|
-
gltfPrimitive
|
|
151
|
-
|
|
152
|
-
gltfMesh
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
208
|
+
function createNodeForGLTFPrimitive({
|
|
209
|
+
device,
|
|
210
|
+
gltfPrimitive,
|
|
211
|
+
primitiveIndex,
|
|
212
|
+
gltfMesh,
|
|
213
|
+
gltf,
|
|
214
|
+
gltfMaterialIdToMaterialMap,
|
|
215
|
+
options
|
|
216
|
+
}: CreateNodeForGLTFPrimitiveOptions): ModelNode {
|
|
217
|
+
const id = gltfPrimitive.name || `${gltfMesh.name || gltfMesh.id}-primitive-${primitiveIndex}`;
|
|
156
218
|
const topology = convertGLDrawModeToTopology(gltfPrimitive.mode || 4);
|
|
157
219
|
const vertexCount = gltfPrimitive.indices
|
|
158
220
|
? gltfPrimitive.indices.count
|
|
@@ -160,16 +222,17 @@ function createNodeForGLTFPrimitive(
|
|
|
160
222
|
|
|
161
223
|
const geometry = createGeometry(id, gltfPrimitive, topology);
|
|
162
224
|
|
|
163
|
-
const parsedPPBRMaterial = parsePBRMaterial(
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
options
|
|
168
|
-
);
|
|
225
|
+
const parsedPPBRMaterial = parsePBRMaterial(device, gltfPrimitive.material, geometry.attributes, {
|
|
226
|
+
...options,
|
|
227
|
+
gltf
|
|
228
|
+
});
|
|
169
229
|
|
|
170
230
|
const modelNode = createGLTFModel(device, {
|
|
171
231
|
id,
|
|
172
232
|
geometry: createGeometry(id, gltfPrimitive, topology),
|
|
233
|
+
material: gltfPrimitive.material
|
|
234
|
+
? gltfMaterialIdToMaterialMap.get(gltfPrimitive.material.id) || null
|
|
235
|
+
: null,
|
|
173
236
|
parsedPPBRMaterial,
|
|
174
237
|
modelOptions: options.modelOptions,
|
|
175
238
|
vertexCount
|
|
@@ -203,3 +266,7 @@ function createGeometry(id: string, gltfPrimitive: any, topology: PrimitiveTopol
|
|
|
203
266
|
attributes
|
|
204
267
|
});
|
|
205
268
|
}
|
|
269
|
+
|
|
270
|
+
function getGLTFMaterialId(gltfMaterial: GLTFMaterialPostprocessed, materialIndex: number): string {
|
|
271
|
+
return gltfMaterial.name || gltfMaterial.id || `material-${materialIndex}`;
|
|
272
|
+
}
|