develop and improve the source code of blender?

Is there anyone have experience of developing of source code of blender. if i want to add some new tools for blender ,how could i do. is there some tutorials ?:spin:

From time to time I see people asking about becoming a blender developer,
Here is my (general) advice.
Just a note that I assume if you read this you are not a guru programmer already :),

Firstly blender is a big application with many different areas so the skills you need depend a lot on what area you want to work on so donā€™t assume specific skills are needed before doing any blender development.

  • Education in computer science/programming not necessary, many blender developers are self taught (including myself).
  • Strong math background isnā€™t essential, though you will probably end up learning some math along the way.

So, where to start? - many people start with some idea of what they would like to change with blender, but be prepared that it may take a while to learn enough to make these changes, so you may need to think of some easier projects and work up to this.

Firstly pick a general area youā€™d like to investigate and try making small changes, reading the source and generally learn how it works, this way you donā€™t get bogged down by the fact blender has 1000ā€˜s of files all this code you donā€™t understand!.

Examples:

  • Take a python script template and modify it to do something useful.
  • Write a simple exporter to a mesh format.
  • Take an existing tool and improve it in some way.
  • Take an existing node/modifier/script/addon and use it as the basis for your own work.
  • Look at the bug tracker and try fix a bug (be really careful here, mostly the old bugs are very tricky, try looking at the newer bugs).

There are a few things that you need to be careful of when starting up.

  • If you work on projects that are not enough of a challenge it can be hard to stay motivated.
  • If you work on projects that are too complicated they may be too difficult to complete.
  • What your capable of and what you want to do probably are not on the same level, try have realistic expectations.
  • If your unsure of something, join in the #blendercoders IRC chat room or ask on the http://lists.blender.org/mailman/listinfo/bf-committers mailing list.
  • Donā€™t be too disappointed if other developers are not so excited about your contribution as youā€™d have hoped, many developers are busy with their own projects and reviewing other peoples code is not always that simple. So you can submit a patch but depending on the scale of your work you may also try get a build on graphicall and have users test to get feedback.

Iā€™d recommend you start on the easier tasks so at least you learn the process of making a change, submitting a patch and donā€™t feel like you wasted a lot of time if your patch is rejected for some reason.

In most cases Iā€™d suggest starting with Python, even if you intend to use C/C++ eventually,

  • The barrier of entry is a lot lower, you can run a script immediately without having to get blender compiling.
  • You get errors a lot faster and can test your script a lot quicker.
  • You may find out python is all you need to solve your problem, in this case its normally easier to write a script as an Addon or give it to others.
  • Even if you end up using C/C++, Python is great for prototyping and learning how blender works.

There are some exceptions to this - if you want to write new compositor/shader nodes for example, python isnā€™t much use.
also, if you have experience with C/C++ but not with Python, then you may want to skip scripting.

Some developers only use Python, others move to C/C++ or keep using both, this depends a lot on which areas of blender you work on.

If you stick to an area of blender - eg: Modifiers, GameLogic, Shading, Compositor, Import/Export, Physicsā€¦ in time you can become quite expert in this field and can make bigger changes or even become the maintainer where you get to make decisions and choose the direction for this area of blender to go.

ā€“ <edited> ā€“
This document would be a lot longer if I attempted to write about how to develop but there are a few tips I think are important.

  • Firstly get used to searching blenders code, whatever IDE/editor your use, you should be able to search for a string or function name immediately.
    Before I knew anything about development I would just search the C files for tooltips and find the function calls from there & I still find this useful.

  • Secondly, get used to ā€˜reading the sourceā€™
    Iā€™ve read that ***ā€œits harder to read code then write itā€, which is spot on!
    But unavoidable if you work with an existing project. Just get used to the fact that if you work on blender at first you may spend a fair bit of time reading functions to understand how it works. Fortunately you can learn a lot from this and once you follow how the functions work its not so hard to go back and be up to speed.

  • Third, When you code C in blender you have to appreciate you are often not working with a well defined, documented API. There is internal functionality which isnā€™t easy to follow, For closed source applications you would most likely never see this.
    This isnā€™t an excuse for bad code, just keep in mind a large application with millions of lines of code is just very different from writing your own program.
    At least we converted most of the Dutch variable names & comments now :D.

*** good read http://www.joelonsoftware.com/articles/fog0000000069.html
ā€“ </edit> ā€“

ok, so you become an experienced developer but ā€˜what now?ā€™ :smiley:
If you make all this effort to develop blender you may wonder whats the point of all this volunteer work when you donā€™t get paid.

A number of blender developers have jobs where they use blender for their company, others are developers on other software but still enjoy doing some blender work in their spare time.
there are cases where being able to script/code a 3D tool gives a great benefit when working on projects even if they are not blender-focused.

