14 Commits

Author SHA1 Message Date
Syoyo Fujita
4e37545c9b add test scene with envmap(DomeLight) 2025-12-17 02:16:46 +09:00
Syoyo Fujita
db55d902b5 Fix data corruption issue by reverting TypedArray to std::vector
Revert TypedArray usage back to std::vector in crate-reader.cc and
usdGeom.cc to fix memory corruption issues that caused crashes when
loading certain USDZ files. The TypedArray view mode with mmap was
causing uninitialized memory access.

Changes:
- Replace TypedArray with std::vector in usdGeom.cc flatten_with_indices
- Remove TypedArray usage for float2, double2, double3, half2, half4 in crate-reader.cc
- Add sanity check for array size to catch corrupted data
- Fix missing return statement in material-serializer.cc switch case
- Fix typo TUSD_LOG_I -> TUSDZ_LOG_I in crate-reader.cc

This fixes crashes when loading fancy-teapot-mtlx.usdz and similar files.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-12 10:26:06 +09:00
Syoyo Fujita
dd522def5b initial working MaterialX + USD demo. 2025-11-06 10:00:19 +09:00
Syoyo Fujita
99e05822cc Merge branch 'release' into mtlx-2025 with compilation fixes
Resolved merge conflicts and fixed compilation errors introduced by animation system refactoring and API changes:
- Updated AnimationClip API usage in threejs-exporter (channels/samplers)
- Fixed PropertyMap const-correctness in MaterialX shader reconstructors
- Fixed 32-bit build warnings (sign conversion, variable shadowing)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-04 21:55:27 +09:00
Syoyo Fujita
a58c48e105 add test models for SkinAnimation.
improve a bit for skinning-anim.js demo.
2025-11-04 08:57:12 +09:00
Syoyo Fujita
a54f18475c Add multiple UV set support and MaterialX example library
This commit implements comprehensive multiple UV coordinate set support across
the entire TinyUSDZ MaterialX/OpenPBR stack, and adds a curated collection of
MaterialX example files with an automated texture download system.

## Part 1: Multiple UV Set Support

Enables different textures on the same material to use different UV mappings,
essential for complex materials (e.g., base color on UV0, detail maps on UV1).

### C++ Core (src/usdShade.hh)
- Add UVSetInfo struct for UV set metadata
- Enhance UsdUVTexture with uv_set (int) and uv_set_name (token)
- Default to UV set 0 for backward compatibility

### WASM Binding (web/binding.cc)
- Modified getMesh() to export ALL UV sets, not just UV0
- New JavaScript structure: uvSets: {uv0: {...}, uv1: {...}}
- Each UV set includes data, vertexCount, and slotId metadata
- Maintain backward compatibility with texcoords field

### Three.js Demo (web/js/materialx.js)
- Load all UV sets from WASM to Three.js geometry attributes
- Add UV set selector dropdown in texture panel (shown when multiple UV sets exist)
- Track selection in textureUVSet[materialIndex][mapName]
- Export UV set info in both JSON and MaterialX XML formats
- Zero UI overhead for single-UV-set meshes

### Documentation
- Update MATERIALX-SUPPORT-STATUS.md feature matrix
- Add UV_SET_SUPPORT.md with comprehensive examples and API docs
- Document all three layers: C++, WASM, and JavaScript

**Changes**: 4 files, 254 lines added
**Features**: Per-texture UV selection, automatic detection, export support

## Part 2: MaterialX Example Library

Add curated MaterialX examples from official repository with on-demand texture
downloads to keep git repository lean.

### MaterialX Files (web/demo/public/assets/mtlx/)
Downloaded from MaterialX GitHub repository:
- 11 Standard Surface materials (copper, gold, glass, brass, brick, etc.)
- 4 Custom OpenPBR materials (metal, glass, plastic)
- Ranges from simple (683 bytes) to complex (32 KB chess set)
- Total: 15 .mtlx files

### Texture Download System
- download_textures.sh: Automated bash script with 3 modes
  * --minimal: 5 essential textures (~10 MB)
  * (default): All ~54 textures (~50 MB)
  * --clean: Remove downloaded textures
