-
Notifications
You must be signed in to change notification settings - Fork 433
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add distance-preserving alignment #33
Open
strace44
wants to merge
23
commits into
Radivarig:master
Choose a base branch
from
strace44:align-preserve-dist
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
* Don't compare against numeric constants with 'is' -- those should be checked for equality and not identity * Remove explicit comparisons against True and False Also remove some redundant parentheses
The previous data collection/manipulation done in lists_of_verts tracks BMLoopUV objects, and as far as I can tell, these don't store any references to the corresponding BMLoops. I need to perform a graph traversal of the selected UV vertices, which necessitates using the link information in the BMLoop objects -- so build new mappings storing BMLoops.
I don't know why I thought it was necessary or appropriate to traverse loops in their *entirety* to find the selected neighbors of a vertex in UV space, but this definitely isn't appropriate. We just need to look at the previous and next links.
The direction of vertices isn't stable; successive runs of this flipt he directionality of the vertices. This is worth fixing, but not for my immediate usage.
Quick-and-dirty heuristic: choose the vertex order with minimum total L1 distance
Sequence doesn't imply mutability.
Also deduplicate code that chooses new coordinate directions based on minimum total L1 distance
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
First, thanks for the addon! I've found it quite useful in manipulating UV unwrapping.
After using this addon a few times, I realized that what I really wanted to do isn't implemented: aligning vertices to the U or V axis while preserving the distance between them in UV space. As far as I can tell, the existing code paths use
BMLoopUV
objects to move vertices in UV space, but I needed to access the parentBMLoop
objects to walk the edges between vertices. I didn't see a way to access theBMLoop
object from aBMLoopUV
, so I had to build entirely separate data structures to map vertex coordinates toBMLoop
s (see 0c9f0c5). (I consider myself very fluent in Python, and I've written a lot of Python code in the last decade or so, but this is my first exposure to the Blender API.)The new code in this PR requires NumPy and Python 3.7 or newer -- Blender 2.82 on Windows already includes both, so this version of the addon can be installed and used as-is. On Ubuntu, I had to install the
python3-numpy
system package, which is now described in the README (ebdad46).This functionality uses two BFS graph traversals to find a linear ordering of vertices:
Vertices can overlap in both U and V coordinates; this is handled properly:
Disconnected sets of vertices are aligned independently:
If it's not possible to find a simple linear ordering of selected vertices, the addon exits with an error:
I also modernized the code a bit and fixed some
SyntaxWarning
s that are shown by Python 3.8 -- for example,None
is usually the only constant that should be compared against with identity and not equality. There is now amath.isclose
method that handles the hand-crafted comparison of vertex positions, too. The code formatting was inconsistent in a lot of places, and I cleaned that up with theblack
formatter.I understand if you don't want to merge this due to the not-strictly-necessary changes included in this PR, but I couldn't resist making small cleanups while stepping through the code with the debugger to get a feel for the Blender API.
Thanks again for the addon; it was great as an introduction to the Blender API!