User:HooglyBoogly/GSoC2019/Notes

Project Home
This is a work in progress document! It will be updated as I make progress. At the end I'll try to make sure all the information here is correct though.

[[File:Complete_Mockup.png]]
Modifications New Inputs  Custom profile boolean option Profile curve Vertices at curve nodes option  Symmetrical case option? 

 Custom Profile Struct There are two options for this.  This would be an ordered list of X-Y pairs of nodes on the curve graph and their handle positions. The other option is that there is a suitable storage already associated with the curves that come from the curve builder. And it might be simpler to try to use this existing system.

 The second option proved a better path here with the  code. The harder part is removing the assumption that the path will be a function, in other words removing the sorting that the code does to the. For the sampling this is done by walking down the path of the curve instead of down the X axis. For the drawing I will have to see how the parts below the line are shaded and correct that and remove the sorting as the points are moved around. Sampling the Custom Profile Struct Either way the custom profile is stored, it will have to be sampled, both during the construction and finally with the nseg vertices. The sampling is much more complicated with curves because there is no closed form solution for the distance along a curve, it just has to be subdivided and added up. So I&#39;m focussing on straight lines between the points. The  struct contains   structs that contain   structs with X and Y positions. I built the ability to travel linearly along the list of points to find the position for the ith segment vertex in 2D. Creating a table of known positions and them sampling it later will probably be important for performance though. Finding Even Profile Spacing There may need to be a replacement for. This may necessitate knowing how long the curve is in total and having the ability to travel down the curve a set amount (total length / nseg). However, there won&#39;t be a requirement for even profile spacing if the &quot;Vertices at curve nodes&quot; option is on. This could be a simple case to start out with. Profile Drawing User Interface I hope to be able to reuse the existing CurveMapping user interface template to some extend. Hopefully I will be able to make a different mode with the  argument that will draw the UI specifically for a profile curve, but separating it out into separate code would be possible too, and not too bad. I will get advice about that decision there before I progress too far. The largest difficulty will be changing the profile curve into something that doesn&#39;t have to be a function and-- as mentioned above-- sampling that, because this will be completely new functionality for the curve mapping code. Challenges that came up and how I resolved them: <ol start='' > The curve mapping template doesn&#39;t draw in the modifier UI.</li>

</ol> Piping New Data to Bevel Modifier There are quite a few files and definitions that have to be modified to accept the new arguments: <ol start='' >  : The modifier UI</li>  : The BMesh operator call for the bevel tool. (Tools must run through another step while modifiers are called directly from the C code)</li>  : The bevel exec call</li>  : The obvious one (the actual operator code)</li>  : Just a short header file for the own include</li>  : Holds the modifier data that&#39;s recieved from the UI</li>  : The types / info for the new properties</li>  : Locations and declarations for flags and struct</li>

</ol> Adding the Custom Profile Information After adding the sampled custom profile points (2D) to the  struct I mentioned below, the question becomes whether the mapping from that to 3D in the   struct will need to be different. Because the points I&#39;ve created are still in the 0 to 1 range, I wouldn&#39;t think there would have to be any change in the mapping. The only thing I can think of is that the  function which does the mapping divides the profile in to two pieces, which I would need to change. Regularizing Profile Orientation Along Contiguous Beveled Edges (UPDATE SECTION) One of the problems I&#39;m introducing with custom bevel profiles is the orientation of the profile. One of the problems is more normal-- as I modify the way that the profiles get built, I might mistakenly flip the indices of the profile vertices, so the connections to the next profile along the line will be flipped, creating a whole segment of messed up geometry. The other (possibly more problematic) situation is when the code chooses a different orientation for the profile, so the shape is rotated the other direction compared to another profile. The indices could match up or they couldn&#39;t, either way the connection to the next profile will not be correct. These two situations I described are likely part of the same problem, and the only way to fix it will be to maintain consistent orientation of the profile along contiguous beveled edges. (OUT OF DATE:) There are two types of contiguous beveled edges: cycles and chains. I need to write code that travels down beveled edges to find these contiguous sections. As it travels along the edges it will carry over the orientation of the custom profile by making sure it starts at the same side of the bevel, or the new  that&#39;s linked to the last one with an edge. Here&#39;s the process: <ol start='' > Start at a random .</li> Travel along each  connected to the vertex, marking which of the   the profile will start at when a new vertex is reached.</li> Stop when there is no continuation of the beveled edge, or when the next  has already been visited.</li> As long as there is still another unvisited, start the process there again, and in the end all of the   will be visited.</li>

