Intersesting Questions involving extending and embedding

Dev_NuLL dev_null at email.com
Tue Feb 27 22:27:42 EST 2001


There is a free multi-platform 3D package called Blender (
www.blender.nl ) that has builtin python capabilities to help in
automating animation and modeling tasks. The Blender Python module is
builtin the Blender executable. Others have written external python
modules for use with Blender and would like to figure out how it is
done. Here is an example of code that would create a plane consisting
of 4 vertices and one face:


################## START CODE ###################

import Blender

scene = Blender.getCurrentScene()
mesh = Blender.Mesh("plane")
object = Blender.Object("plane")

mesh.enterEditMode()

indices = []

index = mesh.addVertex(1,-1,0)
indices.append(index)
index = mesh.addVertex(1,1,0)
indices.append(index)
index = mesh.addVertex(-1,-1,0)
indices.append(index)
index = mesh.addVertex(-1,1,0)
indices.append(index)

mesh.addFace(indices[0],indices[1],indices[2],indices[3])

Blender.connect(object,mesh)
Blender.connect(scene,object)
mesh.leaveEditMode()

################## END CODE ###################

I would like to create a primitives module to create 3D solids I would
like to wrap the above code (or similar) into a module and call it
'Primitives' with a 'plane' function so my code would look like:

import Blender
import Primitives
Primitive.plane()

Of course I would like the 'plane' function to take args for the size,
rotation, scaling, etc.., 
I have begun to read the docs on extending and embedding, and since
the above does not use any C functions I imagine I would be doing
mostly embedding. How would I go about creating a Windows DLL or Linux
.so that would do this? I don't need help on compiling, just on how to
get the module to directly connect to the 'Blender' module that is
builtin the Blender executable. I am having a hard time getting
started with the limmited knowledge I have in creating simple external
modules that just do things like divide 2 numbers and return a result.
How do I attach to the Blender module from within my module and make
use of its functions like:

mesh = Blender.Mesh("plane")
object = Blender.Object("plane")
mesh.enterEditMode()

I know I sound desparate, but the 2 books I bought and the online docs
barely scratch the surface of embedding.

TIA



More information about the Python-list mailing list