Hi!
Before being on holidays I wanted to complete this other personal project using my favourite two toys: Python and Blender
Today I’ll show you how to get with cheap technology such as a webcam, a pen and a laser, cool things like object tracking in the BGE. Of course when you don’t have enough money to buy awesome (and really expensive..) hardware, then you go with software solutions.
First of all, what’s object tracking? For those who don’t know it yet, it’s a “is the process of locating a moving object (or several ones) in time using a camera. An algorithm analyses the video frames and outputs the location of moving targets within the video frame.” (from Wikipedia) So basically, it’s like the computer is able to see and detect moving objects. There are many approaches to this, I used laser lights and color-tracking. Somehow color-tracking is simpler, but my plan is of course to do full motion tracking in the future. Unfortunately I couldn’t use OpenCV because my webcam was not supported, so I used Videocapture to get PIL data from the webcam, Python Imaging Library (PIL) to handle the matrix and sockets to communicate internally with Blender. Why sockets? Read my previous post
Laser tracking is simpler, however you can’t have depth which restricts movements in the BGE to two dimensions. On the other hand tracking objects is good if you want to have a full 3D interaction. How do you get the depth? Just checking the size of the bounding box area, when it gets bigger it means the object is closer and viceversa. Another important concept in this is the threshold. You need some time to tune it in order to get a perfect tracking. Spheres are the easiest to track since the shape doesn’t change if you rotate them. I didn’t have any sphere, so I used also a red d20 from my dungeons and dragons kit
Anyway, stop talking, enjoy the video and if you have question post it below
Sources will be available in a couple of days, I need to clean them up a bit from test code and write also some comments. If you are interested in another cool thing about webcams and BGE check this video made by Nathan Letwory, one of the Blender’s coder living here in Finland who I never had the pleasure to meet, but just exchange a couple of emails
Edit: look at what Mike Pan did using BlenderTrack, amazing and brilliant idea. I was actually wondering how to head track using this script, but Mike was faster and smarter than me
Enjoy his video and let’s see what comes next!
Hi, after one busy week I managed to release this first simple demo that shows you how to use the n95 accelerometer as an input device in Blender The application is structured in this way:
Mobile client, a python script which reads the accelerometer data and sends it via bluetooth to the pc
A server that runs on your pc and shares the data with the BGE through a local UDP non-blocking socket
A Blender script which handles the cube rotation in the BGE using the n95 accelerometer’s data
Why did I use a local socket? Sometimes I experienced some lag using pyserial in Blender, so to avoid that my idea was to use a non blocking socket. With this approach I had a smooth game running in Blender without any lag.
What do you need to run this? A Nokia N95, a PC/Laptop with a BT connection and Blender of course! You need to install PyS60 on your Nokia phone from here. Download both PythonForS60_1_4_5_3rdEd.sis and PythonScriptShell_1_4_5_3rdEd_unsigned_testrange.SIS you need to sign the ScriptShell otherwise the accelerometer data won’t be retrieved by the script due to security reasons of Nokia phones. You can sign it from https://www.symbiansigned.com/app/page using “Open signed online”. I’m going to put the source code of what I did really soon, I want to improve a little bit some part of the code to make it more stable. However even though the scenario I present in this video is really simple, it’s a way to show you how Blender is really powerful (besides modeling, animating, composing, whatever ), Python is really one the strongest features that Blender has, since it makes the possibilities of interaction with other apps, device etc, endless. Try for example to imagine the N95 as a joypad for a Blender game WipeOut style (I personally hate WipeOut, but somebody may love it ).
So enjoy the video and if you have feedbacks, questions, comments, feel free to ask!
Sometimes I noticed that is not realistic to animate softbodies without having a good stress map that makes the stretched object to look more realistic. Try for example to think about a balloon, when you fill it with air the material stretches, becoming more transparent on the stressed areas. This effect can be reproduced as well in Blender using stress maps. If you check the second tab of the Texture field in the Material view (Map Input) you can see that one of the possible choices is Stress. That’s what we are going to use in our tutorial and it means that the texture will be mapped on the basis of the difference of edges length compared to the original ones of the mesh. Since a softbody has springs and they stretch, this is perfect for us
In this tutorial I’ll assume that you are already familiar with Blender and know how to follow the basics steps that are not explained in this tutorial
Clear the scene and add a UV Sphere with default values. Add a plane and place it above the sphere, more or less 5 Blender units on the z-axis. Subdivide the plane pressing W and subdivide multi, input 18 and press enter. Switch to weight paint mode and give a weight of 1 to the corners of the plane, so that they don’t float away when we animate it, but they stay still. Name the vertex group softgoal from the Edit panel.
Here it should look the scene after the weight painting:
Weight painting
Create a simple rubber material for the plane, it’s enough to use the default material and assign it your favourite colour, change the specular shader to WardIso (my favourite ) to give a shiny, rubbery look. I’ll come back to its stress map later. Set the plane as a soft body from the physics menu and change the values in this way:
- Click “Use goal” and select softgoal that you created previously
- GStiff 0.186
- Bend 0.500
All the rest leave it as default. Now select the sphere and activate collision from the physics tab. Set damping 0.100 , Inner 0.020 and Outer 0.200.
Animate the plane downward, be careful to do not push too down the plane, otherwise it will go through the sphere. This part requires as usual with soft bodies in Blender, some tuning. So play with settings until you have something that looks like the picture below and you get the best result from the soft body solver.
The soft plane stretched
Now you are ready for the stress mapping! First thing add a new texture to the plane material. It should be a Blend texture and the mapping has to be as below:
Map Input -> Stress
Map to -> Col, Alpha then change the mode from Mix to Add.
Now let’s play with the Blend texture! Basically you need something as in the picture below:
Blend texture settings
The range of the colorband determines teh range of values between high stress and low stress areas of the mesh. A gentler fade on the colorband yields a gentle fade from low stress to high stress areas and viceversa.
When you’re done, try to render the frame in which the rubber plane is stretched and it should look something like this:
Looks cool! Definitely a realistic soft body!
Play with settings and try to customize this tutorial as you wish and for your needs! If you have any question, leave a comment below
after a long period in which I’ve been quite busy with my work and research, I finally found some time to create something new and play again with my favourite toy, Blender
The teddy bear idea comes from this tutorial -> http://www.cgcookie.com/articles/modeling-a-teddy-bear , even if I didn’t follow it at all since I prefer to use my own tecniques to model stuff.
You can find the .blend original file clicking here, make a good use of it and remember always to share what you do with other Blender users/artists as much as you download them from the web don’t break the chain!