#70267 Retopology Overlay #104599

Merged
Clément Foucault merged 30 commits from bonj/blender:retopology-overlay into main 2023-03-03 00:35:56 +01:00
8 changed files with 55 additions and 13 deletions
Showing only changes of commit 63f58db6ae - Show all commits

View File

@ -6550,7 +6550,11 @@ class VIEW3D_PT_overlay_edit_mesh_shading(Panel):
col = layout.column()
col.active = display_all
col.prop(overlay, "show_occlude_wire")
row = col.row(align=True)
row.prop(overlay, "show_retopology", text="")
sub = row.row()
sub.active = overlay.show_retopology
sub.prop(overlay, "retopology_bias", text="Retopology")
col.prop(overlay, "show_weight", text="Vertex Group Weights")
if overlay.show_weight:

View File

@ -2981,7 +2981,7 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain)
enum { V3D_OCCLUDE_WIRE = (1 << 14) };
View3D *v3d = (View3D *)sl;
if (v3d->flag2 & V3D_OCCLUDE_WIRE) {
v3d->overlay.edit_flag |= V3D_OVERLAY_EDIT_OCCLUDE_WIRE;
v3d->overlay.edit_flag |= V3D_OVERLAY_EDIT_RETOPOLOGY;
v3d->flag2 &= ~V3D_OCCLUDE_WIRE;
}
}

View File

@ -4013,6 +4013,20 @@ void blo_do_versions_300(FileData *fd, Library * /*lib*/, Main *bmain)
* \note Keep this message at the bottom of the function.
*/
{
/* Z bias for retopology overlay. */
if (!DNA_struct_elem_find(fd->filesdna, "View3DOverlay", "float", "retopology_bias")) {
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.retopology_bias = 0.2f;
}
}
}
}
}
/* Keep this block, even when empty. */
}
}

View File

@ -58,10 +58,13 @@ void OVERLAY_edit_mesh_cache_init(OVERLAY_Data *vedata)
bool select_face = pd->edit_mesh.select_face = (tsettings->selectmode & SCE_SELECT_FACE) != 0;
bool select_edge = pd->edit_mesh.select_edge = (tsettings->selectmode & SCE_SELECT_EDGE) != 0;
bool do_occlude_wire = (v3d->overlay.edit_flag & V3D_OVERLAY_EDIT_OCCLUDE_WIRE) != 0;
bool show_face_dots = (v3d->overlay.edit_flag & V3D_OVERLAY_EDIT_FACE_DOT) != 0 ||
pd->edit_mesh.do_zbufclip;
float retopology_bias = ((v3d->overlay.edit_flag & V3D_OVERLAY_EDIT_RETOPOLOGY) != 0) ?
(v3d->overlay.retopology_bias * v3d->clip_start) :
0.0;
bonj marked this conversation as resolved
Review

Just a small tweak.
Use max_ff(v3d->overlay.retopology_offset, FLT_EPSILON) and remove comment as this is then cleaner in the code.

Just a small tweak. Use `max_ff(v3d->overlay.retopology_offset, FLT_EPSILON)` and remove comment as this is then cleaner in the code.
Review

Makes sense, I'll do that.

Makes sense, I'll do that.
pd->edit_mesh.do_faces = true;
pd->edit_mesh.do_edges = true;
@ -94,7 +97,7 @@ void OVERLAY_edit_mesh_cache_init(OVERLAY_Data *vedata)
}
float backwire_opacity = (pd->edit_mesh.do_zbufclip) ? v3d->overlay.backwire_opacity : 1.0f;
float face_alpha = (do_occlude_wire || !pd->edit_mesh.do_faces) ? 0.0f : 1.0f;
float face_alpha = (!pd->edit_mesh.do_faces) ? 0.0f : 1.0f;
GPUTexture **depth_tex = (pd->edit_mesh.do_zbufclip) ? &dtxl->depth : &txl->dummy_depth_tx;
/* Run Twice for in-front passes. */
@ -104,7 +107,9 @@ void OVERLAY_edit_mesh_cache_init(OVERLAY_Data *vedata)
DRW_PASS_CREATE(psl->edit_mesh_depth_ps[i], state | pd->clipping_state);
bonj marked this conversation as resolved

Style: Prefer:

