[Bf-blender-cvs] [9342f55d12f] blender2.8: Merge branch 'master' into blender2.8

Campbell Barton noreply at git.blender.org
Thu Mar 8 07:48:03 CET 2018


Commit: 9342f55d12f87dbc72e6953e0bc6c2564e57465f
Author: Campbell Barton
Date:   Thu Mar 8 17:52:10 2018 +1100
Branches: blender2.8
https://developer.blender.org/rB9342f55d12f87dbc72e6953e0bc6c2564e57465f

Merge branch 'master' into blender2.8

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



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

diff --cc source/blender/editors/armature/armature_select.c
index f178ad640b6,2e2c184e43d..397691a409b
--- a/source/blender/editors/armature/armature_select.c
+++ b/source/blender/editors/armature/armature_select.c
@@@ -172,9 -170,8 +172,9 @@@ void *get_nearest_bone(bContext *C, con
  	rcti rect;
  	unsigned int buffer[MAXPICKBUF];
  	short hits;
 -	
 +
 +	CTX_data_eval_ctx(C, &eval_ctx);
- 	view3d_set_viewcontext(C, &vc);
+ 	ED_view3d_viewcontext_init(C, &vc);
  	
  	// rect.xmin = ... mouseco!
  	rect.xmin = rect.xmax = xy[0];
@@@ -490,9 -486,8 +490,9 @@@ bool ED_armature_select_pick(bContext *
  	EditBone *nearBone = NULL;
  	int selmask;
  
 +	CTX_data_eval_ctx(C, &eval_ctx);
- 	view3d_set_viewcontext(C, &vc);
+ 	ED_view3d_viewcontext_init(C, &vc);
 -	
 +
  	if (BIF_sk_selectStroke(C, mval, extend)) {
  		return true;
  	}
diff --cc source/blender/editors/armature/editarmature_sketch.c
index f17a83dec8f,79b538b4f4a..f01eed21996
--- a/source/blender/editors/armature/editarmature_sketch.c
+++ b/source/blender/editors/armature/editarmature_sketch.c
@@@ -1931,8 -1905,7 +1931,8 @@@ static bool sk_selectStroke(bContext *C
  	unsigned int buffer[MAXPICKBUF];
  	short hits;
  
 +	CTX_data_eval_ctx(C, &eval_ctx);
- 	view3d_set_viewcontext(C, &vc);
+ 	ED_view3d_viewcontext_init(C, &vc);
  
  	BLI_rcti_init_pt_radius(&rect, mval, 5);
  
diff --cc source/blender/editors/curve/editcurve_paint.c
index 169afb140fb,0d7cb089c4f..36eb4c6c5bc
--- a/source/blender/editors/curve/editcurve_paint.c
+++ b/source/blender/editors/curve/editcurve_paint.c
@@@ -605,10 -580,8 +605,10 @@@ static bool curve_draw_init(bContext *C
  
  	struct CurveDrawData *cdd = MEM_callocN(sizeof(*cdd), __func__);
  
 +	cdd->depsgraph = CTX_data_depsgraph(C);
 +
  	if (is_invoke) {
- 		view3d_set_viewcontext(C, &cdd->vc);
+ 		ED_view3d_viewcontext_init(C, &cdd->vc);
  		if (ELEM(NULL, cdd->vc.ar, cdd->vc.rv3d, cdd->vc.v3d, cdd->vc.win, cdd->vc.scene)) {
  			MEM_freeN(cdd);
  			BKE_report(op->reports, RPT_ERROR, "Unable to access 3D viewport");
diff --cc source/blender/editors/mesh/meshtools.c
index 4daa4a23470,b66821c4e37..aebfd46a554
--- a/source/blender/editors/mesh/meshtools.c
+++ b/source/blender/editors/mesh/meshtools.c
@@@ -1101,8 -1088,7 +1101,8 @@@ bool ED_mesh_pick_face(bContext *C, Obj
  	if (!me || me->totpoly == 0)
  		return false;
  
 +	CTX_data_eval_ctx(C, &eval_ctx);
- 	view3d_set_viewcontext(C, &vc);
+ 	ED_view3d_viewcontext_init(C, &vc);
  
  	if (size) {
  		/* sample rect to increase chances of selecting, so that when clicking
diff --cc source/blender/editors/metaball/mball_edit.c
index 935f1a5ea4a,e948de02f40..310325ee143
--- a/source/blender/editors/metaball/mball_edit.c
+++ b/source/blender/editors/metaball/mball_edit.c
@@@ -597,8 -595,7 +597,8 @@@ bool ED_mball_select_pick(bContext *C, 
  	unsigned int buffer[MAXPICKBUF];
  	rcti rect;
  
 +	CTX_data_eval_ctx(C, &eval_ctx);
- 	view3d_set_viewcontext(C, &vc);
+ 	ED_view3d_viewcontext_init(C, &vc);
  
  	BLI_rcti_init_pt_radius(&rect, mval, 12);
  
diff --cc source/blender/editors/object/object_transform.c
index b336b560ef2,9fea7bf5b89..033f9d190b7
--- a/source/blender/editors/object/object_transform.c
+++ b/source/blender/editors/object/object_transform.c
@@@ -1152,389 -1131,3 +1152,389 @@@ void OBJECT_OT_origin_set(wmOperatorTyp
  	ot->prop = RNA_def_enum(ot->srna, "type", prop_set_center_types, 0, "Type", "");
  	RNA_def_enum(ot->srna, "center", prop_set_bounds_types, V3D_AROUND_CENTER_MEAN, "Center", "");
  }
 +
 +/* -------------------------------------------------------------------- */
 +
 +/** \name Transform Axis Target
 + *
 + * Note this is an experemental operator to point lamps/cameras at objects.
 + * We may re-work how this behaves based on user feedback.
 + * - campbell.
 + * \{ */
 +
 +/* When using multiple objects, apply their relative rotational offset to the active object. */
 +#define USE_RELATIVE_ROTATION
 +
 +struct XFormAxisItem {
 +	Object *ob;
 +	float rot_mat[3][3];
 +	void *obtfm;
 +	float xform_dist;
 +
 +#ifdef USE_RELATIVE_ROTATION
 +	/* use when translating multiple */
 +	float xform_rot_offset[3][3];
 +#endif
 +};
 +
 +struct XFormAxisData {
 +	ViewContext vc;
 +	struct {
 +		float depth;
 +		float normal[3];
 +		bool is_depth_valid;
 +		bool is_normal_valid;
 +	} prev;
 +
 +	struct XFormAxisItem *object_data;
 +	uint object_data_len;
 +	bool is_translate;
 +
 +	int init_event;
 +};
 +
 +static bool object_is_target_compat(const Object *ob)
 +{
 +	if (ob->type == OB_LAMP) {
 +		const Lamp *la = ob->data;
 +		if (ELEM(la->type, LA_SUN, LA_SPOT, LA_HEMI, LA_AREA)) {
 +			return true;
 +		}
 +	}
 +	/* We might want to enable this later, for now just lamps */
 +#if 0
 +	else if (ob->type == OB_CAMERA) {
 +		return true;
 +	}
 +#endif
 +	return false;
 +}
 +
 +static void object_transform_axis_target_free_data(wmOperator *op)
 +{
 +	struct XFormAxisData *xfd = op->customdata;
 +	struct XFormAxisItem *item = xfd->object_data;
 +	for (int i = 0; i < xfd->object_data_len; i++, item++) {
 +		MEM_freeN(item->obtfm);
 +	}
 +	MEM_freeN(xfd->object_data);
 +	MEM_freeN(xfd);
 +	op->customdata = NULL;
 +}
 +
 +/* We may want to expose as alternative to: BKE_object_apply_rotation */
 +static void object_apply_rotation(Object *ob, const float rmat[3][3])
 +{
 +	float size[3];
 +	float loc[3];
 +	float rmat4[4][4];
 +	copy_m4_m3(rmat4, rmat);
 +
 +	copy_v3_v3(size, ob->size);
 +	copy_v3_v3(loc, ob->loc);
 +	BKE_object_apply_mat4(ob, rmat4, true, true);
 +	copy_v3_v3(ob->size, size);
 +	copy_v3_v3(ob->loc, loc);
 +}
 +/* We may want to extract this to: BKE_object_apply_location */
 +static void object_apply_location(Object *ob, const float loc[3])
 +{
 +	/* quick but weak */
 +	Object ob_prev = *ob;
 +	float mat[4][4];
 +	copy_m4_m4(mat, ob->obmat);
 +	copy_v3_v3(mat[3], loc);
 +	BKE_object_apply_mat4(ob, mat, true, true);
 +	copy_v3_v3(mat[3], ob->loc);
 +	*ob = ob_prev;
 +	copy_v3_v3(ob->loc, mat[3]);
 +}
 +
 +static void object_orient_to_location(
 +        Object *ob, float rot_orig[3][3], const float axis[3], const float location[3])
 +{
 +	float delta[3];
 +	sub_v3_v3v3(delta, ob->obmat[3], location);
 +	if (normalize_v3(delta) != 0.0f) {
 +		if (len_squared_v3v3(delta, axis) > FLT_EPSILON) {
 +			float delta_rot[3][3];
 +			float final_rot[3][3];
 +			rotation_between_vecs_to_mat3(delta_rot, axis, delta);
 +
 +			mul_m3_m3m3(final_rot, delta_rot, rot_orig);
 +
 +			object_apply_rotation(ob, final_rot);
 +
 +			DEG_id_tag_update(&ob->id, OB_RECALC_OB);
 +		}
 +	}
 +}
 +
 +static void object_transform_axis_target_cancel(bContext *C, wmOperator *op)
 +{
 +	struct XFormAxisData *xfd = op->customdata;
 +	struct XFormAxisItem *item = xfd->object_data;
 +	for (int i = 0; i < xfd->object_data_len; i++, item++) {
 +		BKE_object_tfm_restore(item->ob, item->obtfm);
 +		DEG_id_tag_update(&item->ob->id, OB_RECALC_OB);
 +		WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, item->ob);
 +	}
 +
 +	object_transform_axis_target_free_data(op);
 +}
 +
 +static int object_transform_axis_target_invoke(bContext *C, wmOperator *op, const wmEvent *event)
 +{
 +	ViewContext vc;
- 	view3d_set_viewcontext(C, &vc);
++	ED_view3d_viewcontext_init(C, &vc);
 +
 +	if (!object_is_target_compat(vc.obact)) {
 +		/* Falls back to texture space transform. */
 +		return OPERATOR_PASS_THROUGH;
 +	}
 +
 +	EvaluationContext eval_ctx;
 +
 +	CTX_data_eval_ctx(C, &eval_ctx);
 +
 +	ED_view3d_autodist_init(&eval_ctx, vc.depsgraph, vc.ar, vc.v3d, 0);
 +
 +	if (vc.rv3d->depths != NULL) {
 +		vc.rv3d->depths->damaged = true;
 +	}
 +	ED_view3d_depth_update(vc.ar);
 +
 +	if (vc.rv3d->depths == NULL) {
 +		BKE_report(op->reports, RPT_WARNING, "Unable to access depth buffer, using view plane");
 +		return OPERATOR_CANCELLED;
 +	}
 +
 +	ED_region_tag_redraw(vc.ar);
 +
 +	struct XFormAxisData *xfd;
 +	xfd = op->customdata = MEM_callocN(sizeof(struct XFormAxisData), __func__);
 +
 +	/* Don't change this at runtime. */
 +	xfd->vc = vc;
 +	xfd->vc.mval[0] = event->mval[0];
 +	xfd->vc.mval[1] = event->mval[1];
 +
 +	xfd->prev.depth = 1.0f;
 +	xfd->prev.is_depth_valid = false;
 +	xfd->prev.is_normal_valid = false;
 +	xfd->is_translate = false;
 +
 +	xfd->init_event = WM_userdef_event_type_from_keymap_type(event->type);
 +
 +	{
 +		struct XFormAxisItem *object_data = NULL;
 +		BLI_array_declare(object_data);
 +
 +		struct XFormAxisItem *item = BLI_array_append_ret(object_data);
 +		item->ob = xfd->vc.obact;
 +
 +		CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects)
 +		{
 +			if ((ob != xfd->vc.obact) && object_is_target_compat(ob)) {
 +				item = BLI_array_append_ret(object_data);
 +				item->ob = ob;
 +			}
 +		}
 +		CTX_DATA_END;
 +
 +		xfd->object_data = object_data;
 +		xfd->object_data_len = BLI_array_count(object_data);
 +
 +		if (xfd->object_data_len != BLI_array_count(object_data)) {
 +			xfd->object_data = MEM_reallocN(xfd->object_data, xfd->object_data_len * sizeof(*xfd->object_data));
 +		}
 +	}
 +
 +	{
 +		struct XFormAxisItem *item = xfd->object_data;
 +		for (int i = 0; i < xfd->object_data_len; i++, item++) {
 +			item->obtfm = BKE_object_tfm_backup(item->ob);
 +			BKE_object_rot_to_mat3(item->ob, item->rot_mat, true);
 +		}
 +	}
 +
 +	WM_event_add_modal_handler(C, op);
 +
 +	return OPERATOR_RUNNING_MODAL;
 +}
 +
 +static int object_transform_axis_target_modal(bContext *C, wmOperator *op, const wmEvent *event)
 +{
 +	struct XFormAxisData *xfd = op->customdata;
 +	ARegion *ar = xfd->vc.ar;
 +
 +	view3d_operator_needs_opengl(C);
 +
 +	const bool is_translate = (event->ctrl != 0);
 +	const bool is_translate_init = is_translate && (xfd->is_translate != is_translate);
 +
 +	if (event->type == MOUSEMOVE || is_translate_init) {
 +		const ViewDepths *depths = xfd->vc.rv3d->depths;
 +		if (depths &&
 +		    ((unsigned int)event->mval[0] < depths->w) &&
 +		    ((unsigned int)event->mval[1] < depths->h))
 +		{
 +			double depth = (double)ED_view3d_depth_read_cached(&xfd->vc, event->mval);
 +			float location_world[3];
 +			if (depth == 1.0f) {
 +				if (xfd->prev.is_depth_valid) {
 +					depth = (double)xfd->prev.depth;
 +				}
 +			}
 +			if ((depth > depths->depth_range[0]) && (depth < depths->depth_range[1])) {
 +				xfd->prev.depth = dept

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list