Blender V5.3
abstract_hierarchy_iterator.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2019 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
6
7#include <string>
8
9#include <fmt/core.h>
10
11#include "BKE_anim_data.hh"
12#include "BKE_duplilist.hh"
13#include "BKE_geometry_set.hh"
15#include "BKE_key.hh"
16#include "BKE_object.hh"
17#include "BKE_particle.h"
18
19#include "BLI_assert.hh"
20#include "BLI_math_matrix.hh"
22#include "BLI_set.hh"
23#include "BLI_string_utils.hh"
24
25#include "DNA_ID.h"
26#include "DNA_layer_types.h"
27#include "DNA_modifier_types.h"
28#include "DNA_object_types.h"
29#include "DNA_particle_types.h"
30#include "DNA_rigidbody_types.h"
31
33
34namespace blender::io {
35
37{
38 return nullptr;
39}
40
42{
43 return !original_export_path.empty();
44}
45void HierarchyContext::mark_as_instance_of(const std::string &reference_export_path)
46{
47 original_export_path = reference_export_path;
48}
53
55{
56 /* The context is for a prototype if it's for a duplisource or
57 * for a duplicated object that was designated to be a prototype
58 * because the original was not included in the export. */
59 return is_duplisource || (duplicator != nullptr && !is_instance());
60}
61
62bool HierarchyContext::is_object_visible(const enum eEvaluationMode evaluation_mode) const
63{
64 const bool is_dupli = duplicator != nullptr;
65 int base_flag;
66
67 if (is_dupli) {
68 /* Construct the object's base flags from its dupli-parent, just like is done in
69 * deg_objects_dupli_iterator_next(). Without this, the visibility check below will fail. Doing
70 * this here, instead of a more suitable location in AbstractHierarchyIterator, prevents
71 * copying the Object for every dupli. */
72 base_flag = object->base_flag;
73 object->base_flag = duplicator->base_flag | BASE_FROM_DUPLI;
74 }
75
76 const int visibility = BKE_object_visibility(object, evaluation_mode);
77
78 if (is_dupli) {
79 object->base_flag = base_flag;
80 }
81
82 return (visibility & OB_VISIBLE_SELF) != 0;
83}
84
85EnsuredWriter::EnsuredWriter() : writer_(nullptr), newly_created_(false) {}
86
88 : writer_(writer), newly_created_(newly_created)
89{
90}
91
92EnsuredWriter EnsuredWriter::empty()
93{
94 return EnsuredWriter(nullptr, false);
95}
97{
98 return EnsuredWriter(writer, false);
99}
101{
102 return EnsuredWriter(writer, true);
103}
104
106{
107 return newly_created_;
108}
109
110EnsuredWriter::operator bool() const
111{
112 return writer_ != nullptr;
113}
114
116{
117 return writer_;
118}
119
121{
122 Object *object = context.object;
123
125 return true;
126 }
127 if (BKE_key_from_object(object) != nullptr) {
128 return true;
129 }
130 if (check_has_deforming_physics(context)) {
131 return true;
132 }
133
134 /* Test modifiers. */
135 /* TODO(Sybren): replace this with a check on the depsgraph to properly check for dependency on
136 * time. */
137 ModifierData *md = object->modifiers.first();
138 while (md) {
139 if (md->type != eModifierType_Subsurf) {
140 return true;
141 }
142 md = md->next;
143 }
144
145 return false;
146}
147
149{
150 const RigidBodyOb *rbo = context.object->rigidbody_object;
151 return rbo != nullptr && rbo->type == RBO_TYPE_ACTIVE;
152}
153
155{
156 const RigidBodyOb *rbo = context.object->rigidbody_object;
157 return rbo != nullptr && rbo->type == RBO_TYPE_ACTIVE && (rbo->flag & RBO_FLAG_USE_DEFORM) != 0;
158}
159
161{
162 if (!object) {
163 return false;
164 }
165
166 /* Collection instancers are handled elsewhere as part of Scene instancing. */
167 if (object->type == OB_EMPTY && object->instance_collection != nullptr) {
168 return false;
169 }
170
171 const bke::GeometrySet geometry_set = bke::object_get_evaluated_geometry_set(*object);
172 return geometry_set.has_instances();
173}
174
176 : bmain_(bmain), depsgraph_(depsgraph), export_subset_({true, true})
177{
178}
179
181{
182 /* release_writers() cannot be called here directly, as it calls into the pure-virtual
183 * release_writer() function. By the time this destructor is called, the subclass that implements
184 * that pure-virtual function is already destructed. */
187 "release_writers() should be called before the AbstractHierarchyIterator goes out of scope");
188}
189
191{
192 export_graph_construct();
193 connect_loose_objects();
194 export_graph_prune();
195 determine_export_paths(HierarchyContext::root());
196 determine_duplication_references(HierarchyContext::root(), "");
197 make_writers(HierarchyContext::root());
198 export_graph_clear();
199}
200
202{
203 for (AbstractHierarchyWriter *writer : writers_.values()) {
204 release_writer(writer);
205 }
206 writers_.clear();
207}
208
210{
211 export_subset_ = export_subset;
212}
213
214std::string AbstractHierarchyIterator::make_valid_name(const std::string &name) const
215{
216 return name;
217}
218
219std::string AbstractHierarchyIterator::get_id_name(const ID *id) const
220{
221 if (id == nullptr) {
222 return "";
223 }
224
225 return make_valid_name(std::string(id->name + 2));
226}
227
228std::string AbstractHierarchyIterator::make_unique_name(const std::string &original_name,
229 Set<std::string> &used_names)
230{
231 if (original_name.empty()) {
232 return "";
233 }
234
235 std::string name = BLI_uniquename_cb(
236 [&](const StringRef check_name) { return used_names.contains_as(check_name); },
237 '_',
238 make_valid_name(original_name));
239
240 used_names.add_new(name);
241 return name;
242}
243
245{
246 BLI_assert(!context->export_path.empty());
247 BLI_assert(context->object->data);
248
249 return path_concatenate(context->export_path, get_object_data_name(context->object));
250}
251
252void AbstractHierarchyIterator::debug_print_export_graph(const ExportGraph &graph) const
253{
254 size_t total_graph_size = 0;
255 for (const auto item : graph.items()) {
256 const ObjectIdentifier &parent_info = item.key;
257 const Object *const export_parent = parent_info.object;
258 const Object *const duplicator = parent_info.duplicated_by;
259
260 if (duplicator != nullptr) {
261 fmt::println(" DU {} (as dupped by {}):",
262 export_parent == nullptr ? "-null-" : (export_parent->id.name + 2),
263 duplicator->id.name + 2);
264 }
265 else {
266 fmt::println(" OB {}:",
267 export_parent == nullptr ? "-null-" : (export_parent->id.name + 2));
268 }
269
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() ?
277 "" :
278 (std::string("ref ") + child_ctx->original_export_path).c_str());
279 }
280 else {
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() ?
286 "" :
287 (std::string("ref ") + child_ctx->original_export_path).c_str());
288 }
289 }
290 }
291 fmt::println(" (Total graph size: {} objects)", total_graph_size);
292}
293
294void AbstractHierarchyIterator::export_graph_construct()
295{
296 /* Add a "null" root node with no children immediately for the case where the top-most node in
297 * the scene is not being exported and a root node otherwise wouldn't get added. */
298 ObjectIdentifier root_node_id = ObjectIdentifier::for_real_object(nullptr);
299 export_graph_.add_new(root_node_id, {});
300
301 DEGObjectIterSettings deg_iter_settings{};
302 deg_iter_settings.depsgraph = depsgraph_;
303 deg_iter_settings.flags = DEG_ITER_OBJECT_FLAG_LINKED_DIRECTLY |
305 DupliList duplilist;
306 DEG_OBJECT_ITER_BEGIN (&deg_iter_settings, object) {
307 /* Non-instanced objects always have their object-parent as export-parent. */
308 const bool weak_export = mark_as_weak_export(object);
309 visit_object(object, object->parent, weak_export);
310
311 if (weak_export) {
312 /* If a duplicator shouldn't be exported, its duplilist also shouldn't be. */
313 continue;
314 }
315
316 /* Export the duplicated objects instanced by this object. */
317 object_duplilist(depsgraph_, object, nullptr, duplilist);
318 if (!duplilist.is_empty()) {
319 DupliParentFinder dupli_parent_finder;
320
321 for (const DupliObject &dupli_object : duplilist) {
322 if (!should_visit_dupli_object(&dupli_object, object)) {
323 continue;
324 }
325 dupli_parent_finder.insert(&dupli_object);
326 }
327
328 for (const DupliObject &dupli_object : duplilist) {
329 if (!should_visit_dupli_object(&dupli_object, object)) {
330 continue;
331 }
332 visit_dupli_object(&dupli_object, object, dupli_parent_finder);
333 }
334 }
335
336 duplilist.clear();
337 }
339}
340
341void AbstractHierarchyIterator::connect_loose_objects()
342{
343 /* Find those objects whose parent is not part of the export graph; these
344 * objects would be skipped when traversing the graph as a hierarchy.
345 * These objects will have to be re-attached to some parent object in order to
346 * fit into the hierarchy. */
347 ExportGraph loose_objects_graph = export_graph_;
348 for (const ExportChildren &children : export_graph_.values()) {
349 for (const HierarchyContext *child : children) {
350 /* An object that is marked as a child of another object is not considered 'loose'. */
351 ObjectIdentifier child_oid = ObjectIdentifier::for_hierarchy_context(child);
352 loose_objects_graph.remove(child_oid);
353 }
354 }
355 /* The root of the hierarchy is always found, so it's never considered 'loose'. */
357
358 /* Iterate over the loose objects and connect them to their export parent. */
359 for (const ObjectIdentifier &graph_key : loose_objects_graph.keys()) {
360 Object *object = graph_key.object;
361
362 while (true) {
363 /* Loose objects will all be real objects, as duplicated objects always have
364 * their duplicator or other exported duplicated object as ancestor. */
365
366 const bool found = export_graph_.contains(ObjectIdentifier::for_real_object(object->parent));
367 visit_object(object, object->parent, true);
368 if (found) {
369 break;
370 }
371 /* 'object->parent' will never be nullptr here, as the export graph contains the
372 * root as nullptr and thus will cause a break above. */
373 BLI_assert(object->parent != nullptr);
374
375 object = object->parent;
376 }
377 }
378}
379
380static bool remove_weak_subtrees(const HierarchyContext *context,
383{
384 bool all_is_weak = context != nullptr && context->weak_export;
386
387 const AbstractHierarchyIterator::ExportChildren *children = input_graph.lookup_ptr(map_key);
388 if (children) {
389 for (HierarchyContext *child_context : *children) {
390 bool child_tree_is_weak = remove_weak_subtrees(child_context, clean_graph, input_graph);
391 all_is_weak &= child_tree_is_weak;
392
393 if (child_tree_is_weak) {
394 /* This subtree is all weak, so we can remove it from the current object's children. */
395 clean_graph.lookup(map_key).remove(child_context);
396 delete child_context;
397 }
398 }
399 }
400
401 if (all_is_weak) {
402 /* This node and all its children are weak, so it can be removed from the export graph. */
403 clean_graph.remove(map_key);
404 }
405
406 return all_is_weak;
407}
408
409void AbstractHierarchyIterator::export_graph_prune()
410{
411 /* Take a copy of the map so that we can modify while recusing. */
412 ExportGraph unpruned_export_graph = export_graph_;
414}
415
416void AbstractHierarchyIterator::export_graph_clear()
417{
418 for (const ExportChildren &children : export_graph_.values()) {
419 for (HierarchyContext *context : children) {
420 delete context;
421 }
422 }
425}
426
427void AbstractHierarchyIterator::visit_object(Object *object,
428 Object *export_parent,
429 bool weak_export)
430{
431 HierarchyContext *context = new HierarchyContext();
432 context->object = object;
433 context->is_object_data_context = false;
434 context->export_name = get_object_name(object, export_parent);
435 context->export_parent = export_parent;
436 context->duplicator = nullptr;
437 context->weak_export = weak_export;
438 context->animation_check_include_parent = false;
439 context->export_path = "";
440 context->original_export_path = "";
441 context->higher_up_export_path = "";
442 context->is_duplisource = false;
443 context->matrix_world = object->object_to_world();
444
445 ObjectIdentifier graph_index = determine_graph_index_object(context);
446 context_update_for_graph_index(context, graph_index);
447
448 /* Store this HierarchyContext as child of the export parent. */
449 export_graph_.lookup_or_add(graph_index, {}).add_new(context);
450
451 /* Create an empty entry for this object to indicate it is part of the export. This will be used
452 * by connect_loose_objects(). Having such an "indicator" will make it possible to do an O(log n)
453 * check on whether an object is part of the export, rather than having to check all objects in
454 * the map. Note that it's not possible to simply search for (object->parent, nullptr), as the
455 * object's parent in Blender may not be the same as its export-parent. */
456 ObjectIdentifier object_key = ObjectIdentifier::for_real_object(object);
457 export_graph_.add(object_key, {});
458}
459
465
466void AbstractHierarchyIterator::visit_dupli_object(const DupliObject *dupli_object,
467 Object *duplicator,
468 const DupliParentFinder &dupli_parent_finder)
469{
470 HierarchyContext *context = new HierarchyContext();
471 context->object = dupli_object->ob;
472 context->is_object_data_context = false;
473 context->duplicator = duplicator;
474 context->persistent_id = PersistentID(dupli_object);
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);
481
482 /* Construct export name for the dupli-instance. */
483 std::string export_name = get_object_name(context->object) + "-" +
484 context->persistent_id.as_object_name_suffix();
485
486 Set<std::string> &used_names = used_names_.lookup_or_add(duplicator->id.name, {});
487 context->export_name = make_unique_name(make_valid_name(export_name), used_names);
488
490 context, dupli_object, dupli_parent_finder);
491 context_update_for_graph_index(context, graph_index);
492
493 export_graph_.lookup_or_add(graph_index, {}).add_new(context);
494
495 if (dupli_object->ob) {
496 this->duplisources_.add(&dupli_object->ob->id);
497 }
498}
499
501 const HierarchyContext *context,
502 const DupliObject *dupli_object,
503 const DupliParentFinder &dupli_parent_finder)
504{
505 const DupliObject *dupli_parent = dupli_parent_finder.find_suitable_export_parent(dupli_object);
506
507 if (dupli_parent != nullptr) {
508 return ObjectIdentifier::for_duplicated_object(dupli_parent, context->duplicator);
509 }
510 return ObjectIdentifier::for_real_object(context->duplicator);
511}
512
513void AbstractHierarchyIterator::context_update_for_graph_index(
514 HierarchyContext *context, const ObjectIdentifier &graph_index) const
515{
516 /* Update the HierarchyContext so that it is consistent with the graph index. */
517 context->export_parent = graph_index.object;
518
519 /* If the parent type is such that it cannot be exported (at least not currently to USD or
520 * Alembic), always check the parent for animation. */
521 const eObject_Partype partype = context->object->partype & PARTYPE;
522 context->animation_check_include_parent |= ELEM(partype, PARBONE, PARVERT1, PARVERT3, PARSKEL);
523
524 if (context->export_parent != context->object->parent) {
525 /* The parent object in Blender is NOT used as the export parent. This means
526 * that the world transform of this object can be influenced by objects that
527 * are not part of its export graph. */
528 context->animation_check_include_parent = true;
529 }
530}
531
533 const HierarchyContext *context)
534{
535 /* Note: `graph_children` is called during recursive iteration and MUST NOT change the export
536 * graph, which would invalidate the iteration. As a result, we cannot add an entry in the
537 * graph if the incoming `context` is not found. */
539}
540
541void AbstractHierarchyIterator::determine_export_paths(const HierarchyContext *parent_context)
542{
543 const std::string &parent_export_path = parent_context ? parent_context->export_path : "";
544
545 const ExportChildren *children = graph_children(parent_context);
546 if (!children) {
547 return;
548 }
549
550 for (HierarchyContext *context : *children) {
551 context->export_path = path_concatenate(parent_export_path, context->export_name);
552
553 if (context->duplicator == nullptr) {
554 /* This is an original (i.e. non-instanced) object, so we should keep track of where it was
555 * exported to, just in case it gets instanced somewhere. */
556 ID *source_ob = &context->object->id;
557 duplisource_export_path_.add(source_ob, context->export_path);
558
559 if (context->object->data != nullptr) {
560 ID *source_data = context->object->data;
562 }
563 }
564
565 determine_export_paths(context);
566 }
567}
568
569bool AbstractHierarchyIterator::determine_duplication_references(
570 const HierarchyContext *parent_context, const std::string &indent)
571{
572 const ExportChildren *children = graph_children(parent_context);
573 if (!children) {
574 return false;
575 }
576
577 /* Will be set to true if any child contexts are instances that were designated
578 * as proxies for the original prototype. */
579 bool contains_proxy_prototype = false;
580
581 for (HierarchyContext *context : *children) {
582 if (context->duplicator != nullptr) {
583 ID *source_id = &context->object->id;
584 const std::string *source_path = duplisource_export_path_.lookup_ptr(source_id);
585 if (!source_path) {
586 /* The original was not found, so mark this instance as "the original". */
587 context->mark_as_not_instanced();
588 duplisource_export_path_.add_new(source_id, context->export_path);
589 contains_proxy_prototype = true;
590 }
591 else {
592 context->mark_as_instance_of(*source_path);
593 }
594
595 if (context->object->data) {
596 ID *source_data_id = context->object->data;
597 if (!duplisource_export_path_.contains(source_data_id)) {
598 /* The original was not found, so mark this instance as "original". */
599 std::string data_path = get_object_data_path(context);
600 context->mark_as_not_instanced();
601 duplisource_export_path_.add_overwrite(source_id, context->export_path);
602 duplisource_export_path_.add_new(source_data_id, data_path);
603 }
604 }
605 }
606 else {
607 /* Determine is this context is for an instance prototype. */
608 ID *id = &context->object->id;
609 if (duplisources_.contains(id)) {
610 context->is_duplisource = true;
611 }
612 }
613
614 if (determine_duplication_references(context, indent + " ")) {
615 /* A descendant was designated a prototype proxy. If the current context
616 * is an instance, we must change it to a prototype proxy as well. */
617 if (context->is_instance()) {
618 context->mark_as_not_instanced();
619 ID *source_id = &context->object->id;
620 duplisource_export_path_.add_overwrite(source_id, context->export_path);
621 }
622 contains_proxy_prototype = true;
623 }
624 }
625 return contains_proxy_prototype;
626}
627
628void AbstractHierarchyIterator::make_writers(const HierarchyContext *parent_context)
629{
630 float4x4 parent_matrix_inv_world;
631
632 if (parent_context) {
633 parent_matrix_inv_world = math::invert(parent_context->matrix_world);
634 }
635 else {
636 parent_matrix_inv_world = float4x4::identity();
637 }
638
639 const ExportChildren *children = graph_children(parent_context);
640 if (!children) {
641 return;
642 }
643
644 bool has_point_instance_ancestor = false;
645 if (parent_context &&
646 (parent_context->is_point_instance || parent_context->has_point_instance_ancestor))
647 {
648 has_point_instance_ancestor = true;
649 }
650
651 for (HierarchyContext *context : *children) {
652 context->has_point_instance_ancestor = has_point_instance_ancestor;
653
654 /* Update the context so that it is correct for this parent-child relation. */
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;
658 }
659
660 /* Get or create the transform writer. */
661 EnsuredWriter transform_writer = ensure_writer(
663
664 if (!transform_writer) {
665 /* Unable to export, so there is nothing to attach any children to; just abort this entire
666 * branch of the export hierarchy. */
667 continue;
668 }
669
670 const bool need_writers = context->is_point_proto || (!context->is_point_instance &&
671 !context->has_point_instance_ancestor);
672
674 if ((transform_writer.is_newly_created() || export_subset_.transforms) && need_writers) {
675 /* XXX This can lead to too many XForms being written. For example, a camera writer can
676 * refuse to write an orthographic camera. By the time that this is known, the XForm has
677 * already been written. */
678 transform_writer->write(*context);
679 }
680
681 if (!context->weak_export && include_data_writers(context) && need_writers) {
682 make_writers_particle_systems(context);
683 make_writer_object_data(context);
684 }
685
686 if (include_child_writers(context)) {
687 /* Recurse into this object's children. */
688 make_writers(context);
689 }
690 }
691
692 /* TODO(Sybren): iterate over all unused writers and call unused_during_iteration() or something.
693 */
694}
695
696HierarchyContext AbstractHierarchyIterator::context_for_object_data(
697 const HierarchyContext *object_context) const
698{
699 HierarchyContext data_context = *object_context;
700 data_context.is_object_data_context = true;
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);
705
706 const ObjectIdentifier object_key = ObjectIdentifier::for_hierarchy_context(&data_context);
707 const ExportChildren *children = export_graph_.lookup_ptr(object_key);
708 data_context.is_parent = children ? (children->size() > 0) : false;
709
710 return data_context;
711}
712
713void AbstractHierarchyIterator::make_writer_object_data(const HierarchyContext *context)
714{
715 if (context->object->data == nullptr) {
716 return;
717 }
718
719 HierarchyContext data_context = context_for_object_data(context);
720 if (data_context.is_instance()) {
721 ID *object_data = context->object->data;
722 data_context.original_export_path = duplisource_export_path_.lookup(object_data);
723
724 /* If the object is marked as an instance, so should the object data. */
725 BLI_assert(data_context.is_instance());
726 }
727
728 /* Always write upon creation, otherwise depend on which subset is active. */
729 EnsuredWriter data_writer = ensure_writer(&data_context,
731 if (!data_writer) {
732 return;
733 }
734
735 if (data_writer.is_newly_created() || export_subset_.shapes) {
736 data_writer->write(data_context);
737 }
738}
739
740void AbstractHierarchyIterator::make_writers_particle_systems(
741 const HierarchyContext *transform_context)
742{
743 Object *object = transform_context->object;
744 ParticleSystem *psys = object->particlesystem.first();
745 for (; psys; psys = psys->next) {
746 if (!psys_check_enabled(object, psys, true)) {
747 continue;
748 }
749
750 HierarchyContext hair_context = *transform_context;
751 hair_context.export_name = make_valid_name(psys->name);
752 hair_context.export_path = path_concatenate(transform_context->export_path,
753 hair_context.export_name);
754 hair_context.higher_up_export_path = transform_context->export_path;
755 hair_context.particle_system = psys;
756
757 EnsuredWriter writer;
758 switch (psys->part->type) {
759 case PART_HAIR:
760 writer = ensure_writer(&hair_context, &AbstractHierarchyIterator::create_hair_writer);
761 break;
762 case PART_EMITTER:
763 case PART_FLUID_FLIP:
764 case PART_FLUID_SPRAY:
766 case PART_FLUID_FOAM:
772 writer = ensure_writer(&hair_context, &AbstractHierarchyIterator::create_particle_writer);
773 break;
774 default:
775 break;
776 }
777 if (!writer) {
778 continue;
779 }
780
781 /* Always write upon creation, otherwise depend on which subset is active. */
782 if (writer.is_newly_created() || export_subset_.shapes) {
783 writer->write(hair_context);
784 }
785 }
786}
787
788std::string AbstractHierarchyIterator::get_object_name(const Object *object) const
789{
790 return get_id_name(&object->id);
791}
792
793std::string AbstractHierarchyIterator::get_object_name(const Object *object, const Object *parent)
794{
795 Set<std::string> &used_names = used_names_.lookup_or_add(parent ? parent->id.name : "", {});
796 return make_unique_name(object->id.name + 2, used_names);
797}
798
799std::string AbstractHierarchyIterator::get_object_data_name(const Object *object) const
800{
801 const ID *object_data = object->data;
802 return get_id_name(object_data);
803}
804
806 const std::string &export_path) const
807{
808 return writers_.lookup_default(export_path, nullptr);
809}
810
811EnsuredWriter AbstractHierarchyIterator::ensure_writer(
812 const HierarchyContext *context, AbstractHierarchyIterator::create_writer_func create_func)
813{
814 AbstractHierarchyWriter *writer = get_writer(context->export_path);
815 if (writer != nullptr) {
816 return EnsuredWriter::existing(writer);
817 }
818
819 writer = (this->*create_func)(context);
820 if (writer == nullptr) {
821 return EnsuredWriter::empty();
822 }
823
824 writers_.add_new(context->export_path, writer);
825 return EnsuredWriter::newly_created(writer);
826}
827
828std::string AbstractHierarchyIterator::path_concatenate(const std::string &parent_path,
829 const std::string &child_path) const
830{
831 return parent_path + "/" + child_path;
832}
833
835{
836 return false;
837}
839 const Object *duplicator) const
840{
841 /* Do not visit dupli objects that the depsgraph iterator would hide for this evaluation mode
842 * (covers the `no_draw` flag, meta-ball instance data and originals hidden behind their duplis),
843 * so the exported instances match what Cycles and the Hydra delegate render. */
845 return false;
846 }
847
848 /* Meta-balls / text objects / NURBS surfaces generate a dupli that just re-exposes the
849 * duplicator's own evaluated mesh conversion, duplicating the object/data pairing that is
850 * already exported for the duplicator itself. Skip only that redundant case, i.e. when the
851 * dupli is the duplicator object re-instancing itself; a dupli of one of these object types
852 * generated by a genuine instance elsewhere (e.g. a collection instance or a Geometry Nodes
853 * "Instance on Points") is the only representation of that instance and must still be
854 * exported. */
855 if (ELEM(dupli_object->ob->type, OB_MBALL, OB_FONT, OB_SURF) && dupli_object->ob == duplicator) {
856 return false;
857 }
858
859 return true;
860}
861
862} // namespace blender::io
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(a)
#define ELEM(...)
#define BLI_assert_msg(a, msg)
void clear()
Definition BLI_map.hh:1038
const Value * lookup_ptr(const Key &key) const
Definition BLI_map.hh:508
bool add_overwrite(const Key &key, const Value &value)
Definition BLI_map.hh:325
ValueIterator values() const &
Definition BLI_map.hh:884
bool add(const Key &key, const Value &value)
Definition BLI_map.hh:295
const Value & lookup(const Key &key) const
Definition BLI_map.hh:545
Value lookup_default(const Key &key, const Value &default_value) const
Definition BLI_map.hh:570
void clear_and_keep_capacity()
Definition BLI_map.hh:1051
void remove_contained(const Key &key)
Definition BLI_map.hh:387
void add_new(const Key &key, const Value &value)
Definition BLI_map.hh:265
bool remove(const Key &key)
Definition BLI_map.hh:368
bool is_empty() const
Definition BLI_map.hh:986
bool contains(const Key &key) const
Definition BLI_map.hh:353
Value & lookup_or_add(const Key &key, const Value &value)
Definition BLI_map.hh:588
bool contains_as(const ForwardKey &key) const
Definition BLI_set.hh:314
bool contains(const Key &key) const
Definition BLI_set.hh:310
bool add(const Key &key)
Definition BLI_set.hh:248
void add_new(const Key &key)
Definition BLI_set.hh:233
Map< ObjectIdentifier, ExportChildren > ExportGraph
virtual ObjectIdentifier determine_graph_index_object(const HierarchyContext *context)
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)
virtual std::string get_id_name(const ID *id) const
virtual AbstractHierarchyWriter * create_particle_writer(const HierarchyContext *context)=0
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 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
virtual std::string make_valid_name(const std::string &name) const
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
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)
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)
Definition anim_data.cc:224
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)
Definition object.cc:2063
@ 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)
Definition particle.cc:739
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)
Definition key.cc:1311
@ OB_VISIBLE_SELF
const NodeType * type
Definition graph/node.h:179
ustring name
Definition graph/node.h:178
char name[258]
Definition DNA_ID.h:433
struct ModifierData * next
struct Collection * instance_collection
bool is_object_visible(enum eEvaluationMode evaluation_mode) const
static const HierarchyContext * root()
void mark_as_instance_of(const std::string &reference_export_path)