if (show_retopology) {
  /* Do not cull backfaces for retopology. This is because [insert explanation here] */
  state &= ~DRW_STATE_CULL_BACK;
}
Style: Prefer: ``` if (show_retopology) { /* Do not cull backfaces for retopology. This is because [insert explanation here] */ state &= ~DRW_STATE_CULL_BACK; }
Review

Added an if block and explanation, as discussed in DMs.

Added an if block and explanation, as discussed in DMs.
sh = OVERLAY_shader_depth_only();
pd->edit_mesh_depth_grp[i] = DRW_shgroup_create(sh, psl->edit_mesh_depth_ps[i]);
grp = pd->edit_mesh_depth_grp[i] = DRW_shgroup_create(sh, psl->edit_mesh_depth_ps[i]);
DRW_shgroup_uniform_block(grp, "globalsBlock", G_draw.block_ubo);
DRW_shgroup_uniform_float_copy(grp, "retopologyBias", retopology_bias);
}
{
/* Normals */
@ -123,6 +128,7 @@ void OVERLAY_edit_mesh_cache_init(OVERLAY_Data *vedata)
(flag & V3D_OVERLAY_EDIT_CONSTANT_SCREEN_SIZE_NORMALS) != 0);
DRW_shgroup_uniform_float_copy(
grp, "normalScreenSize", v3d->overlay.normals_constant_screen_size);
DRW_shgroup_uniform_float_copy(grp, "retopologyBias", retopology_bias);
}
{
/* Mesh Analysis Pass */
@ -156,6 +162,7 @@ void OVERLAY_edit_mesh_cache_init(OVERLAY_Data *vedata)
DRW_shgroup_uniform_ivec4(grp, "dataMask", mask, 1);
DRW_shgroup_uniform_float_copy(grp, "alpha", face_alpha);
DRW_shgroup_uniform_bool_copy(grp, "selectFaces", select_face);
DRW_shgroup_uniform_float_copy(grp, "retopologyBias", retopology_bias);
}
if (do_zbufclip) {
@ -175,6 +182,7 @@ void OVERLAY_edit_mesh_cache_init(OVERLAY_Data *vedata)
DRW_shgroup_uniform_texture_ref(grp, "depthTex", depth_tex);
DRW_shgroup_uniform_bool_copy(grp, "selectEdges", pd->edit_mesh.do_edges || select_edge);
DRW_shgroup_uniform_bool_copy(grp, "do_smooth_wire", do_smooth_wire);
DRW_shgroup_uniform_float_copy(grp, "retopologyBias", retopology_bias);
/* Verts */
state |= DRW_STATE_WRITE_DEPTH;
@ -188,10 +196,12 @@ void OVERLAY_edit_mesh_cache_init(OVERLAY_Data *vedata)
DRW_shgroup_uniform_float_copy(grp, "alpha", backwire_opacity);
DRW_shgroup_uniform_texture_ref(grp, "depthTex", depth_tex);
DRW_shgroup_uniform_ivec4_copy(grp, "dataMask", vert_mask);
DRW_shgroup_uniform_float_copy(grp, "retopologyBias", retopology_bias);
sh = OVERLAY_shader_edit_mesh_skin_root();
grp = pd->edit_mesh_skin_roots_grp[i] = DRW_shgroup_create(sh, psl->edit_mesh_verts_ps[i]);
DRW_shgroup_uniform_block(grp, "globalsBlock", G_draw.block_ubo);
DRW_shgroup_uniform_float_copy(grp, "retopologyBias", retopology_bias);
}
/* Face-dots */
if (select_face && show_face_dots) {
@ -201,6 +211,7 @@ void OVERLAY_edit_mesh_cache_init(OVERLAY_Data *vedata)
DRW_shgroup_uniform_float_copy(grp, "alpha", backwire_opacity);
DRW_shgroup_uniform_texture_ref(grp, "depthTex", depth_tex);
DRW_shgroup_uniform_ivec4_copy(grp, "dataMask", vert_mask);
DRW_shgroup_uniform_float_copy(grp, "retopologyBias", retopology_bias);
DRW_shgroup_state_enable(grp, DRW_STATE_WRITE_DEPTH);
}
else {
@ -263,7 +274,8 @@ void OVERLAY_edit_mesh_cache_populate(OVERLAY_Data *vedata, Object *ob)
bool draw_as_solid = (ob->dt > OB_WIRE);
bool do_in_front = (ob->dtx & OB_DRAW_IN_FRONT) != 0;
bool do_occlude_wire = (pd->edit_mesh.flag & V3D_OVERLAY_EDIT_OCCLUDE_WIRE) != 0;
bool show_retopology = (pd->edit_mesh.flag & V3D_OVERLAY_EDIT_RETOPOLOGY) != 0 &&
pd->overlay.retopology_bias != 0.0;
bool do_show_mesh_analysis = (pd->edit_mesh.flag & V3D_OVERLAY_EDIT_STATVIS) != 0;
bool fnormals_do = (pd->edit_mesh.flag & V3D_OVERLAY_EDIT_FACE_NORMALS) != 0;
bool vnormals_do = (pd->edit_mesh.flag & V3D_OVERLAY_EDIT_VERT_NORMALS) != 0;
@ -276,7 +288,7 @@ void OVERLAY_edit_mesh_cache_populate(OVERLAY_Data *vedata, Object *ob)
}
}
if (do_occlude_wire || (do_in_front && draw_as_solid)) {
if (show_retopology || (do_in_front && draw_as_solid)) {
geom = DRW_cache_mesh_surface_get(ob);
DRW_shgroup_call_no_cull(pd->edit_mesh_depth_grp[do_in_front], geom, ob);
}

View File

@ -188,7 +188,8 @@ bool DRW_object_is_renderable(const Object *ob)
if (ob->type == OB_MESH) {
if ((ob == DST.draw_ctx.object_edit) || DRW_object_is_in_edit_mode(ob)) {
View3D *v3d = DST.draw_ctx.v3d;
if (v3d && v3d->overlay.edit_flag & V3D_OVERLAY_EDIT_OCCLUDE_WIRE) {
if (v3d && (v3d->overlay.edit_flag & V3D_OVERLAY_EDIT_RETOPOLOGY) &&
v3d->overlay.retopology_bias != 0.0) {
return false;
}
}

View File

@ -39,6 +39,7 @@
.flag = V3D_OVERLAY_VIEWER_ATTRIBUTE | V3D_OVERLAY_SCULPT_SHOW_MASK | V3D_OVERLAY_SCULPT_SHOW_FACE_SETS, \
.wireframe_threshold = 1.0f, \
.wireframe_opacity = 1.0f, \
.retopology_bias = 0.2f, \
.viewer_attribute_opacity = 1.0f, \
.xray_alpha_bone = 0.5f, \
.bone_wire_alpha = 1.0f, \

View File

@ -214,7 +214,6 @@ typedef struct View3DOverlay {
/** Armature edit/pose mode settings. */
float xray_alpha_bone;
float bone_wire_alpha;
char _pad1[4];
/** Darken Inactive. */
float fade_alpha;
@ -222,6 +221,7 @@ typedef struct View3DOverlay {
/** Other settings. */
float wireframe_threshold;
float wireframe_opacity;
float retopology_bias;
/** Grease pencil settings. */
float gpencil_paper_opacity;
@ -560,7 +560,7 @@ enum {
V3D_OVERLAY_EDIT_LOOP_NORMALS = (1 << 1),
V3D_OVERLAY_EDIT_FACE_NORMALS = (1 << 2),
V3D_OVERLAY_EDIT_OCCLUDE_WIRE = (1 << 3),
V3D_OVERLAY_EDIT_RETOPOLOGY = (1 << 3),
V3D_OVERLAY_EDIT_WEIGHT = (1 << 4),

View File

@ -4527,9 +4527,19 @@ static void rna_def_space_view3d_overlay(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Show Weights", "Display weights in editmode");
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
prop = RNA_def_property(srna, "show_occlude_wire", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "overlay.edit_flag", V3D_OVERLAY_EDIT_OCCLUDE_WIRE);
RNA_def_property_ui_text(prop, "Hidden Wire", "Use hidden wireframe display");
prop = RNA_def_property(srna, "show_retopology", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "overlay.edit_flag", V3D_OVERLAY_EDIT_RETOPOLOGY);
RNA_def_property_ui_text(prop, "Retopology", "Use retopology display");
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D | NS_VIEW3D_SHADING, NULL);
prop = RNA_def_property(srna, "retopology_bias", PROP_FLOAT, PROP_FACTOR);
bonj marked this conversation as resolved

Now that we fixed the bias equation, the property types should be PROP_DISTANCE.

You will loose the ability to see the blue fill bar but it will be much explicit that this value is in distance unit.

You might have to adjust the sensitivity to have kind of the same drag feeling as when it was a factor.
And bump the soft max to 2 or 10 (seems nicer to discover that this isn't clamped).
This is what control those RNA_def_property_ui_range(prop, 0.0f, 1.0f, 0.1f, 3);.

Now that we fixed the bias equation, the property types should be `PROP_DISTANCE`. You will loose the ability to see the blue fill bar but it will be much explicit that this value is in distance unit. You might have to adjust the sensitivity to have kind of the same drag feeling as when it was a factor. And bump the soft max to 2 or 10 (seems nicer to discover that this isn't clamped). This is what control those `RNA_def_property_ui_range(prop, 0.0f, 1.0f, 0.1f, 3);`.
Review

Made it PROP_DISTANCE and upped the soft max to 10.
I think 0.1 step and 3 digits still feels good so I'll leave those the same.

Made it PROP_DISTANCE and upped the soft max to 10. I think 0.1 step and 3 digits still feels good so I'll leave those the same.
RNA_def_property_float_sdna(prop, NULL, "overlay.retopology_bias");
RNA_def_property_ui_text(prop,
bonj marked this conversation as resolved

Replace description by Offset used to draw the edit mesh in front of other geometry.

Maybe @JulienKaspar can agree this is clearer? Z Bias is too technical in my opinion.

Replace description by `Offset used to draw the edit mesh in front of other geometry`. Maybe @JulienKaspar can agree this is clearer? `Z Bias` is too technical in my opinion.
Review

I agree. I'll rename it to retopology offset everywhere.

I agree. I'll rename it to retopology offset everywhere.
"Retopology Bias",
bonj marked this conversation as resolved

Max should be FLT_MAX. Arbitrary limits like these are not good.

Max should be FLT_MAX. Arbitrary limits like these are not good.
Review

Done.

Done.
"Z Bias used to draw edit mesh in front "
"(0.0 to disable)");
RNA_def_property_range(prop, 0.0f, 1.0f);
RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D | NS_VIEW3D_SHADING, NULL);
prop = RNA_def_property(srna, "show_face_normals", PROP_BOOLEAN, PROP_NONE);