@needle-tools/gltf-build-pipeline 2.13.0 → 2.13.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/CHANGELOG.md +520 -517
- package/README.md +38 -38
- package/dist/cache/cache.d.ts +55 -55
- package/dist/cache/cache.js +326 -326
- package/dist/cache/index.d.ts +1 -1
- package/dist/cache/index.js +1 -1
- package/dist/cli/index.d.ts +2 -2
- package/dist/cli/index.js +198 -198
- package/dist/config/index.d.ts +53 -53
- package/dist/config/index.js +152 -152
- package/dist/constants.d.ts +7 -7
- package/dist/constants.js +7 -7
- package/dist/extensions/NEEDLE_compression_texture/NEEDLE_compression_texture.d.ts +24 -24
- package/dist/extensions/NEEDLE_compression_texture/NEEDLE_compression_texture.js +54 -54
- package/dist/extensions/NEEDLE_compression_texture/index.d.ts +1 -1
- package/dist/extensions/NEEDLE_compression_texture/index.js +1 -1
- package/dist/extensions/NEEDLE_mesh_compression/NEEDLE_mesh_compression.d.ts +27 -27
- package/dist/extensions/NEEDLE_mesh_compression/NEEDLE_mesh_compression.js +88 -88
- package/dist/extensions/NEEDLE_mesh_compression/index.d.ts +1 -1
- package/dist/extensions/NEEDLE_mesh_compression/index.js +1 -1
- package/dist/extensions/NEEDLE_opaque/NEEDLE_opaque.d.ts +27 -27
- package/dist/extensions/NEEDLE_opaque/NEEDLE_opaque.js +980 -980
- package/dist/extensions/NEEDLE_opaque/index.d.ts +3 -3
- package/dist/extensions/NEEDLE_opaque/index.js +30 -30
- package/dist/extensions/NEEDLE_progressive/NEEDLE_progressive.d.ts +48 -48
- package/dist/extensions/NEEDLE_progressive/NEEDLE_progressive.js +69 -69
- package/dist/extensions/NEEDLE_progressive/index.d.ts +1 -1
- package/dist/extensions/NEEDLE_progressive/index.js +1 -1
- package/dist/extensions/NEEDLE_progressive_mesh_settings/index.d.ts +23 -23
- package/dist/extensions/NEEDLE_progressive_mesh_settings/index.js +41 -41
- package/dist/extensions/NEEDLE_progressive_texture_settings/index.d.ts +25 -25
- package/dist/extensions/NEEDLE_progressive_texture_settings/index.js +38 -38
- package/dist/extensions/index.d.ts +7 -7
- package/dist/extensions/index.js +17 -17
- package/dist/extensions/utils.d.ts +6 -6
- package/dist/extensions/utils.js +72 -72
- package/dist/functions/weld.3.d.ts +76 -76
- package/dist/functions/weld.3.js +414 -414
- package/dist/index.d.ts +8 -8
- package/dist/index.js +8 -8
- package/dist/scripts/index.d.ts +2 -2
- package/dist/scripts/index.js +2 -2
- package/dist/scripts/pack-gltf.d.ts +15 -15
- package/dist/scripts/pack-gltf.js +135 -133
- package/dist/scripts/stats.d.ts +2 -2
- package/dist/scripts/stats.js +19 -19
- package/dist/transforms/index.d.ts +9 -9
- package/dist/transforms/index.js +9 -9
- package/dist/transforms/needle_animation_transform.d.ts +2 -2
- package/dist/transforms/needle_animation_transform.js +5 -5
- package/dist/transforms/needle_asset.d.ts +3 -3
- package/dist/transforms/needle_asset.js +50 -50
- package/dist/transforms/needle_common.d.ts +17 -17
- package/dist/transforms/needle_common.js +1 -1
- package/dist/transforms/needle_mesh_transform.d.ts +15 -15
- package/dist/transforms/needle_mesh_transform.js +223 -223
- package/dist/transforms/needle_progressive.d.ts +45 -45
- package/dist/transforms/needle_progressive.js +1043 -1043
- package/dist/transforms/needle_texture_transform.d.ts +13 -13
- package/dist/transforms/needle_texture_transform.js +257 -257
- package/dist/transforms/needle_toktx.d.ts +26 -26
- package/dist/transforms/needle_toktx.js +243 -243
- package/dist/transforms/needle_webp.d.ts +15 -15
- package/dist/transforms/needle_webp.js +53 -53
- package/dist/transforms/toktx.d.ts +52 -52
- package/dist/transforms/toktx.js +221 -221
- package/dist/transforms/toktx_types.d.ts +78 -78
- package/dist/transforms/toktx_types.js +62 -62
- package/dist/transforms/util.d.ts +21 -21
- package/dist/transforms/util.js +90 -90
- package/dist/utils/compression_utils.d.ts +2 -2
- package/dist/utils/compression_utils.js +6 -6
- package/dist/utils/fileutils.d.ts +19 -19
- package/dist/utils/fileutils.js +177 -177
- package/dist/utils/guid.d.ts +1 -1
- package/dist/utils/guid.js +5 -5
- package/dist/utils/index.d.ts +10 -10
- package/dist/utils/index.js +10 -10
- package/dist/utils/merge.d.ts +12 -12
- package/dist/utils/merge.js +31 -31
- package/dist/utils/mesh.d.ts +13 -13
- package/dist/utils/mesh.js +124 -124
- package/dist/utils/nodeio.d.ts +6 -6
- package/dist/utils/nodeio.js +86 -86
- package/dist/utils/stats.d.ts +70 -70
- package/dist/utils/stats.js +258 -258
- package/dist/utils/texture.d.ts +5 -5
- package/dist/utils/texture.js +14 -14
- package/dist/utils/validate.d.ts +5 -5
- package/dist/utils/validate.js +17 -17
- package/dist/utils/version.d.ts +1 -1
- package/dist/utils/version.gen.d.ts +1 -1
- package/dist/utils/version.gen.js +1 -1
- package/dist/utils/version.js +4 -4
- package/package.json +79 -79
- package/scripts/clear-caches.mjs +3 -3
- package/scripts/defaults.mjs +11 -11
- package/scripts/fileutils.mjs +5 -5
- package/scripts/index.mjs +41 -41
- package/scripts/limit-caches.mjs +3 -3
- package/scripts/make-progressive.mjs +16 -16
- package/scripts/pack-gltf.mjs +106 -106
- package/tsconfig.json +19 -19
package/dist/extensions/utils.js
CHANGED
|
@@ -1,72 +1,72 @@
|
|
|
1
|
-
import { WriterContext } from '@gltf-transform/core';
|
|
2
|
-
export function tryGetInArray(arr, index) {
|
|
3
|
-
if (index === undefined)
|
|
4
|
-
return null;
|
|
5
|
-
if (Array.isArray(arr) && arr.length > index) {
|
|
6
|
-
return arr[index];
|
|
7
|
-
}
|
|
8
|
-
return null;
|
|
9
|
-
}
|
|
10
|
-
export function writeExtension(prop, name, ext) {
|
|
11
|
-
if (prop === null)
|
|
12
|
-
return;
|
|
13
|
-
if (ext) {
|
|
14
|
-
if (!prop.extensions) {
|
|
15
|
-
prop.extensions = {};
|
|
16
|
-
}
|
|
17
|
-
prop.extensions[name] = ext;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
// Texture index in context.textures
|
|
21
|
-
export function getTexture(context, tex) {
|
|
22
|
-
if (!context.jsonDoc.json.images)
|
|
23
|
-
return null;
|
|
24
|
-
if (tex.source !== undefined) {
|
|
25
|
-
return context.textures[tex.source];
|
|
26
|
-
}
|
|
27
|
-
else {
|
|
28
|
-
for (const key of Object.keys(tex.extensions)) {
|
|
29
|
-
const ext = tex.extensions[key];
|
|
30
|
-
if (ext && typeof ext["source"] === "number") {
|
|
31
|
-
return context.textures[ext["source"]];
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
console.log("Could not fnd texture", tex);
|
|
36
|
-
return null;
|
|
37
|
-
}
|
|
38
|
-
export function getTextureDefinition(context, tex) {
|
|
39
|
-
const textureDefinitions = context.jsonDoc.json.textures;
|
|
40
|
-
if (!textureDefinitions)
|
|
41
|
-
return null;
|
|
42
|
-
if (context instanceof WriterContext) {
|
|
43
|
-
// we use the texture image map to find the texture definition to write the extension to
|
|
44
|
-
const textureImageIndexMap = context.imageIndexMap;
|
|
45
|
-
// get the image this texture is using
|
|
46
|
-
const imageIndex = textureImageIndexMap.get(tex);
|
|
47
|
-
// find the texture definition that uses this image and add the extension
|
|
48
|
-
for (const def of textureDefinitions) {
|
|
49
|
-
if (def.source === imageIndex) {
|
|
50
|
-
return def;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
else {
|
|
55
|
-
const textureIndex = context.textures.indexOf(tex);
|
|
56
|
-
for (let i = 0; i < textureDefinitions.length; i++) {
|
|
57
|
-
const textureDef = textureDefinitions[i];
|
|
58
|
-
if (textureDef.source === textureIndex) {
|
|
59
|
-
return textureDef;
|
|
60
|
-
}
|
|
61
|
-
else if (textureDef.extensions) {
|
|
62
|
-
for (const key of Object.keys(textureDef.extensions)) {
|
|
63
|
-
const ext = textureDef.extensions[key];
|
|
64
|
-
if (ext && ext["source"] === textureIndex) {
|
|
65
|
-
return textureDef;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
return null;
|
|
72
|
-
}
|
|
1
|
+
import { WriterContext } from '@gltf-transform/core';
|
|
2
|
+
export function tryGetInArray(arr, index) {
|
|
3
|
+
if (index === undefined)
|
|
4
|
+
return null;
|
|
5
|
+
if (Array.isArray(arr) && arr.length > index) {
|
|
6
|
+
return arr[index];
|
|
7
|
+
}
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
10
|
+
export function writeExtension(prop, name, ext) {
|
|
11
|
+
if (prop === null)
|
|
12
|
+
return;
|
|
13
|
+
if (ext) {
|
|
14
|
+
if (!prop.extensions) {
|
|
15
|
+
prop.extensions = {};
|
|
16
|
+
}
|
|
17
|
+
prop.extensions[name] = ext;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
// Texture index in context.textures
|
|
21
|
+
export function getTexture(context, tex) {
|
|
22
|
+
if (!context.jsonDoc.json.images)
|
|
23
|
+
return null;
|
|
24
|
+
if (tex.source !== undefined) {
|
|
25
|
+
return context.textures[tex.source];
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
for (const key of Object.keys(tex.extensions)) {
|
|
29
|
+
const ext = tex.extensions[key];
|
|
30
|
+
if (ext && typeof ext["source"] === "number") {
|
|
31
|
+
return context.textures[ext["source"]];
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
console.log("Could not fnd texture", tex);
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
export function getTextureDefinition(context, tex) {
|
|
39
|
+
const textureDefinitions = context.jsonDoc.json.textures;
|
|
40
|
+
if (!textureDefinitions)
|
|
41
|
+
return null;
|
|
42
|
+
if (context instanceof WriterContext) {
|
|
43
|
+
// we use the texture image map to find the texture definition to write the extension to
|
|
44
|
+
const textureImageIndexMap = context.imageIndexMap;
|
|
45
|
+
// get the image this texture is using
|
|
46
|
+
const imageIndex = textureImageIndexMap.get(tex);
|
|
47
|
+
// find the texture definition that uses this image and add the extension
|
|
48
|
+
for (const def of textureDefinitions) {
|
|
49
|
+
if (def.source === imageIndex) {
|
|
50
|
+
return def;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
const textureIndex = context.textures.indexOf(tex);
|
|
56
|
+
for (let i = 0; i < textureDefinitions.length; i++) {
|
|
57
|
+
const textureDef = textureDefinitions[i];
|
|
58
|
+
if (textureDef.source === textureIndex) {
|
|
59
|
+
return textureDef;
|
|
60
|
+
}
|
|
61
|
+
else if (textureDef.extensions) {
|
|
62
|
+
for (const key of Object.keys(textureDef.extensions)) {
|
|
63
|
+
const ext = textureDef.extensions[key];
|
|
64
|
+
if (ext && ext["source"] === textureIndex) {
|
|
65
|
+
return textureDef;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
@@ -1,76 +1,76 @@
|
|
|
1
|
-
import { Document, Primitive, Transform } from '@gltf-transform/core';
|
|
2
|
-
/** @hidden */
|
|
3
|
-
export declare function createIndices(count: number, maxIndex?: number): Uint16Array | Uint32Array;
|
|
4
|
-
export declare function formatLong(x: number): string;
|
|
5
|
-
export declare function formatDelta(a: number, b: number, decimals?: number): string;
|
|
6
|
-
export declare function formatDeltaOp(a: number, b: number): string;
|
|
7
|
-
export declare function cleanPrimitive(prim: Primitive): void;
|
|
8
|
-
/** Options for the {@link weld} function. */
|
|
9
|
-
export interface WeldOptions {
|
|
10
|
-
/** Tolerance for vertex positions, as a fraction of primitive AABB. */
|
|
11
|
-
tolerance?: number;
|
|
12
|
-
/** Tolerance for vertex normals, in radians. */
|
|
13
|
-
toleranceNormal?: number;
|
|
14
|
-
/** Whether to overwrite existing indices. */
|
|
15
|
-
overwrite?: boolean;
|
|
16
|
-
/** Enables a more thorough, but slower, search for vertices to weld. */
|
|
17
|
-
exhaustive?: boolean;
|
|
18
|
-
}
|
|
19
|
-
export declare const WELD_DEFAULTS: Required<WeldOptions>;
|
|
20
|
-
/**
|
|
21
|
-
* Index {@link Primitive Primitives} and (optionally) merge similar vertices. When merged
|
|
22
|
-
* and indexed, data is shared more efficiently between vertices. File size can
|
|
23
|
-
* be reduced, and the GPU can sometimes use the vertex cache more efficiently.
|
|
24
|
-
*
|
|
25
|
-
* When welding, the 'tolerance' threshold determines which vertices qualify for
|
|
26
|
-
* welding based on distance between the vertices as a fraction of the primitive's
|
|
27
|
-
* bounding box (AABB). For example, tolerance=0.01 welds vertices within +/-1%
|
|
28
|
-
* of the AABB's longest dimension. Other vertex attributes are also compared
|
|
29
|
-
* during welding, with attribute-specific thresholds. For `tolerance=0`, geometry
|
|
30
|
-
* is indexed in place, without merging.
|
|
31
|
-
*
|
|
32
|
-
* To preserve visual appearance consistently, use low `toleranceNormal` thresholds
|
|
33
|
-
* around 0.1 (±3º). To pre-processing a scene before simplification or LOD creation,
|
|
34
|
-
* use higher thresholds around 0.5 (±30º).
|
|
35
|
-
*
|
|
36
|
-
* Example:
|
|
37
|
-
*
|
|
38
|
-
* ```javascript
|
|
39
|
-
* import { weld } from '@gltf-transform/functions';
|
|
40
|
-
*
|
|
41
|
-
* await document.transform(
|
|
42
|
-
* weld({ tolerance: 0.001, toleranceNormal: 0.5 })
|
|
43
|
-
* );
|
|
44
|
-
* ```
|
|
45
|
-
*
|
|
46
|
-
* @category Transforms
|
|
47
|
-
*/
|
|
48
|
-
export declare function weld(_options?: WeldOptions): Transform;
|
|
49
|
-
/**
|
|
50
|
-
* Index a {@link Primitive} and (optionally) weld similar vertices. When merged
|
|
51
|
-
* and indexed, data is shared more efficiently between vertices. File size can
|
|
52
|
-
* be reduced, and the GPU can sometimes use the vertex cache more efficiently.
|
|
53
|
-
*
|
|
54
|
-
* When welding, the 'tolerance' threshold determines which vertices qualify for
|
|
55
|
-
* welding based on distance between the vertices as a fraction of the primitive's
|
|
56
|
-
* bounding box (AABB). For example, tolerance=0.01 welds vertices within +/-1%
|
|
57
|
-
* of the AABB's longest dimension. Other vertex attributes are also compared
|
|
58
|
-
* during welding, with attribute-specific thresholds. For tolerance=0, geometry
|
|
59
|
-
* is indexed in place, without merging.
|
|
60
|
-
*
|
|
61
|
-
* Example:
|
|
62
|
-
*
|
|
63
|
-
* ```javascript
|
|
64
|
-
* import { weldPrimitive } from '@gltf-transform/functions';
|
|
65
|
-
*
|
|
66
|
-
* const mesh = document.getRoot().listMeshes()
|
|
67
|
-
* .find((mesh) => mesh.getName() === 'Gizmo');
|
|
68
|
-
*
|
|
69
|
-
* for (const prim of mesh.listPrimitives()) {
|
|
70
|
-
* weldPrimitive(prim, {tolerance: 0.0001});
|
|
71
|
-
* }
|
|
72
|
-
* ```
|
|
73
|
-
*
|
|
74
|
-
* @privateRemarks TODO(v4): Remove the "Document" parameter.
|
|
75
|
-
*/
|
|
76
|
-
export declare function weldPrimitive(a: Document | Primitive, b?: Primitive | WeldOptions, c?: Required<WeldOptions>): void;
|
|
1
|
+
import { Document, Primitive, Transform } from '@gltf-transform/core';
|
|
2
|
+
/** @hidden */
|
|
3
|
+
export declare function createIndices(count: number, maxIndex?: number): Uint16Array | Uint32Array;
|
|
4
|
+
export declare function formatLong(x: number): string;
|
|
5
|
+
export declare function formatDelta(a: number, b: number, decimals?: number): string;
|
|
6
|
+
export declare function formatDeltaOp(a: number, b: number): string;
|
|
7
|
+
export declare function cleanPrimitive(prim: Primitive): void;
|
|
8
|
+
/** Options for the {@link weld} function. */
|
|
9
|
+
export interface WeldOptions {
|
|
10
|
+
/** Tolerance for vertex positions, as a fraction of primitive AABB. */
|
|
11
|
+
tolerance?: number;
|
|
12
|
+
/** Tolerance for vertex normals, in radians. */
|
|
13
|
+
toleranceNormal?: number;
|
|
14
|
+
/** Whether to overwrite existing indices. */
|
|
15
|
+
overwrite?: boolean;
|
|
16
|
+
/** Enables a more thorough, but slower, search for vertices to weld. */
|
|
17
|
+
exhaustive?: boolean;
|
|
18
|
+
}
|
|
19
|
+
export declare const WELD_DEFAULTS: Required<WeldOptions>;
|
|
20
|
+
/**
|
|
21
|
+
* Index {@link Primitive Primitives} and (optionally) merge similar vertices. When merged
|
|
22
|
+
* and indexed, data is shared more efficiently between vertices. File size can
|
|
23
|
+
* be reduced, and the GPU can sometimes use the vertex cache more efficiently.
|
|
24
|
+
*
|
|
25
|
+
* When welding, the 'tolerance' threshold determines which vertices qualify for
|
|
26
|
+
* welding based on distance between the vertices as a fraction of the primitive's
|
|
27
|
+
* bounding box (AABB). For example, tolerance=0.01 welds vertices within +/-1%
|
|
28
|
+
* of the AABB's longest dimension. Other vertex attributes are also compared
|
|
29
|
+
* during welding, with attribute-specific thresholds. For `tolerance=0`, geometry
|
|
30
|
+
* is indexed in place, without merging.
|
|
31
|
+
*
|
|
32
|
+
* To preserve visual appearance consistently, use low `toleranceNormal` thresholds
|
|
33
|
+
* around 0.1 (±3º). To pre-processing a scene before simplification or LOD creation,
|
|
34
|
+
* use higher thresholds around 0.5 (±30º).
|
|
35
|
+
*
|
|
36
|
+
* Example:
|
|
37
|
+
*
|
|
38
|
+
* ```javascript
|
|
39
|
+
* import { weld } from '@gltf-transform/functions';
|
|
40
|
+
*
|
|
41
|
+
* await document.transform(
|
|
42
|
+
* weld({ tolerance: 0.001, toleranceNormal: 0.5 })
|
|
43
|
+
* );
|
|
44
|
+
* ```
|
|
45
|
+
*
|
|
46
|
+
* @category Transforms
|
|
47
|
+
*/
|
|
48
|
+
export declare function weld(_options?: WeldOptions): Transform;
|
|
49
|
+
/**
|
|
50
|
+
* Index a {@link Primitive} and (optionally) weld similar vertices. When merged
|
|
51
|
+
* and indexed, data is shared more efficiently between vertices. File size can
|
|
52
|
+
* be reduced, and the GPU can sometimes use the vertex cache more efficiently.
|
|
53
|
+
*
|
|
54
|
+
* When welding, the 'tolerance' threshold determines which vertices qualify for
|
|
55
|
+
* welding based on distance between the vertices as a fraction of the primitive's
|
|
56
|
+
* bounding box (AABB). For example, tolerance=0.01 welds vertices within +/-1%
|
|
57
|
+
* of the AABB's longest dimension. Other vertex attributes are also compared
|
|
58
|
+
* during welding, with attribute-specific thresholds. For tolerance=0, geometry
|
|
59
|
+
* is indexed in place, without merging.
|
|
60
|
+
*
|
|
61
|
+
* Example:
|
|
62
|
+
*
|
|
63
|
+
* ```javascript
|
|
64
|
+
* import { weldPrimitive } from '@gltf-transform/functions';
|
|
65
|
+
*
|
|
66
|
+
* const mesh = document.getRoot().listMeshes()
|
|
67
|
+
* .find((mesh) => mesh.getName() === 'Gizmo');
|
|
68
|
+
*
|
|
69
|
+
* for (const prim of mesh.listPrimitives()) {
|
|
70
|
+
* weldPrimitive(prim, {tolerance: 0.0001});
|
|
71
|
+
* }
|
|
72
|
+
* ```
|
|
73
|
+
*
|
|
74
|
+
* @privateRemarks TODO(v4): Remove the "Document" parameter.
|
|
75
|
+
*/
|
|
76
|
+
export declare function weldPrimitive(a: Document | Primitive, b?: Primitive | WeldOptions, c?: Required<WeldOptions>): void;
|