[Bf-blender-cvs] [2814740f5be] master: Geometry Nodes: 4 Field Inputs for Mesh Topology Data

Johnny Matthews noreply at git.blender.org
Mon Dec 6 18:59:09 CET 2021


Commit: 2814740f5be86fc389ba82ffbb3a40c43f47a9f5
Author: Johnny Matthews
Date:   Mon Dec 6 11:58:08 2021 -0600
Branches: master
https://developer.blender.org/rB2814740f5be86fc389ba82ffbb3a40c43f47a9f5

Geometry Nodes: 4 Field Inputs for Mesh Topology Data

Creates 4 new nodes which provide topology information
for the mesh. Values are interpolated from the primary
domain in each case using basic attribute interpolation.

Vertex Neighbors
  - Vertex Count
  - Face Count
Face Neighbors
  - Vertex Count
  - Neighboring Face Count
Edge Vertices
  - Vertex Index 1
  - Vertex Index 2
  - Position 1
  - Position 2
Face Area
  - Face Area

Differential Revision: https://developer.blender.org/D13343

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

M	release/scripts/startup/nodeitems_builtins.py
M	source/blender/blenkernel/BKE_node.h
M	source/blender/blenkernel/intern/node.cc
M	source/blender/nodes/NOD_geometry.h
M	source/blender/nodes/NOD_static_types.h
M	source/blender/nodes/geometry/CMakeLists.txt
A	source/blender/nodes/geometry/nodes/node_geo_input_mesh_edge_vertices.cc
A	source/blender/nodes/geometry/nodes/node_geo_input_mesh_face_area.cc
A	source/blender/nodes/geometry/nodes/node_geo_input_mesh_face_neighbors.cc
A	source/blender/nodes/geometry/nodes/node_geo_input_mesh_vertex_neighbors.cc

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

diff --git a/release/scripts/startup/nodeitems_builtins.py b/release/scripts/startup/nodeitems_builtins.py
index 4880a07115a..7a4210f0d0c 100644
--- a/release/scripts/startup/nodeitems_builtins.py
+++ b/release/scripts/startup/nodeitems_builtins.py
@@ -150,7 +150,11 @@ def mesh_node_items(context):
     yield NodeItem("GeometryNodeSubdivisionSurface")
     yield NodeItem("GeometryNodeTriangulate")
     yield NodeItemCustom(draw=lambda self, layout, context: layout.separator())
+    yield NodeItem("GeometryNodeInputMeshEdgeVertices")
+    yield NodeItem("GeometryNodeInputMeshFaceArea")
+    yield NodeItem("GeometryNodeInputMeshFaceNeighbors")
     yield NodeItem("GeometryNodeInputShadeSmooth")
+    yield NodeItem("GeometryNodeInputMeshVertexNeighbors")
     yield NodeItemCustom(draw=lambda self, layout, context: layout.separator())
     yield NodeItem("GeometryNodeSetShadeSmooth")
 
diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h
index fcfbe3ccc6f..f925834beac 100644
--- a/source/blender/blenkernel/BKE_node.h
+++ b/source/blender/blenkernel/BKE_node.h
@@ -1530,7 +1530,10 @@ int ntreeTexExecTree(struct bNodeTree *ntree,
 #define GEO_NODE_SET_ID 1135
 #define GEO_NODE_ATTRIBUTE_DOMAIN_SIZE 1136
 #define GEO_NODE_DUAL_MESH 1137
-
+#define GEO_NODE_INPUT_MESH_EDGE_VERTICES 1138
+#define GEO_NODE_INPUT_MESH_FACE_AREA 1139
+#define GEO_NODE_INPUT_MESH_FACE_NEIGHBORS 1140
+#define GEO_NODE_INPUT_MESH_VERTEX_NEIGHBORS 1141
 /** \} */
 
 /* -------------------------------------------------------------------- */
diff --git a/source/blender/blenkernel/intern/node.cc b/source/blender/blenkernel/intern/node.cc
index 359dbaab12b..6558ad894b8 100644
--- a/source/blender/blenkernel/intern/node.cc
+++ b/source/blender/blenkernel/intern/node.cc
@@ -5900,6 +5900,10 @@ static void registerGeometryNodes()
   register_node_type_geo_input_index();
   register_node_type_geo_input_material_index();
   register_node_type_geo_input_material();
+  register_node_type_geo_input_mesh_edge_vertices();
+  register_node_type_geo_input_mesh_face_area();
+  register_node_type_geo_input_mesh_face_neighbors();
+  register_node_type_geo_input_mesh_vertex_neighbors();
   register_node_type_geo_input_normal();
   register_node_type_geo_input_position();
   register_node_type_geo_input_radius();
diff --git a/source/blender/nodes/NOD_geometry.h b/source/blender/nodes/NOD_geometry.h
index a3d36788ee2..a64c53c32e1 100644
--- a/source/blender/nodes/NOD_geometry.h
+++ b/source/blender/nodes/NOD_geometry.h
@@ -104,6 +104,10 @@ void register_node_type_geo_input_id(void);
 void register_node_type_geo_input_index(void);
 void register_node_type_geo_input_material_index(void);
 void register_node_type_geo_input_material(void);
+void register_node_type_geo_input_mesh_edge_vertices(void);
+void register_node_type_geo_input_mesh_face_area(void);
+void register_node_type_geo_input_mesh_face_neighbors(void);
+void register_node_type_geo_input_mesh_vertex_neighbors(void);
 void register_node_type_geo_input_normal(void);
 void register_node_type_geo_input_position(void);
 void register_node_type_geo_input_radius(void);
diff --git a/source/blender/nodes/NOD_static_types.h b/source/blender/nodes/NOD_static_types.h
index 7df670c5397..5ef0fc52877 100644
--- a/source/blender/nodes/NOD_static_types.h
+++ b/source/blender/nodes/NOD_static_types.h
@@ -357,6 +357,10 @@ DefNode(GeometryNode, GEO_NODE_INPUT_ID, 0, "INPUT_ID", InputID, "ID", "")
 DefNode(GeometryNode, GEO_NODE_INPUT_INDEX, 0, "INDEX", InputIndex, "Index", "")
 DefNode(GeometryNode, GEO_NODE_INPUT_MATERIAL_INDEX, 0, "INPUT_MATERIAL_INDEX", InputMaterialIndex, "Material Index", "")
 DefNode(GeometryNode, GEO_NODE_INPUT_MATERIAL, def_geo_input_material, "INPUT_MATERIAL", InputMaterial, "Material", "")
+DefNode(GeometryNode, GEO_NODE_INPUT_MESH_EDGE_VERTICES, 0, "MESH_EDGE_VERTICES", InputMeshEdgeVertices, "Edge Vertices", "")
+DefNode(GeometryNode, GEO_NODE_INPUT_MESH_FACE_AREA, 0, "MESH_FACE_AREA", InputMeshFaceArea, "Face Area", "")
+DefNode(GeometryNode, GEO_NODE_INPUT_MESH_FACE_NEIGHBORS, 0, "MESH_FACE_NEIGHBORS", InputMeshFaceNeighbors, "Face Neighbors", "")
+DefNode(GeometryNode, GEO_NODE_INPUT_MESH_VERTEX_NEIGHBORS, 0, "MESH_VERTEX_NEIGHBORS", InputMeshVertexNeighbors, "Vertex Neighbors", "")
 DefNode(GeometryNode, GEO_NODE_INPUT_NORMAL, 0, "INPUT_NORMAL", InputNormal, "Normal", "")
 DefNode(GeometryNode, GEO_NODE_INPUT_POSITION, 0, "POSITION", InputPosition, "Position", "")
 DefNode(GeometryNode, GEO_NODE_INPUT_RADIUS, 0, "INPUT_RADIUS", InputRadius, "Radius", "")
diff --git a/source/blender/nodes/geometry/CMakeLists.txt b/source/blender/nodes/geometry/CMakeLists.txt
index 4a34e1bd6d0..2d7e0293b62 100644
--- a/source/blender/nodes/geometry/CMakeLists.txt
+++ b/source/blender/nodes/geometry/CMakeLists.txt
@@ -122,6 +122,10 @@ set(SRC
   nodes/node_geo_input_index.cc
   nodes/node_geo_input_material_index.cc
   nodes/node_geo_input_material.cc
+  nodes/node_geo_input_mesh_edge_vertices.cc
+  nodes/node_geo_input_mesh_face_area.cc
+  nodes/node_geo_input_mesh_face_neighbors.cc
+  nodes/node_geo_input_mesh_vertex_neighbors.cc
   nodes/node_geo_input_normal.cc
   nodes/node_geo_input_position.cc
   nodes/node_geo_input_radius.cc
diff --git a/source/blender/nodes/geometry/nodes/node_geo_input_mesh_edge_vertices.cc b/source/blender/nodes/geometry/nodes/node_geo_input_mesh_edge_vertices.cc
new file mode 100644
index 00000000000..a9385b50600
--- /dev/null
+++ b/source/blender/nodes/geometry/nodes/node_geo_input_mesh_edge_vertices.cc
@@ -0,0 +1,198 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include "DNA_mesh_types.h"
+#include "DNA_meshdata_types.h"
+
+#include "BKE_mesh.h"
+
+#include "node_geometry_util.hh"
+
+namespace blender::nodes::node_geo_input_mesh_edge_vertices_cc {
+
+static void node_declare(NodeDeclarationBuilder &b)
+{
+  b.add_output<decl::Int>(N_("Vertex Index 1"))
+      .field_source()
+      .description(N_("The index of the first vertex in the edge"));
+  b.add_output<decl::Int>(N_("Vertex Index 2"))
+      .field_source()
+      .description(N_("The index of the second vertex in the edge"));
+  b.add_output<decl::Vector>(N_("Position 1"))
+      .field_source()
+      .description(N_("The position of the first vertex in the edge"));
+  b.add_output<decl::Vector>(N_("Position 2"))
+      .field_source()
+      .description(N_("The position of the second vertex in the edge"));
+}
+
+enum VertexNumber { VERTEX_ONE, VERTEX_TWO };
+
+static VArray<int> construct_edge_vertices_gvarray(const MeshComponent &component,
+                                                   const VertexNumber vertex,
+                                                   const AttributeDomain domain)
+{
+  const Mesh *mesh = component.get_for_read();
+  if (mesh == nullptr) {
+    return {};
+  }
+  if (domain == ATTR_DOMAIN_EDGE) {
+
+    if (vertex == VERTEX_ONE) {
+      return VArray<int>::ForFunc(mesh->totpoly,
+                                  [mesh](const int i) -> int { return mesh->medge[i].v1; });
+    }
+    return VArray<int>::ForFunc(mesh->totpoly,
+                                [mesh](const int i) -> int { return mesh->medge[i].v2; });
+  }
+  return {};
+}
+
+class EdgeVerticesFieldInput final : public fn::FieldInput {
+ private:
+  VertexNumber vertex_;
+
+ public:
+  EdgeVerticesFieldInput(VertexNumber vertex)
+      : fn::FieldInput(CPPType::get<int>(), "Edge Vertices Field"), vertex_(vertex)
+  {
+    category_ = Category::Generated;
+  }
+
+  GVArray get_varray_for_context(const fn::FieldContext &context,
+                                 IndexMask UNUSED(mask),
+                                 ResourceScope &UNUSED(scope)) const final
+  {
+    if (const GeometryComponentFieldContext *geometry_context =
+            dynamic_cast<const GeometryComponentFieldContext *>(&context)) {
+      const GeometryComponent &component = geometry_context->geometry_component();
+      const AttributeDomain domain = geometry_context->domain();
+      if (component.type() == GEO_COMPONENT_TYPE_MESH) {
+        const MeshComponent &mesh_component = static_cast<const MeshComponent &>(component);
+        return construct_edge_vertices_gvarray(mesh_component, vertex_, domain);
+      }
+    }
+    return {};
+  }
+
+  uint64_t hash() const override
+  {
+    return get_default_hash_2(vertex_, 9872922352);
+  }
+
+  bool is_equal_to(const fn::FieldNode &other) const override
+  {
+    if (const EdgeVerticesFieldInput *other_field = dynamic_cast<const EdgeVerticesFieldInput *>(
+            &other)) {
+      return vertex_ == other_field->vertex_;
+    }
+    return false;
+  }
+};
+
+static VArray<float3> construct_edge_positions_gvarray(const MeshComponent &component,
+                                                       const VertexNumber vertex,
+                                                       const AttributeDomain domain)
+{
+  const Mesh *mesh = component.get_for_read();
+  if (mesh == nullptr) {
+    return {};
+  }
+
+  if (vertex == VERTEX_ONE) {
+    return component.attribute_try_adapt_domain<float3>(
+        VArray<float3>::ForFunc(
+            mesh->totedge,
+            [mesh](const int i) { return float3(mesh->mvert[mesh->medge[i].v1].co); }),
+        ATTR_DOMAIN_EDGE,
+        domain);
+  }
+  return component.attribute_try_adapt_domain<float3>(
+      VArray<float3>::ForFunc(
+          mesh->totedge,
+          [mesh](const int i) { return float3(mesh->mvert[mesh->medge[i].v2].co); }),
+      ATTR_DOMAI

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list