nutti / Magic-UV

Blender Add-on: Magic UV

Home Page:http://nutti.github.io/Magic-UV/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Overlay island centers for tiling applications

DanMcLaughlin opened this issue · comments

Description about the feature

For games it's common to make a large object - such as a wall for a building, cut into approximately equal squares, then overlay the UV squares so they can share texture space. It simply consists of taking the centers of all selected squares and moving them to the same place like the cursor.

The description about the feature. It is good to clear who will benefit with this feature.

This is a common, tedious operation that can involve a lot of mindless repetition.

Are you willing to contribute about this feature. (Yes/No)

Yes

Screenshots [Optional]
Capture

Additional comments
Honestly should be easy (speaking as a developer)

commented

@DanMcLaughlin

Thanks for your proposal.
It is a great idea to add this feature.

BTW, what is the difference between Copy/Paste UVs and this feature.
I think we can achieve this idea by using Copy/Paste UVs feature which is already in Magic UV.
What do you think?

@nutti
Similar which is why I agree this would be a good addition to the Magic-UV feature set. But in this case it would be a Cut/Paste operation instead of Copy. However there are some problems with it. First is that what you want is to select a set of UV's and have them individually all be moved to the cursor.

image

For these the operation would be to loop over all the individual sections and move each to the cursor. Not the same as selecting all, copy and doing a paste. Presently it can be tediously done by using the UV operation one by one selecting each individually

bpy.ops.uv.snap_selected(target="CURSOR_OFFSET")

so the pseudo code would be

