mirror of
https://github.com/lighttransport/tinyusdz.git
synced 2026-01-18 01:11:17 +01:00
Comprehensive documentation and working C++ examples for OpenUSD's Crate (USDC binary) format implementation. Documentation (crate-impl.md, 1249 lines): - Complete binary format specification with diagrams - File layout: Bootstrap, Value Data, Structural Sections, TOC - Key data structures: ValueRep (8 bytes), Spec, Field, TimeSamples - Type system: All 60 supported types documented - Reading implementation: 3 ByteStream backends (mmap/pread/asset) - Writing implementation: Packing, deduplication, async I/O - Compression: Integer/float/LZ4 algorithms detailed - Deduplication: 3-level system (structural/per-type/time arrays) - Version history: 13 versions (0.0.1 to 0.13.0) - Optimizations: Zero-copy arrays, parallel construction, etc. - Performance: Read/write speeds, memory usage, file sizes - Security: Bounds checking, recursion protection, validation C++ Examples (aousd/crate/): Three working programs demonstrating OpenUSD C++ API: 1. crate_reader (157 KB) - Read .usdc/.usda files - Traverse prim hierarchy - Display attributes and TimeSamples - Works with any USD file 2. crate_writer (329 KB) - Create animated USD scenes - Write TimeSamples for animation - Animated transforms and colors - Simple and complex scene modes 3. crate_internal_api (169 KB) - Inspect binary format (magic, version, TOC) - Analyze TimeSamples (uniform/non-uniform sampling) - Compare format sizes (ASCII vs binary) - Low-level format introspection Build Systems: - Makefile: Simple, fast Unix builds - CMake: Cross-platform, IDE integration - build.sh: Convenience wrapper script - Both monolithic and standard USD linking - Links against no-python OpenUSD builds Documentation: - README.md: Complete build/usage instructions - EXAMPLES_OUTPUT.md: Actual program outputs - Full API usage examples - Troubleshooting guide Verified Working: - Compiles with C++17 - Links against libusd_ms.so (monolithic) - Creates/reads .usdc files successfully - Binary format inspection working - TimeSamples encoding/decoding functional File sizes: ~660 KB total (all 3 programs) Binary compression: 50-60% smaller than ASCII 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
122 lines
3.4 KiB
CMake
122 lines
3.4 KiB
CMake
cmake_minimum_required(VERSION 3.12)
|
|
project(USDCrateExamples CXX)
|
|
|
|
set(CMAKE_CXX_STANDARD 17)
|
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
|
|
# Option to use monolithic build
|
|
option(USE_MONOLITHIC_USD "Use monolithic USD library (libusd_ms)" OFF)
|
|
|
|
# Find USD installation
|
|
# Set USD_ROOT to your OpenUSD installation directory
|
|
if(NOT DEFINED USD_ROOT)
|
|
if(USE_MONOLITHIC_USD)
|
|
set(USD_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/../dist_nopython_monolithic"
|
|
CACHE PATH "USD installation directory (monolithic)")
|
|
else()
|
|
set(USD_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/../dist_nopython"
|
|
CACHE PATH "USD installation directory")
|
|
endif()
|
|
endif()
|
|
|
|
message(STATUS "USD_ROOT: ${USD_ROOT}")
|
|
message(STATUS "USE_MONOLITHIC_USD: ${USE_MONOLITHIC_USD}")
|
|
|
|
# Check if USD installation exists
|
|
if(NOT EXISTS "${USD_ROOT}")
|
|
message(FATAL_ERROR "USD installation not found at: ${USD_ROOT}\n"
|
|
"Please build OpenUSD first or set USD_ROOT")
|
|
endif()
|
|
|
|
# USD include directories
|
|
include_directories(${USD_ROOT}/include)
|
|
|
|
# USD library directory
|
|
link_directories(${USD_ROOT}/lib)
|
|
|
|
# Platform-specific settings
|
|
if(UNIX AND NOT APPLE)
|
|
# Linux
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated")
|
|
# Add rpath for runtime library loading
|
|
set(CMAKE_INSTALL_RPATH "${USD_ROOT}/lib")
|
|
set(CMAKE_BUILD_RPATH "${USD_ROOT}/lib")
|
|
endif()
|
|
|
|
# Define USD libraries based on build type
|
|
if(USE_MONOLITHIC_USD)
|
|
# Monolithic build - single library
|
|
set(USD_LIBRARIES
|
|
usd_ms
|
|
tbb
|
|
)
|
|
message(STATUS "Using monolithic USD library: libusd_ms")
|
|
else()
|
|
# Standard build - multiple libraries
|
|
set(USD_LIBRARIES
|
|
# Core USD libraries
|
|
usd
|
|
usdGeom
|
|
sdf
|
|
tf
|
|
vt
|
|
gf
|
|
ar
|
|
arch
|
|
plug
|
|
trace
|
|
work
|
|
# TBB for threading
|
|
tbb
|
|
)
|
|
message(STATUS "Using standard USD libraries")
|
|
endif()
|
|
|
|
# Print found libraries
|
|
message(STATUS "USD libraries: ${USD_LIBRARIES}")
|
|
|
|
# Common function to create executable
|
|
function(add_usd_executable target source)
|
|
add_executable(${target} ${source})
|
|
|
|
target_link_libraries(${target}
|
|
${USD_LIBRARIES}
|
|
${CMAKE_DL_LIBS}
|
|
pthread
|
|
)
|
|
|
|
# Set RPATH
|
|
set_target_properties(${target} PROPERTIES
|
|
BUILD_RPATH "${USD_ROOT}/lib"
|
|
INSTALL_RPATH "${USD_ROOT}/lib"
|
|
)
|
|
|
|
message(STATUS "Added executable: ${target}")
|
|
endfunction()
|
|
|
|
# Build executables
|
|
add_usd_executable(crate_reader src/crate_reader.cpp)
|
|
add_usd_executable(crate_writer src/crate_writer.cpp)
|
|
add_usd_executable(crate_internal_api src/crate_internal_api.cpp)
|
|
|
|
# Install targets
|
|
install(TARGETS crate_reader crate_writer crate_internal_api
|
|
RUNTIME DESTINATION bin)
|
|
|
|
# Print summary
|
|
message(STATUS "")
|
|
message(STATUS "========================================")
|
|
message(STATUS "USD Crate Examples Configuration")
|
|
message(STATUS "========================================")
|
|
message(STATUS " Build type: ${CMAKE_BUILD_TYPE}")
|
|
message(STATUS " USD root: ${USD_ROOT}")
|
|
message(STATUS " Monolithic: ${USE_MONOLITHIC_USD}")
|
|
message(STATUS " Compiler: ${CMAKE_CXX_COMPILER}")
|
|
message(STATUS " C++ Standard: ${CMAKE_CXX_STANDARD}")
|
|
message(STATUS "")
|
|
message(STATUS "Targets:")
|
|
message(STATUS " - crate_reader")
|
|
message(STATUS " - crate_writer")
|
|
message(STATUS " - crate_internal_api")
|
|
message(STATUS "========================================")
|