Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohnny Matthews <johnny.matthews@gmail.com>2021-10-18 23:11:04 +0300
committerJohnny Matthews <johnny.matthews@gmail.com>2021-10-18 23:11:04 +0300
commit5f59bf00444bf310d0ad0dd20039839912af5122 (patch)
tree215419309bde918c69b94ba86c4a58d048a904c4 /source/blender/nodes
parentec8a9a0d6586d01b144ce4168e0f57d29ef7f738 (diff)
Geometry Nodes: Sort Children in Collection Info
When the 'Separate Children' option is selected, the children of the selected collection are inserted into the geometry output sorted alphabetically by name. One item to note is that the rename function does not trigger a depsgraph update. This means that the changes are not reflected in the spreadsheet until another action triggers the update. Differential Revision: https://developer.blender.org/D12907
Diffstat (limited to 'source/blender/nodes')
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_collection_info.cc26
1 files changed, 23 insertions, 3 deletions
diff --git a/source/blender/nodes/geometry/nodes/node_geo_collection_info.cc b/source/blender/nodes/geometry/nodes/node_geo_collection_info.cc
index d03221703f0..eca4e3d2d14 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_collection_info.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_collection_info.cc
@@ -25,13 +25,16 @@
#include "node_geometry_util.hh"
+#include <algorithm>
+
namespace blender::nodes {
static void geo_node_collection_info_declare(NodeDeclarationBuilder &b)
{
b.add_input<decl::Collection>("Collection").hide_label();
b.add_input<decl::Bool>("Separate Children")
- .description("Output each child of the collection as a separate instance");
+ .description(
+ "Output each child of the collection as a separate instance, sorted alphabetically");
b.add_input<decl::Bool>("Reset Children")
.description(
"Reset the transforms of every child instance in the output. Only used when Separate "
@@ -52,6 +55,12 @@ static void geo_node_collection_info_node_init(bNodeTree *UNUSED(tree), bNode *n
node->storage = data;
}
+struct InstanceListEntry {
+ int handle;
+ char *name;
+ float4x4 transform;
+};
+
static void geo_node_collection_info_exec(GeoNodeExecParams params)
{
Collection *collection = params.get_input<Collection *>("Collection");
@@ -85,6 +94,8 @@ static void geo_node_collection_info_exec(GeoNodeExecParams params)
}
instances.reserve(children_collections.size() + children_objects.size());
+ Vector<InstanceListEntry> entries;
+ entries.reserve(children_collections.size() + children_objects.size());
for (Collection *child_collection : children_collections) {
float4x4 transform = float4x4::identity();
@@ -98,7 +109,7 @@ static void geo_node_collection_info_exec(GeoNodeExecParams params)
}
}
const int handle = instances.add_reference(*child_collection);
- instances.add_instance(handle, transform);
+ entries.append({handle, &(child_collection->id.name[2]), transform});
}
for (Object *child_object : children_objects) {
const int handle = instances.add_reference(*child_object);
@@ -112,7 +123,16 @@ static void geo_node_collection_info_exec(GeoNodeExecParams params)
}
mul_m4_m4_post(transform.values, child_object->obmat);
}
- instances.add_instance(handle, transform);
+ entries.append({handle, &(child_object->id.name[2]), transform});
+ }
+
+ std::sort(entries.begin(),
+ entries.end(),
+ [](const InstanceListEntry &a, const InstanceListEntry &b) {
+ return BLI_strcasecmp_natural(a.name, b.name) <= 0;
+ });
+ for (const InstanceListEntry &entry : entries) {
+ instances.add_instance(entry.handle, entry.transform);
}
}
else {