[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [55318] trunk/blender/source/blender/ editors/mesh/editmesh_knife.c: knife project improvements
Campbell Barton
ideasman42 at gmail.com
Fri Mar 15 21:39:56 CET 2013
Revision: 55318
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=55318
Author: campbellbarton
Date: 2013-03-15 20:39:56 +0000 (Fri, 15 Mar 2013)
Log Message:
-----------
knife project improvements
When running in non-interactive mode, dont add a area draw callback or adjust the cursor, use a fixed snap value and don't use opengl lookups on faces.
Minor optimization - compare squared distances where possible.
Modified Paths:
--------------
trunk/blender/source/blender/editors/mesh/editmesh_knife.c
Modified: trunk/blender/source/blender/editors/mesh/editmesh_knife.c
===================================================================
--- trunk/blender/source/blender/editors/mesh/editmesh_knife.c 2013-03-15 20:16:20 UTC (rev 55317)
+++ trunk/blender/source/blender/editors/mesh/editmesh_knife.c 2013-03-15 20:39:56 UTC (rev 55318)
@@ -176,6 +176,9 @@
KnifeColors colors;
+ /* run by the UI or not */
+ bool is_interactive;
+
/* operatpr options */
bool cut_through; /* preference, can be modified at runtime (that feature may go) */
bool only_select; /* set on initialization */
@@ -194,7 +197,8 @@
int prevmode;
bool snap_midpoints, extend;
- bool ignore_edge_snapping, ignore_vert_snapping;
+ bool ignore_edge_snapping;
+ bool ignore_vert_snapping;
enum {
ANGLE_FREE,
@@ -1385,7 +1389,7 @@
knife_project_v3(kcd, v1, s1);
knife_project_v3(kcd, v2, s2);
- if (len_v2v2(s1, s2) < 1)
+ if (len_squared_v2v2(s1, s2) < 1)
return;
/* unproject screen line */
@@ -1503,13 +1507,15 @@
*is_space = !f;
if (!f) {
- /* try to use backbuffer selection method if ray casting failed */
- f = EDBM_face_find_nearest(&kcd->vc, &dist);
+ if (kcd->is_interactive) {
+ /* try to use backbuffer selection method if ray casting failed */
+ f = EDBM_face_find_nearest(&kcd->vc, &dist);
- /* cheat for now; just put in the origin instead
- * of a true coordinate on the face.
- * This just puts a point 1.0f infront of the view. */
- add_v3_v3v3(co, origin, ray);
+ /* cheat for now; just put in the origin instead
+ * of a true coordinate on the face.
+ * This just puts a point 1.0f infront of the view. */
+ add_v3_v3v3(co, origin, ray);
+ }
}
return f;
@@ -1517,18 +1523,21 @@
/* find the 2d screen space density of vertices within a radius. used to scale snapping
* distance for picking edges/verts.*/
-static int knife_sample_screen_density(KnifeTool_OpData *kcd, float radius)
+static int knife_sample_screen_density(KnifeTool_OpData *kcd, const float radius)
{
BMFace *f;
bool is_space;
float co[3], cageco[3], sco[3];
+ BLI_assert(kcd->is_interactive == true);
+
f = knife_find_closest_face(kcd, co, cageco, &is_space);
if (f && !is_space) {
+ const float radius_squared = radius * radius;
ListBase *lst;
Ref *ref;
- float dis;
+ float dis_squared;
int c = 0;
knife_project_v3(kcd, cageco, sco);
@@ -1543,8 +1552,8 @@
knife_project_v3(kcd, kfv->cageco, kfv->sco);
- dis = len_v2v2(kfv->sco, sco);
- if (dis < radius) {
+ dis_squared = len_v2v2(kfv->sco, sco);
+ if (dis_squared < radius_squared) {
if (kcd->vc.rv3d->rflag & RV3D_CLIPPING) {
if (ED_view3d_clipping_test(kcd->vc.rv3d, kfv->cageco, TRUE) == 0) {
c++;
@@ -1567,8 +1576,15 @@
* surrounding mesh (in screen space)*/
static float knife_snap_size(KnifeTool_OpData *kcd, float maxsize)
{
- float density = (float)knife_sample_screen_density(kcd, maxsize * 2.0f);
+ float density;
+ if (kcd->is_interactive) {
+ density = (float)knife_sample_screen_density(kcd, maxsize * 2.0f);
+ }
+ else {
+ density = 1.0f;
+ }
+
if (density < 1.0f)
density = 1.0f;
@@ -2888,10 +2904,12 @@
if (!kcd)
return;
- WM_cursor_restore(CTX_wm_window(C));
+ if (kcd->is_interactive) {
+ WM_cursor_restore(CTX_wm_window(C));
- /* deactivate the extra drawing stuff in 3D-View */
- ED_region_draw_cb_exit(kcd->ar->type, kcd->draw_handle);
+ /* deactivate the extra drawing stuff in 3D-View */
+ ED_region_draw_cb_exit(kcd->ar->type, kcd->draw_handle);
+ }
/* free the custom data */
BLI_mempool_destroy(kcd->refs);
@@ -2956,7 +2974,7 @@
/* called when modal loop selection gets set up... */
static void knifetool_init(bContext *C, KnifeTool_OpData *kcd,
- const bool only_select, const bool cut_through)
+ const bool only_select, const bool cut_through, const bool is_interactive)
{
Scene *scene = CTX_data_scene(C);
Object *obedit = CTX_data_edit_object(C);
@@ -2967,7 +2985,7 @@
/* assign the drawing handle for drawing preview line... */
kcd->ob = obedit;
kcd->ar = CTX_wm_region(C);
- kcd->draw_handle = ED_region_draw_cb_activate(kcd->ar->type, knifetool_draw, kcd, REGION_DRAW_POST_VIEW);
+
em_setup_viewcontext(C, &kcd->vc);
kcd->em = BMEdit_FromObject(kcd->ob);
@@ -3008,6 +3026,7 @@
kcd->kedgefacemap = BLI_ghash_ptr_new("knife origvertmap");
/* cut all the way through the mesh if use_occlude_geometry button not pushed */
+ kcd->is_interactive = is_interactive;
kcd->cut_through = cut_through;
kcd->only_select = only_select;
@@ -3017,7 +3036,11 @@
knife_pos_data_clear(&kcd->curr);
knife_pos_data_clear(&kcd->prev);
- knife_init_colors(&kcd->colors);
+ if (is_interactive) {
+ kcd->draw_handle = ED_region_draw_cb_activate(kcd->ar->type, knifetool_draw, kcd, REGION_DRAW_POST_VIEW);
+
+ knife_init_colors(&kcd->colors);
+ }
}
static int knifetool_cancel(bContext *C, wmOperator *op)
@@ -3039,7 +3062,7 @@
/* alloc new customdata */
kcd = op->customdata = MEM_callocN(sizeof(KnifeTool_OpData), __func__);
- knifetool_init(C, kcd, only_select, cut_through);
+ knifetool_init(C, kcd, only_select, cut_through, true);
/* add a modal handler for this operator - handles loop selection */
WM_cursor_modal(CTX_wm_window(C), BC_KNIFECURSOR);
@@ -3360,10 +3383,11 @@
{
const bool only_select = false;
const bool cut_through = false;
+ const bool is_interactive = false; /* can enable for testing */
kcd = MEM_callocN(sizeof(KnifeTool_OpData), __func__);
- knifetool_init(C, kcd, only_select, cut_through);
+ knifetool_init(C, kcd, only_select, cut_through, is_interactive);
kcd->ignore_edge_snapping = true;
kcd->ignore_vert_snapping = true;
More information about the Bf-blender-cvs
mailing list