for (uv in all selected UV's) rip(uv) #separate verticies uv.bpy.ops.uv.snap_selected(target="CURSOR_OFFSET")

commented

@DanMcLaughlin

I'm so sorry about late reply because of tackling other projects such as Screencast Keys and fake-bpy-module.
From now, I can concentrate to upgrade Magic UV.

I understood your proposal.
It looks good feature to me.
Before implementing this issue, I would like to check your intention of contribution.
Do you still want to contribute this feature?
I think your Python development is enough to implement this feature.

@nutti

No problem, likewise I needed some time to think about this.

Yes I'm very experienced engineer and with Python, I don't have any experience in Magic UV and a little in Blender UV API. Anyhow if you could give me a kickstart, or better a shell file to fill in - with where you want it and such, maybe just check in such a shell that I can check out, then I can fill it in with the functionality

commented

@DanMcLaughlin

Nice!

I think this feature seems to relate to Copy/Paste UV feature.
Also, this feature seems to be used in UV Editor.
So, it is good to add to its source code.
UI code exists in this code.

If you have any trouble to implement this feature, don't hesitate contacting me.
I could support you as far as possible.

commented

@DanMcLaughlin

Is there any update about this?
If you have no much time to do this, I will implement this to target v6.4 release.

@nutti Really sorry, yes there's little time (nothing new), if I knew you're codebase I'd just grab a morning and bang it out but other higher priority things to learn and do are taking time. If you can do it then probably best, it shouldn't take too much time I hope.

commented

@DanMcLaughlin

Thanks for your reply.
OK, I will implement this.

commented

@DanMcLaughlin

Hi, I implemented this feature.
Could you check if implemented feature is that you assumed.
https://github.com/nutti/Magic-UV/suites/1232737792/artifacts/18575051

github_20200923

Great work! Unfortunately I can't see the option. I updated to the version you link above but it's not in Align UV, I also tried latest 6.3 and the development branch latest (update from the UV Preferences), oddly it's not showing up

commented

@DanMcLaughlin

Thanks for your reply.
How about below links?
https://github.com/nutti/Magic-UV/archive/ci_testing.zip

This feature is not released officially, so we can only use this feature at develop branch.
After this feature is implemented, I will release v6.4 which includes this feature.

This is really weird, still not there. I installed that version you link, Blender says it installs the modules fine, the version string is 6.2 and nothing.

image

commented

@DanMcLaughlin

Did you remove built-in add-on?
Magic UV is included in Blender officially, so you need to remove built-in Magic UV add-on.

I updated in place, but this time I went to the Blender add on folders and deleted magic_uv (is there a better way? Not that I saw), but this time installing the last version you sent is says "Missing script files" in the Add-ons list. Hunh, not sure what to do here, this should be a simple operation.

commented

@DanMcLaughlin

I did a following process.

  1. Make sure built-in Magic UV add-on and external Magic UV add-on
  2. Install Magic UV from zip file (in Blender).
  3. Enable Magic UV add-on.

Or, you can use updator of Magic UV from Blender Preferences.
(Choose develop branch)

github_20200924

OK, the development branch update worked!

Yes this is great, works as I expected. At first it was in a mode that it snapped and overlaid all of the islands and I was wondering how to individually snap them over, or a group. After playing with UV sync and other settings it started to snap individually or whatever is selected. Anyhow it seems to work perfectly, great work!

Yeah already using it, constantly need to overlay islands to save/reuse UV space.

commented

@DanMcLaughlin

Thanks for trying this feature!
Do you have any ideas to improve of this feature?
If not, I will tackle to release v6.4 which includes this feature.

I really like the 'Snap Group" addition, though for games I think UV Island is the most common choice. The workflow that constantly comes up over and over for this kind of low poly hard surface workflow is

  1. Find common areas where UV space can be reused
  2. Select that area, "Smart UV Project" works much of the time
  3. That area fills the UV space, and is often flipped (reversed) so needs to be rotated 180. Imagine doing a wall, that can be the same as another wall, but when smart projected is mirror reversed
  4. You have thousands of objects that need to have a common texel density, so scale the object to that by using a grid reference texture
  5. Repeat

OK walking through this makes me think of another common one, which is for something like a wall with a door or window hole. Take a look at this

image

Here's the UV

image

So you can see all those window interior edges need to be aligned at specific places. Specifically

image

That left hand island needs to be aligned to snap to the left the center square. I did this one by hand, but what I'm saying is if there could be a 'snap two islands together along this edge' that would be glorious. For example

image

For that rectangle off the 0-1 space, I'd like to snap it to the center one left. Ideally this would work by first selecting the island to be snapped, then selecting the island to snap to, with a choice as to which edge.

This entire operation would be done for one side, and would be repeated for the other side, and for that the snap you just implemented would be used. You can see how much work already this will save as there's a lot of overlaying and snapping going on. If the UV cursor could be moved more easily that would help, and another I talk about above, which is edge snapping (by moving the entire island).

commented

I think this is a specific case, so we can extend this behavior to general case.

i.e.

  1. Select UV vertex where another UV will be snapped to
  2. Move 2D cursor to selected UV vertex (or save cursor location internally)
  3. Select UV vertex from which will be snapped
  4. Move UV island to the location specified by process 2

In other words, we introduce new option Target where UV vertices will snap to.

Does this feature meet your requirement?

Had to think through this a couple of times ... yes I see your design, select two verticies which are intended to be either coincident (snapped on top of each other) or co-linear (snap then slide x or y for further alignment for non rectilinear islands), in their respective islands. Only the island is moving. Yes that will work wonderfully.

commented

Thanks for your feedback.
I'll implement this option.

Beautiful. This is a very powerful feature for packing the UV's to save space, and when you want sections to align on a texture.

commented

@DanMcLaughlin

Added target option. (It has already in develop branch)

github_20200926

Could you try this?

commented

I could not hear your description (volume is low?)
But I figured out what you want to say from your instructions.

This version, UV vertices move along to the center of face/island.
But, you want to move island not only center but also corners of face/island (i.e. left-bottom, right-bottom, etc...)
Is my understanding correct?

Sorry, don't know what happened.

Yes snapping the center of an island to a vertex of another island isn't something that's come up because you get partial overlap*. In practice what's needed is either 100 overlap (center to center) or edge snap non overlap - meaning snap one edge to another, so two arbitrary islands are side by side. Seems like the best way to do that would be to select a vertex and hit the vertex snap coordinate button, then select a vertex of the island to be moved, and when the big snap button is hit the whole island moves over, with the vertex at the coordinate of the other vertex selected previously.

The other thing was I show that selecting some islands and clicking the vertex snap button puts the coordinates to zero, which seems like a bug.

Finally it wasn't clear which vertex would be chosen for the snap coordinate. In one case I showed it was the lower left vertex, for another it was the upper left.

*islands, or a selection of islands almost always represents a distinct region, so you always either want to overlap that region (center to center) or snap to an edge of the region (e.g. snap a region that is contiguous to the other island, as I show above with the window frame)

commented

The other thing was I show that selecting some islands and clicking the vertex snap button puts the coordinates to zero, which seems like a bug.

I think you didn't select face in View3D.
I'm not sure which is a better whether face selection is needed or not.
Do you have any idea?

Finally it wasn't clear which vertex would be chosen for the snap coordinate. In one case I showed it was the lower left vertex, for another it was the upper left.

Currently, snap coordinate is average of selected vertices.
Instead you can set snap coordinate by selecting only one vertex.
But I think this makes you confused.
Is there any good idea about this process?

OK, what's confusing is that setting the snap coordinates only fully works when "UV Sync Selection" is turned off. I usually work with it turned on, as that's much more convenient than having to keep everything selected. If the coordinate setting can always work when "UV Sync Selection" is enabled that would fix the confusion.

Now I'm still not able to get the "edge to edge" snapping. Take a look at this video (no speaking)

https://youtu.be/gmnTPptz6lc

  • I turn off UV Sync Selection and select all faces
  • I select an edge and get it's coordinates (it takes the average)
  • I select another edge and want to snap the average/center of that, to the other, keeping the island intact
  • I can snap a vertex to the snapping point, but can't seem to get the whole island over then edge to edge with the other

Does that make sense?

commented

I usually work with it turned on, as that's much more convenient than having to keep everything selected. If the coordinate setting can always work when "UV Sync Selection" is enabled that would fix the confusion.

Thanks for your feedback.
I agree with you, so I will consider when UV Sync Selection is on.

I'm still not able to get the "edge to edge" snapping.

I understood your issue.
But currently, this feature is not implemented.

I think we should separate original feature (face to face) from the new feature (edge to edge).
The process seems different each other.

But I'm not sure how to realize "edge to edge" feature when the edges are different rotation each other.

I think we should separate original feature (face to face) from the new feature (edge to edge).
But I'm not sure how to realize "edge to edge" feature when the edges are different rotation each other.

Rotation is a different issue, and an equal problem for both cases. I think you have to assume the user has the proper rotation already for the islands, and that's easy enough to fix with the normal Blender tools. I often get mirrored or rotated islands, and for any texture that has an orientation (e.g. bricks) those have to be fixed manually, because there's so many different problems that can happen with the texture and geometry. I don't think there's much that can be automated with that. In other words rotation is a packing problem, not tiling.

But I think edge to edge and face on face are part of the same tiling problem and the two seem to always be needed together. On the edge to edge I think snapping the midpoint of the two edges - just like you snap the midpoint of two faces, is the right solution and shows they are the same issue. But regardless if you want to check this on and come back to it later that's fine too.

commented

Thanks for your feedback.
I will try to implement this feature. If I finish the implementation, it is helpful to test them :-)

