[Bf-blender-cvs] [a48186c5d74] blender2.8: Orientation for 3D cursor

Campbell Barton noreply at git.blender.org
Tue May 8 15:39:09 CEST 2018


Commit: a48186c5d74b3d353c5c65cd4a930dd98cc9a603
Author: Campbell Barton
Date:   Tue May 8 14:18:09 2018 +0200
Branches: blender2.8
https://developer.blender.org/rBa48186c5d74b3d353c5c65cd4a930dd98cc9a603

Orientation for 3D cursor

Currently set when setting the cursor location,
optionally used as an orientation type.

Intended for use by tools too.

See: D3208

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

M	source/blender/blenloader/intern/readfile.c
M	source/blender/blenloader/intern/versioning_280.c
M	source/blender/draw/intern/draw_cache.c
M	source/blender/draw/intern/draw_cache.h
M	source/blender/draw/intern/draw_view.c
M	source/blender/editors/armature/armature_add.c
M	source/blender/editors/armature/armature_edit.c
M	source/blender/editors/curve/editcurve.c
M	source/blender/editors/curve/editcurve_paint.c
M	source/blender/editors/gpencil/gpencil_brush.c
M	source/blender/editors/gpencil/gpencil_convert.c
M	source/blender/editors/gpencil/gpencil_edit.c
M	source/blender/editors/gpencil/gpencil_paint.c
M	source/blender/editors/gpencil/gpencil_utils.c
M	source/blender/editors/include/ED_view3d.h
M	source/blender/editors/mesh/editmesh_bisect.c
M	source/blender/editors/mesh/editmesh_extrude.c
M	source/blender/editors/mesh/editmesh_extrude_screw.c
M	source/blender/editors/mesh/editmesh_extrude_spin.c
M	source/blender/editors/mesh/editmesh_polybuild.c
M	source/blender/editors/mesh/editmesh_tools.c
M	source/blender/editors/object/object_add.c
M	source/blender/editors/object/object_hook.c
M	source/blender/editors/object/object_transform.c
M	source/blender/editors/object/object_warp.c
M	source/blender/editors/sculpt_paint/paint_image_proj.c
M	source/blender/editors/space_outliner/outliner_tools.c
M	source/blender/editors/space_view3d/view3d_edit.c
M	source/blender/editors/space_view3d/view3d_snap.c
M	source/blender/editors/space_view3d/view3d_utils.c
M	source/blender/editors/space_view3d/view3d_view.c
M	source/blender/editors/transform/transform.c
M	source/blender/editors/transform/transform_constraints.c
M	source/blender/editors/transform/transform_generics.c
M	source/blender/editors/transform/transform_manipulator_3d.c
M	source/blender/editors/transform/transform_orientations.c
M	source/blender/editors/uvedit/uvedit_unwrap_ops.c
M	source/blender/makesdna/DNA_scene_types.h
M	source/blender/makesdna/DNA_view3d_types.h
M	source/blender/makesrna/intern/rna_scene.c
M	source/blender/makesrna/intern/rna_space.c

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

diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 672b61fa122..a84124f353d 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -7355,7 +7355,8 @@ void blo_lib_link_restore(Main *newmain, wmWindowManager *curwm, Scene *curscene
 		BKE_workspace_active_set(win->workspace_hook, workspace);
 
 		/* keep cursor location through undo */
-		copy_v3_v3(win->scene->cursor, oldscene->cursor);
+		copy_v3_v3(win->scene->cursor.location, oldscene->cursor.location);
+		copy_qt_qt(win->scene->cursor.rotation, oldscene->cursor.rotation);
 		lib_link_workspace_scene_data_restore(win, win->scene);
 
 		BLI_assert(win->screen == NULL);
@@ -10039,7 +10040,7 @@ static void give_base_to_groups(
 			/* Assign the group. */
 			ob->dup_group = group;
 			ob->transflag |= OB_DUPLIGROUP;
-			copy_v3_v3(ob->loc, scene->cursor);
+			copy_v3_v3(ob->loc, scene->cursor.location);
 		}
 	}
 }
diff --git a/source/blender/blenloader/intern/versioning_280.c b/source/blender/blenloader/intern/versioning_280.c
index 55bc314d6b4..1ce721232f0 100644
--- a/source/blender/blenloader/intern/versioning_280.c
+++ b/source/blender/blenloader/intern/versioning_280.c
@@ -1099,5 +1099,21 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *main)
 				}
 			}
 		}
