[Bf-blender-cvs] [66cdb4df51d] sculpt-mode-features: Blueprint tool: Initial implementation

Pablo Dobarro noreply at git.blender.org
Mon Jul 8 16:21:19 CEST 2019


Commit: 66cdb4df51d4768f6408564dca033d450170955d
Author: Pablo Dobarro
Date:   Mon Jul 8 16:15:00 2019 +0200
Branches: sculpt-mode-features
https://developer.blender.org/rB66cdb4df51d4768f6408564dca033d450170955d

Blueprint tool: Initial implementation

Work in progress

- Geometry generation code is only for testing the operator. It will triangulate any
generated ngon and the normal calculation can fail.
- Snapping options are not integrated with scene settings
- Gird alignment is forced to global X axis. This can cause problems
with rotated objects.
- The tool only works from object mode. It crashes in other modes.
- Some internal grid default values are not set up properly and can make
the operator crash
- The grid preview is not integrated with the gizmo system, you need to
start the operator in order to see it

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

M	release/scripts/presets/keyconfig/keymap_data/blender_default.py
M	release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
M	source/blender/editors/object/CMakeLists.txt
A	source/blender/editors/object/object_blueprint.c
M	source/blender/editors/object/object_intern.h
M	source/blender/editors/object/object_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 17b1b874dec..acc4c8c173d 100644
--- a/release/scripts/presets/keyconfig/keymap_data/blender_default.py
+++ b/release/scripts/presets/keyconfig/keymap_data/blender_default.py
@@ -5916,6 +5916,15 @@ def km_3d_view_tool_sculpt_gpencil_select_lasso(params):
     )
 
 
+def km_3d_view_tool_object_blueprint(params):
+    return (
+        "Object: Blueprint",
+        {"space_type": 'VIEW_3D', "region_type": 'WINDOW'},
+        {"items": [
+            ("object.blueprint", {"type": params.tool_mouse, "value": 'PRESS'},
+             None)
+        ]},
+    )
 # ------------------------------------------------------------------------------
 # Full Configuration
 
@@ -6128,6 +6137,7 @@ def generate_keymaps(params=None):
         km_3d_view_tool_sculpt_gpencil_select_box(params),
         km_3d_view_tool_sculpt_gpencil_select_circle(params),
         km_3d_view_tool_sculpt_gpencil_select_lasso(params),
+        km_3d_view_tool_object_blueprint(params),
     ]
 
 # ------------------------------------------------------------------------------
diff --git a/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py b/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
index 77945702e2a..1dce523402c 100644
--- a/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
+++ b/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
@@ -140,6 +140,28 @@ class _defs_view3d_generic:
             keymap="3D View Tool: Measure",
         )
 
+    @ToolDef.from_fn
+    def blueprint():
+        def draw_settings(context, layout, tool):
+            props = tool.operator_properties("object.blueprint")
+            sub = layout.row()
+            sub.use_property_split = False
+            sub.prop(props, "draw_tool", expand=False)
+            sub.prop(props, "plane_offset", expand=False)
+            sub.prop(props, "grid_snap", expand=False)
+            sub.prop(props, "grid_size", expand=False)
+            sub.prop(props, "floor_grid_snap", expand=False)
+            sub.prop(props, "vertex_snap", expand=False)
+            sub.prop(props, "symmetrical_extrude", expand=False)
+            sub.prop(props, "ellipse_nsegments", expand=False)
+        return dict(
+            idname="object.blueprint",
+            label="Bluerprint",
+            icon="object.blueprint",
+            keymap="Object: Blueprint",
+            draw_settings=draw_settings,
+        )
+
 
 class _defs_annotate:
 
@@ -1911,6 +1933,8 @@ class VIEW3D_PT_tools_active(ToolSelectPanelHelper, Panel):
         None,
         *_tools_annotate,
         _defs_view3d_generic.ruler,