</ol> This should give enough information to pick which  to start building the bevel profile from in. However, I&#39;m not sure how this will interact with intersections of &gt;2 beveled edges. As soon as a beveled edge comes into one of these larger intersections the profile will be messed up to some extent anyway, so maybe I should treat the a &gt;2 way intersection as another stopping point for the travelling code. But then it&#39;s not clear that anything would happen on a shape like a cube where all of the  have 3 incident beveled edges. If there are many other edges with the same angle to the current edge, should you really even continue at all? So maybe this should just keep track of whether there is ambiguity, and if there is, it will just stop travelling. And it should probably only try to find the best route through a vert when there are less than 4 or so beveled edges comint into it. Passing Along the Choice of BoundVert for Profile Start (UP TO DATE:) Possibly the most obvious idea for how deciding which side of the beveled edge the profile should start on is just by distance to the last profile start. On reaching the next  the new   that was closest to the   that was last marked as the profile start would also be marked as the profile start point, and the opposite   would be marked as the end point. But after looking at this method further, it&#39;s clear that this method doesn&#39;t work when the sequence of beveled edges curves-- the orientation can flip when the beveled path turns back on itself and the profile start is on the outside of the curve. This means a more more complicated method will be needed to carry over the profile&#39;s orientation to the next edge. The solution I came up with is this (assume we&#39;ve just travelled to a a new EdgeHalf and we marked one of the last &#39;s   as the profile start): Case 1: Travelling into a  In this case the last profile start vertex is on the other side of the (full) edge. <ol start='' >  Choose one of the &#39;s. </li>  Visit all  connected to that  &#39;s BMVert. </li>  See if any of the vertices meet these three conditions: <ol start='' > <li>Have a </li> <li>That  was marked as the start of its bevel profile</li> <li>That  was the one we last marked as the start of its profile</li>

</ol> </li> <li> If the conditions are met,  selected in part 1 should be the profile&#39;s start. If they aren&#39;t met, the start should be on the other side. </li>

</ol> Case 2: Travelling out of a  In this case the last profile start vertex is on the other side of the. I&#39;m still thinking about this case, but maybe I can travel around the &#39;s boundary edges and check which of the two   choices is more steps away from the last. Backlog There are backlog items here, along with notes and smaller items tagged with  in the code. Here are tasks that I will need to come back to, but I&#39;m passing over for the moment to make faster progress towards the most important goals. The more important are on top. <ol start='' > <li>The bevel tool crashes on invocation. (Slots to bmesh-op issue)</li> <li>There is a memory leak of the  struct (Where to free it?)</li> <li>Fix the drawing to not assume a X&lt;-&gt;Y map in the profile widget</li> <li>Don&#39;t sort the list of  only in a &quot;path&quot; widget</li> <li>Sampling the profile path with curved interpolation</li> <li>Discarding const qualifier into CurveMapping code warning</li> <li>Merge the sampled custom profile points with the normal points when all cases are completed</li> <li>Versioning for old bevel modifiers so the profile curve is filled with a new curve_mapping. Maybe this just needs a check for whether the pointer to the profile curve is null, but right now even opening an old file with a, the pointer goes bad.</li>

</ol> Finished Backlog items: <ol start='' > <li>...</li>

</ol> BMesh Bevel Implementation Notes Questions There are questions here, and more questions in the code labelled, although I generally remove those when I answer them. <ul> <li>Is there any parallel computation with ? No, there isn&#39;t, but it&#39;s fast enough without it, at least the speed-up probably wouldn&#39;t be worth the effort. Plus the outcome sometimes depends on the order of the calculations so parallelization would be even harder. </li> <li>I&#39;m curious about the reasoning for calling  multiple times rather than finding the correct parameters for each   first and build the structure properly then. I guess you need to have the structure built to do the calculations anyway. The actually vertices are only created on the first call to build boundary. Anyways the recalculations and optimizations need the initial state created the first time. Essentially it&#39;s just the same function doing different things. </li> <li>Which code creates the boundaries on the edge of the ? The boundary profiles are created in, where it seems like most of the mesh is created. </li> <li>Does &quot;Custom Profiles&quot; directly conflict with &quot;Only Vertices?&quot; I would think it does. If so, it would be nice to gray out them to gray out each other when one of them is selected. Although I suspect there are other conflicting settings that don&#39;t do that currently.</li> <li>What case arrises with just two edges coming together at a single vertex? (with the vertex bevel tool). I thought this was the definition of the weld case.</li> <li>What is the case called for the middle edge of a two face strip?</li> <li>Is there a good way to get the  that an   is connected to?</li>

</ul> Important Functions in bmesh_bevel.c In approximate order of appearance in  <ul> <li> bevel_vert_construct : &quot;Construction around the vertex&quot; Clarify what this means </li> <li> build_boundary : Creates the list of  with their initial positions </li> <li> bevel_limit_offset : Finds the biggest that the width can be without colliding into other geometry </li> <li> adjust_offsets : Finds the best solution to the graph of bevel width dependencies by solving the cycle and chain cases separately. Rebuilds the boundary structure with the better widths. </li> <li> build_vmesh : Creates the BMesh vertexes for both the boundary and the interior of the mesh. Creates a bunch of <ul> <li> calculate_profile : This is the function that actually gives the coordinate values for the  profile. Currently works by sampling the super-ellipse (Also samples at powers of 2 to just beyond the number of segments for the construction of the ADJ pattern)</li>

