Archives for posts with tag: blender

A while ago, I posted a simple demo I made in the Blender game engine that let’s 2 player interact with each other over the internet, all it is required is a really simple networking script and the IP address of the two players.  Here is as youtube video of it in action, mouse-over the video to see some caption text.

The laptop on the left is physically separated from the desktop to the right, linked only by a wireless internet connection. And as you can see, input made to the desktop computer is sent across the network to the laptop, in realtime.

And here is the script, I’ll try to explain everything as best I can:

# Simple Python UDP networking demo Created by Mike Pan
# Todo: auto-self IP detection would be nice

# the following line loads the game module used by Python
# to access the Blender Game Engine API, and assigns it the alias G
import GameLogic as G
# load the network socket python module, we'll need it later
import socket

# define own IP address, and stores it as a property under GameLogic
# essentially making it accessible as a global variable
G.ownIP = "xxx.xxx.xxx.xxx"
# define peer IP address, stores it as a property under GameLogic
# again, essentially making it accessible as a global variable
G.peerIP = "xxx.xxx.xxx.xxx"
# define the port number (arbitrary), and the socket buffer size
# (4096 is a good starting point)
G.port = 4000
G.buffer = 4096

# create an IPV4 address with the pre-defined IP and the port number
addr = (G.peerIP, G.port)

# We'll add this line to all our communication, so when debugging,
# we won't get confused as to who send the packets.
signature = "Sent from " + G.ownIP

def init():
	# create an UDP socket for **sending** datagram
	G.sender = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
	# time out is 10ms, pretty short for realworld application,
	#but enough for debugging over local network
	G.sender.settimeout(0.01)
	# this is important! by making this socket object a
	# non-blocking operation, all network stuff is run on
	# a separate thread, thus any network delay will not
	# cause the game to slow down
	G.sender.setblocking(0)

	# creates UDP socket for **receiving** datagram
	G.listener = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
	# same as above, time out is 10ms
	G.listener.settimeout(0.01)
	# same as above, we also need to make sure network operations
	# will not slow down the main application
	G.listener.setblocking(0)

	# Win32 needs the socket binded:
	try:
	 G.listener.bind((G.ownIP, G.port))
	except:
	 print "Binding Listener failed"

def comm():
	# get the object that is attached to this script
	own = G.getCurrentController().owner

 	# receive from peer
	try:
		data, port = G.listener.recvfrom(G.buffer)
		# data contains all the data that came through,
		# it's a string, and we can do whatever we want
		# like print it out
		print data.split(',')
	# if the receiving fails, print something to notify the user
	except:
		print "Receive failed"

	# send to peer
	# generate data to be sent here,
	# send the position data across the network:
	string = str(own.worldPosition)+ ',' + signature

	# going to try to send the data
	try:
		G.sender.sendto(string, addr)
		# if sending fails, notify with error message
	except:
		print "Send failed"

That’s it! To use this script, we simply need to call init() once at the start of the game, and then comm() everytime you wish to send/receive some data (perhaps every 1/30th of a second). As mentioned, here is no ‘server’ involved, the two peers connect direction to each other via a UDP socket. All the user has to do is specify the two IP addresses.

I know I will never be a great writer, so instead of doing tutorials, I have decided to release some of the personal project I’ve worked on. The result is a 300MB folder of 22 project, including a lot of the things on my portfolio and demoreel.

When I was learning Blender, I start a lot of personal mini-project that I never really finished, so instead of having them just sitting on my harddrive, perhaps others can find them useful in some way.  The pack contains animations, stills and a realtime game project.

=======================Download=================== ====

Mike’s Blender Pack v2 Zip (175MB Compressed)

Mike’s Blender Pack v2 Individual files

=======================Download=================== ====

File listing of the Blender Pack content.

File listing of the Blender Pack content.

I’ve tried my best to make sure everything is packed and ready to go. All files should work in Blender 2.49a.

This guide was written for Blender 2.45.  I have an updated guide for building Blender 2.5 available HERE.

1. Acquire Blender source code and libraries

- Download and install tortoisesvn from: tortoisesvn.tigris.org
-created a folder named “blender” under c:\build, select the folder and click on SVN checkout, and use the following location:

https://svn.blender.org/svnroot/bf-blender/trunk/blender

-created a folder named “windows” under c:\build\lib, select the folder and click on SVN checkout, and use the following location:

https://svn.blender.org/svnroot/bf-blender/trunk/lib/windows

Once the above 3 steps are done, you will have the most up-to-date blender source code and library in the world.

OPTIONAL INFO: If you want to build an official release, you can grab the more stable source code (~10MB, library files are not included) from blender.org/download/source-code. Simply delete everything under C:\build\blender and then extract the tarball to the same directory. Building from the official release ensures the Blender you compiled is stable and relatively bug-free.

2. Acquire compiling softwares

- Download and install Python 2.5.1 (9MB) from www.python.org
- Download Mingw 5.1.3 (~10MB) from www.mingw.org . Run the installer, Pick any mirror, Select Current and install packages MinGW BASETOOLS and G++ COMPILER.
- Download and install SCons 0.97 Windows (300KB) from www.scons.org
- Download the experimental GCC4.x for MinGW package from tdragon.net. Extract it to the place where you installed MinGW, and this will serve as a ‘drop in’ replacement compiler. From my own testing, GCC4 is faster than the one that comes with MinGW, but can cause trouble when compiling OpenAL.

3. Environment setup

