• 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.

ggaliens
Offline

Erlang Hacker
Posts: 954
Threads: 143
Joined: Nov 2012
#22
03-20-2016, 11:59 PM
Code is a little heavy. Want it to read better. Could use a bit of your help Dan. I think there is at least one thing I'd break out and put into wings_vertex.

Code:
command({vertex,{manifoldlab,connect_surface_norm}},#st{sel=[{WeID,Set}]}=St0) ->
    #we{es=Etab} = We = gb_trees:get(WeID,St0#st.shapes),
    [VS0,VE0|_] = gb_sets:to_list(Set),
    Pt1a  = wings_vertex:pos(VS0,We),
    Pt2a  = wings_vertex:pos(VE0,We),
    Mid0 = e3d_vec:average([Pt1a,Pt2a]),
    V1 = e3d_vec:sub(Pt2a,Pt1a),
    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)),
    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, A_B_C_D),
        S2 = e3d_vec:plane_side(Pt2, A_B_C_D),
        if (S1 /= S2) ->
            D1 = abs(e3d_vec:plane_dist(Pt1, A_B_C_D)),
            D2 = abs(e3d_vec:plane_dist(Pt2, A_B_C_D)),
            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,
    ETree = array:sparse_foldl(MyAcc, gb_trees:empty(), Etab),
    Es = gb_sets:from_list(gb_trees:keys(ETree)),
    St2 = St0#st{selmode=edge,sel=[{WeID,Es}]},
    #st{sel=[{WeID,FaceSet}]} = St3 = wings_sel_conv:mode(face,St2),
    MyFs = fun(Fi, Acc) ->
        Center = wings_face:center(Fi, We),
        S1a = e3d_vec:plane_side(Mid0, Plane1),
        S2a = e3d_vec:plane_side(Center, Plane1),
        S1b = e3d_vec:plane_side(Mid0, Plane2),
        S2b = e3d_vec:plane_side(Center, Plane2),
        if (S1a ==S2a) andalso (S1b ==S2b) -> gb_sets:add(Fi,Acc); true -> Acc end
    end,
    FaceSet2 = gb_sets:fold(MyFs, gb_sets:empty(), FaceSet),
    %% 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,
    EsI = lists:foldl(ConnectsOnly, EsIb, FaceRgns),
    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,
    {We2,Vs} = gb_sets:fold(MyCuts, {We,gb_sets:empty()}, EsI),
    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}]};
« 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