+        None,
+        _defs_view3d_generic.blueprint,
     )
 
     _tools = {
diff --git a/source/blender/editors/object/CMakeLists.txt b/source/blender/editors/object/CMakeLists.txt
index 48c8c8cee08..43323a939ed 100644
--- a/source/blender/editors/object/CMakeLists.txt
+++ b/source/blender/editors/object/CMakeLists.txt
@@ -46,6 +46,7 @@ set(SRC
   object_add.c
   object_bake.c
   object_bake_api.c
+  object_blueprint.c
   object_collection.c
   object_constraint.c
   object_data_transfer.c
diff --git a/source/blender/editors/object/object_blueprint.c b/source/blender/editors/object/object_blueprint.c
new file mode 100644
index 00000000000..874ea86d085
--- /dev/null
+++ b/source/blender/editors/object/object_blueprint.c
@@ -0,0 +1,1433 @@
+/*
+ * 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.
+ *
+ * The Original Code is Copyright (C) 2019 by Blender Foundation
+ * All rights reserved.
+ */
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_math.h"
+#include "BLI_task.h"
+#include "BLI_utildefines.h"
+#include "BLI_ghash.h"
+#include "BLI_listbase.h"
+#include "BLI_polyfill_2d.h"
+#include "BLI_math_color_blend.h"
+
+#include "DNA_customdata_types.h"
+#include "DNA_mesh_types.h"
+#include "DNA_meshdata_types.h"
+#include "DNA_node_types.h"
+#include "DNA_object_types.h"
+#include "DNA_scene_types.h"
+#include "DNA_camera_types.h"
+
+#include "BKE_context.h"
+#include "BKE_library.h"
+#include "BKE_main.h"
+#include "BKE_mesh.h"
+#include "BKE_editmesh.h"
+#include "BKE_modifier.h"
+#include "BKE_object.h"
+#include "BKE_report.h"
+#include "BKE_scene.h"
+#include "BKE_screen.h"
+
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_query.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+#include "WM_message.h"
+#include "WM_toolsystem.h"
+
+#include "ED_screen.h"
+#include "ED_object.h"
+#include "ED_view3d.h"
+#include "ED_space_api.h"
+#include "ED_transform_snap_object_context.h"
+
+#include "RNA_access.h"
+#include "RNA_define.h"
+
+#include "UI_interface.h"
+#include "UI_resources.h"
+
+#include "bmesh.h"
+#include "bmesh_tools.h"
+
+#include "GPU_draw.h"
+#include "GPU_immediate.h"
+#include "GPU_immediate_util.h"
+#include "GPU_matrix.h"
+#include "GPU_state.h"
+
+#include <math.h>
+#include <stdlib.h>
+#include <string.h>
+
+typedef enum BlueprintContext {
+  BLUEPRINT_CTX_GEOMETRY,
+  BLUEPRINT_CTX_SELECTION,
+  BLUEPRINT_CTX_VOLUME,
+} BlueprintContext;
+
+typedef enum BlueprintState {
+  BLUEPRINT_STATE_PLANE,
+  BLUEPRINT_STATE_DRAW,
+  BLUEPRINT_STATE_EXTRUDE,
+  BLUEPRINT_STATE_BOOLEAN,
+} BlueprintState;
+
+typedef enum BlueprintDrawTool {
+  BLUEPRINT_DT_RECT,
+  BLUEPRINT_DT_ELLIPSE,
+  BLUEPRINT_DT_POLYLINE,
+  BLUEPRINT_DT_FREEHAND,
+} BlueprintDrawTool;
+
+typedef struct BlueprintConfig {
+  BlueprintContext context;
+
+} BlueprintConfig;
+
+typedef enum BlueprintFlags {
+  BLUEPRINT_SYMMETRICAL_EXTRUDE = 1 << 0,
+  BLUEPRINT_AUTO_ENTER_DRAW_STATE = 1 << 1,
+  BLUEPRINT_AUTO_START_DRAW_STATE = 1 << 2,
+  BLUEPRINT_SKIP_EXTRUDE_STATE = 1 << 3,
+  BLUEPRINT_ENABLE_GRID = 1 << 4,
+  BLUEPRINT_ENABLE_GRID_BACKGROUD = 1 << 5,
+  BLUEPRINT_ENABLE_GEOMETRY_FILL = 1 << 6,
+  BLUEPRINT_EXTRUDE_ON_RELEASE = 1 << 7,
+} BlueprintFlags;
+
+typedef struct BlueprintGeometryData {
+  float n[3];
+  float t[3];
+  float co[3];
+
+  Object *sf_object;
+} BlueprintGeometryData;
+
+EnumPropertyItem prop_blueprint_draw_tool_types[] = {
+    {BLUEPRINT_DT_RECT, "RECT", 0, "Rect", "Rectangle drawing"},
+    {BLUEPRINT_DT_ELLIPSE, "ELLIPSE", 0, "Ellipse", "Ellipse drawing"},
+    {BLUEPRINT_DT_POLYLINE, "POLYLINE", 0, "Polyline", "Polyline drawing"},
+    {BLUEPRINT_DT_FREEHAND, "FREEHAND", 0, "Freehand", "Freehand drawing"},
+    {0, NULL, 0, NULL, NULL},
+};
+
+
+typedef struct BlueprintPolyPoint {
+  struct BlueprintPolyPoint *next, *prev;
+
+  float co[2];
+  int status;
+  char _pad[4];
+} BlueprintPolyPoint;
+
+typedef struct BlueprintColor {
+  uchar grid[4];
+  uchar geom_stroke[4];
+  uchar geom_fill[4];
+  uchar cursor[4];
+  uchar bg[4];
+} BlueprintColor;
+
+typedef struct BlueprintCache {
+  BlueprintContext context;
+  BlueprintState state;
+  BlueprintDrawTool drawtool;
+  BlueprintColor color;
+
+  ARegion *ar;
+  View3D *v3d;
+
+  /* geometry creation context */
+  Object *ob;
+
+
+
+  float plane_offset;
+
+  int grid_snap;
+  float gridx_size;
+  float gridy_size;
+  float gridz_size;
+
+  int grid_padding;
+  float grid_extends_min[2];
+  float grid_extends_max[2];
+
+  float n[3];
+  float bn[3];
+  float co[3];
+
+  float plane[4];
+  float origin[3];
+  float mat[4][4];
+  float mat_inv[4][4];
+
+  float cursor[3];
+  float cursor_global[3];
+  float cursor_mat[4][4];
+
+  float extrudedist;
+  float extrude_co[3];
+
+  int extrude_both_sides;
+
+  int point_count;
+  ListBase poly;
+  float (*coords)[2];
+  uint (*r_tris)[3];
+
+  /* for Draw rect tool */
+  BlueprintPolyPoint *ps[4];
+
+  /* for Ellipse tool */
+  float cursor_start[3];
+  int ellipse_nsegments;
+
+  /* for Freehand tool */
+  float freehand_step_threshold;
+
+  int flags;
+  bool draw_tool_init;
+  char _pad[7];
+
+  Object *sf_ob;
+  Object *new_ob;
+} BlueprintCache;
+
+typedef struct BlueprintCD {
+  BlueprintCache cache;
+
+  void *draw_handle;
+
+} BlueprintCD;
+
+void BKE_blueprint_color_init(BlueprintCache *cache)
+{
+  cache->color.cursor[0] = 235;
+  cache->color.cursor[1] = 59;
+  cache->color.cursor[2] = 59;
+  cache->color.cursor[3] = 255;
+
+  cache->color.grid[0] = 220;
+  cache->color.grid[1] = 220;
+  cache->color.grid[2] = 220;
+  cache->color.grid[3] = 200;
+
+  cache->color.bg[0] = 111;
+  cache->color.bg[1] = 158;
+  cache->color.bg[2] = 232;
+  cache->color.bg[3] = 180;
+
+  cache->color.geom_fill[0] = 190;
+  cache->color.geom_fill[1] = 190;
+  cache->color.geom_fill[2] = 190;
+  cache->color.geom_fill[3] = 150;
+
+  cache->color.geom_stroke[0] = 230;
+  cache->color.geom_stroke[1] = 230;
+  cache->color.geom_stroke[2] = 230;
+  cache->color.geom_stroke[3] = 255;
+}
+
+void blueprint_draw_poly_volume(uint pos3d, BlueprintCache *cache, float z)
+{
+  int point_count = cache->point_count;
+  GPU_depth_test(true);
+  immUniformColor4ubv(cache->color.geom_fill);
+    float z_base = 0.0f;
+    if (cache->flags & BLUEPRINT_SYMMETRICAL_EXTRUDE) {
+      z_base = -cache->extrudedist;
+    }
+
+   bool draw_fill = cache->flags & BLUEPRINT_ENABLE_GEOMETRY_FILL;
+  if (point_count >= 3) {
+    if (draw_fill) {
+        immBegin(GPU_PRIM_TRIS, point_count * 6);
+        LISTBASE_FOREACH (BlueprintPolyPoint *, p, &cache->poly) {
+          BlueprintPolyPoint *np;
+          if (p->next) {
+            np = p->next;
+          }
+          else {
+            np = cache->poly.first;
+          }
+
+          immVertex3f(pos3d, p->co[0], p->co[1], z_base);
+          immVertex3f(pos3d, p->co[0], p-

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list