Fix #120239: Snap in edit mode is ignoring some self elements #120270

Merged
Germano Cavalcante merged 12 commits from mano-wii/blender:fix_120239 into main 2024-04-18 16:48:32 +02:00

Caused by commit 1c77779160, where we start creating a mesh
representing the edited mesh.

Mesh Snap to Vertex works in the following order:

  • Snap to vertices of visible triangles
  • Snap to vertices of Loose Edges
  • Snap to Loose Vertices

The problem occurs because, in editing mode, we ignore faces whose
vertices are being transformed. We mark this face as being hidden in
the snap. Consequently, we lose some vertices in triangles.

The solution is to consider the edges and vertices of hidden faces as
loose elements since, although connected to faces, they are still
visible to snap.

Therefore, two new types of BVHTree were created:

  • BVHTREE_FROM_LOOSEVERTS_NO_HIDDEN
  • BVHTREE_FROM_LOOSEEDGES_NO_HIDDEN

The disadvantage of this solution is that we can no longer rely on
cached mesh->loose_verts() and mesh->loose_edges() which can be bad
for performance.

Caused by commit 1c77779160, where we start creating a mesh representing the edited mesh. Mesh Snap to Vertex works in the following order: - Snap to vertices of visible triangles - Snap to vertices of Loose Edges - Snap to Loose Vertices The problem occurs because, in editing mode, we ignore faces whose vertices are being transformed. We mark this face as being hidden in the snap. Consequently, we lose some vertices in triangles. The solution is to consider the edges and vertices of hidden faces as loose elements since, although connected to faces, they are still visible to snap. Therefore, two new types of BVHTree were created: - BVHTREE_FROM_LOOSEVERTS_NO_HIDDEN - BVHTREE_FROM_LOOSEEDGES_NO_HIDDEN ~~The disadvantage of this solution is that we can no longer rely on cached `mesh->loose_verts()` and `mesh->loose_edges()` which can be bad for performance.~~
Germano Cavalcante added 1 commit 2024-04-04 19:42:40 +02:00
7e8aa02c72 Fix #120239: Snap in edit mode ignoring some elements
Caused by 1c77779160 when we create a mesh representing the edited
mesh.

Caused by 1c77779160 when we create a mesh representing the edited
mesh.

Mesh Snap to Vertex works in the following order:
- Snap to vertices of visible triangles
- Snap to vertices of Loose Edges
- Snap to Loose Vertices

The problem happens because, in editing mode, we ignore faces whose
vertices are being transformed. We mark this face as being hidden in
the snap. So we lost some vertices in triangles.

The solution then is to consider the edges and vertices of hidden faces
as loose elements, because, although connected to faces, they are still
visible to snap.

Therefore, two new types of BVHTree were created:
- BVHTREE_FROM_LOOSEVERTS_NO_HIDDEN
- BVHTREE_FROM_LOOSEEDGES_NO_HIDDEN

The disadvantage of this solution is that we can no longer rely on
cached `mesh->loose_verts()` and `mesh->loose_edges()` which can be bad
for performance.
Germano Cavalcante requested review from Hans Goudey 2024-04-04 19:42:57 +02:00
Author
Member

Tagging @HooglyBoogly as reviewer because:

  • reviewed the PR from the mentioned commit
  • have worked on this BVHTree Utils code before.
  • was involved in creating the loose elements cache API.
Tagging @HooglyBoogly as reviewer because: - reviewed the PR from the mentioned commit - have worked on this BVHTree Utils code before. - was involved in creating the loose elements cache API.
Germano Cavalcante added 1 commit 2024-04-04 20:50:23 +02:00
Germano Cavalcante added 1 commit 2024-04-05 02:43:38 +02:00
Germano Cavalcante added 1 commit 2024-04-05 02:58:06 +02:00
Germano Cavalcante added 3 commits 2024-04-07 17:32:43 +02:00
Germano Cavalcante added 2 commits 2024-04-17 16:37:15 +02:00
buildbot/vexp-code-patch-lint Build done. Details
buildbot/vexp-code-patch-linux-x86_64 Build done. Details
buildbot/vexp-code-patch-darwin-x86_64 Build done. Details
buildbot/vexp-code-patch-windows-amd64 Build done. Details
buildbot/vexp-code-patch-darwin-arm64 Build done. Details
buildbot/vexp-code-patch-coordinator Build done. Details
2f8482ebb5
Split Fixes: Fix only the trasnforming edit mesh case
Author
Member

@blender-bot build

