@openusd-wasm/utils
v0.0.17
Published
Shared OpenUSD WebAssembly utilities for asset resolution and USDZ packaging workflows.
Readme
@openusd-wasm/utils
Shared utilities for browser and worker OpenUSD workflows backed by
@openusd-wasm/pxr.
import { toLayerRelativeAssetPath } from '@openusd-wasm/utils'
refs.AddReference(toLayerRelativeAssetPath('assets/gearbox.usdz'), '')Asset References
When generating USDA files that reference assets written next to the layer,
author explicit layer-relative asset paths. OpenUSD treats
@assets/model.usdz@ as a search-path asset, while @./assets/model.usdz@
is anchored to the current layer directory and packages without transient
0/model.usdz remap warnings.
Asset Resolution
autoResolveAssetFiles and autoResolveTextureFiles scan USD references and
metadata, fetch same-origin relative assets, and return virtual filesystem
entries that can be written next to the root layer before opening or packaging
with OpenUSD.
Both resolvers accept an optional per-load fetchAsset(url) transport. It receives
each candidate URL, including nested layers and material textures, and returns
Uint8Array bytes. Return null to continue trying alternate paths; reject to stop
resolution, for example when the caller cancels a load. Without this option, the
resolvers keep using the built-in fetch behavior.
import { autoResolveAssetFiles } from '@openusd-wasm/utils'
const controller = new AbortController()
const files = await autoResolveAssetFiles(pxr, '/tmp/scene.usda', {
sourcePath: 'https://example.com/models/scene.usda',
async fetchAsset(url) {
const response = await fetch(url, { signal: controller.signal })
if (!response.ok) return null
return new Uint8Array(await response.arrayBuffer())
},
})Applications can read the response body as a stream inside fetchAsset to report
download progress without changing the global fetch. Reference discovery still
uses the native pxr.UsdUtils.ExtractSanitizedExternalReferences API.
extractPackageEntries, findPackageRootLayer, createPackageTextureResolver,
and createTextureResolverFromEntries help inspect USDZ packages already
written to the pxr virtual filesystem via pxr.Sdf.ZipFile, then map packaged
image entries to object URLs.
