diff options
author | Hans Goudey <h.goudey@me.com> | 2020-12-28 06:26:53 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2020-12-28 06:26:53 +0300 |
commit | 57fe65b17e407003f44f5b82c778a9a4c08bba19 (patch) | |
tree | 1d20e92c3cb2e4aac3c5cfbeeb5de4d80c85011e | |
parent | aa64fd69e733e49317101ea60299f2179830ae95 (diff) |
Cleanup: Reduce indentation
Since the if statement is just a NULL check, returning early is simpler
and makes reading the rest of the funtion easier.
-rw-r--r-- | source/blender/nodes/geometry/nodes/node_geo_point_instance.cc | 62 |
1 files changed, 32 insertions, 30 deletions
diff --git a/source/blender/nodes/geometry/nodes/node_geo_point_instance.cc b/source/blender/nodes/geometry/nodes/node_geo_point_instance.cc index 4274ded2024..0a07af37115 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_point_instance.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_point_instance.cc @@ -82,40 +82,42 @@ static void get_instanced_data__collection( bke::PersistentCollectionHandle collection_handle = params.get_input<bke::PersistentCollectionHandle>("Collection"); Collection *collection = params.handle_map().lookup(collection_handle); - if (collection != nullptr) { - const bool use_whole_collection = node.custom2 == 0; - if (use_whole_collection) { + if (collection == nullptr) { + return; + } + + const bool use_whole_collection = node.custom2 == 0; + if (use_whole_collection) { + InstancedData instance; + instance.type = INSTANCE_DATA_TYPE_COLLECTION; + instance.data.collection = collection; + r_instances_data.fill(instance); + } + else { + Vector<InstancedData> possible_instances; + /* Direct child objects are instanced as objects. */ + LISTBASE_FOREACH (CollectionObject *, cob, &collection->gobject) { + Object *object = cob->ob; + InstancedData instance; + instance.type = INSTANCE_DATA_TYPE_OBJECT; + instance.data.object = object; + possible_instances.append(instance); + } + /* Direct child collections are instanced as collections. */ + LISTBASE_FOREACH (CollectionChild *, child, &collection->children) { + Collection *child_collection = child->collection; InstancedData instance; instance.type = INSTANCE_DATA_TYPE_COLLECTION; - instance.data.collection = collection; - r_instances_data.fill(instance); + instance.data.collection = child_collection; + possible_instances.append(instance); } - else { - Vector<InstancedData> possible_instances; - /* Direct child objects are instanced as objects. */ - LISTBASE_FOREACH (CollectionObject *, cob, &collection->gobject) { - Object *object = cob->ob; - InstancedData instance; - instance.type = INSTANCE_DATA_TYPE_OBJECT; - instance.data.object = object; - possible_instances.append(instance); - } - /* Direct child collections are instanced as collections. */ - LISTBASE_FOREACH (CollectionChild *, child, &collection->children) { - Collection *child_collection = child->collection; - InstancedData instance; - instance.type = INSTANCE_DATA_TYPE_COLLECTION; - instance.data.collection = child_collection; - possible_instances.append(instance); - } - if (!possible_instances.is_empty()) { - const int seed = params.get_input<int>("Seed"); - Array<uint32_t> ids = get_geometry_element_ids_as_uints(component, ATTR_DOMAIN_POINT); - for (const int i : r_instances_data.index_range()) { - const int index = BLI_hash_int_2d(ids[i], seed) % possible_instances.size(); - r_instances_data[i] = possible_instances[index]; - } + if (!possible_instances.is_empty()) { + const int seed = params.get_input<int>("Seed"); + Array<uint32_t> ids = get_geometry_element_ids_as_uints(component, ATTR_DOMAIN_POINT); + for (const int i : r_instances_data.index_range()) { + const int index = BLI_hash_int_2d(ids[i], seed) % possible_instances.size(); + r_instances_data[i] = possible_instances[index]; } } } |