Fix #108105: Fix operators affecting hidden geometry #119168

Open
Mangal Kushwah wants to merge 11 commits from Mangal-Kushwah/blender:operators-hidden-geometry into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
First-time contributor

Problem:
These operators in sculpt mode affect hidden geometry which is undesirable.

bpy.ops.sculpt.face_set_edit 
bpy.ops.sculpt.face_sets_init
bpy.ops.sculpt.face_sets_create(mode='SELECTION')
bpy.ops.mesh.paint_mask_extract()
bpy.ops.mesh.paint_mask_slice()

Solution:

This PR adds checks for hidden faces in these operators.

For operator bpy.ops.sculpt.face_sets_init it also modifies the way face sets indices were generated so generated indices is unique. This in needed so new initialized face sets do not get same indices as hidden face sets.
For generating unique face set index i have created a set container which stores hidden face sets indices. Before assigning indices to a face set it checks if it is already in set container, if it is then it'll keep increasing index by 1 until it is not in set container.

Modifying Operator bpy.ops.mesh.paint_mask_slice() is little complex, it will not affect hidden geometry only when fill holes option is unchecked, because currently filling hole code does not take hidden geometry into account and because of this in some cases hidden part of geometry can be trapped inside mesh.

Problem: These operators in sculpt mode affect hidden geometry which is undesirable. ``` bpy.ops.sculpt.face_set_edit bpy.ops.sculpt.face_sets_init bpy.ops.sculpt.face_sets_create(mode='SELECTION') bpy.ops.mesh.paint_mask_extract() bpy.ops.mesh.paint_mask_slice() ``` Solution: This PR adds checks for hidden faces in these operators. For operator `bpy.ops.sculpt.face_sets_init` it also modifies the way face sets indices were generated so generated indices is unique. This in needed so new initialized face sets do not get same indices as hidden face sets. For generating unique face set index i have created a set container which stores hidden face sets indices. Before assigning indices to a face set it checks if it is already in set container, if it is then it'll keep increasing index by 1 until it is not in set container. Modifying Operator `bpy.ops.mesh.paint_mask_slice()` is little complex, it will not affect hidden geometry only when fill holes option is unchecked, because currently filling hole code does not take hidden geometry into account and because of this in some cases hidden part of geometry can be trapped inside mesh.
Mangal Kushwah added 1 commit 2024-03-07 16:07:01 +01:00
Mangal Kushwah changed title from WIP Fix #108105: Fix operators that affect hidden geometry to WIP: Fix #108105: Fix operators that affect hidden geometry 2024-03-07 16:08:23 +01:00
Iliya Katushenock added this to the Sculpt, Paint & Texture project 2024-03-07 16:09:29 +01:00
Mangal Kushwah added 1 commit 2024-03-28 11:39:18 +01:00
475a313561 Ensure sculpt_face_sets_init_flood_fill() doesn't alter hidden face sets
This commit modify the sculpt_face_sets_init_flood_fill() so it doesn't
modify hidden geometry.
Author
First-time contributor

With this commit bpy.ops.sculpt.face_sets_init operations will not modify the hidden face sets, except Initialize Face Sets by Material.

I'm confused for Face Sets by Materials would it be better if it can modify hidden geometry?

With this commit `bpy.ops.sculpt.face_sets_init` operations will not modify the hidden face sets, except Initialize Face Sets by **Material**. I'm confused for Face Sets by Materials would it be better if it can modify hidden geometry?
Author
First-time contributor

I'm confused for Face Sets by Materials would it be better if it can modify hidden geometry?

@HooglyBoogly @Sergey @JulienKaspar.

> I'm confused for Face Sets by Materials would it be better if it can modify hidden geometry? @HooglyBoogly @Sergey @JulienKaspar.

Not sure why material case is special here. From the perspective of operators not modifying invisible data, it will just initialize face sets based on material slots for the visible geometry.

Not sure why material case is special here. From the perspective of operators not modifying invisible data, it will just initialize face sets based on material slots for the visible geometry.
Member

I'm confused for Face Sets by Materials would it be better if it can modify hidden geometry?

They should just follow the operator "Modify Hidden" option. And if there is no such option for an operator, hidden geometry should generally not be modified.

