Intersesting Questions involving extending and embedding 
Author Message
 Intersesting Questions involving extending and embedding

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



Sun, 17 Aug 2003 11:27:42 GMT  
 Intersesting Questions involving extending and embedding

Quote:

> 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()

umm.  any reason you cannot just put your code in a
Primitives.py file?

    http://www.python.org/doc/current/tut/node8.html

Cheers /F



Sun, 17 Aug 2003 15:18:20 GMT  
 Intersesting Questions involving extending and embedding

Quote:
>umm.  any reason you cannot just put your code in a
>Primitives.py file?

The writers of Blender modules release the modules compiled to protect
the source code, and that is what I am also interested in doing. This
Primitives.py is just an example, I have a much more complicated
project involving Catmul-Clark subdivision libs which are not open
source.


Sun, 17 Aug 2003 22:27:09 GMT  
 Intersesting Questions involving extending and embedding

Quote:

> >umm.  any reason you cannot just put your code in a
> >Primitives.py file?

> The writers of Blender modules release the modules compiled to protect
> the source code, and that is what I am also interested in doing.

compiled as in DLL/SO, or compiled as in PYC?

Cheers /F



Sun, 17 Aug 2003 22:34:41 GMT  
 Intersesting Questions involving extending and embedding

Quote:
>compiled as in DLL/SO, or compiled as in PYC?

from the original message:

 How would I go about creating a Windows DLL or Linux
.so that would do this?



Mon, 18 Aug 2003 11:30:55 GMT  
 Intersesting Questions involving extending and embedding

Quote:

> > > The writers of Blender modules release the modules compiled to protect
> > > the source code, and that is what I am also interested in doing.

> >compiled as in DLL/SO, or compiled as in PYC?

> from the original message:

>  How would I go about creating a Windows DLL or Linux
> .so that would do this?

from your original message:

Quote:
> [a piece of python 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 [...]

to which the answer is to use a PY or PYC file, like everyone
else.

if you insist on wrapping the PYCs in DLL/SO files (as if that
would make them harder to reverse engineer), search the net
for python2c [1], or study the freeze sources [2]

Cheers /F

1) last seen here: http://lima.mudlib.org/~rassilon/p2c
2) in the source distribution



Mon, 18 Aug 2003 14:26:58 GMT  
 Intersesting Questions involving extending and embedding

Quote:
>1) last seen here: http://lima.mudlib.org/~rassilon/p2c

bunk URL

Quote:
>to which the answer is to use a PY or PYC file, like everyone
>else.

that's not the answer, because the question was to compile DLL's and
.so LIKE everyone else does with 3D modules, NOBODY uses .pyc's
Want an example? Look at the Lightflow raytracer module
www.lightflowtech.org

the distro is a DLL and an .so

A complied C module is much faster than a Py or PYC and when you are
dealing with complex graphics code you need all the speed you can get,
but I guess you cannot help me here.



Tue, 19 Aug 2003 10:12:41 GMT  
 Intersesting Questions involving extending and embedding

Quote:

> A complied C module is much faster than a Py or PYC and when you are
> dealing with complex graphics code you need all the speed you can get,
> but I guess you cannot help me here.

I don't think anyone can help someone who wants to compile
Python source code with a C compiler, without translating the
code in any way.

But I'll make one last attempt:

- If you have Python source code (as you said in your first post),
Ship it as a PYC file, or convert it to a C module using python2c
or freeze-style techniques.

- If you're writing C or C++ code, you're *extending* Python.
Read the docs again, and look as the samples shipped with the
source distribution.  There's some 80 extension modules in the
Modules directory, so there should be plenty of inspiration.

Cheers /F



Tue, 19 Aug 2003 15:40:16 GMT  
 Intersesting Questions involving extending and embedding

Quote:
>- If you're writing C or C++ code, you're *extending* Python.

No shit, and you could be embedding also.

Quote:
>Read the docs again, and look as the samples shipped with the
>source distribution.

Thanks for your responses, but they have been useless. From reading
them it seems you didn't read my entire post or you could have
answered the main problem I am having:

" how to get the new module to directly connect to the 'Blender'
module that is builtin the Blender executable."

In other words how to write an extended module in C that can call
functions in other compiled extended modules also in C.



Tue, 19 Aug 2003 21:52:15 GMT  
 Intersesting Questions involving extending and embedding

Quote:

> >1) last seen here: http://lima.mudlib.org/~rassilon/p2c

> bunk URL

   http://www.mudlib.org/~rassilon/p2c, but th stuff is old - Aug 1999.

Oleg.
----

           Programmers don't die, they just GOSUB without RETURN.



Tue, 19 Aug 2003 21:36:48 GMT  
 Intersesting Questions involving extending and embedding

Quote:

> >Read the docs again, and look as the samples shipped with the
> >source distribution.
> Thanks for your responses, but they have been useless. From reading
> them it seems you didn't read my entire post or you could have
> answered the main problem I am having:
> " how to get the new module to directly connect to the 'Blender'
> module that is builtin the Blender executable."
> In other words how to write an extended module in C that can call
> functions in other compiled extended modules also in C.

Read the docs again. Really. Specifically, read
http://www.python.org/doc/ext/using-cobjects.html
which is the chapter headed
1.12 Providing a C API for an Extension Module

It contains everything you need to know. Use 'grep' in the modules dir and
you'll find three more examples.

--

Hi! I'm a .signature virus! copy me into your .signature file to help me spread!



Wed, 20 Aug 2003 08:47:25 GMT  
 Intersesting Questions involving extending and embedding
Damn, your dense
Who the hell said anything about compiling Python code in C ?? For the
last time I want to access FUNCTIONS in another Python module (which
happens to be inside the Blender executable) from within my module.
others have done it, but they won't release the source code.
BTW, you can execute Python code in C modules:

PyRun_SimpleString("print 'Hello Python World'");

Quote:
>- If you're writing C or C++ code, you're *extending* Python.

Or embedding can be done in C (maybe you should read the docs)

Quote:
>Read the docs again, and look as the samples shipped with the
>source distribution.  

Like I said, the examples in the docs are too Mickey Mouse.

Please, don't waste your time replying if your post are as usless as
the previous ones were. I can't believe a person can not even get a
simple answer to a simple question. Thank god for the kind sould who
pointed mt to starship.



Thu, 21 Aug 2003 01:19:50 GMT  
 Intersesting Questions involving extending and embedding

Quote:
>Read the docs again. Really. Specifically, read
>http://www.python.org/doc/ext/using-cobjects.html
>which is the chapter headed
>1.12 Providing a C API for an Extension Module

Thank God! Somebody who can actually help me, see Fredrik - that
wasn't hard, was it?


Thu, 21 Aug 2003 01:27:16 GMT  
 Intersesting Questions involving extending and embedding
Thanks for the help
Quote:
>> bunk URL

>   http://www.mudlib.org/~rassilon/p2c, but th stuff is old - Aug 1999.



Thu, 21 Aug 2003 09:05:09 GMT  
 
 [ 14 post ] 

 Relevant Pages 

1. Couple of embedding & extending questions

2. performance question when using embedding/extending

3. c-ffi question involving c-struct

4. Syntax Question involving parameters, function, ranges...

5. Two questions (Sorry, Goobers no cash involved :-)

6. Fortran syntax question (involving **)

7. Conformance question involving equivalence

8. problems extending & embedding python

9. problems with extending and embedding python on win2k

10. Win32 embedding and extending

11. Extending/embedding versus separation

12. embedded AND extended C code

 

 
Powered by phpBB® Forum Software