Absolutely I'll support any way I can.

commented

@DanMcLaughlin

Sorry for late reply.
I implemented Snap to Edge feature.
It's now in develop branch.

github_20201007

  1. At first, you need to select edge which snap to, and click button (green box).
  2. Select edge which will be snapped, and click Snap to Edge button (yellow box).

@nutti

  • Wonderful! Yes this turns it into a snapping lego set, the edge to edge works great.
  • Point to point isn't working for me. I select one point, hit the point or cursor icon to set the location, select another point then "Snap to Point", no error but nothing happens, changing the group doesn't matter
    image
    Here you see an attempt to move an island to the cursor by selecting a point on the island (could be any of them)
    image
  • Otherwise selecting entire islands you can snap them, or a group of them, to a point, this works great
    image
  • Still doesn't appear to work with "Sync Selection" on

So works great with two possible issues. One, support for sync selection being on would be helpful, otherwise it's confusing why it's not working (and it forces you to work in non sync mode). Two, unless I'm misunderstanding point to point isn't working correctly.

commented

@DanMcLaughlin

Thanks for your feedback.
I missed the understanding of the specification of Sync Selection in Python API.
So, it will work correctly for "Snap to Point" in current version (develop branch.)

However, it is difficult to realize Sync Selection feature for "Snap to Edge" feature.
Because if we select one edge, another edge will be selected automatically.

