Skip to content

Commit

Permalink
- Added support to multiple textures in the AutoUV editor.
Browse files Browse the repository at this point in the history
  The option is available in Body selection mode by toggling the
  "Texture Set Mode" which will ask for the standard naming to be used (Wings3D,
  Zbrush, Mudbox or Mari). After that the editor layout will switch to a set of
  25 tiles (5x5).
  The "Create Texture" option will be active over the selected tile which can
  be selected by holding the ALT key while clicking on the desired tile.
  The align operations were adjusted to act over the islands on their tiles.
  • Loading branch information
Micheus committed Sep 5, 2024
1 parent 58d901f commit 795190e
Show file tree
Hide file tree
Showing 3 changed files with 501 additions and 58 deletions.
5 changes: 5 additions & 0 deletions plugins_src/autouv/auv.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,15 @@
{matname, %% The textured MatName
bg_img, %% The background image
id, %% The we id of the shape we are working with.
tile={0,0}, %% Index of the active texture set we are working with
mode=object, %% object mode or a gb_sets of faces which we are editing
st %% Wings working 'st', i.e. no autouv stuff in this one
}).

-define(TEXTURESET, textureset).
-define(SINGLE, single_tx).
-define(MULTIPLE, multi_tx).

-ifdef(DEBUG).
-define(DBG(S,A), io:format("~p:~p " ++ S, [?MODULE,?LINE|A])).
-else.
Expand Down
53 changes: 46 additions & 7 deletions plugins_src/autouv/auv_texture.erl
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,11 @@ draw_options(#st{bb=Uvs}=AuvSt0) ->
OldId ->
OldImg = wings_image:info(OldId),
case OldImg#e3d_image.name of
"auvBG" -> atom_to_list(MatName0);
Name when is_list(Name) ->
case string:left(Name, 5) of
"auvBG" -> atom_to_list(MatName0);
_ -> Name
end;
Other -> Other
end
end,
Expand Down Expand Up @@ -984,10 +988,11 @@ error_msg(Line) ->
end.

draw_texture_square() ->
VertexUvQ = << 0.0:?F32,0.0:?F32, 0.0:?F32,0.0:?F32,
1.0:?F32,0.0:?F32, 1.0:?F32,0.0:?F32,
1.0:?F32,1.0:?F32, 1.0:?F32,1.0:?F32,
0.0:?F32,1.0:?F32, 0.0:?F32,1.0:?F32>>,
{U,V} = {1,0},
VertexUvQ = << (0.0+U):?F32,(0.0+V):?F32, (0.0+U):?F32,(0.0+V):?F32,
(1.0+U):?F32,(0.0+V):?F32, (1.0+U):?F32,(0.0+V):?F32,
(1.0+U):?F32,(1.0+V):?F32, (1.0+U):?F32,(1.0+V):?F32,
(0.0+U):?F32,(1.0+V):?F32, (0.0+U):?F32,(1.0+V):?F32>>,
wings_vbo:draw(fun(_) -> gl:drawArrays(?GL_QUADS, 0, 4) end, VertexUvQ, [vertex2d, uv]).

fill_bg_tex(#sh_conf{fbo_w=Prev}) ->
Expand Down Expand Up @@ -1116,9 +1121,43 @@ set_viewport({X,Y,W,H}=Viewport, Scale) ->
%% Data setup
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

setup(#st{bb=#uvstate{id=RId,st=#st{shapes=Sh0}}}=St, Reqs) ->
setup(#st{shapes=ShUV,selmode=SModeUV0,sel=SelUV0,bb=#uvstate{id=RId,matname=MatName,st=#st{shapes=Sh0}}}=St, Reqs) ->
We = gb_trees:get(RId,Sh0),
{Charts,{_Cnt,UVpos,Vpos,Ns,Ts,BB,Vc}} = setup_charts(St, We, Reqs),
{Charts,{_Cnt,UVpos,Vpos,Ns,Ts,BB,Vc}} =
case wpc_autouv:get_textureset_info(We) of
{?MULTIPLE,[_,[_|_]]} ->
Get_mat_face = fun(#we{id=Id}=WeUV) ->
FsMat = wings_facemat:all(WeUV),
case [F || {F,Mat} <- FsMat, Mat==MatName] of
[] -> [];
Fs -> {Id,Fs}
end
end,
SelForTile = lists:flatten([Get_mat_face(WeUV) || WeUV <- gb_trees:values(ShUV)]),
case SelForTile of
[_|_] ->
if (SelUV0==[]) -> % bor (SModeUV0==body) ->
SModeUV = body,
SelUV = [{Id,gb_sets:singleton(0)} || {Id,_} <- SelForTile];
true ->
SelUV1 = [Sel || {IdSel,_}=Sel <- SelUV0, proplists:is_defined(IdSel,SelForTile)],
case SelUV1 of
[] -> %% selection doesn't correspond to the active tile
SModeUV = face,
SelUV = [{Id,gb_sets:from_list(Fs)} || {Id,Fs} <- SelForTile];
_ ->
SModeUV = SModeUV0,
SelUV = SelUV0
end
end,
setup_charts(St#st{selmode=SModeUV,sel=SelUV}, We, Reqs);
[] ->
setup_charts(St, We, Reqs)
end;
none ->
setup_charts(St, We, Reqs)
end,
%% {Charts,{_Cnt,UVpos,Vpos,Ns,Ts,BB,Vc}} = setup_charts(St, We, Reqs),
#ts{charts=Charts,
uv = to_bin(UVpos,uv),
pos= to_bin(Vpos,pos),
Expand Down
Loading

0 comments on commit 795190e

Please sign in to comment.