Iā€™m speaking in general terms but just to say that if you become experienced in this area it can lead to work!

Hope this is of some help, if theres something I should cover let me know.

  • (ideasman42)
4 Likes

This should be a sticky!!!

Agreed and put a link to it in #blendercoders :slight_smile:

I believe there is guides for developers lying around on the Blender website, if Ideasman said anything here thatā€™s not in any of the guides in the Blender wiki then it should be added.

The more information a developer can get off the wiki the more likely a new person who wants to develop a feature or fix a bug can start doing it without getting lost first.

Although Python-biased I loved ideasman42 reply :stuck_out_tongue: Kidding, Python is certainly handy specially in areas hard to debug that requires a lot of try and errors.

On that topic I wrote recently a blog entry on ā€œBlender 3D, Who pays the Bill?ā€. Itā€™s a brief analysis on trying to understand a bit what is pushing the Blender development forward (although Iā€™m a developer myself the ideas expressed there are purely personal).

And for anyone speaking Portuguese this is another post on a Workshop on Blender Game Engine development. The workshop was for the BlenderPRO 2010 (Brazilian Blender Conference). I recorded two videos of realtime patch review and feature coding. Audio is in Portuguese, but I can redub in English if there are interested people.

In general I agree that there are not so many coding documentation out there. I know some of the reasons (the code changes a lot, people donā€™t like writing, things are easier to understand reading the code, ā€¦). So motivation is a key factor here, since frustration can be frequent while trying to get your hands in to coding. Something that always helped me was to see the coding process as a learning experience. For even if something doesnā€™t get done or committed, I tried to see what I learned in the process.

Last and probably least. I always found interesting to see the ā€œbackstageā€ aspect of things. And the same apply for coding. Thatā€™s why I blog (and will keep blogging) about it. So if you want to read about motivational and technical history about implementing an addon, go for it: Pasteal.org Add-on

Good luck !

1 Like

Iā€™ve been trying to get into coding for blender for what feels like eons, and I feel that my ignorance is annoying to thoes already in the know.
At times it feels like you need to be able to pass an initiation, involving a goat, one trouser leg rolled up to the knee and a couple of punishment paddles, just to get a glimpse of what can be done :smiley:

What I would like personally, are a few seperate python examples to give the basic building blocks to start off from,

  1. This is the addon basic template
  2. This is how you add a button, set its size, add an icon. And this is class you need to look at that supports buttons.
  3. Do this so when you click a button the selected object moves/Scales/Rotates, this edits the x location of the button, this is where you can find out how to do this in the docā€™s
  4. Click a button to Subdivide/extrude/apply location, rotation, scale

For example, Iā€™ve tried to break down and explain all the commands for an addon to make it easier for new users, and hopefully learn a thing or two myself,
and eventually add to the wiki, but I got stuck, I cant work out how to apply to the selected object with : location_apply(), I assumed it would work like ob.location.x but no

Iā€™d like to be able to do this myself, but that would be like the blind trying to lead the blind.



bl_addon_info = {
    'name': 'Experiment Two Buttons',                                        # Name that appears in the Addon List
    'author': 'insert your name here',                                     # your name if your doing the writing
    'version': 'this is my nth attempt',                                   # I've screwed this up, this many times
    'blender': (2, 5, 3),                                                  # no idea, doesnt seem to change anything that I can see
    'location': 'in the cube object list at the bottom',                   # where will you see the addon in the blender UI
    'description': 'create a button',                                      # say what it does
    'wiki_url': 'http://www.arcane3d.co.uk',                               # website to say how this addon works
    'tracker_url': 'http://www.arcane3d.co.uk',                            # where to say HELP I FOUND A BUG
    'category': 'Experiment'}                                              # will create a new addon category if it doesnt already exist


import bpy                                                                 # grab the stuff that other people have written to make this work

class OBJECT_PT_testaddon(bpy.types.Panel):# Create a panel?
bl_label = "Test Panel Header"                                            # will appear as the label for your addon
bl_space_type = "PROPERTIES"                                              # where to place the addon in the Blender UI?
bl_region_type = "WINDOW"                                                 # where to place the addon in the Blender UI?
bl_context = "object"                                                     # where to place the addon in the Blender UI?

def draw_header(self, context):                                           # how to draw the information above in the header
  layout = self.layout                                                     # blender desides on how its shown?


