41 pxr::UsdStageRefPtr stage,
53 switch (object->
type) {
60 return !params_.export_meshes;
62 return !params_.export_cameras;
64 return !params_.export_lights;
67 return !params_.export_curves;
69 return !params_.export_volumes;
71 return !params_.export_armatures;
73 return !params_.export_points;
95 skinned_mesh_export_map_,
96 shape_key_mesh_export_map_,
105 export_time_ = pxr::UsdTimeCode(frame_nr);
112 path = pxr::SdfPath(params_.
root_prim_path + context->export_path);
115 path = pxr::SdfPath(context->export_path);
118 if (params_.
merge_parent_xform && context->is_object_data_context && !context->is_parent) {
119 bool can_merge_with_xform =
true;
121 can_merge_with_xform =
false;
124 if (params_.
use_instancing && (context->is_prototype() || context->is_instance())) {
125 can_merge_with_xform =
false;
128 if (can_merge_with_xform) {
129 path = path.GetParentPath();
135 const pxr::SdfLayerHandle root_layer = stage_->GetRootLayer();
136 const std::string export_file_path = root_layer->GetRealPath();
137 auto get_time_code = [
this]() {
return this->export_time_; };
139 USDExporterContext exporter_context = USDExporterContext{
140 bmain_,
depsgraph_, stage_, path, get_time_code, params_, export_file_path,
nullptr};
145 this->add_usd_skel_export_mapping(obj, path);
148 return exporter_context;
161 if (context->is_point_instancer()) {
166 bool is_referencing_self =
false;
168 pxr::SdfPath instancer_path;
169 if (strlen(params_.root_prim_path) != 0) {
170 instancer_path = pxr::SdfPath(std::string(params_.root_prim_path) + context->export_path);
173 instancer_path = pxr::SdfPath(context->export_path);
176 if (children !=
nullptr) {
178 if (!child_context->original_export_path.empty()) {
179 const pxr::SdfPath parent_export_path(context->export_path);
180 const pxr::SdfPath children_original_export_path(child_context->original_export_path);
183 if (parent_export_path.HasPrefix(children_original_export_path)) {
184 is_referencing_self =
true;
189 pxr::SdfPath prototype_path;
190 if (child_context->is_instance() && child_context->duplicator !=
nullptr) {
193 if (strlen(params_.root_prim_path) != 0) {
194 prototype_path = pxr::SdfPath(std::string(params_.root_prim_path) +
195 child_context->original_export_path);
198 prototype_path = pxr::SdfPath(child_context->original_export_path);
201 prototype_paths[instancer_path].insert(
202 std::make_pair(prototype_path, child_context->object));
203 child_context->is_point_instance =
true;
208 if (strlen(params_.root_prim_path) != 0) {
209 prototype_path = pxr::SdfPath(std::string(params_.root_prim_path) +
210 child_context->export_path);
213 prototype_path = pxr::SdfPath(child_context->export_path);
216 prototype_paths[instancer_path].insert(
217 std::make_pair(prototype_path, child_context->object));
218 child_context->is_point_proto =
true;
226 if (is_referencing_self) {
228 params_.worker_status->reports,
230 "One or more objects used as prototypes in 'Instance on Points' nodes either do not "
231 "have 'As Instance' enabled in their 'Object Info' nodes, or the prototype is the "
232 "base geometry input itself. Both cases prevent valid point instancer export. If it's "
233 "the former, enable 'As Instance' to avoid incorrect self-referencing.");
235 prototype_paths[instancer_path].clear();
237 child_context->is_point_instance =
false;
238 child_context->is_point_proto =
false;
249 if (params_.use_instancing) {
260 std::set<std::pair<pxr::SdfPath, Object *>> proto_paths =
261 prototype_paths[usd_export_context.
usd_path.GetParentPath()];
263 switch (context->object->type) {
266 if (params_.use_instancing && context->is_point_instancer() && !proto_paths.empty()) {
269 std::unique_ptr<USDMeshWriter> mesh_writer = std::make_unique<USDMeshWriter>(
273 usd_export_context, proto_paths, std::move(mesh_writer));
308 if (params_.use_instancing && context->is_point_instancer() && !proto_paths.empty()) {
311 std::unique_ptr<USDCurvesWriter> curves_writer = std::make_unique<USDCurvesWriter>(
315 usd_export_context, proto_paths, std::move(curves_writer));
343 if (params_.use_instancing && context->is_point_instancer() && !proto_paths.empty()) {
345 context, usd_export_context);
346 std::unique_ptr<USDPointsWriter> point_cloud_writer = std::make_unique<USDPointsWriter>(
347 point_cloud_context);
350 usd_export_context, proto_paths, std::move(point_cloud_writer));
377 if (data_writer && !data_writer->
is_supported(context)) {
382 if (data_writer && (params_.export_armatures || params_.export_shapekeys)) {
383 add_usd_skel_export_mapping(context->object, data_writer->
usd_path());
391 if (!params_.export_hair) {
394 return new USDHairWriter(create_usd_export_context(context));
407 return !(params_.use_instancing && context->is_instance());
414 return !(params_.use_instancing && context->is_instance());
417void USDHierarchyIterator::add_usd_skel_export_mapping(
const Object *
obj,
const pxr::SdfPath &path)
420 shape_key_mesh_export_map_.
add(
obj, path);
424 armature_export_map_.
add(
obj, path);
430 skinned_mesh_export_map_.
add(obj, path);
438 std::string base_name = std::string(
BKE_id_name(
context->object->id)).append(
"_base");
440 usd_export_context.export_params.allow_unicode);
442 pxr::SdfPath base_path = usd_export_context.usd_path.GetParentPath().AppendChild(
443 pxr::TfToken(safe_name));
445 USDExporterContext new_context = usd_export_context;
446 *
const_cast<pxr::SdfPath *
>(&new_context.usd_path) = base_path;
const char * BKE_id_name(const ID &id)
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
#define BLI_assert_unreachable()
#define BLI_assert_msg(a, msg)
Object is a sort of wrapper for general info.
#define BASE_SELECTED(v3d, base)
BPy_StructRNA * depsgraph
bool add(const Key &key, const Value &value)
ExportChildren * graph_children(const HierarchyContext *context)
AbstractHierarchyIterator(Main *bmain, Depsgraph *depsgraph)
blender::Set< HierarchyContext * > ExportChildren
const pxr::SdfPath & usd_path() const
virtual bool is_supported(const HierarchyContext *context) const
bool mark_as_weak_export(const Object *object) const override
AbstractHierarchyWriter * create_data_writer(const HierarchyContext *context) override
void release_writer(AbstractHierarchyWriter *writer) override
AbstractHierarchyWriter * create_particle_writer(const HierarchyContext *context) override
void process_usd_skel() const
USDHierarchyIterator(Main *bmain, Depsgraph *depsgraph, pxr::UsdStageRefPtr stage, const USDExportParams ¶ms)
AbstractHierarchyWriter * create_hair_writer(const HierarchyContext *context) override
bool include_child_writers(const HierarchyContext *context) const override
void determine_point_instancers(const HierarchyContext *context)
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)
int context(const bContext *C, const char *member, bContextDataResult *result)
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)
char root_prim_path[1024]
std::function< void(const Object *, const pxr::SdfPath &)> add_skel_mapping_fn
const USDExportParams & export_params
const pxr::SdfPath usd_path