Which part of an edge is visible in the view

Which part of an edge is visible in the view

AGGilliam
Collaborator Collaborator
693 Views
6 Replies
Message 1 of 7

Which part of an edge is visible in the view

AGGilliam
Collaborator
Collaborator

I recently created a tool similar to the flatten or flatshot commands in AutoCAD so the user doesn't have to leave Revit to create certain details; it loops through the edges of the selected element(s), projects them onto a plane, and draws them on a drafting view. However, this results in a wireframe drawing that would need to be trimmed. I've tried brainstorming how I could go about drawing only what's seen in the view, but my ideas (trimming the lines based on intersections; creating extrusions, cutting them, and drawing the resulting faces) resulted in a dead end. I was curious if anyone here had any creative ideas?

0 Likes
694 Views
6 Replies
Replies (6)
Message 2 of 7

jeremy_tammik
Alumni
Alumni

Wow, sounds tricky. What do you have? A bunch of lines and a polygon enclosing (part of) them? And you would like to trim the lines against the polygon? Sound like a Boolean operation to me, and I would search for a computational geometry algorithm to address it.

 

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
Message 3 of 7

AGGilliam
Collaborator
Collaborator

I start by selecting elements from a 3D view, for each element selected I grab its geometry and project the edges onto a 2D plane. At this point it's just a bunch of lines that resemble a wireframe of the selected element. My goal is to sort these lines by face and trim appropriately. For example, if I selected a cube from an isometric perspective, you shouldn't see the edges on the other side of the cube because they're not visible. So yeah, I would be trimming the lines with the polygon being the face(s) / curve loops in front.

 

I would agree that sounds like a boolean operation, but I'm stumped on how to go about accomplishing it. I did manage to stumble across this project though that seems to be somewhat similar. I'll try looking into computational geometry algorithms and see what pops up.

0 Likes
Message 4 of 7

AGGilliam
Collaborator
Collaborator

Okay, so I figured out what computational geometry is (sort of) and I found a library of methods designed for that purpose called Clipper. I've referenced it in my project but now I need to figure out how to implement it. I think I'll have to isolate it to a selection of a couple faces rather than looping through all of them because the result keeps returning empty and I don't know why haha. Hopefully I'll have some good results to share after tomorrow.

0 Likes
Message 5 of 7

RPTHOMAS108
Mentor
Mentor

Not sure you'll fully solve the problem this way because the face edges may not always represent the actual edges of the object in relation to view direction. I don't know how you are currently resolving that?

 

As an example a solid cylinder will likely have four faces, one planar face at each end and two cylindrical faces joined to form the shaft face. In such an example will the edges of each cylindrical face (two lines and two arcs) coincide with the edge of the solid from the view direction (all view directions)? These things are mathematical faces but in the end all such faces are split into triangles for graphical display.

 

If you have a series of 3D graphical triangles, edges and face normal values:

Each triangle normal value can be compared to view direction (facing more towards, more away or perpendicular to via dot product).

Each edge is part of two triangles (for fully enclosed volume).

If an edge is part of one triangle with normal that points more opposite to view direction than towards and one triangle that points more towards than opposite the view direction (or perpendicular to) then that edge is part of the periphery I believe i.e. it is in a region where the face starts to curve away from viewer.

 

After getting the edges that are on the periphery form loops by comparing ends, you may get overlaps.

You then decide either keep lines or draw curves through points of lines that form loops.

 

You still then have secondary problem of one solid totally obscuring another. To eliminate such ReferenceIntersector.FindNearest could be used with rays pointing in view direction with search grid based on view scale. This may be the first step since it will identify the parametric faces that need to be triangulated.

 

I would have suggested IExportContext2D.OnFaceEdge2D but this notes that it exports non visible edges also.

 

I suppose it is obvious to state you only need to follow this more convoluted approach for non-planar faces.

Message 6 of 7

AGGilliam
Collaborator
Collaborator

Thanks for the insight! I hadn't even considered non-planar faces yet, the only parts I've tested so far have planar faces. I like the idea of looking at the triangles from the mesh, I'll have to look into that when I get to some of our non-planar components.

0 Likes
Message 7 of 7

AGGilliam
Collaborator
Collaborator

It took me a little while, but I finally figured out how to make use of the Clipper library. I had some weird results at first because I forgot to account for the fact that it uses integers for the points, so 2.5 ft became 2 ft and so on. Now that I have the basic concept figured out, I just need to scale it up. For anyone else interested, this example (among other documentation on the site) helped a lot with getting started. I'll make another post when I have something interesting to show.

0 Likes