# [Bf-committers] Learning Blender Code?

Jonathan deWerd jjoonathan at gmail.com
Wed Jul 2 18:39:22 CEST 2014

```>> So, I'm wondering how others have learned the code, or is it just a matter
>> of putting in lots of time?

It's just a matter of putting in lots of time. Not what you wanted to hear but I think you suspected it was true already.

I'm the summer student working on NURBS. Just wanted to drop by and say that you could work on this bug without stepping on my toes. The NURBS extrusion operator already exists, ctrl+click just doesn't call it. If you stick to calling the extrusion operator you will guarantee compatibility with any changes that I make since I have to make the extrusion operator work regardless.

In order to decide which edge to extrude from, you will need to access the NURBS object (search for "typedef struct Nurb"). Relevant fields are:

Nurb nb;
nb->pntsu; //Number of control points in u direction
nb->pntsv; //Number of control points in v direction
nb->bp; //A 1D array of BPoints that holds the 2D array of control points.
// Writing coords (u,v), they are packed like
// (0,0),(1,0),...,(nb->pntsu-1,0),(0,1),(1,1),...(nb->pntsu-1,1),...,(nb->pntsu-1,nb->pntsv-1).

BPoint p;
p->vec[0]; // x
p->vec[1]; // y
p->vec[2]; // z
p->vec[3]; // w
// NOTE: this BPoint corresponds to the point (x, y, z) in space, *not* (x/w, y/w, z/w) as per mathematical convention for homogeneous coordinates.

Hope that helps. Nurb::bp packing order and BPoint's strange half-homogeneous behavior were discovered by trial+error+debugger. I haven't written any interactive operators yet so I can't help you there. I don't think you would be shooting yourself in the foot by working with the NURBS code. It's old but it seems to use the same operator and undo code as the rest of blender. It's also relatively monolithic compared to BMesh: it doesn't change representations in editmode, it doesn't keep its own separate stack of operators, it doesn't have a domain-specific language to represent modifications (why does BMesh even have that anyway?), and the relevant struct definitions fit handily on half of a single screen.

Cheers,
Jon

On Jul 2, 2014, at 11:50 AM, Howard Trickey <howard.trickey at gmail.com> wrote:

> Some introductory FAQ material is here:
> http://wiki.blender.org/index.php/Dev:Doc/FAQ#Source_Code_FAQ
>
> As it says there, reading all of the docs on
> http://wiki.blender.org/index.php/Dev:Source/Architecture
> is useful, though hard-going and somewhat out of date.
>
> It's probably best to start on just a small area of the code and not worry
> Follow through what happens when you execute some command in an area that
> you are interested in.
> Do what you are trying to do: fix a small problem or make a small feature
> change in that command.
> Probably doing a NURBS task isn't the best idea to start, since there is a
> summer student right now working on revamping NURBS, and anyway that code
> is fairly old and somewhat removed from the modern part of Blender.
>
> - Howard
>
>
> On Wed, Jul 2, 2014 at 11:07 AM, John Alway <jalway at gmail.com> wrote:
>
>> Hello,
>>
>> I've been working to understand Blender code so that I can try my hand at
>> fixing some bugs and adding some features as needed.   However, I'm finding
>> the learning curve to be quite steep.   C and C++ code per se are no
>> problem for me, but it's hard to determine what the code is doing, because
>> there are many abstract concepts that have been implemented.
>>
>> I was trying my hand at Issue T39656, just to see what it would take:
>> https://developer.blender.org/T39656
>>
>> And, to help me along, I've been using the Visual Studio debugger and I've
>> read many things out of the wiki, including this overview:
>>
>> http://wiki.blender.org/index.php/Dev:Source/Architecture/Overview
>>
>> However, at the end of the day, this is proving to be pretty heavy going.
>>
>> So, I'm wondering how others have learned the code, or is it just a matter
>> of putting in lots of time?
>>
>> I do know OpenGL and I have studied many graphical concepts, and I've done
>> a lot of matrix math for rotating and translating objects, etc.   But, I'm
>> sure there is much to more learn, anyway.  There always is!
>>
>> Anyway, I'm just looking for pointers and any kind of help on this.
>>
>> Thanks for any feedback!
>> ...Regards,
>> John
>> _______________________________________________
>> Bf-committers mailing list
>> Bf-committers at blender.org
>> http://lists.blender.org/mailman/listinfo/bf-committers
>>
> _______________________________________________
> Bf-committers mailing list
> Bf-committers at blender.org
> http://lists.blender.org/mailman/listinfo/bf-committers

```