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!

  • 1
    $\begingroup$ 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. $\endgroup$ – CodeManX Dec 4 '14 at 15:03
  • $\begingroup$ @CoDEmanX Thanks for the link. Hmm, would you recommend implementing this in C++ instead (and compile a local branch of Blender)? $\endgroup$ – Ailurus Dec 5 '14 at 14:08
  • $\begingroup$ 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. $\endgroup$ – CodeManX Dec 5 '14 at 14:46

There is an extra objects addon that provides a 3d function surface that should help with how to create the mesh.

For the showing the surface in the viewport I would look at CGCookies retopology tools. If you watch the demo video you will find they draw a preview over the mesh object before creating the final mesh data.

You might want to look at the PropertyGroup or Collection types as a way to add extra data to an object.

There is a chance you may be asking too much for python, maybe you need to consider it as a patch to be added to blenders main source code.

  • $\begingroup$ Thanks for your answer :). Ah, the retopology tool reminded me of the BSurfaces add-on. Yes, the patch approach might make more sense (partially because the description in my question is a much simplified version of the actual project). $\endgroup$ – Ailurus Dec 5 '14 at 14:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.