Page MenuHome

Basic Select Similar tool for UV faces
Needs ReviewPublic

Authored by Jeff Knox (knox) on Jul 11 2017, 1:23 AM.

Details

Summary

Diff for T52005

This is the basic structure for implementing a Select Similar tool for UVs. The first iteration here contains code only for selecting by similar UV faces, but it is general enough that adding new types (edges and vertices) should be straightforward.

Similar selection is now available for:

  • Material - Select UV faces that have the same polygon material
  • Image - Select UV faces that have the same polygon UV texture image
  • Area - Select UV faces with similar area
  • UV Sides - Select UV faces with same number of sides
  • Perimeter - Select UV faces with similar edge perimeter
  • Normal - Select UV faces whose polygons have the same normal
  • Co-planar - Select UV faces associated with co-planar polygons
  • Flat/Smooth - Select UV faces based on polygon smoothness

Diff Detail

Repository
rB Blender
Branch
T47437_uv_select_similar
Build Status
Buildable 843
Build 843: arc lint + arc unit

Event Timeline

source/blender/editors/uvedit/uvedit_intern.h
55

This has been copied (with the addition of a selected field) from bmo_similar.c, but I'm wondering if I should try to reuse the original code.

source/blender/editors/uvedit/uvedit_ops.c
4252

Another code duplication, this time from editmesh_select.c.

Brecht Van Lommel (brecht) requested changes to this revision.Jul 25 2017, 1:32 AM

Seems generally fine. Not sure if you would like to see this committed with a single type, if so we should tweak the description to only mention faces. If the plan is to add more types it's not needed of course.

source/blender/editors/uvedit/uvedit_intern.h
55

I think it would be ok to share the code here, moving the structs from bmo_similar.c to bmesh_operators.h. But maybe Campbell has a different opinion on this, I'm not too familiar with the BMesh code structure / conventions.

source/blender/editors/uvedit/uvedit_ops.c
659

I think we should use the absolute value in case UVs are flipped?

4301

I get a few warnings building this, they can be solved with bContext *UNUSED(C).

source/blender/editors/uvedit/uvedit_ops.c:4306:50: warning: unused parameter 'C' [-Wunused-parameter]
source/blender/editors/uvedit/uvedit_ops.c:4306:65: warning: unused parameter 'op' [-Wunused-parameter]
source/blender/editors/uvedit/uvedit_ops.c:4313:50: warning: unused parameter 'C' [-Wunused-parameter]                                                 ^
source/blender/editors/uvedit/uvedit_ops.c:4313:65: warning: unused parameter 'op' [-Wunused-parameter]
4337

This variable is unused.

4398

We don't typically use goto's for cases like this in Blender. But why even exit the loop here, I think we would want to select all faces with similar area, not just the first one that is found?

This revision now requires changes to proceed.Jul 25 2017, 1:32 AM
source/blender/editors/uvedit/uvedit_ops.c
4398

In this case the outer loop goes over every (unselected) UV face, and the inner loop goes over all the currently selected target UV faces trying to find a match. Once a target match has been found, the unselected UV gets marked for selection, so we shouldn't need to continue looking for target UVs. I'll add comments to make the loops more clear.

Maybe I can put the inner loop into a function and return early if a match is found? But I didn't want to add too much function call overhead in case there are millions of UVs. Perhaps I should profile it first.

source/blender/editors/uvedit/uvedit_ops.c
4398

Ah, ok. Don't worry about function call overhead, it's very small and often the compiler will automatically inline the function anyway. If there's anything to worry about regarding performance here, it's the O(n^2) behavior, but that's a bit harder to fix and BMesh doesn't seem to bother with it either.

I suggest to match bmo_similar.c then, using a bool cont to check if the loop needs to continue.

Jeff Knox (knox) marked 8 inline comments as done.Sep 22 2017, 10:13 PM
Jeff Knox (knox) updated this revision to Diff 9307.EditedSep 23 2017, 2:14 AM
Jeff Knox (knox) edited edge metadata.
Jeff Knox (knox) edited the summary of this revision. (Show Details)

Updating D2738: Basic Select Similar tool for UVs
This revision fixes the issues from the last review and adds new UV face selection operations. Similar selection is now
available for:

  • Material - Select UV faces that have the same polygon material
  • Image - Select UV faces that have the same polygon UV texture image
  • Area - Select UV faces with similar area
  • UV Sides - Select UV faces with same number of sides
  • Perimeter - Select UV faces with similar edge perimeter
  • Normal - Select UV faces whose polygons have the same normal
  • Co-planar - Select UV faces associated with co-planar polygons
  • Flat/Smooth - Select UV faces based on polygon smoothness

Note that Material, Image, Normal, Co-Planar and Flat/Smooth select UV faces based on the associated polys,
while Area, UV Sides and Perimeter select UV faces based on the UVs themselves.

I'm saving the select similar UV edges/vertices for another revision.

In addition, a python test file was created for the tool. Let me know if this should be done in a separate revision...

Jeff Knox (knox) retitled this revision from Basic Select Similar tool for UVs to Basic Select Similar tool for UV faces.Sep 23 2017, 2:17 AM
Jeff Knox (knox) edited the summary of this revision. (Show Details)
Jeff Knox (knox) edited the summary of this revision. (Show Details)Sep 23 2017, 2:20 AM