> I'm confused for Face Sets by Materials would it be better if it can modify hidden geometry? They should just follow the operator "Modify Hidden" option. And if there is no such option for an operator, hidden geometry should generally not be modified.
Mangal Kushwah added 3 commits 2024-03-29 14:40:18 +01:00
5ee36fe1f6 Ensure Intialize Face Set by Material doesn't alter hidden face sets
This add checks for hidden faces and also modify the face_set
index generation so that the face doesn't get the same face set
index as the hidden face_set.
Mangal Kushwah added 1 commit 2024-03-29 18:40:03 +01:00
c523317439 Ensure Mask Slice operations doesn't effect hidden faces
It will work only when fill_hole is not checked
Mangal Kushwah changed title from WIP: Fix #108105: Fix operators that affect hidden geometry to Fix #108105: Fix operators that affect hidden geometry 2024-03-29 18:41:28 +01:00
Mangal Kushwah changed title from Fix #108105: Fix operators that affect hidden geometry to Fix #108105: Fix operators affecting hidden geometry 2024-03-29 18:45:42 +01:00
Mangal Kushwah changed title from Fix #108105: Fix operators affecting hidden geometry to WIP: Fix #108105: Fix operators affecting hidden geometry 2024-03-29 18:46:28 +01:00
Mangal Kushwah changed title from WIP: Fix #108105: Fix operators affecting hidden geometry to Fix #108105: Fix operators affecting hidden geometry 2024-03-29 18:46:43 +01:00
Mangal Kushwah requested review from Sergey Sharybin 2024-03-29 18:48:01 +01:00
Mangal Kushwah requested review from Hans Goudey 2024-03-29 18:48:02 +01:00
Sergey Sharybin reviewed 2024-04-02 15:49:00 +02:00
Sergey Sharybin left a comment
Owner

Just some quick notes. Did not have time yet to verify the behavior on algorithmical level.

Just some quick notes. Did not have time yet to verify the behavior on algorithmical level.
@ -246,1 +246,4 @@
BMIter face_iter;
if (BM_elem_flag_test_bool(f, BM_ELEM_HIDDEN)) {
keep_face = false;
BM_elem_flag_set(f, BM_ELEM_TAG, !keep_face);

This can just be BM_elem_flag_set(f, BM_ELEM_TAG, true); ?

This can just be `BM_elem_flag_set(f, BM_ELEM_TAG, true);` ?
Author
First-time contributor

Done

Done
Mangal-Kushwah marked this conversation as resolved
@ -418,6 +423,9 @@ static void slice_paint_mask(BMesh *bm, bool invert, bool fill_holes, float mask
break;
}
}
if (!fill_holes && BM_elem_flag_test_bool(f, BM_ELEM_HIDDEN)) {

Why is the visibility only checked when !fill_holes ?

Why is the visibility only checked when `!fill_holes` ?
Author
First-time contributor

Currently filling hole code does not take hidden geometry into account and because of this in some cases hidden part of geometry can be trapped inside mesh which i assumed is bad thing not entirely sure though.

Currently filling hole code does not take hidden geometry into account and because of this in some cases hidden part of geometry can be trapped inside mesh which i assumed is bad thing not entirely sure though.
Author
First-time contributor

Removed it

Removed it
Mangal-Kushwah marked this conversation as resolved
@ -421,2 +427,4 @@
keep_face = false;
};
if (invert) {
keep_face = !keep_face;

This invert behavior is a bit fragile, as it potentially marks faces which are hidden. From reading the code it is seems fine from the current usages of this function. However, it worth:

  • Double-checking that Paint Mask Slice with hidden faces behaves correctly.
  • Adding a comment about it.

There might be some smarter and less error-prone we can do here, but I do not have quick concrete proposals.

This `invert` behavior is a bit fragile, as it potentially marks faces which are hidden. From reading the code it is seems fine from the current usages of this function. However, it worth: - Double-checking that `Paint Mask Slice` with hidden faces behaves correctly. - Adding a comment about it. There might be some smarter and less error-prone we can do here, but I do not have quick concrete proposals.
Author
First-time contributor

Will look into it tomorrow

Will look into it tomorrow
Author
First-time contributor

Added the comment about invert

Added the comment about invert
Mangal-Kushwah marked this conversation as resolved
@ -834,0 +862,4 @@
".hide_poly", bke::AttrDomain::Face, false);
const Array<int> prev_face_sets = duplicate_face_sets(*mesh);
Set<int> hidden_face_sets;
for (const int i : hide_poly.index_range()) {

Perhaps it will be more readable if the code is moved to gather_hidden_face_sets (or some similar name)? Currently the code seems to be duplicated between multiple operators.

Perhaps it will be more readable if the code is moved to `gather_hidden_face_sets` (or some similar name)? Currently the code seems to be duplicated between multiple operators.
Author
First-time contributor

Ok, Should I make it static?

Ok, Should I make it static?
Mangal-Kushwah marked this conversation as resolved
Mangal Kushwah added 2 commits 2024-04-03 17:57:16 +02:00
Author
First-time contributor

Why is the visibility only checked when !fill_holes ?

@Sergey I disabled visibility checks for fill holes because of this (check the video).

I have some question:

  • Is this a bad thing?

  • If yes, do you have any suggestions about how I should proceed?

Currently I'm thinking about modifying function responsible for filling holes so it takes hidden geometry into account.

> Why is the visibility only checked when `!fill_holes` ? @Sergey I disabled visibility checks for fill holes because of this (check the video). I have some question: - Is this a bad thing? - If yes, do you have any suggestions about how I should proceed? Currently I'm thinking about modifying function responsible for filling holes so it takes hidden geometry into account.

It might be worth involving input from @DanielBystedt.

To me intuitively the algorithm should give the same exact results as if the hidden part of the mesh simply did not exist at the time when an operator runs, and was added later. Hope the analogy is clear :) But not sure if it has some negative implications.

