Skip to content

Commit

Permalink
Merge pull request #599 from Micheus/mv/v2.4-fix-drang-drop-autouv
Browse files Browse the repository at this point in the history
AutoUV texture issues
  • Loading branch information
dgud authored Jan 2, 2025
2 parents f44baa0 + b95f8e7 commit b1dd781
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 12 deletions.
9 changes: 4 additions & 5 deletions plugins_src/autouv/auv_texture.erl
Original file line number Diff line number Diff line change
Expand Up @@ -985,11 +985,10 @@ error_msg(Line) ->
end.

draw_texture_square() ->
{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>>,
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>>,
wings_vbo:draw(fun(_) -> gl:drawArrays(?GL_QUADS, 0, 4) end, VertexUvQ, [vertex2d, uv]).

fill_bg_tex(#sh_conf{fbo_w=Prev}) ->
Expand Down
55 changes: 48 additions & 7 deletions plugins_src/autouv/wpc_autouv.erl
Original file line number Diff line number Diff line change
Expand Up @@ -522,16 +522,28 @@ insert_material(Cs, MatName, We) ->

%%%%% Material handling

get_texture(MatName, #st{mat=Materials}) ->
get_texture(MatName, Materials);
get_texture(MatName, Materials) ->
case gb_trees:lookup(MatName, Materials) of
get_texture(MatName, #st{mat=MTab}) ->
get_texture(MatName, MTab);
get_texture(MatName, MTab) ->
case gb_trees:lookup(MatName, MTab) of
none -> false;
{value,Mat} ->
Maps = proplists:get_value(maps, Mat, []),
proplists:get_value(diffuse, Maps, false)
end.

set_texture(MatName, Id, #st{mat=Mtab0}=St) ->
Mat0 = gb_trees:get(MatName, Mtab0),
{Maps0,Mat1} = prop_get_delete(maps, Mat0),
Maps = [{diffuse,Id}|lists:keydelete(diffuse, 1, Maps0)],
Mat = [{maps,Maps}|Mat1],
Mtab = gb_trees:update(MatName, Mat, Mtab0),
St#st{mat=Mtab}.

prop_get_delete(Key, List) ->
Val = proplists:get_value(Key, List),
{Val,lists:keydelete(Key, 1, List)}.

add_material({txset,Tx}, Name, St0) ->
add_material_0(Tx, list_to_atom(Name), St0);
add_material(Tx, Name, St0) ->
Expand Down Expand Up @@ -1969,9 +1981,38 @@ drag_filter({image,_,_}) ->
{yes,?__(1,"Drop: Change the texture image")};
drag_filter(_) -> no.

handle_drop(#{type:=image,id:=Id}, #st{bb=Uvs0}=St) ->
Uvs = Uvs0#uvstate{bg_img=Id},
get_event(St#st{bb=Uvs});
handle_drop(#{type:=image,id:=Id}, #st{bb=Uvs0, shapes=Shs0}=AuvSt0) ->
#uvstate{matname=MatName, tile=Tile, st=#st{shapes=GShs0}=GeomSt0, id=WId} = Uvs0,
TxSetMode = wings_wm:get_prop(wings_wm:this(), texture_set_mode),
{AuvSt,GeomSt} =
case TxSetMode of
true ->
FWe0 = gb_trees:get(WId,GShs0),
We0 = gb_trees:get(WId,Shs0),
case get_textureset_info(FWe0) of
{?MULTIPLE,[TxSetNaming,[_|_]=TxSet0]} ->
case lists:keyfind(Tile,1,TxSet0) of
false ->
{set_texture(MatName,Id,AuvSt0),set_texture(MatName,Id,GeomSt0)};
{Tile,#{mat:=MatName,bg_img:=_OldTxId}} ->
TxSet = lists:keyreplace(Tile,1,TxSet0,{Tile,#{mat=>MatName,bg_img=>Id}}),
%% updates the image id in the texture set data
We = update_textureset_system(We0,?MULTIPLE,[TxSetNaming,TxSet]),
GWe = update_textureset_system(FWe0,?MULTIPLE,[TxSetNaming,TxSet]),
Shs = gb_trees:update(We#we.id,We,Shs0),
GShs = gb_trees:update(GWe#we.id,GWe,GShs0),
%% updates the Mtab
AuvSt1 = set_texture(MatName,Id,AuvSt0),
GeomSt1 = set_texture(MatName,Id,GeomSt0),
{AuvSt1#st{shapes=Shs},GeomSt1#st{shapes=GShs}}
end;
_ ->
{set_texture(MatName,Id,AuvSt0), set_texture(MatName,Id,GeomSt0)}
end;
false ->
{set_texture(MatName,Id,AuvSt0), set_texture(MatName,Id,GeomSt0)}
end,
new_state(AuvSt#st{bb=Uvs0#uvstate{bg_img=Id, st=GeomSt}});
handle_drop(_DropData, _) ->
?dbg("Ignore ~P~n",[_DropData,30]),
keep.
Expand Down
1 change: 1 addition & 0 deletions src/wings_outliner.erl
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ command({assign_texture,Type,Id,Name0, Format}, #st{mat=Mtab}=St) ->
occlusion when Format =/= g8 -> wings_u:message(ConvertWarning);
_ -> ignore
end,
wings_wm:psend(geom, {drop,#{type=>image,id=>Id}}), %% ensure AutoUV is updated if active
wings_wm:send(geom, {action,{material,{update,Name,Mat}}});
false ->
keep
Expand Down

0 comments on commit b1dd781

Please sign in to comment.