18 Commits

Author SHA1 Message Date
Syoyo Fujita
3c1b1735b7 raise C++ version requirement from C++14 to C++17
Update all CMakeLists.txt, Makefiles, meson.build, setup.py,
and documentation files to use C++17 standard.

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-08 03:39:41 +09:00
Syoyo Fujita
de47bc8f07 Merge branch 'anim-mtlx-phase2' of github.com:lighttransport/tinyusdz into anim-mtlx-phase2 2025-11-30 04:26:18 +09:00
Syoyo Fujita
ab0ef8900c Add comprehensive UsdLux parsing and conversion system with test suite
Implements complete UsdLux light parsing and conversion pipeline:

Core Infrastructure:
- RenderLight data structure supporting 6 UsdLux light types (Point/Sphere, Directional, Rect, Disk, Cylinder, Dome)
- MeshLightAPI support for emissive geometry lights
- Full property extraction: color, intensity, exposure, shadows, shaping, IES profiles
- Color temperature support with Kelvin-based specification

JSON Serialization:
- Complete light data serialization in material-serializer.cc
- Geometry light mesh references with geometryMeshId
- Material sync mode for mesh lights

Three.js Exporter:
- Light type conversion to Three.js equivalents
- Shadow map configuration
- Directional/Point/Spot/Rect/Hemisphere light export

WASM Bindings:
- numLights() API for light count
- getLightWithFormat() supporting JSON/YAML output
- Node.js CLI tool (dump-usdlux-cli.js) for testing

Test Suite:
- Comprehensive test files in tests/usda/:
  * usdlux_basic_lights.usda - 6 light types
  * usdlux_advanced_features.usda - IES, shaping, textures
  * usdlux_mesh_lights_simple.usda - MeshLightAPI
- Automated test suite (test-usdlux-parsing.js)
- npm test:usdlux script for CI/CD integration
- All tests passing (4/4)

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-19 03:27:19 +09:00
Syoyo Fujita
9b02a97a5b Merge branch 'mtlx-2025' into usdlux-2025 2025-11-18 22:02:52 +09:00
Syoyo Fujita
eb3c64b618 Merge branch 'mtlx-2025' into skinning 2025-11-17 02:11:52 +09:00
Syoyo Fujita
32b2e15d72 Add grouped and flattened parameter export for MaterialX OpenPBR materials
Add use_grouped_parameters option to ThreeJSMaterialExporter to support both flattened (base_color) and grouped (base.color) parameter naming for JSON export. Includes setJsonParameter helper for automatic name transformation and test suite for validation.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-14 00:29:37 +09:00
Syoyo Fujita
ba612f0389 Merge branch 'mtlx-2025' into usdlux-2025 2025-11-10 03:30:03 +09:00
Syoyo Fujita
4ca91e3012 usdlux 2025-11-10 02:54:07 +09:00
Syoyo Fujita
8fdfa376da Move synthetic SkelAnimation test files to tests/feat/skinning
Relocated skelanim-complete-*.usda test files from models/ to tests/feat/skinning/
to organize feature-specific test files separately from general model assets.

Updated test-synthetic-anims.js to load files from the new location.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-04 22:45:03 +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
2ad9a46573 Add MaterialX export support for StandardSurface, OpenPBR, and NodeGraphs
This commit completes MaterialX export functionality by adding:

1. Float formatting improvements:
   - Clean float output with 6-digit precision
   - Automatic trailing zero removal
   - Fixes precision artifacts in exported XML

2. StandardSurface export:
   - Complete Autodesk StandardSurface shader export
   - All 33+ parameters supported
   - Connection attribute handling

3. OpenPBR export:
   - Complete OpenPBR Surface shader export
   - All 30+ parameters supported
   - Connection attribute handling

4. NodeGraph export:
   - Basic nodegraph structure serialization
   - Output declarations with nodename references
   - Shader-to-nodegraph connection preservation
   - Fixed shader name resolution for proper connection matching

