@openusd-wasm/utils 0.0.3 → 0.0.5
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/README.md +4 -3
- package/dist/openusd_utils.d.ts +4 -3
- package/dist/openusd_utils.js +22 -52
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -24,6 +24,7 @@ metadata, fetch same-origin relative assets, and return virtual filesystem
|
|
|
24
24
|
entries that can be written next to the root layer before opening or packaging
|
|
25
25
|
with OpenUSD.
|
|
26
26
|
|
|
27
|
-
`findPackageRootLayer`, `createPackageTextureResolver`,
|
|
28
|
-
`createTextureResolverFromEntries` help inspect
|
|
29
|
-
|
|
27
|
+
`extractPackageEntries`, `findPackageRootLayer`, `createPackageTextureResolver`,
|
|
28
|
+
and `createTextureResolverFromEntries` help inspect USDZ packages already
|
|
29
|
+
written to the pxr virtual filesystem via `pxr.Sdf.ZipFile`, then map packaged
|
|
30
|
+
image entries to object URLs.
|
package/dist/openusd_utils.d.ts
CHANGED
|
@@ -30,10 +30,11 @@ declare function createTextureResolverFromEntries(entries: Map<string, Uint8Arra
|
|
|
30
30
|
resolve: USDTextureResolver;
|
|
31
31
|
urls: Map<string, string>;
|
|
32
32
|
} | null;
|
|
33
|
-
declare function
|
|
33
|
+
declare function extractPackageEntries(pxr: Pxr, filePath: string, tempDirectory?: string): Map<string, Uint8Array>;
|
|
34
|
+
declare function createPackageTextureResolver(pxr: Pxr, filePath: string, tempDirectory?: string): {
|
|
34
35
|
resolve: USDTextureResolver;
|
|
35
36
|
urls: Map<string, string>;
|
|
36
37
|
} | null;
|
|
37
|
-
declare function findPackageRootLayer(
|
|
38
|
+
declare function findPackageRootLayer(pxr: Pxr, filePath: string): string | null;
|
|
38
39
|
//#endregion
|
|
39
|
-
export { type USDAssetResolverOptions, type USDAssetValue, type USDTextureResolver, type USDTextureResolverContext, autoResolveAssetFiles, autoResolveTextureFiles, createPackageTextureResolver, createTextureResolverFromEntries, findPackageRootLayer, toLayerRelativeAssetPath };
|
|
40
|
+
export { type USDAssetResolverOptions, type USDAssetValue, type USDTextureResolver, type USDTextureResolverContext, autoResolveAssetFiles, autoResolveTextureFiles, createPackageTextureResolver, createTextureResolverFromEntries, extractPackageEntries, findPackageRootLayer, toLayerRelativeAssetPath };
|
package/dist/openusd_utils.js
CHANGED
|
@@ -26,7 +26,7 @@ const DEFAULT_ASSET_SEARCH_ROOTS = [
|
|
|
26
26
|
"material",
|
|
27
27
|
"materials"
|
|
28
28
|
];
|
|
29
|
-
const DEFAULT_MAX_ASSET_REFERENCES =
|
|
29
|
+
const DEFAULT_MAX_ASSET_REFERENCES = 512;
|
|
30
30
|
const DEFAULT_MAX_ASSET_REFERENCE_DEPTH = 4;
|
|
31
31
|
const DEFAULT_PACKAGE_REMAP_ALIAS_COUNT = 16;
|
|
32
32
|
const USD_LAYER_EXTENSIONS = new Set([
|
|
@@ -108,18 +108,6 @@ function toArrayBuffer(data) {
|
|
|
108
108
|
new Uint8Array(buffer).set(data);
|
|
109
109
|
return buffer;
|
|
110
110
|
}
|
|
111
|
-
function trimAssetReference(value) {
|
|
112
|
-
let ref = value.trim();
|
|
113
|
-
if (!ref || ref.length > 220) return null;
|
|
114
|
-
ref = ref.replace(/^[@<"']+/, "").replace(/[@>"')\]},;]+$/g, "");
|
|
115
|
-
if (!ref || ref.startsWith("#") || ref.startsWith("$")) return null;
|
|
116
|
-
if (/^[A-Za-z]:[\\/]/.test(ref)) return null;
|
|
117
|
-
if (/^[A-Za-z][A-Za-z0-9+.-]*:/.test(ref)) return null;
|
|
118
|
-
if (ref.startsWith("/")) return null;
|
|
119
|
-
if (/[\0\r\n\t\f\v]/.test(ref)) return null;
|
|
120
|
-
if (!/^[ A-Za-z0-9._~!$&'()+,;=@/-]+$/.test(ref)) return null;
|
|
121
|
-
return ref;
|
|
122
|
-
}
|
|
123
111
|
function buildExtensionVariants(path, searchExtensions) {
|
|
124
112
|
const normalized = normalizeFsRelativePath(path);
|
|
125
113
|
if (!normalized) return [];
|
|
@@ -233,13 +221,6 @@ async function fetchBinary(url) {
|
|
|
233
221
|
return null;
|
|
234
222
|
}
|
|
235
223
|
}
|
|
236
|
-
function extractedAssetReferences(extracted) {
|
|
237
|
-
return unique([
|
|
238
|
-
...extracted.subLayers,
|
|
239
|
-
...extracted.references,
|
|
240
|
-
...extracted.payloads
|
|
241
|
-
].map((ref) => trimAssetReference(ref)).filter((ref) => !!ref));
|
|
242
|
-
}
|
|
243
224
|
function isQueueableUsdLayer(path) {
|
|
244
225
|
return USD_LAYER_EXTENSIONS.has(extensionOf(path));
|
|
245
226
|
}
|
|
@@ -251,6 +232,12 @@ function existingFsPath(pxr, directory, relativePaths, files) {
|
|
|
251
232
|
for (const relativePath of relativePaths) if (files[relativePath] || pxr.FS.exists(joinFsPath(directory, relativePath))) return relativePath;
|
|
252
233
|
return null;
|
|
253
234
|
}
|
|
235
|
+
function writeQueueableLayer(pxr, directory, files, relativePath, data) {
|
|
236
|
+
if (!isQueueableUsdLayer(relativePath)) return;
|
|
237
|
+
const filePath = joinFsPath(directory, relativePath);
|
|
238
|
+
if (!files[relativePath]) files[relativePath] = data;
|
|
239
|
+
pxr.FS.writeFile(filePath, data);
|
|
240
|
+
}
|
|
254
241
|
function urlForSourceRelativePath(sourceRelativePath, rootSourceUrl) {
|
|
255
242
|
try {
|
|
256
243
|
return new URL(sourceRelativePath, rootSourceUrl).href;
|
|
@@ -302,7 +289,7 @@ async function autoResolveAssetFiles(pxr, rootFilePath, options) {
|
|
|
302
289
|
while (queue.length > 0 && uniqueFileCount(files) < maxFiles) {
|
|
303
290
|
const item = queue.shift();
|
|
304
291
|
if (!item || item.depth > maxDepth) continue;
|
|
305
|
-
const refs =
|
|
292
|
+
const refs = pxr.UsdUtils.ExtractSanitizedExternalReferences(item.filePath).filter((ref) => shouldFetchAssetReference(ref, searchExtensions));
|
|
306
293
|
const itemSearchRoots = unique([
|
|
307
294
|
...item.searchRoots,
|
|
308
295
|
...inferReferencedSearchRoots(refs, configuredSearchRoots),
|
|
@@ -311,7 +298,7 @@ async function autoResolveAssetFiles(pxr, rootFilePath, options) {
|
|
|
311
298
|
for (const ref of refs) {
|
|
312
299
|
if (uniqueFileCount(files) >= maxFiles) break;
|
|
313
300
|
for (const attempt of buildFetchAttempts(ref, item.sourceUrl, item.sourceRelativePath, searchExtensions, item.rootSourceUrl, itemSearchRoots)) {
|
|
314
|
-
const existingPath = existingFsPath(pxr, directory, [attempt.sourceRelativePath], files);
|
|
301
|
+
const existingPath = existingFsPath(pxr, directory, [attempt.sourceRelativePath, ...attempt.fsPaths], files);
|
|
315
302
|
if (existingPath) {
|
|
316
303
|
if (item.depth < maxDepth) queueUsdLayer(queue, queuedLayers, pxr, directory, existingPath, urlForSourceRelativePath(existingPath, item.rootSourceUrl), item.rootSourceUrl, itemSearchRoots, item.depth + 1);
|
|
317
304
|
break;
|
|
@@ -320,10 +307,11 @@ async function autoResolveAssetFiles(pxr, rootFilePath, options) {
|
|
|
320
307
|
fetchedUrls.add(attempt.url);
|
|
321
308
|
const data = await fetchBinary(attempt.url);
|
|
322
309
|
if (!data) continue;
|
|
310
|
+
writeQueueableLayer(pxr, directory, files, attempt.sourceRelativePath, data);
|
|
323
311
|
for (const fsPath of attempt.fsPaths) {
|
|
324
312
|
ownedPackageAliases.delete(fsPath);
|
|
325
313
|
files[fsPath] = data;
|
|
326
|
-
|
|
314
|
+
writeQueueableLayer(pxr, directory, files, fsPath, data);
|
|
327
315
|
}
|
|
328
316
|
addPackageRemapAliases(files, attempt.packageRemapAliases, data, ownedPackageAliases, packageAliasConflicts);
|
|
329
317
|
if (item.depth < maxDepth) queueUsdLayer(queue, queuedLayers, pxr, directory, attempt.sourceRelativePath, attempt.url, item.rootSourceUrl, itemSearchRoots, item.depth + 1);
|
|
@@ -388,29 +376,6 @@ async function autoResolveTextureFiles(metadata, existingFiles, options) {
|
|
|
388
376
|
}
|
|
389
377
|
return files;
|
|
390
378
|
}
|
|
391
|
-
function readZipEntryName(data, start, length) {
|
|
392
|
-
return new TextDecoder().decode(data.subarray(start, start + length));
|
|
393
|
-
}
|
|
394
|
-
function extractStoredZipEntries(data) {
|
|
395
|
-
const view = new DataView(data.buffer, data.byteOffset, data.byteLength);
|
|
396
|
-
const entries = /* @__PURE__ */ new Map();
|
|
397
|
-
let offset = 0;
|
|
398
|
-
while (offset + 30 <= data.byteLength) {
|
|
399
|
-
if (view.getUint32(offset, true) !== 67324752) break;
|
|
400
|
-
const method = view.getUint16(offset + 8, true);
|
|
401
|
-
const compressedSize = view.getUint32(offset + 18, true);
|
|
402
|
-
const fileNameLength = view.getUint16(offset + 26, true);
|
|
403
|
-
const extraLength = view.getUint16(offset + 28, true);
|
|
404
|
-
const nameStart = offset + 30;
|
|
405
|
-
const dataStart = nameStart + fileNameLength + extraLength;
|
|
406
|
-
const dataEnd = dataStart + compressedSize;
|
|
407
|
-
if (dataEnd > data.byteLength) break;
|
|
408
|
-
const name = normalizeFsRelativePath(readZipEntryName(data, nameStart, fileNameLength));
|
|
409
|
-
if (name && method === 0) entries.set(name, data.slice(dataStart, dataEnd));
|
|
410
|
-
offset = dataEnd;
|
|
411
|
-
}
|
|
412
|
-
return entries;
|
|
413
|
-
}
|
|
414
379
|
function createTextureResolverFromEntries(entries) {
|
|
415
380
|
if (typeof Blob === "undefined" || typeof URL === "undefined" || typeof URL.createObjectURL !== "function") return null;
|
|
416
381
|
const imageEntries = new Map([...entries].filter(([path]) => [
|
|
@@ -455,12 +420,17 @@ function createTextureResolverFromEntries(entries) {
|
|
|
455
420
|
}
|
|
456
421
|
};
|
|
457
422
|
}
|
|
458
|
-
function
|
|
459
|
-
|
|
423
|
+
function extractPackageEntries(pxr, filePath, tempDirectory) {
|
|
424
|
+
const entries = /* @__PURE__ */ new Map();
|
|
425
|
+
for (const item of pxr.UsdUtils.GetPackageEntries(filePath, tempDirectory ?? "/tmp/openusd-wasm-package-entries", DEFAULT_MAX_ASSET_REFERENCE_DEPTH)) if (typeof item.path === "string" && item.data instanceof Uint8Array) entries.set(item.path, item.data);
|
|
426
|
+
return entries;
|
|
427
|
+
}
|
|
428
|
+
function createPackageTextureResolver(pxr, filePath, tempDirectory) {
|
|
429
|
+
return createTextureResolverFromEntries(extractPackageEntries(pxr, filePath, tempDirectory));
|
|
460
430
|
}
|
|
461
|
-
function findPackageRootLayer(
|
|
462
|
-
|
|
463
|
-
return null;
|
|
431
|
+
function findPackageRootLayer(pxr, filePath) {
|
|
432
|
+
const path = pxr.UsdUtils.FindPackageRootLayer(filePath);
|
|
433
|
+
return typeof path === "string" && path ? path : null;
|
|
464
434
|
}
|
|
465
435
|
//#endregion
|
|
466
|
-
export { autoResolveAssetFiles, autoResolveTextureFiles, createPackageTextureResolver, createTextureResolverFromEntries, findPackageRootLayer, toLayerRelativeAssetPath };
|
|
436
|
+
export { autoResolveAssetFiles, autoResolveTextureFiles, createPackageTextureResolver, createTextureResolverFromEntries, extractPackageEntries, findPackageRootLayer, toLayerRelativeAssetPath };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openusd-wasm/utils",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.5",
|
|
5
5
|
"description": "Shared OpenUSD WebAssembly utilities for asset resolution and USDZ packaging workflows.",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://github.com/openusd-wasm/openusd-pxr-wasm",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"dist"
|
|
25
25
|
],
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@openusd-wasm/pxr": "0.0.
|
|
27
|
+
"@openusd-wasm/pxr": "0.0.5"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@types/node": "^25.6.2",
|