[Bf-blender-cvs] [881e148cc5d] geometry-nodes: Geometry Nodes: maintain some more data in the Join node

Jacques Lucke noreply at git.blender.org
Thu Nov 26 15:34:25 CET 2020


Commit: 881e148cc5dea4ceb7b4da4251713100fa5e4b71
Author: Jacques Lucke
Date:   Thu Nov 26 15:33:59 2020 +0100
Branches: geometry-nodes
https://developer.blender.org/rB881e148cc5dea4ceb7b4da4251713100fa5e4b71

Geometry Nodes: maintain some more data in the Join node

Material indices and smooth states are not destroyed anymore.
If the two incoming meshes use different materials, the materials of
the first input will be used. This is obviously not ideal, because the
second input might change its material.

In the future we want to handle that differently and keep both materials,
but for now this is consistent with the boolean node.

===================================================================

M	source/blender/nodes/geometry/nodes/node_geo_join_geometry.cc

===================================================================

diff --git a/source/blender/nodes/geometry/nodes/node_geo_join_geometry.cc b/source/blender/nodes/geometry/nodes/node_geo_join_geometry.cc
index 1dd448004c0..9ce39403bf0 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_join_geometry.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_join_geometry.cc
@@ -36,7 +36,7 @@ static bNodeSocketTemplate geo_node_join_geometry_out[] = {
 
 namespace blender::nodes {
 
-static Mesh *join_mesh_topologies(Span<const MeshComponent *> src_components)
+static Mesh *join_mesh_topology_and_builtin_attributes(Span<const MeshComponent *> src_components)
 {
   int totverts = 0;
   int totloops = 0;
@@ -45,17 +45,15 @@ static Mesh *join_mesh_topologies(Span<const MeshComponent *> src_components)
 
   for (const MeshComponent *mesh_component : src_components) {
     const Mesh *mesh = mesh_component->get_for_read();
-    if (mesh == nullptr) {
-      continue;
-    }
-
     totverts += mesh->totvert;
     totloops += mesh->totloop;
     totedges += mesh->totedge;
     totpolys += mesh->totpoly;
   }
 
+  const Mesh *first_input_mesh = src_components[0]->get_for_read();
   Mesh *new_mesh = BKE_mesh_new_nomain(totverts, totedges, 0, totloops, totpolys);
+  BKE_mesh_copy_settings(new_mesh, first_input_mesh);
 
   int vert_offset = 0;
   int loop_offset = 0;
@@ -67,23 +65,31 @@ static Mesh *join_mesh_topologies(Span<const MeshComponent *> src_components)
       continue;
     }
 
+    for (const int i : IndexRange(mesh->totvert)) {
+      const MVert &old_vert = mesh->mvert[i];
+      MVert &new_vert = new_mesh->mvert[vert_offset + i];
+      new_vert = old_vert;
+    }
+
     for (const int i : IndexRange(mesh->totedge)) {
       const MEdge &old_edge = mesh->medge[i];
       MEdge &new_edge = new_mesh->medge[edge_offset + i];
-      new_edge.v1 = old_edge.v1 + vert_offset;
-      new_edge.v2 = old_edge.v2 + vert_offset;
+      new_edge = old_edge;
+      new_edge.v1 += vert_offset;
+      new_edge.v2 += vert_offset;
     }
     for (const int i : IndexRange(mesh->totloop)) {
       const MLoop &old_loop = mesh->mloop[i];
       MLoop &new_loop = new_mesh->mloop[loop_offset + i];
-      new_loop.v = old_loop.v + vert_offset;
-      new_loop.e = old_loop.e + edge_offset;
+      new_loop = old_loop;
+      new_loop.v += vert_offset;
+      new_loop.e += edge_offset;
     }
     for (const int i : IndexRange(mesh->totpoly)) {
       const MPoly &old_poly = mesh->mpoly[i];
       MPoly &new_poly = new_mesh->mpoly[poly_offset + i];
-      new_poly.loopstart = old_poly.loopstart + loop_offset;
-      new_poly.totloop = old_poly.totloop;
+      new_poly = old_poly;
+      new_poly.loopstart += loop_offset;
     }
 
     vert_offset += mesh->totvert;
@@ -159,9 +165,13 @@ static void fill_new_attribute(Span<const GeometryComponent *> src_components,
 }
 
 static void join_attributes(Span<const GeometryComponent *> src_components,
-                            GeometryComponent &result)
+                            GeometryComponent &result,
+                            Span<StringRef> ignored_attributes = {})
 {
   Set<std::string> attribute_names = find_all_attribute_names(src_components);
+  for (StringRef name : ignored_attributes) {
+    attribute_names.remove(name);
+  }
 
   for (const std::string &attribute_name : attribute_names) {
     CustomDataType data_type;
@@ -181,12 +191,13 @@ static void join_attributes(Span<const GeometryComponent *> src_components,
 
 static void join_components(Span<const MeshComponent *> src_components, GeometrySet &result)
 {
-  Mesh *new_mesh = join_mesh_topologies(src_components);
+  Mesh *new_mesh = join_mesh_topology_and_builtin_attributes(src_components);
 
   MeshComponent &dst_component = result.get_component_for_write<MeshComponent>();
   dst_component.replace(new_mesh);
 
-  join_attributes(to_base_components(src_components), dst_component);
+  /* The position attribute is handled above already. */
+  join_attributes(to_base_components(src_components), dst_component, {"position"});
 }
 
 static void join_components(Span<const PointCloudComponent *> src_components, GeometrySet &result)



More information about the Bf-blender-cvs mailing list