+
+		if (!DNA_struct_find(fd->filesdna, "View3DCursor")) {
+			for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
+				unit_qt(scene->cursor.rotation);
+			}
+			for (bScreen *screen = main->screen.first; screen; screen = screen->id.next) {
+				for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
+					for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
+						if (sl->spacetype == SPACE_VIEW3D) {
+							View3D *v3d = (View3D *)sl;
+							unit_qt(v3d->cursor.rotation);
+						}
+					}
+				}
+			}
+		}
 	}
 }
diff --git a/source/blender/draw/intern/draw_cache.c b/source/blender/draw/intern/draw_cache.c
index 2366fa556b9..aec1750edc5 100644
--- a/source/blender/draw/intern/draw_cache.c
+++ b/source/blender/draw/intern/draw_cache.c
@@ -46,6 +46,7 @@
 static struct DRWShapeCache {
 	Gwn_Batch *drw_single_vertice;
 	Gwn_Batch *drw_cursor;
+	Gwn_Batch *drw_cursor_only_circle;
 	Gwn_Batch *drw_fullscreen_quad;
 	Gwn_Batch *drw_quad;
 	Gwn_Batch *drw_sphere;
@@ -3021,9 +3022,11 @@ Gwn_Batch *DRW_cache_particles_get_prim(int type)
 }
 
 /* 3D cursor */
