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

Force Z Axis

MatthiasThDs opened this issue · comments

Hi Nutti,

I hope you are doing great. Thanks again for your work on that great Addon!

I wanted to ask if you are interested in the following idea. My building roofs are working as expected, when I apply uvw_box and the roof faces have a face normal pointing sideways (more than 45 degrees):
image

As soon as I am going lower than 45 degrees, It uses some kind of "flat mode":
image

Therefore I developed the following functionality for my usecase. Because sometimes the user may know that he wants to force the uv map behave in such a way:
image

The Problem with just "deactivating" your #Z-plane code (see below), is that the texture looks horrible :) So I also multiply the texture aspect a little bit depending on the angle

if force_z and abs(n[0]) < abs(n[2]):
     aspect = tex_aspect + ( (abs(n[2]) - abs(n[0])) * 3.14 )

My math is not "correct", but it looks nice up to 10 degrees. Its not correctly aligned to the house walls anymore. But the real use case is more directed to the case in which you have a roof only.

Most changes would be here:

uvw.py / _apply_box_map()

           # X-plane
            if abs(n[0]) >= abs(n[1]) and (abs(n[0]) >= abs(n[2]) or force_z): #change
                if force_z and abs(n[0]) < abs(n[2]): #change
                    aspect = tex_aspect + ( (abs(n[2]) - abs(n[0])) * 3.14 ) #change
                if n[0] >= 0.0:
                    u = (y - ofy) * cos(rx) + (z - ofz) * sin(rx)
                    v = -(y * aspect - ofy) * sin(rx) + \
                        (z * aspect - ofz) * cos(rx)
                else:
                    u = -(y - ofy) * cos(rx) + (z - ofz) * sin(rx)
                    v = (y * aspect - ofy) * sin(rx) + \
                        (z * aspect - ofz) * cos(rx)
            # Y-plane
            elif abs(n[1]) >= abs(n[0]) and (abs(n[1]) >= abs(n[2]) or force_z): #change
                if force_z and abs(n[1]) < abs(n[2]): #change
                    aspect = tex_aspect + ( (abs(n[2]) - abs(n[1])) * 3.14 ) #change
                if n[1] >= 0.0:                    
                    u = -(x - ofx) * cos(ry) + (z - ofz) * sin(ry)
                    v = (x * aspect - ofx) * sin(ry) + \
                        (z * aspect - ofz) * cos(ry)
                else:
                    u = (x - ofx) * cos(ry) + (z - ofz) * sin(ry)
                    v = -(x * aspect - ofx) * sin(ry) + \
                        (z * aspect - ofz) * cos(ry)
            # Z-plane
            else:
                if n[2] >= 0.0:
                    u = (x - ofx) * cos(rz) + (y - ofy) * sin(rz)
                    v = -(x * aspect - ofx) * sin(rz) + \
                        (y * aspect - ofy) * cos(rz)
                else:
                    u = -(x - ofx) * cos(rz) - (y + ofy) * sin(rz)
                    v = -(x * aspect + ofx) * sin(rz) + \
                        (y * aspect - ofy) * cos(rz)
commented

@MatthiasThDs

Thanks for your continuous contribution for this add-on.
This feature is also interesting.

I have comments about this addition.

  • We could expand not only force_z, but also force_x/force_y (perhaps, force_xy is useful?)
  • The threshold angle to enable flat mode can be an option.

What do you think?
And, the contribution of this feature is also welcomed.

Thanks!

commented

@MatthiasThDs

Is there any update?
I think this improvement is great for including next version.

Hi nutti,

would it be ok if i make a pull request for "forcing z" first and you take a look at it?
Because this I can do pretty fast.

Both of your additional ideas sounds great. But I think they need some testing and try and error (thats how I did the force Z :) )

commented

@MatthiasThDs

would it be ok if i make a pull request for "forcing z" first and you take a look at it?

Sure, go ahead!
We could also test your feature in PR.

commented

@MatthiasThDs

Hi, is there any update about this?

commented

@MatthiasThDs

Any update?
If you have no time to tackle this issue, I will consider to tackle this issue.

commented

@MatthiasThDs

I tried to support this feature X-axis and Y-axis as well.
https://github.com/nutti/Magic-UV/tree/issue_140

But, I found that your patch could not solve well in X-axis and Y-axis.
If you have a good idea, please let me know.

If there is no solution, I want to postpone this feature because this feature only targets to specific use-case.

commented

I also introduce force_axis_tex_aspect_correction option and force_axis_rotation option to handle the mapping with flexibly.
I think these options help us to use UVW mapping in addition to force_axis option.

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