@loaders.gl/gltf 4.2.0-alpha.5 → 4.2.0-alpha.6

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.
@@ -22,6 +22,10 @@ function makeDefaultGLTFJson() {
22
22
  * Class for structured access to GLTF data
23
23
  */
24
24
  export class GLTFScenegraph {
25
+ // internal
26
+ gltf;
27
+ sourceBuffers;
28
+ byteLength;
25
29
  // TODO - why is this not GLTFWithBuffers - what happens to images?
26
30
  constructor(gltf) {
27
31
  // Declare locally so
@@ -70,22 +70,21 @@ const GLTF_KEYS = {
70
70
  * Converts (normalizes) glTF v1 to v2
71
71
  */
72
72
  class GLTFV1Normalizer {
73
- constructor() {
74
- this.idToIndexMap = {
75
- animations: {},
76
- accessors: {},
77
- buffers: {},
78
- bufferViews: {},
79
- images: {},
80
- materials: {},
81
- meshes: {},
82
- nodes: {},
83
- samplers: {},
84
- scenes: {},
85
- skins: {},
86
- textures: {}
87
- };
88
- }
73
+ idToIndexMap = {
74
+ animations: {},
75
+ accessors: {},
76
+ buffers: {},
77
+ bufferViews: {},
78
+ images: {},
79
+ materials: {},
80
+ meshes: {},
81
+ nodes: {},
82
+ samplers: {},
83
+ scenes: {},
84
+ skins: {},
85
+ textures: {}
86
+ };
87
+ json;
89
88
  // constructor() {}
90
89
  /**
91
90
  * Convert (normalize) glTF < 2.0 to glTF 2.0
@@ -66,11 +66,13 @@ function getSizeFromAccessorType(type) {
66
66
  return COMPONENTS[type];
67
67
  }
68
68
  class GLTFPostProcessor {
69
- constructor() {
70
- this.baseUri = '';
71
- this.buffers = [];
72
- this.images = [];
73
- }
69
+ baseUri = '';
70
+ // @ts-expect-error
71
+ jsonUnprocessed;
72
+ // @ts-expect-error
73
+ json;
74
+ buffers = [];
75
+ images = [];
74
76
  postProcess(gltf, options = {}) {
75
77
  const { json, buffers = [], images = [] } = gltf;
76
78
  // @ts-expect-error
@@ -6,8 +6,8 @@ import { getAccessorArrayTypeAndLength } from "../gltf-utils/gltf-utils.js";
6
6
  import { BYTES, COMPONENTS } from "../gltf-utils/gltf-constants.js";
7
7
  import { GLTFScenegraph } from "../api/gltf-scenegraph.js";
8
8
  /** Extension name */
9
- const EXT_MESHOPT_TRANSFORM = 'KHR_texture_transform';
10
- export const name = EXT_MESHOPT_TRANSFORM;
9
+ const KHR_TEXTURE_TRANSFORM = 'KHR_texture_transform';
10
+ export const name = KHR_TEXTURE_TRANSFORM;
11
11
  const scratchVector = new Vector3();
12
12
  const scratchRotationMatrix = new Matrix3();
13
13
  const scratchScaleMatrix = new Matrix3();
@@ -18,7 +18,7 @@ const scratchScaleMatrix = new Matrix3();
18
18
  */
19
19
  export async function decode(gltfData, options) {
20
20
  const gltfScenegraph = new GLTFScenegraph(gltfData);
21
- const hasExtension = gltfScenegraph.hasExtension(EXT_MESHOPT_TRANSFORM);
21
+ const hasExtension = gltfScenegraph.hasExtension(KHR_TEXTURE_TRANSFORM);
22
22
  if (!hasExtension || !options.gltf?.loadBuffers) {
23
23
  return;
24
24
  }
@@ -33,28 +33,20 @@ export async function decode(gltfData, options) {
33
33
  * @param gltfData gltf buffers and json
34
34
  */
35
35
  function transformTexCoords(materialIndex, gltfData) {
36
+ const material = gltfData.json.materials?.[materialIndex];
37
+ const materialTextures = [
38
+ material?.pbrMetallicRoughness?.baseColorTexture,
39
+ material?.emissiveTexture,
40
+ material?.normalTexture,
41
+ material?.occlusionTexture,
42
+ material?.pbrMetallicRoughness?.metallicRoughnessTexture
43
+ ];
36
44
  // Save processed texCoords in order no to process the same twice
37
45
  const processedTexCoords = [];
38
- const material = gltfData.json.materials?.[materialIndex];
39
- const baseColorTexture = material?.pbrMetallicRoughness?.baseColorTexture;
40
- if (baseColorTexture) {
41
- transformPrimitives(gltfData, materialIndex, baseColorTexture, processedTexCoords);
42
- }
43
- const emisiveTexture = material?.emissiveTexture;
44
- if (emisiveTexture) {
45
- transformPrimitives(gltfData, materialIndex, emisiveTexture, processedTexCoords);
46
- }
47
- const normalTexture = material?.normalTexture;
48
- if (normalTexture) {
49
- transformPrimitives(gltfData, materialIndex, normalTexture, processedTexCoords);
50
- }
51
- const occlusionTexture = material?.occlusionTexture;
52
- if (occlusionTexture) {
53
- transformPrimitives(gltfData, materialIndex, occlusionTexture, processedTexCoords);
54
- }
55
- const metallicRoughnessTexture = material?.pbrMetallicRoughness?.metallicRoughnessTexture;
56
- if (metallicRoughnessTexture) {
57
- transformPrimitives(gltfData, materialIndex, metallicRoughnessTexture, processedTexCoords);
46
+ for (const textureInfo of materialTextures) {
47
+ if (textureInfo && textureInfo?.extensions?.[KHR_TEXTURE_TRANSFORM]) {
48
+ transformPrimitives(gltfData, materialIndex, textureInfo, processedTexCoords);
49
+ }
58
50
  }
59
51
  }
60
52
  /**
@@ -86,7 +78,7 @@ function transformPrimitives(gltfData, materialIndex, texture, processedTexCoord
86
78
  * @returns texCoord couple and transformation matrix
87
79
  */
88
80
  function getTransformParameters(texture, processedTexCoords) {
89
- const textureInfo = texture.extensions?.[EXT_MESHOPT_TRANSFORM];
81
+ const textureInfo = texture.extensions?.[KHR_TEXTURE_TRANSFORM];
90
82
  const { texCoord: originalTexCoord = 0 } = texture;
91
83
  // If texCoord is not set in the extension, original attribute data will be replaced
92
84
  const { texCoord = originalTexCoord } = textureInfo;
@@ -1,4 +1,4 @@
1
1
  // Version constant cannot be imported, it needs to correspond to the build version of **this** module.
2
2
  // __VERSION__ is injected by babel-plugin-version-inline
3
3
  // @ts-ignore TS2304: Cannot find name '__VERSION__'.
4
- export const VERSION = typeof "4.2.0-alpha.4" !== 'undefined' ? "4.2.0-alpha.4" : 'latest';
4
+ export const VERSION = typeof "4.2.0-alpha.5" !== 'undefined' ? "4.2.0-alpha.5" : 'latest';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loaders.gl/gltf",
3
- "version": "4.2.0-alpha.5",
3
+ "version": "4.2.0-alpha.6",
4
4
  "description": "Framework-independent loader for the glTF format",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -43,14 +43,15 @@
43
43
  "build-bundle-dev": "ocular-bundle ./bundle.ts --env=dev --output=dist/dist.dev.js"
44
44
  },
45
45
  "dependencies": {
46
- "@loaders.gl/draco": "4.2.0-alpha.5",
47
- "@loaders.gl/images": "4.2.0-alpha.5",
48
- "@loaders.gl/loader-utils": "4.2.0-alpha.5",
49
- "@loaders.gl/textures": "4.2.0-alpha.5",
46
+ "@loaders.gl/draco": "4.2.0-alpha.6",
47
+ "@loaders.gl/images": "4.2.0-alpha.6",
48
+ "@loaders.gl/loader-utils": "4.2.0-alpha.6",
49
+ "@loaders.gl/schema": "4.2.0-alpha.6",
50
+ "@loaders.gl/textures": "4.2.0-alpha.6",
50
51
  "@math.gl/core": "^4.0.0"
51
52
  },
52
53
  "peerDependencies": {
53
54
  "@loaders.gl/core": "^4.0.0"
54
55
  },
55
- "gitHead": "32d95a81971f104e4dfeb88ab57065f05321a76a"
56
+ "gitHead": "37bd8ca71763529f18727ee4bf29dd176aa914ca"
56
57
  }
@@ -20,9 +20,9 @@ import {} from '../types/gltf-json-schema';
20
20
  import {GLTFScenegraph} from '../api/gltf-scenegraph';
21
21
 
22
22
  /** Extension name */
23
- const EXT_MESHOPT_TRANSFORM = 'KHR_texture_transform';
23
+ const KHR_TEXTURE_TRANSFORM = 'KHR_texture_transform';
24
24
 
25
- export const name = EXT_MESHOPT_TRANSFORM;
25
+ export const name = KHR_TEXTURE_TRANSFORM;
26
26
 
27
27
  const scratchVector = new Vector3();
28
28
  const scratchRotationMatrix = new Matrix3();
@@ -60,7 +60,7 @@ type TransformParameters = {
60
60
  */
61
61
  export async function decode(gltfData: GLTFWithBuffers, options: GLTFLoaderOptions) {
62
62
  const gltfScenegraph = new GLTFScenegraph(gltfData);
63
- const hasExtension = gltfScenegraph.hasExtension(EXT_MESHOPT_TRANSFORM);
63
+ const hasExtension = gltfScenegraph.hasExtension(KHR_TEXTURE_TRANSFORM);
64
64
  if (!hasExtension || !options.gltf?.loadBuffers) {
65
65
  return;
66
66
  }
@@ -76,28 +76,22 @@ export async function decode(gltfData: GLTFWithBuffers, options: GLTFLoaderOptio
76
76
  * @param gltfData gltf buffers and json
77
77
  */
78
78
  function transformTexCoords(materialIndex: number, gltfData: GLTFWithBuffers): void {
79
+ const material = gltfData.json.materials?.[materialIndex];
80
+ const materialTextures = [
81
+ material?.pbrMetallicRoughness?.baseColorTexture,
82
+ material?.emissiveTexture,
83
+ material?.normalTexture,
84
+ material?.occlusionTexture,
85
+ material?.pbrMetallicRoughness?.metallicRoughnessTexture
86
+ ];
87
+
79
88
  // Save processed texCoords in order no to process the same twice
80
89
  const processedTexCoords: [number, number][] = [];
81
- const material = gltfData.json.materials?.[materialIndex];
82
- const baseColorTexture = material?.pbrMetallicRoughness?.baseColorTexture;
83
- if (baseColorTexture) {
84
- transformPrimitives(gltfData, materialIndex, baseColorTexture, processedTexCoords);
85
- }
86
- const emisiveTexture = material?.emissiveTexture;
87
- if (emisiveTexture) {
88
- transformPrimitives(gltfData, materialIndex, emisiveTexture, processedTexCoords);
89
- }
90
- const normalTexture = material?.normalTexture;
91
- if (normalTexture) {
92
- transformPrimitives(gltfData, materialIndex, normalTexture, processedTexCoords);
93
- }
94
- const occlusionTexture = material?.occlusionTexture;
95
- if (occlusionTexture) {
96
- transformPrimitives(gltfData, materialIndex, occlusionTexture, processedTexCoords);
97
- }
98
- const metallicRoughnessTexture = material?.pbrMetallicRoughness?.metallicRoughnessTexture;
99
- if (metallicRoughnessTexture) {
100
- transformPrimitives(gltfData, materialIndex, metallicRoughnessTexture, processedTexCoords);
90
+
91
+ for (const textureInfo of materialTextures) {
92
+ if (textureInfo && textureInfo?.extensions?.[KHR_TEXTURE_TRANSFORM]) {
93
+ transformPrimitives(gltfData, materialIndex, textureInfo, processedTexCoords);
94
+ }
101
95
  }
102
96
  }
103
97
 
@@ -139,7 +133,7 @@ function getTransformParameters(
139
133
  texture: CompoundGLTFTextureInfo,
140
134
  processedTexCoords: [number, number][]
141
135
  ): TransformParameters | null {
142
- const textureInfo = texture.extensions?.[EXT_MESHOPT_TRANSFORM];
136
+ const textureInfo = texture.extensions?.[KHR_TEXTURE_TRANSFORM];
143
137
  const {texCoord: originalTexCoord = 0} = texture;
144
138
  // If texCoord is not set in the extension, original attribute data will be replaced
145
139
  const {texCoord = originalTexCoord} = textureInfo;