GSoC 2016: Improvements for Bezier Curves

Synopsis

Most architectural and engineering projects nowadays involve a strong part of surface modeling. To do this kind of modeling objects like Bezier or NURBS curves are required. These provide a great amount of editing freedom. However, current limitations require these objects to be converted to meshes in order to perform tasks such as multiple material assignment. With this project I propose to improve curve editing by adding features that currently require the curve to be converted to mesh, or cannot be performed at all.

I will also improve the documentation of the code related to curve editing (by editing documentation and by improving the comments on the code).

Benefits

This project would simplify the workflow for Blender users working in architectural or product design.

This project would also benefit future Blender development since by improving the documentation of the existing code it will allow for future developers to better understand what is going on under the hood, and therefore spend less time trying to crack the code.

Deliverables

The user-level features I plan to implement are:

• Multiple material slots. The user would be able to assign materials to the edges of the curve, and when making a shell using, for example, the screw modifier these would be inherited by the resulting mesh.
• Improve curve editing tools by adding trim, extend, intersect, fillet, chamfer and offset functionality.
• Improved curve extrude functionality (an example can already be seen in my patch https://developer.blender.org/D1841)
• Add an option for uniform UV calculation (that is, no stretching on longer segments and shrinking on shorter ones)

I will make efforts to ensure backwards compatibility in all modifications. Along with each modification, I would provide a tutorial on how to use each of the features, along with the necessary documentation.

Project Details

Regarding the features proposed in the Deliverables section, in the previously mentioned order:

Currently, it is impossible to assign different materials to curves in Blender. This means that users wanting to modify the appearance of their objects have to convert them to meshes and then assign the materials. My proposal is to add the ability to assign different materials to both curve edges and vertices. These materials would then be inherited by the operations that followed.

CAD software allows users to trim, extend and intersect lines in sketches. The objective is to add these features to curves in Blender. The user would be able to trim curve segments, extend a curve until intersection with another (for 2D curves this is trivial; for 3D curves, the intersection will be calculated taking into account the user view). Further work would involve implementing a fillet and chamfer feature for curves. The fillet and chamfer operators would be applied to vertices. This is mainly useful when working with vector handles. An offset operation will also be added. More information on this point is added below.

Currently, when extruding a Bezier curve (with extruding I mean the extrusion in object mode), Blender extrudes the curve by twice the amount given by the user. This requires the user to think twice before inputting a value. The objective of this part would be to make the behavior more coherent (for each Blender unit inputted, the curve would only extrude one unit). The user would also be able to choose the extrude direction (positive, negative or symmetric). Changes made to this part of the code would also have to be made to the bevel functionality, since code is shared between the two.

When calculating the UVs for a curve object, the distance in-between handles affects the relative stretching and/or shrinking of certain parts of the curve. As a consequence, the user has to perform some manual corrections to ensure good mapping of images to the curve. The idea would be to approach the UV coordinates to object space coordinates.

Some background on Bezier curves

Bezier curves are parametric curves that run through a start and an end point, with some control points in the middle that control the curvature. The parametric functions that define them are the binomial polynomials, which are weighted according to the coordinates of the respective control points. As an example consider the curve defined by the points (10,10), (10,20), (20,10) and (20,40). This is curve can be interpolated by a cubic binomial polynomial:

$x = 10 \times (1-t)^3 + 10\times(1-t)^2\times t + 20\times(t-1)\times t^2 + 20\times t^3$ $y = 10\times(1-t)^3 + 20\times(1-t)^2 \times t + 10\times(t-1)\times t^2 + 40\times t^3$

Trim, extend, intersect and related features

For the trim feature, I propose the implementation of two behaviors. The first one is of a tool similar to the knife tool. The user would click and drag over the segment he wanted to erase, and that segment would be deleted, with the remaining segments preserved. In the curve depicted above, this would delete the whole curve. The second one is more similar to AutoCAD trim functionality, which uses curves to cut other curves. As mentioned previously, Bezier curves are parametric functions. The parameter varies between 0 and 1 (respectively, the start and end points). The curve can be extended by simply increasing the value of the parameter, and adding a new handle at the intersection point. This opens two possibilities on the plane, and infinite possibilities on 3D space. On the plane, the user may want linear extension (a straight line from the endpoint to the intersection) or an extension of the curve itself. These two features can be easily added. In 3D space however, the curves may even never intersect. One solution would be to intersect the curves considering the view plane. In this solution, the code for extensions on the plane can be used. Some work has already been done regarding trim and extending in Blender. The add-on can be found in here: https://github.com/jimflim/blender-scripts In order to implement an extend feature, an intersection feature must be in place. Though obvious to the viewer, this is not so obvious when talking about equations. In order to intersect and offset the curve, I am planning on following the algorithm available on http://pomax.github.io/bezierinfo/#offsetting Tools for offsetting and filleting are already available, but as commercial add-ons.

Project Schedule

I will use the community bonding period to identify the code responsible for each of the features mentioned above that require improvement. I will also study the existing add ons and patches that already implement, to some extent, the features mentioned above, and try to understand what went wrong or what is missing, and devise an initial plan to implement these features. I will discuss this plan with my mentor, the developers, and the user community, to have some initial feedback. Together with the plan I will write a few proof-of-concept add-ons, in order to have a notion of what to implement in Blender's source code, and the best way to do this. On the 23rd of May I will start coding. I will have 4 exams until the 18th of June, and so I will have to manage my time between Blender and college. My objective is to have a working prototype for at least half of the features by this time. During the mid-term evaluation, I will once again contact everyone to ask about eventual issues that may rise as consequence from the changes performed. I will also release a test build so that users may test what has been done and give feedback accordingly. I am expecting to spend the first two weeks of July in this, and use this time to improve the code and write some documentation. In the third week of July, I will pick up on where I left implementing the features, and will proceed implementing what is left. My objective is to have everything working by the first week of August. That way, I will be able to use the week from 15 to 23 of August to focus solely on tidying the code, and write the remaining documentation.

Bio

I am a first year Mechanical Engineering student at the Instituto Superior Técnico of Lisbon's University. I grew up watching Pixar movies, and so when I discovered Blender 6 years ago I was immediately attracted to it. The three years that followed were a painful learning experience, which I enjoyed deeply, and that even today helps me in many things. However three years ago I had to stop working with Blender, and thought little about it until recently. Right now I am trying to pick up on where I left, but most of my time I spend it working on CAD software. I have been programming in Python for the last 6 years, mainly implementing algorithms for research in abstract algebra and computational algebra. I have also worked with C, and successfully added features to one of the external packages that we use mostly (Prover9). I was always attracted by the idea to contribute to Blender, and to prove I am able to work through its code I decided to try and implement the aforementioned patch (https://developer.blender.org/D1841). The thing that attracts me more to Blender development is the perfect match between maths, programming, and (3D) graphics, which are some of my biggest interests.

Sources

The original document which detailed many of these ideas: [1]