gsoc2024-UV-Seam-Weld-Underlying-Geometry #124221
No reviewers
Labels
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset System
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
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
Viewport & EEVEE
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Asset Browser Project
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
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
Module
Viewport & EEVEE
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Severity
High
Severity
Low
Severity
Normal
Severity
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
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender#124221
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "Anish-Bharadwaj/blender:gsoc2024-UV-Seam-Weld-Underlying-Geometry"
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?
This Pull request does the following:
Adds the new Operator UV Seam Weld
Implements the method to perform a Seam Weld on Underlying Geometry
Please make this PR limited to: "Merge By Distance" option to only consider connected underlying geometry. Other changes would be better to review separately.
Also, follow commit message guidelines for the PR text: https://developer.blender.org/docs/handbook/guidelines/commit_messages/
@ -2790,0 +2806,4 @@
luvmap.append(BM_ELEM_CD_GET_FLOAT_P(l, offsets.uv));
}
}
/*Filter out luv pointers who are not within threshold
The method used here looks like it will depend on the order UV's are iterated over. I think it would be good to avoid this as it means the order BMLoop's are visited will change the result of merging.
Use a deterministic method of merging UV's. e.g. calculate the center, then start with the UV closest to this center point. This is also less likely to merge into an outlier and will also produce better results.
@ -2790,0 +2881,4 @@
return OPERATOR_FINISHED;
}
void UV_OT_stitch_distance(wmOperatorType *ot)
There is no need for a new operator, this can be a boolean option for the existing
UV_OT_remove_doubles
operator.@ -2790,0 +2808,4 @@
}
/*Filter out luv pointers who are not within threshold
distance of another selected loop from same vertex*/
auto outer = luvmap.begin();
It's simpler to use indices than iterators.
@ -2790,0 +2828,4 @@
}
if (!keep) {
int outerIndex = std::distance(luvmap.begin(), outer);
luvmap.remove(outerIndex);
Use
remove_and_reorder(..)
since it avoids a memmove on remaining elements, since the order of UV's in the array should not matter.@ -815,0 +859,4 @@
centeruv = i;
}
}
/*Filter UV coordinates that are not within threshold distance of central UV*/
These should still be considered for merging, just not with the
centeruv
vertex. Other UV's which are not in this threshold may need to be merged with eachother.@ -814,0 +824,4 @@
/* Since we are using len_squared_v2v2 to calculate distance, we need to square the
* user-defined threshold*/
float threshold = RNA_float_get(op->ptr, "threshold");
threshold = threshold * threshold;
Use a
_sq
suffix for squared lengths as it's easy to accidentally compare these with non-squared lengths.const float threshold = math::square(RNA_float_get(op->ptr, "threshold"));
@ -814,0 +838,4 @@
blender::Vector<float *> luvmap;
/*Grap all luv pointers from selected loops*/
BM_ITER_ELEM (l, &liter, v, BM_LOOPS_OF_VERT) {
For each vertex, it should only be necessary to fill
luvmap
once.The UV's that are merged can be removed and the remaining UV's can be handled.
With the logic here it looks as if UV's could be tested for merging multiple times since the loops of the vertex are continually added to the array. Even if this doesn't cause any problems - there is no need to do this so the array should only be created once.
Then instead of
while (changed) {...}
the loop can continue untilluvmap
is empty (or has a single UV).@ -814,0 +843,4 @@
luvmap.append(BM_ELEM_CD_GET_FLOAT_P(l, offsets.uv));
}
}
if (luvmap.size() == 0) {
A single UV has nothing to merge with, so this could test the value is <= 1.
@ -814,0 +847,4 @@
break;
}
/*Find the central UV coordinate*/
Surround text by spaces, use full-stops, e.g..
/* Find the central UV coordinate. */
@ -814,0 +848,4 @@
}
/*Find the central UV coordinate*/
std::vector<float> sum(2, 0.0f);
Use a
blender::float2
for both values.The approach used seems fine, minor issued noted inline.
Some general code quality review.
cent
,center
,midpoint
&sum
(also used for a center calculation).I think these should be renamed to clarity their purpose, for one of these center points is used as a reference so it could be called
uv_reference_point
. The code comments can note that the center-most point is picked for deterministic merging.luvmap
&mergesection
. Suggest to renameuvs_for_vert
.uvs_for_vert_merge_num
const
.@ -815,0 +828,4 @@
/* Since we are using len_squared_v2v2 to calculate distance, we need to square the
* user-defined threshold*/
float threshold = RNA_float_get(op->ptr, "threshold");
There is no need to declare the non-squared value,
const float threshold_sq = math::squared(...);
@ -815,0 +837,4 @@
BMLoop *l;
BMIter viter, liter;
BM_ITER_MESH (v, &viter, em->bm, BM_VERTS_OF_MESH) {
blender::Vector<float *> luvmap;
This allocates a new vector for every vertex. Best declare this outside the loop & reserve a buffer to avoid re-allocation at small sizes (32 for example).
Then reuse the vector each iteration.
@ -815,0 +849,4 @@
while (luvmap.size() > 1) {
blender::float2 cent = {0.0f, 0.0f};
for (auto &luv : luvmap) {
luvmap
contains floats, there is no benefit here in using a reference to a float pointer use:for (const float *luv : luvmap) {..}
.@ -815,0 +856,4 @@
cent[0] /= luvmap.size();
cent[1] /= luvmap.size();
/*Find the loop closest to the cent coordinate. This loop will be the base that all
Some of the logic here would read better if the index to the last element was stored as a variable:
const int luvmap_end = luvmap.size() - 1
Then there is no need to subtract 1 from indices calculated later on.
@ -815,0 +862,4 @@
float mindist = len_squared_v2v2(cent, luvmap[0]);
float *center = luvmap[0];
int centerindex = 0;
for (int i = 0; i < luvmap.size(); i++) {
This loop can start at 1.
@ -815,0 +873,4 @@
float *tmp = center;
luvmap[centerindex] = luvmap[luvmap.size() - 1];
luvmap[luvmap.size() - 1] = tmp;
blender::float2 sum = {center[0], center[1]};
This reads like a mistake at first, as a sum typically starts at zero. Note in a comment that this is initialized to a single UV
mergesection
.@ -815,0 +879,4 @@
int i = 0;
int mergesection = 1;
while (luvmap[i] != center and i < luvmap.size() - mergesection) {
Use
&&
instead ofand
(our code style docs need updating for this).@ -815,0 +880,4 @@
int i = 0;
int mergesection = 1;
while (luvmap[i] != center and i < luvmap.size() - mergesection) {
float dist = len_squared_v2v2(center, luvmap[i]);
dist_sq
to be clear this is a squared value, same for other squared values.@ -815,0 +884,4 @@
if (dist < threshold_sq) {
sum[0] += luvmap[i][0];
sum[1] += luvmap[i][1];
float *tmp = luvmap[i];
it should be possible to use
std::swap
here.@ -815,0 +898,4 @@
* from luvmap.*/
if (mergesection > 1) {
blender::float2 midpoint = {0.0f, 0.0f};
can be written as
const blender::float2 midpoint = sum / mergesection;
@ -815,0 +912,4 @@
luvmap.resize(luvmap.size() - mergesection);
}
}
uvedit_live_unwrap_update(sima, scene, obedit);
Updated should only run if something changed.
Add a
changed
boolean which is set if any UV's are merged, then only run updates if this is true.While this is mostly fine (one bug noted inline), various naming and style issues remain.
Posted some updates to this branch: https://projects.blender.org/ideasman42/blender/commits/branch/Anish-Bharadwaj-gsoc2024-UV-Seam-Weld-Underlying-Geometry
@ -815,0 +841,4 @@
luvmapvector.reserve(32);
bool changed = false;
BM_ITER_MESH (v, &viter, em->bm, BM_VERTS_OF_MESH) {
The loop will enter with
luvmapvector
containing UV's from a previous iteration.Checkout
From your project repository, check out a new branch and test the changes.