diff options
author | Jeroen Bakker <jeroen@blender.org> | 2021-08-04 11:52:51 +0300 |
---|---|---|
committer | Jeroen Bakker <jeroen@blender.org> | 2021-08-04 11:55:05 +0300 |
commit | cb67bfdba2e22d0ee967e50afe0912ac80d73e9b (patch) | |
tree | 73062214d0be9135b3b56a863a68d1732523daa5 | |
parent | 218df9941097bf973485ac343c070bdc6641a539 (diff) |
Viewport normal drawing with constant length
Patch for: T37878
{F10169694}
Reviewed By: fclem
Differential Revision: https://developer.blender.org/D11487
17 files changed, 81 insertions, 4 deletions
diff --git a/release/datafiles/alert_icons.png b/release/datafiles/alert_icons.png Binary files differindex e1cb671713f..0add7a3ccf8 100644 --- a/release/datafiles/alert_icons.png +++ b/release/datafiles/alert_icons.png diff --git a/release/datafiles/blender_icons.svg b/release/datafiles/blender_icons.svg index f894ca3f298..54357550847 100644 --- a/release/datafiles/blender_icons.svg +++ b/release/datafiles/blender_icons.svg @@ -17301,6 +17301,11 @@ d="m 1800,348 h 3 v 14 h -3 z m -4,7 h 16 v 3 h -16 z" inkscape:connector-curvature="0" /> </g> + <path + style="color:#000000;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:medium;line-height:normal;font-family:sans-serif;font-variant-ligatures:normal;font-variant-position:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-alternates:normal;font-feature-settings:normal;text-indent:0;text-align:start;text-decoration:none;text-decoration-line:none;text-decoration-style:solid;text-decoration-color:#000000;letter-spacing:normal;word-spacing:normal;text-transform:none;writing-mode:lr-tb;direction:ltr;text-orientation:mixed;dominant-baseline:auto;baseline-shift:baseline;text-anchor:start;white-space:normal;shape-padding:0;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:0.98999999;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;vector-effect:none;fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:1;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:new" + d="m 418.85321,140.04954 -2.82,-2.82 a 0.62,0.62 0 0 0 -0.4,-0.18 0.6,0.6 0 0 0 -0.6,0.6 0.62,0.62 0 0 0 0.18,0.43 l 1,1 -9.18,9.12 -1,-1 a 0.62,0.62 0 0 0 -0.4,-0.15 0.6,0.6 0 0 0 -0.6,0.6 0.62,0.62 0 0 0 0.18,0.4 l 2.82,2.82 a 0.6,0.6 0 0 0 0.82,-0.82 l -1,-1 9.18,-9.15 1,1 a 0.6,0.6 0 0 0 0.82,-0.85 z" + id="path3261" + inkscape:connector-curvature="0" /> </g> <g inkscape:groupmode="layer" diff --git a/release/datafiles/blender_icons16/icon16_fixed_size.dat b/release/datafiles/blender_icons16/icon16_fixed_size.dat Binary files differnew file mode 100644 index 00000000000..95a777e733f --- /dev/null +++ b/release/datafiles/blender_icons16/icon16_fixed_size.dat diff --git a/release/datafiles/blender_icons16/icon16_force_boid.dat b/release/datafiles/blender_icons16/icon16_force_boid.dat Binary files differindex 71f89bd7c04..f719054d84a 100644 --- a/release/datafiles/blender_icons16/icon16_force_boid.dat +++ b/release/datafiles/blender_icons16/icon16_force_boid.dat diff --git a/release/datafiles/blender_icons32/icon32_fixed_size.dat b/release/datafiles/blender_icons32/icon32_fixed_size.dat Binary files differnew file mode 100644 index 00000000000..a83e3755229 --- /dev/null +++ b/release/datafiles/blender_icons32/icon32_fixed_size.dat diff --git a/release/datafiles/blender_icons32/icon32_force_boid.dat b/release/datafiles/blender_icons32/icon32_force_boid.dat Binary files differindex 7fc7cb5ee8c..9043989024b 100644 --- a/release/datafiles/blender_icons32/icon32_force_boid.dat +++ b/release/datafiles/blender_icons32/icon32_force_boid.dat diff --git a/release/scripts/startup/bl_ui/space_view3d.py b/release/scripts/startup/bl_ui/space_view3d.py index df41445ee6f..20b706f5004 100644 --- a/release/scripts/startup/bl_ui/space_view3d.py +++ b/release/scripts/startup/bl_ui/space_view3d.py @@ -6386,7 +6386,13 @@ class VIEW3D_PT_overlay_edit_mesh_normals(Panel): sub = row.row(align=True) sub.active = overlay.show_vertex_normals or overlay.show_face_normals or overlay.show_split_normals - sub.prop(overlay, "normals_length", text="Size") + if overlay.use_normals_constant_screen_size: + sub.prop(overlay, "normals_constant_screen_size", text="Size") + else: + sub.prop(overlay, "normals_length", text="Size") + + row.prop(overlay, "use_normals_constant_screen_size", text="", icon='FIXED_SIZE') + class VIEW3D_PT_overlay_edit_mesh_freestyle(Panel): diff --git a/source/blender/blenloader/intern/versioning_300.c b/source/blender/blenloader/intern/versioning_300.c index f1f7f2edd35..7df4d2d93ec 100644 --- a/source/blender/blenloader/intern/versioning_300.c +++ b/source/blender/blenloader/intern/versioning_300.c @@ -708,5 +708,19 @@ void blo_do_versions_300(FileData *fd, Library *UNUSED(lib), Main *bmain) */ { /* Keep this block, even when empty. */ + + if (!DNA_struct_elem_find( + fd->filesdna, "View3DOverlay", "float", "normals_constant_screen_size")) { + LISTBASE_FOREACH (bScreen *, screen, &bmain->screens) { + LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) { + LISTBASE_FOREACH (SpaceLink *, sl, &area->spacedata) { + if (sl->spacetype == SPACE_VIEW3D) { + View3D *v3d = (View3D *)sl; + v3d->overlay.normals_constant_screen_size = 7.0f; + } + } + } + } + } } } diff --git a/source/blender/blenloader/intern/versioning_defaults.c b/source/blender/blenloader/intern/versioning_defaults.c index 7ff624b44da..82c577d11a0 100644 --- a/source/blender/blenloader/intern/versioning_defaults.c +++ b/source/blender/blenloader/intern/versioning_defaults.c @@ -190,6 +190,7 @@ static void blo_update_defaults_screen(bScreen *screen, } /* Disable Curve Normals. */ v3d->overlay.edit_flag &= ~V3D_OVERLAY_EDIT_CU_NORMALS; + v3d->overlay.normals_constant_screen_size = 7.0f; } else if (area->spacetype == SPACE_CLIP) { SpaceClip *sclip = area->spacedata.first; diff --git a/source/blender/draw/engines/overlay/overlay_edit_mesh.c b/source/blender/draw/engines/overlay/overlay_edit_mesh.c index a7ed6c777e8..3a2871249a2 100644 --- a/source/blender/draw/engines/overlay/overlay_edit_mesh.c +++ b/source/blender/draw/engines/overlay/overlay_edit_mesh.c @@ -132,6 +132,11 @@ void OVERLAY_edit_mesh_cache_init(OVERLAY_Data *vedata) DRW_shgroup_uniform_float_copy(grp, "normalSize", v3d->overlay.normals_length); DRW_shgroup_uniform_float_copy(grp, "alpha", backwire_opacity); DRW_shgroup_uniform_texture_ref(grp, "depthTex", depth_tex); + DRW_shgroup_uniform_bool_copy(grp, + "isConstantScreenSizeNormals", + (flag & V3D_OVERLAY_EDIT_CONSTANT_SCREEN_SIZE_NORMALS) != 0); + DRW_shgroup_uniform_float_copy( + grp, "normalScreenSize", v3d->overlay.normals_constant_screen_size); } { /* Mesh Analysis Pass */ diff --git a/source/blender/draw/engines/overlay/shaders/edit_mesh_normal_vert.glsl b/source/blender/draw/engines/overlay/shaders/edit_mesh_normal_vert.glsl index 007495f84e0..f649a5cb3ed 100644 --- a/source/blender/draw/engines/overlay/shaders/edit_mesh_normal_vert.glsl +++ b/source/blender/draw/engines/overlay/shaders/edit_mesh_normal_vert.glsl @@ -1,5 +1,7 @@ uniform float normalSize; +uniform float normalScreenSize; +uniform bool isConstantScreenSizeNormals; uniform sampler2D depthTex; uniform float alpha = 1.0; @@ -49,11 +51,25 @@ void main() } vec3 n = normalize(normal_object_to_world(nor)); - vec3 world_pos = point_object_to_world(pos); if (gl_VertexID == 0) { - world_pos += n * normalSize; + if (isConstantScreenSizeNormals) { + bool is_persp = (ProjectionMatrix[3][3] == 0.0); + if (is_persp) + { + float dist_fac = length(cameraPos - world_pos); + float cos_fac = dot(cameraForward, cameraVec(world_pos)); + world_pos += n * normalScreenSize * dist_fac * cos_fac * pixelFac * sizePixel; + } + else { + float frustrum_fac = mul_project_m4_v3_zfac(n) * sizePixel; + world_pos += n * normalScreenSize * frustrum_fac; + } + } + else { + world_pos += n * normalSize; + } } gl_Position = point_world_to_ndc(world_pos); diff --git a/source/blender/editors/datafiles/CMakeLists.txt b/source/blender/editors/datafiles/CMakeLists.txt index beb22d43930..4af6e1bdcb8 100644 --- a/source/blender/editors/datafiles/CMakeLists.txt +++ b/source/blender/editors/datafiles/CMakeLists.txt @@ -583,6 +583,7 @@ set(ICON_NAMES uv_facesel uv_islandsel uv_sync_select + fixed_size transform_origins gizmo orientation_cursor diff --git a/source/blender/editors/include/UI_icons.h b/source/blender/editors/include/UI_icons.h index 7ccdc49d291..eb893fbe029 100644 --- a/source/blender/editors/include/UI_icons.h +++ b/source/blender/editors/include/UI_icons.h @@ -715,7 +715,7 @@ DEF_ICON(UV_ISLANDSEL) DEF_ICON(UV_SYNC_SELECT) DEF_ICON_BLANK(240) DEF_ICON_BLANK(241) -DEF_ICON_BLANK(242) +DEF_ICON(FIXED_SIZE) DEF_ICON(TRANSFORM_ORIGINS) DEF_ICON(GIZMO) DEF_ICON(ORIENTATION_CURSOR) diff --git a/source/blender/makesdna/DNA_view3d_defaults.h b/source/blender/makesdna/DNA_view3d_defaults.h index 9dfc37e57b1..c4d0c83b346 100644 --- a/source/blender/makesdna/DNA_view3d_defaults.h +++ b/source/blender/makesdna/DNA_view3d_defaults.h @@ -71,6 +71,7 @@ .gpencil_paper_opacity = 0.5f, \ .gpencil_grid_opacity = 0.9f, \ .gpencil_vertex_paint_opacity = 1.0f, \ + .normals_constant_screen_size = 7.0f, \ } #define _DNA_DEFAULT_View3DCursor \ diff --git a/source/blender/makesdna/DNA_view3d_types.h b/source/blender/makesdna/DNA_view3d_types.h index 08b29c82707..4d88f6f0c15 100644 --- a/source/blender/makesdna/DNA_view3d_types.h +++ b/source/blender/makesdna/DNA_view3d_types.h @@ -204,6 +204,7 @@ typedef struct View3DOverlay { /** Edit mode settings. */ int edit_flag; float normals_length; + float normals_constant_screen_size; float backwire_opacity; /** Paint mode settings. */ @@ -238,6 +239,8 @@ typedef struct View3DOverlay { float gpencil_vertex_paint_opacity; /** Handles display type for curves. */ int handle_display; + + char _pad[4]; } View3DOverlay; /* View3DOverlay->handle_display */ @@ -551,6 +554,7 @@ enum { // V3D_OVERLAY_EDIT_CU_HANDLES = (1 << 20), V3D_OVERLAY_EDIT_CU_NORMALS = (1 << 21), + V3D_OVERLAY_EDIT_CONSTANT_SCREEN_SIZE_NORMALS = (1 << 22), }; /** #View3DOverlay.paint_flag */ diff --git a/source/blender/makesdna/DNA_view3d_types.h.rej b/source/blender/makesdna/DNA_view3d_types.h.rej new file mode 100644 index 00000000000..a62f1c4b7d3 --- /dev/null +++ b/source/blender/makesdna/DNA_view3d_types.h.rej @@ -0,0 +1,9 @@ +diff a/source/blender/makesdna/DNA_view3d_types.h b/source/blender/makesdna/DNA_view3d_types.h (rejected hunks) +@@ -550,6 +553,7 @@ + /* V3D_OVERLAY_EDIT_CU_HANDLES = (1 << 20), */ + + V3D_OVERLAY_EDIT_CU_NORMALS = (1 << 21), ++ V3D_OVERLAY_EDIT_CONSTANT_SCREEN_SIZE_NORMALS = (1 << 22), + }; + + /** #View3DOverlay.paint_flag */ diff --git a/source/blender/makesrna/intern/rna_space.c b/source/blender/makesrna/intern/rna_space.c index 796e62c8b2a..c7a5c43255a 100644 --- a/source/blender/makesrna/intern/rna_space.c +++ b/source/blender/makesrna/intern/rna_space.c @@ -4363,6 +4363,21 @@ static void rna_def_space_view3d_overlay(BlenderRNA *brna) RNA_def_property_float_default(prop, 0.02); RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL); + prop = RNA_def_property(srna, "normals_constant_screen_size", PROP_FLOAT, PROP_PIXEL); + RNA_def_property_float_sdna(prop, NULL, "overlay.normals_constant_screen_size"); + RNA_def_property_ui_text(prop, "Normal Screen Size", "Screen size for normals in the 3D view"); + RNA_def_property_range(prop, 0.0, 100000.0); + RNA_def_property_ui_range(prop, 1.0, 100.0, 50, 0); + RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL); + + prop = RNA_def_property(srna, "use_normals_constant_screen_size", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna( + prop, NULL, "overlay.edit_flag", V3D_OVERLAY_EDIT_CONSTANT_SCREEN_SIZE_NORMALS); + RNA_def_property_ui_text(prop, + "Constant Screen Size Normals", + "Keep size of normals constant in relation to 3D view"); + RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL); + prop = RNA_def_property(srna, "backwire_opacity", PROP_FLOAT, PROP_FACTOR); RNA_def_property_float_sdna(prop, NULL, "overlay.backwire_opacity"); RNA_def_property_ui_text(prop, "Backwire Opacity", "Opacity when rendering transparent wires"); |