[Bf-blender-cvs] [6f525e0d986] temp-geometry-nodes-fields-prototype: Upgrade extrude node with field inputs and selection outputs

Hans Goudey noreply at git.blender.org
Fri Aug 6 22:30:25 CEST 2021


Commit: 6f525e0d9866248bb84487536f767c4478228c2a
Author: Hans Goudey
Date:   Fri Aug 6 14:55:32 2021 -0500
Branches: temp-geometry-nodes-fields-prototype
https://developer.blender.org/rB6f525e0d9866248bb84487536f767c4478228c2a

Upgrade extrude node with field inputs and selection outputs

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

M	source/blender/bmesh/intern/bmesh_mesh.c
M	source/blender/bmesh/intern/bmesh_mesh.h
M	source/blender/bmesh/intern/bmesh_opdefines.c
M	source/blender/bmesh/operators/bmo_inset.c
M	source/blender/nodes/geometry/nodes/node_geo_extrude.cc

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

diff --git a/source/blender/bmesh/intern/bmesh_mesh.c b/source/blender/bmesh/intern/bmesh_mesh.c
index ad8158e2e6f..0b32f71af69 100644
--- a/source/blender/bmesh/intern/bmesh_mesh.c
+++ b/source/blender/bmesh/intern/bmesh_mesh.c
@@ -1447,8 +1447,8 @@ void BM_mesh_vert_coords_apply_with_mat4(BMesh *bm,
 }
 
 /**
-* Use to select  bmesh vertex data based on an array of bool.
-*/
+ * Use to select  bmesh vertex data based on an array of bool.
+ */
 void BM_select_vertices(BMesh *bm, const bool *mask)
 {
   BMIter iter;
@@ -1556,4 +1556,37 @@ void BM_tag_faces(BMesh *bm, const bool *mask)
     i++;
   }
 }
+
+void BM_get_tagged_faces(BMesh *bm, bool *selection)
+{
+  BMIter iter;
+  BMFace *f;
+  int i = 0;
+  BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) {
+    selection[i] = BM_elem_flag_test(f, BM_ELEM_TAG);
+    i++;
+  }
+}
+
+void BM_tag_new_faces(BMesh *bm, BMOperator *b_mesh_operator)
+{
+  BMOIter iter;
+  BMFace *f;
+  BM_mesh_elem_hflag_disable_all(bm, BM_FACE, BM_ELEM_TAG, false);
+  BMO_ITER (f, &iter, b_mesh_operator->slots_out, "faces.out", BM_FACE) {
+    BM_elem_flag_enable(f, BM_ELEM_TAG);
+  }
+}
+
+void BM_get_selected_faces(BMesh *bm, bool *selection)
+{
+  BMIter iter;
+  BMFace *f;
+  int i = 0;
+  BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) {
+    selection[i] = BM_elem_flag_test(f, BM_ELEM_SELECT);
+    i++;
+  }
+}
+
 /** \} */
diff --git a/source/blender/bmesh/intern/bmesh_mesh.h b/source/blender/bmesh/intern/bmesh_mesh.h
index eb7dcaac046..475372f4089 100644
--- a/source/blender/bmesh/intern/bmesh_mesh.h
+++ b/source/blender/bmesh/intern/bmesh_mesh.h
@@ -140,4 +140,8 @@ void BM_select_edges(BMesh *bm, const bool *mask);
 void BM_select_faces(BMesh *bm, const bool *mask);
 void BM_tag_vertices(BMesh *bm, const bool *mask);
 void BM_tag_edges(BMesh *bm, const bool *mask);
