| 
									
										
										
										
											2013-08-29 18:45:04 +00:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * 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) 2013 by Blender Foundation. | 
					
						
							|  |  |  |  * All rights reserved. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-18 08:08:12 +11:00
										 |  |  | /** \file
 | 
					
						
							|  |  |  |  * \ingroup edmesh | 
					
						
							| 
									
										
										
										
											2013-08-29 18:45:04 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "MEM_guardedalloc.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "DNA_object_types.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "BLI_math.h"
 | 
					
						
							| 
									
										
										
										
											2014-01-04 05:41:58 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-16 17:32:01 +10:00
										 |  |  | #include "BLT_translation.h"
 | 
					
						
							| 
									
										
										
										
											2013-08-29 18:45:04 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include "BKE_context.h"
 | 
					
						
							|  |  |  | #include "BKE_editmesh.h"
 | 
					
						
							| 
									
										
										
										
											2020-03-19 09:33:03 +01:00
										 |  |  | #include "BKE_global.h"
 | 
					
						
							| 
									
										
										
										
											2018-08-22 16:33:39 +10:00
										 |  |  | #include "BKE_layer.h"
 | 
					
						
							| 
									
										
										
										
											2013-11-26 09:44:08 +11:00
										 |  |  | #include "BKE_report.h"
 | 
					
						
							| 
									
										
										
										
											2013-08-29 18:45:04 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include "RNA_access.h"
 | 
					
						
							| 
									
										
										
										
											2020-03-19 09:33:03 +01:00
										 |  |  | #include "RNA_define.h"
 | 
					
						
							| 
									
										
										
										
											2013-08-29 18:45:04 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include "WM_api.h"
 | 
					
						
							|  |  |  | #include "WM_types.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-19 09:33:03 +01:00
										 |  |  | #include "ED_gizmo_utils.h"
 | 
					
						
							| 
									
										
										
										
											2013-08-29 18:45:04 +00:00
										 |  |  | #include "ED_mesh.h"
 | 
					
						
							|  |  |  | #include "ED_screen.h"
 | 
					
						
							|  |  |  | #include "ED_view3d.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-08 17:06:24 +10:00
										 |  |  | #include "UI_resources.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-29 18:45:04 +00:00
										 |  |  | #include "mesh_intern.h" /* own include */
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-14 23:49:00 +02:00
										 |  |  | #define USE_GIZMO
 | 
					
						
							| 
									
										
										
										
											2017-06-16 08:25:24 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-14 23:49:00 +02:00
										 |  |  | #ifdef USE_GIZMO
 | 
					
						
							| 
									
										
										
										
											2018-07-14 23:16:34 +02:00
										 |  |  | #  include "ED_gizmo_library.h"
 | 
					
						
							| 
									
										
										
										
											2018-04-02 15:18:10 +02:00
										 |  |  | #  include "ED_undo.h"
 | 
					
						
							| 
									
										
										
										
											2017-06-16 08:25:24 +10:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-30 12:48:39 +00:00
										 |  |  | static int mesh_bisect_exec(bContext *C, wmOperator *op); | 
					
						
							| 
									
										
										
										
											2013-08-29 18:45:04 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* -------------------------------------------------------------------- */ | 
					
						
							|  |  |  | /* Model Helpers */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | typedef struct { | 
					
						
							|  |  |  |   /* modal only */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-22 16:33:39 +10:00
										 |  |  |   /* Aligned with objects array. */ | 
					
						
							|  |  |  |   struct { | 
					
						
							|  |  |  |     BMBackup mesh; | 
					
						
							|  |  |  |     bool is_valid; | 
					
						
							|  |  |  |     bool is_dirty; | 
					
						
							|  |  |  |   } * backup; | 
					
						
							|  |  |  |   int backup_len; | 
					
						
							| 
									
										
										
										
											2018-07-15 14:24:10 +02:00
										 |  |  |   short gizmo_flag; | 
					
						
							| 
									
										
										
										
											2013-08-29 18:45:04 +00:00
										 |  |  | } BisectData; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-22 16:33:39 +10:00
										 |  |  | static void mesh_bisect_interactive_calc(bContext *C, | 
					
						
							| 
									
										
										
										
											2013-08-29 18:45:04 +00:00
										 |  |  |                                          wmOperator *op, | 
					
						
							|  |  |  |                                          float plane_co[3], | 
					
						
							|  |  |  |                                          float plane_no[3]) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-12-08 12:41:27 +01:00
										 |  |  |   View3D *v3d = CTX_wm_view3d(C); | 
					
						
							| 
									
										
										
										
											2020-03-06 16:56:42 +01:00
										 |  |  |   ARegion *region = CTX_wm_region(C); | 
					
						
							|  |  |  |   RegionView3D *rv3d = region->regiondata; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-29 18:45:04 +00:00
										 |  |  |   int x_start = RNA_int_get(op->ptr, "xstart"); | 
					
						
							|  |  |  |   int y_start = RNA_int_get(op->ptr, "ystart"); | 
					
						
							|  |  |  |   int x_end = RNA_int_get(op->ptr, "xend"); | 
					
						
							|  |  |  |   int y_end = RNA_int_get(op->ptr, "yend"); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-09 20:22:01 +00:00
										 |  |  |   /* reference location (some point in front of the view) for finding a point on a plane */ | 
					
						
							| 
									
										
										
										
											2013-08-29 18:45:04 +00:00
										 |  |  |   const float *co_ref = rv3d->ofs; | 
					
						
							|  |  |  |   float co_a_ss[2] = {x_start, y_start}, co_b_ss[2] = {x_end, y_end}, co_delta_ss[2]; | 
					
						
							|  |  |  |   float co_a[3], co_b[3]; | 
					
						
							| 
									
										
										
										
											2013-08-30 16:52:54 +00:00
										 |  |  |   const float zfac = ED_view3d_calc_zfac(rv3d, co_ref, NULL); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-29 18:45:04 +00:00
										 |  |  |   /* view vector */ | 
					
						
							| 
									
										
										
										
											2020-03-06 16:56:42 +01:00
										 |  |  |   ED_view3d_win_to_vector(region, co_a_ss, co_a); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-29 18:45:04 +00:00
										 |  |  |   /* view delta */ | 
					
						
							|  |  |  |   sub_v2_v2v2(co_delta_ss, co_a_ss, co_b_ss); | 
					
						
							| 
									
										
										
										
											2020-03-06 16:56:42 +01:00
										 |  |  |   ED_view3d_win_to_delta(region, co_delta_ss, co_b, zfac); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-29 18:45:04 +00:00
										 |  |  |   /* cross both to get a normal */ | 
					
						
							|  |  |  |   cross_v3_v3v3(plane_no, co_a, co_b); | 
					
						
							| 
									
										
										
										
											2013-08-30 12:48:39 +00:00
										 |  |  |   normalize_v3(plane_no); /* not needed but nicer for user */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-29 18:45:04 +00:00
										 |  |  |   /* point on plane, can use either start or endpoint */ | 
					
						
							| 
									
										
										
										
											2020-03-06 16:56:42 +01:00
										 |  |  |   ED_view3d_win_to_3d(v3d, region, co_ref, co_a_ss, plane_co); | 
					
						
							| 
									
										
										
										
											2013-08-29 18:45:04 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int mesh_bisect_invoke(bContext *C, wmOperator *op, const wmEvent *event) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-08-22 16:33:39 +10:00
										 |  |  |   ViewLayer *view_layer = CTX_data_view_layer(C); | 
					
						
							|  |  |  |   int valid_objects = 0; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-22 16:33:39 +10:00
										 |  |  |   /* If the properties are set or there is no rv3d,
 | 
					
						
							|  |  |  |    * skip model and exec immediately. */ | 
					
						
							| 
									
										
										
										
											2013-08-30 12:48:39 +00:00
										 |  |  |   if ((CTX_wm_region_view3d(C) == NULL) || (RNA_struct_property_is_set(op->ptr, "plane_co") && | 
					
						
							|  |  |  |                                             RNA_struct_property_is_set(op->ptr, "plane_no"))) { | 
					
						
							|  |  |  |     return mesh_bisect_exec(C, op); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-22 16:33:39 +10:00
										 |  |  |   uint objects_len = 0; | 
					
						
							| 
									
										
										
										
											2018-11-25 09:50:34 -02:00
										 |  |  |   Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data( | 
					
						
							|  |  |  |       view_layer, CTX_wm_view3d(C), &objects_len); | 
					
						
							| 
									
										
										
										
											2018-08-22 16:33:39 +10:00
										 |  |  |   for (uint ob_index = 0; ob_index < objects_len; ob_index++) { | 
					
						
							|  |  |  |     Object *obedit = objects[ob_index]; | 
					
						
							|  |  |  |     BMEditMesh *em = BKE_editmesh_from_object(obedit); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-22 16:33:39 +10:00
										 |  |  |     if (em->bm->totedgesel != 0) { | 
					
						
							|  |  |  |       valid_objects++; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-08-22 16:33:39 +10:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-22 16:33:39 +10:00
										 |  |  |   if (valid_objects == 0) { | 
					
						
							|  |  |  |     BKE_report(op->reports, RPT_ERROR, "Selected edges/faces required"); | 
					
						
							|  |  |  |     MEM_freeN(objects); | 
					
						
							|  |  |  |     return OPERATOR_CANCELLED; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-22 16:33:39 +10:00
										 |  |  |   int ret = WM_gesture_straightline_invoke(C, op, event); | 
					
						
							| 
									
										
										
										
											2013-08-29 18:45:04 +00:00
										 |  |  |   if (ret & OPERATOR_RUNNING_MODAL) { | 
					
						
							|  |  |  |     View3D *v3d = CTX_wm_view3d(C); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-29 18:45:04 +00:00
										 |  |  |     wmGesture *gesture = op->customdata; | 
					
						
							|  |  |  |     BisectData *opdata; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-29 18:45:04 +00:00
										 |  |  |     opdata = MEM_mallocN(sizeof(BisectData), "inset_operator_data"); | 
					
						
							| 
									
										
										
										
											2019-05-20 15:06:06 +10:00
										 |  |  |     gesture->user_data.data = opdata; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-22 16:33:39 +10:00
										 |  |  |     opdata->backup_len = objects_len; | 
					
						
							|  |  |  |     opdata->backup = MEM_callocN(sizeof(*opdata->backup) * objects_len, __func__); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-22 16:33:39 +10:00
										 |  |  |     /* Store the mesh backups. */ | 
					
						
							|  |  |  |     for (uint ob_index = 0; ob_index < objects_len; ob_index++) { | 
					
						
							|  |  |  |       Object *obedit = objects[ob_index]; | 
					
						
							|  |  |  |       BMEditMesh *em = BKE_editmesh_from_object(obedit); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-22 16:33:39 +10:00
										 |  |  |       if (em->bm->totedgesel != 0) { | 
					
						
							|  |  |  |         opdata->backup[ob_index].is_valid = true; | 
					
						
							|  |  |  |         opdata->backup[ob_index].mesh = EDBM_redo_state_store(em); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-22 16:33:39 +10:00
										 |  |  |     /* Misc other vars. */ | 
					
						
							| 
									
										
										
										
											2013-08-29 18:45:04 +00:00
										 |  |  |     G.moving = G_TRANSFORM_EDIT; | 
					
						
							| 
									
										
										
										
											2018-07-15 14:24:10 +02:00
										 |  |  |     opdata->gizmo_flag = v3d->gizmo_flag; | 
					
						
							|  |  |  |     v3d->gizmo_flag = V3D_GIZMO_HIDE; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-22 16:33:39 +10:00
										 |  |  |     /* Initialize modal callout. */ | 
					
						
							| 
									
										
										
										
											2019-06-11 22:25:01 +02:00
										 |  |  |     ED_workspace_status_text(C, TIP_("LMB: Click and drag to draw cut line")); | 
					
						
							| 
									
										
										
										
											2013-08-29 18:45:04 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2018-08-22 16:33:39 +10:00
										 |  |  |   MEM_freeN(objects); | 
					
						
							| 
									
										
										
										
											2013-08-29 18:45:04 +00:00
										 |  |  |   return ret; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void edbm_bisect_exit(bContext *C, BisectData *opdata) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   View3D *v3d = CTX_wm_view3d(C); | 
					
						
							| 
									
										
										
										
											2018-07-15 14:24:10 +02:00
										 |  |  |   v3d->gizmo_flag = opdata->gizmo_flag; | 
					
						
							| 
									
										
										
										
											2013-08-29 18:45:04 +00:00
										 |  |  |   G.moving = 0; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-22 16:33:39 +10:00
										 |  |  |   for (int ob_index = 0; ob_index < opdata->backup_len; ob_index++) { | 
					
						
							|  |  |  |     if (opdata->backup[ob_index].is_valid) { | 
					
						
							|  |  |  |       EDBM_redo_state_free(&opdata->backup[ob_index].mesh, NULL, false); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   MEM_freeN(opdata->backup); | 
					
						
							| 
									
										
										
										
											2013-08-29 18:45:04 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int mesh_bisect_modal(bContext *C, wmOperator *op, const wmEvent *event) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   wmGesture *gesture = op->customdata; | 
					
						
							| 
									
										
										
										
											2019-05-20 15:06:06 +10:00
										 |  |  |   BisectData *opdata = gesture->user_data.data; | 
					
						
							| 
									
										
										
										
											2013-08-29 18:45:04 +00:00
										 |  |  |   BisectData opdata_back = *opdata; /* annoyance, WM_gesture_straightline_modal, frees */ | 
					
						
							|  |  |  |   int ret; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-29 18:45:04 +00:00
										 |  |  |   ret = WM_gesture_straightline_modal(C, op, event); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-04 05:41:58 +01:00
										 |  |  |   /* update or clear modal callout */ | 
					
						
							|  |  |  |   if (event->type == EVT_MODAL_MAP) { | 
					
						
							| 
									
										
										
										
											2014-01-09 11:44:14 +11:00
										 |  |  |     if (event->val == GESTURE_MODAL_BEGIN) { | 
					
						
							| 
									
										
										
										
											2019-06-11 22:25:01 +02:00
										 |  |  |       ED_workspace_status_text(C, TIP_("LMB: Release to confirm cut line")); | 
					
						
							| 
									
										
										
										
											2014-01-04 05:41:58 +01:00
										 |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							| 
									
										
										
										
											2018-06-26 17:19:25 +02:00
										 |  |  |       ED_workspace_status_text(C, NULL); | 
					
						
							| 
									
										
										
										
											2014-01-04 05:41:58 +01:00
										 |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-29 18:45:04 +00:00
										 |  |  |   if (ret & (OPERATOR_FINISHED | OPERATOR_CANCELLED)) { | 
					
						
							| 
									
										
										
										
											2013-08-29 19:02:07 +00:00
										 |  |  |     edbm_bisect_exit(C, &opdata_back); | 
					
						
							| 
									
										
										
										
											2017-06-16 08:25:24 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-14 23:49:00 +02:00
										 |  |  | #ifdef USE_GIZMO
 | 
					
						
							|  |  |  |     /* Setup gizmos */ | 
					
						
							| 
									
										
										
										
											2017-06-16 08:25:24 +10:00
										 |  |  |     { | 
					
						
							|  |  |  |       View3D *v3d = CTX_wm_view3d(C); | 
					
						
							| 
									
										
										
										
											2018-07-15 14:24:10 +02:00
										 |  |  |       if (v3d && (v3d->gizmo_flag & V3D_GIZMO_HIDE) == 0) { | 
					
						
							|  |  |  |         WM_gizmo_group_type_ensure("MESH_GGT_bisect"); | 
					
						
							| 
									
										
										
										
											2017-06-16 08:25:24 +10:00
										 |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2013-08-29 18:45:04 +00:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return ret; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* End Model Helpers */ | 
					
						
							|  |  |  | /* -------------------------------------------------------------------- */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int mesh_bisect_exec(bContext *C, wmOperator *op) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   Scene *scene = CTX_data_scene(C); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-29 18:45:04 +00:00
										 |  |  |   /* both can be NULL, fallbacks values are used */ | 
					
						
							|  |  |  |   RegionView3D *rv3d = ED_view3d_context_rv3d(C); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-22 16:33:39 +10:00
										 |  |  |   int ret = OPERATOR_CANCELLED; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-29 18:45:04 +00:00
										 |  |  |   float plane_co[3]; | 
					
						
							|  |  |  |   float plane_no[3]; | 
					
						
							|  |  |  |   float imat[4][4]; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-29 18:45:04 +00:00
										 |  |  |   const float thresh = RNA_float_get(op->ptr, "threshold"); | 
					
						
							|  |  |  |   const bool use_fill = RNA_boolean_get(op->ptr, "use_fill"); | 
					
						
							|  |  |  |   const bool clear_inner = RNA_boolean_get(op->ptr, "clear_inner"); | 
					
						
							|  |  |  |   const bool clear_outer = RNA_boolean_get(op->ptr, "clear_outer"); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-29 18:45:04 +00:00
										 |  |  |   PropertyRNA *prop_plane_co; | 
					
						
							|  |  |  |   PropertyRNA *prop_plane_no; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-29 18:45:04 +00:00
										 |  |  |   prop_plane_co = RNA_struct_find_property(op->ptr, "plane_co"); | 
					
						
							|  |  |  |   if (RNA_property_is_set(op->ptr, prop_plane_co)) { | 
					
						
							|  |  |  |     RNA_property_float_get_array(op->ptr, prop_plane_co, plane_co); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   else { | 
					
						
							| 
									
										
										
										
											2018-11-26 13:49:17 +11:00
										 |  |  |     copy_v3_v3(plane_co, scene->cursor.location); | 
					
						
							| 
									
										
										
										
											2013-08-29 18:45:04 +00:00
										 |  |  |     RNA_property_float_set_array(op->ptr, prop_plane_co, plane_co); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-29 18:45:04 +00:00
										 |  |  |   prop_plane_no = RNA_struct_find_property(op->ptr, "plane_no"); | 
					
						
							|  |  |  |   if (RNA_property_is_set(op->ptr, prop_plane_no)) { | 
					
						
							|  |  |  |     RNA_property_float_get_array(op->ptr, prop_plane_no, plane_no); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   else { | 
					
						
							|  |  |  |     if (rv3d) { | 
					
						
							|  |  |  |       copy_v3_v3(plane_no, rv3d->viewinv[1]); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							|  |  |  |       /* fallback... */ | 
					
						
							|  |  |  |       plane_no[0] = plane_no[1] = 0.0f; | 
					
						
							|  |  |  |       plane_no[2] = 1.0f; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     RNA_property_float_set_array(op->ptr, prop_plane_no, plane_no); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-22 16:33:39 +10:00
										 |  |  |   wmGesture *gesture = op->customdata; | 
					
						
							| 
									
										
										
										
											2019-05-20 15:06:06 +10:00
										 |  |  |   BisectData *opdata = (gesture != NULL) ? gesture->user_data.data : NULL; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-29 18:45:04 +00:00
										 |  |  |   /* -------------------------------------------------------------------- */ | 
					
						
							|  |  |  |   /* Modal support */ | 
					
						
							| 
									
										
										
										
											2018-09-27 15:49:59 +02:00
										 |  |  |   /* Note: keep this isolated, exec can work without this */ | 
					
						
							| 
									
										
										
										
											2018-08-22 16:33:39 +10:00
										 |  |  |   if (opdata != NULL) { | 
					
						
							|  |  |  |     mesh_bisect_interactive_calc(C, op, plane_co, plane_no); | 
					
						
							|  |  |  |     /* Write back to the props. */ | 
					
						
							| 
									
										
										
										
											2013-08-29 18:45:04 +00:00
										 |  |  |     RNA_property_float_set_array(op->ptr, prop_plane_no, plane_no); | 
					
						
							|  |  |  |     RNA_property_float_set_array(op->ptr, prop_plane_co, plane_co); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   /* End Modal */ | 
					
						
							|  |  |  |   /* -------------------------------------------------------------------- */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-22 16:33:39 +10:00
										 |  |  |   uint objects_len = 0; | 
					
						
							| 
									
										
										
										
											2018-11-25 09:50:34 -02:00
										 |  |  |   Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data( | 
					
						
							|  |  |  |       CTX_data_view_layer(C), CTX_wm_view3d(C), &objects_len); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-22 16:33:39 +10:00
										 |  |  |   for (uint ob_index = 0; ob_index < objects_len; ob_index++) { | 
					
						
							|  |  |  |     Object *obedit = objects[ob_index]; | 
					
						
							|  |  |  |     BMEditMesh *em = BKE_editmesh_from_object(obedit); | 
					
						
							|  |  |  |     BMesh *bm = em->bm; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-22 16:33:39 +10:00
										 |  |  |     if (opdata != NULL) { | 
					
						
							|  |  |  |       if (opdata->backup[ob_index].is_dirty) { | 
					
						
							|  |  |  |         EDBM_redo_state_restore(opdata->backup[ob_index].mesh, em, false); | 
					
						
							|  |  |  |         opdata->backup[ob_index].is_dirty = false; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2018-08-22 16:33:39 +10:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-22 16:33:39 +10:00
										 |  |  |     if (bm->totedgesel == 0) { | 
					
						
							|  |  |  |       continue; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-22 16:33:39 +10:00
										 |  |  |     if (opdata != NULL) { | 
					
						
							|  |  |  |       if (opdata->backup[ob_index].is_valid) { | 
					
						
							|  |  |  |         opdata->backup[ob_index].is_dirty = true; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2018-08-22 16:33:39 +10:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-22 16:33:39 +10:00
										 |  |  |     float plane_co_local[3]; | 
					
						
							|  |  |  |     float plane_no_local[3]; | 
					
						
							|  |  |  |     copy_v3_v3(plane_co_local, plane_co); | 
					
						
							|  |  |  |     copy_v3_v3(plane_no_local, plane_no); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-22 16:33:39 +10:00
										 |  |  |     invert_m4_m4(imat, obedit->obmat); | 
					
						
							|  |  |  |     mul_m4_v3(imat, plane_co_local); | 
					
						
							|  |  |  |     mul_transposed_mat3_m4_v3(obedit->obmat, plane_no_local); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-22 16:33:39 +10:00
										 |  |  |     BMOperator bmop; | 
					
						
							|  |  |  |     EDBM_op_init( | 
					
						
							|  |  |  |         em, | 
					
						
							|  |  |  |         &bmop, | 
					
						
							|  |  |  |         op, | 
					
						
							|  |  |  |         "bisect_plane geom=%hvef plane_co=%v plane_no=%v dist=%f clear_inner=%b clear_outer=%b", | 
					
						
							|  |  |  |         BM_ELEM_SELECT, | 
					
						
							|  |  |  |         plane_co_local, | 
					
						
							|  |  |  |         plane_no_local, | 
					
						
							|  |  |  |         thresh, | 
					
						
							|  |  |  |         clear_inner, | 
					
						
							|  |  |  |         clear_outer); | 
					
						
							|  |  |  |     BMO_op_exec(bm, &bmop); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-22 16:33:39 +10:00
										 |  |  |     EDBM_flag_disable_all(em, BM_ELEM_SELECT); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-22 16:33:39 +10:00
										 |  |  |     if (use_fill) { | 
					
						
							|  |  |  |       float normal_fill[3]; | 
					
						
							|  |  |  |       BMOperator bmop_fill; | 
					
						
							|  |  |  |       BMOperator bmop_attr; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-20 19:19:04 +11:00
										 |  |  |       /* The fill normal sign is ignored as the face-winding is defined by surrounding faces.
 | 
					
						
							|  |  |  |        * The normal is passed so triangle fill wont have to calculate it. */ | 
					
						
							| 
									
										
										
										
											2018-08-22 16:33:39 +10:00
										 |  |  |       normalize_v3_v3(normal_fill, plane_no_local); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-22 16:33:39 +10:00
										 |  |  |       /* Fill */ | 
					
						
							|  |  |  |       BMO_op_initf(bm, | 
					
						
							|  |  |  |                    &bmop_fill, | 
					
						
							|  |  |  |                    0, | 
					
						
							|  |  |  |                    "triangle_fill edges=%S normal=%v use_dissolve=%b", | 
					
						
							|  |  |  |                    &bmop, | 
					
						
							|  |  |  |                    "geom_cut.out", | 
					
						
							|  |  |  |                    normal_fill, | 
					
						
							|  |  |  |                    true); | 
					
						
							|  |  |  |       BMO_op_exec(bm, &bmop_fill); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-22 16:33:39 +10:00
										 |  |  |       /* Copy Attributes */ | 
					
						
							|  |  |  |       BMO_op_initf(bm, | 
					
						
							|  |  |  |                    &bmop_attr, | 
					
						
							|  |  |  |                    0, | 
					
						
							|  |  |  |                    "face_attribute_fill faces=%S use_normals=%b use_data=%b", | 
					
						
							|  |  |  |                    &bmop_fill, | 
					
						
							|  |  |  |                    "geom.out", | 
					
						
							| 
									
										
										
										
											2020-01-20 19:19:04 +11:00
										 |  |  |                    true, | 
					
						
							| 
									
										
										
										
											2018-08-22 16:33:39 +10:00
										 |  |  |                    true); | 
					
						
							|  |  |  |       BMO_op_exec(bm, &bmop_attr); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-22 16:33:39 +10:00
										 |  |  |       BMO_slot_buffer_hflag_enable( | 
					
						
							|  |  |  |           bm, bmop_fill.slots_out, "geom.out", BM_FACE, BM_ELEM_SELECT, true); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-22 16:33:39 +10:00
										 |  |  |       BMO_op_finish(bm, &bmop_attr); | 
					
						
							|  |  |  |       BMO_op_finish(bm, &bmop_fill); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-22 16:33:39 +10:00
										 |  |  |     BMO_slot_buffer_hflag_enable( | 
					
						
							|  |  |  |         bm, bmop.slots_out, "geom_cut.out", BM_VERT | BM_EDGE, BM_ELEM_SELECT, true); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-22 16:33:39 +10:00
										 |  |  |     if (EDBM_op_finish(em, &bmop, op, true)) { | 
					
						
							| 
									
										
										
										
											2021-06-14 22:56:01 +10:00
										 |  |  |       EDBM_update(obedit->data, | 
					
						
							|  |  |  |                   &(const struct EDBMUpdate_Params){ | 
					
						
							|  |  |  |                       .calc_looptri = true, | 
					
						
							|  |  |  |                       .calc_normals = false, | 
					
						
							|  |  |  |                       .is_destructive = true, | 
					
						
							|  |  |  |                   }); | 
					
						
							| 
									
										
										
										
											2018-08-22 16:33:39 +10:00
										 |  |  |       EDBM_selectmode_flush(em); | 
					
						
							|  |  |  |       ret = OPERATOR_FINISHED; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2013-08-29 18:45:04 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2018-08-22 16:33:39 +10:00
										 |  |  |   MEM_freeN(objects); | 
					
						
							|  |  |  |   return ret; | 
					
						
							| 
									
										
										
										
											2013-08-29 18:45:04 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-14 23:49:00 +02:00
										 |  |  | #ifdef USE_GIZMO
 | 
					
						
							| 
									
										
										
										
											2018-07-15 14:24:10 +02:00
										 |  |  | static void MESH_GGT_bisect(struct wmGizmoGroupType *gzgt); | 
					
						
							| 
									
										
										
										
											2017-06-16 08:25:24 +10:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2013-08-29 18:45:04 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | void MESH_OT_bisect(struct wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   PropertyRNA *prop; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-29 18:45:04 +00:00
										 |  |  |   /* identifiers */ | 
					
						
							|  |  |  |   ot->name = "Bisect"; | 
					
						
							| 
									
										
										
										
											2013-10-14 08:45:43 +00:00
										 |  |  |   ot->description = "Cut geometry along a plane (click-drag to define plane)"; | 
					
						
							| 
									
										
										
										
											2013-08-29 18:45:04 +00:00
										 |  |  |   ot->idname = "MESH_OT_bisect"; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-29 18:45:04 +00:00
										 |  |  |   /* api callbacks */ | 
					
						
							|  |  |  |   ot->exec = mesh_bisect_exec; | 
					
						
							|  |  |  |   ot->invoke = mesh_bisect_invoke; | 
					
						
							|  |  |  |   ot->modal = mesh_bisect_modal; | 
					
						
							|  |  |  |   ot->cancel = WM_gesture_straightline_cancel; | 
					
						
							|  |  |  |   ot->poll = ED_operator_editmesh; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-29 18:45:04 +00:00
										 |  |  |   /* flags */ | 
					
						
							|  |  |  |   ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-24 17:38:05 +01:00
										 |  |  |   prop = RNA_def_float_vector_xyz(ot->srna, | 
					
						
							|  |  |  |                                   "plane_co", | 
					
						
							|  |  |  |                                   3, | 
					
						
							|  |  |  |                                   NULL, | 
					
						
							|  |  |  |                                   -1e12f, | 
					
						
							|  |  |  |                                   1e12f, | 
					
						
							|  |  |  |                                   "Plane Point", | 
					
						
							|  |  |  |                                   "A point on the plane", | 
					
						
							|  |  |  |                                   -1e4f, | 
					
						
							|  |  |  |                                   1e4f); | 
					
						
							| 
									
										
										
										
											2013-08-29 18:45:04 +00:00
										 |  |  |   RNA_def_property_flag(prop, PROP_SKIP_SAVE); | 
					
						
							| 
									
										
										
										
											2015-06-21 21:56:35 +02:00
										 |  |  |   prop = RNA_def_float_vector(ot->srna, | 
					
						
							|  |  |  |                               "plane_no", | 
					
						
							|  |  |  |                               3, | 
					
						
							|  |  |  |                               NULL, | 
					
						
							|  |  |  |                               -1.0f, | 
					
						
							|  |  |  |                               1.0f, | 
					
						
							|  |  |  |                               "Plane Normal", | 
					
						
							|  |  |  |                               "The direction the plane points", | 
					
						
							|  |  |  |                               -1.0f, | 
					
						
							|  |  |  |                               1.0f); | 
					
						
							| 
									
										
										
										
											2013-08-29 18:45:04 +00:00
										 |  |  |   RNA_def_property_flag(prop, PROP_SKIP_SAVE); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-29 18:45:04 +00:00
										 |  |  |   RNA_def_boolean(ot->srna, "use_fill", false, "Fill", "Fill in the cut"); | 
					
						
							|  |  |  |   RNA_def_boolean( | 
					
						
							|  |  |  |       ot->srna, "clear_inner", false, "Clear Inner", "Remove geometry behind the plane"); | 
					
						
							| 
									
										
										
										
											2013-09-09 20:22:01 +00:00
										 |  |  |   RNA_def_boolean( | 
					
						
							|  |  |  |       ot->srna, "clear_outer", false, "Clear Outer", "Remove geometry in front of the plane"); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-29 17:14:44 +10:00
										 |  |  |   prop = RNA_def_float(ot->srna, | 
					
						
							|  |  |  |                        "threshold", | 
					
						
							|  |  |  |                        0.0001, | 
					
						
							|  |  |  |                        0.0, | 
					
						
							|  |  |  |                        10.0, | 
					
						
							|  |  |  |                        "Axis Threshold", | 
					
						
							|  |  |  |                        "Preserves the existing geometry along the cut plane", | 
					
						
							|  |  |  |                        0.00001, | 
					
						
							|  |  |  |                        0.1); | 
					
						
							|  |  |  |   /* Without higher precision, the default value displays as zero. */ | 
					
						
							|  |  |  |   RNA_def_property_ui_range(prop, 0.0, 10.0, 0.01, 5); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-26 14:31:48 +02:00
										 |  |  |   WM_operator_properties_gesture_straightline(ot, WM_CURSOR_EDIT); | 
					
						
							| 
									
										
										
										
											2017-06-16 08:25:24 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-14 23:49:00 +02:00
										 |  |  | #ifdef USE_GIZMO
 | 
					
						
							| 
									
										
										
										
											2018-07-15 14:24:10 +02:00
										 |  |  |   WM_gizmogrouptype_append(MESH_GGT_bisect); | 
					
						
							| 
									
										
										
										
											2017-06-16 08:25:24 +10:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-14 23:49:00 +02:00
										 |  |  | #ifdef USE_GIZMO
 | 
					
						
							| 
									
										
										
										
											2017-06-16 08:25:24 +10:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* -------------------------------------------------------------------- */ | 
					
						
							| 
									
										
										
										
											2018-07-14 23:49:00 +02:00
										 |  |  | /** \name Bisect Gizmo
 | 
					
						
							| 
									
										
										
										
											2017-06-16 08:25:24 +10:00
										 |  |  |  * \{ */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-14 23:49:00 +02:00
										 |  |  | typedef struct GizmoGroup { | 
					
						
							| 
									
										
										
										
											2017-06-16 08:25:24 +10:00
										 |  |  |   /* Arrow to change plane depth. */ | 
					
						
							| 
									
										
										
										
											2018-07-14 23:49:00 +02:00
										 |  |  |   struct wmGizmo *translate_z; | 
					
						
							| 
									
										
										
										
											2017-06-17 06:13:44 +10:00
										 |  |  |   /* Translate XYZ */ | 
					
						
							| 
									
										
										
										
											2018-07-14 23:49:00 +02:00
										 |  |  |   struct wmGizmo *translate_c; | 
					
						
							|  |  |  |   /* For grabbing the gizmo and moving freely. */ | 
					
						
							|  |  |  |   struct wmGizmo *rotate_c; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-16 08:25:24 +10:00
										 |  |  |   /* We could store more vars here! */ | 
					
						
							|  |  |  |   struct { | 
					
						
							|  |  |  |     bContext *context; | 
					
						
							|  |  |  |     wmOperator *op; | 
					
						
							|  |  |  |     PropertyRNA *prop_plane_co; | 
					
						
							|  |  |  |     PropertyRNA *prop_plane_no; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-16 08:25:24 +10:00
										 |  |  |     float rotate_axis[3]; | 
					
						
							|  |  |  |     float rotate_up[3]; | 
					
						
							|  |  |  |   } data; | 
					
						
							| 
									
										
										
										
											2018-07-14 23:49:00 +02:00
										 |  |  | } GizmoGroup; | 
					
						
							| 
									
										
										
										
											2017-06-16 08:25:24 +10:00
										 |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |  * XXX. calling redo from property updates is not great. | 
					
						
							|  |  |  |  * This is needed because changing the RNA doesn't cause a redo | 
					
						
							|  |  |  |  * and we're not using operator UI which does just this. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2018-09-17 12:47:45 +10:00
										 |  |  | static void gizmo_bisect_exec(GizmoGroup *ggd) | 
					
						
							| 
									
										
										
										
											2017-06-16 08:25:24 +10:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-09-17 12:47:45 +10:00
										 |  |  |   wmOperator *op = ggd->data.op; | 
					
						
							|  |  |  |   if (op == WM_operator_last_redo((bContext *)ggd->data.context)) { | 
					
						
							|  |  |  |     ED_undo_operator_repeat((bContext *)ggd->data.context, op); | 
					
						
							| 
									
										
										
										
											2017-06-16 08:25:24 +10:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2013-08-29 18:45:04 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2017-06-16 08:25:24 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-17 12:47:45 +10:00
										 |  |  | static void gizmo_mesh_bisect_update_from_op(GizmoGroup *ggd) | 
					
						
							| 
									
										
										
										
											2017-06-16 08:25:24 +10:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-09-17 12:47:45 +10:00
										 |  |  |   wmOperator *op = ggd->data.op; | 
					
						
							| 
									
										
										
										
											2017-06-16 08:25:24 +10:00
										 |  |  | 
 | 
					
						
							|  |  |  |   float plane_co[3], plane_no[3]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-17 12:47:45 +10:00
										 |  |  |   RNA_property_float_get_array(op->ptr, ggd->data.prop_plane_co, plane_co); | 
					
						
							|  |  |  |   RNA_property_float_get_array(op->ptr, ggd->data.prop_plane_no, plane_no); | 
					
						
							| 
									
										
										
										
											2017-06-16 08:25:24 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-17 12:47:45 +10:00
										 |  |  |   WM_gizmo_set_matrix_location(ggd->translate_z, plane_co); | 
					
						
							|  |  |  |   WM_gizmo_set_matrix_location(ggd->rotate_c, plane_co); | 
					
						
							| 
									
										
										
										
											2017-08-15 17:13:32 +10:00
										 |  |  |   /* translate_c location comes from the property. */ | 
					
						
							| 
									
										
										
										
											2017-06-16 08:25:24 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-17 12:47:45 +10:00
										 |  |  |   WM_gizmo_set_matrix_rotation_from_z_axis(ggd->translate_z, plane_no); | 
					
						
							| 
									
										
										
										
											2017-06-16 08:25:24 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-17 12:47:45 +10:00
										 |  |  |   WM_gizmo_set_scale(ggd->translate_c, 0.2); | 
					
						
							| 
									
										
										
										
											2017-06-17 06:13:44 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-17 12:47:45 +10:00
										 |  |  |   RegionView3D *rv3d = ED_view3d_context_rv3d(ggd->data.context); | 
					
						
							| 
									
										
										
										
											2017-06-16 08:25:24 +10:00
										 |  |  |   if (rv3d) { | 
					
						
							| 
									
										
										
										
											2018-09-17 12:47:45 +10:00
										 |  |  |     normalize_v3_v3(ggd->data.rotate_axis, rv3d->viewinv[2]); | 
					
						
							|  |  |  |     normalize_v3_v3(ggd->data.rotate_up, rv3d->viewinv[1]); | 
					
						
							| 
									
										
										
										
											2017-06-16 08:25:24 +10:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /* ensure its orthogonal */ | 
					
						
							| 
									
										
										
										
											2018-09-17 12:47:45 +10:00
										 |  |  |     project_plane_normalized_v3_v3v3( | 
					
						
							|  |  |  |         ggd->data.rotate_up, ggd->data.rotate_up, ggd->data.rotate_axis); | 
					
						
							|  |  |  |     normalize_v3(ggd->data.rotate_up); | 
					
						
							| 
									
										
										
										
											2017-06-16 08:25:24 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-17 12:47:45 +10:00
										 |  |  |     WM_gizmo_set_matrix_rotation_from_z_axis(ggd->translate_c, plane_no); | 
					
						
							| 
									
										
										
										
											2017-06-17 15:32:47 +10:00
										 |  |  | 
 | 
					
						
							|  |  |  |     float plane_no_cross[3]; | 
					
						
							| 
									
										
										
										
											2018-09-17 12:47:45 +10:00
										 |  |  |     cross_v3_v3v3(plane_no_cross, plane_no, ggd->data.rotate_axis); | 
					
						
							| 
									
										
										
										
											2017-06-17 15:32:47 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-17 12:47:45 +10:00
										 |  |  |     WM_gizmo_set_matrix_offset_rotation_from_yz_axis( | 
					
						
							|  |  |  |         ggd->rotate_c, plane_no_cross, ggd->data.rotate_axis); | 
					
						
							|  |  |  |     RNA_enum_set(ggd->rotate_c->ptr, | 
					
						
							|  |  |  |                  "draw_options", | 
					
						
							| 
									
										
										
										
											2018-07-14 23:49:00 +02:00
										 |  |  |                  ED_GIZMO_DIAL_DRAW_FLAG_ANGLE_MIRROR | ED_GIZMO_DIAL_DRAW_FLAG_ANGLE_START_Y); | 
					
						
							| 
									
										
										
										
											2017-06-16 08:25:24 +10:00
										 |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* depth callbacks */ | 
					
						
							| 
									
										
										
										
											2018-07-15 14:24:10 +02:00
										 |  |  | static void gizmo_bisect_prop_depth_get(const wmGizmo *gz, wmGizmoProperty *gz_prop, void *value_p) | 
					
						
							| 
									
										
										
										
											2017-06-16 08:25:24 +10:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-09-17 12:47:45 +10:00
										 |  |  |   GizmoGroup *ggd = gz->parent_gzgroup->customdata; | 
					
						
							|  |  |  |   wmOperator *op = ggd->data.op; | 
					
						
							| 
									
										
										
										
											2017-06-26 14:31:26 +10:00
										 |  |  |   float *value = value_p; | 
					
						
							| 
									
										
										
										
											2017-06-16 08:25:24 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-15 14:24:10 +02:00
										 |  |  |   BLI_assert(gz_prop->type->array_length == 1); | 
					
						
							|  |  |  |   UNUSED_VARS_NDEBUG(gz_prop); | 
					
						
							| 
									
										
										
										
											2017-06-16 08:25:24 +10:00
										 |  |  | 
 | 
					
						
							|  |  |  |   float plane_co[3], plane_no[3]; | 
					
						
							| 
									
										
										
										
											2018-09-17 12:47:45 +10:00
										 |  |  |   RNA_property_float_get_array(op->ptr, ggd->data.prop_plane_co, plane_co); | 
					
						
							|  |  |  |   RNA_property_float_get_array(op->ptr, ggd->data.prop_plane_no, plane_no); | 
					
						
							| 
									
										
										
										
											2017-06-16 08:25:24 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-15 14:24:10 +02:00
										 |  |  |   value[0] = dot_v3v3(plane_no, plane_co) - dot_v3v3(plane_no, gz->matrix_basis[3]); | 
					
						
							| 
									
										
										
										
											2017-06-16 08:25:24 +10:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-14 23:49:00 +02:00
										 |  |  | static void gizmo_bisect_prop_depth_set(const wmGizmo *gz, | 
					
						
							| 
									
										
										
										
											2018-07-15 14:24:10 +02:00
										 |  |  |                                         wmGizmoProperty *gz_prop, | 
					
						
							| 
									
										
										
										
											2017-06-26 14:31:26 +10:00
										 |  |  |                                         const void *value_p) | 
					
						
							| 
									
										
										
										
											2017-06-16 08:25:24 +10:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-09-17 12:47:45 +10:00
										 |  |  |   GizmoGroup *ggd = gz->parent_gzgroup->customdata; | 
					
						
							|  |  |  |   wmOperator *op = ggd->data.op; | 
					
						
							| 
									
										
										
										
											2017-06-26 14:31:26 +10:00
										 |  |  |   const float *value = value_p; | 
					
						
							| 
									
										
										
										
											2017-06-16 08:25:24 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-15 14:24:10 +02:00
										 |  |  |   BLI_assert(gz_prop->type->array_length == 1); | 
					
						
							|  |  |  |   UNUSED_VARS_NDEBUG(gz_prop); | 
					
						
							| 
									
										
										
										
											2017-06-16 08:25:24 +10:00
										 |  |  | 
 | 
					
						
							|  |  |  |   float plane_co[3], plane[4]; | 
					
						
							| 
									
										
										
										
											2018-09-17 12:47:45 +10:00
										 |  |  |   RNA_property_float_get_array(op->ptr, ggd->data.prop_plane_co, plane_co); | 
					
						
							|  |  |  |   RNA_property_float_get_array(op->ptr, ggd->data.prop_plane_no, plane); | 
					
						
							| 
									
										
										
										
											2017-06-16 08:25:24 +10:00
										 |  |  |   normalize_v3(plane); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-15 14:24:10 +02:00
										 |  |  |   plane[3] = -value[0] - dot_v3v3(plane, gz->matrix_basis[3]); | 
					
						
							| 
									
										
										
										
											2017-06-16 08:25:24 +10:00
										 |  |  | 
 | 
					
						
							|  |  |  |   /* Keep our location, may be offset simply to be inside the viewport. */ | 
					
						
							|  |  |  |   closest_to_plane_normalized_v3(plane_co, plane, plane_co); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-17 12:47:45 +10:00
										 |  |  |   RNA_property_float_set_array(op->ptr, ggd->data.prop_plane_co, plane_co); | 
					
						
							| 
									
										
										
										
											2017-06-16 08:25:24 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-17 12:47:45 +10:00
										 |  |  |   gizmo_bisect_exec(ggd); | 
					
						
							| 
									
										
										
										
											2017-06-16 08:25:24 +10:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-17 06:13:44 +10:00
										 |  |  | /* translate callbacks */ | 
					
						
							| 
									
										
										
										
											2018-07-14 23:49:00 +02:00
										 |  |  | static void gizmo_bisect_prop_translate_get(const wmGizmo *gz, | 
					
						
							| 
									
										
										
										
											2018-07-15 14:24:10 +02:00
										 |  |  |                                             wmGizmoProperty *gz_prop, | 
					
						
							| 
									
										
										
										
											2017-06-26 14:31:26 +10:00
										 |  |  |                                             void *value_p) | 
					
						
							| 
									
										
										
										
											2017-06-17 06:13:44 +10:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-09-17 12:47:45 +10:00
										 |  |  |   GizmoGroup *ggd = gz->parent_gzgroup->customdata; | 
					
						
							|  |  |  |   wmOperator *op = ggd->data.op; | 
					
						
							| 
									
										
										
										
											2017-06-17 06:13:44 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-15 14:24:10 +02:00
										 |  |  |   BLI_assert(gz_prop->type->array_length == 3); | 
					
						
							|  |  |  |   UNUSED_VARS_NDEBUG(gz_prop); | 
					
						
							| 
									
										
										
										
											2017-06-22 18:29:45 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-17 12:47:45 +10:00
										 |  |  |   RNA_property_float_get_array(op->ptr, ggd->data.prop_plane_co, value_p); | 
					
						
							| 
									
										
										
										
											2017-06-17 06:13:44 +10:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-14 23:49:00 +02:00
										 |  |  | static void gizmo_bisect_prop_translate_set(const wmGizmo *gz, | 
					
						
							| 
									
										
										
										
											2018-07-15 14:24:10 +02:00
										 |  |  |                                             wmGizmoProperty *gz_prop, | 
					
						
							| 
									
										
										
										
											2017-06-26 14:31:26 +10:00
										 |  |  |                                             const void *value_p) | 
					
						
							| 
									
										
										
										
											2017-06-17 06:13:44 +10:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-09-17 12:47:45 +10:00
										 |  |  |   GizmoGroup *ggd = gz->parent_gzgroup->customdata; | 
					
						
							|  |  |  |   wmOperator *op = ggd->data.op; | 
					
						
							| 
									
										
										
										
											2017-06-17 06:13:44 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-15 14:24:10 +02:00
										 |  |  |   BLI_assert(gz_prop->type->array_length == 3); | 
					
						
							|  |  |  |   UNUSED_VARS_NDEBUG(gz_prop); | 
					
						
							| 
									
										
										
										
											2017-06-22 18:29:45 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-17 12:47:45 +10:00
										 |  |  |   RNA_property_float_set_array(op->ptr, ggd->data.prop_plane_co, value_p); | 
					
						
							| 
									
										
										
										
											2017-06-17 06:13:44 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-17 12:47:45 +10:00
										 |  |  |   gizmo_bisect_exec(ggd); | 
					
						
							| 
									
										
										
										
											2017-06-17 06:13:44 +10:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-16 08:25:24 +10:00
										 |  |  | /* angle callbacks */ | 
					
						
							| 
									
										
										
										
											2018-07-15 14:24:10 +02:00
										 |  |  | static void gizmo_bisect_prop_angle_get(const wmGizmo *gz, wmGizmoProperty *gz_prop, void *value_p) | 
					
						
							| 
									
										
										
										
											2017-06-16 08:25:24 +10:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-09-17 12:47:45 +10:00
										 |  |  |   GizmoGroup *ggd = gz->parent_gzgroup->customdata; | 
					
						
							|  |  |  |   wmOperator *op = ggd->data.op; | 
					
						
							| 
									
										
										
										
											2017-06-26 14:31:26 +10:00
										 |  |  |   float *value = value_p; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-15 14:24:10 +02:00
										 |  |  |   BLI_assert(gz_prop->type->array_length == 1); | 
					
						
							|  |  |  |   UNUSED_VARS_NDEBUG(gz_prop); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-16 08:25:24 +10:00
										 |  |  |   float plane_no[4]; | 
					
						
							| 
									
										
										
										
											2018-09-17 12:47:45 +10:00
										 |  |  |   RNA_property_float_get_array(op->ptr, ggd->data.prop_plane_no, plane_no); | 
					
						
							| 
									
										
										
										
											2017-06-16 08:25:24 +10:00
										 |  |  |   normalize_v3(plane_no); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-16 08:25:24 +10:00
										 |  |  |   float plane_no_proj[3]; | 
					
						
							| 
									
										
										
										
											2018-09-17 12:47:45 +10:00
										 |  |  |   project_plane_normalized_v3_v3v3(plane_no_proj, plane_no, ggd->data.rotate_axis); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-16 08:25:24 +10:00
										 |  |  |   if (!is_zero_v3(plane_no_proj)) { | 
					
						
							| 
									
										
										
										
											2018-09-17 12:47:45 +10:00
										 |  |  |     const float angle = -angle_signed_on_axis_v3v3_v3( | 
					
						
							|  |  |  |         plane_no_proj, ggd->data.rotate_up, ggd->data.rotate_axis); | 
					
						
							| 
									
										
										
										
											2017-06-16 08:25:24 +10:00
										 |  |  |     value[0] = angle; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   else { | 
					
						
							|  |  |  |     value[0] = 0.0f; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-14 23:49:00 +02:00
										 |  |  | static void gizmo_bisect_prop_angle_set(const wmGizmo *gz, | 
					
						
							| 
									
										
										
										
											2018-07-15 14:24:10 +02:00
										 |  |  |                                         wmGizmoProperty *gz_prop, | 
					
						
							| 
									
										
										
										
											2017-06-26 14:31:26 +10:00
										 |  |  |                                         const void *value_p) | 
					
						
							| 
									
										
										
										
											2017-06-16 08:25:24 +10:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-09-17 12:47:45 +10:00
										 |  |  |   GizmoGroup *ggd = gz->parent_gzgroup->customdata; | 
					
						
							|  |  |  |   wmOperator *op = ggd->data.op; | 
					
						
							| 
									
										
										
										
											2017-06-26 14:31:26 +10:00
										 |  |  |   const float *value = value_p; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-15 14:24:10 +02:00
										 |  |  |   BLI_assert(gz_prop->type->array_length == 1); | 
					
						
							|  |  |  |   UNUSED_VARS_NDEBUG(gz_prop); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-16 08:25:24 +10:00
										 |  |  |   float plane_no[4]; | 
					
						
							| 
									
										
										
										
											2018-09-17 12:47:45 +10:00
										 |  |  |   RNA_property_float_get_array(op->ptr, ggd->data.prop_plane_no, plane_no); | 
					
						
							| 
									
										
										
										
											2017-06-16 08:25:24 +10:00
										 |  |  |   normalize_v3(plane_no); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-16 08:25:24 +10:00
										 |  |  |   float plane_no_proj[3]; | 
					
						
							| 
									
										
										
										
											2018-09-17 12:47:45 +10:00
										 |  |  |   project_plane_normalized_v3_v3v3(plane_no_proj, plane_no, ggd->data.rotate_axis); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-16 08:25:24 +10:00
										 |  |  |   if (!is_zero_v3(plane_no_proj)) { | 
					
						
							| 
									
										
										
										
											2018-09-17 12:47:45 +10:00
										 |  |  |     const float angle = -angle_signed_on_axis_v3v3_v3( | 
					
						
							|  |  |  |         plane_no_proj, ggd->data.rotate_up, ggd->data.rotate_axis); | 
					
						
							| 
									
										
										
										
											2017-06-16 08:25:24 +10:00
										 |  |  |     const float angle_delta = angle - angle_compat_rad(value[0], angle); | 
					
						
							|  |  |  |     if (angle_delta != 0.0f) { | 
					
						
							|  |  |  |       float mat[3][3]; | 
					
						
							| 
									
										
										
										
											2018-09-17 12:47:45 +10:00
										 |  |  |       axis_angle_normalized_to_mat3(mat, ggd->data.rotate_axis, angle_delta); | 
					
						
							| 
									
										
										
										
											2017-06-16 08:25:24 +10:00
										 |  |  |       mul_m3_v3(mat, plane_no); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-16 08:25:24 +10:00
										 |  |  |       /* re-normalize - seems acceptable */ | 
					
						
							| 
									
										
										
										
											2018-09-17 12:47:45 +10:00
										 |  |  |       RNA_property_float_set_array(op->ptr, ggd->data.prop_plane_no, plane_no); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-17 12:47:45 +10:00
										 |  |  |       gizmo_bisect_exec(ggd); | 
					
						
							| 
									
										
										
										
											2017-06-16 08:25:24 +10:00
										 |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-15 14:24:10 +02:00
										 |  |  | static bool gizmo_mesh_bisect_poll(const bContext *C, wmGizmoGroupType *gzgt) | 
					
						
							| 
									
										
										
										
											2017-06-16 08:25:24 +10:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-09-18 16:10:07 +10:00
										 |  |  |   return ED_gizmo_poll_or_unlink_delayed_from_operator(C, gzgt, "MESH_OT_bisect"); | 
					
						
							| 
									
										
										
										
											2017-06-16 08:25:24 +10:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-15 14:24:10 +02:00
										 |  |  | static void gizmo_mesh_bisect_setup(const bContext *C, wmGizmoGroup *gzgroup) | 
					
						
							| 
									
										
										
										
											2017-06-16 08:25:24 +10:00
										 |  |  | { | 
					
						
							|  |  |  |   wmOperator *op = WM_operator_last_redo(C); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-16 08:25:24 +10:00
										 |  |  |   if (op == NULL || !STREQ(op->type->idname, "MESH_OT_bisect")) { | 
					
						
							|  |  |  |     return; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-17 12:47:45 +10:00
										 |  |  |   struct GizmoGroup *ggd = MEM_callocN(sizeof(GizmoGroup), __func__); | 
					
						
							|  |  |  |   gzgroup->customdata = ggd; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-15 14:24:10 +02:00
										 |  |  |   const wmGizmoType *gzt_arrow = WM_gizmotype_find("GIZMO_GT_arrow_3d", true); | 
					
						
							| 
									
										
										
										
											2018-09-06 12:13:01 +02:00
										 |  |  |   const wmGizmoType *gzt_move = WM_gizmotype_find("GIZMO_GT_move_3d", true); | 
					
						
							| 
									
										
										
										
											2018-07-15 14:24:10 +02:00
										 |  |  |   const wmGizmoType *gzt_dial = WM_gizmotype_find("GIZMO_GT_dial_3d", true); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-17 12:47:45 +10:00
										 |  |  |   ggd->translate_z = WM_gizmo_new_ptr(gzt_arrow, gzgroup, NULL); | 
					
						
							|  |  |  |   ggd->translate_c = WM_gizmo_new_ptr(gzt_move, gzgroup, NULL); | 
					
						
							|  |  |  |   ggd->rotate_c = WM_gizmo_new_ptr(gzt_dial, gzgroup, NULL); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-17 12:47:45 +10:00
										 |  |  |   UI_GetThemeColor3fv(TH_GIZMO_PRIMARY, ggd->translate_z->color); | 
					
						
							|  |  |  |   UI_GetThemeColor3fv(TH_GIZMO_PRIMARY, ggd->translate_c->color); | 
					
						
							|  |  |  |   UI_GetThemeColor3fv(TH_GIZMO_SECONDARY, ggd->rotate_c->color); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-17 12:47:45 +10:00
										 |  |  |   RNA_enum_set(ggd->translate_z->ptr, "draw_style", ED_GIZMO_ARROW_STYLE_NORMAL); | 
					
						
							|  |  |  |   RNA_enum_set(ggd->translate_c->ptr, "draw_style", ED_GIZMO_MOVE_STYLE_RING_2D); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-17 12:47:45 +10:00
										 |  |  |   WM_gizmo_set_flag(ggd->translate_c, WM_GIZMO_DRAW_VALUE, true); | 
					
						
							|  |  |  |   WM_gizmo_set_flag(ggd->rotate_c, WM_GIZMO_DRAW_VALUE, true); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-16 08:25:24 +10:00
										 |  |  |   { | 
					
						
							| 
									
										
										
										
											2018-09-17 12:47:45 +10:00
										 |  |  |     ggd->data.context = (bContext *)C; | 
					
						
							|  |  |  |     ggd->data.op = op; | 
					
						
							|  |  |  |     ggd->data.prop_plane_co = RNA_struct_find_property(op->ptr, "plane_co"); | 
					
						
							|  |  |  |     ggd->data.prop_plane_no = RNA_struct_find_property(op->ptr, "plane_no"); | 
					
						
							| 
									
										
										
										
											2017-06-16 08:25:24 +10:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-17 12:47:45 +10:00
										 |  |  |   gizmo_mesh_bisect_update_from_op(ggd); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-16 08:25:24 +10:00
										 |  |  |   /* Setup property callbacks */ | 
					
						
							|  |  |  |   { | 
					
						
							| 
									
										
										
										
											2018-07-14 23:49:00 +02:00
										 |  |  |     WM_gizmo_target_property_def_func(ggd->translate_z, | 
					
						
							| 
									
										
										
										
											2018-09-17 12:47:45 +10:00
										 |  |  |                                       "offset", | 
					
						
							| 
									
										
										
										
											2018-07-14 23:49:00 +02:00
										 |  |  |                                       &(const struct wmGizmoPropertyFnParams){ | 
					
						
							|  |  |  |                                           .value_get_fn = gizmo_bisect_prop_depth_get, | 
					
						
							|  |  |  |                                           .value_set_fn = gizmo_bisect_prop_depth_set, | 
					
						
							| 
									
										
										
										
											2017-06-16 08:25:24 +10:00
										 |  |  |                                           .range_get_fn = NULL, | 
					
						
							|  |  |  |                                           .user_data = NULL, | 
					
						
							| 
									
										
										
										
											2017-06-17 06:13:44 +10:00
										 |  |  |                                       }); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-14 23:49:00 +02:00
										 |  |  |     WM_gizmo_target_property_def_func(ggd->translate_c, | 
					
						
							| 
									
										
										
										
											2018-09-17 12:47:45 +10:00
										 |  |  |                                       "offset", | 
					
						
							| 
									
										
										
										
											2018-07-14 23:49:00 +02:00
										 |  |  |                                       &(const struct wmGizmoPropertyFnParams){ | 
					
						
							|  |  |  |                                           .value_get_fn = gizmo_bisect_prop_translate_get, | 
					
						
							|  |  |  |                                           .value_set_fn = gizmo_bisect_prop_translate_set, | 
					
						
							| 
									
										
										
										
											2017-06-17 06:13:44 +10:00
										 |  |  |                                           .range_get_fn = NULL, | 
					
						
							|  |  |  |                                           .user_data = NULL, | 
					
						
							| 
									
										
										
										
											2017-06-16 08:25:24 +10:00
										 |  |  |                                       }); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-14 23:49:00 +02:00
										 |  |  |     WM_gizmo_target_property_def_func(ggd->rotate_c, | 
					
						
							| 
									
										
										
										
											2018-09-17 12:47:45 +10:00
										 |  |  |                                       "offset", | 
					
						
							| 
									
										
										
										
											2018-07-14 23:49:00 +02:00
										 |  |  |                                       &(const struct wmGizmoPropertyFnParams){ | 
					
						
							|  |  |  |                                           .value_get_fn = gizmo_bisect_prop_angle_get, | 
					
						
							|  |  |  |                                           .value_set_fn = gizmo_bisect_prop_angle_set, | 
					
						
							| 
									
										
										
										
											2017-06-16 08:25:24 +10:00
										 |  |  |                                           .range_get_fn = NULL, | 
					
						
							|  |  |  |                                           .user_data = NULL, | 
					
						
							|  |  |  |                                       }); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-15 14:24:10 +02:00
										 |  |  | static void gizmo_mesh_bisect_draw_prepare(const bContext *UNUSED(C), wmGizmoGroup *gzgroup) | 
					
						
							| 
									
										
										
										
											2017-06-16 08:25:24 +10:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-09-17 12:47:45 +10:00
										 |  |  |   GizmoGroup *ggd = gzgroup->customdata; | 
					
						
							|  |  |  |   if (ggd->data.op->next) { | 
					
						
							|  |  |  |     ggd->data.op = WM_operator_last_redo((bContext *)ggd->data.context); | 
					
						
							| 
									
										
										
										
											2017-10-19 22:44:51 +11:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2018-09-17 12:47:45 +10:00
										 |  |  |   gizmo_mesh_bisect_update_from_op(ggd); | 
					
						
							| 
									
										
										
										
											2017-06-16 08:25:24 +10:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-15 14:24:10 +02:00
										 |  |  | static void MESH_GGT_bisect(struct wmGizmoGroupType *gzgt) | 
					
						
							| 
									
										
										
										
											2017-06-16 08:25:24 +10:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-07-15 14:24:10 +02:00
										 |  |  |   gzgt->name = "Mesh Bisect"; | 
					
						
							|  |  |  |   gzgt->idname = "MESH_GGT_bisect"; | 
					
						
							| 
									
										
										
										
											2017-06-16 08:25:24 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-15 14:24:10 +02:00
										 |  |  |   gzgt->flag = WM_GIZMOGROUPTYPE_3D; | 
					
						
							| 
									
										
										
										
											2017-06-16 08:25:24 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-15 14:24:10 +02:00
										 |  |  |   gzgt->gzmap_params.spaceid = SPACE_VIEW3D; | 
					
						
							|  |  |  |   gzgt->gzmap_params.regionid = RGN_TYPE_WINDOW; | 
					
						
							| 
									
										
										
										
											2017-06-16 08:25:24 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-15 14:24:10 +02:00
										 |  |  |   gzgt->poll = gizmo_mesh_bisect_poll; | 
					
						
							|  |  |  |   gzgt->setup = gizmo_mesh_bisect_setup; | 
					
						
							|  |  |  |   gzgt->draw_prepare = gizmo_mesh_bisect_draw_prepare; | 
					
						
							| 
									
										
										
										
											2017-06-16 08:25:24 +10:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** \} */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-14 23:49:00 +02:00
										 |  |  | #endif /* USE_GIZMO */
 |