319c64205d
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