• Website
  • Search
  • Member List
  • Help
  • Old Forum
  • Social Media
    •   @Wings3dOfficial
    •   @Wings3dOfficial
    •   Wings3dOfficial
    •   Wings3dOfficial
  • Register
  • Login
  • Website
  • Search
  • Member List
  • Help
  • Old Forum
  • Register
  • Login
Wings 3D Development Forum Wings 3D ManifoldLab Plug-ins Collection v
« Previous 1 2 3 4 5 … 7 Next »
The Connect surface tool by Dimitri.

 
  • 1 Vote(s) - 1 Average
The Connect surface tool by Dimitri.

dgud
Offline

Grumpy Dev
Posts: 692
Threads: 37
Joined: Nov 2012
#23
03-21-2016, 03:39 PM (This post was last modified: 03-21-2016, 03:40 PM by dgud.)
Something like this?

EDIT: (untested of course)...

Code:
command({vertex,{manifoldlab,connect_surface_norm}},#st{sel=[{WeID,Set}]}=St0) ->
    We = gb_trees:get(WeID,St0#st.shapes),
    case gb_sets:to_list(Set) of
    [Vs,Ve] ->
        connect_surface(Vs, Ve, We, St0);
    _ ->
        wings_util:error("only two verts can be selected..") %% FIXME
    end.


connect_surface(VS0, VE0, #wx{id=WeID}=We, St0) ->
    {Mid, A_B_C_D, Plane1, Plane2} = calc_planes(VS0, VE0, We),
    ETree = collect_edges(A_B_C_D, We),
    Es = gb_sets:from_list(gb_trees:keys(ETree)),
    FaceSet2 = collect_faces(Mid, Plane1, Plane2, Es, We, St0),
    {We2,Vs} = make_cuts(ETree, We, limit_edges(VS0, VE0, FaceSet2, Es, We)),
    St4 = wings_shape:replace(WeID,We2,St0#st{selmode=vertex,sel=[{WeID,Vs}]}),
    {save_state,#st{}=St5} = wings_vertex_cmd:command(connect,St4),
    #we{} = We5 = gb_trees:get(WeID,St5#st.shapes),
    MyBetweens = fun(Ei,#edge{vs=_VS,ve=_VE}, Acc) ->
             Two = gb_sets:from_list([_VS,_VE]),
             _I = gb_sets:intersection(Two,Vs),
             case gb_sets:size(_I) /= 2 of
                 true -> Acc;
                 false -> gb_sets:add(Ei,Acc)
             end
         end,
    EsConn = array:sparse_foldl(MyBetweens, gb_sets:empty(), We5#we.es),
    %%{_,StCleaned} = wings_body:command({cleanup, [{short_edges,true},1.0E-5,{isolated_vs,true}]}, St7),
    St5#st{selmode=edge,sel=[{WeID,EsConn}]}.


calc_planes(VS0, VE0, We) ->
    Pt1a  = wings_vertex:pos(VS0,We),
    Pt2a  = wings_vertex:pos(VE0,We),
    V1 = e3d_vec:sub(Pt2a,Pt1a),
    Mid0 = e3d_vec:average([Pt1a,Pt2a]),
    Norm0 = e3d_vec:average([wings_vertex:normal(VS0,We), wings_vertex:normal(VE0,We)]),
    Cross = e3d_vec:norm(e3d_vec:cross(V1,Norm0)),
    A_B_C_D = e3d_vec:plane(Mid0,Cross), %% slicer plane
    Plane1 = e3d_vec:plane(Pt1a,e3d_vec:norm(V1)),
    Plane2 = e3d_vec:plane(Pt2a,e3d_vec:norm(V1)),
    {Mid0, A_B_C_D, Plane1, Plane2}.

collect_edges(Plane, #we{es=Etab}=We) ->
    MyAcc = fun(Ei, _Val, Acc) ->
            #edge{vs=VS,ve=VE} = array:get(Ei,Etab),
            Pt1 = wings_vertex:pos(VS,We),
            Pt2 = wings_vertex:pos(VE,We),
            S1 = e3d_vec:plane_side(Pt1, Plane),
            S2 = e3d_vec:plane_side(Pt2, Plane),
            if (S1 /= S2) ->
                D1 = abs(e3d_vec:plane_dist(Pt1, Plane)),
                D2 = abs(e3d_vec:plane_dist(Pt2, Plane)),
                Dir = e3d_vec:norm(e3d_vec:sub(Pt2,Pt1)),
                Percent = D1/(D1+D2),
                PtX = e3d_vec:add(Pt1, e3d_vec:mul(Dir, Percent*wings_edge:length(Ei,We))),
                gb_trees:enter(Ei,PtX,Acc);
               true ->
                Acc
            end
        end,
    array:sparse_foldl(MyAcc, gb_trees:empty(), Etab).

collect_faces(Mid, Plane1, Plane2, Es, #we{id=Id} = We, St0) ->
    St1 = St0#st{selmode=edge,sel=[{Id,Es}]},
    #st{sel=[{Id,FaceSet}]} = wings_sel_conv:mode(face,St1),
    MyFs = fun(Fi, Acc) ->
           Center = wings_face:center(Fi, We),
           S1a = e3d_vec:plane_side(Mid, Plane1),
           S2a = e3d_vec:plane_side(Center, Plane1),
           S1b = e3d_vec:plane_side(Mid, Plane2),
           S2b = e3d_vec:plane_side(Center, Plane2),
           if (S1a ==S2a) andalso (S1b ==S2b) ->
               gb_sets:add(Fi,Acc);
              true -> Acc end
       end,
    gb_sets:fold(MyFs, gb_sets:empty(), FaceSet).

limit_edges(VS0, VE0, FaceSet2, Es, #{} = We) ->
    %% if the initial verts are on in the face region ... remove edges.
    FaceRgns = wings_sel:strict_face_regions(FaceSet2, We),
    EsIa = wings_edge:from_faces(FaceSet2, We),
    EsIb = gb_sets:intersection(EsIa,Es),
    ConnectsOnly = fun(Region, Acc) ->
               %% if the initial verts are on in the face region ... remove edges.
               _Vs = wings_face:to_vertices(Region,We),
               _Es = wings_edge:from_faces(Region,We),
               I = gb_sets:intersection(gb_sets:from_list(_Vs),
                            gb_sets:from_list([VS0,VE0])),
               case gb_sets:is_empty(I) of
                   true -> gb_sets:subtract(Acc,_Es);
                   false -> Acc
               end
           end,
    lists:foldl(ConnectsOnly, EsIb, FaceRgns).

make_cuts(ETree, We, EsI) ->
    MyCuts = fun(Ei, {#we{}=WeAcc,AccVs}) ->
             Pos = gb_trees:get(Ei,ETree),
             {We1,Idx} = wings_edge:screaming_cut(Ei, Pos, WeAcc),
             {We1,gb_sets:add(Idx,AccVs)}
         end,
    gb_sets:fold(MyCuts, {We,gb_sets:empty()}, EsI).
« Next Oldest | Next Newest »

Users browsing this thread: 1 Guest(s)



Messages In This Thread
The Connect surface tool by Dimitri. - by ggaliens - 02-01-2016, 02:55 AM
RE: The Connect surface tool by Dimitri. - by Dimitri - 02-01-2016, 02:28 PM
RE: The Connect surface tool by Dimitri. - by ggaliens - 02-01-2016, 04:07 PM
RE: The Connect surface tool by Dimitri. - by Dimitri - 02-01-2016, 09:02 PM
RE: The Connect surface tool by Dimitri. - by Dimitri - 02-07-2016, 01:12 PM
RE: The Connect surface tool by Dimitri. - by ggaliens - 02-07-2016, 01:49 PM
RE: The Connect surface tool by Dimitri. - by Dimitri - 02-07-2016, 04:37 PM
RE: The Connect surface tool by Dimitri. - by ggaliens - 02-07-2016, 06:25 PM
RE: The Connect surface tool by Dimitri. - by Dimitri - 02-07-2016, 08:39 PM
RE: The Connect surface tool by Dimitri. - by ggaliens - 02-08-2016, 04:48 PM
RE: The Connect surface tool by Dimitri. - by ggaliens - 03-12-2016, 03:03 PM
RE: The Connect surface tool by Dimitri. - by ggaliens - 03-13-2016, 02:44 AM
RE: The Connect surface tool by Dimitri. - by Dimitri - 03-13-2016, 03:55 PM
RE: The Connect surface tool by Dimitri. - by ggaliens - 03-14-2016, 02:21 PM
RE: The Connect surface tool by Dimitri. - by Dimitri - 03-15-2016, 05:05 PM
RE: The Connect surface tool by Dimitri. - by ggaliens - 03-15-2016, 11:50 PM
RE: The Connect surface tool by Dimitri. - by ggaliens - 03-16-2016, 03:42 AM
RE: The Connect surface tool by Dimitri. - by ggaliens - 03-17-2016, 04:23 AM
RE: The Connect surface tool by Dimitri. - by ggaliens - 03-17-2016, 09:04 PM
RE: The Connect surface tool by Dimitri. - by dgud - 03-20-2016, 03:43 PM
RE: The Connect surface tool by Dimitri. - by ggaliens - 03-20-2016, 06:42 PM
RE: The Connect surface tool by Dimitri. - by ggaliens - 03-20-2016, 11:59 PM
RE: The Connect surface tool by Dimitri. - by dgud - 03-21-2016, 03:39 PM
RE: The Connect surface tool by Dimitri. - by ggaliens - 03-21-2016, 05:20 PM
RE: The Connect surface tool by Dimitri. - by dgud - 03-22-2016, 07:37 AM
RE: The Connect surface tool by Dimitri. - by ggaliens - 03-23-2016, 12:22 PM
RE: The Connect surface tool by Dimitri. - by ggaliens - 03-23-2016, 02:38 PM
RE: The Connect surface tool by Dimitri. - by Dimitri - 03-27-2016, 06:08 PM
A few more changes to support polygon connects ... - by ggaliens - 04-04-2016, 03:38 PM
RE: The Connect surface tool by Dimitri. - by Dimitri - 04-07-2016, 04:26 PM
RE: The Connect surface tool by Dimitri. - by dgud - 04-08-2016, 09:50 AM
RE: The Connect surface tool by Dimitri. - by Dimitri - 04-08-2016, 01:19 PM
RE: The Connect surface tool by Dimitri. - by ggaliens - 04-08-2016, 01:53 PM

  • View a Printable Version
  • Subscribe to this thread
Forum Jump:

© Designed by D&D - Powered by MyBB

Linear Mode
Threaded Mode