[Bf-blender-cvs] [6bc6b49ddb6] extrude_boolean: Edit Mesh: New Extrude Boolean (WIP)

Germano Cavalcante noreply at git.blender.org
Tue Sep 7 03:40:31 CEST 2021


Commit: 6bc6b49ddb6130405f92f0fbd93758748851e143
Author: Germano Cavalcante
Date:   Fri Sep 3 22:31:08 2021 -0300
Branches: extrude_boolean
https://developer.blender.org/rB6bc6b49ddb6130405f92f0fbd93758748851e143

Edit Mesh: New Extrude Boolean (WIP)

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

M	release/scripts/presets/keyconfig/keymap_data/blender_default.py
M	release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
M	source/blender/editors/mesh/CMakeLists.txt
A	source/blender/editors/mesh/editmesh_extrude_boolean.c
M	source/blender/editors/mesh/mesh_intern.h
M	source/blender/editors/mesh/mesh_ops.c

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

diff --git a/release/scripts/presets/keyconfig/keymap_data/blender_default.py b/release/scripts/presets/keyconfig/keymap_data/blender_default.py
index 6a9306c2eab..c3f1d64957d 100644
--- a/release/scripts/presets/keyconfig/keymap_data/blender_default.py
+++ b/release/scripts/presets/keyconfig/keymap_data/blender_default.py
@@ -6226,6 +6226,16 @@ def km_3d_view_tool_edit_mesh_extrude_manifold(params):
     )
 
 
+def km_3d_view_tool_edit_mesh_extrude_boolean(params):
+    return (
+        "3D View Tool: Edit Mesh, Extrude Boolean",
+        {"space_type": 'VIEW_3D', "region_type": 'WINDOW'},
+        {"items": [
+            ("mesh.extrude_boolean", {"type": params.tool_tweak, "value": 'ANY'}, None),
+        ]},
+    )
+
+
 def km_3d_view_tool_edit_mesh_extrude_along_normals(params):
     return (
         "3D View Tool: Edit Mesh, Extrude Along Normals",
@@ -7222,6 +7232,7 @@ def generate_keymaps(params=None):
         km_3d_view_tool_edit_armature_extrude_to_cursor(params),
         km_3d_view_tool_edit_mesh_extrude_region(params),
         km_3d_view_tool_edit_mesh_extrude_manifold(params),
+        km_3d_view_tool_edit_mesh_extrude_boolean(params),
         km_3d_view_tool_edit_mesh_extrude_along_normals(params),
         km_3d_view_tool_edit_mesh_extrude_individual(params),
         km_3d_view_tool_edit_mesh_extrude_to_cursor(params),
diff --git a/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py b/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
index c5191e80aef..b3488135e83 100644
--- a/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
+++ b/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
@@ -938,6 +938,19 @@ class _defs_edit_mesh:
             keymap=(),
         )
 
+    @ToolDef.from_fn
+    def extrude_boolean():
+        return dict(
+            idname="builtin.extrude_boolean",
+            label="Extrude Boolean",
+            description=(
+                "Extrude, dissolves edges whose faces form a flat surface and intersect new edges"
+            ),
+            icon="ops.mesh.extrude_manifold",
+            widget="VIEW3D_GGT_tool_generic_handle_normal",
+            keymap=(),
+        )
+
     @ToolDef.from_fn
     def extrude_normals():
         def draw_settings(_context, layout, tool):
