[Bf-blender-cvs] [161ab6109e2] blender2.8: COW Operators: Fix VIEW3D_OT_ rotate move zoom dolly orbit roll pan smoothview and the ndof versions

Ines Almeida noreply at git.blender.org
Mon May 21 20:40:56 CEST 2018


Commit: 161ab6109e265ea906e0308ab404f95282534770
Author: Ines Almeida
Date:   Mon May 21 20:29:00 2018 +0200
Branches: blender2.8
https://developer.blender.org/rB161ab6109e265ea906e0308ab404f95282534770

COW Operators: Fix VIEW3D_OT_ rotate move zoom dolly orbit roll pan smoothview and the ndof versions

Fixes camera view locking, camera related transitions and movements with the active object as pivot point
Note there can still be problems if the active object is not selectable

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

M	source/blender/blenkernel/BKE_object.h
M	source/blender/blenkernel/intern/object.c
M	source/blender/editors/include/ED_view3d.h
M	source/blender/editors/space_view3d/view3d_edit.c
M	source/blender/editors/space_view3d/view3d_utils.c
M	source/blender/editors/space_view3d/view3d_view.c

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

diff --git a/source/blender/blenkernel/BKE_object.h b/source/blender/blenkernel/BKE_object.h
index 99e40c5a975..7dbdac1b835 100644
--- a/source/blender/blenkernel/BKE_object.h
+++ b/source/blender/blenkernel/BKE_object.h
@@ -125,6 +125,7 @@ void BKE_object_mat3_to_rot(struct Object *ob, float mat[3][3], bool use_compat)
 void BKE_object_to_mat3(struct Object *ob, float mat[3][3]);
 void BKE_object_to_mat4(struct Object *ob, float mat[4][4]);
 void BKE_object_apply_mat4(struct Object *ob, float mat[4][4], const bool use_compat, const bool use_parent);
+void BKE_object_apply_mat4_ex(struct Object *ob, float mat[4][4], struct Object *parent, float parentinv[4][4], const bool use_compat);
 void BKE_object_matrix_local_get(struct Object *ob, float mat[4][4]);
 
 bool BKE_object_pose_context_check(const struct Object *ob);
diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c
index 1e6d3041f3f..8e50d1b32e1 100644
--- a/source/blender/blenkernel/intern/object.c
+++ b/source/blender/blenkernel/intern/object.c
@@ -2199,17 +2199,25 @@ void BKE_object_workob_calc_parent(Depsgraph *depsgraph, Scene *scene, Object *o
 	BKE_object_where_is_calc(depsgraph, scene, workob);
 }
 
