43 pxr::UsdStageRefPtr stage,
63 return !params_.export_meshes;
65 return !params_.export_cameras;
67 return !params_.export_lights;
70 return !params_.export_curves;
72 return !params_.export_volumes;
74 return !params_.export_armatures;
76 return !params_.export_points;
98 skinned_mesh_export_map_,
99 shape_key_mesh_export_map_,
108 export_time_ = pxr::UsdTimeCode(frame_nr);
115 path = pxr::SdfPath(params_.
root_prim_path + context->export_path);
118 path = pxr::SdfPath(context->export_path);
121 if (params_.
merge_parent_xform && context->is_object_data_context && !context->is_parent) {
122 bool can_merge_with_xform =
true;
124 can_merge_with_xform =
false;
127 if (params_.
use_instancing && (context->is_prototype() || context->is_instance())) {
128 can_merge_with_xform =
false;
131 if (can_merge_with_xform) {
132 path = path.GetParentPath();
138 const pxr::SdfLayerHandle root_layer = stage_->GetRootLayer();
139 const std::string export_file_path = root_layer->GetRealPath();
140 auto get_time_code = [
this]() {
return this->export_time_; };
142 USDExporterContext exporter_context = USDExporterContext{
bmain_,
156 this->add_usd_skel_export_mapping(obj, usd_path);
159 return exporter_context;
172 bool is_referencing_self =
false;
173 if (context->is_point_instancer()) {
178 pxr::SdfPath instancer_path;
179 if (!params_.root_prim_path.empty()) {
180 instancer_path = pxr::SdfPath(params_.root_prim_path + context->export_path);
183 instancer_path = pxr::SdfPath(context->export_path);
186 if (children !=
nullptr) {
188 if (!child_context->original_export_path.empty()) {
189 const pxr::SdfPath parent_export_path(context->export_path);
190 const pxr::SdfPath children_original_export_path(child_context->original_export_path);
193 if (parent_export_path.HasPrefix(children_original_export_path)) {
194 is_referencing_self =
true;
199 pxr::SdfPath prototype_path;
200 if (child_context->is_instance() && child_context->duplicator !=
nullptr) {
203 if (!params_.root_prim_path.empty()) {
204 prototype_path = pxr::SdfPath(params_.root_prim_path +
205 child_context->original_export_path);
208 prototype_path = pxr::SdfPath(child_context->original_export_path);
211 prototype_paths_.lookup_or_add(instancer_path, {})
212 .add(std::make_pair(prototype_path, child_context->object));
213 child_context->is_point_instance =
true;
218 if (!params_.root_prim_path.empty()) {
219 prototype_path = pxr::SdfPath(params_.root_prim_path + child_context->export_path);
222 prototype_path = pxr::SdfPath(child_context->export_path);
225 prototype_paths_.lookup_or_add(instancer_path, {})
226 .add(std::make_pair(prototype_path, child_context->object));
227 child_context->is_point_proto =
true;
235 if (is_referencing_self) {
237 params_.worker_status->reports,
239 "One or more objects used as prototypes in 'Instance on Points' nodes either do not "
240 "have 'As Instance' enabled in their 'Object Info' nodes, or the prototype is the "
241 "base geometry input itself. Both cases prevent valid point instancer export. If it's "
242 "the former, enable 'As Instance' to avoid incorrect self-referencing.");
250 child_context->is_point_instance =
false;
251 child_context->is_point_proto =
false;
256 return !is_referencing_self;
264 if (params_.use_instancing) {
281 usd_export_context.
usd_path.GetParentPath());
282 const bool use_point_instancing = context->is_point_instancer() &&
283 (proto_paths && !proto_paths->
is_empty());
285 switch (context->object->type) {
291 if (params_.use_instancing && use_point_instancing) {
294 std::unique_ptr<USDMeshWriter> mesh_writer = std::make_unique<USDMeshWriter>(
298 usd_export_context, *proto_paths, std::move(mesh_writer));
333 if (params_.use_instancing && use_point_instancing) {
336 std::unique_ptr<USDCurvesWriter> curves_writer = std::make_unique<USDCurvesWriter>(
340 usd_export_context, *proto_paths, std::move(curves_writer));
368 if (params_.use_instancing && use_point_instancing) {
370 context, usd_export_context);
371 std::unique_ptr<USDPointsWriter> point_cloud_writer = std::make_unique<USDPointsWriter>(
372 point_cloud_context);
375 usd_export_context, *proto_paths, std::move(point_cloud_writer));
401 if (data_writer && !data_writer->
is_supported(context)) {
406 if (data_writer && (params_.export_armatures || params_.export_shapekeys)) {
407 add_usd_skel_export_mapping(context->object, data_writer->
usd_path());
415 if (!params_.export_hair) {
418 return new USDHairWriter(create_usd_export_context(context));
431 return !(params_.use_instancing && context->is_instance());
438 return !(params_.use_instancing && context->is_instance());
441void USDHierarchyIterator::add_usd_skel_export_mapping(
const Object *
obj,
const pxr::SdfPath &path)
444 shape_key_mesh_export_map_.
add(
obj, path);
448 armature_export_map_.
add(
obj, path);
454 skinned_mesh_export_map_.
add(obj, path);
460 return exported_prim_map_;
475 Vector<ID *> &id_list = exported_prim_map_.lookup_or_add_default(usd_path);
486 std::string base_name = std::string(
BKE_id_name(context->object->id)).append(
"_base");
489 pxr::SdfPath base_path = export_context.
usd_path.GetParentPath().AppendChild(
490 pxr::TfToken(safe_name));
492 return {export_context.
bmain,
494 export_context.
stage,
Object is a sort of wrapper for general info.
#define BLI_assert_unreachable()
#define BLI_assert_msg(a, msg)
bool add(const Key &key, const Value &value)
bool contains(const T &value) const
void append(const T &value)
Set< HierarchyContext * > ExportChildren
ExportChildren * graph_children(const HierarchyContext *context)
AbstractHierarchyIterator(Main *bmain, Depsgraph *depsgraph)
const pxr::SdfPath & usd_path() const
virtual bool is_supported(const HierarchyContext *context) const
USDArmatureWriter(const USDExporterContext &ctx)
USDCameraWriter(const USDExporterContext &ctx)
USDCurvesWriter(const USDExporterContext &ctx)
USDHairWriter(const USDExporterContext &ctx)
bool mark_as_weak_export(const Object *object) const override
AbstractHierarchyWriter * create_data_writer(const HierarchyContext *context) override
void add_to_prim_map(const pxr::SdfPath &usd_path, const ID *id) const
void release_writer(AbstractHierarchyWriter *writer) override
bool determine_point_instancers(const HierarchyContext *context)
AbstractHierarchyWriter * create_particle_writer(const HierarchyContext *context) override
void process_usd_skel() const
USDHierarchyIterator(Main *bmain, Depsgraph *depsgraph, pxr::UsdStageRefPtr stage, const USDExportParams ¶ms)
const Map< pxr::SdfPath, Vector< ID * > > & get_exported_prim_map() const
AbstractHierarchyWriter * create_hair_writer(const HierarchyContext *context) override
bool include_child_writers(const HierarchyContext *context) const override
pxr::UsdStageRefPtr get_stage() const
bool include_data_writers(const HierarchyContext *context) const override
std::string make_valid_name(const std::string &name) const override
AbstractHierarchyWriter * create_transform_writer(const HierarchyContext *context) override
void set_export_frame(float frame_nr)
USDLightWriter(const USDExporterContext &ctx)
USDMeshWriter(const USDExporterContext &ctx)
USDPointInstancerWriter(const USDExporterContext &ctx, const Set< std::pair< pxr::SdfPath, Object * > > &prototype_paths, std::unique_ptr< USDAbstractWriter > base_writer)
USDPointsWriter(const USDExporterContext &ctx)
USDTextWriter(const USDExporterContext &ctx)
USDVolumeWriter(const USDExporterContext &ctx)
void skel_export_chaser(pxr::UsdStageRefPtr stage, const ObjExportMap &armature_export_map, const ObjExportMap &skinned_mesh_export_map, const ObjExportMap &shape_key_mesh_export_map, const Depsgraph *depsgraph)
std::string make_safe_name(const StringRef name, bool allow_unicode)
void create_skel_roots(pxr::UsdStageRefPtr stage, const USDExportParams ¶ms)
bool can_export_skinned_mesh(const Object &obj, const Depsgraph *depsgraph)
bool is_mesh_with_shape_keys(const Object *obj)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
ID * BKE_libblock_find_name(Main *bmain, short type, const char *name, const std::optional< Library * > lib=std::nullopt) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
const char * BKE_id_name(const ID &id)
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
ID_Type GS(const char *name)
std::string root_prim_path
std::function< pxr::UsdTimeCode()> get_time_code
std::function< std::string(Main *, Scene *, Image *, ImageUser *)> export_image_fn
std::function< void(const Object *, const pxr::SdfPath &)> add_skel_mapping_fn
const USDExportParams & export_params
USDHierarchyIterator * hierarchy_iterator
const pxr::SdfPath usd_path
std::string export_file_path
const pxr::UsdStageRefPtr stage