Permalink
Browse files

Merge branches 'rj/preview_dialogs' and 'rj/sculpt_changes' into pu

  • Loading branch information...
2 parents 924f999 + 8cfe80e commit 55a6a5641278bab42278802b84ebbc0246c4b1da @optigon committed May 7, 2012
Showing with 155 additions and 28 deletions.
  1. +155 −28 plugins_src/commands/wpc_sculpt.erl
View
183 plugins_src/commands/wpc_sculpt.erl
@@ -38,6 +38,7 @@ init() ->
wings_pref:set_default(sculpt_magnet, {false,1.0}),
wings_pref:set_default(sculpt_magnet_type, dome),
wings_pref:set_default(sculpt_initial, false),
+ wings_pref:set_default(sculpt_constraint_axis, none),
%% Delete old prefs
wings_pref:delete_value(sculpt_magnet_color),
true.
@@ -159,9 +160,9 @@ handle_sculpt_event_1(#mousebutton{button=3,mod=Mod,x=X,y=Y,state=?SDL_PRESSED},
when Mod band ?CTRL_BITS =:= 0 ->
{GX,GY} = wings_wm:local2global(X, Y),
adjust_magnet(GX, GY, Sc);
-handle_sculpt_event_1(#mousebutton{button=3,mod=Mod,x=X,y=Y,state=?SDL_RELEASED}, _)
+handle_sculpt_event_1(#mousebutton{button=3,mod=Mod,x=X,y=Y,state=?SDL_RELEASED}, Sc)
when Mod band ?CTRL_BITS =/= 0 ->
- sculpt_menu(X, Y);
+ sculpt_menu(X, Y, Sc);
handle_sculpt_event_1(#keyboard{sym=Sym,state=?SDL_PRESSED}=Ev, Sc) ->
handle_key(Sym, Ev, Sc);
handle_sculpt_event_1({action,Action}, Sc) ->
@@ -390,7 +391,14 @@ sculpt(X, Y, #sculpt{id=ID,mir=Mir,str=Str,mag=false,mode=pinch,locked=Locked,
true -> Vtab1;
false ->
Pos = array:get(V, Vtab0),
- pinch(V, Pos, Cnt, 1, Str, Mir, We, Vtab1)
+ Vtab2 = pinch(V, Pos, Cnt, 1, Str, Mir, We, Vtab1),
+ case wings_io:is_modkey_pressed(?SHIFT_BITS) of
+ false ->
+ Vtab2;
+ true ->
+ NewPos = array:get(V, Vtab2),
+ smooth(V, NewPos, 1, Str*10, Mir, We, Vtab2)
+ end
end
end, Vtab0, [Face], We),
Shs = gb_trees:update(Id, We#we{vp=Vtab}, Shs0),
@@ -418,7 +426,14 @@ sculpt(X, Y, #sculpt{id=ID,mir=Mir,str=Str,rad=Rad,mag_type=MagType,mode=pinch,
case Dist =< Rad of
true ->
Inf = magnetic_influence(MagType, Dist, Rad),
- pinch(V, Pos, Cnt, Inf, Str, Mir, We, Vtab1);
+ Vtab2 = pinch(V, Pos, Cnt, Inf, Str, Mir, We, Vtab1),
+ case wings_io:is_modkey_pressed(?SHIFT_BITS) of
+ false ->
+ Vtab2;
+ true ->
+ NewPos = array:get(V, Vtab2),
+ smooth(V, NewPos, Inf, Str*10, Mir, We, Vtab2)
+ end;
false -> Vtab1
end;
false -> Vtab1
@@ -450,8 +465,14 @@ sculpt(X, Y, #sculpt{id=ID,locked=Locked,mir=Mir,str=Str,mag=false,
true -> Vtab1;
false ->
NewPos0 = e3d_vec:add_prod(Pos, Normal, Str),
- NewPos = handle_mirror(Id, V, NewPos0, Mir),
- array:set(V, NewPos, Vtab1)
+ NewPos1 = constraint_check(Pos, NewPos0),
+ NewPos = handle_mirror(Id, V, NewPos1, Mir),
+ case wings_io:is_modkey_pressed(?SHIFT_BITS) of
+ false ->
+ array:set(V, NewPos, Vtab1);
+ true ->
+ smooth(V, NewPos, 1, Str*10, Mir, We, Vtab1)
+ end
end
end, Vtab0, Vpos),
Shs = gb_trees:update(Id, We#we{vp=Vtab}, Shs0),
@@ -485,8 +506,14 @@ sculpt(X, Y, #sculpt{id=ID,locked=Locked,mir=Mir,str=Str,rad=Rad,
true -> e3d_vec:neg(Normal0)
end,
NewPos0 = e3d_vec:add_prod(Pos, Normal, Str*Inf),
- NewPos = handle_mirror(Id, V, NewPos0, Mir),
- {FNs,array:set(V, NewPos, Vtab1)};
+ NewPos1 = constraint_check(Pos, NewPos0),
+ NewPos = handle_mirror(Id, V, NewPos1, Mir),
+ case wings_io:is_modkey_pressed(?SHIFT_BITS) of
+ false ->
+ {FNs,array:set(V, NewPos, Vtab1)};
+ true ->
+ {FNs,smooth(V, NewPos, Inf, Str*10, Mir, We, Vtab1)}
+ end;
false -> {FNs0,Vtab1}
end;
false -> {FNs0,Vtab1}
@@ -566,7 +593,8 @@ smooth(V, Pos, Inf, Str, Mir, #we{id=Id}=We, Vtab) ->
Avg = e3d_vec:average(Positions),
Vec = e3d_vec:sub(Avg, Pos),
NewPos0 = e3d_vec:add_prod(Pos, Vec, Str*Inf),
- NewPos = handle_mirror(Id, V, NewPos0, Mir),
+ NewPos1 = constraint_check(Pos, NewPos0),
+ NewPos = handle_mirror(Id, V, NewPos1, Mir),
array:set(V, NewPos, Vtab).
pinch(V, Pos, Cnt, Inf, Str, Mir, #we{id=Id}, Vtab) ->
@@ -575,9 +603,39 @@ pinch(V, Pos, Cnt, Inf, Str, Mir, #we{id=Id}, Vtab) ->
true -> e3d_vec:sub(Pos, Cnt)
end,
NewPos0 = e3d_vec:add_prod(Pos, Vec, Str*Inf),
- NewPos = handle_mirror(Id, V, NewPos0, Mir),
+ NewPos1 = constraint_check(Pos, NewPos0),
+ NewPos = handle_mirror(Id, V, NewPos1, Mir),
array:set(V, NewPos, Vtab).
+constraint_check({X1,Y1,Z1}=OrigPos, {X2,Y2,Z2}=NewPos) ->
+ Const = wings_pref:get_value(sculpt_constraint_axis),
+ case Const of
+ none -> NewPos;
+ x -> {X2,Y1,Z1};
+ y -> {X1,Y2,Z1};
+ z -> {X1,Y1,Z2};
+ default_axis ->
+ {_,DefaultAxis} = wings_pref:get_value(default_axis),
+ intersect_vec_plane(OrigPos, NewPos, DefaultAxis, DefaultAxis);
+ x_radial -> {X1,Y2,Z2};
+ y_radial -> {X2,Y1,Z2};
+ z_radial -> {X2,Y2,Z1};
+ default_axis_radial ->
+ {_,DefaultAxis} = wings_pref:get_value(default_axis),
+ intersect_vec_plane(NewPos, OrigPos, DefaultAxis, DefaultAxis)
+ end.
+
+intersect_vec_plane(PosA, PosB, Plane, Vec) ->
+%% Return point where Vec through PosA intersects with Plane at PosB
+ case e3d_vec:dot(Vec,Plane) of
+ 0.0 ->
+ Intersection = e3d_vec:dot(e3d_vec:sub(PosB, PosA), Plane),
+ e3d_vec:add(PosB, e3d_vec:mul(Plane, Intersection));
+ Dot ->
+ Intersection = e3d_vec:dot(e3d_vec:sub(PosB, PosA), Plane) / Dot,
+ e3d_vec:add(PosA, e3d_vec:mul(Vec, Intersection))
+ end.
+
%%%
%%% Mirror Handling
%%%
@@ -671,6 +729,22 @@ command_handling(Action, #sculpt{st=St0,mag=Mag}=Sc) ->
prefs(Sc);
{sculpt,exit_sculpt} ->
exit_sculpt(Sc);
+ {sculpt,{axis_constraint,Axis}} ->
+ Const0 = wings_pref:get_value(sculpt_constraint_axis),
+ case Axis of
+ Const0 ->
+ wings_pref:set_value(sculpt_constraint_axis, none),
+ wings_wm:dirty(),
+ update_sculpt_handler(Sc);
+ clear_constraints ->
+ wings_pref:set_value(sculpt_constraint_axis, none),
+ wings_wm:dirty(),
+ update_sculpt_handler(Sc);
+ Axis ->
+ wings_pref:set_value(sculpt_constraint_axis, Axis),
+ wings_wm:dirty(),
+ update_sculpt_handler(Sc)
+ end;
_ -> keep
end.
@@ -693,15 +767,16 @@ exit_sculpt(#sculpt{mag=Mag,mag_type=MagType,str=Str,rad=Rad,mode=Mode,st=#st{sh
%%%
help(#sculpt{mag=Mag,rad=Rad,mag_type=MagType,str=Str,mode=Mode}) ->
+ AddSmooth = " "++ ?__(13,"Hold [Shift]: Smooth")++") ",
ModeMsg =
case Mode of
pinch ->
Pinch = mode(pinch),
- Pinch++" "++?__(12,"(Hold [Ctrl]: Inflate)");
+ Pinch++" ("++?__(12,"Hold [Ctrl]: Inflate")++AddSmooth;
smooth -> mode(smooth);
_ ->
Pull = mode(pull),
- Pull++" "++?__(11,"(Hold [Ctrl]: Push)")
+ Pull++" ("++?__(11,"Hold [Ctrl]: Push")++AddSmooth
end,
Sculpt = ?__(1,"L: Sculpt"),
Menu = ?__(2,"[Ctrl]+R: Sculpt Menu"),
@@ -718,7 +793,8 @@ help(#sculpt{mag=Mag,rad=Rad,mag_type=MagType,str=Str,mode=Mode}) ->
true -> ?__(9,"None (Magnet is off)")
end]),
{_,H} = wings_wm:win_size(),
- LLine = wings_msg:join([?__(10,"Sculpt Mode")++": "++ModeMsg, StatusBar]),
+ Constraint = constraint_info(),
+ LLine = wings_msg:join([?__(10,"Sculpt Mode")++": "++ModeMsg,StatusBar,Constraint]),
wings_io:info(0, H-?LINE_HEIGHT-3, LLine),
wings_wm:message(wings_msg:join([Sculpt,Menu,Exit]),
wings_msg:join([Radius,Strength])).
@@ -772,25 +848,76 @@ set_values([]) -> ok.
%%% Sculpt Menu
%%%
-sculpt_menu(X0, Y0) ->
+sculpt_menu(X0, Y0, Sc) ->
{X,Y} = wings_wm:local2global(X0, Y0),
- Menu = sculpt_menu(),
+ Menu = sculpt_menu(Sc),
wings_menu:popup_menu(X, Y, sculpt, Menu).
-sculpt_menu() ->
- [{mode(push)++"/"++mode(pull),pull},
- {mode(pinch)++"/"++mode(inflate),pinch},
- {mode(smooth),smooth},
+sculpt_menu(#sculpt{mag=Mag,mag_type=MagType,mode=Mode}) ->
+ [{mode(push)++"/"++mode(pull),pull,?__(4,"Activate the Push/Pull sculpt tool"),crossmark(Mode, pull)},
+ {mode(pinch)++"/"++mode(inflate),pinch,?__(5,"Activate the Pinch/Inflate sculpt tool"),crossmark(Mode, pinch)},
+ {mode(smooth),smooth,?__(6,"Activate the smoothing brush"),crossmark(Mode, smooth)},
+ separator,
+ {magtype(dome),dome,?__(7,"Activate the dome magnet"),crossmark(MagType, dome)},
+ {magtype(absolute),absolute,?__(8,"Activate the absolute magnet"),crossmark(MagType, absolute)},
+ {magtype(straight),straight,?__(9,"Activate the straight magnet"),crossmark(MagType, straight)},
+ {magtype(spike),spike,?__(10,"Activate the spike magnet"),crossmark(MagType, spike)},
+ {magtype(bell),bell,?__(11,"Activate the bell magnet"),crossmark(MagType, bell)},
+ separator,
+ {?__(1,"Magnet On/Off"),magnet,?__(12,"Toggle the magnet on or off"),crossmark(Mag, true)},
+ {?__(2,"Magnet Mask On/Off"),mask_toggle,
+ ?__(13,"Toggle the Magnet Mask. Masking options are found in the Tools menu."),
+ wings_menu_util:crossmark(magnet_mask_on)},
separator,
- {magtype(dome),dome},
- {magtype(absolute),absolute},
- {magtype(straight),straight},
- {magtype(spike),spike},
- {magtype(bell),bell},
+ {?__(16,"Axis Constraints"),{axis_constraint, constraints_menu()}},
separator,
- {?__(1,"Magnet On/Off"),magnet},
- {?__(2,"Magnet Mask On/Off"),mask_toggle},
+ {?__(3,"Preferences"),prefs,?__(14,"Sculpt mode preferences")},
separator,
- {?__(3,"Preferences"),prefs},
+ {exit_string(),exit_sculpt,?__(15,"Exit sculpt mode")}].
+
+constraints_menu() ->
+ Constraint = wings_pref:get_value(sculpt_constraint_axis),
+ X = wings_s:dir(x),
+ Y = wings_s:dir(y),
+ Z = wings_s:dir(z),
+ Rad = ?__(5,"Radial of ~s"),
+ Def = ?__(4,"Default"),
+ Help1 = ?__(1,"Constrain movement to the ~s axis."),
+ Help2 = ?__(7,"Constrain movement to the radial of the ~s axis."),
+ [{X,x,wings_util:format(Help1, [X]),crossmark(x, Constraint)},
+ {Y,y,wings_util:format(Help1, [Y]),crossmark(y, Constraint)},
+ {Z,z,wings_util:format(Help1, [Z]),crossmark(z, Constraint)},
+ {?__(3,"Default Axis"),default_axis,wings_util:format(Help1, [Def]),
+ crossmark(default_axis, Constraint)},
separator,
- {exit_string(),exit_sculpt}].
+ {wings_util:format(Rad, [X]),x_radial,wings_util:format(Help2, [X]),crossmark(x_radial, Constraint)},
+ {wings_util:format(Rad, [Y]),y_radial,wings_util:format(Help2, [Y]),crossmark(y_radial, Constraint)},
+ {wings_util:format(Rad, [Z]),z_radial,wings_util:format(Help2, [Z]),crossmark(z_radial, Constraint)},
+ {?__(6,"Radial of Default Axis"),default_axis_radial,wings_util:format(Help2, [Def]),
+ crossmark(default_axis_radial, Constraint)},
+ separator,
+ {?__(8,"Clear Constraints"),clear_constraints}].
+
+constraint_info() ->
+ Constraint = wings_pref:get_value(sculpt_constraint_axis),
+ X = wings_s:dir(x),
+ Y = wings_s:dir(y),
+ Z = wings_s:dir(z),
+ Def = ?__(1,"Default"),
+ Rad = ?__(2,"Radial of ~s"),
+ Str = case Constraint of
+ none -> ?__(3,"None");
+ x -> X;
+ y -> Y;
+ z -> Z;
+ default_axis -> Def;
+ x_radial -> wings_util:format(Rad, [X]);
+ y_radial -> wings_util:format(Rad, [Y]);
+ z_radial -> wings_util:format(Rad, [Z]);
+ default_axis_radial -> wings_util:format(Rad, [Def])
+ end,
+ wings_util:format(?__(4,"Constraint: ~s"), [Str]).
+
+crossmark(Axis, Axis) -> [crossmark];
+crossmark(_, _) -> [].
+

0 comments on commit 55a6a56

Please sign in to comment.