Blender + ManuelBastioniLAB to UE4 workflow

I’ve recently struggled more than usual to get this to work, so I’ll store it for later reference.
My sources are this great Youtube video and this post on the Unreal Engine forums.

Initial Setup

First thing to do is to correct a “feature” in Blender, the FBX export plugin adds a root on top of our armature root. That could create problems when exporting to UE4.

Python script and where to modify it

Under Blender/2.78/scripts/addons/io_scene_fbx/ edit the file named export_fbx_bin.py. You need to find the following section.

[cc lang=”python”]
elif ob_obj.type == ‘EMPTY’ or ob_obj.type == ‘ARMATURE’:
empty_key = data_empties[ob_obj]
connections.append((b”OO”, get_fbx_uuid_from_key(empty_key), ob_obj.fbx_uuid, None))
[/cc]
And comment it like so
[cc lang=”python”]
#elif ob_obj.type == ‘EMPTY’ or ob_obj.type == ‘ARMATURE’:
#empty_key = data_empties[ob_obj]
#connections.append((b”OO”, get_fbx_uuid_from_key(empty_key), ob_obj.fbx_uuid, None))
[/cc]

Then, download Manuel Bastioni’s plugin from here, unzip it under Blender/2.78/scripts/addons/ and activate the plugin under File|User Preferences|Add-ons|, also make sure to save your settings so you won’t have to do this step again.

Blender Addon Settings

Creating a new character

On a fresh Blender file, delete the cube and set the scene units to centimeter (Metric and 0.01 unit scale).

Then, click on the ManuelBastioniLAB tab, select a preset of your liking and click on Init Character.

Configure the character as your will, the only setting that is important here is inside the Pose Tools section, where you should select the t-pose.

However, before finalizing, you need to delete the modifiers except for the armature (DO NOT APPLY ANY OF THEM).

Make sure it looks more or less like this.

Now we can click on finalize. I like to clean things up as well, and delete all cameras and lamps.

The issue that needs to be corrected now is that our character is too small, measuring only a few centimeters, so we need to scale it by 100 or so. Select everything and hit S then type 100 and press Enter. You can adjust to a correct zoom level with the Home key.

This scaling needs to be applied to the object, otherwise we will have bone weight issues in UE4. You do this by pressing Ctrl+A and selecting Apply Rotation and Scale.

We are now ready to export our character to an FBX formatted file. These are the export settings that work for me, but YMMV.

Under UE4, these are the import settings that work for me. Using this process I don’t get any errors.

Open up the newly created skeleton. There is a section called Retarget Manager where you need to select the Humanoid Rig and make sure you assign each node to its corresponding bone in your skeleton. You should do this for your source and your target skeletons. Also, make sure everything is saved.

Now, find the element that you want to retarget, right click on it and select Retarget Anim Assets|Duplicate Anim Assets and Retarget.

Fill the menu as you prefer, making sure you select your target skeleton (the one we just imported) and placing the files under our desired folder. Once everything is ready hit Retarget.

A new beginning

Looks like I am going to have some time to do my own thing, finally. Maybe it is a good time to retake some old forgotten projects. For a very long time, I’ve wanted to make videogames. Not just as a hobby, but as a profession. I’m a huge fan of indie games as you can see from my Steam library here. Now with SteamOS and smatphone games it seems like there’s a lot of changes in the videogame industry. You don’t need to have a team of 100+ people working together to create the next hit game, it just seems like game development is going back to its roots, where people created little gems, on their own, with a lot of talent and tons of imagination.

Limbo
Limbo, one of the best games I’ve ever played

Now, I’m a hardcore techie, so I’m not going to be using any popular engines like Unity or Ogre. I did contribute to Leadwerks being ported to Linux on Kickstarter, but I don’t think I’ll be using it.

I don’t intend on reinventing the wheel though, so I will be using a great number of open source libraries. This is a list of technologies that I might probably be using :

  • C/C++
  • Lua, for scripting purposes
  • Simple DirectMedia Layer (SDL), by the great icculus, the cross-platform equivalent of DirectX, handles images, audio, net, …
  • OpenGL, the cross-platform of Direct3D
  • OpenAL, the audio equivalent to OpenGL
  • Assimp, the Asset Import Library, a library used to import 3D models, bones and animations
  • Audacity, audio editor
  • zlib, probably, for compression purposes
  • Boost, because it just rocks
  • LMMS, to produce music. I’m actually going to give this a shot! Needless to say, I have no idea what i’m doing.
  • Blender, 3D model creation
  • Makehuman, quick and easy character creation
  • Git, version control
  • CMake, the most flexible build system I can think of
  • Valgrind, the analysis tools that have taught me so much about programming
  • GCC/GDB the GNU compiler and debugger

