[Bf-committers] blender command port - blender python server and client

Dietrich Bollmann diresu at web.de
Thu Jun 28 13:05:23 CEST 2007


Hi Chris,

On Wed, 2007-06-27 at 09:56 -0600, Chris Want wrote:
> This looks really interesting, although I haven't had a chance
> to build/try it.
> 
> I wonder if it wouldn't make more sense to make 'blash'
> a python module rather than a stand alone program, i.e.
> you might do something like
> 
> $ python
>  >>> import Blash
>  >>> Blash.connect(host:7777)
>  >>> from Blash import Blender.*
> 
> ...
> 
> or such.

I try to implement something similar in lisp since a while.  The
problem is that the Blender server uses its own Python interpreter.
So every object of the lisp/python client would need a handle to the
object on the server side and the other way around in order to reflect
changes made via the Blender server GUI on the server side at the
client side and the other way around.  This makes things very
complicated.

If the Python client should simply be able to "remote control" objects
on the Blender server, things are much easier:

I wrote some very simple example Python clients inspired by
your mail:

A very simple "hello world" BCP Python client:

  $ python
  Python 2.4.4 (#2, Apr 26 2007, 00:02:45) 
  [GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] on linux2
  Type "help", "copyright", "credits" or "license" for more information.
  >>> import socket
  >>> sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  >>> sock.connect(("127.0.0.1", 7777))
  >>> sock.send('#cS\n#s13\n"hello world"\n\0')
  24
  >>> sock.recv(1024)
  "#i0\n#s0\n\n#s14\n'hello world'\n\n#s0\n\n\x00"
  >>> sock.close()
  >>> 

See http://formgames.org/blender/command-port/#bcp-protocol
and http://formgames.org/blender/command-port/#hello-world-python-client
for a more detailed description.

And here another one for modelling a simple pyramid:

  $ python
  Python 2.4.4 (#2, Apr 26 2007, 00:02:45) 
  [GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] on linux2
  Type "help", "copyright", "credits" or "license" for more information.
  >>> import socket
  >>> sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  >>> sock.connect(("127.0.0.1", 7777))
  >>> sock.send("""#cF
  ... #s323
  ... from Blender import *
  ... vertexes = [[1, 1, 0], [-1, 1, 0], [-1, -1, 0], [1, -1, 0], [0, 0,
1.27]]
  ... faces    = [[3, 2, 1, 0], [0, 1, 4], [1, 2, 4], [2, 3, 4], [3, 0,
4]]
  ... mesh = Mesh.New('mesh')
  ... mesh.verts.extend(vertexes)
  ... mesh.faces.extend(faces)
  ... scene  = Scene.GetCurrent()
  ... object = scene.objects.new(mesh, 'object')
  ... Redraw()
  ... 
  ... \0""")
  335
  >>> sock.recv(1024)
  '#i0\n#s4\nNone\n#s0\n\n#s0\n\n\x00'
  >>> sock.close()
  >>> 

Taken from
http://formgames.org/blender/command-port/#pyramid-python-client

Of course, a real program should have code to abstract from the BCP
protocol etc.

> I really like the idea of being able to run arbitrary
> blender API commands in a python interpreter -- it
> would be even better if it could be done without
> having to actually start blender as a separate
> process though.

Isn't this the idea of Blender 3.0?

On
http://www.blender.org/documentation/intranet/docs/develop/python/api-proposal.html
for example the following can be read:

| Python Toolbox
| 
| The Python toolbox will be a set of modules to operate on 3D or image
| data, independently from the Blender internals. The toolbox routines
| may be used by Blender itself through a C API or external applications
| to process data.  For a possible Blender 3.0 redesign, this might be
| one of the core libraries to process 3D data.

> Anyways, cool work!

:) - Thanks for your rewarding words :)

Regards,
Dietrich

> Regards,
> Chris
> 
> Dietrich Bollmann wrote:
> > Hi,
> > 
> > The appended patch makes it possible to start Blender in Python server
> > mode.  Clients can connect and send Python commands via the command
> > port to the server.
> > 
> >   - The Command Port allows to edit objects simultaneously using the
> >     Blender GUI and one or more clients connected to Blender via the
> >     command port.
> >   - The patch also includes `blash', a Blender Python shell client.
> >   - `blash' can be used with the emacs python mode - the result is a
> >     formidable Blender Python development environment.
> >   - Clients can be written in any language: lisp, Python, Perl, C,
> >     C++, Java etc.
> >   - The patch was only tested on Debian sid until now but should run
> >     on any platform after a little customisation.
> > 
> > For a screen shot see http://formgames.org/blender/command-port/
> > 
> > Have fun,
> > Dietrich
> > 
> > * Blender command port patch
> > 
> >   -
> > https://projects.blender.org/tracker/index.php?func=detail&aid=6887&group_id=9&atid=127
> > 
> > * Example - a simple pyramid
> > 
> > The following example shows how the command port can be used to model
> > a simple pyramid:
> > 
> >   - start the Blender server in some xterm
> > 
> >       $ blender --geometry 800x600+10+10 --bcp 6789 &
> > 
> >   - start blash in another xterm
> > 
> >       $ blash --port 6789
> >       This is Blash - the GNU BLender-Again SHell :)
> >       Connection to Blender Server established.   (IP address:
> > 127.0.0.1, port: 6789)
> > 
> >   - enter blender python commands
> > 
> >       from Blender import *
> > 
> >       vertexes = [[1, 1, 0], [-1, 1, 0], [-1, -1, 0], [1, -1, 0], [0, 0,
> > 1.27]]
> >       faces    = [[3, 2, 1, 0], [0, 1, 4], [1, 2, 4], [2, 3, 4], [3, 0,
> > 4]]
> > 
> >       mesh = Mesh.New('mesh')
> >       mesh.verts.extend(vertexes)
> >       mesh.faces.extend(faces)
> > 
> >       scene  = Scene.GetCurrent()
> >       object = scene.objects.new(mesh, 'object')
> >       Redraw()
> > 
> >       bye
> > 
> > 
> > * Installation
> > 
> >   - make a directory to build Blender
> > 
> >       BCP=$HOME/bcp
> >       mkdir -p $BCP
> >       cd $BCP
> > 
> >   - download blender 2.44 sources
> > 
> >       wget http://download.blender.org/source/blender-2.44.tar.gz
> >       wget http://download.blender.org/source/blender-2.44.tar.gz.md5sum
> >       md5sum -c blender-2.44.tar.gz.md5sum
> > 
> >   - download blender command port patch
> > 
> >       wget
> > http://formgames.org/blender/command-port/patches/blender-command-port-patch.2007-06-26.txt
> > 
> >   - unpack the blender sources
> > 
> >       gunzip blender-2.44.tar.gz
> >       tar xvf blender-2.44.tar
> > 
> >   - patch them
> > 
> >       cd blender-2.44
> >       patch -p0 < ../blender-command-port-patch.2007-06-26.txt
> > 
> >   - build blash and blender
> > 
> >       scons WITH_COMMAND_PORT=true blash
> > 
> >   - the (linux) binaries
> > 
> >       $BCP/install/linux2/blender
> >       $BCP/install/linux2/blash
> > 
> > 
> > _______________________________________________
> > Bf-committers mailing list
> > Bf-committers at blender.org
> > http://lists.blender.org/mailman/listinfo/bf-committers
> > 
> 
> 



More information about the Bf-committers mailing list