@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,7 +3,12 @@
|
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
5
|
import {Device, SamplerProps} from '@luma.gl/core';
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
DynamicTexture,
|
|
8
|
+
type Texture2DData,
|
|
9
|
+
type TextureCubeData,
|
|
10
|
+
type TextureCubeFace
|
|
11
|
+
} from '@luma.gl/engine';
|
|
7
12
|
import {loadImageTexture} from '@loaders.gl/textures';
|
|
8
13
|
|
|
9
14
|
/** Environment textures for PBR module */
|
|
@@ -28,6 +33,8 @@ export type PBREnvironmentProps = {
|
|
|
28
33
|
|
|
29
34
|
/** Loads textures for PBR environment */
|
|
30
35
|
export function loadPBREnvironment(device: Device, props: PBREnvironmentProps): PBREnvironment {
|
|
36
|
+
const specularMipLevels = props.specularMipLevels ?? 1;
|
|
37
|
+
|
|
31
38
|
const brdfLutTexture = new DynamicTexture(device, {
|
|
32
39
|
id: 'brdfLUT',
|
|
33
40
|
sampler: {
|
|
@@ -42,7 +49,10 @@ export function loadPBREnvironment(device: Device, props: PBREnvironmentProps):
|
|
|
42
49
|
|
|
43
50
|
const diffuseEnvSampler = makeCube(device, {
|
|
44
51
|
id: 'DiffuseEnvSampler',
|
|
45
|
-
getTextureForFace:
|
|
52
|
+
getTextureForFace: face =>
|
|
53
|
+
loadImageTexture(
|
|
54
|
+
props.getTexUrl('diffuse', FACES.indexOf(face), 0)
|
|
55
|
+
) as Promise<Texture2DData>,
|
|
46
56
|
sampler: {
|
|
47
57
|
addressModeU: 'clamp-to-edge',
|
|
48
58
|
addressModeV: 'clamp-to-edge',
|
|
@@ -53,13 +63,13 @@ export function loadPBREnvironment(device: Device, props: PBREnvironmentProps):
|
|
|
53
63
|
|
|
54
64
|
const specularEnvSampler = makeCube(device, {
|
|
55
65
|
id: 'SpecularEnvSampler',
|
|
56
|
-
getTextureForFace: (
|
|
57
|
-
const imageArray: Promise<
|
|
58
|
-
|
|
59
|
-
for (let lod = 0; lod
|
|
60
|
-
imageArray.push(loadImageTexture(props.getTexUrl('specular',
|
|
66
|
+
getTextureForFace: (face: TextureCubeFace) => {
|
|
67
|
+
const imageArray: Array<Promise<unknown>> = [];
|
|
68
|
+
const direction = FACES.indexOf(face);
|
|
69
|
+
for (let lod = 0; lod < specularMipLevels; lod++) {
|
|
70
|
+
imageArray.push(loadImageTexture(props.getTexUrl('specular', direction, lod)));
|
|
61
71
|
}
|
|
62
|
-
return imageArray
|
|
72
|
+
return Promise.all(imageArray) as Promise<Texture2DData>;
|
|
63
73
|
},
|
|
64
74
|
sampler: {
|
|
65
75
|
addressModeU: 'clamp-to-edge',
|
|
@@ -77,7 +87,7 @@ export function loadPBREnvironment(device: Device, props: PBREnvironmentProps):
|
|
|
77
87
|
}
|
|
78
88
|
|
|
79
89
|
// TODO put somewhere common
|
|
80
|
-
const FACES = [
|
|
90
|
+
const FACES: TextureCubeFace[] = ['+X', '-X', '+Y', '-Y', '+Z', '-Z'];
|
|
81
91
|
|
|
82
92
|
/** Construction props for an asynchronously loaded cubemap. */
|
|
83
93
|
function makeCube(
|
|
@@ -89,23 +99,26 @@ function makeCube(
|
|
|
89
99
|
}: {
|
|
90
100
|
/** Debug id assigned to the created texture. */
|
|
91
101
|
id: string;
|
|
92
|
-
/** Returns the image
|
|
93
|
-
getTextureForFace: (
|
|
102
|
+
/** Returns the image or mip-array promise for one cubemap face. */
|
|
103
|
+
getTextureForFace: (face: TextureCubeFace) => Promise<Texture2DData>;
|
|
94
104
|
/** Sampler configuration shared across faces. */
|
|
95
105
|
sampler: SamplerProps;
|
|
96
106
|
}
|
|
97
107
|
): DynamicTexture {
|
|
98
|
-
const data =
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
108
|
+
const data: Promise<TextureCubeData> = Promise.all(
|
|
109
|
+
FACES.map(face => getTextureForFace(face))
|
|
110
|
+
).then(faceDataArray => {
|
|
111
|
+
const cubeData = {} as TextureCubeData;
|
|
112
|
+
FACES.forEach((face, index) => {
|
|
113
|
+
cubeData[face] = faceDataArray[index];
|
|
114
|
+
});
|
|
115
|
+
return cubeData;
|
|
102
116
|
});
|
|
103
117
|
return new DynamicTexture(device, {
|
|
104
118
|
id,
|
|
105
119
|
dimension: 'cube',
|
|
106
120
|
mipmaps: false,
|
|
107
121
|
sampler,
|
|
108
|
-
// @ts-expect-error
|
|
109
122
|
data
|
|
110
123
|
});
|
|
111
124
|
}
|
package/src/pbr/pbr-material.ts
CHANGED
|
@@ -1,14 +1,24 @@
|
|
|
1
1
|
import type {Texture, Parameters} from '@luma.gl/core';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
IBLBindings,
|
|
4
|
+
PBRMaterialBindings,
|
|
5
|
+
PBRMaterialUniforms,
|
|
6
|
+
PBRProjectionProps
|
|
7
|
+
} from '@luma.gl/shadertools';
|
|
8
|
+
|
|
9
|
+
type ParsedPBRMaterialUniforms = Partial<PBRProjectionProps & PBRMaterialUniforms> & {
|
|
10
|
+
clearcoatRoughnessMapEnabled?: boolean;
|
|
11
|
+
sheenRoughnessMapEnabled?: boolean;
|
|
12
|
+
};
|
|
3
13
|
|
|
4
14
|
/** Material state extracted from a glTF primitive for consumption by the PBR shader module. */
|
|
5
15
|
export type ParsedPBRMaterial = {
|
|
6
16
|
/** Shader defines inferred from geometry and material features. */
|
|
7
17
|
readonly defines: Record<string, boolean>;
|
|
8
18
|
/** Texture and sampler bindings for the PBR shader module. */
|
|
9
|
-
readonly bindings: Partial<PBRMaterialBindings>;
|
|
19
|
+
readonly bindings: Partial<PBRMaterialBindings & IBLBindings>;
|
|
10
20
|
/** Uniform values for the projection and PBR shader modules. */
|
|
11
|
-
readonly uniforms:
|
|
21
|
+
readonly uniforms: ParsedPBRMaterialUniforms;
|
|
12
22
|
/** Render pipeline parameters derived from the glTF material. */
|
|
13
23
|
readonly parameters: Parameters;
|
|
14
24
|
/** @deprecated Use parameters */
|
|
@@ -5,24 +5,24 @@
|
|
|
5
5
|
// TODO: convert in loaders.gl?
|
|
6
6
|
|
|
7
7
|
import type {SamplerProps} from '@luma.gl/core';
|
|
8
|
-
import {
|
|
8
|
+
import {GLEnum} from './gltf-webgl-constants';
|
|
9
9
|
|
|
10
10
|
/** Minimal glTF sampler representation used during conversion. */
|
|
11
11
|
type GLTFSampler = {
|
|
12
12
|
/** Horizontal wrap mode. */
|
|
13
|
-
wrapS?:
|
|
13
|
+
wrapS?: GLEnum.CLAMP_TO_EDGE | GLEnum.REPEAT | GLEnum.MIRRORED_REPEAT;
|
|
14
14
|
/** Vertical wrap mode. */
|
|
15
|
-
wrapT?:
|
|
15
|
+
wrapT?: GLEnum.CLAMP_TO_EDGE | GLEnum.REPEAT | GLEnum.MIRRORED_REPEAT;
|
|
16
16
|
/** Magnification filter. */
|
|
17
|
-
magFilter?:
|
|
17
|
+
magFilter?: GLEnum.NEAREST | GLEnum.LINEAR;
|
|
18
18
|
/** Minification and mip filter combination. */
|
|
19
19
|
minFilter?:
|
|
20
|
-
|
|
|
21
|
-
|
|
|
22
|
-
|
|
|
23
|
-
|
|
|
24
|
-
|
|
|
25
|
-
|
|
|
20
|
+
| GLEnum.NEAREST
|
|
21
|
+
| GLEnum.LINEAR
|
|
22
|
+
| GLEnum.NEAREST_MIPMAP_NEAREST
|
|
23
|
+
| GLEnum.LINEAR_MIPMAP_NEAREST
|
|
24
|
+
| GLEnum.NEAREST_MIPMAP_LINEAR
|
|
25
|
+
| GLEnum.LINEAR_MIPMAP_LINEAR;
|
|
26
26
|
};
|
|
27
27
|
|
|
28
28
|
/** Converts a glTF sampler into luma.gl sampler props. */
|
|
@@ -37,14 +37,14 @@ export function convertSampler(gltfSampler: GLTFSampler): SamplerProps {
|
|
|
37
37
|
|
|
38
38
|
/** Converts a glTF wrap enum into a luma.gl address mode. */
|
|
39
39
|
function convertSamplerWrapMode(
|
|
40
|
-
mode:
|
|
40
|
+
mode: GLEnum.CLAMP_TO_EDGE | GLEnum.REPEAT | GLEnum.MIRRORED_REPEAT | undefined
|
|
41
41
|
): 'clamp-to-edge' | 'repeat' | 'mirror-repeat' | undefined {
|
|
42
42
|
switch (mode) {
|
|
43
|
-
case
|
|
43
|
+
case GLEnum.CLAMP_TO_EDGE:
|
|
44
44
|
return 'clamp-to-edge';
|
|
45
|
-
case
|
|
45
|
+
case GLEnum.REPEAT:
|
|
46
46
|
return 'repeat';
|
|
47
|
-
case
|
|
47
|
+
case GLEnum.MIRRORED_REPEAT:
|
|
48
48
|
return 'mirror-repeat';
|
|
49
49
|
default:
|
|
50
50
|
return undefined;
|
|
@@ -53,12 +53,12 @@ function convertSamplerWrapMode(
|
|
|
53
53
|
|
|
54
54
|
/** Converts a glTF mag filter enum into a luma.gl mag filter. */
|
|
55
55
|
function convertSamplerMagFilter(
|
|
56
|
-
mode:
|
|
56
|
+
mode: GLEnum.NEAREST | GLEnum.LINEAR | undefined
|
|
57
57
|
): 'nearest' | 'linear' | undefined {
|
|
58
58
|
switch (mode) {
|
|
59
|
-
case
|
|
59
|
+
case GLEnum.NEAREST:
|
|
60
60
|
return 'nearest';
|
|
61
|
-
case
|
|
61
|
+
case GLEnum.LINEAR:
|
|
62
62
|
return 'linear';
|
|
63
63
|
default:
|
|
64
64
|
return undefined;
|
|
@@ -68,26 +68,26 @@ function convertSamplerMagFilter(
|
|
|
68
68
|
/** Converts a glTF min filter enum into luma.gl minification and mipmap filters. */
|
|
69
69
|
function convertSamplerMinFilter(
|
|
70
70
|
mode:
|
|
71
|
-
|
|
|
72
|
-
|
|
|
73
|
-
|
|
|
74
|
-
|
|
|
75
|
-
|
|
|
76
|
-
|
|
|
71
|
+
| GLEnum.NEAREST
|
|
72
|
+
| GLEnum.LINEAR
|
|
73
|
+
| GLEnum.NEAREST_MIPMAP_NEAREST
|
|
74
|
+
| GLEnum.LINEAR_MIPMAP_NEAREST
|
|
75
|
+
| GLEnum.NEAREST_MIPMAP_LINEAR
|
|
76
|
+
| GLEnum.LINEAR_MIPMAP_LINEAR
|
|
77
77
|
| undefined
|
|
78
78
|
): {minFilter?: 'nearest' | 'linear'; mipmapFilter?: 'nearest' | 'linear'} {
|
|
79
79
|
switch (mode) {
|
|
80
|
-
case
|
|
80
|
+
case GLEnum.NEAREST:
|
|
81
81
|
return {minFilter: 'nearest'};
|
|
82
|
-
case
|
|
82
|
+
case GLEnum.LINEAR:
|
|
83
83
|
return {minFilter: 'linear'};
|
|
84
|
-
case
|
|
84
|
+
case GLEnum.NEAREST_MIPMAP_NEAREST:
|
|
85
85
|
return {minFilter: 'nearest', mipmapFilter: 'nearest'};
|
|
86
|
-
case
|
|
86
|
+
case GLEnum.LINEAR_MIPMAP_NEAREST:
|
|
87
87
|
return {minFilter: 'linear', mipmapFilter: 'nearest'};
|
|
88
|
-
case
|
|
88
|
+
case GLEnum.NEAREST_MIPMAP_LINEAR:
|
|
89
89
|
return {minFilter: 'nearest', mipmapFilter: 'linear'};
|
|
90
|
-
case
|
|
90
|
+
case GLEnum.LINEAR_MIPMAP_LINEAR:
|
|
91
91
|
return {minFilter: 'linear', mipmapFilter: 'linear'};
|
|
92
92
|
default:
|
|
93
93
|
return {};
|
|
@@ -3,21 +3,7 @@
|
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
5
|
import {PrimitiveTopology} from '@luma.gl/core';
|
|
6
|
-
|
|
7
|
-
// NOTE: Modules other than `@luma.gl/webgl` should not import `GL` from
|
|
8
|
-
// `@luma.gl/constants`. Locally we use `GLEnum` instead of `GL` to avoid
|
|
9
|
-
// conflicts with the `babel-plugin-inline-webgl-constants` plugin.
|
|
10
|
-
// eslint-disable-next-line no-shadow
|
|
11
|
-
/** Minimal WebGL draw-mode enum subset used by the glTF converter. */
|
|
12
|
-
export enum GLEnum {
|
|
13
|
-
POINTS = 0x0,
|
|
14
|
-
LINES = 0x1,
|
|
15
|
-
LINE_LOOP = 0x2,
|
|
16
|
-
LINE_STRIP = 0x3,
|
|
17
|
-
TRIANGLES = 0x4,
|
|
18
|
-
TRIANGLE_STRIP = 0x5,
|
|
19
|
-
TRIANGLE_FAN = 0x6
|
|
20
|
-
}
|
|
6
|
+
import {GLEnum} from './gltf-webgl-constants';
|
|
21
7
|
|
|
22
8
|
/** Converts a WebGL draw mode into a luma.gl primitive topology string. */
|
|
23
9
|
export function convertGLDrawModeToTopology(
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
// NOTE: `@luma.gl/gltf` intentionally keeps this as a local enum subset so it
|
|
6
|
+
// does not need to depend on `@luma.gl/webgl` for a handful of stable WebGL values.
|
|
7
|
+
// eslint-disable-next-line no-shadow
|
|
8
|
+
export enum GLEnum {
|
|
9
|
+
POINTS = 0x0,
|
|
10
|
+
LINES = 0x1,
|
|
11
|
+
LINE_LOOP = 0x2,
|
|
12
|
+
LINE_STRIP = 0x3,
|
|
13
|
+
TRIANGLES = 0x4,
|
|
14
|
+
TRIANGLE_STRIP = 0x5,
|
|
15
|
+
TRIANGLE_FAN = 0x6,
|
|
16
|
+
|
|
17
|
+
ONE = 1,
|
|
18
|
+
SRC_ALPHA = 0x0302,
|
|
19
|
+
ONE_MINUS_SRC_ALPHA = 0x0303,
|
|
20
|
+
FUNC_ADD = 0x8006,
|
|
21
|
+
|
|
22
|
+
LINEAR = 0x2601,
|
|
23
|
+
NEAREST = 0x2600,
|
|
24
|
+
NEAREST_MIPMAP_NEAREST = 0x2700,
|
|
25
|
+
LINEAR_MIPMAP_NEAREST = 0x2701,
|
|
26
|
+
NEAREST_MIPMAP_LINEAR = 0x2702,
|
|
27
|
+
LINEAR_MIPMAP_LINEAR = 0x2703,
|
|
28
|
+
TEXTURE_MIN_FILTER = 0x2801,
|
|
29
|
+
TEXTURE_WRAP_S = 0x2802,
|
|
30
|
+
TEXTURE_WRAP_T = 0x2803,
|
|
31
|
+
REPEAT = 0x2901,
|
|
32
|
+
CLAMP_TO_EDGE = 0x812f,
|
|
33
|
+
MIRRORED_REPEAT = 0x8370,
|
|
34
|
+
UNPACK_FLIP_Y_WEBGL = 0x9240
|
|
35
|
+
}
|