def draw(self, context):                                                  # the meat and two veg of the Addon UI/
  global obj                                                               # obj variable that can be accessed by all classes
  obj = context.object                                                     # assign the selection to obj
  layout = self.layout                                                     # get the layout information for the UI and assign it to layout
  layout.label(text="label text", icon='MONKEY')                           # text with icon to dscribe what a button or checkbox is.. moved from def draw_header
  row = layout.row()                                                       # grab the row information out of layout and assign it to row
  layout.operator("buttonMoveX", icon='FORWARD')      # edit the label on the button to say what state it is in
  layout.operator("buttonMove-X", icon='BACK')


def moveTheBallF():                                                         # lets say what the cube does
    global state                                                           # setting state to be a global variable
    print('Button Clicked')                                               # lets shout out so we can see whats happening in the event window
    sc = bpy.context.scene                                                 # sc = the current scene?
    ob = sc.objects[obj.name]                                              # ob = the name of the object obj referes to
    ob.location.x -= 1.0                                         # add one to the x location of the cube
   #  cant get this to work  ob.location_apply()
                                             
   
def moveTheBallB():                                                         # lets say what the cube does
    global state                                                           # setting state to be a global variable
    print('Button Clicked')                                               # lets shout out so we can see whats happening in the event window
    sc = bpy.context.scene                                                 # sc = the current scene?
    ob = sc.objects[obj.name]                                              # ob = the name of the object obj referes to
    ob.location.x -= 1.0                                                 # add one to the x location of the cube
   
#---------------------------------------------------------------------

class VIEW3D_OT_CreateButtonOne(bpy.types.Operator):                       # create the class for your button
    '''Button One'''                                                       # say what the hell does this button do when you hover your mouse over it?
    bl_idname = "buttonMoveX"                                              # If this is set, the panel gets a custom ID, otherwise it takes the name of the class used to define the panel.
    bl_label = ""                                                # The panel label, http://www.blender.org/documentation/250PythonDoc/bpy.types.Panel.html
    bl_options = {'REGISTER', 'UNDO'}                              # Options for this panel type
    @classmethod                                                           # ?
    def poll(cls, context):                                       # Boolean: If this method returns a non-null output, then the menu can be drawn.
        return context.active_object != None                              # as long as something is selected, return the active Object?
    def execute(self, context):                     #1 ?
        moveTheBallF()                           #2 ?
        return {'FINISHED'}                           #3 ?
   
class VIEW3D_OT_CreateButtonTwo(bpy.types.Operator):                      # create the class for your button
    '''ButtonTwo'''                                                       # say what the hell does this button do when you hover your mouse over it?
    bl_idname = "buttonMove-X"
    bl_label = ""                                                # The panel label, http://www.blender.org/documentation/250PythonDoc/bpy.types.Panel.html
    bl_options = {'REGISTER', 'UNDO'}                              # Options for this panel type
    @classmethod                                                           # ?
    def poll(cls, context):                                       # Boolean: If this method returns a non-null output, then the menu can be drawn.
        return context.active_object != None                              # as long as something is selected, return the active Object?
    def execute(self, context):                     #1 ?
        moveTheBallB()                           #2 ?
        return {'FINISHED'}                        #3 ?

def register():                                 #4 ?
    pass                                    #5 ?
def unregister():                              #6 ?
    pass                                    #7 ?
if __name__ == "__main__":                        #8 ?
    register()                                 #9 ?
   
   
   
   


Oh and to anyone else like me who doesnt know, this is some great documentation on how to build blender:
http://wiki.blender.org/index.php/Dev:2.5/Doc/Building_Blender/Windows
But once you have built it, you need cMake to to create the project files that visual studio can open.
Now Iā€™ve got it open in visual studio, I dont know what to do, but thanks to #blendercoders for getting me that far.

+1
English subtitles/redub would be very good!

This post is very helpful, let it be a sticky for the common good. I have not started torturing the Blender source yet, but this I would do in the beginning.

Do it the C++ way:

  1. Have a look at this page (Actually, the blender.org site has plenty of information, itā€™s good remember itā€™s sitemap).
    http://www.blender.org/development/

  2. You can have a touring of Blender source (as many programmers call it, a view from the 10.000 feet)
    http://wiki.blender.org/index.php/Dev:2.5/Source

  3. And also some other resources to initiate your interest
    http://www.blender.org/community/get-involved/

  4. Most important, download the source code (from repository) and start messing with it.

Do it the Python way (you can start right away):

  1. Start this tutorial and eventually learning Python Blender API
    http://www.youtube.com/watch?v=vmhU_whC6zw

I donā€™t want to discourage anyone, programming needs patience, practicing, time and note taking skills. Programmers tend to make todo lists, not only for the next days, but also for the next 10 months, itā€™s a vital practice to track progress of a project.

