• 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 Design & Development v
1 2 3 4 5 … 12 Next »
To Micheus about Ivla Vert|Perpendicular Connect idea

 
  • 0 Vote(s) - 0 Average
To Micheus about Ivla Vert|Perpendicular Connect idea

Luiz Fonte Boa
Offline

Junior Member

Posts: 17
Threads: 4
Joined: Nov 2026
#1
12-01-2026, 03:35 AM (This post was last modified: 12-01-2026, 03:39 AM by Luiz Fonte Boa.)
The idea of user "Ivla" remained on my mind, Micheus. So... 

-------------------

Hello Micheus! First of all, thank you for all the continuous hard work and dedication maintaining and improving Wings3D.

In these times of artificial intelligence—and considering the idea of using it as an ally—this whole suggestion actually started while I was just playing around with Google's Gemini AI. To be completely honest, I am just copying and pasting what it gave me here! Haha! So I would love to know from you, dear Micheus, if the structure of these instructions makes any sense at all—because for me, as you know, this is all Greek!

Following up on the original idea brought up by user **IVLA** in the thread https://wings3d.com/forum/showthread.php...n=lastpost, I would like to respectfully suggest a small feature for future consideration: a Vertex | Perpendicular Connect command, which would allow connecting a selected vertex directly to an opposite edge at an exact 90-degree angle.

Just as a starting point or conceptual reference, here is one possible way this could be structured within `src/wings_vertex_cmd.erl`:

### 1. Context Menu Entry (`menu/1`)
Adding the command alongside the existing `Connect` options in Vertex mode:

```erlang
menu(St) ->
    [ ...
      {?__(10,"Connect"),connect,
      ?__(11,"Create a new edge by connecting selected vertices")},
      {?__(12,"Perpendicular Connect"), perp_connect,
      ?__(13,"Connect selected vertex perpendicularly (90 deg) to a target edge")},
      ...
    ].
```

### 2. Command Routing (`command/2`)
Mapping the `perp_connect` atom to prompt the user for the target edge:

```erlang
command(connect, St) ->
    ?SLOW(connect(St));
command(perp_connect, St) ->
    ask_perp_connect(St);
```

### 3. Orthogonal Projection Logic
Using vector dot product to find the exact 90-degree intersection point on the target edge before splitting and connecting:

```erlang
%%%
%%% Perpendicular Connect (90 degrees)
%%%

ask_perp_connect(St) ->
    wings:ask({[{edge, ?__(14,"Select target edge for 90-degree connection")}], []},
              St, fun do_perp_connect/2).

do_perp_connect({TargetEdge, _}, #st{sel=[{Id, SelVertices}]} = St) ->
    case gb_sets:to_list(SelVertices) of
        [VertP] ->
            wings_sel:map(
              fun(_, #we{id=WeId}=We) when WeId =:= Id ->
                      apply_perp_cut(VertP, TargetEdge, We);
                (_, We) ->
                      We
              end, St);
        _ ->
            wings_u:error_msg(?__(15,"Select exactly ONE source vertex first."))
    end;
do_perp_connect(_, _) ->
    wings_u:error_msg(?__(16,"Select one vertex in a single object.")).

apply_perp_cut(VertP, Edge, #we{vp=Vtab, es=Etab}=We0) ->
    #edge{vs=VertA, ve=VertB} = array:get(Edge, Etab),
    PosP = array:get(VertP, Vtab),
    PosA = array:get(VertA, Vtab),
    PosB = array:get(VertB, Vtab),

    AB = e3d_vecConfusedub(PosB, PosA),
    AP = e3d_vecConfusedub(PosP, PosA),
    LenSq = e3d_vec:dot(AB, AB),

    case LenSq > 1.0e-12 of
        true ->
            T = e3d_vec:dot(AP, AB) / LenSq,
            if
                T > 0.0001 andalso T < 0.9999 ->
                    PosQ = e3d_vec:add(PosA, e3d_vec:mul(AB, T)),
                    {We1, VertQ} = wings_edge:fast_cut(Edge, PosQ, We0),
                    {We2, _NewSel} = wings_vertex:connect(VertP, [VertQ], We1),
                    We2;
                true ->
                    wings_u:error_msg(?__(17,"Perpendicular point falls outside the edge segment."))
            end;
        false ->
            wings_u:error_msg(?__(18,"Target edge has zero length."))
    end.
```

*(Note: I also realize there are three tricky edge cases to keep in mind: ensuring both the vertex and target edge actually share the same face, handling non-planar faces where a 90° cut might create an unexpected crease, and obtuse angles where the perpendicular projection falls outside the edge segment).*

Of course, you know the internal architecture and edge-case conventions of Wings3D far better than I do, so please feel free to adapt or disregard this snippet as you see fit. Thank you again for your time and for keeping Wings3D such a great tool!
Luiz Fonte Boa
Offline