-void BM_tag_faces(BMesh *bm, const bool *mask);
\ No newline at end of file
+void BM_tag_faces(BMesh *bm, const bool *mask);
+
+void BM_get_tagged_faces(BMesh *bm, bool *selection);
+void BM_get_selected_faces(BMesh *bm, bool *selection);
+void BM_tag_new_faces(BMesh *bm, BMOperator *b_mesh_operator);
\ No newline at end of file
diff --git a/source/blender/bmesh/intern/bmesh_opdefines.c b/source/blender/bmesh/intern/bmesh_opdefines.c
index b63a09a97a6..fc3f592cb79 100644
--- a/source/blender/bmesh/intern/bmesh_opdefines.c
+++ b/source/blender/bmesh/intern/bmesh_opdefines.c
@@ -1898,6 +1898,9 @@ static BMOpDefine bmo_inset_individual_def = {
   {{"faces", BMO_OP_SLOT_ELEMENT_BUF, {BM_FACE}},    /* input faces */
    {"thickness", BMO_OP_SLOT_FLT}, /* thickness */
    {"depth", BMO_OP_SLOT_FLT}, /* depth */
+   {"thickness_array", BMO_OP_SLOT_PTR}, /* thickness */
+   {"depth_array", BMO_OP_SLOT_PTR}, /* depth */
+   {"use_attributes", BMO_OP_SLOT_BOOL}, /* Use spans for thickness and depth */
    {"use_even_offset", BMO_OP_SLOT_BOOL}, /* scale the offset to give more even thickness */
    {"use_interpolate", BMO_OP_SLOT_BOOL}, /* blend face data across the inset */
    {"use_relative_offset", BMO_OP_SLOT_BOOL}, /* scale the offset by surrounding geometry */
@@ -1929,6 +1932,9 @@ static BMOpDefine bmo_inset_region_def = {
    {"use_edge_rail", BMO_OP_SLOT_BOOL}, /* inset the region along existing edges */
    {"thickness", BMO_OP_SLOT_FLT}, /* thickness */
    {"depth", BMO_OP_SLOT_FLT}, /* depth */
+   {"thickness_array", BMO_OP_SLOT_PTR}, /* thickness */
+   {"depth_array", BMO_OP_SLOT_PTR}, /* depth */
+   {"use_attributes", BMO_OP_SLOT_BOOL}, /* Use spans for thickness and depth */
    {"use_outset", BMO_OP_SLOT_BOOL}, /* outset rather than inset */
    {{'\0'}},
   },
@@ -1940,7 +1946,6 @@ static BMOpDefine bmo_inset_region_def = {
   (BMO_OPTYPE_FLAG_NORMALS_CALC |
    BMO_OPTYPE_FLAG_SELECT_FLUSH),
 };
-
 /*
  * Edge-loop Offset.
  *
diff --git a/source/blender/bmesh/operators/bmo_inset.c b/source/blender/bmesh/operators/bmo_inset.c
index 4833290aa0b..1e30f1b72b3 100644
--- a/source/blender/bmesh/operators/bmo_inset.c
+++ b/source/blender/bmesh/operators/bmo_inset.c
@@ -419,6 +419,9 @@ void bmo_inset_individual_exec(BMesh *bm, BMOperator *op)
   BMOIter oiter;
   MemArena *interp_arena = NULL;
 
+  const bool use_attributes = BMO_slot_bool_get(op->slots_in, "use_attributes");
+  const float *thickness_array = BMO_slot_ptr_get(op->slots_in, "thickness_array");
+  const float *depth_array = BMO_slot_ptr_get(op->slots_in, "depth_array");
   const float thickness = BMO_slot_float_get(op->slots_in, "thickness");
   const float depth = BMO_slot_float_get(op->slots_in, "depth");
   const bool use_even_offset = BMO_slot_bool_get(op->slots_in, "use_even_offset");
@@ -433,19 +436,37 @@ void bmo_inset_individual_exec(BMesh *bm, BMOperator *op)
   if (use_interpolate) {
     interp_arena = BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, __func__);
   }
+  int i = 0;
+  if (use_attributes) {
+    BMO_ITER_INDEX (f, &oiter, op->slots_in, "faces", BM_FACE, i) {
+      bmo_face_inset_individual(bm,
+                                f,
+                                interp_arena,
+                                thickness_array[i],
+                                depth_array[i],
+                                use_even_offset,
+                                use_relative_offset,
+                                use_interpolate);
 
-  BMO_ITER (f, &oiter, op->slots_in, "faces", BM_FACE) {
-    bmo_face_inset_individual(bm,
-                              f,
-                              interp_arena,
-                              thickness,
-                              depth,
-                              use_even_offset,
-                              use_relative_offset,
-                              use_interpolate);
+      if (use_interpolate) {
+        BLI_memarena_clear(interp_arena);
+      }
+    }
+  }
+  else {
+    BMO_ITER (f, &oiter, op->slots_in, "faces", BM_FACE) {
+      bmo_face_inset_individual(bm,
+                                f,
+                                interp_arena,
+                                thickness,
+                                depth,
+                                use_even_offset,
+                                use_relative_offset,
+                                use_interpolate);
 
-    if (use_interpolate) {
-      BLI_memarena_clear(interp_arena);
+      if (use_interpolate) {
+        BLI_memarena_clear(interp_arena);
+      }
     }
   }
 
@@ -683,6 +704,9 @@ void bmo_inset_region_exec(BMesh *bm, BMOperator *op)
   const bool use_edge_rail = BMO_slot_bool_get(op->slots_in, "use_edge_rail");
   const bool use_interpolate = BMO_slot_bool_get(op->slots_in, "use_interpolate");
   const float thickness = BMO_slot_float_get(op->slots_in, "thickness");
+  const bool use_attributes = BMO_slot_bool_get(op->slots_in, "use_attributes");
+  const float *thickness_array = BMO_slot_ptr_get(op->slots_in, "thickness_array");
+  const float *depth_array = BMO_slot_ptr_get(op->slots_in, "depth_array");
   const float depth = BMO_slot_float_get(op->slots_in, "depth");
 #ifdef USE_LOOP_CUSTOMDATA_MERGE
   const bool has_math_ldata = (use_interpolate && CustomData_has_math(&bm->ldata));
@@ -1096,7 +1120,12 @@ void bmo_inset_region_exec(BMesh *bm, BMOperator *op)
             }
 
             /* apply the offset */
-            madd_v3_v3fl(v_split->co, tvec, thickness);
+            if (use_attributes) {
+              madd_v3_v3fl(v_split->co, tvec, thickness_array[v_split->head.index]);
+            }
+            else {
+              madd_v3_v3fl(v_split->co, tvec, thickness);
+            }
           }
 
           /* this saves expensive/slow glue check for common cases */
diff --git a/source/blender/nodes/geometry/nodes/node_geo_extrude.cc b/source/blender/nodes/geometry/nodes/node_geo_extrude.cc
index a938c705484..0679195c83e 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_extrude.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_extrude.cc
@@ -17,9 +17,11 @@
 #include "DNA_mesh_types.h"
 #include "DNA_meshdata_types.h"
 
-#include "UI_interface.h"
-
 #include "BKE_mesh.h"
+#include "BKE_node.h"
+
+#include "UI_interface.h"
+#include "UI_resources.h"
 
 #include "bmesh.h"
 #include "bmesh_tools.h"
@@ -37,18 +39,21 @@ static bNodeSocketTemplate geo_node_extrude_in[] = {
 
 static bNodeSocketTemplate geo_node_extrude_out[] = {
     {SOCK_GEOMETRY, N_("Geometry")},
+    {SOCK_BOOLEAN, N_("Top Faces")},
+    {SOCK_BOOLEAN, N_("Side Faces")},
     {-1, ""},
 };
 
-using blender::Span;
+namespace blender::nodes {
 
 static Mesh *extrude_mesh(const Mesh *mesh,
                           const Span<bool> selection,
-                          const float distance,
-                          const float inset,
-                          const bool inset_individual_faces)
+                          const Span<float> distance,
+                          const Span<float> inset,
+                          const bool inset_individual_faces,
+                          AnonymousCustomDataLayerID *top_faces_id,
+                          AnonymousCustomDataLayerID *side_faces_id)
 {
-  BLI_assert(selection.size() == mesh->totpoly);
   const BMeshCreateParams bmesh_create_params = {true};
   const BMeshFromMeshParams bmesh_from_mesh_params = {
       true, 0, 0, 0, {CD_MASK_ORIGINDEX, CD_MASK_ORIGINDEX, CD_MASK_ORIGINDEX}};
@@ -61,61 +66,129 @@ static Mesh *extrude_mesh(const Mesh *mesh,
     BMO_op_initf(bm,
                  &op,
                  0,
-                 "inset_individual faces=%hf use_even_offset=%b thickness=%f depth=%f",
+                 "inset_individual faces=%hf use_even_offset=%b thickness=%f depth=%f "
+                 "thickness_array=%p depth_array=%p use_attributes=%b",
                  BM_ELEM_SELECT,
                  true,
-                 inset,
-                 distance);
+                 inset.first(),
+                 distance.first(),
+                 inset.data(),
+                 distance.data(),
+                 true);
   }
   else {
     BMO_op_initf(bm,
                  &op,
                  0,
-                 "inset_region faces=%hf use_boundary=%b use_even_offset=%b thickness=%f depth=%f",
+                 "inset_region faces=%hf use_boundary=%b use_even_offset=%b

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list