@loaders.gl/gltf 4.2.0-alpha.5 → 4.2.0-beta.1
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 +135 -107
- package/dist/dist.min.js +1 -1
- package/dist/glb-loader.d.ts +22 -2
- package/dist/glb-loader.d.ts.map +1 -1
- package/dist/glb-loader.js +2 -0
- package/dist/glb-writer.d.ts +17 -2
- package/dist/glb-writer.d.ts.map +1 -1
- package/dist/gltf-loader.d.ts +24 -2
- package/dist/gltf-loader.d.ts.map +1 -1
- package/dist/gltf-loader.js +2 -0
- package/dist/gltf-writer.d.ts +2 -18
- package/dist/gltf-writer.d.ts.map +1 -1
- package/dist/gltf-writer.js +2 -2
- package/dist/index.cjs +50 -47
- package/dist/index.cjs.map +2 -2
- package/dist/lib/api/gltf-scenegraph.js +4 -0
- package/dist/lib/api/normalize-gltf-v1.js +15 -16
- package/dist/lib/api/post-process-gltf.js +7 -5
- package/dist/lib/extensions/KHR_texture_transform.js +16 -24
- package/dist/lib/utils/version.js +1 -1
- package/package.json +7 -6
- package/src/glb-loader.ts +4 -2
- package/src/glb-writer.ts +2 -2
- package/src/gltf-loader.ts +4 -2
- package/src/gltf-writer.ts +5 -5
- package/src/lib/extensions/KHR_texture_transform.ts +18 -24
|
@@ -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
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
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
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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
|
|
10
|
-
export const name =
|
|
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(
|
|
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
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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?.[
|
|
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
|
+
export const VERSION = typeof "4.2.0-alpha.6" !== 'undefined' ? "4.2.0-alpha.6" : 'latest';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loaders.gl/gltf",
|
|
3
|
-
"version": "4.2.0-
|
|
3
|
+
"version": "4.2.0-beta.1",
|
|
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-
|
|
47
|
-
"@loaders.gl/images": "4.2.0-
|
|
48
|
-
"@loaders.gl/loader-utils": "4.2.0-
|
|
49
|
-
"@loaders.gl/
|
|
46
|
+
"@loaders.gl/draco": "4.2.0-beta.1",
|
|
47
|
+
"@loaders.gl/images": "4.2.0-beta.1",
|
|
48
|
+
"@loaders.gl/loader-utils": "4.2.0-beta.1",
|
|
49
|
+
"@loaders.gl/schema": "4.2.0-beta.1",
|
|
50
|
+
"@loaders.gl/textures": "4.2.0-beta.1",
|
|
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": "
|
|
56
|
+
"gitHead": "c386a9196516fe3ff24847b40e6c77be039cf905"
|
|
56
57
|
}
|
package/src/glb-loader.ts
CHANGED
|
@@ -16,7 +16,9 @@ export type GLBLoaderOptions = LoaderOptions & {
|
|
|
16
16
|
* GLB Loader -
|
|
17
17
|
* GLB is the binary container format for GLTF
|
|
18
18
|
*/
|
|
19
|
-
export const GLBLoader
|
|
19
|
+
export const GLBLoader = {
|
|
20
|
+
dataType: null as unknown as GLB,
|
|
21
|
+
batchType: null as never,
|
|
20
22
|
name: 'GLB',
|
|
21
23
|
id: 'glb',
|
|
22
24
|
module: 'gltf',
|
|
@@ -31,7 +33,7 @@ export const GLBLoader: LoaderWithParser<GLB, never, GLBLoaderOptions> = {
|
|
|
31
33
|
strict: false // Enables deprecated XVIZ support (illegal CHUNK formats)
|
|
32
34
|
}
|
|
33
35
|
}
|
|
34
|
-
}
|
|
36
|
+
} as const satisfies LoaderWithParser<GLB, never, GLBLoaderOptions>;
|
|
35
37
|
|
|
36
38
|
async function parse(arrayBuffer: ArrayBuffer, options?: GLBLoaderOptions): Promise<GLB> {
|
|
37
39
|
return parseSync(arrayBuffer, options);
|
package/src/glb-writer.ts
CHANGED
|
@@ -16,7 +16,7 @@ export type GLBWriterOptions = WriterOptions & {
|
|
|
16
16
|
* GLB exporter
|
|
17
17
|
* GLB is the binary container format for GLTF
|
|
18
18
|
*/
|
|
19
|
-
export const GLBWriter
|
|
19
|
+
export const GLBWriter = {
|
|
20
20
|
name: 'GLB',
|
|
21
21
|
id: 'glb',
|
|
22
22
|
module: 'gltf',
|
|
@@ -31,7 +31,7 @@ export const GLBWriter: WriterWithEncoder<GLB, never, GLBWriterOptions> = {
|
|
|
31
31
|
|
|
32
32
|
encode: async (glb, options: GLBWriterOptions = {}) => encodeSync(glb, options),
|
|
33
33
|
encodeSync
|
|
34
|
-
}
|
|
34
|
+
} as const satisfies WriterWithEncoder<GLB, never, GLBWriterOptions>;
|
|
35
35
|
|
|
36
36
|
function encodeSync(glb, options) {
|
|
37
37
|
const {byteOffset = 0} = options;
|
package/src/gltf-loader.ts
CHANGED
|
@@ -22,7 +22,9 @@ export type GLTFLoaderOptions = LoaderOptions &
|
|
|
22
22
|
/**
|
|
23
23
|
* GLTF loader
|
|
24
24
|
*/
|
|
25
|
-
export const GLTFLoader
|
|
25
|
+
export const GLTFLoader = {
|
|
26
|
+
dataType: null as unknown as GLTFWithBuffers,
|
|
27
|
+
batchType: null as never,
|
|
26
28
|
name: 'glTF',
|
|
27
29
|
id: 'gltf',
|
|
28
30
|
module: 'gltf',
|
|
@@ -46,7 +48,7 @@ export const GLTFLoader: LoaderWithParser<GLTFWithBuffers, never, GLBLoaderOptio
|
|
|
46
48
|
// common?
|
|
47
49
|
log: console // eslint-disable-line
|
|
48
50
|
}
|
|
49
|
-
}
|
|
51
|
+
} as const satisfies LoaderWithParser<GLTFWithBuffers, never, GLBLoaderOptions>;
|
|
50
52
|
|
|
51
53
|
export async function parse(
|
|
52
54
|
arrayBuffer,
|
package/src/gltf-writer.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {WriterOptions, WriterWithEncoder} from '@loaders.gl/loader-utils';
|
|
2
2
|
import {VERSION} from './lib/utils/version';
|
|
3
3
|
import {encodeGLTFSync} from './lib/encoders/encode-gltf';
|
|
4
4
|
|
|
@@ -11,6 +11,9 @@ export type GLTFWriterOptions = WriterOptions & {
|
|
|
11
11
|
* GLTF exporter
|
|
12
12
|
*/
|
|
13
13
|
export const GLTFWriter = {
|
|
14
|
+
dataType: null as unknown as any,
|
|
15
|
+
batchType: null as never,
|
|
16
|
+
|
|
14
17
|
name: 'glTF',
|
|
15
18
|
id: 'gltf',
|
|
16
19
|
module: 'gltf',
|
|
@@ -25,7 +28,7 @@ export const GLTFWriter = {
|
|
|
25
28
|
|
|
26
29
|
encode: async (gltf, options: GLTFWriterOptions = {}) => encodeSync(gltf, options),
|
|
27
30
|
encodeSync
|
|
28
|
-
}
|
|
31
|
+
} as WriterWithEncoder<any, never, GLTFWriterOptions>;
|
|
29
32
|
|
|
30
33
|
function encodeSync(gltf, options: GLTFWriterOptions = {}) {
|
|
31
34
|
const {byteOffset = 0} = options;
|
|
@@ -38,6 +41,3 @@ function encodeSync(gltf, options: GLTFWriterOptions = {}) {
|
|
|
38
41
|
|
|
39
42
|
return arrayBuffer;
|
|
40
43
|
}
|
|
41
|
-
|
|
42
|
-
// TYPE TESTS - TODO find a better way than exporting junk
|
|
43
|
-
export const _TypecheckGLBLoader: Writer = GLTFWriter;
|
|
@@ -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
|
|
23
|
+
const KHR_TEXTURE_TRANSFORM = 'KHR_texture_transform';
|
|
24
24
|
|
|
25
|
-
export const name =
|
|
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(
|
|
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
|
-
|
|
82
|
-
const
|
|
83
|
-
|
|
84
|
-
|
|
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?.[
|
|
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;
|