@blender-bot build
Hans Goudey requested changes 2024-04-18 14:36:07 +02:00
Dismissed
@ -783,0 +800,4 @@
if (hide_edge[i]) {
continue;
}
for (const int vert_index : {edges[i][0], edges[i][1]}) {
Member

vert_index -> vert
Just a shorter name that gets the same thing across. Conceptually a vertex is just an index in these arrays anyway

`vert_index` -> `vert` Just a shorter name that gets the same thing across. Conceptually a vertex is just an index in these arrays anyway
mano-wii marked this conversation as resolved
@ -783,0 +831,4 @@
AttributeAccessor attributes = mesh.attributes();
const OffsetIndices<int> &faces = mesh.faces();
const Span<int> &corner_edges = mesh.corner_edges();
const VArray<bool> &hide_poly = *attributes.lookup_or_default(
Member
  • Remove references here. All these functions return by value.
  • Add const for the attribute accessor
- Remove references here. All these functions return by value. - Add `const` for the attribute accessor
mano-wii marked this conversation as resolved
@ -783,0 +840,4 @@
if (hide_poly[i]) {
continue;
}
for (const int corner_index : faces[i]) {
Member

for (const int edge : corner_edges.slice(faces[i])) {

`for (const int edge : corner_edges.slice(faces[i])) {`
mano-wii marked this conversation as resolved
@ -857,2 +938,2 @@
case BVHTREE_FROM_LOOSEVERTS: {
const LooseVertCache &loose_verts = mesh->loose_verts();
case BVHTREE_FROM_VERTS:
case BVHTREE_FROM_LOOSEVERTS:
Member

Better keep the existing switch statements as is. Duplicating some code is better than the spaghetti logic happening here now.

Better keep the existing switch statements as is. Duplicating some code is better than the spaghetti logic happening here now.
mano-wii marked this conversation as resolved
@ -869,0 +960,4 @@
int mask_bits_act_len = -1;
BitSpan mask = {};
BitVector<> mask_stack;
if (bvh_cache_type == BVHTREE_FROM_LOOSEEDGES_NO_HIDDEN) {
Member

Same here

Same here
mano-wii marked this conversation as resolved
@ -425,3 +425,3 @@
}
static eSnapMode mesh_snap_mode_supported(const Mesh *mesh)
static eSnapMode mesh_snap_mode_supported(const Mesh *mesh, const bool is_from_edit_mesh)
Member

Better name is_from_edit_mesh something a bit more specific like skip_hidden. Otherwise it becomes a catch-all for changing the behavior of this function in arbitrary ways

Better name `is_from_edit_mesh` something a bit more specific like `skip_hidden`. Otherwise it becomes a catch-all for changing the behavior of this function in arbitrary ways
mano-wii marked this conversation as resolved
Germano Cavalcante added 2 commits 2024-04-18 16:23:03 +02:00
Author
Member

Changes made.

Given that the parameters is_from_edit_mesh and use_hide serve the same purpose of skipping hidden elements, I combined them once again and renamed it to skip_hidden for better clarity.

With this modification, both related issues (snapping to edit mesh for vertices and edges of a face being transformed and snapping to mesh with hidden loose elements) are addressed simultaneously.

Optionally, we could address the first issue separately by generating the BVHTrees within the snap system itself. These BVHTrees would be stored in a SnapCache_EditMesh *em_cache, which would then be passed as a parameter to the snap to Mesh function (snap_object_mesh). This would allow snap_object_mesh to utilize these BVHTrees instead of storing them in the Mesh itself.

The drawback of this approach is that resolving the other issue (snapping to mesh with hidden loose elements) would require creating the same BVHTree and storing it in the Mesh cache, essentially redoing the actual code in this PR.

Changes made. Given that the parameters `is_from_edit_mesh` and `use_hide` serve the same purpose of skipping hidden elements, I combined them once again and renamed it to `skip_hidden` for better clarity. With this modification, both related issues (snapping to edit mesh for vertices and edges of a face being transformed and snapping to mesh with hidden loose elements) are addressed simultaneously. Optionally, we could address the first issue separately by generating the BVHTrees within the snap system itself. These BVHTrees would be stored in a `SnapCache_EditMesh *em_cache`, which would then be passed as a parameter to the snap to Mesh function (`snap_object_mesh`). This would allow `snap_object_mesh` to utilize these BVHTrees instead of storing them in the `Mesh` itself. The drawback of this approach is that resolving the other issue (snapping to mesh with hidden loose elements) would require creating the same BVHTree and storing it in the `Mesh` cache, essentially redoing the actual code in this PR.
Hans Goudey approved these changes 2024-04-18 16:25:42 +02:00
Germano Cavalcante added 1 commit 2024-04-18 16:37:50 +02:00
Germano Cavalcante merged commit 3fc29d8080 into main 2024-04-18 16:48:32 +02:00
Germano Cavalcante deleted branch fix_120239 2024-04-18 16:48:35 +02:00
Sign in to join this conversation.
No reviewers
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 project
No Assignees
2 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#120270
No description provided.