Other than this, I will give a shot to LLVM, as I keep hearing more and more about it, but I’ve never actually tried it. And I have no idea what I could use for creating sound effects.

Eventually, I might write a second part to this post, where I will aacknowledge how wrong I was about many choices I make here. There is one thing I know for sure though, and it’s that, at the very least, I will get more knowledge from this experience.

OpenMP, multiprocessing made easy

OpenMP is, according to the Wikipedia, an application programming interface (API) that supports multi-platform shared memory multiprocessing programming in C, C++, and Fortran on many architectures, including Unix and Microsoft Windows platforms. This means, in a nutshell, that it’s an API that makes multiprocessing easy.

The API is currently on its third version, and it is supported to some degree by most compilers on the market today, including GCC since version 4.2, Microsoft’s Visual C++ since version 2005, Intel’s C++ compiler, IBM XL C/C++ compiler and many others.

The most interesting feature of OpenMP is simplicity of implementation, even on existing, production code. With just a little effort, one can turn a single threaded program and turn it into a multiprocessing program, quite often experiencing a huge performance boost, specially on multicore architectures. Although its use is so simple, I still find that it’s unusual to see it being used by most programmers I’ve met. Maybe it’s because most programmers are still used to thinking in terms of one process for most of our non time-critical code, and we don’t have the reflex of implementing such features on a day-to-day basis. And when we implement processes and/or threads, we do it using platform-specific instructions like fork().

This “Hello World” example from the Wikipedia is the perfect example to demonstrate OpenMP’s simplicity:
[cc lang=”c”]
#include
#include
#include

int main (int argc, char *argv[]) {
int th_id, nthreads;
#pragma omp parallel private(th_id)
{
th_id = omp_get_thread_num();
printf(“Hello World from thread %d\n”, th_id);
#pragma omp barrier
if ( th_id == 0 ) {
nthreads = omp_get_num_threads();
printf(“There are %d threads\n”,nthreads);
}
}
return EXIT_SUCCESS;
}
[/cc]

I compile this using GCC by adding -fopenmp to the list of parameters.

[cc lang=”text”]
$ gcc -fopenmp -o openmptest openmp.c
$ ./openmptest
Hello World from thread 0
Hello World from thread 3
Hello World from thread 1
Hello World from thread 2
There are 4 threads
[/cc]
Now if I want to adjust the number of threads to, let’s say, eight threads, I simply have to add an instruction omp_set_num_threads() as such:
[cc lang=”c”]
#include
#include
#include

int main (int argc, char *argv[]) {
int th_id, nthreads;
omp_set_num_threads(8);
#pragma omp parallel private(th_id)
{
th_id = omp_get_thread_num();
printf(“Hello World from thread %d\n”, th_id);
#pragma omp barrier
if ( th_id == 0 ) {
nthreads = omp_get_num_threads();
printf(“There are %d threads\n”,nthreads);
}
}
return EXIT_SUCCESS;
}
[/cc]
The result, as I expected:
[cc lang=”text”]
$ gcc -fopenmp -o openmptest2 openmp2.c
$ ./openmptest2
Hello World from thread 6
Hello World from thread 2
Hello World from thread 3
Hello World from thread 0
Hello World from thread 4
Hello World from thread 1
Hello World from thread 5
Hello World from thread 7
There are 8 threads
[/cc]
How is this done in Linux using fork()? Well, an example program with similar functionality would be something as such:
[cc lang=”c”]
#include
#include
#include

int num_threads = 4;

int main (int argc, char *argv[])
{
int pid[num_threads];
int thread_num;
int status;

// Fork creation
for(thread_num=0; thread_num<num_threads; thread_num++)
{
if ((pid[thread_num] = fork()) == 0)
{
// Wait until all child processes are finished
wait(&status);
}
else
{
printf(“Hello World from thread %d\n”, thread_num);
exit(0);
}
}

printf(“There are %d threads\n”,num_threads);
return EXIT_SUCCESS;
}
[/cc]
The result, as expected, is as follows:
[cc lang=”text”]
$ gcc -o forktest forktest.c
$ ./forktest
Hello World from thread 0
Hello World from thread 1
Hello World from thread 2
Hello World from thread 3
There are 4 threads
[/cc]