- Colored output with progress indicators
- Downloads from MaterialX GitHub on-demand
- .gitignore excludes images/ directory (saves 50 MB in repo)

### Documentation
- Comprehensive README.md with usage examples
- Texture coverage table and testing recommendations
- C++ and JavaScript code examples
- Source attributions and license info

**Benefits**:
- Lean repository (no binary images in git)
- Easy testing with real MaterialX files
- Flexible download options
- Well-documented with examples

**Files Added**: 18 files (15 .mtlx + script + docs + .gitignore)
**Repository Impact**: +68 KB text files, -50 MB by excluding images

## Testing

### UV Set Support
-  C++ structures compile
-  WASM binding exports uvSets correctly
-  Three.js loads multiple UV sets
-  UI dropdown works
-  JSON/MaterialX export includes UV sets
-  Backward compatibility maintained

### MaterialX Examples
-  Script executable and tested
-  Minimal download works (brass textures)
-  .gitignore properly excludes images/
-  All .mtlx files valid XML

## Summary
- Multiple UV set support: Complete stack implementation
- MaterialX library: 15 example files + download system
- Documentation: 2 new docs, 1 updated feature matrix
- Total changes: 22 files modified/added

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-02 07:22:45 +09:00
Syoyo Fujita
a4f42e29fc Fix PropertyBinding UUID syntax for Three.js AnimationMixer
This commit fixes the PropertyBinding error that occurred when playing USD animations.

**Root Cause:**
- Three.js PropertyBinding expects UUID-based track names in the format `<uuid>.<property>`
- The code was incorrectly using `.uuid[<uuid>].<property>` format which PropertyBinding doesn't support
- PropertyBinding resolves nodes by checking `childNode.name === nodeName || childNode.uuid === nodeName`

**Changes Made:**

1. **Animation track UUID syntax** (track-based and channel-based):
   - Changed from: `.uuid[${targetUUID}].position`
   - Changed to: `${targetUUID}.position`
   - Applied to position, quaternion, and scale tracks

2. **UUID validation and lookup logic**:
   - Changed from regex matching `.uuid[...]`
   - Changed to: `track.name.split('.')[0]` to extract UUID from first part
   - Applied to track validation and object lookup code

3. **AnimationMixer attachment**:
   - Added `usdContentNode` global variable to store actual USD root node
   - Mixer now created on `usdContentNode` (threeNode) instead of `usdSceneRoot`
   - Ensures mixer root matches the root used for animation extraction

4. **Additional improvements**:
   - Enhanced shadow map quality (2048x2048 resolution)
   - Shadow camera frustum scaling with scene scale to prevent artifacts
   - Bounding box visualization feature for animated objects
   - Improved animation track name matching (exact match then prefix match)
   - Scene graph tree UI with per-object animation controls

**Result:**
-  PropertyBinding successfully resolves all UUID-based animation tracks
-  Timeline slider updates all animated objects correctly
-  Per-object animation toggles work in Scene Graph UI
-  Hierarchical node animations work properly

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-30 08:20:06 +09:00
Syoyo Fujita
af2115490e Fix segfault in TimeSamples::get when accessing empty _samples vector
Added bounds check before accessing _samples[0] to prevent crash when
using unified storage mode where _samples is empty but empty() returns false.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-28 10:12:09 +09:00
Syoyo Fujita
d926905030 add xformop example model. 2025-10-21 12:35:16 +09:00
Syoyo Fujita
db3e703a9f fix type is not printed.
fix array print is shorten up to 10 items.
2025-10-21 07:36:20 +09:00
Syoyo Fujita
795677d0b1 improve MCP protocol. 2025-08-04 15:57:16 +09:00
Syoyo Fujita
2f8fd55141 update README. 2025-06-28 06:23:43 +09:00
Syoyo Fujita
b432cefd0b bump tinyusdz npm version
Use URL for texture file.
2025-06-26 09:21:18 +09:00
Syoyo Fujita
967a19daf6 add doubleSided support.
some code cleanups.
Change file layout for web demos.
Add demo list web page.
2025-06-26 08:47:45 +09:00