@stowkit/three-loader 0.1.31 → 0.1.32
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.
|
@@ -364,7 +364,6 @@ class MeshParser {
|
|
|
364
364
|
if (cacheKey && version) {
|
|
365
365
|
const cached = await AssetMemoryCache.getGeometry(cacheKey, version);
|
|
366
366
|
if (cached) {
|
|
367
|
-
reader.PerfLogger.log(`[Perf] Geometry cache hit: ${cacheKey}`);
|
|
368
367
|
const geometry = new THREE__namespace.BufferGeometry();
|
|
369
368
|
geometry.setAttribute('position', new THREE__namespace.BufferAttribute(cached.positions, 3));
|
|
370
369
|
if (cached.normals) {
|
|
@@ -422,12 +421,8 @@ class MeshParser {
|
|
|
422
421
|
root.name = 'StowKitMesh';
|
|
423
422
|
const { geometries, materials, nodes, meshIndices } = parsedData;
|
|
424
423
|
// Pre-load ALL geometries in parallel for maximum speed
|
|
425
|
-
const dracoStart = performance.now();
|
|
426
424
|
const geometryPromises = geometries.map((geoInfo, index) => this.createGeometry(geoInfo, dataBlob, dracoLoader, cacheKeyPrefix ? `${cacheKeyPrefix}_geo${index}` : undefined, version));
|
|
427
425
|
const loadedGeometries = await Promise.all(geometryPromises);
|
|
428
|
-
const dracoTime = performance.now() - dracoStart;
|
|
429
|
-
const totalVerts = geometries.reduce((sum, g) => sum + g.vertexCount, 0);
|
|
430
|
-
reader.PerfLogger.log(`[Perf] Draco: ${dracoTime.toFixed(2)}ms (${geometries.length} meshes, ${totalVerts} verts)`);
|
|
431
426
|
// Create all Three.js objects for nodes
|
|
432
427
|
const nodeObjects = [];
|
|
433
428
|
for (const node of nodes) {
|
|
@@ -865,12 +860,7 @@ class StowKitPack {
|
|
|
865
860
|
// Parse mesh data
|
|
866
861
|
const parsedData = MeshParser.parseMeshData(metadata, data);
|
|
867
862
|
// Load textures for materials
|
|
868
|
-
|
|
869
|
-
const textureNames = await this.loadMaterialTextures(parsedData.materialData, parsedData.materials);
|
|
870
|
-
const textureTime = performance.now() - textureStart;
|
|
871
|
-
if (textureNames.length > 0) {
|
|
872
|
-
reader.PerfLogger.log(`[Perf] Textures: ${textureTime.toFixed(2)}ms (${textureNames.join(', ')})`);
|
|
873
|
-
}
|
|
863
|
+
await this.loadMaterialTextures(parsedData.materialData, parsedData.materials);
|
|
874
864
|
// Build Three.js scene with Draco decoder (with caching)
|
|
875
865
|
const cacheKey = `${this.packUrl}::${assetPath}`;
|
|
876
866
|
const scene = await MeshParser.buildScene(parsedData, data, this.dracoLoader, cacheKey, this.packVersion);
|
|
@@ -1224,26 +1214,23 @@ class StowKitPack {
|
|
|
1224
1214
|
// Try IndexedDB cache first
|
|
1225
1215
|
const cacheKey = textureName ? `${this.packUrl}::${textureName}` : undefined;
|
|
1226
1216
|
if (cacheKey) {
|
|
1227
|
-
const startCache = performance.now();
|
|
1228
1217
|
const cached = await AssetMemoryCache.getTexture(cacheKey, this.packVersion);
|
|
1229
1218
|
if (cached) {
|
|
1230
|
-
reader.PerfLogger.log(`[Perf] Texture
|
|
1219
|
+
reader.PerfLogger.log(`[Perf] ✓ Texture "${textureName}": 0ms (IndexedDB cache)`);
|
|
1231
1220
|
const texture = new THREE__namespace.CompressedTexture([{ data: cached.data, width: cached.width, height: cached.height }], cached.width, cached.height, cached.format, THREE__namespace.UnsignedByteType);
|
|
1232
1221
|
texture.needsUpdate = true;
|
|
1233
1222
|
return texture;
|
|
1234
1223
|
}
|
|
1235
1224
|
}
|
|
1236
|
-
//
|
|
1225
|
+
// Decode using Basis transcoder
|
|
1226
|
+
const decodeStart = performance.now();
|
|
1237
1227
|
const arrayBuffer = data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength);
|
|
1238
1228
|
const blob = new Blob([arrayBuffer]);
|
|
1239
1229
|
const url = URL.createObjectURL(blob);
|
|
1240
1230
|
try {
|
|
1241
|
-
const decodeStart = performance.now();
|
|
1242
1231
|
const texture = await new Promise((resolve, reject) => {
|
|
1243
1232
|
this.ktx2Loader.load(url, (texture) => {
|
|
1244
1233
|
URL.revokeObjectURL(url);
|
|
1245
|
-
const decodeTime = performance.now() - decodeStart;
|
|
1246
|
-
reader.PerfLogger.log(`[Perf] Basis decode: ${decodeTime.toFixed(2)}ms (${textureName || 'unknown'}, ${texture.image?.width}x${texture.image?.height})`);
|
|
1247
1234
|
texture.needsUpdate = true;
|
|
1248
1235
|
resolve(texture);
|
|
1249
1236
|
}, undefined, (error) => {
|
|
@@ -1251,6 +1238,8 @@ class StowKitPack {
|
|
|
1251
1238
|
reject(error);
|
|
1252
1239
|
});
|
|
1253
1240
|
});
|
|
1241
|
+
const decodeTime = performance.now() - decodeStart;
|
|
1242
|
+
reader.PerfLogger.log(`[Perf] ✓ Texture "${textureName || 'unknown'}": ${decodeTime.toFixed(2)}ms (Basis decode ${texture.image?.width}x${texture.image?.height})`);
|
|
1254
1243
|
// Cache the transcoded texture data to IndexedDB
|
|
1255
1244
|
if (cacheKey && texture.mipmaps && texture.mipmaps.length > 0) {
|
|
1256
1245
|
const mipmap = texture.mipmaps[0];
|