My Windows C programming is rusty to say the least, but of course, the above code with fork() would not work under Windows, I would have to use CreateThread(), while the OpenMP example should work if I adjust the includes and the main function parameters as usual.

So, anyways, I’m going to try something a bit more fun. There’s this fairly simple yet cool algorithm which is based on the so called “Montecarlo method”. This method consists of using randomly generated numbers to calculate a value through approximation. I’m doing something slightly different, mine is basically an algorithm to make an estimation of the ? number, but instead of using randomly generated numbers, I will be using a great amount of evenly sequenced numbers. The basic idea is that in a 1 x 1 square the area is 1 square units, and the area of a 1 radius circle is ? square units (? * 12). So if I place the centre of my circle on one of the four corners of the square, the area in common would be ?/4 square units.

Now, if I “throw” a high number of evenly distributed dots on my 1 x 1 square, the ratio of dots landing inside the circle quarter to the total number of dots would be ? / 4 to 1. We can, with this ratio, make an estimate of the value of ?. This, in quick and dirty C code, could be written like this:

[cc lang=”c”]
#include
#include
#include
#include

#define TOTAL_BULLETS 100000

int main(int argc, char *argv[])
{
double almost_pi;
int i,j;
double counter_in=0.0f;
struct timeval startTime;
struct timeval endTime;
double x, y, hypotenuse;

gettimeofday(&startTime, NULL);
for(i=0;i<=TOTAL_BULLETS;i++)
{
for(j=0;j<=TOTAL_BULLETS;j++)
{
x=(double) i / (double) TOTAL_BULLETS;
y=(double)j/(double) TOTAL_BULLETS;

hypotenuse = sqrt(x*x + y*y);

if (hypotenuse <= 1.0f)
counter_in+=1.0f;
}
}

printf(“%f bullets hit the circle\n”,counter_in);
almost_pi=((double)counter_in/(double)TOTAL_BULLETS/(double)TOTAL_BULLETS*4.0f);
printf(“Estimated value of pi is %f\n”,almost_pi);

gettimeofday(&endTime, NULL);
double tS = startTime.tv_sec*1000000 + (startTime.tv_usec);
double tE = endTime.tv_sec*1000000 + (endTime.tv_usec);
double duration = tE-tS;
printf(“Time : %f\n”,duration);
return EXIT_SUCCESS;
}
[/cc]

And the result of my little experiment is actually pretty decent:

[cc lang=”bash]
$ gcc -lm shotgun.c -O3 -o shotgun
$ ./shotgun
7854081365.000000 bullets hit the circle
Estimated value of pi is 3.141633
Time : 455893907.000000
[/cc]

The CPU use during that time was below 50%, as only one core of my dual core machine was in use by my program.

[cc lang=”bash”]
top – 11:14:35 up 2:58, 4 users, load average: 0.58, 1.36, 1.53
Tasks: 112 total, 2 running, 110 sleeping, 0 stopped, 0 zombie
Cpu(s): 50.0%us, 0.2%sy, 0.0%ni, 49.8%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
Mem: 2058320k total, 540940k used, 1517380k free, 58280k buffers
Swap: 4095992k total, 0k used, 4095992k free, 337472k cached

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
4460 txukie 25 0 6244 328 256 R 100.2 0.0 0:26.12 shotgun
409 root 10 -5 0 0 0 S 0.3 0.0 0:00.90 scsi_eh_0
1 root 18 0 10372 684 572 S 0.0 0.0 0:00.51 init
2 root RT -5 0 0 0 S 0.0 0.0 0:00.00 migration/0
3 root 34 19 0 0 0 S 0.0 0.0 0:00.00 ksoftirqd/0
4 root RT -5 0 0 0 S 0.0 0.0 0:00.00 watchdog/0
5 root RT -5 0 0 0 S 0.0 0.0 0:00.00 migration/1
6 root 34 19 0 0 0 S 0.0 0.0 0:00.00 ksoftirqd/1
7 root RT -5 0 0 0 S 0.0 0.0 0:00.00 watchdog/1
8 root 10 -5 0 0 0 S 0.0 0.0 0:00.00 events/0
[/cc]

