Blender for Robotics | Part 3 | Interfacing with the GameEngine
- Part 1 | Introduction and Modelling
- Part 2 | Parenting and Rigging
- Part 3 | Interfacing with the Game Engine
- Part 4 | Programming in the Game Engine
- Part 5 | Game Engine and The Kinect
In the second part of this tutorial I presented how to rig a robot model in Blender. In this part I will show you how to make use of the Blender Game Engine (BGE) — and more importantly, how to control armatures/robot models in the GameEngine .
In order to complete this tutorial I assume you have little experience in C++ and Python programming as well as CMake and other build tools. Therefore, this tutorial will be as detailed as possible. As a first step I need to make sure you have set up your environment correctly (in terms of this HowTo).
Install Python 3.2.1
sudo mkdir -p /opt/blendertutorial
sudo chgrp -R $YOUR_USERNAME /opt/blendertutorial
sudo chmod -R g+w /opt/blendertutorial
mkdir dependencies && cd dependencies
tar xvf Python-3.2.1.tar.bz2
./configure --prefix=/opt/blendertutorial --without-pymalloc --with-wide-unicode --enable-shared
Install Blender 2.63a
Now, install Blender 2.63a, fast version below:
sudo apt-get update; sudo apt-get install subversion build-essential gettext \
libxi-dev libsndfile1-dev \
libpng12-dev libjpeg-dev libfftw3-dev \
libopenexr-dev libopenjpeg-dev \
libopenal-dev libalut-dev libvorbis-dev \
libglu1-mesa-dev libsdl1.2-dev libfreetype6-dev \
libtiff4-dev libavdevice-dev cmake libboost-all-dev \
libavformat-dev libavutil-dev libavcodec-dev libjack-dev \
libswscale-dev libx264-dev libmp3lame-dev python3.2-dev git \
libspnav-dev libtheora-dev libjack-dev libglew1.6-dev curl
mkdir blender && cd blender
tar xvvf blender-2.63a.tar.gz
mkdir build && cd build
cmake -DCMAKE_INSTALL_PREFIX=/opt/blendertutorial -DWITH_BUILDINFO=ON -DWITH_IK_ITASC=ON -DWITH_BULLET=ON -DWITH_GAMEENGINE=ON -DWITH_PLAYER=ON -DWITH_PYTHON_INSTALL=ON -WITH_OPENMP=ON ..
make -j2 && make install
ln -s ../dependencies/blender/blender-2.63a/build/bin/blender blender
ln -s ../dependencies/blender/blender-2.63a/build/bin/blenderplayer blenderplayer
Test your installation! Execute: /opt/blendertutorial/bin/blender. You should see something like that:
If everything worked out as expected, you may open the first blend file provided along with this tutorial. You will find a "robot" in there. Well, it is not exactly the most advanced robot, this is not about modelling, but programming. In the last tutorial you learned how to rig a robot model, and how to apply a kinematic chain. Now you will learn how to make use of that in the BGE. The robot consists of a torso and two arms, each with 3 joints. IK chains are applied on both arms without any angular limitations (3 DoF). The IK chains are driven by so called empty_objects (see: orange cross in the figure below), which means: If you move an empty_object, the robots arm tries to approximate the 3D position (no orientation) of the emtpy_object (target_left & target_right). Please play around with the provided blend file.
The Game Engine
To view the model in the BGE, open the tutorial file and place your mouse cursor over the 3D window and press "p" — to exit the Game Engine press "ESC". In the first video you will learn how to record and replay actions in the BGE.
Here's the video, you may watch it first to actually see what's about to happen. The necessary steps will be described below. There's a complete solution of this tutorial attached below, but you should try this out on your own — using the first file.
Okay, in the opened blend file select an empty_object (right mouse button) and place it somewhere in the 3D space. Press "i". A new menu opens, select LocRotScale.
What this actually does, is to add a key frame  for the selected object with regard to location, rotation and scale of the object. At this point it is important to set the position of the timeline marker (bottom window, green lines) to another time step if you want to add further key frames.
After you added several key frames for all objects you may want to animate, you can skip through the key frames in the timeline window to actually see whats going on. Alternatively, you can place the mouse cursor over the 3D window and press ''Alt+a" which plays the whole animation from the beginning to the end in a loop.
If you're happy with your animation(s) you can trigger them in the BGE. How to do that? First of all select the Armature in Object Mode. With the Armature selected, open the Game Logic Panel . You can open the Logic Panel by selecting the "Joystick" option from the list in the bottom left corner (check Video 2:05 minutes).
It is extremely important to add an "Always" Sensor, connected to an "Or" Controller which connects to an "Armature" Actuator. If you don't do this, you won't see any movements of the Armature in the Game Engine (check the video 1:50 minutes). Another important fact to mention here is, that you add Controllers, Actuators and Sensors to each object you want to animate, trigger or move in the BGE. In the beginning, at least from my point of view, this was confusing, because as soon as you select another object, all the stuff in the Logic Panel is gone (not really, but one might think so).
In the following step we will add a "Keyboard" Sensor connected to a "Or" Controller, connected to an "Action" Actuator, which plays the previously recorded animations (check video 2:15 minutes). You need to do that for both empty objects. The key "G" triggers both actions. You connect the logic bricks by dragging the mouse while holding the left mouse button pressed.
As you can see in the video at 3:42 minutes it is also important to set the animation length to the desired/correct value, which is 65 frames in this example.
Well, now you are done. Place the mouse cursor over the 3D window, press "p" and the Game Engine will come up. Now press "g" and you will see the previously recorded actions. That's pretty cool, huh? All steps which were previously explained are assembled in this file.
As a "plus" I have yet another blend file where you can control the left arm using you keyboard keys "Left Arrow" and "Right Arrow" — but have you look yourself. Remember, press "p" and have fun.
This tutorial is partially based on CC content, therefore I decided to publish my content under CC too.
Recent blog posts
- MORSE Master and ROS Groovy Install Script | HowTo
- Full Install Guide | NGINX for Drupal and FastCGI | CentOS | RHEL
- ROS Leap Motion Integration
- Leap Motion and Blender | Finger Pose Estimation @ 100Hz | Third Test
- Leap Motion and Blender | Hand Orientation @ 100Hz | Second Test
- Leap Motion and Blender | Hand Orientation | First Test
- Leap Motion SDK with Python3 (python 3.3) in Ubuntu
- Install and use Leap Motion in Ubuntu 13.04 | Linux | HowTo
- Continuous Integration Servers in Comparison | The Shoot-Out
- Google Summer of Code (GSoC) Project Rejected | Still Rated Good | Example Material
What is Flattr ? Flattr is the worlds first social micro-payment system The idea had already been initiated in 2007, but the first release was in 2010 due to typical geeky laziness. Flattr was founded to help people share money, not just content. https://flattr.com/about