5. Additional improvements:
   - Added bool template specialization for to_xml_string
   - Fixed shader name lookup to prioritize shaders map over shader_name field
   - Added comprehensive test for nodegraph export functionality

All export tests pass successfully.

Tested: All three shader types export correctly with nodegraph support

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-03 05:55:50 +09:00
Syoyo Fujita
182e9029e2 Add MaterialX node graph support and fix critical XML parser bug
- Fix XML parser bug preventing nested tag parsing:
  * Added pending token mechanism to handle non-attribute tokens
  * Parser now correctly processes child elements and text nodes
  * Fixes mismatched end tag errors that blocked all parsing

- Add MaterialX math and procedural nodes:
  * Implement constant, multiply, add, subtract, mix nodes
  * Add noise variants (noise2d/3d, cellnoise, worleynoise, fractal3d)
  * All nodes properly convert to USD shader representations

- Implement connection serialization for MaterialX export:
  * Parse shader input connections (nodegraph/output/nodename attributes)
  * Store connections in MtlxModel.shader_connections map
  * Serialize connections back to MaterialX XML on export
  * Support for all three shader types (UsdPreviewSurface, StandardSurface, OpenPBR)

- Fix string value parsing:
  * Add template specialization for std::string in ParseMaterialXValue
  * MaterialX XML attributes are already unquoted, no ASCII parser needed
  * Fixes "Failed to parse a value of type string" errors

- Add lowercase shader tag support:
  * Support both "OpenPBRSurface" and "open_pbr_surface" tag variants
  * Ensures compatibility with different MaterialX authoring tools

- Set primary shader value when parsing:
  * Populate mtlx->shader in addition to mtlx->shaders map
  * Enables proper export functionality

- Add comprehensive test suite:
  * test_mtlx_export.cc - Tests MaterialX export with connections
  * test_parser_debug.cc - XML parser validation tests
  * Updated Makefile with new test targets

- Fix compiler warnings:
  * Add GCC pragma guards for unused function in threejs-exporter.cc
  * Complements existing clang pragma guards

Tested: All MaterialX import/export tests pass, builds cleanly with C++14

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-03 01:59:03 +09:00
Syoyo Fujita
1d290767fd Add C++ MaterialX import support with built-in secure XML parser
MAJOR UPDATE: Complete MaterialX (.mtlx) file loading support in C++

## Key Changes:

### 1. Built-in MaterialX XML Parser (NEW)
Integrated secure, dependency-free parser from sandbox:
- src/mtlx-xml-tokenizer.{hh,cc} - Low-level XML tokenization
- src/mtlx-simple-parser.{hh,cc} - Lightweight DOM builder
- src/mtlx-dom.{hh,cc} - MaterialX-specific document model
- src/mtlx-usd-adapter.hh - pugixml-compatible adapter

**Benefits:**
- No external dependencies (replaces pugixml)
- Security focused: memory limits, bounds checking, XXE protection
- MaterialX optimized
- pugixml-compatible API for easy migration

**Security Features:**
- Max name length: 256 chars
- Max string: 64KB
- Max text: 1MB
- Max nesting: 1000 levels
- Safe entity handling
- No external file access

### 2. OpenPBR Surface Shader Support (NEW)
Added complete MtlxOpenPBRSurface struct to usdMtlx.hh:
- All 8 parameter groups (Base, Specular, Transmission, Coat, etc.)
- 40+ individual parameters
- Proper USD type mappings
- Type trait registration

### 3. MaterialX Import API (ENHANCED)
Updated src/usdMtlx.cc to use built-in parser:
- Replaced all pugi:: with tinyusdz::mtlx::pugi::
- ReadMaterialXFromString() - Load from XML string
- ReadMaterialXFromFile() - Load from file path
- ToPrimSpec() - Convert MaterialX to USD PrimSpec
- LoadMaterialXFromAsset() - USD asset reference support

### 4. Testing Infrastructure
Added comprehensive test suite:
- tests/feat/mtlx/test_mtlx_import.cc - Import test with examples
- Updated Makefile for both import and export tests
- Test with embedded OpenPBR MaterialX XML
- Command-line file loading support