The good about the Blender community is that there are plenty of fellow developers out there. But as mr. ideasman said, they canā€™t code for you but I think that they could answer your questions easily. I think that you will be able to complete your project with 30 questions, but you must walk each step at a time in order to be able to produce these questions.

these instructions are kindof old but useful:
http://www.geneome.com/tutorials/blender-tutorials/building-blender-with-msvc-using-cmake/
also, once in Visual studio, make sure you set it to ā€œReleaseā€
instead of ā€œDebugā€
then click Build solution (F7 Key)

Iā€™d recommend that anyone start with the ā€˜developers quick start guideā€™

http://wiki.blender.org/index.php/Dev:2.5/Doc/Developers_Quickstart

Yeah, i think that is important that everyone can easily begin to code, but everyone should have a good self-critiques aptitudeā€¦
Iā€™ve just started learning C at university, and the first time the professor assigned us a program (that find all the prime numbers) to do, after giving us the time to write it, we run our program for 30 secs, and made a hit with the top score. Some programs run 10 time faster than others, in such a simple problemā€¦ There are many way to solve a problem, some good, some better, some perfectā€¦
Submitting code not well optimized at long run will slow down blender terriblyā€¦ My opinionā€¦ If ideasman said different, probably i havenā€™t understood well what he meansā€¦ :confused:

this thread got referenced on blendernation: http://www.blendernation.com/2010/10/19/so-you-want-to-be-a-blender-developer-but-where-do-you-start/ it may be a sticky soon :slight_smile:

Thatā€™s why the more experienced devs do code reviews.

Just donā€™t take it personally if your new wizz-bang feature doesnā€™t get accepted or they want the code reworked a couple times since they too are worried about the quality of blenderā€™s code base.

I donā€™t think itā€™s up to new coders to be able to self-criticize their code regarding elegance, efficiency, ā€¦ This is up to whoever takes the role of reviewing the code and eventually commit it into trunk.

What I would expect from anyone (specially if you are starting) in such a big collaborative project like Blender coding is to understand that sometimes you will need to re-do your work a few times before ā€œget it rightā€ (and sometimes things donā€™t even get into trunk). In the end itā€™s always for the best of the project.

@Ace Dragon, the problem with making things like this into wiki documents is they tend to get edited to become a lot bigger, people add all sorts of info until it doesnt read so well.
Or perhaps the answer is to better communicate with wiki authors and not let this happen.

I started the compiling blender quickstart wiki doc, and after a while it had all sorts of fluff added. ā€œyou want to use makefilesā€¦ā€, ā€œif you get this error with ffmpegā€, ā€œif blender fails on some distroā€, ā€œyou could do this if you want colladaā€ā€¦
Until is was nolonger a quickstart!

This sort of advice is also just my opinion, Ton would not encourage python so much! :D.

@Makers_F, I see you had some replies about code review which are right, but will answer this in a different way.
Being self critical helps ofcourse in the sense of not assuming you know best. Learning development while seeing Brecht and Ton code was very humbling for me :).
And its true developers can produce vastly varying quality of code.
http://www.devtopics.com/programmer-productivity-the-tenfinity-factor/

But I dont think there are hard and fast rules as to optimizing code. Aside from ā€œwrite first optimize laterā€.
Sometimes maintainability is more important, or your better off getting something working quick and optimizing later.
On the other hand if you build code ontop of a bad design it can shoot you in the foot later. Iā€™ve even found that stupid code is even better in rare cases and after hours of research you find that for some reason the compiler manages to optimize really well.

Also something to consider is you may write very complicated, optimized code that existing blender developers will find hard to understand. You may be better off submitting a patch with a simple implementation, then submitting the optimization as a separate patch. This way you also get the benefit that if your optimization breaks for some corner case, we can check if its the crazy complicated optimization or not.

Pharion, thanks for the Addon template, Ill try review and include in blender this week.

ideasman42,
nice interview with BlenderGuru. Funny and informative to follow.
Fits very well in this thread.

BlenderGuru: Interview with Campbell Barton

i have few newbie questions; some of which i got help from jesterKing in #blendercoders but more insight would help.
for reference, i work with Mac OS 10.6, 64-bit

  1. i followed the wiki instructions on building blender using Sconsā€¦ it seems that there is a python script (scons.py) that guides the build process. my question is, it took a few minutes to compile blender, what if i want to make a few changes to the code and see what happens? i hope i donā€™t have to recompile the whole thing each timeā€¦

  2. when navigating through the code, i come across lots of function calls. how do i know where to find the function definitions in the huge pile of other .c files? it seems modern IDEs provide tools for that, but what if iā€™m developing with python inside of blender? i doubt text editor has that functionalityā€¦

  3. any recommendations on IDEs for Mac OSX?

thanks