As seen on the previous example, running this program on an old Core 2 Duo E6400 machine running CentOS 5.6 takes 455 seconds. Now, if I adapt the code with OpenMP it should take a lot less time. Just a few lines of code are necessary to accomplish this task.

[cc lang=”c”]
#include
#include
#include
#include
#include

#define TOTAL_BULLETS 100000

int main(int argc, char *argv[])
{
double almost_pi;
int i,j;
double counter_in=0.0f;
struct timeval startTime;
struct timeval endTime;
double x, y, hypotenuse;

gettimeofday(&startTime, NULL);

#pragma omp parallel for private(i) reduction(+: counter_in)
for(i=0;i<=TOTAL_BULLETS;i++)
{
#pragma omp parallel for private(j,x,y,hypotenuse)
for(j=0;j<=TOTAL_BULLETS;j++)
{
x=(double) i / (double) TOTAL_BULLETS;
y=(double)j/(double) TOTAL_BULLETS;

hypotenuse = sqrt(x*x + y*y);

if (hypotenuse <= 1.0f)
{
#pragma omp atomic
counter_in++;
}
}
}

printf(“%f bullets hit the circle\n”,counter_in);
almost_pi=((double)counter_in/(double)TOTAL_BULLETS/(double)TOTAL_BULLETS*4.0f);
printf(“Estimated value of pi is %f\n”,almost_pi);

gettimeofday(&endTime, NULL);
double tS = startTime.tv_sec*1000000 + (startTime.tv_usec);
double tE = endTime.tv_sec*1000000 + (endTime.tv_usec);
double duration = tE-tS;
printf(“Time : %f\n”,duration);
return EXIT_SUCCESS;
}
[/cc]

The result is as follows:

[cc lang=”bash”]
$ gcc -lm shotgun.c -fopenmp -O3 -o shotgun_omp
$ ./shotgun_omp
7854081365.000000 bullets hit the circle
Estimated value of pi is 3.141633
Time : 385923213.000000
[/cc]

Now the result is a lot better, as the time taken to complete is 385 seconds, that’s a reduction of almost 70 seconds. My computer’s cores are used fully now, as indicated by top:

[cc lang=”bash”]
top – 10:54:51 up 2:39, 3 users, load average: 1.99, 1.90, 1.25
Tasks: 111 total, 2 running, 109 sleeping, 0 stopped, 0 zombie
Cpu(s): 84.3%us, 15.7%sy, 0.0%ni, 0.0%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
Mem: 2058320k total, 538088k used, 1520232k free, 56672k buffers
Swap: 4095992k total, 0k used, 4095992k free, 337468k cached

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
4361 txukie 25 0 22964 560 444 R 199.7 0.0 31:37.46 shotgun_omp
3432 txukie 15 0 77244 1588 600 S 0.3 0.1 0:00.05 screen
1 root 18 0 10372 684 572 S 0.0 0.0 0:00.51 init
2 root RT -5 0 0 0 S 0.0 0.0 0:00.00 migration/0
3 root 34 19 0 0 0 S 0.0 0.0 0:00.00 ksoftirqd/0
4 root RT -5 0 0 0 S 0.0 0.0 0:00.00 watchdog/0
5 root RT -5 0 0 0 S 0.0 0.0 0:00.00 migration/1
6 root 34 19 0 0 0 S 0.0 0.0 0:00.00 ksoftirqd/1
[/cc]

A full specification on OpenMP 3.0, and many more resources, can be found here.

darktable, a photo workflow software for Linux users

As I’m a Linux user I was looking for a decent substitute for Adobe Lightroom. I recently discovered a viable alternative called darktable. I decided to give it a try, as, even if I managed to work with the excellent UFRaw, it took me way too long to get things done, as the user interface wasn’t really suitable for fast workflow.

Darktable seems to be a project that has been going on for two years now, but I have to admit I had never heard of it until recently. I only found out about it because I looked for an alternative to Lightroom in The Linux Alternative Project, and so I decided to give it a go.

My first impressions were excellent, the interface is very similar to LightRoom’s and the program is agile even on an underpowered computer. The program seems to use libraw, meaning it instantly supports RAW formats from an overwhelming number of manufacturers.

After some hours spent editing, I’ve discovered a few weak points with it though; the interface can be a bit difficult to understand at first, and it would be particularly uncomfortable to navigate using a touchpad. Some of the extra tools are difficult to find and are not properly documented, but I still have to admire the effort put into documenting most features, something where most open source programs lag behind.

