# Add new parametric curve object/type using Python

I'm thinking of implementing an add-on (using Python) for Lagrange curves. In short (after an instance has been added), in Object Mode there should just be a curve (i.e. the parametric curve evaluated at a couple of parameter values subsequently connected by line segments) like a Bézier curve, whereas in Edit Mode there should be a control net as well (similar to the control net of a NURBS curve) that allows the user to change/modify the curve. In addition, it should be possible to assign a numerical value to each point/vertex and edge of the control net.

My approach would be to draw the curve using bgl (given a polynomial degree, the values assigned to the edges could act as parameter spans, thereby defining Lagrange basis functions — any position on the curve can then be computed as the sum of the control points multiplied by their associated basis functions). However, I'm not sure how to make the curve into an actual object (such that it can be selected, saved, ...). In addition, it should still be possible to change the resolution of the curve at a later time.

Next, how/where to store the control net and additional information? My approach would be to create a mesh for this purpose and store values in a bmesh layer. In Object Mode this mesh should be hidden. But how to link it to the curve (changing values re-defines the basis functions which should result in a different curve, likewise moving control points should change the curve)?

I realize this is a rather comprehensive question -- I'm fairly familiar with bmesh but apart from simple scripts I don't have much experience coding things in Blender. Any thoughts on a general workflow (see steps/outline above) or references to similar add-ons would be much appreciated!

• Have a look at the motion trail addon, it's fully interactive in 3D viewport (with handles you can drag). Note that it's a really complex script, because you need to do everything, from event capturing to processing and OpenGL drawning. – CodeManX Dec 4 '14 at 15:03
• @CoDEmanX Thanks for the link. Hmm, would you recommend implementing this in C++ instead (and compile a local branch of Blender)? – Ailurus Dec 5 '14 at 14:08
• It's probably even harder to do in C++, but depends on your programming skills. You will have more control of what you can do and performance should be far better. – CodeManX Dec 5 '14 at 14:46