Below sample shows the simple example.

github_20201008

If we select one edge, other edge will be selected automatically.
Do you have any idea about it?

Yeah that's a problem, I guess it's there to show you what edges are mesh connected. I don't know ... just leave it though I guess, the functionality is clear, and otherwise it seems to be working well, with one exception.

Go into Snap to Point, select your Point, select another Vertex, select Face or Island group and snap - this isn't working. If you select Vertex mode it does work (so Vertex->Vertex does work, but Face/Island->Vertex isn't)

commented

If you select Vertex mode it does work (so Vertex->Vertex does work, but Face/Island->Vertex isn't)

Did you select face/island which will be snapped?
If you don't select all vertices of face/island, nothing will be happened.

Or, is it better to select only vertex of face/island instead of whole vertices of face/island?

Did you select face/island which will be snapped?

Ah I see, yes that snaps the center of the island. That is fine, but also supporting that if you have only a single vertex selected (in Face/Island group mode) then it snaps the entire face/island, vertex to vertex.

This would be equivalent to edge snapping if the two edges are equal size, but this particular feature would be useful for when you want precise edge snapping to a vertex point on that edge, if that makes sense. Regardless its confusing that selecting a vertex (or an edge really) in Face/Island snapping doesn't also snap to the vertex.

commented

That's right.

  1. "Snap to Point" & Group="Vertex": All selected vertices will snap to target point.
  2. "Snap to Point" & Group="Face": Center of all selected faces will snap to target point.
  3. "Snap to Point" & Group="UV Island": Center of all selected islands will snap to target point.
  4. "Snap to Edge" & Group="Edge": Selected edge, will snap to center of target edge.
  5. "Snap to Edge" & Group="Face": Vertices which is includes in selected edge, will snap to center of target edge.
  6. "Snap to Edge" & Group="UV Island": Vertices which is includes in selected edge, will snap to center of target edge.

My question is this specification is clear or not.
I think the features are already enough for us. So only I concern is the user interface.

OK, yeah there are a few extra cases that could be done, but if you're done with the features and are only concerned with UI then in this example

"Snap to Point" & Group = "Face or Island" & Edge is selected: You should post a warning that a Face/Island isn't selected.

I'd vote for supporting that type of snap, but for the present features set posting warnings when the user hasn't properly selected the Face/Island would clear up the confusion and make it clear that the feature isn't supported, or said differently that they did something wrong. Right now with no warning it's confusing why it doesn't work.

commented

Thanks for your feedback.

"Snap to Point" & Group = "Face or Island" & Edge is selected: You should post a warning that a Face/Island isn't selected.

I agree that its feedback is important for the users.
I will tackle it.

commented

@DanMcLaughlin

I finished to add logs you requested.
If this feature does not have any other issue from your workflow, I will prepare for releasing v6.4.

Looks great @nutti, thanks so much for your hard work

commented

I will tackle to release v6.4.
Thanks for your great help!

commented

This feature is now merged to master branch.
I will close this issue.