72 base_flag =
object->base_flag;
79 object->base_flag = base_flag;
88 : writer_(writer), newly_created_(newly_created)
107 return newly_created_;
110EnsuredWriter::operator bool()
const
112 return writer_ !=
nullptr;
122 Object *
object = context.object;
150 const RigidBodyOb *rbo = context.object->rigidbody_object;
156 const RigidBodyOb *rbo = context.object->rigidbody_object;
187 "release_writers() should be called before the AbstractHierarchyIterator goes out of scope");
192 export_graph_construct();
193 connect_loose_objects();
194 export_graph_prune();
198 export_graph_clear();
231 if (original_name.empty()) {
249 return path_concatenate(context->export_path, get_object_data_name(context->object));
252void AbstractHierarchyIterator::debug_print_export_graph(
const ExportGraph &graph)
const
254 size_t total_graph_size = 0;
255 for (
const auto item : graph.items()) {
260 if (duplicator !=
nullptr) {
261 fmt::println(
" DU {} (as dupped by {}):",
262 export_parent ==
nullptr ?
"-null-" : (export_parent->
id.
name + 2),
266 fmt::println(
" OB {}:",
267 export_parent ==
nullptr ?
"-null-" : (export_parent->
id.
name + 2));
270 total_graph_size += item.value.size();
271 for (HierarchyContext *child_ctx : item.value) {
272 if (child_ctx->duplicator ==
nullptr) {
273 fmt::println(
" - {}{}{}",
274 child_ctx->export_name.c_str(),
275 child_ctx->weak_export ?
" (weak)" :
"",
276 child_ctx->original_export_path.empty() ?
278 (std::string(
"ref ") + child_ctx->original_export_path).c_str());
281 fmt::println(
" - {} (dup by {}{}) {}",
282 child_ctx->export_name.c_str(),
283 child_ctx->duplicator->id.name + 2,
284 child_ctx->weak_export ?
", weak" :
"",
285 child_ctx->original_export_path.empty() ?
287 (std::string(
"ref ") + child_ctx->original_export_path).c_str());
291 fmt::println(
" (Total graph size: {} objects)", total_graph_size);
294void AbstractHierarchyIterator::export_graph_construct()
301 DEGObjectIterSettings deg_iter_settings{};
309 visit_object(
object, object->parent, weak_export);
318 if (!duplilist.is_empty()) {
319 DupliParentFinder dupli_parent_finder;
321 for (
const DupliObject &dupli_object : duplilist) {
325 dupli_parent_finder.insert(&dupli_object);
328 for (
const DupliObject &dupli_object : duplilist) {
332 visit_dupli_object(&dupli_object,
object, dupli_parent_finder);
341void AbstractHierarchyIterator::connect_loose_objects()
349 for (
const HierarchyContext *child : children) {
352 loose_objects_graph.remove(child_oid);
359 for (
const ObjectIdentifier &graph_key : loose_objects_graph.keys()) {
360 Object *
object = graph_key.object;
367 visit_object(
object, object->parent,
true);
375 object =
object->parent;
384 bool all_is_weak = context !=
nullptr && context->weak_export;
391 all_is_weak &= child_tree_is_weak;
393 if (child_tree_is_weak) {
395 clean_graph.
lookup(map_key).remove(child_context);
396 delete child_context;
403 clean_graph.
remove(map_key);
409void AbstractHierarchyIterator::export_graph_prune()
416void AbstractHierarchyIterator::export_graph_clear()
419 for (HierarchyContext *context : children) {
427void AbstractHierarchyIterator::visit_object(Object *
object,
428 Object *export_parent,
431 HierarchyContext *
context =
new HierarchyContext();
433 context->is_object_data_context =
false;
434 context->export_name = get_object_name(
object, export_parent);
435 context->export_parent = export_parent;
437 context->weak_export = weak_export;
438 context->animation_check_include_parent =
false;
440 context->original_export_path =
"";
441 context->higher_up_export_path =
"";
442 context->is_duplisource =
false;
443 context->matrix_world =
object->object_to_world();
446 context_update_for_graph_index(context, graph_index);
466void AbstractHierarchyIterator::visit_dupli_object(
const DupliObject *dupli_object,
471 context->object = dupli_object->
ob;
472 context->is_object_data_context =
false;
473 context->duplicator = duplicator;
475 context->weak_export =
false;
476 context->export_path =
"";
477 context->original_export_path =
"";
478 context->animation_check_include_parent =
false;
479 context->is_duplisource =
false;
480 context->matrix_world =
float4x4(dupli_object->
mat);
483 std::string export_name = get_object_name(context->object) +
"-" +
484 context->persistent_id.as_object_name_suffix();
490 context, dupli_object, dupli_parent_finder);
491 context_update_for_graph_index(context, graph_index);
495 if (dupli_object->
ob) {
507 if (dupli_parent !=
nullptr) {
513void AbstractHierarchyIterator::context_update_for_graph_index(
517 context->export_parent = graph_index.
object;
524 if (context->export_parent != context->object->parent) {
528 context->animation_check_include_parent =
true;
541void AbstractHierarchyIterator::determine_export_paths(
const HierarchyContext *parent_context)
543 const std::string &parent_export_path = parent_context ? parent_context->
export_path :
"";
551 context->export_path =
path_concatenate(parent_export_path, context->export_name);
553 if (context->duplicator ==
nullptr) {
556 ID *source_ob = &context->object->id;
559 if (context->object->data !=
nullptr) {
560 ID *source_data = context->object->data;
565 determine_export_paths(context);
569bool AbstractHierarchyIterator::determine_duplication_references(
579 bool contains_proxy_prototype =
false;
581 for (HierarchyContext *context : *children) {
582 if (
context->duplicator !=
nullptr) {
583 ID *source_id = &
context->object->id;
587 context->mark_as_not_instanced();
589 contains_proxy_prototype =
true;
592 context->mark_as_instance_of(*source_path);
596 ID *source_data_id =
context->object->data;
600 context->mark_as_not_instanced();
610 context->is_duplisource =
true;
614 if (determine_duplication_references(context, indent +
" ")) {
618 context->mark_as_not_instanced();
619 ID *source_id = &
context->object->id;
622 contains_proxy_prototype =
true;
625 return contains_proxy_prototype;
628void AbstractHierarchyIterator::make_writers(
const HierarchyContext *parent_context)
632 if (parent_context) {
633 parent_matrix_inv_world =
math::invert(parent_context->matrix_world);
644 bool has_point_instance_ancestor =
false;
645 if (parent_context &&
646 (parent_context->is_point_instance || parent_context->has_point_instance_ancestor))
648 has_point_instance_ancestor =
true;
651 for (HierarchyContext *context : *children) {
652 context->has_point_instance_ancestor = has_point_instance_ancestor;
655 context->parent_matrix_inv_world = parent_matrix_inv_world;
656 if (parent_context !=
nullptr) {
657 context->higher_up_export_path = parent_context->export_path;
661 EnsuredWriter transform_writer = ensure_writer(
664 if (!transform_writer) {
670 const bool need_writers =
context->is_point_proto || (!
context->is_point_instance &&
671 !
context->has_point_instance_ancestor);
678 transform_writer->write(*context);
682 make_writers_particle_systems(context);
683 make_writer_object_data(context);
688 make_writers(context);
699 HierarchyContext data_context = *object_context;
701 data_context.higher_up_export_path = object_context->export_path;
702 data_context.export_name = get_object_data_name(data_context.object);
703 data_context.export_path =
path_concatenate(data_context.higher_up_export_path,
704 data_context.export_name);
708 data_context.is_parent = children ? (children->size() > 0) :
false;
713void AbstractHierarchyIterator::make_writer_object_data(
const HierarchyContext *context)
715 if (
context->object->data ==
nullptr) {
719 HierarchyContext data_context = context_for_object_data(context);
720 if (data_context.is_instance()) {
721 ID *object_data =
context->object->data;
729 EnsuredWriter data_writer = ensure_writer(&data_context,
736 data_writer->write(data_context);
740void AbstractHierarchyIterator::make_writers_particle_systems(
743 Object *
object = transform_context->object;
744 ParticleSystem *psys =
object->particlesystem.first();
745 for (; psys; psys = psys->next) {
750 HierarchyContext hair_context = *transform_context;
753 hair_context.export_name);
754 hair_context.higher_up_export_path = transform_context->export_path;
755 hair_context.particle_system = psys;
757 EnsuredWriter writer;
758 switch (psys->part->
type) {
783 writer->write(hair_context);
788std::string AbstractHierarchyIterator::get_object_name(
const Object *
object)
const
793std::string AbstractHierarchyIterator::get_object_name(
const Object *
object,
const Object *parent)
799std::string AbstractHierarchyIterator::get_object_data_name(
const Object *
object)
const
801 const ID *object_data =
object->data;
806 const std::string &export_path)
const
812 const HierarchyContext *context, AbstractHierarchyIterator::create_writer_func create_func)
815 if (writer !=
nullptr) {
819 writer = (this->*create_func)(context);
820 if (writer ==
nullptr) {
829 const std::string &child_path)
const
831 return parent_path +
"/" + child_path;
839 const Object *duplicator)
const
General operations, lookup, etc. for blender objects.
#define DEG_OBJECT_ITER_BEGIN(settings_, instance_)
#define DEG_OBJECT_ITER_END
ID and Library types, which are fundamental for SDNA.
Object is a sort of wrapper for general info.
Types and defines for representing Rigid Body entities.
#define BLI_assert_msg(a, msg)
const Value * lookup_ptr(const Key &key) const
bool add_overwrite(const Key &key, const Value &value)
ValueIterator values() const &
bool add(const Key &key, const Value &value)
const Value & lookup(const Key &key) const
Value lookup_default(const Key &key, const Value &default_value) const
void clear_and_keep_capacity()
void remove_contained(const Key &key)
void add_new(const Key &key, const Value &value)
bool remove(const Key &key)
bool contains(const Key &key) const
Value & lookup_or_add(const Key &key, const Value &value)
bool contains_as(const ForwardKey &key) const
bool contains(const Key &key) const
void add_new(const Key &key)
Map< ObjectIdentifier, ExportChildren > ExportGraph
virtual ObjectIdentifier determine_graph_index_object(const HierarchyContext *context)
Set< HierarchyContext * > ExportChildren
virtual ~AbstractHierarchyIterator()
virtual bool include_child_writers(const HierarchyContext *) const
virtual void release_writer(AbstractHierarchyWriter *writer)=0
ExportChildren * graph_children(const HierarchyContext *context)
virtual bool mark_as_weak_export(const Object *object) const
void set_export_subset(ExportSubset export_subset)
ExportGraph export_graph_
DupliSources duplisources_
virtual std::string get_id_name(const ID *id) const
virtual AbstractHierarchyWriter * create_particle_writer(const HierarchyContext *context)=0
ExportPathMap duplisource_export_path_
virtual AbstractHierarchyWriter * create_transform_writer(const HierarchyContext *context)=0
AbstractHierarchyIterator(Main *bmain, Depsgraph *depsgraph)
virtual bool should_visit_dupli_object(const DupliObject *dupli_object, const Object *duplicator) const
virtual void iterate_and_write()
virtual std::string make_unique_name(const std::string &original_name, Set< std::string > &used_names)
virtual std::string path_concatenate(const std::string &parent_path, const std::string &child_path) const
virtual ObjectIdentifier determine_graph_index_dupli(const HierarchyContext *context, const DupliObject *dupli_object, const DupliParentFinder &dupli_parent_finder)
AbstractHierarchyWriter * get_writer(const std::string &export_path) const
virtual AbstractHierarchyWriter * create_data_writer(const HierarchyContext *context)=0
virtual AbstractHierarchyWriter * create_hair_writer(const HierarchyContext *context)=0
ExportUsedNameMap used_names_
virtual std::string make_valid_name(const std::string &name) const
ExportSubset export_subset_
virtual std::string get_object_data_path(const HierarchyContext *context) const
virtual bool include_data_writers(const HierarchyContext *) const
virtual bool check_is_animated(const HierarchyContext &context) const
static bool check_has_deforming_physics(const HierarchyContext &context)
static bool check_has_physics(const HierarchyContext &context)
const DupliObject * find_suitable_export_parent(const DupliObject *dupli_ob) const
bool is_newly_created() const
static EnsuredWriter empty()
static EnsuredWriter existing(AbstractHierarchyWriter *writer)
static EnsuredWriter newly_created(AbstractHierarchyWriter *writer)
AbstractHierarchyWriter * operator->()
static ObjectIdentifier for_graph_root()
static ObjectIdentifier for_duplicated_object(const DupliObject *dupli_object, Object *duplicated_by)
static ObjectIdentifier for_real_object(Object *object)
static ObjectIdentifier for_hierarchy_context(const HierarchyContext *context)
GeometrySet object_get_evaluated_geometry_set(const Object &object, bool apply_subdiv=true)
int context(const bContext *C, const char *member, bContextDataResult *result)
void add_new(const MultiFunction &fn)
static bool remove_weak_subtrees(const HierarchyContext *context, AbstractHierarchyIterator::ExportGraph &clean_graph, const AbstractHierarchyIterator::ExportGraph &input_graph)
CartesianBasis invert(const CartesianBasis &basis)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
@ PART_FLUID_SPRAYFOAMBUBBLE
bool BKE_animdata_id_is_animated(const ID *id)
MatBase< float, 4, 4 > float4x4
size_t void BLI_uniquename_cb(FunctionRef< bool(StringRefNull)> unique_check, const char *defname, char delim, char *name, size_t name_maxncpy) ATTR_NONNULL(2
void object_duplilist(Depsgraph *depsgraph, Object *ob, Set< const Object * > *include_objects, DupliList &r_duplilist)
int BKE_object_visibility(const Object *ob, int dag_eval_mode)
@ DEG_ITER_OBJECT_FLAG_LINKED_VIA_SET
@ DEG_ITER_OBJECT_FLAG_LINKED_DIRECTLY
VectorList< DupliObject > DupliList
eEvaluationMode DEG_get_mode(const Depsgraph *graph)
bool psys_check_enabled(struct Object *ob, struct ParticleSystem *psys, bool use_render_params)
bool DEG_is_evaluated_id(const ID *id)
bool DEG_iterator_dupli_is_visible(const DupliObject *dupli, eEvaluationMode eval_mode)
Key * BKE_key_from_object(Object *ob)
static MatBase identity()
struct ModifierData * next
struct Collection * instance_collection
bool has_instances() const
bool is_prototype() const
bool is_point_instancer() const
bool is_object_visible(enum eEvaluationMode evaluation_mode) const
void mark_as_not_instanced()
std::string original_export_path
static const HierarchyContext * root()
bool is_object_data_context
void mark_as_instance_of(const std::string &reference_export_path)