Junior Member

Posts: 17
Threads: 4
Joined: Nov 2026
#2
12-01-2026, 03:43 AM (This post was last modified: 12-01-2026, 03:51 AM by Luiz Fonte Boa.)
Alternatively, instead of creating a separate command in the Vertex menu, another very natural approach would be integrating this as a 90-degree perpendicular snap directly inside the interactive Tools | Connect tool (for example, triggered by holding a modifier key like Ctrl or Shift while dragging along the target edge).

Conceptually, this could be structured within plugins_src/commands/wpc_connect.erl as follows:

1. Updating the Help / Information Line
Adding a hint in the bottom status bar when the user is dragging a connection from an existing vertex to an edge:

Code:
%% Inside the interactive drag loop help string:
"Drag along edge to slide  [Ctrl] Snap to 90° perpendicular"

2. Intercepting the Drag Event (Modifier Key Check)
During the mouse motion event when the previous point was a vertex (PosP) and the cursor is currently sliding over an edge (VertA to VertB):

Code:
handle_motion(Event, #cstate{prev_pos=PosP, curr_edge={VertA, VertB}}=State) ->
    %% Calculate standard mouse slide percentage (0.0 to 1.0)
    RawT = calc_mouse_slide_t(Event, VertA, VertB),
   
    %% Check if the modifier key (e.g., Ctrl) is held down
    T = case is_ctrl_pressed(Event) of
            true ->
                calc_perpendicular_t(PosP, VertA, VertB, RawT);
            false ->
                RawT
        end,
    update_preview_vertex(T, State).

3. Orthogonal Projection Helper Function
Using vector dot product to override the slide percentage T with the exact 90-degree projection point:

Code:
calc_perpendicular_t(PosP, PosA, PosB, FallbackT) ->
    AB = e3d_vec:sub(PosB, PosA),
    AP = e3d_vec:sub(PosP, PosA),
    LenSq = e3d_vec:dot(AB, AB),

    case LenSq > 1.0e-12 of
        true ->
            T = e3d_vec:dot(AP, AB) / LenSq,
            %% Only snap if the 90-degree point lies inside the edge segment
            if
                T > 0.0001 andalso T < 0.9999 -> T;
                true -> FallbackT
            end;
        false ->
            FallbackT
    end.

(Note: Integrating this into Tools | Connect actually handles face-sharing validation naturally since the interactive tool already restricts connections to valid adjacent topology. However, two edge cases still apply: non-planar faces where a 90° cut might create an unexpected crease, and obtuse angles where the perpendicular projection falls outside the edge segment—handled above by smoothly falling back to standard mouse sliding).
PS:
To avoid any conflict with Wings3D's standard camera navigation or selection modifiers (Ctrl, Shift, Alt), this perpendicular snap could be toggled using a clean, non-conflicting hotkey while dragging—such as pressing [1] (or whatever available key fits Wings3D's input conventions best).
micheus
Offline

Forum's Admin and Support | Bug fixer
Posts: 3,744
Threads: 201
Joined: Jun 2012
#3
12-01-2026, 12:28 PM
I liked the second approach. I would avoid to create a command just for this.
Currently, Connect Tool already uses the key [1], so we would need to use [2] for that. Also, in this mode we probably will need to "disable" the vertices highlight since it's like an snap - moving the mouse pointer on the edge and we getting near to its vertex the "selection" just jumps to the vertex.

Thanks for the pseud-code. AI really can help with insights and some small code, but we need to be sure it is nothing inflating it. I also have been doing some tests with it. Smile
[Image: tw.png] @MicheusVieira [Image: yt.png] @MicheusVieira [Image: da.png] Micheuss [Image: ig.png] micheus4wings3d
* Wings3D Team stands for: Björn and Dan
micheus
Offline

Forum's Admin and Support | Bug fixer
Posts: 3,744
Threads: 201
Joined: Jun 2012
#4
12-01-2026, 10:20 PM
Fonte Boa,
Since you cannot test on v1.5.4 I recorded this gif. Take a look and see if is there something unexpected.
I didn't filter the cut crossing edges although it's not a big deal.

In case someone else wants to check it, here is the patch (for v2.4.1): wpc_connect_tool.beam

[Image: connect-perpendicular.gif]
[Image: tw.png] @MicheusVieira [Image: yt.png] @MicheusVieira [Image: da.png] Micheuss [Image: ig.png] micheus4wings3d
* Wings3D Team stands for: Björn and Dan
« Next Oldest | Next Newest »

Users browsing this thread: 1 Guest(s)



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

© Designed by D&D - Powered by MyBB

Linear Mode
Threaded Mode