Files
tinyusdz/.serena/.gitignore
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

2 lines
7 B
Plaintext