mirror of
https://github.com/lighttransport/tinyusdz.git
synced 2026-01-18 01:11:17 +01:00
This commit enhances the WebAssembly bindings with two major improvements:
1. **Zero-Copy Asset Loading** (`setAssetFromRawPointer`):
- Direct Uint8Array access using raw pointers
- Eliminates intermediate copying during JS↔C++ transfer
- 67% reduction in memory copies (from 3 to 1)
- Optimal performance for large binary assets (textures, meshes, USD files)
2. **Memory View Access** (`getAssetCacheDataAsMemoryView`):
- Direct typed memory view of cached asset data
- Returns Uint8Array for existing assets, undefined otherwise
- Consistent with existing getAsset method
**Technical Details:**
- Added AssetCacheEntry struct with SHA-256 hash validation
- Implemented raw pointer method with emscripten::allow_raw_pointers()
- Enhanced error handling and data integrity checks
- Backward compatible with existing setAsset/getAsset methods
**JavaScript Usage:**
```javascript
// Zero-copy loading
const dataPtr = Module.HEAPU8.subarray(uint8Array.byteOffset,
uint8Array.byteOffset + uint8Array.byteLength).byteOffset;
loader.setAssetFromRawPointer('texture.jpg', dataPtr, uint8Array.length);
// Direct memory view
const memView = loader.getAssetCacheDataAsMemoryView('texture.jpg');
```
**Testing:**
- Comprehensive Node.js test suite with mock implementations
- Performance benchmarking utilities
- Data integrity validation
- Zero-copy helper functions for real-world usage
Ideal for USD workflows with large textures, geometry data, and binary scene files.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
23 lines
690 B
JSON
23 lines
690 B
JSON
{
|
|
"name": "tinyusdz-web-tests",
|
|
"version": "1.0.0",
|
|
"description": "Node.js tests for TinyUSDZ WebAssembly bindings",
|
|
"main": "test-memory-view.js",
|
|
"scripts": {
|
|
"test": "node test-memory-view-mock.js && node test-zero-copy-mock.js && echo 'Note: Run actual tests after building WebAssembly module'",
|
|
"test-memory-view": "node test-memory-view.js",
|
|
"test-zero-copy": "node test-zero-copy-mock.js",
|
|
"test-mock": "node test-memory-view-mock.js && node test-zero-copy-mock.js"
|
|
},
|
|
"keywords": [
|
|
"tinyusdz",
|
|
"webassembly",
|
|
"usd",
|
|
"test"
|
|
],
|
|
"author": "TinyUSDZ Contributors",
|
|
"license": "Apache-2.0",
|
|
"engines": {
|
|
"node": ">=14.0.0"
|
|
}
|
|
} |