I’m hoping that, as this program keeps getting better and better, it won’t be long until it comes included in all major Linux distro repositories. It is, in my opinion, crucial to make it more easily available for it to get the attention it deserves.

Darktable

Night photography course

Last Christmas, I was offered a photography course at Stage Photo Paris. Among all the different courses that were available, I decided to go for the night photography course, because I thought that from a technical point of view, it would be the most challenging.

One of my greatest passions is photography, digital photography to be more precise. A couple of years ago I got a digital SLR. The camera, an Olympus E-410, comes packed with a wide range of nifty features, while managing to stay fairly compact. Of course, it’s got a few weak points like it struggles with exposure under certain conditions, and, like most non-professional SLRs, it’s not very good with white balance. This being my first ever SLR, I find this camera to be a great choice.

Olympus E-410

From the very beginning, I tried hard to avoid using the so-called “automatic” modes, and I began using priority mode. Every time I tried using manual mode I would almost always end up with a horrible result. From the outset processing techniques such as HDR appealed to me, but I obtained mixed results.

HDR

Last Christmas, I was offered a photography course at Stage Photo Paris. Among all the different courses that were available, I decided to go for the night photography course, because I thought that from a technical point of view, it would be the most challenging.

Colourful boat

The date of the course arrived, and I got there, late (thanks a lot RATP!) and after a brief introduction and a cup of coffee, we all headed to where we were going to spend the next 5 hours taking pictures: Bercy.

[codepeople-post-map]

I have to say, Bercy is probably one of the places in Paris which I hate most, but I was surprised to notice how photogenic it is at night. The mixture of very poorly lit areas with modern office buildings makes a very interesting blend of light and dark.

Skate Park in Bercy

We first started off at the Palais Omnisports de Paris-Bercy. It’s a horrible building, shaped like a sort of aztec pyramid and covered in grass. It doesn’t get much better at night and there were huge lights that made it difficult to point at the building while avoiding them. The surroundings, however, are a lot more interesting: there’s a skate park with some excellent graffiti and some sort of carved monument whose sole purpose seemed to be to serve as an improvised toilet for the regular alcohol drinkers that the place received. All that was bathed with inexpensive public street lighting, which created some great shadow areas and shapes.

Improvised toilet

We then moved onto the Passerelle Simone-de-Beauvoir which I really enjoyed; the water, the lights, the metallic shapes and the occasional passing boat offered plenty of material to work with.

Hand rail at Passerelle Simone-de-Beauvoir

There was even a busy road near there, so I gave night motion blur a try. It’s getting old, I know, and I don’t even think I made a great job of it, but I’m still quite impressed with the results considering it was the first time I tried it.

Motion blur and reflection

It’s amazing to see how water comes alive at night, and the wide variety of colours at Bercy really helped to produce some pretty special pictures.

Bercy at night

Pont de Bercy close-up

Passerelle Simone-de-Beauvoir

To top it all off, we then moved to a construction site. I absolutely love those kind of settings, dark and gloomy, metal, concrete and raw shapes. I decided to take some pictures with almost no light, huge exposure times and very low ISOs to achieve great effects. Some images work much better in monochrome, others probably could do with HDR or some other processing of some sort, but I decided to keep it simple in the end.

Spiral staircase

Another perspective of the spiral staircase

Some broken plastic web

We headed into a dark alley, the river by our side, which offered great panoramics of the river, and some brilliant perspective photos.

Dark alley

Other side of the alley

Glass staircase

I tried to give my pictures a bit of a subject, perhaps this could be the perfect setting for a 40s film noir, or the surroundings of some dark hard-rock music venue, so I focused on trying to find the perfect scene, the perfect picture (don’t we all?) and let the camera do the talking.

Dark corner

Metallic staircase

Graffiti behind a grid

Monochrome of the alley

It was getting very late, so I decided to spend my last few minutes using the alley as a platform to look out onto the Quai de Bercy, the Ministry of Finance and the odd passing boat, and of course, Paris’ red night sky.

Bercy panoramic

Bercy panoramic

Little dock

Another Bercy panoramic

Do not cross sign

I was even lucky enough to get a brilliant motion blurred picture of a passing tourist boat, with very bright side lights.

Passing boat

Feel free to take a look at the full gallery here.