Fix #102843: Add UV Packer with O(nlogn) performance #105393
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#105393
Loading…
Reference in New Issue
No description provided.
Delete Branch "Chris_Blackbourn:uv-alpaca-packer"
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?
Adds a novel "Alpaca" UV packing strategy for fast packing
of UV island AABBs without rotation.
The name is a bit fun, but I'm a bit skeptical of adding a pun in the code just for the sake of it. The fact that it's a "novel strategy" doesn't really help IMO. It would be better to just give it a straightforward name like L-packer or something. And the "turbo" because "it's fast" seems a bit strange too-- I haven't seen that done anywhere else. It's all relative anyway.
Other than that, I took a look at general C++ stuff.
@ -23,0 +27,4 @@
public:
float2 uv_diagonal;
float2 uv_placement;
int64_t index;
Looks like the
index
value isn't actually used. Best to remove it IMO, since the index should be known from the context during iteration, etc.The
aabb_vector
get sorted on line 121:We need to remember the original position in the
island_vector
so that the call toBLI_box_pack_2d
will write back to the correct place.Ah, I missed that in my search of the file, sorry about that!
All good.. there's a lot going on here, so maybe it needs to be renamed.
input_index
orsource_index
or something?I'll post a new version shortly, hopefully that will be a bit cleaner
@ -23,0 +45,4 @@
* Each box is packed into an "L" shaped region, gradually filling up space.
* "Alpaca" is a pun, as it's pronounced the same as "L-Packer" in English.
* In theory, alpaca_turbo should be the fastest non-trivial packer, hence the "turbo" suffix.
*/
island_vector
is a span here, not a vector. A simpler name might just beislands
-- there's no real need to put the data structure in the name, since we see both all the time.@ -23,0 +46,4 @@
* "Alpaca" is a pun, as it's pronounced the same as "L-Packer" in English.
* In theory, alpaca_turbo should be the fastest non-trivial packer, hence the "turbo" suffix.
*/
static void pack_islands_alpaca_turbo(const Span<UVAABBIsland *> &island_vector,
Span
is a small struct and should be passed by value, otherwise it's semantically like a pointer to a pointer@ -23,0 +47,4 @@
* In theory, alpaca_turbo should be the fastest non-trivial packer, hence the "turbo" suffix.
*/
static void pack_islands_alpaca_turbo(const Span<UVAABBIsland *> &island_vector,
BoxPack *box_array,
Use
Span
orMutableSpan
for thisbox_array
variable too. That makes it clearer that it's actually an array and not a pointer to a single value, and gives better safety and some utility functions.Actually.. looks like it's unused here
box_array
is somewhat historical, and I'm a little reluctant to change it piecemeal.At some point, I'll refactor it out of the public interface and some of this stuff will make more sense.
:( I think we're stuck with it just a little longer..
@ -23,0 +60,4 @@
float v0 = zigzag ? 0.0f : next_v1;
/* Visit every island in order. */
for (auto island : island_vector) {
Convention in Blender code is to spell out the type name rather than using
auto
in such situations, since it can be helpful to the reader.@ -26,2 +106,4 @@
const float margin)
{
/* First, copy information from our input into the AABB structure. */
Vector<UVAABBIsland *> aabb_vector;
Looks like this should be an
Array
rather thanVector
, since it doesn't need to grow-- it can be with the known size directly@ -28,2 +110,3 @@
for (const int64_t index : island_vector.index_range()) {
PackIsland *island = island_vector[index];
PackIsland *pack_island = island_vector[index];
UVAABBIsland *aabb = new UVAABBIsland();
Use
std::make_unique
.OR! Even better, avoid allocating each struct individually! They're only 24 bytes each
The "Alpaca" strategy also serves as an introduction to the other packing strategies, which use larger structures and combine them in more complicated ways than a simple array.
I think it's more important to have consistency (with the code that's not in this PR) than to make this particular PR cleaner.
@ -30,0 +119,4 @@
}
/* Sort from "biggest" to "smallest". */
std::stable_sort(aabb_vector.begin(), aabb_vector.end(), UVAABBSorterNoRotate());
Any particular reason not to use a lambda here? That's more common. Like this here:
Nice!
@ -30,0 +126,4 @@
int64_t max_box_pack = std::min(alpaca_cutoff, island_vector.size());
/* Prepare for box_pack. */
for (int64_t index = 0; index < island_vector.size(); index++) {
for (const int64_t i : island_vector.index_range())
Some reasoning:
index
rather thani
const
makes it clearer that it's only changed in the iteration@ -38,0 +137,4 @@
/* Call box_pack (slow for large N.) */
float max_box_u = 0.0f;
float max_box_v = 0.0f;
BLI_box_pack_2d(box_array, (int)max_box_pack, &max_box_u, &max_box_v);
Use functional casts in C++:
int(max_box_pack)
https://wiki.blender.org/wiki/Style_Guide/C_Cpp#C.2B.2B_Type_Cast@ -38,0 +143,4 @@
/* Call Alpaca. */
pack_islands_alpaca_turbo(
Span<UVAABBIsland *>(aabb_vector.data() + max_box_pack, aabb_vector.size() - max_box_pack),
Looks like the perfect place to use some of the helper methods like
aabb_vector.as_span().drop_front(max_box_pack)
Nice!
@ -38,0 +163,4 @@
delete aabb;
}
return max_ff(max_box_u, max_box_v);
Use blenders C++
math
namespace orstd::max
insteadFix #102843: Add UV Packer with O(nlogn) performance.to Fix #102843: Add UV Packer with O(nlogn) performance@ -30,0 +123,4 @@
});
/* Partition island_vector, largest will go to box_pack, the rest alpaca_turbo. */
const int64_t alpaca_cutoff = int64_t(1024); /* TODO: Tune constant. */
It would be good to give some context for whats going on here.
b1185da403
Pull request closed