- Go to Start Menu >> Control Panel >> System >> Advanced (Tab) >> Envoronmant Variables (button) >> System Variables scroll area double click on the PATH item
- Add the following line to the end: ;C:\Python25;C:\mingw\bin

4. Python stuff…

Copy libpython25.a from C:\Python25\libs to C:\build\lib\windows\python\lib


5. Customization (Enable/disable features, add speed optimizations)

- Create a new file named user-config.py under C:\build\blender\
- Open user-config.py with notepad and copy the following text into it.

WITH_BF_GAMEENGINE=’true’
WITH_BF_BULLET = ‘true’
WITH_BF_ODE = ‘true’
WITH_BF_OPENEXR = ‘true’
WITH_BF_FTGL = ‘true’
WITH_BF_FMOD = ‘true’
WITH_BF_FFMPEG = ‘true’
WITH_BF_QUICKTIME = ‘false’
WITH_BF_OPENAL = ‘false’
WITH_BF_SDL = ‘false’
BF_PYTHON_VERSION = ’2.5′

CCFLAGS.extend( ['-march=i686', '-ftracer', '-fomit-frame-pointer', '-finline-functions', '-ffast-math'])
CXXFLAGS.extend(['-march=i686', '-ftracer', '-fomit-frame-pointer', '-finline-functions', '-ffast-math'])

REL_CFLAGS = [ '-O3' ]
REL_CCFLAGS = [ '-O3' ]

‘-march=’ is probably the most important flag in this config file. Newer Intel CPU (Pentium D, Core 2) owners are recommended to use ‘-march=nocona’, AMD (A64, X2) owners can try ‘-march=k8′.
‘-mmmx’, ‘-msse’, ‘-msse2′, ‘-msse3′ are usually implied by using a valid march flag, therefore they are not included in the config file.
‘-ffast-math’ are in general stable enough for daily use (I’ve never seen a crash), but if you are running a real production server or can not tolorate crashes, remove this flag. It will make the binary a little slower.

This is how the directory should look like:
build2

6. Compile!

- Open a command prompt window by click on Start >> Run >> type in “cmd” and hit OK.
- Navigate to where the Blender source code is by typing this into the command prompt cd C:\build\blender
- Start the building process: scons BF_TOOLSET=mingw BF_BUILDDIR=c:\install -j4
- The above command should take about 5-10 minutes to process, and it helps if you have a dual-core processor!
- When it finishes, (Hopefully without error), you can nagivate to C:\install\win32-mingw\ and find a complete Blender installation ready to be zipped up and distributed!

Where to go from here?

You might want to rid the blender.exe of extra useless debug data by entering the following command into the command line:
strip C:\install\win32-mingw\blender.exe
This will reduce the size of the executable by 8mb or so without having any negative impact

The above ‘user-config.py’ file will result in a full-featured Blender that is optimized for speed and should run on almost all modern processors. To speed up the building process, you can chose to disable some of the features by replacing ‘true’ with ‘false’ (this will give you a blender binary without certain feaures such as gameengine, audio, etc…)
scons clean BF_TOOLSET=mingw BF_BUILDDIR=C:\install
can be used to clean the build data and getting ready for a new build


I also recommend: How to build Blender using Visual C++ Express Edition 2008 By Eugene (etr9j), MSVC produces faster binary, but takes a lot longer to setup for the first time.

This guide was written for Blender 2.45.  I have an updated guide for building Blender 2.5 available HERE.

1. Acquire Blender source code and libraries

- Download and install tortoisesvn from: tortoisesvn.tigris.org
-created a folder named “blender” under c:\build, select the folder and click on SVN checkout, and use the following location:

https://svn.blender.org/svnroot/bf-blender/trunk/blender

-created a folder named “windows” under c:\build\lib, select the folder and click on SVN checkout, and use the following location:

https://svn.blender.org/svnroot/bf-blender/trunk/lib/windows

2. Acquire compiling softwares

- Download and install Python 2.5.1 (9MB) from www.python.org
- Download Mingw 5.1.3 (~10MB) from www.mingw.org . Run the installer, Pick any mirror, Select Current and install packages MinGW BASETOOLS and G++ COMPILER.
- Download and install SCons 0.97 Windows (300KB) from www.scons.org

3. Environment setup

- Go to Start Menu >> Control Panel >> System >> Advanced (Tab) >> Envoronmant Variables (button) >> System Variables scroll area double click on the PATH item
- Add the following line to the end: ;C:\Python25;C:\mingw\bin
- Copy libpython25.a from C:\Python25\libs to C:\build\lib\windows\python\lib

4. Compile!

Before you start, this is how the everything should look like:

build2

- Open a command prompt window by click on Start >> Run >> type in “cmd” and hit OK.

- Navigate to where the Blender source code is by typing this into the command prompt cd C:\build\blender

- Start the building process by:
scons BF_BUILDDIR=c:\install -j4

- The above command should take about 5-10 minutes to process, and it helps if you have a dual-core processor!

- When it finishes, (Hopefully without error), you can nagivate to C:\install\win32-mingw\ and find a complete Blender installation ready to be zipped up and distributed!

Where to go from here?

You might want to rid the blender.exe of extra useless debug data by entering the following command into the command line:
strip C:\install\win32-mingw\blender.exe
This will reduce the size of the executable by 8mb or so without having any negative impact

scons clean BF_BUILDDIR=C:\install
can be used to clean the build data and getting ready for a new build

Once you have successfully compiled Blender, you can try more customization by following the Advanced Guide.