-Gwn_Batch *DRW_cache_cursor_get(void)
+Gwn_Batch *DRW_cache_cursor_get(bool crosshair_lines)
 {
-	if (!SHC.drw_cursor) {
+	Gwn_Batch **drw_cursor = crosshair_lines ? &SHC.drw_cursor : &SHC.drw_cursor_only_circle;
+
+	if (*drw_cursor == NULL) {
 		const float f5 = 0.25f;
 		const float f10 = 0.5f;
 		const float f20 = 1.0f;
@@ -3034,8 +3037,6 @@ Gwn_Batch *DRW_cache_cursor_get(void)
 
 		unsigned char red[3] = {255, 0, 0};
 		unsigned char white[3] = {255, 255, 255};
-		unsigned char crosshair_color[3];
-		UI_GetThemeColor3ubv(TH_VIEW_OVERLAY, crosshair_color);
 
 		static Gwn_VertFormat format = { 0 };
 		static struct { uint pos, color; } attr_id;
@@ -3065,45 +3066,51 @@ Gwn_Batch *DRW_cache_cursor_get(void)
 			GWN_indexbuf_add_generic_vert(&elb, v++);
 		}
 		GWN_indexbuf_add_generic_vert(&elb, 0);
-		GWN_indexbuf_add_primitive_restart(&elb);
-
-		GWN_vertbuf_attr_set(vbo, attr_id.pos, v, (const float[2]){-f20, 0});
-		GWN_vertbuf_attr_set(vbo, attr_id.color, v, crosshair_color);
-		GWN_indexbuf_add_generic_vert(&elb, v++);
-		GWN_vertbuf_attr_set(vbo, attr_id.pos, v, (const float[2]){-f5, 0});
-		GWN_vertbuf_attr_set(vbo, attr_id.color, v, crosshair_color);
-		GWN_indexbuf_add_generic_vert(&elb, v++);
-
-		GWN_indexbuf_add_primitive_restart(&elb);
-
-		GWN_vertbuf_attr_set(vbo, attr_id.pos, v, (const float[2]){+f5, 0});
-		GWN_vertbuf_attr_set(vbo, attr_id.color, v, crosshair_color);
-		GWN_indexbuf_add_generic_vert(&elb, v++);
-		GWN_vertbuf_attr_set(vbo, attr_id.pos, v, (const float[2]){+f20, 0});
-		GWN_vertbuf_attr_set(vbo, attr_id.color, v, crosshair_color);
-		GWN_indexbuf_add_generic_vert(&elb, v++);
-
-		GWN_indexbuf_add_primitive_restart(&elb);
-
-		GWN_vertbuf_attr_set(vbo, attr_id.pos, v, (const float[2]){0, -f20});
-		GWN_vertbuf_attr_set(vbo, attr_id.color, v, crosshair_color);
-		GWN_indexbuf_add_generic_vert(&elb, v++);
-		GWN_vertbuf_attr_set(vbo, attr_id.pos, v, (const float[2]){0, -f5});
-		GWN_vertbuf_attr_set(vbo, attr_id.color, v, crosshair_color);
-		GWN_indexbuf_add_generic_vert(&elb, v++);
-
-		GWN_indexbuf_add_primitive_restart(&elb);
-
-		GWN_vertbuf_attr_set(vbo, attr_id.pos, v, (const float[2]){0, +f5});
-		GWN_vertbuf_attr_set(vbo, attr_id.color, v, crosshair_color);
-		GWN_indexbuf_add_generic_vert(&elb, v++);
-		GWN_vertbuf_attr_set(vbo, attr_id.pos, v, (const float[2]){0, +f20});
-		GWN_vertbuf_attr_set(vbo, attr_id.color, v, crosshair_color);
-		GWN_indexbuf_add_generic_vert(&elb, v++);
+
+		if (crosshair_lines) {
+			unsigned char crosshair_color[3];
+			UI_GetThemeColor3ubv(TH_VIEW_OVERLAY, crosshair_color);
+
+			GWN_indexbuf_add_primitive_restart(&elb);
+
+			GWN_vertbuf_attr_set(vbo, attr_id.pos, v, (const float[2]){-f20, 0});
+			GWN_vertbuf_attr_set(vbo, attr_id.color, v, crosshair_color);
+			GWN_indexbuf_add_generic_vert(&elb, v++);
+			GWN_vertbuf_attr_set(vbo, attr_id.pos, v, (const float[2]){-f5, 0});
+			GWN_vertbuf_attr_set(vbo, attr_id.color, v, crosshair_color);
+			GWN_indexbuf_add_generic_vert(&elb, v++);
+
+			GWN_indexbuf_add_primitive_restart(&elb);
+
+			GWN_vertbuf_attr_set(vbo, attr_id.pos, v, (const float[2]){+f5, 0});
+			GWN_vertbuf_attr_set(vbo, attr_id.color, v, crosshair_color);
+			GWN_indexbuf_add_generic_vert(&elb, v++);
+			GWN_vertbuf_attr_set(vbo, attr_id.pos, v, (const float[2]){+f20, 0});
+			GWN_vertbuf_attr_set(vbo, attr_id.color, v, crosshair_color);
+			GWN_indexbuf_add_generic_vert(&elb, v++);
+
+			GWN_indexbuf_add_primitive_restart(&elb);
+
+			GWN_vertbuf_attr_set(vbo, attr_id.pos, v, (const float[2]){0, -f20});
+			GWN_vertbuf_attr_set(vbo, attr_id.color, v, crosshair_color);
+			GWN_indexbuf_add_generic_vert(&elb, v++);
+			GWN_vertbuf_attr_set(vbo, attr_id.pos, v, (const float[2]){0, -f5});
+			GWN_vertbuf_attr_set(vbo, attr_id.color, v, crosshair_color);
+			GWN_indexbuf_add_generic_vert(&elb, v++);
+
+			GWN_indexbuf_add_primitive_restart(&elb);
+
+			GWN_vertbuf_attr_set(vbo, attr_id.pos, v, (const float[2]){0, +f5});
+			GWN_vertbuf_attr_set(vbo, attr_id.color, v, crosshair_color);
+			GWN_indexbuf_add_generic_vert(&elb, v++);
+			GWN_vertbuf_attr_set(vbo, attr_id.pos, v, (const float[2]){0, +f20});
+			GWN_vertbuf_attr_set(vbo, attr_id.color, v, crosshair_color);
+			GWN_indexbuf_add_generic_vert(&elb, v++);
+		}
 
 		Gwn_IndexBuf *ibo = GWN_indexbuf_build(&elb);
 
-		SHC.drw_cursor = GWN_batch_create_ex(GWN_PRIM_LINE_STRIP, vbo, ibo, GWN_BATCH_OWNS_VBO | GWN_BATCH_OWNS_INDEX);
+		*drw_cursor = GWN_batch_create_ex(GWN_PRIM_LINE_STRIP, vbo, ibo, GWN_BATCH_OWNS_VBO | GWN_BATCH_OWNS_INDEX);
 	}
-	return SHC.drw_cursor;
+	return *drw_cursor;
 }
