[Bf-blender-cvs] [1f22ef34bbb] blender2.8: Merge branch 'master' into blender2.8

Campbell Barton noreply at git.blender.org
Thu Sep 6 06:35:20 CEST 2018


Commit: 1f22ef34bbb13e17dd5e4f4c573bdcccc146fb3a
Author: Campbell Barton
Date:   Thu Sep 6 14:42:59 2018 +1000
Branches: blender2.8
https://developer.blender.org/rB1f22ef34bbb13e17dd5e4f4c573bdcccc146fb3a

Merge branch 'master' into blender2.8

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



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

diff --cc source/blender/editors/space_view3d/view3d_gizmo_ruler.c
index 1fe9a2b1632,00000000000..d7a605eca5e
mode 100644,000000..100644
--- a/source/blender/editors/space_view3d/view3d_gizmo_ruler.c
+++ b/source/blender/editors/space_view3d/view3d_gizmo_ruler.c
@@@ -1,1093 -1,0 +1,1093 @@@
 +/*
 + * ***** BEGIN GPL LICENSE BLOCK *****
 + *
 + * 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.
 + *
 + * ***** END GPL LICENSE BLOCK *****
 + */
 +
 +/** \file blender/editors/space_view3d/view3d_gizmo_ruler.c
 + *  \ingroup spview3d
 + */
 +
 +#include "BLI_listbase.h"
 +#include "BLI_string.h"
 +#include "BLI_rect.h"
 +#include "BLI_math.h"
 +#include "BLI_utildefines.h"
 +
 +#include "BLT_translation.h"
 +
 +#include "BKE_context.h"
 +#include "BKE_gpencil.h"
 +#include "BKE_main.h"
 +
 +#include "BKE_object.h"
 +#include "BKE_unit.h"
 +#include "BKE_material.h"
 +
 +#include "DNA_meshdata_types.h"
 +#include "DNA_object_types.h"
 +#include "DNA_gpencil_types.h"
 +#include "DNA_view3d_types.h"
 +
 +#include "BIF_gl.h"
 +
 +#include "ED_gpencil.h"
 +#include "ED_screen.h"
 +#include "ED_transform_snap_object_context.h"
 +#include "ED_view3d.h"
 +
 +#include "UI_resources.h"
 +#include "UI_interface.h"
 +
 +#include "MEM_guardedalloc.h"
 +
 +#include "RNA_access.h"
 +
 +#include "WM_api.h"
 +#include "WM_types.h"
 +#include "WM_toolsystem.h"
 +
 +#include "view3d_intern.h"  /* own include */
 +
 +#include "GPU_immediate.h"
 +#include "GPU_immediate_util.h"
 +#include "GPU_select.h"
 +#include "GPU_state.h"
 +
 +#include "BLF_api.h"
 +
 +
 +static const char *view3d_gzgt_ruler_id = "VIEW3D_GGT_ruler";
 +
 +
 +#define MVAL_MAX_PX_DIST 12.0f
 +
 +/* -------------------------------------------------------------------- */
 +/* Ruler Item (we can have many) */
 +enum {
 +	RULERITEM_USE_ANGLE = (1 << 0),  /* use protractor */
 +	RULERITEM_USE_RAYCAST = (1 << 1)
 +};
 +
 +enum {
 +	RULERITEM_DIRECTION_IN = 0,
 +	RULERITEM_DIRECTION_OUT
 +};
 +
 +/* keep smaller then selection, since we may want click elsewhere without selecting a ruler */
 +#define RULER_PICK_DIST 12.0f
 +#define RULER_PICK_DIST_SQ (RULER_PICK_DIST * RULER_PICK_DIST)
 +
 +/* not clicking on a point */
 +#define PART_LINE 0xff
 +
 +/* -------------------------------------------------------------------- */
 +/* Ruler Info (wmGizmoGroup customdata) */
 +
 +enum {
 +	RULER_STATE_NORMAL = 0,
 +	RULER_STATE_DRAG
 +};
 +
 +enum {
 +	RULER_SNAP_OK = (1 << 0),
 +};
 +
 +typedef struct RulerInfo {
 +	// ListBase items;
 +	int      item_active;
 +	int flag;
 +	int snap_flag;
 +	int state;
 +
 +	struct SnapObjectContext *snap_context;
 +
 +	/* wm state */
 +	wmWindow *win;
 +	ScrArea *sa;
 +	ARegion *ar;  /* re-assigned every modal update */
 +} RulerInfo;
 +
 +/* -------------------------------------------------------------------- */
 +/* Ruler Item (two or three points) */
 +
 +typedef struct RulerItem {
 +	wmGizmo gz;
 +
 +	/* worldspace coords, middle being optional */
 +	float co[3][3];
 +
 +	int   flag;
 +	int   raycast_dir;  /* RULER_DIRECTION_* */
 +} RulerItem;
 +
 +typedef struct RulerInteraction {
 +	/* selected coord */
 +	char  co_index; /* 0 -> 2 */
 +	float drag_start_co[3];
 +	uint inside_region : 1;
 +} RulerInteraction;
 +
 +/* -------------------------------------------------------------------- */
 +/** \name Internal Ruler Utilities
 + * \{ */
 +
 +static RulerItem *ruler_item_add(wmGizmoGroup *gzgroup)
 +{
 +	/* could pass this as an arg */
 +	const wmGizmoType *gzt_ruler = WM_gizmotype_find("VIEW3D_GT_ruler_item", true);
 +	RulerItem *ruler_item = (RulerItem *)WM_gizmo_new_ptr(gzt_ruler, gzgroup, NULL);
 +	WM_gizmo_set_flag(&ruler_item->gz, WM_GIZMO_DRAW_MODAL, true);
 +	return ruler_item;
 +}
 +
 +static void ruler_item_remove(bContext *C, wmGizmoGroup *gzgroup, RulerItem *ruler_item)
 +{
 +	WM_gizmo_unlink(&gzgroup->gizmos, gzgroup->parent_gzmap, &ruler_item->gz, C);
 +}
 +
 +static void ruler_item_as_string(RulerItem *ruler_item, UnitSettings *unit,
 +                                 char *numstr, size_t numstr_size, int prec)
 +{
 +	const bool do_split = (unit->flag & USER_UNIT_OPT_SPLIT) != 0;
 +
 +	if (ruler_item->flag & RULERITEM_USE_ANGLE) {
 +		const float ruler_angle = angle_v3v3v3(ruler_item->co[0],
 +		                                       ruler_item->co[1],
 +		                                       ruler_item->co[2]);
 +
 +		if (unit->system == USER_UNIT_NONE) {
 +			BLI_snprintf(numstr, numstr_size, "%.*f°", prec, RAD2DEGF(ruler_angle));
 +		}
 +		else {
 +			bUnit_AsString(numstr, numstr_size,
 +			               (double)ruler_angle,
 +			               prec, unit->system, B_UNIT_ROTATION, do_split, false);
 +		}
 +	}
 +	else {
 +		const float ruler_len = len_v3v3(ruler_item->co[0],
 +		                                 ruler_item->co[2]);
 +
 +		if (unit->system == USER_UNIT_NONE) {
 +			BLI_snprintf(numstr, numstr_size, "%.*f", prec, ruler_len);
 +		}
 +		else {
 +			bUnit_AsString(numstr, numstr_size,
 +			               (double)(ruler_len * unit->scale_length),
 +			               prec, unit->system, B_UNIT_LENGTH, do_split, false);
 +		}
 +	}
 +}
 +
 +static bool view3d_ruler_pick(
 +        wmGizmoGroup *gzgroup, RulerItem *ruler_item, const float mval[2],
 +        int *r_co_index)
 +{
 +	RulerInfo *ruler_info = gzgroup->customdata;
 +	ARegion *ar = ruler_info->ar;
 +	bool found = false;
 +
 +	float dist_best = RULER_PICK_DIST_SQ;
 +	int co_index_best = -1;
 +
 +	{
 +		float co_ss[3][2];
 +		float dist;
 +		int j;
 +
 +		/* should these be checked? - ok for now not to */
 +		for (j = 0; j < 3; j++) {
 +			ED_view3d_project_float_global(ar, ruler_item->co[j], co_ss[j], V3D_PROJ_TEST_NOP);
 +		}
 +
 +		if (ruler_item->flag & RULERITEM_USE_ANGLE) {
 +			dist = min_ff(dist_squared_to_line_segment_v2(mval, co_ss[0], co_ss[1]),
 +			              dist_squared_to_line_segment_v2(mval, co_ss[1], co_ss[2]));
 +			if (dist < dist_best) {
 +				dist_best = dist;
 +				found = true;
 +
 +				{
 +					const float dist_points[3] = {
 +					    len_squared_v2v2(co_ss[0], mval),
 +					    len_squared_v2v2(co_ss[1], mval),
 +					    len_squared_v2v2(co_ss[2], mval),
 +					};
 +					if (min_fff(UNPACK3(dist_points)) < RULER_PICK_DIST_SQ) {
 +						co_index_best = min_axis_v3(dist_points);
 +					}
 +					else {
 +						co_index_best = -1;
 +					}
 +				}
 +			}
 +		}
 +		else {
 +			dist = dist_squared_to_line_segment_v2(mval, co_ss[0], co_ss[2]);
 +			if (dist < dist_best) {
 +				dist_best = dist;
 +				found = true;
 +
 +				{
 +					const float dist_points[2] = {
 +					    len_squared_v2v2(co_ss[0], mval),
 +					    len_squared_v2v2(co_ss[2], mval),
 +					};
 +					if (min_ff(UNPACK2(dist_points)) < RULER_PICK_DIST_SQ) {
 +						co_index_best = (dist_points[0] < dist_points[1]) ? 0 : 2;
 +					}
 +					else {
 +						co_index_best = -1;
 +					}
 +				}
 +			}
 +		}
 +	}
 +
 +	*r_co_index = co_index_best;
 +	return found;
 +}
 +
 +/**
 + * Ensure the 'snap_context' is only cached while dragging,
 + * needed since the user may toggle modes between tool use.
 + */
 +static void ruler_state_set(bContext *C, RulerInfo *ruler_info, int state)
 +{
 +	Main *bmain = CTX_data_main(C);
 +	if (state == ruler_info->state) {
 +		return;
 +	}
 +
 +	/* always remove */
 +	if (ruler_info->snap_context) {
 +		ED_transform_snap_object_context_destroy(ruler_info->snap_context);
 +		ruler_info->snap_context = NULL;
 +	}
 +
 +	if (state == RULER_STATE_NORMAL) {
 +		/* pass */
 +	}
 +	else if (state == RULER_STATE_DRAG) {
 +		ruler_info->snap_context = ED_transform_snap_object_context_create_view3d(
 +		        bmain, CTX_data_scene(C), CTX_data_depsgraph(C), 0,
 +		        ruler_info->ar, CTX_wm_view3d(C));
 +	}
 +	else {
 +		BLI_assert(0);
 +	}
 +
 +	ruler_info->state = state;
 +}
 +
 +static void view3d_ruler_item_project(
 +        RulerInfo *ruler_info, float r_co[3],
 +        const int xy[2])
 +{
 +	ED_view3d_win_to_3d_int(ruler_info->sa->spacedata.first, ruler_info->ar, r_co, xy, r_co);
 +}
 +
 +/* use for mousemove events */
 +static bool view3d_ruler_item_mousemove(
 +        RulerInfo *ruler_info, RulerItem *ruler_item, const int mval[2],
 +        const bool do_thickness, const bool do_snap)
 +{
 +	RulerInteraction *inter = ruler_item->gz.interaction_data;
 +	const float eps_bias = 0.0002f;
 +	float dist_px = MVAL_MAX_PX_DIST * U.pixelsize;  /* snap dist */
 +
 +	ruler_info->snap_flag &= ~RULER_SNAP_OK;
 +
 +	if (ruler_item) {
 +		float *co = ruler_item->co[inter->co_index];
 +		/* restore the initial depth */
 +		copy_v3_v3(co, inter->drag_start_co);
 +		view3d_ruler_item_project(ruler_info, co, mval);
 +		if (do_thickness && inter->co_index != 1) {
 +			// Scene *scene = CTX_data_scene(C);
 +			// View3D *v3d = ruler_info->sa->spacedata.first;
 +			const float mval_fl[2] = {UNPACK2(mval)};
 +			float ray_normal[3];
 +			float ray_start[3];
 +			float *co_other;
 +
 +			co_other = ruler_item->co[inter->co_index == 0 ? 2 : 0];
 +
 +			if (ED_transform_snap_object_project_view3d(
 +			        ruler_info->snap_context,
 +			        SCE_SNAP_MODE_FACE,
 +			        &(const struct SnapObjectParams){
 +			            .snap_select = SNAP_ALL,
 +			            .use_object_edit_cage = true,
 +			        },
 +			        mval_fl, &dist_px,
 +			        co, ray_normal))
 +			{
 +				negate_v3(ray_normal);
 +				/* add some bias */
 +				madd_v3_v3v3fl(ray_start, co, ray_normal, eps_bias);
 +				ED_transform_snap_object_project_ray(
 +				        ruler_info->snap_context,
 +				        &(const struct SnapOb

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list