UV: tweak packing heuristics to reduce rotations #112295

Manually merged
Brecht Van Lommel merged 2 commits from brecht/blender:uv-pack-rotation into main 2023-09-14 19:05:48 +02:00

UV unwrapping and packing have always done island rotations, but it is happening now in more cases where users prefer it not to. These changes make it less likely that islands will be rotated.

When finding the best packing method, use area as tie breaker

When multiple packing methods result in effectively the same bounds,
prefer the packer that uses the smallest area. When all islands can
easily fit this is usually the box packer instead of alpaca. The zigzag
method of the latter has a tendendcy to take up more area and rotate
islands.

Fix #110724: smart UV project unnecessarily rotates islands

Disable best fit rotation of all islands at end of UV packing

This has a tendency to place islands diagonally in the image which is
not usually wanted, even if it's maximimizing the number of pixels for
the island.

Fix #109906: UV unwrap packs island diagonally instead of straight

UV unwrapping and packing have always done island rotations, but it is happening now in more cases where users prefer it not to. These changes make it less likely that islands will be rotated. #### When finding the best packing method, use area as tie breaker When multiple packing methods result in effectively the same bounds, prefer the packer that uses the smallest area. When all islands can easily fit this is usually the box packer instead of alpaca. The zigzag method of the latter has a tendendcy to take up more area and rotate islands. Fix #110724: smart UV project unnecessarily rotates islands #### Disable best fit rotation of all islands at end of UV packing This has a tendency to place islands diagonally in the image which is not usually wanted, even if it's maximimizing the number of pixels for the island. Fix #109906: UV unwrap packs island diagonally instead of straight
Brecht Van Lommel added 2 commits 2023-09-12 18:33:07 +02:00
1a26211db4 UV: disable best fit rotation of all islands at end of UV packing
This has a tendency to place islands diagonally in the image which is
not usually wanted, even if it's maximimizing the number of pixels for
the island.

Fix #109906: UV unwrap packs island diagonally instead of straight
buildbot/vexp-code-patch-coordinator Build done. Details
8772523be6
UV: when finding the best packing method, use area as tie breaker
When multiple packing methods results in effectively the same bounds,
prefer the packer that uses the smallest area. When all islands can
easily fit this is usually the box packer instead of alpaca. The zigzag
method of the latter has a tendendcy to take up more area and rotate
islands.

Fix #110724: smart UV project unnecessarily rotates islands
Brecht Van Lommel changed title from UV: tweaking packing heuristics to reduce rotations to UV: tweak packing heuristics to reduce rotations 2023-09-12 18:33:19 +02:00
Brecht Van Lommel requested review from Campbell Barton 2023-09-12 18:33:42 +02:00
Brecht Van Lommel requested review from Chris Blackbourn 2023-09-12 18:33:42 +02:00

@blender-bot package

@blender-bot package
Member

Package build started. Download here when ready.

Package build started. [Download here](https://builder.blender.org/download/patch/PR112295) when ready.
Campbell Barton approved these changes 2023-09-13 01:54:05 +02:00

Shouldn't the aspect be taken into account? (params.target_aspect_y)
Both these reports use a square image so the difference isn't noticeable.

e.g.

    return (BLI_rctf_size_x(&b) / params.target_aspect_y) * BLI_rctf_size_y(&b) <
           (BLI_rctf_size_x(&a) / params.target_aspect_y) * BLI_rctf_size_y(&a);
Shouldn't the aspect be taken into account? (`params.target_aspect_y`) Both these reports use a square image so the difference isn't noticeable. e.g. ``` return (BLI_rctf_size_x(&b) / params.target_aspect_y) * BLI_rctf_size_y(&b) < (BLI_rctf_size_x(&a) / params.target_aspect_y) * BLI_rctf_size_y(&a); ```
Author
Owner

Dividing both sides by the same factor makes no difference, but I can indeed add it for clarity.

Dividing both sides by the same factor makes no difference, but I can indeed add it for clarity.

It's only dividing the width by the aspect though, so unless we know the height is the same, it could make a difference.

It's only dividing the width by the aspect though, so unless we know the height is the same, it could make a difference.

@blender-bot package

(the build has failed on Windows and MacOS apparently :/ - trying it again for @DanielBystedt )

@blender-bot package (the build has failed on Windows and MacOS apparently :/ - trying it again for @DanielBystedt )
Member

Package build started. Download here when ready.

Package build started. [Download here](https://builder.blender.org/download/patch/PR112295) when ready.
Member

I did a bit of testing with various Human Base Meshes and other character files.

When unwrapping a large amount of uv islands the results are the same between this PR and main. Both do a good job in keeping UVs aligned with the object axes.

GEO-body_male_realistic_unwrap_all_pr.png

When unwrapping individual uv islands this PR does a much better job. The unwrapped UVs are consistently well aligned 👍

In this example I unwrapped each UV island individually and packed them afterwards without rotating them. The rotation of UV islands in the PR is typically the same as unwrapping everything at the same time.

main PR
GEO-body_male_realistic_unwrap_individual_main.png GEO-body_male_realistic_unwrap_individual_pr.png
I did a bit of testing with various [Human Base Meshes](https://www.blender.org/download/demo-files/) and other character files. When unwrapping a large amount of uv islands the results are the same between this PR and main. Both do a good job in keeping UVs aligned with the object axes. ![GEO-body_male_realistic_unwrap_all_pr.png](/attachments/5e286c6a-762e-4ce8-9ca0-a8f121b6b1e7) When unwrapping individual uv islands this PR does a much better job. The unwrapped UVs are consistently well aligned 👍 In this example I unwrapped each UV island individually and packed them afterwards without rotating them. The rotation of UV islands in the PR is typically the same as unwrapping everything at the same time. | main | PR | | -------- | -------- | | ![GEO-body_male_realistic_unwrap_individual_main.png](/attachments/e7c9f046-f3e5-4061-8bd9-7de908a6ae00) | ![GEO-body_male_realistic_unwrap_individual_pr.png](/attachments/b0d8da77-85c2-49f7-becf-cf73ba6fa14a) |
Brecht Van Lommel manually merged commit 89b3249c14 into main 2023-09-14 19:05:48 +02:00
Member

This PR has fixed the issues in the description as far as I can tell. Well done!

This PR has fixed the issues in the description as far as I can tell. Well done!
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 project
No Assignees
6 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#112295
No description provided.