diff --git a/source/blender/draw/intern/draw_cache.h b/source/blender/draw/intern/draw_cache.h
index 18bff56920e..dfaf126e425 100644
--- a/source/blender/draw/intern/draw_cache.h
+++ b/source/blender/draw/intern/draw_cache.h
@@ -34,7 +34,7 @@ struct ModifierData;
 void DRW_shape_cache_free(void);
 
 /* 3D cursor */
-struct Gwn_Batch *DRW_cache_cursor_get(void);
+struct Gwn_Batch *DRW_cache_cursor_get(bool crosshair_lines);
 
 /* Common Shapes */
 struct Gwn_Batch *DRW_cache_fullscreen_quad_get(void);
diff --git a/source/blender/draw/intern/draw_view.c b/source/blender/draw/intern/draw_view.c
index be43f0d8c0c..be0556c8077 100644
--- a/source/blender/draw/intern/draw_view.c
+++ b/source/blender/draw/intern/draw_view.c
@@ -659,21 +659,66 @@ void DRW_draw_cursor(void)
 
 	if (is_cursor_visible(draw_ctx, scene, view_layer)) {
 		int co[2];
-		if (ED_view3d_project_int_global(ar, ED_view3d_cursor3d_get(scene, v3d), co, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_OK) {
+		const View3DCursor *cursor = ED_view3d_cursor3d_get(scene, v3d);
+		if (ED_view3d_project_int_global(
+		            ar, cursor->location, co, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_OK)
+		{
+			RegionView3D *rv3d = ar->regiondata;
+
+			/* Draw nice Anti Aliased cursor. */
+			glLineWidth(1.0f);
+			glEnable(GL_BLEND);
+			glEnable(GL_LINE_SMOOTH);
+
+			float eps = 1e-5f;
+			rv3d->viewquat[0] = -rv3d->viewquat[0];
+			const bool is_aligned = compare_v4v4(cursor->rotation, rv3d->viewquat, eps);
+			rv3d->viewquat[0] = -rv3d->viewquat[0];
+
+			/* Draw lines */
+			if  (is_aligned == false) {
+				uint pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+				immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
+				immUniformThemeColor3(TH_VIEW_OVERLAY);
+				immBegin(GWN_PRIM_LINES, 12);
+
+				const float scale = ED_view3d_pixel_size(rv3d, cursor->location) * U.dpi_fac * 20;
+
+#define CURSOR_VERT(axis_vec, axis, fac) \
+				immVertex3f( \
+				        pos, \
+				        cursor->location[0] + axis_vec[0] * (fac), \
+				        cursor->location[1] + axis_vec[1] * (fac), \
+				        cursor->location[2] + axis_vec[2] * (fac))
+
+#define CURSOR_EDGE(axis_vec, axis, sign) { \
+					CURSOR_VERT(axis_vec, axis, sign 1.0f); \
+					CURSOR_VERT(axis_vec, axis, sign 0.3f); \
+				}
+
+				for (int axis = 0; axis < 3; axis++) {
+					float axis_vec[3] = {0};
+					axis_vec[axis] = scale;
+					mul_qt_v3(cursor->rotation, axis_vec);
+					CURSOR_EDGE(axis_vec, axis, +);
+					CURSOR_EDGE(axis_vec, axis, -);
+				}
+
+#undef CURSOR_VERT
+#undef CURSOR_EDGE
+
+				immEnd();
+				immUnbindProgram();
+			}
 
 			ED_region_pixelspace(ar);
 			gpuTranslate2f(co[0] + 0.5f, co[1] + 0.5f);
 			gpuScale2f(U.widget_unit, U.widget_unit);
 
-			Gwn_Batch *cursor_batch = DRW_cache_cursor_get();
+			Gwn_Batch *cursor_batch = DRW_cache_cursor_get(is_aligned);
 			GPUShader *shader = GPU_shader_get_builtin_shader(GPU_SHADER_2D_FLAT_COLOR);
 			GWN_batch_program_set(cursor_batch, GPU_shader_get_program(shader), GPU_shader_get_interface(shader));
 
-			/* Draw nice Anti Aliased cursor. */
-			glLineWidth(1.0f);
-			glEnable(G

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list