WIP: The SLIM UV unwrap algorithm implementation for Blender 4.x #114545
No reviewers
Labels
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
3 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender#114545
Loading…
Reference in New Issue
No description provided.
Delete Branch "glukoz/blender:uv_unwrapping_slim_algorithm_v5_update"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
SUMMARY
The patch integrates an existing implementation of the SLIM unwrapping algorithm into Blender. More info about SLIM here: https://igl.ethz.ch/projects/slim/. The patch is based on the integration code written by Aurel Gruber for Blender 2.7x (not finished and never actually merged with the master branch). To learn more about SLIM, watch the following presentation by Aurel: https://www.youtube.com/watch?v=PLUoLQUK3-s
In this PR the original Aurel's code was rebased to a recent main commit and a bunch of further improvements were introduced.
HANDLING DOUBLED VERTICES AND ZERO TRIANGLES
First of all I used the original
p_chart_simplify
disabled code to implement a new function:p_chart_collapse_doubles
. The collapsing code used byp_chart_collapse_doubles
is almost identical top_chart_simplify
- the criteria of collapsing is different though: as the name suggests it collapses edges only to remove doubled vertices.Thanks to the simplified collapse criteria, it seems that we can avoid explicit uncollapsing after the operation is done - instead we can easily flush UV coords to collapsed vertices just before applying the result. It is the approach the current code uses (check the
p_chart_flush_collapsed_uvs
function).To sum up (together with changes from the previous update): currently the mesh preprocessing before SLIM unwrap consists of two phases:
p_chart_collapse_doubles
- removing doubled verticesp_chart_correct_zero_angles
- correcting zero area triangles.WARNING - at the current stage it is not guaranteed that the above functions will work properly together with the live unwrap functionality. They may require some improvements. The point is that I cannot risk spending much time on improving and polishing these solutions without a confirmation that such an approach is acceptable by Blender devs on the general level.
So at this moment I need a confirmation (or rejection) of this general approach in order to continue work on this task.
The SLIM UV unwrap algorithm implementation for Blender 4.xto WIP: The SLIM UV unwrap algorithm implementation for Blender 4.xThanks, I will find some time to look into this again. Hopefully next week.
I'm still working my way through the code, but pushed a bunch of changes to cut the size of this PR in half. And to use proper SPDX headers and align closer to our code style.
I see various warnings when building this, should show on the buildbot too:
@blender-bot build
I pulled your changes and after that building fails. Is that expect or is it an issue with my environment?
It's not expected. Maybe try to fix the errors, and if you can't show the error log?
Ok, I fixed compilation and all warnings related to this PR.
There were more warnings in the buildbot logs. I fixed them, except these:
I guess certain charts need to be skipped based on these, similar to
p_chart_lscm_begin
.@blender-bot build
@ -222,0 +263,4 @@
}
else {
/* We use the properties from the last unwrap operator for subsequent
* live unwrap and minize stretch operators. */
This comment seems to be incorrect, and perhaps this code and
WM_operator_current_or_default_properties_alloc
can be removed?ED_uvedit_live_unwrap
passes in toolsettings, so this code does not rununwrap_exec
does not pass in tool settings, but the operator should already remember its propertiespack_islands_exec
andaverage_islands_scale_exec
do not pass in tool settings, but these properties seems irrelevant to them.The main rationale of this code was to make the minimize stretch operator use the latest options used by the unwrap operator.
The rationale is not reflected in the current state of the implementation because the minimize stretch operator hasn't been ported to use SLIM yet. But it will probably be ported sooner or later so this code may be useful in the future.
The last used unwrap settings are already stored in the scene tool settings, so minimize stretch should get them from there instead.
I see. So I removed that call.
@ -2605,0 +2826,4 @@
else {
uiDefAutoButsRNA(
layout, &ptr, unwrap_draw_check_prop_abf, NULL, NULL, UI_BUT_LABEL_ALIGN_NONE, false);
}
I think this would benefit from a manual layout now, using
uiItemR
for individual properties instead ofuiDefAUtoButsRNA
. That way properties can be grouped better.For SLIM I think it could be grouped like this:
Done, though I wasn't able to add separators between prop groups you specified. I was looking for a C++ counterpart of the Python
layout.separator()
call but with no luck.It's
uiItemS()
.@ -2610,3 +2838,4 @@
{0, nullptr, 0, nullptr, nullptr},
};
static const EnumPropertyItem reflection_items[] = {{0, "ALLOW", 0, "Allow Flips", ""},
Could this be made into a
allow_flips
boolean? Doesn't seem like it should be an enum.Done.
@ -4286,0 +4961,4 @@
slim::MatrixTransferChart &mt_chart = mt->mt_charts[i];
bool select = false, deselect = false;
int npins = 0;
select
,deselect
andnpins
are not used. Does this need similar logic top_chart_lscm_begin
, skipping some charts based on these?Right now when you use live unwrap, and select a pin on one island and move it, it will continue solving other islands. I think this is unexpected, and would cause poor performance when there are many islands but you only want to work on one.
Done.
Is this code in the pull request? I do not see functions with these names.
The approach sounds good to me.
I was going to open a devtalk topic for user feedback, but it seems the code for doubled vertices and zero triangles is missing? If so I can wait for that. Text was going to be:
Indeed, I forgot to rebase the collapse_doubles part of the original change. Now it's fixed. I think you can open the devtalk topic now :)
I will look into other change requests in the next week.
@blender-bot package
Package build started. Download here when ready.
The double vertex collapsing code looks fine to me. After deduplicating it with the simplify implementation, it's also not much extra code.
User feedback topic:
https://devtalk.blender.org/t/slim-uv-unwrapping/32192
@glukoz are you following the feedback topic? Would be good if you can reply there too.
I think the most obvious improvements to make are to have two separate entries in the Unwrap menu, and to rename Vertex Group to indicate its purpose. For both the trickiest part is finding good names. We should also consider renaming SLIM to something that's easier to understand along with that, as we did for ABF and LSCM in the past.
There was one example of an unwrap failing, maybe possible to solve by tweaking the degenerate triangle handling?
https://devtalk.blender.org/t/slim-uv-unwrapping/32192/26
Report about pins not working well:
https://devtalk.blender.org/t/slim-uv-unwrapping/32192/27
@blender-bot package
Package build started. Download here when ready.
Sure, I will take a look on it.
Sure, I can tweak the algorithm so that the given mesh is processed BUT keep in mind that even after tweaking there may be another mesh which will not pass the test. I mean the algorithm does its best to fix a mesh but it cannot guarantee that it will work for every degenerated example. The question is whether you can accept such an approach in the long term.
What I did for ABF and LSCM is to keep investigating and fixing user reports until failures become rare. There's no well defined cut-off point for that. But it's important to look at some user reported ones since they tend to catch things a developer can find in testing.
If it turns out there is a certain class of problems we don't know how to solve, and it's common, then we can decide if some other algorithm is needed to clean up the geometry or if we accept it. But I would expect simple adjustments could go a long way. For example the in
uv_initializer.cpp
, if that step fails perhaps the angles could be clamped to some minimum value. Something similar really helped for ABF. If some other step fails, maybe similar clamping is possible in the solver.What do you think about naming like this?
In the operator properties:
SLIM -> Minimum Stretch
Vertex Group -> Importance Weights
In the unwrap menu add two separate operators:
It ties in with the same algorithm being used for minimize stretch later.
I ran ABF and SLIM on a random subset of the dataset here. See attachment for script and results.
http://staff.ustc.edu.cn/~fuxm/projects/ProgressivePara/dataset.html
There are a fair amount of models where SLIM fails. Some of them actually succeed when removing the minimum angle and double vertex threshold, though have not checked if the results are good in general.
The naming seems ok for me.
I will take a look at the failing examples soon.
In this update I worked on improving the function for correcting degenerate triangles. The function name is now
p_chart_correct_degenerate_triangles
. I reworked the function so it now checks two triangle parameters: area and minimum angle - the function tries to correct both parameters so they are above specified thresholds (note that both parameters are independent from the mathematical point of view).The
p_chart_correct_degenerate_triangles
function is now able to deal with double vertices so the question is whether we still want to use thep_chart_collapse_doubles
function.I ran a test on the enrite D2 mesh set and it turned out that the correction function in the current state lowers the failing mesh count from 28 to 18. Note that the entire D2 set consists of 6190 meshes.
I investigated some of the failing 18 meshes and it turns out that SLIM may fail even when the correction function is able to correct all triangles in the mesh (by min area and min angle). Note that I double check that all triangles are actually corrected before the function returns (using asserts). So it looks like the failing meshes may be caused by bugs in the SLIM implementation itself.
Now I will take a look at the issue with pins not being respected by SLIM.
@blender-bot package
Package build started. Download here when ready.
I solved the problem with pins not being respected.
Now the main question is whether you still want to merge this algorithm given the fact that SLIM may fail even when the correction function is able to correct all triangles in the mesh (by min area and min angle) - as I explained above.
@brecht Could you start a build with the recent changes? I am not sure whether I can do it on my own.
@blender-bot package
Package build started. Download here when ready.
I'd like to have another look to see if I can find some solution for those failures. I don't think it's a blocker if we can't, but would be nice.
Then I guess this is nearly ready to merge for Blender 4.2? Still need to check all the latest changes.
@brecht Could ask people for feedback for the latest build in the dev thread? Unfortunately I cannot add 3 messages in a row there.
@glukoz I've changed your trust level on devtalk to remove that restriction.
Checkout
From your project repository, check out a new branch and test the changes.