@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
|
@@ -5,6 +5,7 @@ import { DynamicTexture } from '@luma.gl/engine';
|
|
|
5
5
|
import { loadImageTexture } from '@loaders.gl/textures';
|
|
6
6
|
/** Loads textures for PBR environment */
|
|
7
7
|
export function loadPBREnvironment(device, props) {
|
|
8
|
+
const specularMipLevels = props.specularMipLevels ?? 1;
|
|
8
9
|
const brdfLutTexture = new DynamicTexture(device, {
|
|
9
10
|
id: 'brdfLUT',
|
|
10
11
|
sampler: {
|
|
@@ -18,7 +19,7 @@ export function loadPBREnvironment(device, props) {
|
|
|
18
19
|
});
|
|
19
20
|
const diffuseEnvSampler = makeCube(device, {
|
|
20
21
|
id: 'DiffuseEnvSampler',
|
|
21
|
-
getTextureForFace:
|
|
22
|
+
getTextureForFace: face => loadImageTexture(props.getTexUrl('diffuse', FACES.indexOf(face), 0)),
|
|
22
23
|
sampler: {
|
|
23
24
|
addressModeU: 'clamp-to-edge',
|
|
24
25
|
addressModeV: 'clamp-to-edge',
|
|
@@ -28,13 +29,13 @@ export function loadPBREnvironment(device, props) {
|
|
|
28
29
|
});
|
|
29
30
|
const specularEnvSampler = makeCube(device, {
|
|
30
31
|
id: 'SpecularEnvSampler',
|
|
31
|
-
getTextureForFace: (
|
|
32
|
+
getTextureForFace: (face) => {
|
|
32
33
|
const imageArray = [];
|
|
33
|
-
|
|
34
|
-
for (let lod = 0; lod
|
|
35
|
-
imageArray.push(loadImageTexture(props.getTexUrl('specular',
|
|
34
|
+
const direction = FACES.indexOf(face);
|
|
35
|
+
for (let lod = 0; lod < specularMipLevels; lod++) {
|
|
36
|
+
imageArray.push(loadImageTexture(props.getTexUrl('specular', direction, lod)));
|
|
36
37
|
}
|
|
37
|
-
return imageArray;
|
|
38
|
+
return Promise.all(imageArray);
|
|
38
39
|
},
|
|
39
40
|
sampler: {
|
|
40
41
|
addressModeU: 'clamp-to-edge',
|
|
@@ -50,20 +51,21 @@ export function loadPBREnvironment(device, props) {
|
|
|
50
51
|
};
|
|
51
52
|
}
|
|
52
53
|
// TODO put somewhere common
|
|
53
|
-
const FACES = [
|
|
54
|
+
const FACES = ['+X', '-X', '+Y', '-Y', '+Z', '-Z'];
|
|
54
55
|
/** Construction props for an asynchronously loaded cubemap. */
|
|
55
56
|
function makeCube(device, { id, getTextureForFace, sampler }) {
|
|
56
|
-
const data = {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
57
|
+
const data = Promise.all(FACES.map(face => getTextureForFace(face))).then(faceDataArray => {
|
|
58
|
+
const cubeData = {};
|
|
59
|
+
FACES.forEach((face, index) => {
|
|
60
|
+
cubeData[face] = faceDataArray[index];
|
|
61
|
+
});
|
|
62
|
+
return cubeData;
|
|
60
63
|
});
|
|
61
64
|
return new DynamicTexture(device, {
|
|
62
65
|
id,
|
|
63
66
|
dimension: 'cube',
|
|
64
67
|
mipmaps: false,
|
|
65
68
|
sampler,
|
|
66
|
-
// @ts-expect-error
|
|
67
69
|
data
|
|
68
70
|
});
|
|
69
71
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pbr-environment.js","sourceRoot":"","sources":["../../src/pbr/pbr-environment.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAGpC,OAAO,
|
|
1
|
+
{"version":3,"file":"pbr-environment.js","sourceRoot":"","sources":["../../src/pbr/pbr-environment.ts"],"names":[],"mappings":"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"}
|
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
import type { Texture, Parameters } from '@luma.gl/core';
|
|
2
|
-
import { PBRMaterialBindings, PBRMaterialUniforms, PBRProjectionProps } from '@luma.gl/shadertools';
|
|
2
|
+
import { IBLBindings, PBRMaterialBindings, PBRMaterialUniforms, PBRProjectionProps } from '@luma.gl/shadertools';
|
|
3
|
+
type ParsedPBRMaterialUniforms = Partial<PBRProjectionProps & PBRMaterialUniforms> & {
|
|
4
|
+
clearcoatRoughnessMapEnabled?: boolean;
|
|
5
|
+
sheenRoughnessMapEnabled?: boolean;
|
|
6
|
+
};
|
|
3
7
|
/** Material state extracted from a glTF primitive for consumption by the PBR shader module. */
|
|
4
8
|
export type ParsedPBRMaterial = {
|
|
5
9
|
/** Shader defines inferred from geometry and material features. */
|
|
6
10
|
readonly defines: Record<string, boolean>;
|
|
7
11
|
/** Texture and sampler bindings for the PBR shader module. */
|
|
8
|
-
readonly bindings: Partial<PBRMaterialBindings>;
|
|
12
|
+
readonly bindings: Partial<PBRMaterialBindings & IBLBindings>;
|
|
9
13
|
/** Uniform values for the projection and PBR shader modules. */
|
|
10
|
-
readonly uniforms:
|
|
14
|
+
readonly uniforms: ParsedPBRMaterialUniforms;
|
|
11
15
|
/** Render pipeline parameters derived from the glTF material. */
|
|
12
16
|
readonly parameters: Parameters;
|
|
13
17
|
/** @deprecated Use parameters */
|
|
@@ -15,4 +19,5 @@ export type ParsedPBRMaterial = {
|
|
|
15
19
|
/** List of all generated textures, makes it easy to destroy them later */
|
|
16
20
|
readonly generatedTextures: Texture[];
|
|
17
21
|
};
|
|
22
|
+
export {};
|
|
18
23
|
//# sourceMappingURL=pbr-material.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pbr-material.d.ts","sourceRoot":"","sources":["../../src/pbr/pbr-material.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,OAAO,EAAE,UAAU,EAAC,MAAM,eAAe,CAAC;AACvD,OAAO,
|
|
1
|
+
{"version":3,"file":"pbr-material.d.ts","sourceRoot":"","sources":["../../src/pbr/pbr-material.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,OAAO,EAAE,UAAU,EAAC,MAAM,eAAe,CAAC;AACvD,OAAO,EACL,WAAW,EACX,mBAAmB,EACnB,mBAAmB,EACnB,kBAAkB,EACnB,MAAM,sBAAsB,CAAC;AAE9B,KAAK,yBAAyB,GAAG,OAAO,CAAC,kBAAkB,GAAG,mBAAmB,CAAC,GAAG;IACnF,4BAA4B,CAAC,EAAE,OAAO,CAAC;IACvC,wBAAwB,CAAC,EAAE,OAAO,CAAC;CACpC,CAAC;AAEF,+FAA+F;AAC/F,MAAM,MAAM,iBAAiB,GAAG;IAC9B,mEAAmE;IACnE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC1C,8DAA8D;IAC9D,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC,mBAAmB,GAAG,WAAW,CAAC,CAAC;IAC9D,gEAAgE;IAChE,QAAQ,CAAC,QAAQ,EAAE,yBAAyB,CAAC;IAC7C,iEAAiE;IACjE,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC;IAChC,iCAAiC;IACjC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC3C,0EAA0E;IAC1E,QAAQ,CAAC,iBAAiB,EAAE,OAAO,EAAE,CAAC;CACvC,CAAC"}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import type { SamplerProps } from '@luma.gl/core';
|
|
2
|
-
import {
|
|
2
|
+
import { GLEnum } from "./gltf-webgl-constants.js";
|
|
3
3
|
/** Minimal glTF sampler representation used during conversion. */
|
|
4
4
|
type GLTFSampler = {
|
|
5
5
|
/** Horizontal wrap mode. */
|
|
6
|
-
wrapS?:
|
|
6
|
+
wrapS?: GLEnum.CLAMP_TO_EDGE | GLEnum.REPEAT | GLEnum.MIRRORED_REPEAT;
|
|
7
7
|
/** Vertical wrap mode. */
|
|
8
|
-
wrapT?:
|
|
8
|
+
wrapT?: GLEnum.CLAMP_TO_EDGE | GLEnum.REPEAT | GLEnum.MIRRORED_REPEAT;
|
|
9
9
|
/** Magnification filter. */
|
|
10
|
-
magFilter?:
|
|
10
|
+
magFilter?: GLEnum.NEAREST | GLEnum.LINEAR;
|
|
11
11
|
/** Minification and mip filter combination. */
|
|
12
|
-
minFilter?:
|
|
12
|
+
minFilter?: GLEnum.NEAREST | GLEnum.LINEAR | GLEnum.NEAREST_MIPMAP_NEAREST | GLEnum.LINEAR_MIPMAP_NEAREST | GLEnum.NEAREST_MIPMAP_LINEAR | GLEnum.LINEAR_MIPMAP_LINEAR;
|
|
13
13
|
};
|
|
14
14
|
/** Converts a glTF sampler into luma.gl sampler props. */
|
|
15
15
|
export declare function convertSampler(gltfSampler: GLTFSampler): SamplerProps;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"convert-webgl-sampler.d.ts","sourceRoot":"","sources":["../../src/webgl-to-webgpu/convert-webgl-sampler.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,eAAe,CAAC;AAChD,OAAO,EAAC,
|
|
1
|
+
{"version":3,"file":"convert-webgl-sampler.d.ts","sourceRoot":"","sources":["../../src/webgl-to-webgpu/convert-webgl-sampler.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,eAAe,CAAC;AAChD,OAAO,EAAC,MAAM,EAAC,kCAA+B;AAE9C,kEAAkE;AAClE,KAAK,WAAW,GAAG;IACjB,4BAA4B;IAC5B,KAAK,CAAC,EAAE,MAAM,CAAC,aAAa,GAAG,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC,eAAe,CAAC;IACtE,0BAA0B;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAC,aAAa,GAAG,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC,eAAe,CAAC;IACtE,4BAA4B;IAC5B,SAAS,CAAC,EAAE,MAAM,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC;IAC3C,+CAA+C;IAC/C,SAAS,CAAC,EACN,MAAM,CAAC,OAAO,GACd,MAAM,CAAC,MAAM,GACb,MAAM,CAAC,sBAAsB,GAC7B,MAAM,CAAC,qBAAqB,GAC5B,MAAM,CAAC,qBAAqB,GAC5B,MAAM,CAAC,oBAAoB,CAAC;CACjC,CAAC;AAEF,0DAA0D;AAC1D,wBAAgB,cAAc,CAAC,WAAW,EAAE,WAAW,GAAG,YAAY,CAOrE"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// luma.gl
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
|
-
import {
|
|
4
|
+
import { GLEnum } from "./gltf-webgl-constants.js";
|
|
5
5
|
/** Converts a glTF sampler into luma.gl sampler props. */
|
|
6
6
|
export function convertSampler(gltfSampler) {
|
|
7
7
|
return {
|
|
@@ -14,11 +14,11 @@ export function convertSampler(gltfSampler) {
|
|
|
14
14
|
/** Converts a glTF wrap enum into a luma.gl address mode. */
|
|
15
15
|
function convertSamplerWrapMode(mode) {
|
|
16
16
|
switch (mode) {
|
|
17
|
-
case
|
|
17
|
+
case GLEnum.CLAMP_TO_EDGE:
|
|
18
18
|
return 'clamp-to-edge';
|
|
19
|
-
case
|
|
19
|
+
case GLEnum.REPEAT:
|
|
20
20
|
return 'repeat';
|
|
21
|
-
case
|
|
21
|
+
case GLEnum.MIRRORED_REPEAT:
|
|
22
22
|
return 'mirror-repeat';
|
|
23
23
|
default:
|
|
24
24
|
return undefined;
|
|
@@ -27,9 +27,9 @@ function convertSamplerWrapMode(mode) {
|
|
|
27
27
|
/** Converts a glTF mag filter enum into a luma.gl mag filter. */
|
|
28
28
|
function convertSamplerMagFilter(mode) {
|
|
29
29
|
switch (mode) {
|
|
30
|
-
case
|
|
30
|
+
case GLEnum.NEAREST:
|
|
31
31
|
return 'nearest';
|
|
32
|
-
case
|
|
32
|
+
case GLEnum.LINEAR:
|
|
33
33
|
return 'linear';
|
|
34
34
|
default:
|
|
35
35
|
return undefined;
|
|
@@ -38,17 +38,17 @@ function convertSamplerMagFilter(mode) {
|
|
|
38
38
|
/** Converts a glTF min filter enum into luma.gl minification and mipmap filters. */
|
|
39
39
|
function convertSamplerMinFilter(mode) {
|
|
40
40
|
switch (mode) {
|
|
41
|
-
case
|
|
41
|
+
case GLEnum.NEAREST:
|
|
42
42
|
return { minFilter: 'nearest' };
|
|
43
|
-
case
|
|
43
|
+
case GLEnum.LINEAR:
|
|
44
44
|
return { minFilter: 'linear' };
|
|
45
|
-
case
|
|
45
|
+
case GLEnum.NEAREST_MIPMAP_NEAREST:
|
|
46
46
|
return { minFilter: 'nearest', mipmapFilter: 'nearest' };
|
|
47
|
-
case
|
|
47
|
+
case GLEnum.LINEAR_MIPMAP_NEAREST:
|
|
48
48
|
return { minFilter: 'linear', mipmapFilter: 'nearest' };
|
|
49
|
-
case
|
|
49
|
+
case GLEnum.NEAREST_MIPMAP_LINEAR:
|
|
50
50
|
return { minFilter: 'nearest', mipmapFilter: 'linear' };
|
|
51
|
-
case
|
|
51
|
+
case GLEnum.LINEAR_MIPMAP_LINEAR:
|
|
52
52
|
return { minFilter: 'linear', mipmapFilter: 'linear' };
|
|
53
53
|
default:
|
|
54
54
|
return {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"convert-webgl-sampler.js","sourceRoot":"","sources":["../../src/webgl-to-webgpu/convert-webgl-sampler.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAKpC,OAAO,EAAC,
|
|
1
|
+
{"version":3,"file":"convert-webgl-sampler.js","sourceRoot":"","sources":["../../src/webgl-to-webgpu/convert-webgl-sampler.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAKpC,OAAO,EAAC,MAAM,EAAC,kCAA+B;AAoB9C,0DAA0D;AAC1D,MAAM,UAAU,cAAc,CAAC,WAAwB;IACrD,OAAO;QACL,YAAY,EAAE,sBAAsB,CAAC,WAAW,CAAC,KAAK,CAAC;QACvD,YAAY,EAAE,sBAAsB,CAAC,WAAW,CAAC,KAAK,CAAC;QACvD,SAAS,EAAE,uBAAuB,CAAC,WAAW,CAAC,SAAS,CAAC;QACzD,GAAG,uBAAuB,CAAC,WAAW,CAAC,SAAS,CAAC;KAClD,CAAC;AACJ,CAAC;AAED,6DAA6D;AAC7D,SAAS,sBAAsB,CAC7B,IAA+E;IAE/E,QAAQ,IAAI,EAAE,CAAC;QACb,KAAK,MAAM,CAAC,aAAa;YACvB,OAAO,eAAe,CAAC;QACzB,KAAK,MAAM,CAAC,MAAM;YAChB,OAAO,QAAQ,CAAC;QAClB,KAAK,MAAM,CAAC,eAAe;YACzB,OAAO,eAAe,CAAC;QACzB;YACE,OAAO,SAAS,CAAC;IACrB,CAAC;AACH,CAAC;AAED,iEAAiE;AACjE,SAAS,uBAAuB,CAC9B,IAAgD;IAEhD,QAAQ,IAAI,EAAE,CAAC;QACb,KAAK,MAAM,CAAC,OAAO;YACjB,OAAO,SAAS,CAAC;QACnB,KAAK,MAAM,CAAC,MAAM;YAChB,OAAO,QAAQ,CAAC;QAClB;YACE,OAAO,SAAS,CAAC;IACrB,CAAC;AACH,CAAC;AAED,oFAAoF;AACpF,SAAS,uBAAuB,CAC9B,IAOa;IAEb,QAAQ,IAAI,EAAE,CAAC;QACb,KAAK,MAAM,CAAC,OAAO;YACjB,OAAO,EAAC,SAAS,EAAE,SAAS,EAAC,CAAC;QAChC,KAAK,MAAM,CAAC,MAAM;YAChB,OAAO,EAAC,SAAS,EAAE,QAAQ,EAAC,CAAC;QAC/B,KAAK,MAAM,CAAC,sBAAsB;YAChC,OAAO,EAAC,SAAS,EAAE,SAAS,EAAE,YAAY,EAAE,SAAS,EAAC,CAAC;QACzD,KAAK,MAAM,CAAC,qBAAqB;YAC/B,OAAO,EAAC,SAAS,EAAE,QAAQ,EAAE,YAAY,EAAE,SAAS,EAAC,CAAC;QACxD,KAAK,MAAM,CAAC,qBAAqB;YAC/B,OAAO,EAAC,SAAS,EAAE,SAAS,EAAE,YAAY,EAAE,QAAQ,EAAC,CAAC;QACxD,KAAK,MAAM,CAAC,oBAAoB;YAC9B,OAAO,EAAC,SAAS,EAAE,QAAQ,EAAE,YAAY,EAAE,QAAQ,EAAC,CAAC;QACvD;YACE,OAAO,EAAE,CAAC;IACd,CAAC;AACH,CAAC"}
|
|
@@ -1,14 +1,5 @@
|
|
|
1
1
|
import { PrimitiveTopology } from '@luma.gl/core';
|
|
2
|
-
|
|
3
|
-
export declare enum GLEnum {
|
|
4
|
-
POINTS = 0,
|
|
5
|
-
LINES = 1,
|
|
6
|
-
LINE_LOOP = 2,
|
|
7
|
-
LINE_STRIP = 3,
|
|
8
|
-
TRIANGLES = 4,
|
|
9
|
-
TRIANGLE_STRIP = 5,
|
|
10
|
-
TRIANGLE_FAN = 6
|
|
11
|
-
}
|
|
2
|
+
import { GLEnum } from "./gltf-webgl-constants.js";
|
|
12
3
|
/** Converts a WebGL draw mode into a luma.gl primitive topology string. */
|
|
13
4
|
export declare function convertGLDrawModeToTopology(drawMode: GLEnum.POINTS | GLEnum.LINES | GLEnum.LINE_STRIP | GLEnum.LINE_LOOP | GLEnum.TRIANGLES | GLEnum.TRIANGLE_STRIP | GLEnum.TRIANGLE_FAN): PrimitiveTopology;
|
|
14
5
|
//# sourceMappingURL=convert-webgl-topology.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"convert-webgl-topology.d.ts","sourceRoot":"","sources":["../../src/webgl-to-webgpu/convert-webgl-topology.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,iBAAiB,EAAC,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"convert-webgl-topology.d.ts","sourceRoot":"","sources":["../../src/webgl-to-webgpu/convert-webgl-topology.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,iBAAiB,EAAC,MAAM,eAAe,CAAC;AAChD,OAAO,EAAC,MAAM,EAAC,kCAA+B;AAE9C,2EAA2E;AAC3E,wBAAgB,2BAA2B,CACzC,QAAQ,EACJ,MAAM,CAAC,MAAM,GACb,MAAM,CAAC,KAAK,GACZ,MAAM,CAAC,UAAU,GACjB,MAAM,CAAC,SAAS,GAChB,MAAM,CAAC,SAAS,GAChB,MAAM,CAAC,cAAc,GACrB,MAAM,CAAC,YAAY,GACtB,iBAAiB,CAUnB"}
|
|
@@ -1,21 +1,7 @@
|
|
|
1
1
|
// luma.gl
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
|
-
|
|
5
|
-
// `@luma.gl/constants`. Locally we use `GLEnum` instead of `GL` to avoid
|
|
6
|
-
// conflicts with the `babel-plugin-inline-webgl-constants` plugin.
|
|
7
|
-
// eslint-disable-next-line no-shadow
|
|
8
|
-
/** Minimal WebGL draw-mode enum subset used by the glTF converter. */
|
|
9
|
-
export var GLEnum;
|
|
10
|
-
(function (GLEnum) {
|
|
11
|
-
GLEnum[GLEnum["POINTS"] = 0] = "POINTS";
|
|
12
|
-
GLEnum[GLEnum["LINES"] = 1] = "LINES";
|
|
13
|
-
GLEnum[GLEnum["LINE_LOOP"] = 2] = "LINE_LOOP";
|
|
14
|
-
GLEnum[GLEnum["LINE_STRIP"] = 3] = "LINE_STRIP";
|
|
15
|
-
GLEnum[GLEnum["TRIANGLES"] = 4] = "TRIANGLES";
|
|
16
|
-
GLEnum[GLEnum["TRIANGLE_STRIP"] = 5] = "TRIANGLE_STRIP";
|
|
17
|
-
GLEnum[GLEnum["TRIANGLE_FAN"] = 6] = "TRIANGLE_FAN";
|
|
18
|
-
})(GLEnum || (GLEnum = {}));
|
|
4
|
+
import { GLEnum } from "./gltf-webgl-constants.js";
|
|
19
5
|
/** Converts a WebGL draw mode into a luma.gl primitive topology string. */
|
|
20
6
|
export function convertGLDrawModeToTopology(drawMode) {
|
|
21
7
|
// prettier-ignore
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"convert-webgl-topology.js","sourceRoot":"","sources":["../../src/webgl-to-webgpu/convert-webgl-topology.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;
|
|
1
|
+
{"version":3,"file":"convert-webgl-topology.js","sourceRoot":"","sources":["../../src/webgl-to-webgpu/convert-webgl-topology.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAGpC,OAAO,EAAC,MAAM,EAAC,kCAA+B;AAE9C,2EAA2E;AAC3E,MAAM,UAAU,2BAA2B,CACzC,QAOuB;IAEvB,kBAAkB;IAClB,QAAQ,QAAQ,EAAE,CAAC;QACjB,KAAK,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,YAAY,CAAC;QACxC,KAAK,MAAM,CAAC,KAAK,CAAC,CAAC,OAAO,WAAW,CAAC;QACtC,KAAK,MAAM,CAAC,UAAU,CAAC,CAAC,OAAO,YAAY,CAAC;QAC5C,KAAK,MAAM,CAAC,SAAS,CAAC,CAAC,OAAO,eAAe,CAAC;QAC9C,KAAK,MAAM,CAAC,cAAc,CAAC,CAAC,OAAO,gBAAgB,CAAC;QACpD,OAAO,CAAC,CAAC,MAAM,IAAI,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC;IAC7C,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export declare enum GLEnum {
|
|
2
|
+
POINTS = 0,
|
|
3
|
+
LINES = 1,
|
|
4
|
+
LINE_LOOP = 2,
|
|
5
|
+
LINE_STRIP = 3,
|
|
6
|
+
TRIANGLES = 4,
|
|
7
|
+
TRIANGLE_STRIP = 5,
|
|
8
|
+
TRIANGLE_FAN = 6,
|
|
9
|
+
ONE = 1,
|
|
10
|
+
SRC_ALPHA = 770,
|
|
11
|
+
ONE_MINUS_SRC_ALPHA = 771,
|
|
12
|
+
FUNC_ADD = 32774,
|
|
13
|
+
LINEAR = 9729,
|
|
14
|
+
NEAREST = 9728,
|
|
15
|
+
NEAREST_MIPMAP_NEAREST = 9984,
|
|
16
|
+
LINEAR_MIPMAP_NEAREST = 9985,
|
|
17
|
+
NEAREST_MIPMAP_LINEAR = 9986,
|
|
18
|
+
LINEAR_MIPMAP_LINEAR = 9987,
|
|
19
|
+
TEXTURE_MIN_FILTER = 10241,
|
|
20
|
+
TEXTURE_WRAP_S = 10242,
|
|
21
|
+
TEXTURE_WRAP_T = 10243,
|
|
22
|
+
REPEAT = 10497,
|
|
23
|
+
CLAMP_TO_EDGE = 33071,
|
|
24
|
+
MIRRORED_REPEAT = 33648,
|
|
25
|
+
UNPACK_FLIP_Y_WEBGL = 37440
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=gltf-webgl-constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gltf-webgl-constants.d.ts","sourceRoot":"","sources":["../../src/webgl-to-webgpu/gltf-webgl-constants.ts"],"names":[],"mappings":"AAOA,oBAAY,MAAM;IAChB,MAAM,IAAM;IACZ,KAAK,IAAM;IACX,SAAS,IAAM;IACf,UAAU,IAAM;IAChB,SAAS,IAAM;IACf,cAAc,IAAM;IACpB,YAAY,IAAM;IAElB,GAAG,IAAI;IACP,SAAS,MAAS;IAClB,mBAAmB,MAAS;IAC5B,QAAQ,QAAS;IAEjB,MAAM,OAAS;IACf,OAAO,OAAS;IAChB,sBAAsB,OAAS;IAC/B,qBAAqB,OAAS;IAC9B,qBAAqB,OAAS;IAC9B,oBAAoB,OAAS;IAC7B,kBAAkB,QAAS;IAC3B,cAAc,QAAS;IACvB,cAAc,QAAS;IACvB,MAAM,QAAS;IACf,aAAa,QAAS;IACtB,eAAe,QAAS;IACxB,mBAAmB,QAAS;CAC7B"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
// NOTE: `@luma.gl/gltf` intentionally keeps this as a local enum subset so it
|
|
5
|
+
// does not need to depend on `@luma.gl/webgl` for a handful of stable WebGL values.
|
|
6
|
+
// eslint-disable-next-line no-shadow
|
|
7
|
+
export var GLEnum;
|
|
8
|
+
(function (GLEnum) {
|
|
9
|
+
GLEnum[GLEnum["POINTS"] = 0] = "POINTS";
|
|
10
|
+
GLEnum[GLEnum["LINES"] = 1] = "LINES";
|
|
11
|
+
GLEnum[GLEnum["LINE_LOOP"] = 2] = "LINE_LOOP";
|
|
12
|
+
GLEnum[GLEnum["LINE_STRIP"] = 3] = "LINE_STRIP";
|
|
13
|
+
GLEnum[GLEnum["TRIANGLES"] = 4] = "TRIANGLES";
|
|
14
|
+
GLEnum[GLEnum["TRIANGLE_STRIP"] = 5] = "TRIANGLE_STRIP";
|
|
15
|
+
GLEnum[GLEnum["TRIANGLE_FAN"] = 6] = "TRIANGLE_FAN";
|
|
16
|
+
GLEnum[GLEnum["ONE"] = 1] = "ONE";
|
|
17
|
+
GLEnum[GLEnum["SRC_ALPHA"] = 770] = "SRC_ALPHA";
|
|
18
|
+
GLEnum[GLEnum["ONE_MINUS_SRC_ALPHA"] = 771] = "ONE_MINUS_SRC_ALPHA";
|
|
19
|
+
GLEnum[GLEnum["FUNC_ADD"] = 32774] = "FUNC_ADD";
|
|
20
|
+
GLEnum[GLEnum["LINEAR"] = 9729] = "LINEAR";
|
|
21
|
+
GLEnum[GLEnum["NEAREST"] = 9728] = "NEAREST";
|
|
22
|
+
GLEnum[GLEnum["NEAREST_MIPMAP_NEAREST"] = 9984] = "NEAREST_MIPMAP_NEAREST";
|
|
23
|
+
GLEnum[GLEnum["LINEAR_MIPMAP_NEAREST"] = 9985] = "LINEAR_MIPMAP_NEAREST";
|
|
24
|
+
GLEnum[GLEnum["NEAREST_MIPMAP_LINEAR"] = 9986] = "NEAREST_MIPMAP_LINEAR";
|
|
25
|
+
GLEnum[GLEnum["LINEAR_MIPMAP_LINEAR"] = 9987] = "LINEAR_MIPMAP_LINEAR";
|
|
26
|
+
GLEnum[GLEnum["TEXTURE_MIN_FILTER"] = 10241] = "TEXTURE_MIN_FILTER";
|
|
27
|
+
GLEnum[GLEnum["TEXTURE_WRAP_S"] = 10242] = "TEXTURE_WRAP_S";
|
|
28
|
+
GLEnum[GLEnum["TEXTURE_WRAP_T"] = 10243] = "TEXTURE_WRAP_T";
|
|
29
|
+
GLEnum[GLEnum["REPEAT"] = 10497] = "REPEAT";
|
|
30
|
+
GLEnum[GLEnum["CLAMP_TO_EDGE"] = 33071] = "CLAMP_TO_EDGE";
|
|
31
|
+
GLEnum[GLEnum["MIRRORED_REPEAT"] = 33648] = "MIRRORED_REPEAT";
|
|
32
|
+
GLEnum[GLEnum["UNPACK_FLIP_Y_WEBGL"] = 37440] = "UNPACK_FLIP_Y_WEBGL";
|
|
33
|
+
})(GLEnum || (GLEnum = {}));
|
|
34
|
+
//# sourceMappingURL=gltf-webgl-constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gltf-webgl-constants.js","sourceRoot":"","sources":["../../src/webgl-to-webgpu/gltf-webgl-constants.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAEpC,8EAA8E;AAC9E,oFAAoF;AACpF,qCAAqC;AACrC,MAAM,CAAN,IAAY,MA2BX;AA3BD,WAAY,MAAM;IAChB,uCAAY,CAAA;IACZ,qCAAW,CAAA;IACX,6CAAe,CAAA;IACf,+CAAgB,CAAA;IAChB,6CAAe,CAAA;IACf,uDAAoB,CAAA;IACpB,mDAAkB,CAAA;IAElB,iCAAO,CAAA;IACP,+CAAkB,CAAA;IAClB,mEAA4B,CAAA;IAC5B,+CAAiB,CAAA;IAEjB,0CAAe,CAAA;IACf,4CAAgB,CAAA;IAChB,0EAA+B,CAAA;IAC/B,wEAA8B,CAAA;IAC9B,wEAA8B,CAAA;IAC9B,sEAA6B,CAAA;IAC7B,mEAA2B,CAAA;IAC3B,2DAAuB,CAAA;IACvB,2DAAuB,CAAA;IACvB,2CAAe,CAAA;IACf,yDAAsB,CAAA;IACtB,6DAAwB,CAAA;IACxB,qEAA4B,CAAA;AAC9B,CAAC,EA3BW,MAAM,KAAN,MAAM,QA2BjB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@luma.gl/gltf",
|
|
3
|
-
"version": "9.3.0-alpha.
|
|
3
|
+
"version": "9.3.0-alpha.8",
|
|
4
4
|
"description": "glTF support for luma.gl",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -40,10 +40,9 @@
|
|
|
40
40
|
"prepublishOnly": "npm run build-minified-bundle && npm run build-dev-bundle"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
|
-
"@luma.gl/
|
|
44
|
-
"@luma.gl/
|
|
45
|
-
"@luma.gl/
|
|
46
|
-
"@luma.gl/shadertools": "9.2.0-alpha.6"
|
|
43
|
+
"@luma.gl/core": "9.3.0-alpha.6",
|
|
44
|
+
"@luma.gl/engine": "9.3.0-alpha.6",
|
|
45
|
+
"@luma.gl/shadertools": "9.3.0-alpha.6"
|
|
47
46
|
},
|
|
48
47
|
"dependencies": {
|
|
49
48
|
"@loaders.gl/core": "4.4.0-alpha.18",
|
|
@@ -51,5 +50,5 @@
|
|
|
51
50
|
"@loaders.gl/textures": "4.4.0-alpha.18",
|
|
52
51
|
"@math.gl/core": "^4.1.0"
|
|
53
52
|
},
|
|
54
|
-
"gitHead": "
|
|
53
|
+
"gitHead": "371f0979c1cd01563badc36118f314365a66e1a1"
|
|
55
54
|
}
|
|
@@ -2,9 +2,26 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
Buffer,
|
|
7
|
+
Device,
|
|
8
|
+
Sampler,
|
|
9
|
+
Texture,
|
|
10
|
+
TextureView,
|
|
11
|
+
type Binding,
|
|
12
|
+
type RenderPipelineParameters,
|
|
13
|
+
log
|
|
14
|
+
} from '@luma.gl/core';
|
|
15
|
+
import {DynamicTexture} from '@luma.gl/engine';
|
|
6
16
|
import {pbrMaterial, skin} from '@luma.gl/shadertools';
|
|
7
|
-
import {
|
|
17
|
+
import {
|
|
18
|
+
Geometry,
|
|
19
|
+
Material,
|
|
20
|
+
MaterialFactory,
|
|
21
|
+
Model,
|
|
22
|
+
ModelNode,
|
|
23
|
+
type ModelProps
|
|
24
|
+
} from '@luma.gl/engine';
|
|
8
25
|
import {type ParsedPBRMaterial} from '../pbr/pbr-material';
|
|
9
26
|
|
|
10
27
|
const SHADER = /* WGSL */ `
|
|
@@ -170,10 +187,42 @@ export type CreateGLTFModelOptions = {
|
|
|
170
187
|
geometry: Geometry;
|
|
171
188
|
/** Parsed PBR material state for the primitive. */
|
|
172
189
|
parsedPPBRMaterial: ParsedPBRMaterial;
|
|
190
|
+
/** Pre-created material aligned with the source glTF material entry, when available. */
|
|
191
|
+
material?: Material | null;
|
|
173
192
|
/** Additional model props merged into the generated model. */
|
|
174
193
|
modelOptions?: Partial<ModelProps>;
|
|
175
194
|
};
|
|
176
195
|
|
|
196
|
+
export type CreateGLTFMaterialOptions = {
|
|
197
|
+
id?: string;
|
|
198
|
+
parsedPPBRMaterial: ParsedPBRMaterial;
|
|
199
|
+
materialFactory?: MaterialFactory;
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
export function createGLTFMaterial(device: Device, options: CreateGLTFMaterialOptions): Material {
|
|
203
|
+
const materialFactory =
|
|
204
|
+
options.materialFactory || new MaterialFactory(device, {modules: [pbrMaterial]});
|
|
205
|
+
|
|
206
|
+
const pbrMaterialProps = {...options.parsedPPBRMaterial.uniforms};
|
|
207
|
+
delete pbrMaterialProps.camera;
|
|
208
|
+
const materialBindings = Object.fromEntries(
|
|
209
|
+
Object.entries({
|
|
210
|
+
...pbrMaterialProps,
|
|
211
|
+
...options.parsedPPBRMaterial.bindings
|
|
212
|
+
}).filter(
|
|
213
|
+
([name, value]) => materialFactory.ownsBinding(name) && isMaterialBindingResource(value)
|
|
214
|
+
)
|
|
215
|
+
) as Record<string, Binding | DynamicTexture>;
|
|
216
|
+
|
|
217
|
+
const material = materialFactory.createMaterial({
|
|
218
|
+
id: options.id,
|
|
219
|
+
bindings: materialBindings
|
|
220
|
+
});
|
|
221
|
+
material.setProps({pbrMaterial: pbrMaterialProps});
|
|
222
|
+
|
|
223
|
+
return material;
|
|
224
|
+
}
|
|
225
|
+
|
|
177
226
|
/** Creates a luma.gl Model from GLTF data*/
|
|
178
227
|
export function createGLTFModel(device: Device, options: CreateGLTFModelOptions): ModelNode {
|
|
179
228
|
const {id, geometry, parsedPPBRMaterial, vertexCount, modelOptions = {}} = options;
|
|
@@ -209,15 +258,74 @@ export function createGLTFModel(device: Device, options: CreateGLTFModelOptions)
|
|
|
209
258
|
parameters: {...parameters, ...parsedPPBRMaterial.parameters, ...modelOptions.parameters}
|
|
210
259
|
};
|
|
211
260
|
|
|
261
|
+
const material =
|
|
262
|
+
options.material ||
|
|
263
|
+
createGLTFMaterial(device, {
|
|
264
|
+
id: id ? `${id}-material` : undefined,
|
|
265
|
+
parsedPPBRMaterial
|
|
266
|
+
});
|
|
267
|
+
modelProps.material = material;
|
|
268
|
+
|
|
212
269
|
const model = new Model(device, modelProps);
|
|
213
270
|
|
|
214
|
-
const
|
|
271
|
+
const sceneShaderInputValues = {
|
|
215
272
|
...parsedPPBRMaterial.uniforms,
|
|
216
273
|
...modelOptions.uniforms,
|
|
217
274
|
...parsedPPBRMaterial.bindings,
|
|
218
275
|
...modelOptions.bindings
|
|
219
276
|
};
|
|
220
|
-
|
|
221
|
-
|
|
277
|
+
const sceneShaderInputProps = getSceneShaderInputProps(
|
|
278
|
+
model.shaderInputs.getModules(),
|
|
279
|
+
material,
|
|
280
|
+
sceneShaderInputValues
|
|
281
|
+
);
|
|
282
|
+
model.shaderInputs.setProps(sceneShaderInputProps);
|
|
222
283
|
return new ModelNode({managedResources, model});
|
|
223
284
|
}
|
|
285
|
+
|
|
286
|
+
function isMaterialBindingResource(value: unknown): boolean {
|
|
287
|
+
return (
|
|
288
|
+
value instanceof Buffer ||
|
|
289
|
+
value instanceof DynamicTexture ||
|
|
290
|
+
value instanceof Sampler ||
|
|
291
|
+
value instanceof Texture ||
|
|
292
|
+
value instanceof TextureView
|
|
293
|
+
);
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
function getSceneShaderInputProps(
|
|
297
|
+
modules: Array<{
|
|
298
|
+
name: string;
|
|
299
|
+
uniformTypes?: Readonly<Record<string, unknown>>;
|
|
300
|
+
bindingLayout?: ReadonlyArray<{name: string}>;
|
|
301
|
+
}>,
|
|
302
|
+
material: Material,
|
|
303
|
+
shaderInputValues: Record<string, unknown>
|
|
304
|
+
): Record<string, Record<string, unknown>> {
|
|
305
|
+
const propertyToModuleNameMap = new Map<string, string>();
|
|
306
|
+
for (const module of modules) {
|
|
307
|
+
for (const uniformName of Object.keys(module.uniformTypes || {})) {
|
|
308
|
+
propertyToModuleNameMap.set(uniformName, module.name);
|
|
309
|
+
}
|
|
310
|
+
for (const binding of module.bindingLayout || []) {
|
|
311
|
+
propertyToModuleNameMap.set(binding.name, module.name);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
const sceneShaderInputProps: Record<string, Record<string, unknown>> = {};
|
|
316
|
+
for (const [propertyName, value] of Object.entries(shaderInputValues)) {
|
|
317
|
+
if (value === undefined) {
|
|
318
|
+
continue;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
const moduleName = propertyToModuleNameMap.get(propertyName);
|
|
322
|
+
if (!moduleName || material.ownsModule(moduleName)) {
|
|
323
|
+
continue;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
sceneShaderInputProps[moduleName] ||= {};
|
|
327
|
+
sceneShaderInputProps[moduleName][propertyName] = value;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
return sceneShaderInputProps;
|
|
331
|
+
}
|