note:
the current work on this is at http://mediawiki.blender.org/index.php/BlenderDev/PythonBlender
and the stuff below is here as background / historical info
concrete talk about this was recently in http://www.blender.org/modules.php?op=modload&name=phpBB2&file=viewtopic&t=4406 . an older discussion on this on Blender.org forums is http://www.blender.org/modules.php?op=modload&name=phpBB2&file=viewtopic&p=24680#24680
Introduction
The purpose of this document is to study the feasibility of making Blender a package of Python modules, or in a way, enabling using it to make Python applications. (could this be a PEB as in a ProposaltoEnhanceBlender? ?). If successful, this could result in the official Blender itself becoming one. However, there are many obstacles and issues that require careful consideration, as will be discussed here.
http://www.kyperjokki.fi/tools/blender.py is a (so-far) fictional example of how Blender that extended Python could be used.
Background
Currently Blender embeds Python, by shipping with the interpreter and providing an API (actually two APIs?, when counting the game engine in) for using some of the functionality from Python scripts.
The current architecture does not allow using Blender as a Python module. That is, the Blender Python API can be used only from bpython or Blender Python, which is the environment where the embedded interpreter in the Blender application runs the scripts.
There is need for using Blender as Python module (see e.g. "a recent post by Carlos Lòpez on bf-python":xxx). This is called extending.
Also, by extending Python, instead of embedding it, Blender itself might benefit from increased flexibility and ease of development. For an essay which discusses these two approaches and argues strongly for extending, see http://twistedmatrix.com/users/glyph/rant/extendit.html
Issues
- How difficult would it be to make Blender a Python module (or probably a package of several modules?
- so far no clue, but probably quite a lot of work
- OTOH, in bpython, it already is! how difficult would it be to enable using at least parts of it otherwise too?
- if the work on modularization in general gets going (for Blender 3 or 2.5 perhaps), that is where the hard work is
- what does using those modules as Python modules actually require?
- so far no clue, but probably quite a lot of work
- Could Blender be built as a Python application without sacrifying performance?
- must be experimented with, if 1 is reached to some point
Benefits
What would this gain?
- Not having to develop the separate Python API in parallel?
- if the Blender core(s), i.e. the new modules, provide interfaces that can be called from Python too, there will be less work on the currently separate effort of developing the Python API. Currently much of the Python API development is just enabling the use of functions that already are in use on the C++ side, but can be called from the GUI only. In the new system all those calls would be automatically available for both the GUI and the API.
- Flexibility and ease of development
- besides the general benefits of modularization of the c++ parts, enabling the use of a higher-level language such as Python in the core would bring additional benefits:
- breaking news! OOPS in Python described "simpler than it sounds" !, http://www.blender.org/pipermail/bf-python/2004-August/001716.html .. also there's work on integrating Python-written functionality in the GUI (right?), http://www.blender.org/pipermail/bf-python/2004-August/001696.html
- for example, undo and a "history tree" could be programmed in Python. These functionalities are not CPU intensive, as they need to be updated only when the user does something, not anything like called a million times a second for updateing a mesh or something. The high-level (and actually pretty fast too) advanced builtin lists and dictionaries of Python would probably support implementing these features well.
- other examples are the GUI layout, keybindings etc. - both for which there has been work recently, which would be of great interest for non-c programmers to modify (see e.g. the thread now on blender.org), and which again are not CPU intensive and hence don't require compiled code.
- yet another possibility is unit testing: i'm pretty ignorant about the state of unit testing tools in c/c++, but know that Python is used for writing unit tests for Java (via Jython) .. 'cause it's convenient.
- besides the general benefits of modularization of the c++ parts, enabling the use of a higher-level language such as Python in the core would bring additional benefits:
Discussion:
Feel free to comment! (note that this is an really early and probably not-too-well informed draft yet). based on this, a proposal is worked on in PythonBlenderProposal
References:
- Blender 2.5+ Roadmap (Proposal) by Michel Selten (+ comments by others on bf-committers)
- Next-gen projects by Ton Roosendal (+ comments by others on bf-committers)
- if viable enough to start on, this could become one of the colours!
- http://www.blender.org/bf/20datastruct.txt - and old description of the overall architecture from an old book, Ton will write an up-to-date version soon to support the work that should be started on modulization .. yay this is now done, so all here should be refactored based on http://www.blender3d.org/cms/Blender_Architecture.336.0.html
Notes:
isn't some of the big ones, Maya or something, made like this? that the core provides a python api and the app, gui etc. is made using it?