@luma.gl/gltf 9.2.6 → 9.3.0-alpha.2

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.
@@ -1,11 +1,11 @@
1
1
  // luma.gl
2
2
  // SPDX-License-Identifier: MIT
3
3
  // Copyright (c) vis.gl contributors
4
- import { AsyncTexture } from '@luma.gl/engine';
4
+ 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 brdfLutTexture = new AsyncTexture(device, {
8
+ const brdfLutTexture = new DynamicTexture(device, {
9
9
  id: 'brdfLUT',
10
10
  sampler: {
11
11
  addressModeU: 'clamp-to-edge',
@@ -57,7 +57,7 @@ function makeCube(device, { id, getTextureForFace, sampler }) {
57
57
  // @ts-ignore TODO
58
58
  data[String(face)] = getTextureForFace(face);
59
59
  });
60
- return new AsyncTexture(device, {
60
+ return new DynamicTexture(device, {
61
61
  id,
62
62
  dimension: 'cube',
63
63
  mipmaps: false,
@@ -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,EAAC,YAAY,EAAC,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAC,gBAAgB,EAAC,MAAM,sBAAsB,CAAC;AAgBtD,yCAAyC;AACzC,MAAM,UAAU,kBAAkB,CAAC,MAAc,EAAE,KAA0B;IAC3E,MAAM,cAAc,GAAG,IAAI,YAAY,CAAC,MAAM,EAAE;QAC9C,EAAE,EAAE,SAAS;QACb,OAAO,EAAE;YACP,YAAY,EAAE,eAAe;YAC7B,YAAY,EAAE,eAAe;YAC7B,SAAS,EAAE,QAAQ;YACnB,SAAS,EAAE,QAAQ;SACY;QACjC,2EAA2E;QAC3E,IAAI,EAAE,gBAAgB,CA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OAAO,IAAI,cAAc,CAAC,MAAM,EAAE;QAChC,EAAE;QACF,SAAS,EAAE,MAAM;QACjB,OAAO,EAAE,KAAK;QACd,OAAO;QACP,mBAAmB;QACnB,IAAI;KACL,CAAC,CAAC;AACL,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@luma.gl/gltf",
3
- "version": "9.2.6",
3
+ "version": "9.3.0-alpha.2",
4
4
  "description": "glTF support for luma.gl",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -40,10 +40,10 @@
40
40
  "prepublishOnly": "npm run build-minified-bundle && npm run build-dev-bundle"
41
41
  },
42
42
  "peerDependencies": {
43
- "@luma.gl/constants": "~9.2.0",
44
- "@luma.gl/core": "~9.2.0",
45
- "@luma.gl/engine": "~9.2.0",
46
- "@luma.gl/shadertools": "~9.2.0"
43
+ "@luma.gl/constants": "9.2.0-alpha.6",
44
+ "@luma.gl/core": "9.2.0-alpha.6",
45
+ "@luma.gl/engine": "9.2.0-alpha.6",
46
+ "@luma.gl/shadertools": "9.2.0-alpha.6"
47
47
  },
48
48
  "dependencies": {
49
49
  "@loaders.gl/core": "^4.2.0",
@@ -51,5 +51,5 @@
51
51
  "@loaders.gl/textures": "^4.2.0",
52
52
  "@math.gl/core": "^4.1.0"
53
53
  },
54
- "gitHead": "9c7a3adc09c7b23800df3f916762445ebc1fa924"
54
+ "gitHead": "7fedf8d8902f58490a4ffca9a873daee3c732f24"
55
55
  }
@@ -5,7 +5,9 @@
5
5
  import {Device} from '@luma.gl/core';
6
6
  import {GroupNode} from '@luma.gl/engine';
7
7
  import {GLTFPostprocessed} from '@loaders.gl/gltf';
8
+ import {Light} from '@luma.gl/shadertools';
8
9
  import {parseGLTF, type ParseGLTFOptions} from '../parsers/parse-gltf';
10
+ import {parseGLTFLights} from '../parsers/parse-gltf-lights';
9
11
  import {GLTFAnimator} from './gltf-animator';
10
12
  import {parseGLTFAnimations} from '../parsers/parse-gltf-animations';
11
13
  import {deepCopy} from '../utils/deep-copy';
@@ -17,11 +19,13 @@ export function createScenegraphsFromGLTF(
17
19
  ): {
18
20
  scenes: GroupNode[];
19
21
  animator: GLTFAnimator;
22
+ lights: Light[];
20
23
  } {
21
24
  gltf = deepCopy(gltf);
22
25
  const scenes = parseGLTF(device, gltf, options);
23
26
  // Note: There is a nasty dependency on injected nodes in the glTF
24
27
  const animations = parseGLTFAnimations(gltf);
25
28
  const animator = new GLTFAnimator({animations});
26
- return {scenes, animator};
29
+ const lights = parseGLTFLights(gltf);
30
+ return {scenes, animator, lights};
27
31
  }
package/src/index.ts CHANGED
@@ -4,6 +4,7 @@ export {loadPBREnvironment, type PBREnvironment} from './pbr/pbr-environment';
4
4
  export {type ParsedPBRMaterial} from './pbr/pbr-material';
5
5
  export {parsePBRMaterial, type ParsePBRMaterialOptions} from './parsers/parse-pbr-material';
6
6
  export {} from './pbr/pbr-environment';
7
+ export {parseGLTFLights} from './parsers/parse-gltf-lights';
7
8
 
8
9
  // glTF Scenegraph Instantiator
9
10
  export {createScenegraphsFromGLTF} from './gltf/create-scenegraph-from-gltf';
@@ -0,0 +1,91 @@
1
+ import {Matrix4} from '@math.gl/core';
2
+ import type {GLTFNodePostprocessed, GLTFPostprocessed} from '@loaders.gl/gltf';
3
+ import type {DirectionalLight, Light, PointLight} from '@luma.gl/shadertools';
4
+
5
+ /** Parse KHR_lights_punctual extension into luma.gl light definitions */
6
+ export function parseGLTFLights(gltf: GLTFPostprocessed): Light[] {
7
+ const lightDefs = gltf.extensions?.['KHR_lights_punctual']?.['lights'];
8
+ if (!lightDefs || !Array.isArray(lightDefs) || lightDefs.length === 0) {
9
+ return [];
10
+ }
11
+
12
+ const lights: Light[] = [];
13
+
14
+ for (const node of gltf.nodes || []) {
15
+ const nodeLight = node.extensions?.KHR_lights_punctual;
16
+ if (!nodeLight || typeof nodeLight.light !== 'number') {
17
+ // eslint-disable-next-line no-continue
18
+ continue;
19
+ }
20
+ const gltfLight = lightDefs[nodeLight.light];
21
+ if (!gltfLight) {
22
+ // eslint-disable-next-line no-continue
23
+ continue;
24
+ }
25
+
26
+ const color = (gltfLight.color || [1, 1, 1]) as [number, number, number];
27
+ const intensity = gltfLight.intensity ?? 1;
28
+ const range = gltfLight.range;
29
+
30
+ switch (gltfLight.type) {
31
+ case 'directional':
32
+ lights.push(parseDirectionalLight(node, color, intensity));
33
+ break;
34
+ case 'point':
35
+ lights.push(parsePointLight(node, color, intensity, range));
36
+ break;
37
+ case 'spot':
38
+ lights.push(parsePointLight(node, color, intensity, range));
39
+ break;
40
+ default:
41
+ // Unsupported light type
42
+ break;
43
+ }
44
+ }
45
+
46
+ return lights;
47
+ }
48
+
49
+ function parsePointLight(
50
+ node: GLTFNodePostprocessed,
51
+ color: [number, number, number],
52
+ intensity: number,
53
+ range?: number
54
+ ): PointLight {
55
+ const position: Readonly<[number, number, number]> = node.translation
56
+ ? ([...node.translation] as [number, number, number])
57
+ : ([0, 0, 0] as [number, number, number]);
58
+
59
+ let attenuation: Readonly<[number, number, number]> = [1, 0, 0];
60
+ if (range !== undefined && range > 0) {
61
+ attenuation = [1, 0, 1 / (range * range)] as [number, number, number];
62
+ }
63
+
64
+ return {
65
+ type: 'point',
66
+ position,
67
+ color,
68
+ intensity,
69
+ attenuation
70
+ };
71
+ }
72
+
73
+ function parseDirectionalLight(
74
+ node: GLTFNodePostprocessed,
75
+ color: [number, number, number],
76
+ intensity: number
77
+ ): DirectionalLight {
78
+ let direction: [number, number, number] = [0, 0, -1];
79
+
80
+ if (node.rotation) {
81
+ const orientation = new Matrix4().fromQuaternion(node.rotation);
82
+ direction = orientation.transformDirection([0, 0, -1]) as [number, number, number];
83
+ }
84
+
85
+ return {
86
+ type: 'directional',
87
+ direction,
88
+ color,
89
+ intensity
90
+ };
91
+ }
@@ -3,15 +3,15 @@
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
5
  import {Device, SamplerProps} from '@luma.gl/core';
6
- import {AsyncTexture} from '@luma.gl/engine';
6
+ import {DynamicTexture} from '@luma.gl/engine';
7
7
  import {loadImageTexture} from '@loaders.gl/textures';
8
8
 
9
9
  /** Environment textures for PBR module */
10
10
  export type PBREnvironment = {
11
11
  /** Bi-directional Reflectance Distribution Function (BRDF) lookup table */
12
- brdfLutTexture: AsyncTexture;
13
- diffuseEnvSampler: AsyncTexture;
14
- specularEnvSampler: AsyncTexture;
12
+ brdfLutTexture: DynamicTexture;
13
+ diffuseEnvSampler: DynamicTexture;
14
+ specularEnvSampler: DynamicTexture;
15
15
  };
16
16
 
17
17
  export type PBREnvironmentProps = {
@@ -22,7 +22,7 @@ export type PBREnvironmentProps = {
22
22
 
23
23
  /** Loads textures for PBR environment */
24
24
  export function loadPBREnvironment(device: Device, props: PBREnvironmentProps): PBREnvironment {
25
- const brdfLutTexture = new AsyncTexture(device, {
25
+ const brdfLutTexture = new DynamicTexture(device, {
26
26
  id: 'brdfLUT',
27
27
  sampler: {
28
28
  addressModeU: 'clamp-to-edge',
@@ -84,13 +84,13 @@ function makeCube(
84
84
  getTextureForFace: (dir: number) => Promise<any> | Promise<any>[];
85
85
  sampler: SamplerProps;
86
86
  }
87
- ): AsyncTexture {
87
+ ): DynamicTexture {
88
88
  const data = {};
89
89
  FACES.forEach(face => {
90
90
  // @ts-ignore TODO
91
91
  data[String(face)] = getTextureForFace(face);
92
92
  });
93
- return new AsyncTexture(device, {
93
+ return new DynamicTexture(device, {
94
94
  id,
95
95
  dimension: 'cube',
96
96
  mipmaps: false,