-
Notifications
You must be signed in to change notification settings - Fork 99
Added an RMB option to Scale->Normalize in AutoUV window #625
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
Open
Micheus
wants to merge
2
commits into
dgud:master
Choose a base branch
from
Micheus:mv/new-uv-scale-normalize-RMB
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.
+86
−4
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -615,10 +615,7 @@ command_menu(body, X, Y) -> | |
| ?__(3,"Move selected charts")}, | ||
| {?__(4,"Scale"), {scale, scale_directions(false) ++ | ||
| [separator] ++ stretch_directions() ++ | ||
| [separator, | ||
| {?__(411,"Normalize Sizes"), normalize, | ||
| ?__(412,"Normalize Chart Sizes so that each" | ||
| "chart get it's corresponding 2d area")}]}, | ||
| [separator] ++ normalize()}, | ||
| ?__(5,"Scale selected charts")}, | ||
| {?__(6,"Rotate"), {rotate,rotate_free(false)}, | ||
| {?__(7,"Rotate selected charts"),[],?__(59,"Pick rotation center")},[]}, | ||
|
|
@@ -752,6 +749,12 @@ stretch_directions() -> | |
| {?__(3,"Max Horizontal"), max_x, ?__(4,"Maximize horizontally (X dir)")}, | ||
| {?__(5,"Max Vertical"), max_y, ?__(6,"Maximize vertically (Y dir)")}]. | ||
|
|
||
| normalize() -> | ||
| [{?__(411,"Normalize Sizes"), normalize_fun(), | ||
| {?__(412,"Normalize Chart Sizes so that each " | ||
| "chart get its corresponding 2d area"),[], | ||
| ?__(413,"Normalize chart sizes by taking a reference into account")}}]. | ||
|
|
||
| move_directions(true) -> | ||
| [{?__(1,"Free"), free_2d, ?__(2,"Move in both directions"), [magnet]}, | ||
| {?__(3,"Horizontal"), x, ?__(4,"Move horizontally (X dir)"), [magnet]}, | ||
|
|
@@ -831,6 +834,12 @@ max_uniform() -> | |
| (3, _Ns) -> {auv,{scale,{max_uniform,y}}} | ||
| end. | ||
|
|
||
| normalize_fun() -> | ||
| fun | ||
| (1, _Ns) -> {auv,{scale,normalize}}; | ||
| (3, _Ns) -> {auv,{scale,normalize_ref}} | ||
| end. | ||
|
|
||
| option_menu() -> | ||
| [separator, | ||
| {?__(1,"Create Texture"),create_texture,?__(2,"Make and Attach a texture to the model")}]. | ||
|
|
@@ -1222,6 +1231,9 @@ handle_command_1({scale,normalize}, St0) -> %% Normalize chart sizes | |
| Sh = lists:foldl(Scale, Sh0, List), | ||
| St = update_selected_uvcoords(St0#st{shapes=Sh}), | ||
| get_event(St); | ||
| handle_command_1({scale,normalize_ref}, St) -> %% Normalize chart sizes using a reference | ||
| Sel = wings_sel:selected_ids(St), | ||
| wings:ask(normalize_ask(Sel), St, fun normalize_by_ref/2); | ||
| handle_command_1({scale, {'ASK', Ask}}, St) -> | ||
| wings:ask(Ask, St, fun({Dir,M},St0) when is_tuple(M), element(1,M) == magnet -> | ||
| do_drag(wings_scale:setup({Dir,center,M}, St0)); | ||
|
|
@@ -1510,6 +1522,76 @@ do_drag({drag,Drag}) -> | |
| do_drag(Other) -> | ||
| Other. | ||
|
|
||
| normalize_ask(OrigSel) -> | ||
| Fun = fun(check, St) -> | ||
| case check_selection(OrigSel, St) of | ||
| {Result,Msg} -> | ||
| {Result,Msg}; | ||
| Msg -> | ||
| {none,Msg} | ||
| end; | ||
| (exit, {_,_,St}) -> | ||
| case check_selection(OrigSel, St) of | ||
| {{_,_,Id},_} -> | ||
| {result,Id}; | ||
| _ -> | ||
| error | ||
| end | ||
| end, | ||
| {[{Fun,?__(1,"Pick the chart to be used as reference")}],[],[],[body]}. | ||
|
|
||
| check_selection(Ids, #st{selmode=Mode}=St) -> | ||
| Sel = case Mode of | ||
| body -> Ids; | ||
| _ -> [] | ||
| end, | ||
| MF = fun(_Items, #we{id=Id}) -> | ||
| case lists:member(Id, Sel) of | ||
| true -> | ||
| [wrong]; | ||
| false -> | ||
| [{0,0,Id}] | ||
| end; | ||
| (_, _) -> | ||
| [wrong] | ||
|
Comment on lines
+1555
to
+1556
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove this dead code. |
||
| end, | ||
| RF = fun erlang:'++'/2, | ||
| case wings_sel:dfold(MF, RF, [], St) of | ||
| [] -> | ||
| ?__(1,"Nothing selected"); | ||
| [wrong] -> | ||
| ?__(2,"Only unselected charts are allowed"); | ||
| [Result] when is_tuple(Result) -> | ||
| {Result, ?__(3,"Reference chart picked")}; | ||
| [_|_] -> | ||
| ?__(4,"Select only one chart") | ||
| end. | ||
|
|
||
| normalize_by_ref(RefId, St0) -> | ||
| #st{shapes=Sh0, bb=#uvstate{id=Id,st=#st{shapes=Orig}}} = St0, | ||
| OWe = gb_trees:get(Id, Orig), | ||
| RWe = gb_trees:get(RefId, Sh0), | ||
| {RA2D,RA3D,_} = calc_areas(RWe,OWe,{0.0,0.0,[]}), | ||
| RScale = RA2D/wings_util:nonzero(RA3D), | ||
|
|
||
| {_,_,List} = wings_sel:fold(fun(_,We,Areas) -> | ||
| calc_areas(We,OWe,Areas) | ||
| end, {0.0,0.0,[]}, St0), | ||
| Scale = fun({A2D,A3D,We0 = #we{id=WId}},Sh) -> | ||
| Ri = A2D / wings_util:nonzero(A3D), | ||
| ScaleFactor = math:sqrt(RScale / wings_util:nonzero(Ri)), | ||
| Center = wings_vertex:center(We0), | ||
| T0 = e3d_mat:translate(e3d_vec:neg(Center)), | ||
| SM = e3d_mat:scale(ScaleFactor, ScaleFactor, 1.0), | ||
| T1 = e3d_mat:mul(SM, T0), | ||
| T = e3d_mat:mul(e3d_mat:translate(Center), T1), | ||
| We = wings_we:transform_vs(T, We0), | ||
| gb_trees:update(WId,We,Sh) | ||
| end, | ||
| Sh = lists:foldl(Scale, Sh0, List), | ||
| St = update_selected_uvcoords(St0#st{shapes=Sh}), | ||
| get_event(St). | ||
|
|
||
| tighten(#st{selmode=vertex}=St) -> | ||
| tighten_1(fun vertex_tighten/2, St); | ||
| tighten(#st{selmode=body}=St) -> | ||
|
|
||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Crashes if user press middle button otherwise?