Edit Dyntopo Detail Size: Add resolution value for visual feedback #106243

Open
opened 2023-03-28 20:39:21 +02:00 by Julien Kaspar · 15 comments
Member

(NOTE) This task is part of the community & sub tasks of the workboard. Anyone is free to pick up this task and contribute. For any questions or needed reviewers, please tag @Sergey @HooglyBoogly and @JulienKaspar.

Resolution Value in the Viewport

(The initial solution of adding the resolution value to the header was already implemented with #118403)

To match the viewport overlay of object.voxel_size_edit, the dyntopo equivalent SCULPT_OT_dyntopo_detail_size_edit should get a resolution value next to the grid, outside of the brush cursor.

Screenshot_20230328_203346.png

(NOTE) This task is part of the community & sub tasks of the workboard. Anyone is free to pick up this task and contribute. For any questions or needed reviewers, please tag @Sergey @HooglyBoogly and @JulienKaspar. ## Resolution Value in the Viewport (The initial solution of adding the resolution value to the header was already implemented with #118403) To match the viewport overlay of `object.voxel_size_edit`, the dyntopo equivalent `SCULPT_OT_dyntopo_detail_size_edit` should get a resolution value next to the grid, outside of the brush cursor. ![Screenshot_20230328_203346.png](/attachments/9505861e-1c65-4f73-8093-3399051eaee2)
Julien Kaspar added the
Type
To Do
label 2023-03-28 20:39:21 +02:00
Julien Kaspar added this to the Sculpt, Paint & Texture project 2023-03-28 20:39:22 +02:00
Julien Kaspar changed title from Edit Dyntopo Detail Size: Add value to overlay to Edit Dyntopo Detail Size: Add resolution value for visual feedback 2023-03-28 20:39:54 +02:00
Julien Kaspar added the
Meta
Good First Issue
label 2023-03-28 20:40:42 +02:00

@JulienKaspar since no one has picked it up yet, can I pick it up as my first issue?

@JulienKaspar since no one has picked it up yet, can I pick it up as my first issue?
Author
Member

@Abhiyankar-Shakti Sure, go ahead 👍

@Abhiyankar-Shakti Sure, go ahead 👍

@JulienKaspar It would be really helpful if you can elaborate on the issue and guide with some technicalities to help me get started with.

@JulienKaspar It would be really helpful if you can elaborate on the issue and guide with some technicalities to help me get started with.
Julien Kaspar added the
Module
Sculpt, Paint & Texture
label 2023-04-06 13:52:24 +02:00
Author
Member

@Abhiyankar-Shakti Sorry for the late response! Do you have any questions on the task description? If anything is too unclear I'm happy to elaborate.

For technical questions it would be best to get in contact with @JosephEagar here or via blender.chat. He can give some needed pointers and help.

@Abhiyankar-Shakti Sorry for the late response! Do you have any questions on the task description? If anything is too unclear I'm happy to elaborate. For technical questions it would be best to get in contact with @JosephEagar here or via blender.chat. He can give some needed pointers and help.

Like I wanted to know if you wanted to see the resolution size in the viewport itself? Like shown in the second picture? It would be really helpful if you can elaborate.

Like I wanted to know if you wanted to see the resolution size in the viewport itself? Like shown in the second picture? It would be really helpful if you can elaborate.

@JosephEagar it would be really helpful if you can help with some technicalities that are required to achieve this.

@JosephEagar it would be really helpful if you can help with some technicalities that are required to achieve this.
Author
Member

The most important implementation would be to include the resolution value in the header (Like when executing any other modal operator in object/edit mode).

The secondary implementation is to add it in the viewport which is not that clear yet. I added a mockup below.
The idea would be to:

  • Keep the text size relative to the screen space just like with the voxel remesher
  • Position the text above the top edge of the triangular overlay
  • Align the text rotation with the top edge of the overlay, but have the text face the view for readability

The issue with this is that the triangle overlay rotation can sometimes not be ideal for this. So for this to work we should also try to force the top edge of the triangle to always be perfectly horizontal to have the text always readable.

The most important implementation would be to include the resolution value in the header (Like when executing any other modal operator in object/edit mode). The secondary implementation is to add it in the viewport which is not that clear yet. I added a mockup below. The idea would be to: - Keep the text size relative to the screen space just like with the voxel remesher - Position the text above the top edge of the triangular overlay - Align the text rotation with the top edge of the overlay, but have the text face the view for readability The issue with this is that the triangle overlay rotation can sometimes not be ideal for this. So for this to work we should also try to force the top edge of the triangle to always be perfectly horizontal to have the text always readable.
Author
Member

Waiting for @JosephEagar on what he thinks and how this can be done.

Waiting for @JosephEagar on what he thinks and how this can be done.
Member

This is pretty simple, you can use the existing OBJECT_OT_voxel_size_edit operator code (in source/blender/editors/object/object_remesh.cc) as a template. The bug difference is how you build the text matrix. For that you need to build an orthonormal basis from the surface normal and the view vector:

cross_v3_v3v3(mat[0], view_normal, sculpt_normal);
cross_v3_v3v3(mat[1], view_normal);
copy_v3_v3(mat[2], view_normal);

Note: you also have to check if the x and y axes need to be flipped. See how the code in voxel_size_edit_invoke does this. voxel_size_edit_invoke projects to one of the face of the bounding box cube (not the view normal) but is otherwise similar.

This is pretty simple, you can use the existing `OBJECT_OT_voxel_size_edit` operator code (in `source/blender/editors/object/object_remesh.cc`) as a template. The bug difference is how you build the text matrix. For that you need to build an orthonormal basis from the surface normal and the view vector: <pre> cross_v3_v3v3(mat[0], view_normal, sculpt_normal); cross_v3_v3v3(mat[1], view_normal); copy_v3_v3(mat[2], view_normal); </pre> Note: you also have to check if the x and y axes need to be flipped. See how the code in `voxel_size_edit_invoke` does this. `voxel_size_edit_invoke` projects to one of the face of the bounding box cube (not the view normal) but is otherwise similar.
Member

BTW, if you want to scale the grid to always have a fixed viewport size you do something like this:

float constant_viewport_scale_factor(bContext *C, float mouse[2]) {
  Object *ob = CTX_data_active_object(C);
  RegionView3D *rv3d = CTX_wm_region_view3d(C);
  ARegion *region = CTX_wm_region(C);
  SculptSession *ss = ob->sculpt;

  /* Get viewport projection matrix. */
  float projection_mat[4][4];
  ED_view3d_ob_project_mat_get(rv3d, ob, projection_mat);

  /* We need the viewport size. */
  float viewport_size[2] = {region->winx, region->winy};

  /* Get cursor location. */
   SculptCursorGeometryInfo sgi;
   SCULPT_cursor_geometry_info_update(C, &sgi, mouse, false);

  float location[4];
  copy_v3_v3(location, sgi.location);
  location[3] = 1.0f;
  
  /* Project location. */
  mul_m4_v4(location, ob->object_to_world);
  mul_m4_v4(location, projection_mat);

  /* Scale factor is just the w coordination of projected location vector scaled 
      by the longest viewport axis, IIRC. */
  int axis = viewport_size[0] > viewport_size[1] ? 0 : 1;
  float scale = location[3] / viewport_size[axis] * 0.5f; /* Not sure if 0.5f is correct. */

  /* Note: you may need to multiply scale by a DPI factor, not sure. */
  return scale;
}
BTW, if you want to scale the grid to always have a fixed viewport size you do something like this: <pre> float constant_viewport_scale_factor(bContext *C, float mouse[2]) { Object *ob = CTX_data_active_object(C); RegionView3D *rv3d = CTX_wm_region_view3d(C); ARegion *region = CTX_wm_region(C); SculptSession *ss = ob->sculpt; /* Get viewport projection matrix. */ float projection_mat[4][4]; ED_view3d_ob_project_mat_get(rv3d, ob, projection_mat); /* We need the viewport size. */ float viewport_size[2] = {region->winx, region->winy}; /* Get cursor location. */ SculptCursorGeometryInfo sgi; SCULPT_cursor_geometry_info_update(C, &sgi, mouse, false); float location[4]; copy_v3_v3(location, sgi.location); location[3] = 1.0f; /* Project location. */ mul_m4_v4(location, ob->object_to_world); mul_m4_v4(location, projection_mat); /* Scale factor is just the w coordination of projected location vector scaled by the longest viewport axis, IIRC. */ int axis = viewport_size[0] > viewport_size[1] ? 0 : 1; float scale = location[3] / viewport_size[axis] * 0.5f; /* Not sure if 0.5f is correct. */ /* Note: you may need to multiply scale by a DPI factor, not sure. */ return scale; } </pre>

This is really helpful, I will start working on a patch right away.

This is really helpful, I will start working on a patch right away.

@JosephEagar This is a function that I wrote using the OBJECT_OT_voxel_size_edit operator code as a template.

void OBJECT_OT_voxel_size_display(wmOperatorType *ot)
{
  VoxelSizeEditCustomData *cd = MEM_cnew<VoxelSizeEditCustomData>(
      "Voxel Size Edit OP Custom Data");

  float view_normal[3] = {0.0f, 0.0f, 1.0f};
  float sculpt_normal[3] = {};
  float mat[3][3];
  
  cross_v3_v3v3(cd->text_mat[0], view_normal, sculpt_normal);
  //cross_v3_v3v3(mat[1], view_normal);
  copy_v3_v3(cd->text_mat[2], view_normal);


  float d_a[3], d_b[3];
  float d_a_proj[2], d_b_proj[2];

  sub_v3_v3v3(d_a, cd->preview_plane[1], cd->preview_plane[0]);
  sub_v3_v3v3(d_b, cd->preview_plane[3], cd->preview_plane[0]);
  normalize_v3(d_a);
  normalize_v3(d_b);

  /* Project the X and Y axis. */
  normalize_v2(d_a_proj);
  normalize_v2(d_b_proj);

  /* Flip the X and Y basis vectors to make sure they always point upwards and to the right. */
  if (d_b_proj[0] < 0.0f) {
    mul_v3_fl(cd->text_mat[0], -1.0f);
  }
  if (d_a_proj[1] < 0.0f) {
    mul_v3_fl(cd->text_mat[1], -1.0f);
  }
}

I am not able to understand that where this should be called and what are the fixes that needs to be done.

@JosephEagar This is a function that I wrote using the OBJECT_OT_voxel_size_edit operator code as a template. ``` void OBJECT_OT_voxel_size_display(wmOperatorType *ot) { VoxelSizeEditCustomData *cd = MEM_cnew<VoxelSizeEditCustomData>( "Voxel Size Edit OP Custom Data"); float view_normal[3] = {0.0f, 0.0f, 1.0f}; float sculpt_normal[3] = {}; float mat[3][3]; cross_v3_v3v3(cd->text_mat[0], view_normal, sculpt_normal); //cross_v3_v3v3(mat[1], view_normal); copy_v3_v3(cd->text_mat[2], view_normal); float d_a[3], d_b[3]; float d_a_proj[2], d_b_proj[2]; sub_v3_v3v3(d_a, cd->preview_plane[1], cd->preview_plane[0]); sub_v3_v3v3(d_b, cd->preview_plane[3], cd->preview_plane[0]); normalize_v3(d_a); normalize_v3(d_b); /* Project the X and Y axis. */ normalize_v2(d_a_proj); normalize_v2(d_b_proj); /* Flip the X and Y basis vectors to make sure they always point upwards and to the right. */ if (d_b_proj[0] < 0.0f) { mul_v3_fl(cd->text_mat[0], -1.0f); } if (d_a_proj[1] < 0.0f) { mul_v3_fl(cd->text_mat[1], -1.0f); } } ``` I am not able to understand that where this should be called and what are the fixes that needs to be done.
Contributor

@Abhiyankar-Shakti Are you planning on continuing to work on this? If not, I'm planning on taking up the work soon.

Edit (2024-03-13): Not currently working on this at the moment, so this is free to be picked up by anyone else interested in working on the task.

~~@Abhiyankar-Shakti Are you planning on continuing to work on this? If not, I'm planning on taking up the work soon.~~ Edit (2024-03-13): Not currently working on this at the moment, so this is free to be picked up by anyone else interested in working on the task.
Contributor

@JulienKaspar - now that #118403 is merged in, should this task still always show the corresponding "resolution" value or should it show the value being edited within the viewport?

Additionally, I think this task can be clarified as addressing the second viewport solution now, since the operator now displays the value in the status bar with the previously mentioned PR.

@JulienKaspar - now that #118403 is merged in, should this task still always show the corresponding "resolution" value or should it show the value being edited within the viewport? Additionally, I think this task can be clarified as addressing the second viewport solution now, since the operator now displays the value in the status bar with the previously mentioned PR.
Author
Member

@Sean-Kim Yes, now this task is only about showing the value next to the preview grid.
I'm not sure if this will work as expected but in that case it's already great to have the value in the header in main.
I'll update the task descriptions 👍

@Sean-Kim Yes, now this task is only about showing the value next to the preview grid. I'm not sure if this will work as expected but in that case it's already great to have the value in the header in `main`. I'll update the task descriptions 👍
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No Assignees
4 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#106243
No description provided.