mirror of
https://github.com/lighttransport/tinyusdz.git
synced 2026-01-18 01:11:17 +01:00
This commit integrates the optimized 32-byte Value implementation from the
value-opt-32 branch and adapts it to be compatible with the value-opt branch's
recent refactorings (array type system, TimeSamples, POD matrix types).
## Key Changes
### Array Type System Compatibility
- Update from TYPE_ID_1D_ARRAY_BIT to new dual-bit system:
* TYPE_ID_STL_ARRAY_BIT (bit 20) for std::vector arrays
* TYPE_ID_TYPED_ARRAY_BIT (bit 21) for TypedArray/ChunkedTypedArray
* TYPE_ID_ARRAY_BIT_MASK for detecting any array type
- Add array_bit() method to TypeTraits for all array types
- Proper dual-bit marking for TypedArray types (both STL and TYPED bits)
### Matrix Types Refactoring
- Convert all 6 matrix types to trivial/POD-compatible structs:
* matrix2f, matrix3f, matrix4f, matrix2d, matrix3d, matrix4d
- Replace custom constructors with = default
- Add explicit copy/move constructors/operators as = default
- Add static identity() methods for creating identity matrices
- Enables efficient memcpy and compatibility with TimeSamples POD requirements
### Matrix Comparison Operators
- Add operator== for all 6 matrix types using math::is_close()
- Required for TimeSamples array deduplication
- Proper floating-point comparison with tolerance
### Build System
- Add missing src/tydra/bone-util.{cc,hh} to CMakeLists.txt
- Fixes undefined reference to ReduceBoneInfluences()
- Update .gitignore to prevent build artifact commits
### Value32 Implementation Files
- Add value-types-handler.{cc,hh} - Handler-based value type system
- Add value-types-new.{cc,hh} - New 32-byte Value implementation
- Add value-debug-trace.hh - Debug tracing utilities
- Add test_value32.cc - Value32 unit tests
- Add benchmark files for performance comparison
### Documentation
- Add comprehensive design and analysis documents (10 .md files)
- Include performance benchmarks and comparisons
- Document std::any and linb::any analysis
- Add test results summary
## Testing
All tests pass successfully:
- CTest: 3/3 tests passed (100%)
- Unit tests: 27/27 tests passed (100%)
- USD file parsing: 6/6 files tested successfully (USDA and USDC)
- Tydra render scene conversion: Working correctly
## Compatibility
Maintains full backward compatibility:
- All existing tests continue to pass
- No regressions in USD parsing (USDA, USDC, USDZ)
- Tydra conversion still functional
- Compatible with recent TimeSamples and array refactoring
Modified files: 6 (+1040/-118 lines)
New files: 18 (5263 lines)
Total changes: +5263/-118 lines
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
153 lines
3.4 KiB
C++
153 lines
3.4 KiB
C++
// Test program for new Value32 implementation
|
|
|
|
#include "src/value-types-handler.hh"
|
|
#include "src/value-types.hh"
|
|
|
|
#include <iostream>
|
|
#include <cassert>
|
|
|
|
using namespace tinyusdz;
|
|
using namespace tinyusdz::value;
|
|
|
|
void test_basic_types() {
|
|
std::cout << "Testing basic types...\n";
|
|
|
|
// Test int32_t
|
|
{
|
|
Value32 v(int32_t(42));
|
|
assert(!v.is_empty());
|
|
assert(v.type_id() == TYPE_ID_INT32);
|
|
|
|
const int32_t* ptr = v.as<int32_t>();
|
|
assert(ptr != nullptr);
|
|
assert(*ptr == 42);
|
|
std::cout << " int32_t: OK (value=" << *ptr << ")\n";
|
|
}
|
|
|
|
// Test float
|
|
{
|
|
Value32 v(3.14f);
|
|
assert(!v.is_empty());
|
|
assert(v.type_id() == TYPE_ID_FLOAT);
|
|
|
|
const float* ptr = v.as<float>();
|
|
assert(ptr != nullptr);
|
|
assert(*ptr == 3.14f);
|
|
std::cout << " float: OK (value=" << *ptr << ")\n";
|
|
}
|
|
|
|
// Test double
|
|
{
|
|
Value32 v(2.718);
|
|
assert(!v.is_empty());
|
|
assert(v.type_id() == TYPE_ID_DOUBLE);
|
|
|
|
const double* ptr = v.as<double>();
|
|
assert(ptr != nullptr);
|
|
assert(*ptr == 2.718);
|
|
std::cout << " double: OK (value=" << *ptr << ")\n";
|
|
}
|
|
|
|
// Test bool
|
|
{
|
|
Value32 v(true);
|
|
assert(!v.is_empty());
|
|
assert(v.type_id() == TYPE_ID_BOOL);
|
|
|
|
const bool* ptr = v.as<bool>();
|
|
assert(ptr != nullptr);
|
|
assert(*ptr == true);
|
|
std::cout << " bool: OK (value=" << (*ptr ? "true" : "false") << ")\n";
|
|
}
|
|
}
|
|
|
|
void test_string() {
|
|
std::cout << "Testing string (heap allocated)...\n";
|
|
|
|
std::string test_str = "Hello, TinyUSDZ!";
|
|
Value32 v(test_str);
|
|
|
|
assert(!v.is_empty());
|
|
assert(v.type_id() == TYPE_ID_STRING);
|
|
|
|
const std::string* ptr = v.as<std::string>();
|
|
assert(ptr != nullptr);
|
|
assert(*ptr == test_str);
|
|
std::cout << " string: OK (value=\"" << *ptr << "\")\n";
|
|
}
|
|
|
|
void test_copy_move() {
|
|
std::cout << "Testing copy and move...\n";
|
|
|
|
// Test copy constructor
|
|
{
|
|
Value32 v1(int32_t(99));
|
|
Value32 v2(v1); // Copy
|
|
|
|
assert(!v2.is_empty());
|
|
assert(v2.type_id() == TYPE_ID_INT32);
|
|
|
|
const int32_t* ptr1 = v1.as<int32_t>();
|
|
const int32_t* ptr2 = v2.as<int32_t>();
|
|
assert(ptr1 != nullptr && ptr2 != nullptr);
|
|
assert(*ptr1 == 99 && *ptr2 == 99);
|
|
std::cout << " copy constructor: OK\n";
|
|
}
|
|
|
|
// Test move constructor
|
|
{
|
|
Value32 v1(int32_t(77));
|
|
Value32 v2(std::move(v1)); // Move
|
|
|
|
assert(v1.is_empty()); // v1 should be empty after move
|
|
assert(!v2.is_empty());
|
|
assert(v2.type_id() == TYPE_ID_INT32);
|
|
|
|
const int32_t* ptr = v2.as<int32_t>();
|
|
assert(ptr != nullptr);
|
|
assert(*ptr == 77);
|
|
std::cout << " move constructor: OK\n";
|
|
}
|
|
|
|
// Test copy assignment
|
|
{
|
|
Value32 v1(int32_t(55));
|
|
Value32 v2;
|
|
v2 = v1; // Copy assign
|
|
|
|
assert(!v2.is_empty());
|
|
const int32_t* ptr = v2.as<int32_t>();
|
|
assert(ptr != nullptr);
|
|
assert(*ptr == 55);
|
|
std::cout << " copy assignment: OK\n";
|
|
}
|
|
}
|
|
|
|
void test_size() {
|
|
std::cout << "Testing sizeof...\n";
|
|
|
|
size_t size = sizeof(Value32);
|
|
std::cout << " sizeof(Value32) = " << size << " bytes\n";
|
|
assert(size == 32);
|
|
std::cout << " size check: OK (exactly 32 bytes)\n";
|
|
}
|
|
|
|
int main() {
|
|
std::cout << "=== Value32 Test Program ===\n\n";
|
|
|
|
test_size();
|
|
std::cout << "\n";
|
|
|
|
test_basic_types();
|
|
std::cout << "\n";
|
|
|
|
test_string();
|
|
std::cout << "\n";
|
|
|
|
test_copy_move();
|
|
std::cout << "\n";
|
|
|
|
std::cout << "=== All tests passed! ===\n";
|
|
return 0;
|
|
}
|