[Bf-blender-cvs] [57fe65b17e4] master: Cleanup: Reduce indentation
Hans Goudey
noreply at git.blender.org
Mon Dec 28 04:27:01 CET 2020
Commit: 57fe65b17e407003f44f5b82c778a9a4c08bba19
Author: Hans Goudey
Date: Sun Dec 27 21:26:53 2020 -0600
Branches: master
https://developer.blender.org/rB57fe65b17e407003f44f5b82c778a9a4c08bba19
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.
===================================================================
M source/blender/nodes/geometry/nodes/node_geo_point_instance.cc
===================================================================
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];
}
}
}
More information about the Bf-blender-cvs
mailing list