-/* see BKE_pchan_apply_mat4() for the equivalent 'pchan' function */
-void BKE_object_apply_mat4(Object *ob, float mat[4][4], const bool use_compat, const bool use_parent)
+/**
+ * Applies the global transformation \a mat to the \a ob using a relative parent space if supplied.
+ *
+ * \param mat the global transformation mat that the object should be set object to.
+ * \param parent the parent space in which this object will be set relative to (should probably always be parent_eval).
+ * \param use_compat true to ensure that rotations are set using the min difference between the old and new orientation.
+ */
+void BKE_object_apply_mat4_ex(Object *ob, float mat[4][4], Object *parent, float parentinv[4][4], const bool use_compat)
 {
+	/* see BKE_pchan_apply_mat4() for the equivalent 'pchan' function */
+
 	float rot[3][3];
 
-	if (use_parent && ob->parent) {
+	if (parent != NULL) {
 		float rmat[4][4], diff_mat[4][4], imat[4][4], parent_mat[4][4];
 
-		BKE_object_get_parent_matrix(NULL, ob, ob->parent, parent_mat);
+		BKE_object_get_parent_matrix(NULL, ob, parent, parent_mat);
 
-		mul_m4_m4m4(diff_mat, parent_mat, ob->parentinv);
+		mul_m4_m4m4(diff_mat, parent_mat, parentinv);
 		invert_m4_m4(imat, diff_mat);
 		mul_m4_m4m4(rmat, imat, mat); /* get the parent relative matrix */
 
@@ -2231,6 +2239,12 @@ void BKE_object_apply_mat4(Object *ob, float mat[4][4], const bool use_compat, c
 	/* BKE_object_mat3_to_rot handles delta rotations */
 }
 
+/* XXX: should be removed after COW operators port to use BKE_object_apply_mat4_ex directly */
+void BKE_object_apply_mat4(Object *ob, float mat[4][4], const bool use_compat, const bool use_parent)
+{
+	BKE_object_apply_mat4_ex(ob, mat, use_parent ? ob->parent : NULL, ob->parentinv, use_compat);
+}
+
 BoundBox *BKE_boundbox_alloc_unit(void)
 {
 	BoundBox *bb;
diff --git a/source/blender/editors/include/ED_view3d.h b/source/blender/editors/include/ED_view3d.h
index bb86c7ba6c5..9316d8ab265 100644
--- a/source/blender/editors/include/ED_view3d.h
+++ b/source/blender/editors/include/ED_view3d.h
@@ -109,7 +109,8 @@ void ED_view3d_to_m4(float mat[4][4], const float ofs[3], const float quat[4], c
 void ED_view3d_from_m4(float mat[4][4], float ofs[3], float quat[4], float *dist);
 
 void ED_view3d_from_object(struct Object *ob, float ofs[3], float quat[4], float *dist, float *lens);
-void ED_view3d_to_object(struct Object *ob, const float ofs[3], const float quat[4], const float dist);
+void ED_view3d_to_object(
+        const struct Depsgraph *depsgraph, struct Object *ob, const float ofs[3], const float quat[4], const float dist);
 
 void ED_view3d_lastview_store(struct RegionView3D *rv3d);
 
@@ -436,17 +437,21 @@ uint64_t ED_view3d_datamask(const struct Scene *scene, const struct View3D *v3d)
 uint64_t ED_view3d_screen_datamask(const struct Scene *scene, const struct bScreen *screen);
 
 bool ED_view3d_offset_lock_check(const struct View3D *v3d, const struct RegionView3D *rv3d);
-void ED_view3d_persp_switch_from_camera(struct View3D *v3d, struct RegionView3D *rv3d, const char persp);
-bool ED_view3d_persp_ensure(struct View3D *v3d, struct ARegion *ar);
+void ED_view3d_persp_switch_from_camera(const struct Depsgraph *depsgraph,
+        struct View3D *v3d, struct RegionView3D *rv3d, const char persp);
+bool ED_view3d_persp_ensure(const struct Depsgraph *depsgraph,
+        struct View3D *v3d, struct ARegion *ar);
 
 
 /* camera lock functions */
 bool ED_view3d_camera_lock_check(const struct View3D *v3d, const struct RegionView3D *rv3d);
 /* copy the camera to the view before starting a view transformation */
-void ED_view3d_camera_lock_init_ex(struct View3D *v3d, struct RegionView3D *rv3d, const bool calc_dist);
-void ED_view3d_camera_lock_init(struct View3D *v3d, struct RegionView3D *rv3d);
+void ED_view3d_camera_lock_init_ex(const struct Depsgraph *depsgraph,
+        struct View3D *v3d, struct RegionView3D *rv3d, const bool calc_dist);
+void ED_view3d_camera_lock_init(const struct Depsgraph *depsgraph, struct View3D *v3d, struct RegionView3D *rv3d);
 /* copy the view to the camera, return true if */
-bool ED_view3d_camera_lock_sync(struct View3D *v3d, struct RegionView3D *rv3d);
+bool ED_view3d_camera_lock_sync(const struct Depsgraph *depsgraph,
+        struct View3D *v3d, struct RegionView3D *rv3d);
 
 bool ED_view3d_camera_autokey(
         struct Scene *scene, struct ID *id_key,
diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c
index 61292d9b707..6216c7399c7 100644
--- a/source/blender/editors/space_view3d/view3d_edit.c
+++ b/source/blender/editors/space_view3d/view3d_edit.c
@@ -250,9 +250,11 @@ static bool view3d_orbit_calc_center(bContext *C, float r_dyn_ofs[3])
 	static float lastofs[3] = {0, 0, 0};
 	bool is_set = false;
 
+	const Depsgraph *depsgraph = CTX_data_depsgraph(C);
 	Scene *scene = CTX_data_scene(C);
-	ViewLayer *view_layer = CTX_data_view_layer(C);
-	Object *ob_act = OBACT(view_layer);
+	ViewLayer *view_layer_eval = DEG_get_evaluated_view_layer(depsgraph);
+	Object *ob_act_eval = OBACT(view_layer_eval);
+	Object *ob_act = DEG_get_original_object(ob_act_eval);
 
 	if (ob_act && (ob_act->mode & OB_MODE_ALL_PAINT) &&
 	    /* with weight-paint + pose-mode, fall through to using calculateTransformCenter */
@@ -264,16 +266,16 @@ static bool view3d_orbit_calc_center(bContext *C, float r_dyn_ofs[3])
 		 */
 		if (ob_act->mode & (OB_MODE_SCULPT | OB_MODE_TEXTURE_PAINT | OB_MODE_VERTEX_PAINT | OB_MODE_WEIGHT_PAINT)) {
 			float stroke[3];
-			BKE_paint_stroke_get_average(scene, ob_act, stroke);
+			BKE_paint_stroke_get_average(scene, ob_act_eval, stroke);
 			copy_v3_v3(lastofs, stroke);
 		}
 		else {
-			copy_v3_v3(lastofs, ob_act->obmat[3]);
+			copy_v3_v3(lastofs, ob_act_eval->obmat[3]);
 		}
 		is_set = true;
 	}
 	else if (ob_act && (ob_act->mode & OB_MODE_EDIT) && (ob_act->type == OB_FONT)) {
-		Curve *cu = ob_act->data;
+		Curve *cu = ob_act_eval->data;
 		EditFont *ef = cu->editfont;
 		int i;
 
@@ -283,32 +285,32 @@ static bool view3d_orbit_calc_center(bContext *C, float r_dyn_ofs[3])
 		}
 		mul_v2_fl(lastofs, 1.0f / 4.0f);
 
-		mul_m4_v3(ob_act->obmat, lastofs);
+		mul_m4_v3(ob_act_eval->obmat, lastofs);
 
 		is_set = true;
 	}
 	else if (ob_act == NULL || ob_act->mode == OB_MODE_OBJECT) {
 		/* object mode use boundbox centers */
-		Base *base;
+		Base *base_eval;
 		unsigned int tot = 0;
 		float select_center[3];
 
 		zero_v3(select_center);
-		for (base = FIRSTBASE(view_layer); base; base = base->next) {
-			if (TESTBASE(base)) {
+		for (base_eval = FIRSTBASE(view_layer_eval); base_eval; base_eval = base_eval->next) {
+			if (TESTBASE(base_eval)) {
 				/* use the boundbox if we can */
-				Object *ob = base->object;
+				Object *ob_eval = base_eval->object;
 
-				if (ob->bb && !(ob->bb->flag & BOUNDBOX_DIRTY)) {
+				if (ob_eval->bb && !(ob_eval->bb->flag & BOUNDBOX_DIRTY)) {
 					float cent[3];
 
-					BKE_boundbox_calc_center_aabb(ob->bb, cent);
+					BKE_boundbox_calc_center_aabb(ob_eval->bb, cent);
 
-					mul_m4_v3(ob->obmat, cent);
+					mul_m4_v3(ob_eval->obmat, cent);
 					add_v3_v3(select_center, cent);
 				}
 				else {
-					add_v3_v3(select_center, ob->obmat[3]);
+					add_v3_v3(select_center, ob_eval->obmat[3]);
 				}
 				tot++;
 			}
@@ -371,6 +373,7 @@ static void viewops_data_create(
         bContext *C, wmOperator *op, const wmEvent *event,
         enum eViewOpsFlag viewops_flag)
 {
+	Depsgraph *depsgraph = CTX_data_depsgraph(C);
 	ViewOpsData *vod = op->customdata;
 	RegionView3D *rv3d = vod->rv3d;
 
@@ -381,7 +384,6 @@ static void viewops_data_create(
 
 	/* we need the depth info before changing any viewport options */
 	if (viewops_flag & VIEWOPS_FLAG_DEPTH_NAVIGATE) {
-		struct Depsgraph *graph = CTX_data_depsgraph(C);
 		float fallback_depth_pt[3];
 
 		view3d_operator_needs_opengl(C); /* needed for zbuf drawing */
@@ -389,7 +391,7 @@ static void viewops_data_create(
 		negate_v3_v3(fallback_depth_pt, rv3d->ofs);
 
 		vod->use_dyn_ofs = ED_view3d_autodist(
-		        graph, vod->ar, vod->v3d,
+		        depsgraph, vod->ar, vod->v3d,
 		        event->mval, vod->dyn_ofs, true, fallback_depth_pt);
 	}
 	else {
@@ -397,7 +399,7 @@ static void viewops_data_create(
 	}
 
 	if (viewops_flag & VIEWOPS_FLAG_PERSP_ENSURE) {
-		if (ED_view3d_persp_ensure(vod->v3d, vod->ar)) {
+		if (ED_view3d_persp_ensure(depsgraph, vod->v3d, vod->ar)) {
 			/* If we're switching from camera view to the perspective one,
 			 * need to tag viewport update, so camera vuew and borders
 			 * are properly updated.
@@ -408,7 +410,7 @@ static void viewops_data_create(
 
 	/* set the view from the camera, if view locking is enabled.
 	 * we may want to make this optional but for now its needed always */
-	ED_view3d_camera_lock_init(vod->v3d, vod->rv3d);
+	ED_view3d_camera_lock_init(depsgraph, vod->v3d, vod->rv3d);
 
 	vod->init.dist = rv3d->dist;
 	vod->init.camzoom = rv3d->camzoom;
@@ -811,7 +813,7 @@ static void vi

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list