@needle-tools/gltf-build-pipeline 1.1.2 → 1.1.4

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 CHANGED
@@ -4,6 +4,12 @@ All notable changes to this package will be documented in this file.
4
4
  The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
5
5
  and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
6
6
 
7
+ ## [1.1.4] - 2023-06-09
8
+ - fix: progressive texture transform didnt pass mesh compression setting through
9
+
10
+ ## [1.1.3] - 2023-05-24
11
+ - minor change adding info about reduced size after processing gltf files
12
+
7
13
  ## [1.1.2] - 2023-05-24
8
14
  - fix: wasm out of memory error caused by starting to many compression processes at once
9
15
 
@@ -1,22 +1,11 @@
1
1
  import { createTransform } from '@gltf-transform/functions';
2
- import { existsSync, readFileSync } from 'fs';
3
- let version = undefined;
2
+ import { getVersion } from '../index.js';
4
3
  export function needle_asset() {
5
4
  return createTransform("needle_asset_transform", (document) => {
6
5
  const root = document.getRoot();
7
6
  const asset = root.getAsset();
8
7
  if (asset) {
9
- if (version === undefined) {
10
- version = null;
11
- const path = process.cwd() + "/package.json";
12
- if (existsSync(path)) {
13
- const packageJson = readFileSync(path, "utf8");
14
- const packageVersion = JSON.parse(packageJson).version;
15
- version = packageVersion ?? null;
16
- }
17
- else
18
- console.log("Could not find package.json at " + path);
19
- }
8
+ const version = getVersion();
20
9
  if (!asset.generator.startsWith("Needle glTF Build Pipeline")) {
21
10
  asset.generator = "Needle glTF Build Pipeline";
22
11
  if (version?.length > 0) {
@@ -30,6 +30,7 @@ async function applyMeshCompression(document, _context) {
30
30
  }
31
31
  }
32
32
  // by default we still want to run draco if the root doesnt have a compression model configured
33
+ console.log(`[${NAME}]: No compression model configured → will apply draco mesh compression`);
33
34
  return draco()(document, _context);
34
35
  }
35
36
  async function simplifierTransform(document, _context, _options) {
@@ -17,7 +17,7 @@ function registerExtensions(io) {
17
17
  //@ts-ignore
18
18
  createOpaqueExtension(NEEDLE_compression_texture.EXTENSION_NAME, PropertyType.TEXTURE),
19
19
  //@ts-ignore
20
- createOpaqueExtension(NEEDLE_mesh_compression.EXTENSION_NAME, [PropertyType.MESH, PropertyType.PRIMITIVE])
20
+ createOpaqueExtension(NEEDLE_mesh_compression.EXTENSION_NAME, [PropertyType.ROOT, PropertyType.MESH, PropertyType.PRIMITIVE])
21
21
  ]);
22
22
  }
23
23
  export async function make_progressive(opts) {
@@ -1 +1,2 @@
1
1
  export * from "./fileutils.js";
2
+ export * from "./version.js";
@@ -1 +1,2 @@
1
1
  export * from "./fileutils.js";
2
+ export * from "./version.js";
@@ -0,0 +1 @@
1
+ export declare function getVersion(): string;
@@ -0,0 +1,16 @@
1
+ import { existsSync, readFileSync } from 'fs';
2
+ let version = undefined;
3
+ export function getVersion() {
4
+ if (version === undefined) {
5
+ version = null;
6
+ const path = process.cwd() + "/package.json";
7
+ if (existsSync(path)) {
8
+ const packageJson = readFileSync(path, "utf8");
9
+ const packageVersion = JSON.parse(packageJson).version;
10
+ version = packageVersion ?? null;
11
+ }
12
+ else
13
+ console.log("Could not find package.json at " + path);
14
+ }
15
+ return version;
16
+ }
@@ -1,7 +1,10 @@
1
+ import { getVersion } from './dist/index.js';
1
2
  import { make_progressive } from './dist/transforms/needle_progressive.js';
2
3
 
3
4
  const args = process.argv;
4
5
 
6
+ console.log(`[Needle Build Pipeline] transform to progressive — version ${getVersion()}`)
7
+
5
8
  make_progressive({
6
9
  path: args,
7
10
  debug: args.includes("debug"),
package/pack-gltf.mjs CHANGED
@@ -14,6 +14,9 @@ import { needle_animation_transform } from "./dist/transforms/needle_animation_t
14
14
  import { foreachGLTF } from './fileutils.mjs';
15
15
  import { needle_asset } from './dist/transforms/needle_asset.js';
16
16
  import { MeshoptDecoder, MeshoptEncoder } from 'meshoptimizer';
17
+ import { getVersion } from './dist/index.js';
18
+
19
+ console.log(`[Needle Build Pipeline] pack glTF — version ${getVersion()}`)
17
20
 
18
21
  const args = process.argv;
19
22
  const showHelp = args.includes("help");
@@ -72,6 +75,7 @@ const packedFiles = new Set();
72
75
  let totalGPUMemoryInMB = 0;
73
76
  let totalFilesProcessed = 0;
74
77
  let totalFileSizeInMB = 0;
78
+ let totalFileSizeInMBBefore = 0;
75
79
 
76
80
  async function packFile(file) {
77
81
  if (!existsSync(file)) {
@@ -87,7 +91,7 @@ async function packFile(file) {
87
91
  console.log("→ Begin packing: " + file);
88
92
 
89
93
  try {
90
- const prevSize = statSync(file).size;
94
+ const prevSizeInMB = statSync(file).size / 1024 / 1024;
91
95
  const startTime = Date.now();
92
96
  const io = new NodeIO()
93
97
  .registerExtensions(ALL_EXTENSIONS)
@@ -123,10 +127,11 @@ async function packFile(file) {
123
127
  const sizeInMB = statSync(file).size / 1024 / 1024;
124
128
  const filename = path.basename(file);
125
129
  const gpuMemoryInMB = totalGPUTextureMemmory / 1024 / 1024;
126
- console.log(`← Compressing done in ${(duration / 1000).toFixed(1)} sec, ${(prevSize / 1024 / 1024).toFixed(1)} MB → ${sizeInMB.toFixed(1)} MB (GPU: ${gpuMemoryInMB.toFixed(1)} MB textures): ${filename} at ${file}`);
130
+ console.log(`← Compressing done in ${(duration / 1000).toFixed(1)} sec, ${prevSizeInMB.toFixed(1)} MB → ${sizeInMB.toFixed(1)} MB (GPU: ${gpuMemoryInMB.toFixed(1)} MB textures): ${filename} at ${file}`);
127
131
 
128
132
  totalFilesProcessed++;
129
133
  totalFileSizeInMB += sizeInMB;
134
+ totalFileSizeInMBBefore += prevSizeInMB;
130
135
  totalGPUMemoryInMB += gpuMemoryInMB;
131
136
  return true;
132
137
  }
@@ -137,11 +142,13 @@ async function packFile(file) {
137
142
  }
138
143
  }
139
144
 
145
+
146
+
140
147
  let startTime = Date.now();
141
148
  foreachGLTF(process.argv, async (file) => {
142
149
  await packFile(file);
143
150
  }).then(() => {
144
151
  const duration = Date.now() - startTime;
145
152
  const durationInMinutes = duration / 1000 / 60;
146
- console.log(`Finished packing ${totalFilesProcessed} files in ${durationInMinutes.toFixed(1)} minutes; total size: ${totalFileSizeInMB.toFixed(1)} MB, total GPU memory: ${totalGPUMemoryInMB.toFixed(1)} MB`);
153
+ console.log(`[Needle Build Pipeline] v${getVersion()} — Finished packing ${totalFilesProcessed} files in ${durationInMinutes.toFixed(1)} minutes; total size ${totalFileSizeInMBBefore.toFixed(1)} MB → ${totalFileSizeInMB.toFixed(1)} MB, total GPU memory: ${totalGPUMemoryInMB.toFixed(1)} MB`);
147
154
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@needle-tools/gltf-build-pipeline",
3
- "version": "1.1.2",
3
+ "version": "1.1.4",
4
4
  "description": "Pipeline and tools for optimizing gltf files using gltf-transform and compression settings within glTF extensions",
5
5
  "main": "index.mjs",
6
6
  "type": "module",