Files
test2/source/blender/io/usd/CMakeLists.txt
Michael Kowalski 319c64205d USD: Scene graph instancing export
Refactored USD instancing export to support instanceable references.

With this change, it's now possible to instance object hierarchies and
geometry types other than meshes (e.g., curves, point clouds, etc.).

No longer marking mesh prims as instances in
USDGenericMeshWriter::write_mesh().

USDTransformWriter::do_write() now marks the Xform as instanceable
with a reference to the prototype's Xform when the Blender object is
an instance.

In USDAbstractWriter::mark_as_instance() the target prim is now marked
as instanceable.

Added AbstractHierarchyIterator virtual functions include_data_writers()
and include_child_writers() to allow pruning children of instanceable Xforms
in AbstractHierarchyIterator::make_writers(). These functions return true
in the base class implementation, so that the iterator behavior for Alembic
exports is unaffected.  In the USDHierarchyIterator subclass, these functions
are overridden to return false if instancing is enabled and the objects are
instances.

Added virtual function AbstractHierarchyIterator::should_determine_duplication_references()
which returns true if duplication references should be resolved for children
of a given context.  This function is overridden in USDHierarchyIterator to
skip processing children of instances, which is more efficient for USD export,
since children of instances are pruned during traversal for writing.  For nested
instances where the original prototype is not included in the export, this also
avoids designating a duplicated object parented to an instance as "the original",
which would cause USD errors since defining a prim under an instance
proxy is not allowed.

Extended logic in `AbstractHierarchyIterator::determine_duplication_references()`
to identify prototypes.

Added new function `HierarchyContext::is_prototype()`.

Disallowing merging with parent for instances and prototypes, since
the Xforms cannot be discarded in those cases.

