@luma.gl/gltf 9.1.0-alpha.16 → 9.1.0-alpha.17
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 +53 -26
- package/dist/dist.min.js +5 -5
- package/dist/gltf/create-gltf-model.d.ts.map +1 -1
- package/dist/gltf/create-gltf-model.js +11 -6
- package/dist/gltf/gltf-instantiator.js +19 -1
- package/dist/index.cjs +47 -26
- package/dist/index.cjs.map +2 -2
- package/dist/pbr/parse-pbr-material.d.ts +4 -3
- package/dist/pbr/parse-pbr-material.d.ts.map +1 -1
- package/dist/pbr/parse-pbr-material.js +40 -40
- package/package.json +5 -5
- package/src/gltf/create-gltf-model.ts +13 -6
- package/src/gltf/gltf-instantiator.ts +20 -1
- package/src/pbr/parse-pbr-material.ts +50 -43
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@luma.gl/gltf",
|
|
3
|
-
"version": "9.1.0-alpha.
|
|
3
|
+
"version": "9.1.0-alpha.17",
|
|
4
4
|
"description": "glTF support for luma.gl",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -40,14 +40,14 @@
|
|
|
40
40
|
"prepublishOnly": "npm run build-minified-bundle && npm run build-dev-bundle"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
|
-
"@luma.gl/core": "9.1.0-alpha.
|
|
44
|
-
"@luma.gl/engine": "9.1.0-alpha.
|
|
45
|
-
"@luma.gl/shadertools": "9.1.0-alpha.
|
|
43
|
+
"@luma.gl/core": "9.1.0-alpha.16",
|
|
44
|
+
"@luma.gl/engine": "9.1.0-alpha.16",
|
|
45
|
+
"@luma.gl/shadertools": "9.1.0-alpha.16"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
48
|
"@loaders.gl/core": "^4.2.0",
|
|
49
49
|
"@loaders.gl/textures": "^4.2.0",
|
|
50
50
|
"@math.gl/core": "4.1.0-alpha.3"
|
|
51
51
|
},
|
|
52
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "a0d4d3ddc549bbfae6e43eebc8e1afdc4da1693c"
|
|
53
53
|
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
5
|
import {Device, RenderPipelineParameters, log} from '@luma.gl/core';
|
|
6
|
-
import {
|
|
6
|
+
import {pbrMaterial, ShaderModule} from '@luma.gl/shadertools';
|
|
7
7
|
import {Geometry, Model, ModelNode, ModelProps} from '@luma.gl/engine';
|
|
8
8
|
import {ParsePBRMaterialOptions, parsePBRMaterial} from '../pbr/parse-pbr-material';
|
|
9
9
|
|
|
@@ -94,7 +94,7 @@ const vs = /* glsl */ `\
|
|
|
94
94
|
#endif
|
|
95
95
|
|
|
96
96
|
pbr_setPositionNormalTangentUV(positions, _NORMAL, _TANGENT, _TEXCOORD_0);
|
|
97
|
-
gl_Position =
|
|
97
|
+
gl_Position = pbrProjection.modelViewProjectionMatrix * positions;
|
|
98
98
|
}
|
|
99
99
|
`;
|
|
100
100
|
|
|
@@ -145,15 +145,22 @@ export function createGLTFModel(device: Device, options: CreateGLTFModelOptions)
|
|
|
145
145
|
geometry,
|
|
146
146
|
topology: geometry.topology,
|
|
147
147
|
vertexCount,
|
|
148
|
-
modules: [
|
|
148
|
+
modules: [pbrMaterial as unknown as ShaderModule],
|
|
149
149
|
...modelOptions,
|
|
150
150
|
|
|
151
|
-
bindings: {...parsedMaterial.bindings, ...modelOptions.bindings},
|
|
152
151
|
defines: {...parsedMaterial.defines, ...modelOptions.defines},
|
|
153
|
-
parameters: {...parameters, ...parsedMaterial.parameters, ...modelOptions.parameters}
|
|
154
|
-
uniforms: {...parsedMaterial.uniforms, ...modelOptions.uniforms}
|
|
152
|
+
parameters: {...parameters, ...parsedMaterial.parameters, ...modelOptions.parameters}
|
|
155
153
|
};
|
|
156
154
|
|
|
157
155
|
const model = new Model(device, modelProps);
|
|
156
|
+
|
|
157
|
+
const {camera, ...pbrMaterialProps} = {
|
|
158
|
+
...parsedMaterial.uniforms,
|
|
159
|
+
...modelOptions.uniforms,
|
|
160
|
+
...parsedMaterial.bindings,
|
|
161
|
+
...modelOptions.bindings
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
model.shaderInputs.setProps({pbrMaterial: pbrMaterialProps, pbrProjection: {camera}});
|
|
158
165
|
return new ModelNode({managedResources, model});
|
|
159
166
|
}
|
|
@@ -42,7 +42,7 @@ export class GLTFInstantiator {
|
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
instantiate(gltf: any): GroupNode[] {
|
|
45
|
-
this.gltf = gltf;
|
|
45
|
+
this.gltf = deepCopy(gltf);
|
|
46
46
|
const scenes = (gltf.scenes || []).map(scene => this.createScene(scene));
|
|
47
47
|
return scenes;
|
|
48
48
|
}
|
|
@@ -204,3 +204,22 @@ export class GLTFInstantiator {
|
|
|
204
204
|
return false;
|
|
205
205
|
}
|
|
206
206
|
}
|
|
207
|
+
|
|
208
|
+
/** Deeply copies a JS data structure */
|
|
209
|
+
function deepCopy(object: any): any {
|
|
210
|
+
// don't copy binary data
|
|
211
|
+
if (ArrayBuffer.isView(object) || object instanceof ArrayBuffer) {
|
|
212
|
+
return object;
|
|
213
|
+
}
|
|
214
|
+
if (Array.isArray(object)) {
|
|
215
|
+
return object.map(deepCopy);
|
|
216
|
+
}
|
|
217
|
+
if (object && typeof object === 'object') {
|
|
218
|
+
const result = {};
|
|
219
|
+
for (const key in object) {
|
|
220
|
+
result[key] = deepCopy(object[key]);
|
|
221
|
+
}
|
|
222
|
+
return result;
|
|
223
|
+
}
|
|
224
|
+
return object;
|
|
225
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import type {Device, Texture,
|
|
1
|
+
import type {Device, Texture, Parameters} from '@luma.gl/core';
|
|
2
2
|
import {log} from '@luma.gl/core';
|
|
3
3
|
import {PBREnvironment} from './pbr-environment';
|
|
4
|
+
import {PBRMaterialBindings, PBRMaterialUniforms, PBRProjectionProps} from '@luma.gl/shadertools';
|
|
4
5
|
|
|
5
6
|
/* eslint-disable camelcase */
|
|
6
7
|
|
|
@@ -17,8 +18,8 @@ export type ParsePBRMaterialOptions = {
|
|
|
17
18
|
|
|
18
19
|
export type ParsedPBRMaterial = {
|
|
19
20
|
readonly defines: Record<string, number | boolean>;
|
|
20
|
-
readonly bindings:
|
|
21
|
-
readonly uniforms:
|
|
21
|
+
readonly bindings: Partial<PBRMaterialBindings>;
|
|
22
|
+
readonly uniforms: Partial<PBRProjectionProps & PBRMaterialUniforms>;
|
|
22
23
|
readonly parameters: Parameters;
|
|
23
24
|
readonly glParameters: Record<string, any>;
|
|
24
25
|
/** List of all generated textures, makes it easy to destroy them later */
|
|
@@ -58,9 +59,9 @@ export function parsePBRMaterial(
|
|
|
58
59
|
bindings: {},
|
|
59
60
|
uniforms: {
|
|
60
61
|
// TODO: find better values?
|
|
61
|
-
|
|
62
|
+
camera: [0, 0, 0], // Model should override
|
|
62
63
|
|
|
63
|
-
|
|
64
|
+
metallicRoughnessValues: [1, 1] // Default is 1 and 1
|
|
64
65
|
},
|
|
65
66
|
parameters: {},
|
|
66
67
|
glParameters: {},
|
|
@@ -72,19 +73,19 @@ export function parsePBRMaterial(
|
|
|
72
73
|
|
|
73
74
|
const {imageBasedLightingEnvironment} = options;
|
|
74
75
|
if (imageBasedLightingEnvironment) {
|
|
75
|
-
parsedMaterial.bindings.
|
|
76
|
+
parsedMaterial.bindings.pbr_diffuseEnvSampler =
|
|
76
77
|
imageBasedLightingEnvironment.diffuseEnvSampler.texture;
|
|
77
|
-
parsedMaterial.bindings.
|
|
78
|
+
parsedMaterial.bindings.pbr_specularEnvSampler =
|
|
78
79
|
imageBasedLightingEnvironment.specularEnvSampler.texture;
|
|
79
|
-
parsedMaterial.bindings.
|
|
80
|
-
parsedMaterial.uniforms.
|
|
80
|
+
parsedMaterial.bindings.pbr_BrdfLUT = imageBasedLightingEnvironment.brdfLutTexture.texture;
|
|
81
|
+
parsedMaterial.uniforms.scaleIBLAmbient = [1, 1];
|
|
81
82
|
}
|
|
82
83
|
|
|
83
84
|
if (options?.pbrDebug) {
|
|
84
85
|
parsedMaterial.defines.PBR_DEBUG = 1;
|
|
85
86
|
// Override final color for reference app visualization of various parameters in the lighting equation.
|
|
86
|
-
parsedMaterial.uniforms.
|
|
87
|
-
parsedMaterial.uniforms.
|
|
87
|
+
parsedMaterial.uniforms.scaleDiffBaseMR = [0, 0, 0, 0];
|
|
88
|
+
parsedMaterial.uniforms.scaleFGDSpec = [0, 0, 0, 0];
|
|
88
89
|
}
|
|
89
90
|
|
|
90
91
|
if (attributes.NORMAL) parsedMaterial.defines.HAS_NORMALS = 1;
|
|
@@ -103,45 +104,51 @@ export function parsePBRMaterial(
|
|
|
103
104
|
|
|
104
105
|
/** Parse GLTF material record */
|
|
105
106
|
function parseMaterial(device: Device, material, parsedMaterial: ParsedPBRMaterial): void {
|
|
106
|
-
parsedMaterial.uniforms.
|
|
107
|
+
parsedMaterial.uniforms.unlit = Boolean(material.unlit);
|
|
107
108
|
|
|
108
109
|
if (material.pbrMetallicRoughness) {
|
|
109
110
|
parsePbrMetallicRoughness(device, material.pbrMetallicRoughness, parsedMaterial);
|
|
110
111
|
}
|
|
111
112
|
if (material.normalTexture) {
|
|
112
|
-
addTexture(
|
|
113
|
+
addTexture(
|
|
114
|
+
device,
|
|
115
|
+
material.normalTexture,
|
|
116
|
+
'pbr_normalSampler',
|
|
117
|
+
'HAS_NORMALMAP',
|
|
118
|
+
parsedMaterial
|
|
119
|
+
);
|
|
113
120
|
|
|
114
121
|
const {scale = 1} = material.normalTexture;
|
|
115
|
-
parsedMaterial.uniforms.
|
|
122
|
+
parsedMaterial.uniforms.normalScale = scale;
|
|
116
123
|
}
|
|
117
124
|
if (material.occlusionTexture) {
|
|
118
125
|
addTexture(
|
|
119
126
|
device,
|
|
120
127
|
material.occlusionTexture,
|
|
121
|
-
'
|
|
128
|
+
'pbr_occlusionSampler',
|
|
122
129
|
'HAS_OCCLUSIONMAP',
|
|
123
130
|
parsedMaterial
|
|
124
131
|
);
|
|
125
132
|
|
|
126
133
|
const {strength = 1} = material.occlusionTexture;
|
|
127
|
-
parsedMaterial.uniforms.
|
|
134
|
+
parsedMaterial.uniforms.occlusionStrength = strength;
|
|
128
135
|
}
|
|
129
136
|
if (material.emissiveTexture) {
|
|
130
137
|
addTexture(
|
|
131
138
|
device,
|
|
132
139
|
material.emissiveTexture,
|
|
133
|
-
'
|
|
140
|
+
'pbr_emissiveSampler',
|
|
134
141
|
'HAS_EMISSIVEMAP',
|
|
135
142
|
parsedMaterial
|
|
136
143
|
);
|
|
137
|
-
parsedMaterial.uniforms.
|
|
144
|
+
parsedMaterial.uniforms.emissiveFactor = material.emissiveFactor || [0, 0, 0];
|
|
138
145
|
}
|
|
139
146
|
|
|
140
147
|
switch (material.alphaMode) {
|
|
141
148
|
case 'MASK':
|
|
142
149
|
const {alphaCutoff = 0.5} = material;
|
|
143
150
|
parsedMaterial.defines.ALPHA_CUTOFF = 1;
|
|
144
|
-
parsedMaterial.uniforms.
|
|
151
|
+
parsedMaterial.uniforms.alphaCutoff = alphaCutoff;
|
|
145
152
|
break;
|
|
146
153
|
case 'BLEND':
|
|
147
154
|
log.warn('glTF BLEND alphaMode might not work well because it requires mesh sorting')();
|
|
@@ -179,24 +186,24 @@ function parsePbrMetallicRoughness(
|
|
|
179
186
|
addTexture(
|
|
180
187
|
device,
|
|
181
188
|
pbrMetallicRoughness.baseColorTexture,
|
|
182
|
-
'
|
|
189
|
+
'pbr_baseColorSampler',
|
|
183
190
|
'HAS_BASECOLORMAP',
|
|
184
191
|
parsedMaterial
|
|
185
192
|
);
|
|
186
193
|
}
|
|
187
|
-
parsedMaterial.uniforms.
|
|
194
|
+
parsedMaterial.uniforms.baseColorFactor = pbrMetallicRoughness.baseColorFactor || [1, 1, 1, 1];
|
|
188
195
|
|
|
189
196
|
if (pbrMetallicRoughness.metallicRoughnessTexture) {
|
|
190
197
|
addTexture(
|
|
191
198
|
device,
|
|
192
199
|
pbrMetallicRoughness.metallicRoughnessTexture,
|
|
193
|
-
'
|
|
200
|
+
'pbr_metallicRoughnessSampler',
|
|
194
201
|
'HAS_METALROUGHNESSMAP',
|
|
195
202
|
parsedMaterial
|
|
196
203
|
);
|
|
197
204
|
}
|
|
198
205
|
const {metallicFactor = 1, roughnessFactor = 1} = pbrMetallicRoughness;
|
|
199
|
-
parsedMaterial.uniforms.
|
|
206
|
+
parsedMaterial.uniforms.metallicRoughnessValues = [metallicFactor, roughnessFactor];
|
|
200
207
|
}
|
|
201
208
|
|
|
202
209
|
/** Create a texture from a glTF texture/sampler/image combo and add it to bindings */
|
|
@@ -271,9 +278,9 @@ export class PBRMaterialParser {
|
|
|
271
278
|
|
|
272
279
|
this.uniforms = {
|
|
273
280
|
// TODO: find better values?
|
|
274
|
-
|
|
281
|
+
camera: [0, 0, 0], // Model should override
|
|
275
282
|
|
|
276
|
-
|
|
283
|
+
metallicRoughnessValues: [1, 1] // Default is 1 and 1
|
|
277
284
|
};
|
|
278
285
|
|
|
279
286
|
this.bindings = {};
|
|
@@ -282,17 +289,17 @@ export class PBRMaterialParser {
|
|
|
282
289
|
this.generatedTextures = [];
|
|
283
290
|
|
|
284
291
|
if (imageBasedLightingEnvironment) {
|
|
285
|
-
this.bindings.
|
|
286
|
-
this.bindings.
|
|
287
|
-
this.bindings.
|
|
288
|
-
this.uniforms.
|
|
292
|
+
this.bindings.pbr_diffuseEnvSampler = imageBasedLightingEnvironment.getDiffuseEnvSampler();
|
|
293
|
+
this.bindings.pbr_specularEnvSampler = imageBasedLightingEnvironment.getSpecularEnvSampler();
|
|
294
|
+
this.bindings.pbr_BrdfLUT = imageBasedLightingEnvironment.getBrdfTexture();
|
|
295
|
+
this.uniforms.scaleIBLAmbient = [1, 1];
|
|
289
296
|
}
|
|
290
297
|
|
|
291
298
|
if (pbrDebug) {
|
|
292
299
|
// Override final color for reference app visualization
|
|
293
300
|
// of various parameters in the lighting equation.
|
|
294
|
-
this.uniforms.
|
|
295
|
-
this.uniforms.
|
|
301
|
+
this.uniforms.scaleDiffBaseMR = [0, 0, 0, 0];
|
|
302
|
+
this.uniforms.scaleFGDSpec = [0, 0, 0, 0];
|
|
296
303
|
}
|
|
297
304
|
|
|
298
305
|
this.defineIfPresent(attributes.NORMAL, 'HAS_NORMALS');
|
|
@@ -324,31 +331,31 @@ export class PBRMaterialParser {
|
|
|
324
331
|
|
|
325
332
|
/** Parse GLTF material record *
|
|
326
333
|
parseMaterial(material) {
|
|
327
|
-
this.uniforms.
|
|
334
|
+
this.uniforms.unlit = Boolean(material.unlit);
|
|
328
335
|
|
|
329
336
|
if (material.pbrMetallicRoughness) {
|
|
330
337
|
this.parsePbrMetallicRoughness(material.pbrMetallicRoughness);
|
|
331
338
|
}
|
|
332
339
|
if (material.normalTexture) {
|
|
333
|
-
this.addTexture(material.normalTexture, '
|
|
340
|
+
this.addTexture(material.normalTexture, 'pbr_normalSampler', 'HAS_NORMALMAP');
|
|
334
341
|
|
|
335
342
|
const {scale = 1} = material.normalTexture;
|
|
336
|
-
this.uniforms.
|
|
343
|
+
this.uniforms.normalScale = scale;
|
|
337
344
|
}
|
|
338
345
|
if (material.occlusionTexture) {
|
|
339
|
-
this.addTexture(material.occlusionTexture, '
|
|
346
|
+
this.addTexture(material.occlusionTexture, 'pbr_occlusionSampler', 'HAS_OCCLUSIONMAP');
|
|
340
347
|
|
|
341
348
|
const {strength = 1} = material.occlusionTexture;
|
|
342
|
-
this.uniforms.
|
|
349
|
+
this.uniforms.occlusionStrength = strength;
|
|
343
350
|
}
|
|
344
351
|
if (material.emissiveTexture) {
|
|
345
|
-
this.addTexture(material.emissiveTexture, '
|
|
346
|
-
this.uniforms.
|
|
352
|
+
this.addTexture(material.emissiveTexture, 'pbr_emissiveSampler', 'HAS_EMISSIVEMAP');
|
|
353
|
+
this.uniforms.emissiveFactor = material.emissiveFactor || [0, 0, 0];
|
|
347
354
|
}
|
|
348
355
|
if (material.alphaMode === 'MASK') {
|
|
349
356
|
const {alphaCutoff = 0.5} = material;
|
|
350
357
|
this.defines.ALPHA_CUTOFF = 1;
|
|
351
|
-
this.uniforms.
|
|
358
|
+
this.uniforms.alphaCutoff = alphaCutoff;
|
|
352
359
|
} else if (material.alphaMode === 'BLEND') {
|
|
353
360
|
log.warn('BLEND alphaMode might not work well because it requires mesh sorting')();
|
|
354
361
|
Object.assign(this.parameters, {
|
|
@@ -364,21 +371,21 @@ export class PBRMaterialParser {
|
|
|
364
371
|
if (pbrMetallicRoughness.baseColorTexture) {
|
|
365
372
|
this.addTexture(
|
|
366
373
|
pbrMetallicRoughness.baseColorTexture,
|
|
367
|
-
'
|
|
374
|
+
'pbr_baseColorSampler',
|
|
368
375
|
'HAS_BASECOLORMAP'
|
|
369
376
|
);
|
|
370
377
|
}
|
|
371
|
-
this.uniforms.
|
|
378
|
+
this.uniforms.baseColorFactor = pbrMetallicRoughness.baseColorFactor || [1, 1, 1, 1];
|
|
372
379
|
|
|
373
380
|
if (pbrMetallicRoughness.metallicRoughnessTexture) {
|
|
374
381
|
this.addTexture(
|
|
375
382
|
pbrMetallicRoughness.metallicRoughnessTexture,
|
|
376
|
-
'
|
|
383
|
+
'pbr_metallicRoughnessSampler',
|
|
377
384
|
'HAS_METALROUGHNESSMAP'
|
|
378
385
|
);
|
|
379
386
|
}
|
|
380
387
|
const {metallicFactor = 1, roughnessFactor = 1} = pbrMetallicRoughness;
|
|
381
|
-
this.uniforms.
|
|
388
|
+
this.uniforms.metallicRoughnessValues = [metallicFactor, roughnessFactor];
|
|
382
389
|
}
|
|
383
390
|
|
|
384
391
|
/** Create a texture from a glTF texture/sampler/image combo and add it to bindings *
|