It might be worth involving input from @DanielBystedt. To me intuitively the algorithm should give the same exact results as if the hidden part of the mesh simply did not exist at the time when an operator runs, and was added later. Hope the analogy is clear :) But not sure if it has some negative implications.
Mangal Kushwah added 2 commits 2024-04-26 12:20:44 +02:00
Member

It might be worth involving input from @DanielBystedt.

To me intuitively the algorithm should give the same exact results as if the hidden part of the mesh simply did not exist at the time when an operator runs, and was added later. Hope the analogy is clear :) But not sure if it has some negative implications.

What @Sergey describes would be ideal (i.e. Hidden part of mesh is not deleted during the operation). I have included a visual "step by step" that should clarify things.

bild

> It might be worth involving input from @DanielBystedt. > > To me intuitively the algorithm should give the same exact results as if the hidden part of the mesh simply did not exist at the time when an operator runs, and was added later. Hope the analogy is clear :) But not sure if it has some negative implications. What @Sergey describes would be ideal (i.e. Hidden part of mesh is not deleted during the operation). I have included a visual "step by step" that should clarify things. ![bild](/attachments/52578279-561a-4756-b4c5-0e9263960425)
188 KiB
Author
First-time contributor

Thanks for visual explanation, It is working exactly like that.
I have manually tested it so far everything is working as expected.

Thanks for visual explanation✨, It is working exactly like that. I have manually tested it so far everything is working as expected.
Sergey Sharybin reviewed 2024-05-01 16:25:38 +02:00
@ -735,0 +742,4 @@
".hide_poly", bke::AttrDomain::Face, false);
const Array<int> prev_face_sets = duplicate_face_sets(*mesh);
Set<int> hidden_face_sets = gather_hidden_face_sets(hide_poly, prev_face_sets);

It doesn't seem we use prev_face_sets for anything by calculating a set if face sets used by hidden faces. So I think there is a potential to optimize some things here, with an idea of making it so gather_hidden_face_sets accesses face set attribute more directly. Perhaps something like this could work?

const Set<int> hidden_face_sets = gather_hidden_face_sets(hide_poly, face_sets.span);
It doesn't seem we use `prev_face_sets ` for anything by calculating a set if face sets used by hidden faces. So I think there is a potential to optimize some things here, with an idea of making it so `gather_hidden_face_sets ` accesses face set attribute more directly. Perhaps something like this could work? ``` const Set<int> hidden_face_sets = gather_hidden_face_sets(hide_poly, face_sets.span); ```
Mangal-Kushwah marked this conversation as resolved
@ -783,6 +804,18 @@ Array<int> duplicate_face_sets(const Mesh &mesh)
return face_sets;
}
Set<int> gather_hidden_face_sets(const VArray<bool> &hide_poly, const Span<int> prev_face_sets)

I would call it face_sets. The fact that caller might consider the span to be a "previously used face sets" does not really affect this function.

I would call it `face_sets`. The fact that caller might consider the span to be a "previously used face sets" does not really affect this function.
Mangal-Kushwah marked this conversation as resolved
Mangal Kushwah added 1 commit 2024-05-01 17:06:50 +02:00
Sergey Sharybin approved these changes 2024-05-01 17:52:58 +02:00
Sergey Sharybin left a comment
Owner

On a code side it seems correct. But I'd like Hans to also have a look, and maybe help with double-checking that it works good (I didn't have time for that yet).

On a code side it seems correct. But I'd like Hans to also have a look, and maybe help with double-checking that it works good (I didn't have time for that yet).
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u operators-hidden-geometry:Mangal-Kushwah-operators-hidden-geometry
git checkout Mangal-Kushwah-operators-hidden-geometry
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#119168
No description provided.