@@ -2746,6 +2759,7 @@ class VIEW3D_PT_tools_active(ToolSelectPanelHelper, Panel):
             (
                 _defs_edit_mesh.extrude,
                 _defs_edit_mesh.extrude_manifold,
+                _defs_edit_mesh.extrude_boolean,
                 _defs_edit_mesh.extrude_normals,
                 _defs_edit_mesh.extrude_individual,
                 _defs_edit_mesh.extrude_cursor,
diff --git a/source/blender/editors/mesh/CMakeLists.txt b/source/blender/editors/mesh/CMakeLists.txt
index 35bf295a678..4cf6afddc53 100644
--- a/source/blender/editors/mesh/CMakeLists.txt
+++ b/source/blender/editors/mesh/CMakeLists.txt
@@ -43,6 +43,7 @@ set(SRC
   editmesh_bevel.c
   editmesh_bisect.c
   editmesh_extrude.c
+  editmesh_extrude_boolean.c
   editmesh_extrude_screw.c
   editmesh_extrude_spin.c
   editmesh_extrude_spin_gizmo.c
diff --git a/source/blender/editors/mesh/editmesh_extrude_boolean.c b/source/blender/editors/mesh/editmesh_extrude_boolean.c
new file mode 100644
index 00000000000..a7ef5ecfb97
--- /dev/null
+++ b/source/blender/editors/mesh/editmesh_extrude_boolean.c
@@ -0,0 +1,629 @@
+/*
+ * 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.
+ */
+
+/** \file
+ * \ingroup edmesh
+ */
+
+#include "MEM_guardedalloc.h"
+
+#include "BKE_context.h"
+#include "BKE_editmesh.h"
+#include "BKE_report.h"
+
+#include "ED_mesh.h"
+#include "ED_screen.h"
+#include "ED_space_api.h"
+#include "ED_view3d.h"
+
+#include "GPU_batch.h"
+#include "GPU_matrix.h"
+#include "GPU_state.h"
+
+#include "RNA_access.h"
+#include "RNA_define.h"
+
+#include "UI_resources.h"
+
+#include "WM_api.h"
+
+#include "mesh_intern.h" /* own include */
+
+#include "tools/bmesh_boolean.h"
+#include "tools/bmesh_intersect.h"
+
+/* -------------------------------------------------------------------- */
+/** \name Mesh Pre-Select Element Gizmo
+ * \{ */
+
+typedef struct ExtrudeBooleanData {
+  BMesh *bm;
+  /* Start verts and end verts. */
+  BMVert **moving_verts;
+  int moving_verts_len;
+  float normal[3];
+
+  BMLoop *(*looptris)[3];
+  int looptris_len;
+
+  struct {
+    float center[3];
+    float normal[3];
+
+    float dist_initial;
+    float dist_curr;
+  } interaction_data;
+
+  struct {
+    ARegion *region;
+    float color[4];
+    void *draw_handle;
+
+    GPUBatch *batch_faces;
+    GPUBatch *batch_edges;
+    GPUVertBuf *vbo;
+    GPUIndexBuf *ibo_faces;
+    GPUIndexBuf *ibo_edges;
+    float (*v_co)[3];
+  } draw_data;
+
+  struct {
+    View3D *v3d;
+    char gizmo_flag_old;
+  } exit_data;
+} ExtrudeBooleanData;
+
+static void extrude_boolean_drawdata_clear(ExtrudeBooleanData *extrudata)
+{
+  GPU_batch_discard(extrudata->draw_data.batch_faces);
+  GPU_batch_discard(extrudata->draw_data.batch_edges);
+  GPU_vertbuf_discard(extrudata->draw_data.vbo);
+  GPU_indexbuf_discard(extrudata->draw_data.ibo_faces);
+  GPU_indexbuf_discard(extrudata->draw_data.ibo_edges);
+}
+
+static void extrude_boolean_drawdata_create(ExtrudeBooleanData *extrudata)
+{
+  static GPUVertFormat v_format = {0};
+  static GPUVertFormat line_format = {0};
+  if (v_format.attr_len == 0) {
+    GPU_vertformat_attr_add(&v_format, "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT);
+    GPU_vertformat_attr_add(&line_format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
+  }
+
+  BMesh *bm = extrudata->bm;
+  BMIter iter;
+  BMVert *v;
+  BMEdge *e;
+  BMFace *f;
+  int vert_len = 2 * extrudata->moving_verts_len;
+  int i;
+
+  GPUVertBuf *vbo = GPU_vertbuf_create_with_format_ex(&v_format, GPU_USAGE_DYNAMIC);
+  float(*v_co)[3] = NULL;
+  {
+    GPU_vertbuf_data_alloc(vbo, vert_len);
+    v_co = GPU_vertbuf_get_data(vbo);
+
+    for (i = 0; i < vert_len; i++) {
+      v = extrudata->moving_verts[i];
+      copy_v3_v3(v_co[i], v->co);
+      BM_elem_index_set(v, i);
+    }
+
+    bm->elem_index_dirty |= BM_VERT;
+  }
+
+  GPUIndexBuf *ibo_faces;
+  {
+    BMLoop *(*looptris)[3] = extrudata->looptris;
+    int looptris_draw_len = 0;
+    BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) {
+      if (BM_elem_flag_test(f, BM_ELEM_TAG)) {
+        looptris_draw_len += f->len - 2;
+      }
+    }
+
+    GPUIndexBufBuilder builder;
+    GPU_indexbuf_init(&builder, GPU_PRIM_TRIS, looptris_draw_len, vert_len);
+    int loop_first = 0;
+    BM_ITER_MESH_INDEX (f, &iter, bm, BM_FACES_OF_MESH, i) {
+      if (BM_elem_flag_test(f, BM_ELEM_TAG)) {
+        int ltri_index = poly_to_tri_count(i, loop_first);
+        int tri_len = f->len - 2;
+        while (tri_len--) {
+          BMLoop **ltri = looptris[ltri_index++];
+          GPU_indexbuf_add_tri_verts(&builder,
+                                     BM_elem_index_get(ltri[0]->v),
+                                     BM_elem_index_get(ltri[1]->v),
+                                     BM_elem_index_get(ltri[2]->v));
+        }
+      }
+      loop_first += f->len;
+    }
+
+    ibo_faces = GPU_indexbuf_build(&builder);
+  }
+
+  GPUIndexBuf *ibo_edges;
+  {
+    int edges_draw_len = 0;
+    BM_ITER_MESH (e, &iter, bm, BM_EDGES_OF_MESH) {
+      if (BM_elem_flag_test(e->v1, BM_ELEM_TAG) && BM_elem_flag_test(e->v2, BM_ELEM_TAG)) {
+        BM_elem_flag_enable(e, BM_ELEM_TAG);
+        edges_draw_len++;
+      }
+      else {
+        BM_elem_flag_disable(e, BM_ELEM_TAG);
+      }
+    }
+
+    GPUIndexBufBuilder builder;
+    GPU_indexbuf_init(&builder, GPU_PRIM_LINES, edges_draw_len, vert_len);
+    BM_ITER_MESH (e, &iter, bm, BM_EDGES_OF_MESH) {
+      if (BM_elem_flag_test(e, BM_ELEM_TAG)) {
+        GPU_indexbuf_add_line_verts(&builder, BM_elem_index_get(e->v1), BM_elem_index_get(e->v2));
+      }
+    }
+
+    ibo_edges = GPU_indexbuf_build(&builder);
+  }
+
+  GPUBatch *batch_faces = GPU_batch_create(GPU_PRIM_TRIS, vbo, ibo_faces);
+  GPU_batch_program_set_builtin(batch_faces, GPU_SHADER_3D_UNIFORM_COLOR);
+
+  GPUBatch *batch_edges = GPU_batch_create(GPU_PRIM_LINES, vbo, ibo_edges);
+  GPU_batch_program_set_builtin(batch_edges, GPU_SHADER_3D_UNIFORM_COLOR);
+
+  extrudata->draw_data.batch_faces = batch_faces;
+  extrudata->draw_data.batch_edges = batch_edges;
+  extrudata->draw_data.vbo = vbo;
+  extrudata->draw_data.ibo_faces = ibo_faces;
+  extrudata->draw_data.ibo_edges = ibo_edges;
+  extrudata->draw_data.v_co = v_co;
+}
+
+static void extrude_boolean_data_exit(ExtrudeBooleanData *extrudata)
+{
+  if (extrudata->draw_data.batch_faces) {
+    extrude_boolean_drawdata_clear(extrudata);
+  }
+
+  if (extrudata->bm) {
+    BM_mesh_free(extrudata->bm);
+  }
+
+  if (extrudata->looptris) {
+    MEM_freeN(extrudata->looptris);
+  }
+
+  ED_region_draw_cb_exit(extrudata->draw_data.region->type, extrudata->draw_data.draw_handle);
+  extrudata->exit_data.v3d->gizmo_flag = extrudata->exit_data.gizmo_flag_old;
+  MEM_freeN(extrudata->moving_verts);
+  MEM_freeN(extrudata);
+}
+
+static void extrude_boolean_draw_fn(const bContext *C, ARegion *region, void *data)
+{
+  ExtrudeBooleanData *extrudata = data;
+  Object *obedit = CTX_data_edit_object(C);
+  if (!obedit || obedit->type != OB_MESH) {
+    return;
+  }
+
+  const RegionView3D *rv3d = region->regiondata;
+
+  GPU_matrix_push();
+  GPU_matrix_mul(obedit->obmat);
+
+  if (GPU_vertbuf_get_status(extrudata->draw_data.vbo) & GPU_VERTBUF_DATA_DIRTY) {
+    GPU_vertbuf_use(extrudata->draw_data.vbo);
+  }
+
+  ED_view3d_p

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list