@needle-tools/gltf-build-pipeline 2.2.1-alpha.3 → 2.2.1-alpha.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,7 +4,7 @@ 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
- ## [2.2.1-alpha.3] - 2023-06-17
7
+ ## [2.2.1-alpha.4] - 2023-06-17
8
8
  - add: `--verbose` option to transform command
9
9
  - add: `stats` command to create stats.needle.json
10
10
  - add: automatically detect mimetype mismatch and attempt to fix it
@@ -7,7 +7,7 @@ import path, { basename, resolve } from 'path';
7
7
  import { existsSync, readFileSync, rmSync, statSync, writeFileSync } from 'fs';
8
8
  import { addMetaToCache, addToCache, getHash, getKey, tryGetFromCache, tryGetMetaFromCache } from '../cache/index.js';
9
9
  import sharp from "sharp";
10
- import { detectTextureCompressionMode, foreachGLTF, generateGuid, writeNodeIO } from '../utils/index.js';
10
+ import { detectTextureCompressionMode, foreachGLTF, generateGuid, validateImageMimeType, writeNodeIO } from '../utils/index.js';
11
11
  import { needle_asset, writeNeedleAsset } from './needle_asset.js';
12
12
  import { MeshoptDecoder, MeshoptSimplifier } from 'meshoptimizer';
13
13
  import { compressPrimitive } from './needle_mesh_transform.js';
@@ -172,6 +172,11 @@ export function make_progressive_textures(filePath, _options = TEXTURE_RESIZE_DE
172
172
  logger.debug(`[${NAME}] Skipping because progressive extension is not available. ${textureIndex}`);
173
173
  continue;
174
174
  }
175
+ const mimeTypeResult = validateImageMimeType(texture.getMimeType(), texture.getImage());
176
+ if (mimeTypeResult?.error) {
177
+ logger.warn(`[${NAME}] Texture[${index}] has invalid mime type! Reported \"${texture.getMimeType()}\" but is actually \"${mimeTypeResult.mimeType}\": auto-fix`);
178
+ texture.setMimeType(mimeTypeResult.mimeType);
179
+ }
175
180
  /** This is the current texture's size */
176
181
  const currentSize = Math.min(...texture.getSize());
177
182
  if (currentSize <= settings.maxSize) {
@@ -195,7 +200,7 @@ export function make_progressive_textures(filePath, _options = TEXTURE_RESIZE_DE
195
200
  const size = lastSize * .5;
196
201
  if (size <= maxSize)
197
202
  break;
198
- lastSize = size;
203
+ lastSize = Math.round(size);
199
204
  LOD_LEVEL.push({ size: size });
200
205
  }
201
206
  }
@@ -424,6 +429,11 @@ export async function resizeTextureToMax(texture, maxSize, logger) {
424
429
  await resizeTexture(options, texture, logger);
425
430
  }
426
431
  async function resizeTexture(options, texture, logger, uri, slots) {
432
+ const mimeTypeResult = validateImageMimeType(texture.getMimeType(), texture.getImage());
433
+ if (mimeTypeResult?.error) {
434
+ logger.warn(`[${NAME}] Texture[${uri}] has invalid mime type: ${mimeTypeResult.error}: auto-fix`);
435
+ texture.setMimeType(mimeTypeResult.mimeType);
436
+ }
427
437
  const [maxWidth, maxHeight] = options.size;
428
438
  const [srcWidth, srcHeight] = texture.getSize();
429
439
  if (srcWidth <= maxWidth && srcHeight <= maxHeight) {
@@ -444,7 +454,9 @@ async function resizeTexture(options, texture, logger, uri, slots) {
444
454
  dstWidth = Math.floor(dstWidth * (maxHeight / dstHeight));
445
455
  dstHeight = maxHeight;
446
456
  }
447
- logger.info("> Resize texture to " + dstWidth + "x" + dstHeight + " (from " + srcWidth + "x" + srcHeight + ")");
457
+ dstWidth = Math.floor(dstWidth);
458
+ dstHeight = Math.floor(dstHeight);
459
+ logger.warn("> Resize texture to " + dstWidth + "x" + dstHeight + " (from " + srcWidth + "x" + srcHeight + ")");
448
460
  // https://sharp.pixelplumbing.com/api-resize
449
461
  const buffer = await sharp(texture.getImage())
450
462
  .resize(dstWidth, dstHeight, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@needle-tools/gltf-build-pipeline",
3
- "version": "2.2.1-alpha.3",
3
+ "version": "2.2.1-alpha.4",
4
4
  "description": "Pipeline and tools for optimizing gltf files using gltf-transform and compression settings within glTF extensions",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",