Skip to content

Commit

Permalink
Add UV Multiset (tiles) (#584)
Browse files Browse the repository at this point in the history
* - Added support to multiple textures in the AutoUV editor.
  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.

- Added the constant TILE_ROWS which allow us to easily change tiles amount;
- Supressed an extra call to wings_wm:this() in create_uv_state/5;
- The textureset mode needs to be stored by window otherwise we get wrong
  background drawing for a second AutoUV window with a single texture;
- Added option to handle the Reset camera command;
- Forced the camera to start in reset position when AutoUV window is displayed
  allowing us to see the entire texture or textureset;

* - Fixed a missed bind for bend command;

NOTE: Added support for multiple textures in the AutoUV editor.
  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.
  • Loading branch information
Micheus authored Oct 27, 2024
1 parent d084565 commit f595350
Show file tree
Hide file tree
Showing 3 changed files with 530 additions and 70 deletions.
6 changes: 6 additions & 0 deletions plugins_src/autouv/auv.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,16 @@
{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(TILE_ROWS, 5).
-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
54 changes: 45 additions & 9 deletions plugins_src/autouv/auv_texture.erl
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,10 @@ draw_options(#st{bb=Uvs}=AuvSt0) ->
false -> atom_to_list(MatName0);
OldId ->
OldImg = wings_image:info(OldId),
case OldImg#e3d_image.name of
"auvBG" -> atom_to_list(MatName0);
Other -> Other
OldName = OldImg#e3d_image.name,
case string:prefix("auvBG", OldName) of
nomatch -> OldName;
_ -> atom_to_list(MatName0)
end
end,
catch wings_material:update_image(MatName0, diffuse, NewImg#e3d_image{name=TexName}, GeomSt0)
Expand Down Expand Up @@ -984,10 +985,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 +1118,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=Uvs}=St, Reqs) ->
#uvstate{id=RId,matname=MatName,st=#st{shapes=Sh0}} = Uvs,
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==[]) ->
SModeUV = body,
SelUV = [{Id,gb_sets:singleton(0)} || {Id,_} <- SelForTile];
true ->
SelUV1 = [Sel || {IdSel,_}=Sel <- SelUV0, proplists:is_defined(IdSel,SelForTile)],
case SelUV1 of
[] ->
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,
#ts{charts=Charts,
uv = to_bin(UVpos,uv),
pos= to_bin(Vpos,pos),
Expand Down
Loading

0 comments on commit f595350

Please sign in to comment.