### 5. Documentation
Created C++_MATERIALX_IMPORT.md with:
- Complete API documentation
- Usage examples for all import methods
- OpenPBR parameter reference
- Security features overview
- Migration guide from pugixml
- Test instructions

Updated MATERIALX-SUPPORT-STATUS.md:
- C++ import status changed from  to 
- Built-in parser feature matrix
- Updated "What's Missing" section
- Comparison table updated

## Supported Features:

### Shader Types:
 OpenPBR Surface (open_pbr_surface) - FULL
 Autodesk Standard Surface (standard_surface) - FULL
 USD Preview Surface (UsdPreviewSurface) - FULL

### MaterialX Versions:
 1.36, 1.37, 1.38

### File Formats:
 .mtlx XML files
 String-based XML
 USD asset references

## Files Changed:
- src/mtlx-*.{hh,cc}: 9 new parser files (+3,500 lines)
- src/usdMtlx.{hh,cc}: OpenPBR support, parser integration
- src/value-types.hh: Added TYPE_ID_IMAGING_MTLX_OPENPBRSURFACE
- tests/feat/mtlx/*: New import test and updated Makefile
- C++_MATERIALX_IMPORT.md: 400+ line documentation
- MATERIALX-SUPPORT-STATUS.md: Updated status

## API Example:

```cpp
#include "usdMtlx.hh"

tinyusdz::MtlxModel mtlx;
std::string warn, err;

// Load from file
bool success = tinyusdz::ReadMaterialXFromFile(
    resolver, "material.mtlx", &mtlx, &warn, &err);

// Convert to USD
tinyusdz::PrimSpec ps;
tinyusdz::ToPrimSpec(mtlx, ps, &err);
```

## Testing:

```bash
cd tests/feat/mtlx
make
./test_mtlx_import
./test_mtlx_import path/to/your.mtlx
```

## Breaking Changes:
NONE - Backward compatible via pugixml adapter

## Migration:
Automatic - existing usdMtlx.cc code works without changes

TinyUSDZ now has COMPLETE MaterialX support at all layers:
 C++ Core (Import & Export)
 WASM Binding (Import & Export)
 Three.js Demo (Full Interactive)

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-02 02:55:03 +09:00
Syoyo Fujita
2877df9509 Fix C++14 compatibility and add MaterialX export test
- Fix C++14 compatibility issues in threejs-exporter.cc:
  * Replace structured bindings with iterator loops
  * Fix template parsing with reinterpret_cast
  * Fix const correctness in unordered_map access
  * Fix type mismatches in shader parameter access

- Add MaterialX export test infrastructure:
  * New test in tests/feat/mtlx/ directory
  * Standalone Makefile for easy compilation
  * Example demonstrating ExportMaterialX API
  * Complete README documentation

Tested: Builds successfully with C++14, exports valid MaterialX 1.38 XML

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-14 02:09:13 +09:00
Syoyo Fujita
16e8de94b3 Implement compact 16-byte ValueView class with direct typed access
Refactor ValueView to use a more memory-efficient 16-byte representation that
stores type information inline, eliminating dereferencing overhead for type_id
access.

Key changes to ValueView class:
- Replace simple pointer with compact 16-byte structure:
  * const void* ptr (8 bytes) - pointer to data
  * uint32_t type_id (4 bytes) - inline type identifier
  * uint8_t flags (1 byte) - storage type flags (vector/TypedArray)
  * uint8_t padding[3] (3 bytes) - alignment padding to 16 bytes

New features:
- template<typename T> ValueView(const T* ptr) - direct construction from
  concrete type pointers
- template<typename T> const T* view() - direct typed access method without
  Value indirection
- Specialized constructors for std::vector<T>* and TypedArray<T>*
- Storage type tracking via FLAG_IS_VECTOR and FLAG_IS_TYPED_ARRAY
- Inline role type mapping (point3f <-> float3) in underlying_type_id()

Benefits:
- Exactly 16 bytes (2 cache words) for better cache efficiency
- Type information available without pointer dereferencing
- Zero-cost abstraction for typed data access
- Compatible with existing Value interface through as() method

Add comprehensive test suite in tests/feat/value-view/ verifying:
- 16-byte size guarantee
- Direct construction and access functionality
- Role type conversions
- Storage type detection
- Array view creation for containers

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-13 02:58:02 +09:00
Syoyo Fujita
92c76c36e5 Add TypedArrayView methods to TimeSamples for efficient array access
- Add get_typed_array_view_at() and get_typed_array_view_at_time() to PODTimeSamples
- Add corresponding methods to TimeSamples class for both TypedArray and std::vector storage
- Return const-qualified TypedArrayView for safe, zero-copy access to array data
- Handle blocked samples (ValueBlock) by returning empty views
- Add comprehensive test suite in tests/feat/typed-array-view/

These methods enable lightweight, non-owning views over time-sampled array data
without copying, improving performance when accessing array values from TimeSamples.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-12 23:57:03 +09:00
Syoyo Fujita
7fed90c1b7 Add TypedArray factory functions for clearer array creation
Add 15 factory functions to typed-array.hh that provide self-documenting,
type-safe alternatives to boolean flag constructors.

Factory Functions Added:
- MakeOwnedTypedArray() - Owned array (will delete)
- MakeDedupTypedArray() - Deduplicated array (won't delete)
- MakeSharedTypedArray() - Shared array (won't delete)
- MakeMmapTypedArray() - Memory-mapped array (won't delete)
- MakeTypedArrayCopy() - Copy data into owned storage
- MakeTypedArrayView() - Non-owning view over external memory
- MakeTypedArrayMmap() - Non-owning view for mmap data
- MakeTypedArrayReserved() - Empty array with reserved capacity
- CreateOwnedTypedArray() - 3 overloads for creating owned arrays
- CreateDedupTypedArray() - Wrap as deduplicated
- CreateMmapTypedArray() - Create mmap in one call
- DuplicateTypedArray() - Deep copy TypedArray
- DuplicateTypedArrayImpl() - Deep copy TypedArrayImpl

Benefits:
- Self-documenting: Function names clearly indicate intent
- Type-safe: No confusing boolean flags (true/false)
- Zero overhead: All inline, same performance as direct constructors
- Backward compatible: Existing code continues to work

Before (confusing):
  TypedArray<T>(ptr, true);   // What does 'true' mean?

After (clear):
  MakeDedupTypedArray(ptr);   // Clear: deduplicated array

Test Suite:
- Added comprehensive test suite in tests/feat/typed-array-factories/
- 16 tests covering all factory functions
- Standalone Makefile for easy testing
- All tests passing (16/16)

Documentation:
- Complete documentation suite (~43.5K)
- API summary, migration examples, architecture guide
- Before/after examples for all use cases

Feature test added in tests/feat/typed-array-factories/ with standalone Makefile.
All tests pass (16/16).

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-12 00:41:07 +09:00
Syoyo Fujita
ce5c968eae Replace std::vector<T> with TypedArray<T> for TimeSamples array deduplication
- Update dedup cache maps in CrateReader to use TypedArray<T> for POD array types
  (int32/uint32/int64/uint64/half/float/double arrays)
- Add TypedArray<T> overloads for add_array_sample_pod and add_matrix_array_sample_pod
- Update UnpackTimeSampleValue_* functions to use TypedArray with ReadIntArrayTyped,
  ReadFloatArrayTyped, and ReadDoubleArrayTyped
- Maintain backward compatibility with std::vector<T> overloads
- Composite types (half2, float2, double2, quat*, matrix*) still use std::vector
  since they use ReadArray which returns std::vector

Benefits:
- Memory efficiency through ValueRep-based deduplication
- Reduced file I/O for repeated array values in TimeSamples
- TypedArray supports future mmap views for zero-copy access

Feature test added in tests/feat/typed-array-timesamples/ with standalone Makefile.
All tests pass (12/12).

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-10 02:13:48 +09:00