</ul> </li> <li> bevel_build_edge_polygons : Builds the polygons along a beveled edge </li> <li> bevel_extend_edge_data : Used for carrying over edge data from the original mesh to the new geometry. </li> <li> bevel_rebuild_existing_polygons : Rebuilds the original geometry that was attached to the bevels. <ul> <li> bev_rebuild_polygon : Rebuilds a face that had at least one beveled vertex</li>

</ul> </li> <li> bevel_reattach_wires : Also used for reattaching original geometry, this just for wire edges </li> <li> bevel_harden_normals : Largely separate feature to keep the original faces looking flat </li> <li> bevel_set_weighted_normal_face_strength : Figure out what face strength is </li>

</ul> Storing the Profile Information The profile information is stored in a couple of places. The first is the  struct which contains the 2D locations of the vertices in the profile, and also their higher power of 2 counterparts. It&#39;s called &quot;profile spacing&quot; because what it originally stored was the result of the calculations for the even spacing along the superellipse function. The  struct is stored commonly for the entire bevel operation. Further along in the calculation the profile information is stored in the  struct that&#39;s attached to every. The profile struct stores the 3D coordinates of every location in the profile and other information related to the mapping of the 2D coords into 3D: control points along the profile, and infomation about the plane the coordinates are mapped onto. Weld Bevel Case The simplest case for bevel is when just two lines come together at a point and the point is converted into the new bevel profile. This case is detected in  when both: <ul> <li>The number of selected vertices around the  is only 2. (bv-&gt;selcount == 2) </li> <li>There are only 2  total around the. (vm-&gt;count == 2) </li>

</ul> The mesh vert kind  is used for the weld case, because the only thing that&#39;s built is the profile of the edge. Terminal Edge Case The terminal edge case occurs when there is only 1 beveled edge coming into a vertex. This doesn&#39;t seem to need much work except for giving it the new sampled profile. One thing that could be a problem is the triangle fan mesh type (for when there are 3 other edges besides the beveled edge). Because the profile could overlap with itself, there may need to be a more complicated solution to fill the end of the profile. Hopefully it&#39;s possible to use some existing mesh fill method rather than writing a new one to cap the profiles when. Bevel Documentation Notes Questions <ul> <li>How is it possible that a boundary arc has half the number of &quot;rings of quads&quot; as the number of segments? The boundary arc is created in halves, one from each  that connects to it. This strategy works fine when you can assume that the profiles are symmetrical and they will necessarily meet in the middle of the two edges that bound it. Removing this assumption will likely be one of the difficult parts of the problem. </li> <li>Why do the bound verts that connect to two beveled edges not have two ebev pointers? It looks like the ebev pointer is just a pointer to the edge counterclockwise from the bound vert, but what is the use of that?</li> <li>Why would there be multiple  in each   if there is only going to be one final vertex at each position anyway?</li> <li>The indexing of  is also confusing. I only see two indexes for each vertex on the diagrams. And I&#39;m not quite sure about the motivation for those choices of indices.</li> <li>How much should I internalize the formulas for the new vertex positions in the new vertex positions? At what level of abstraction do you usually work at?</li> <li>If the subdivisions steps to create the  give a power of two number of segments, how do you step down to the specified nseg after going past it? There is basically interpolation downsampling that happens after the power of 2 profiles are created. The reason this needs to happen is the subdivision process of building the ADJ pattern. </li> <li>I&#39;m finding it difficult to get a good understanding of all the math in the section about solving for the best bevel widths. Is it worth it to spend more time with this? It doesn&#39;t seem like my project will touch this part of the code.</li>

</ul> Creating the Beveled Vertices A Boundary Arc is the profile at the end of an edge where it meets a beveled vertex. Each beveled vertex becomes a. Each  contains a bunch of   which are the edges going into the vertex, and not just the beveled ones. The  have a counterclockwise order. After the beveled  are finished, the   are created, and are also linked together in a counterclockwise circular list. Any beveled  will be connected to two. point to, one pointer for each direction left and right. And each  has two pointers to the bound edge halves as well, one for &quot;first,&quot; and one for &quot;last,&quot; which use a counterclockwise order. The &#39;s mesh data is kept in another struct called , which is mostly an array of new vertices (with their coordinates and BMesh vertex pointer). Each boundary arc is divided in two and a verte is added to the center of the beveled vert to join them. The mesh is created with a subdivision process where new verts are added in between existing ones (first the face vertices then the edge vertices). The coordinates are changed as more subdivisions happen. The theta values for parameterizing the superellipse function are precomputed at the beginning to give even spacing. And the subdivision steps use the parameterization too, so powers of two need to be calculated to the number of segments. Adjusting the widths to maintain ...? A graph of edge width requirements is created, with priorities for consistent widths in this order: adjacent beveled edges, the two ends of a beveled edge, beveled edges with a non-beveled edge in between, opposite sides of the same beveled edge (which the code ignores).