Extended `USDWriterAbstract::ensure_usd_material()` with special logic
to ensure materials for prototype prims are defined in the subtree of the
prototype.  This helps ensure the hierarchical encapsulation requirement
for prototypes and is required by certain renderers (e.g., Houdini's Karma)
for instance materials to render.

Added a new `process_scene_graph_instances()` function to ensure
prototypes are exported as abstract prims.

Added python tests test_export_native_instancing_true and
test_export_native_instancing_false.

Pull Request: https://projects.blender.org/blender/blender/pulls/131707
2025-01-28 15:51:56 +01:00

261 lines
6.4 KiB
CMake

# SPDX-FileCopyrightText: 2019 Blender Authors
#
# SPDX-License-Identifier: GPL-2.0-or-later
# This suppresses the warning "This file includes at least one deprecated or antiquated
# header which may be removed without further notice at a future date", which is caused
# by the USD library including <ext/hash_set> on Linux. This has been reported at:
# https://github.com/PixarAnimationStudios/USD/issues/1057.
if(UNIX AND NOT APPLE)
add_definitions(-D_GLIBCXX_PERMIT_BACKWARD_HASH)
endif()
if(WIN32)
add_definitions(-DNOMINMAX -DWIN32_LEAN_AND_MEAN -DBOOST_DEBUG_PYTHON)
endif()
add_definitions(-DBOOST_ALL_NO_LIB)
# Pre-compiled Linux libraries are made with GCC, and USD uses some extensions
# which lead to an incompatible ABI for Clang. Using those extensions with
# Clang as well works around the issue.
if(UNIX AND NOT APPLE)
if(CMAKE_C_COMPILER_ID MATCHES "Clang")
if(DEFINED LIBDIR)
add_definitions(-DARCH_HAS_GNU_STL_EXTENSIONS)
endif()
endif()
endif()
# USD headers use deprecated TBB headers, silence warning.
add_definitions(-DTBB_SUPPRESS_DEPRECATED_MESSAGES=1)
if(WIN32)
# Some USD library headers trigger the "unreferenced formal parameter"
# warning alert.
# Silence them by restore warn C4100 back to w4
remove_cc_flag("/w34100")
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "ARM64")
# USD currently does not support the new preprocessor,
# so we remove it here and disable sse2neon
remove_cc_flag("/Zc:preprocessor")
add_definitions(-DDISABLE_SSE2NEON)
endif()
endif()
set(INC
.
../common
../../editors/include
../../makesrna
../../python/intern
../../../../intern/utfconv
# RNA_prototypes.hh
${CMAKE_BINARY_DIR}/source/blender/makesrna
)
set(INC_SYS
${USD_INCLUDE_DIRS}
${BOOST_INCLUDE_DIR}
${TBB_INCLUDE_DIR}
${PYTHON_INCLUDE_DIR}
)
set(SRC
intern/usd_armature_utils.cc
intern/usd_asset_utils.cc
intern/usd_attribute_utils.cc
intern/usd_blend_shape_utils.cc
intern/usd_capi_export.cc
intern/usd_capi_import.cc
intern/usd_hierarchy_iterator.cc
intern/usd_hook.cc
intern/usd_instancing_utils.cc
intern/usd_light_convert.cc
intern/usd_mesh_utils.cc
intern/usd_utils.cc
intern/usd_writer_abstract.cc
intern/usd_writer_armature.cc
intern/usd_writer_camera.cc
intern/usd_writer_curves.cc
intern/usd_writer_hair.cc
intern/usd_writer_light.cc
intern/usd_writer_material.cc
intern/usd_writer_mesh.cc
intern/usd_writer_metaball.cc
intern/usd_writer_points.cc
intern/usd_writer_transform.cc
intern/usd_writer_volume.cc
intern/usd_reader_camera.cc
intern/usd_reader_curve.cc
intern/usd_reader_geom.cc
intern/usd_reader_instance.cc
intern/usd_reader_light.cc
intern/usd_reader_material.cc
intern/usd_reader_mesh.cc
intern/usd_reader_nurbs.cc
intern/usd_reader_pointinstancer.cc
intern/usd_reader_points.cc
intern/usd_reader_prim.cc
intern/usd_reader_shape.cc
intern/usd_reader_skeleton.cc
intern/usd_reader_stage.cc
intern/usd_reader_utils.cc
intern/usd_reader_volume.cc
intern/usd_reader_xform.cc
intern/usd_skel_convert.cc
intern/usd_skel_root_utils.cc
usd.hh
usd_private.hh
intern/usd_armature_utils.hh
intern/usd_asset_utils.hh
intern/usd_attribute_utils.hh
intern/usd_blend_shape_utils.hh
intern/usd_exporter_context.hh
intern/usd_hash_types.hh
intern/usd_hierarchy_iterator.hh
intern/usd_hook.hh
intern/usd_instancing_utils.hh
intern/usd_light_convert.hh
intern/usd_mesh_utils.hh
intern/usd_utils.hh
intern/usd_writer_abstract.hh
intern/usd_writer_armature.hh
intern/usd_writer_camera.hh
intern/usd_writer_curves.hh
intern/usd_writer_hair.hh
intern/usd_writer_light.hh
intern/usd_writer_material.hh
intern/usd_writer_mesh.hh
intern/usd_writer_metaball.hh
intern/usd_writer_points.hh
intern/usd_writer_transform.hh
intern/usd_writer_volume.hh
intern/usd_reader_camera.hh
intern/usd_reader_curve.hh
intern/usd_reader_geom.hh
intern/usd_reader_instance.hh
intern/usd_reader_light.hh
intern/usd_reader_material.hh
intern/usd_reader_mesh.hh
intern/usd_reader_nurbs.hh
intern/usd_reader_pointinstancer.hh
intern/usd_reader_points.hh
intern/usd_reader_prim.hh
intern/usd_reader_shape.hh
intern/usd_reader_skeleton.hh
intern/usd_reader_stage.hh
intern/usd_reader_utils.hh
intern/usd_reader_volume.hh
intern/usd_reader_xform.hh
intern/usd_skel_convert.hh
intern/usd_skel_root_utils.hh
)
if(WITH_HYDRA)
list(APPEND SRC
hydra/curves.cc
hydra/hydra_scene_delegate.cc
hydra/id.cc
hydra/image.cc
hydra/instancer.cc
hydra/light.cc
hydra/material.cc
hydra/mesh.cc
hydra/object.cc
hydra/usd_scene_delegate.cc
hydra/volume.cc
hydra/volume_modifier.cc
hydra/world.cc
hydra/curves.hh
hydra/hydra_scene_delegate.hh
hydra/id.hh
hydra/image.hh
hydra/instancer.hh
hydra/light.hh
hydra/material.hh
hydra/mesh.hh
hydra/object.hh
hydra/usd_scene_delegate.hh
hydra/volume.hh
hydra/volume_modifier.hh
hydra/world.hh
)
endif()
set(LIB
PRIVATE bf::blenkernel
PRIVATE bf::blenlib
PRIVATE bf::blenloader
PRIVATE bf::blentranslation
PRIVATE bf::bmesh
PRIVATE bf::depsgraph
PRIVATE bf::dna
PRIVATE bf::animrig
PRIVATE bf::imbuf
PRIVATE bf::intern::clog
PRIVATE bf::intern::guardedalloc
bf_io_common
PRIVATE bf::extern::fmtlib
PRIVATE bf::nodes
PRIVATE bf::windowmanager
)
list(APPEND LIB
${BOOST_PYTHON_LIBRARIES}
${PYTHON_LIBRARIES}
${USD_LIBRARIES}
${TBB_LIBRARIES}
)
if(WITH_OPENVDB)
add_definitions(-DWITH_OPENVDB ${OPENVDB_DEFINITIONS})
list(APPEND INC
../../../../intern/openvdb
)
list(APPEND INC_SYS
${OPENVDB_INCLUDE_DIRS}
)
list(APPEND LIB
${OPENVDB_LIBRARIES}
)
endif()
if(WITH_MATERIALX)
add_definitions(-DWITH_MATERIALX)
list(APPEND LIB MaterialXCore)
endif()
blender_add_lib(bf_io_usd "${SRC}" "${INC}" "${INC_SYS}" "${LIB}")
# RNA_prototypes.hh
add_dependencies(bf_io_usd bf_rna)
if(COMMAND target_precompile_headers)
target_precompile_headers(bf_io_usd PRIVATE intern/usd_precomp.hh)
endif()
if(WITH_GTESTS)
set(TEST_SRC
tests/usd_export_test.cc
tests/usd_stage_creation_test.cc
tests/usd_usdz_export_test.cc
intern/usd_writer_material.hh
)
include_directories(intern)
set(TEST_INC
)
set(TEST_LIB
bf_blenloader_test_util
)
blender_add_test_suite_lib(io_usd "${TEST_SRC}" "${INC};${TEST_INC}" "${INC_SYS}" "${LIB};${TEST_LIB}")
endif()