Sunday, July 21, 2013

Feck Off!

Britain has spawned a lot of great comedies, some of them even managing to cross borders and become popular outside of the UK. However, one that doesn't have much recognition outside the UK to my knowledge, but is by far one my favourites is the excellent Father Ted.
Set on the fictional Craggy Island, a remote location off Ireland's west coast, the show starred Dermot Morgan as the eponymous Father Ted Crilly, alongside fellow priests Father Dougal McGuire (Ardal O'Hanlon) and Father Jack Hackett (Frank Kelly). Exiled on the island for various past incidents, the priests live together in the parochial house with their housekeeper Mrs. Doyle (Pauline McLynn).
Although all the characters were very funny, Father Jack's alcohol infused antics were some of the most memorable, and his limited vocabulary and foul manner were ripe for impersonation in the school yard (I was 14 when the first episode aired.) Recently a friend at work asked me to make an image for him to put on a t-shirt of Ken Kutaragi in the style of Obama's famous "Hope" image. Being too lazy to do so at the time, another artist at work (talented artist and possessor of beautiful voluminous hair, Yamamura Yasuyoshi) ended up making it for him and I felt like an asshole because he was already overloaded with work. Partly to overcome my feeling bad for not making that t-shirt design, I ended up making an image of Father Jack Hackett in the same style, although coloured with the Irish flag colours, or some bastardisation of them. Hopefully there are a couple of Father Ted fans reading the blog that will like the image.


SVG Version: father_jack_feck.svg

Saturday, June 22, 2013

Blender Quake BSP Importer

UPDATE: Another Blender user named Slight has added some features and fixed some bugs in this importer. His modified files can be found here, and I recommend using this version, as it works with the current version of Blender (2.71 at the time of writing) as well as being improved over the original.

Recently I've been trying to learn how to use Blender. As someone who has worked as an artist in the game industry for quite some time now, I've gotten pretty used to using Maya, but there are so many things I hate about it (not least the $5000 price) that have made me want to learn how to use Blender for serious work. So far I've not exactly become a Blender expert, but as part of my Blender training I decided to do write an add-on.

The addon in question is a Quake (1 of course!) .bsp importer. You can give it any Quake 1 level and it will load all the meshes contained in the .bsp, which also includes loading the textures (stored inside the .bsp in Quake 1 and Half-life) as materials and applying them to the mesh.


Download: blender-quake_bsp_importer-v0.0.4.zip
BlenderArtists thread here.

Quake 1 BSP Importer for Blender

Usage
1. Extract to blender scripts/addons/
2. In user settings go to addons and enable 'Import-Export: Import Quake BSP format'
3. from the File menu, select import>Quake BSP (.bsp)
4. Choose a valid Quake 1 .bsp file
5. Assuming everything worked, your scene should contain all the models in the bsp,
though you may need to move/rotate the camera to see them.

There are several options available when importing:
+ Scale - scale down the level on import (default 0.05) Quake units are 64units ~ 2m (assuming Quake guy is short and stocky)
+ Create materials - enable/disable creation of materials (default on)
+ Worldspawn only - when enabled, only the first model (the worldspawn entity, or main level geometry) is loaded. (default off)

History
0.0.4
+ fixed crash bug caused by texture names not being 0 padded in many older bsps
+ prints bsp version on import (only to terminal, most users won't even see this)
0.0.3
+ added scale option (scale geometry on import)
+ added create materials option (use textures from the bsp to create and assign materials)
+ added worldspawn only option (import just the main map geometry, not doors, triggers etc.)
0.0.2
+ now imports textures from the bsp as materials
+ uvs and materials are applied to faces
0.0.1
+ import bsp imports all models in a bsp file as objects in a blender scene

Sunday, March 10, 2013

Running TrenchBroom Quake Editor on Linux

So after successfully managing to resist the urge to write any new posts during February (I heard it was no blogging month) I'm back with my first post about one of my longer running hobbies - Quake map editing.

Recently, Kristian Duske (aka SleepwalkR) released version 1.0 of his multi-platform open source Quake editor TrenchBroom. He had previously released a preview for Mac only about a year ago and I really wanted to try it out, but since I don't have a Mac, I couldn't. Now there is a Windows and Linux version available, and after having a play with the Windows version I decided to see if I could get it running on my old ThinkPad T61 laptop, which runs Linux Mint 14 Mate Edition.

After having quite a lot of trouble getting the required wxWidgets library set up correctly, I finally managed to get TrenchBroom built and working. There are a few bugs, but it mostly works fine. Here's how to compile and run TrenchBroom for yourself.

Get the TrenchBroom source code
TrenchBroom is an open source project and is online as a GitHub repository. To get the source, you can either download it as a zip without needing to have Git installed, or install Git and clone it to your computer. Cloning has the advantage of allowing you to easily update to the latest source code and recompile to get the latest version, so here's how to clone the TrenchBroom repository:
- Make sure you have Git installed
sudo apt-get install git
- Open a terminal window and navigate to the location you would like to put TrenchBroom.
- Clone the repository
git clone https://github.com/kduske/TrenchBroom.git

Install all dependencies needed to build TrenchBroom
The TrenchBroom source contains instructions on how to build it for each platform. For Linux, this file can be found in TrenchBroom/Linux/Build.txt. The first section lists all the libraries that you need to have installed in order to build TrenchBroom. For convenience, here are the commands needed to install them:
sudo apt-get install g++
sudo apt-get install libgtk2.0-dev
sudo apt-get install freeglut3
sudo apt-get install freeglut3-dev
sudo apt-get install mesa-common-dev
sudo apt-get install libxxf86vm-dev
Hopefully, that should be all that is needed, but if you have problems, check out the link in Build.txt.

Build wxWidgets 2.9.4
wxWidgets is a cross-platform GUI toolkit that is used to handle TrenchBroom's GUI and allows it to work the same way with minimal hassle on all supported platforms. Unfortunately, you will need to build it from the source code, which takes a little time.
- Download the wxWidgets 2.9.4 source code from here: wxWidgets-2.9.4.tar.bz2
- Extract the source to a place you want to keep it.
- Create two folders inside the main wxWidgets-2.9.4 folder called build-release and build-debug
- Enter the build-release folder and enter:
../configure --disable-shared --with-opengl --with-gtk=2
make

- Enter the build-debug folder and enter:
../configure --enable-debug --disable-shared --with-gtk=2
make

Install and configure Code::Blocks IDE
Code::Blocks is a cross platform IDE mainly aimed at c/c++ projects. You can find it in the Software Manager or simply install via the terminal:
sudo apt-get install codeblocks
Once installed, you will need to run Code::Blocks and set up a global variable in order to use wxWidgets when compiling TrenchBroom.
- Open Code::Blocks and go into Settings > Global Variables...
- Create a new variable named WXWIN under the default set by clicking the second 'new' button. 
- Set the 'base' parameter of the new WXWIN variable to point to your wxWidgets-2.9.4 folder
The variable is now set and you can close the window.

Build the TrenchBroom project in Code::Blocks
In the TrenchBroom/Linux folder, there is a Code::Blocks project file named TrenchBroom.cbp. Open it. If you have set everything up correctly, you should be able to build the project successfully and run TrenchBroom for the first time.
Compiling TrenchBroom can takes a few minutes the first time you run, but after that, you can run it as many times as you like without compiling, and any updates you might get via Git shouldn't require a full rebuild, so compiling them will take much less time.
Note that you can either build a release build, or a debug build. If you know what you are doing and want to modify the source (in which case, it might be better to fork the project) then debug is fine, but if you just want to use the editor, it's best to compile a release build, as release will likely run a bit faster.
- Select Release as the build target from Build > Select target > Release
- In Code::Blocks select Build > Build or press ctrl + F9 to build the project
- If the project builds without any errors, you should now be able to run by selecting Build > Run or pressing ctrl + F10
You should now have TrenchBroom in front of you assuming everything went ok and your computer is capable of running it.

If you open up TrenchBroom/Linux/bin there should be a folder named Release (or Debug, if you compiled a debug build). You can safely copy this folder to some other location such as your home folder, rename it to TrenchBroom and then run the executeable when you want to run TrenchBroom in the future. Keep Code::Blocks installed for building new versions though!

Note that if you installed the TrenchBroom source via Git, you can update to the latest version by opening a terminal in the folder you cloned TrenchBroom and running:
git pull origin
This will pull in all the changes up to the current version, and whilst it means you will have absolutely the most bleeding edge code, it might be less stable than specific versions. Still, if you are going to use it regularly, best just get the latest version and report any problems you find.

That's it. Happy mapping!

If you encounter any problems, don't hesitate to contact me or check out the TrenchBroom thread over at func_msgboard.

Update - Possible Issues and Solutions
Since writing this post, I've tried compiling TrenchBroom again on Ubuntu 12.10, and whilst it was mostly pretty straightforward, I had a couple of issues. There are also some issues with TrenchBroom on Linux that can be fixed by manual editing of its settings file.

SIZEOF_LONG compiler error: This can be fixed simply by commenting out the line that defines SIZEOF_LONG in the file wxWidgets-2.9.4/build-<debug/release>/lib/wx/include/gtk2-unicode-static-2.9/wx/setup.h like this:
/* The number of bytes in a long.  */
//#define SIZEOF_LONG 8


Cannot select Quake Path in TrenchBroom preferences: I'm not sure what causes this problem, but it could be a problem with wxWidgets, as I had a similar problem occur in Code::Blocks - another wxWidgets based application. If you can't correctly set the path, you will need to manually edit it by opening the hidden file .TrenchBroom in your <user>/home folder. In there you will find a line in the [General] section that starts "Quake \Path=". Write the correct path after the equals and the next time you load TrenchBroom, it should detect your Quake folder correctly. Here's an example:
Quake\ path=/home/username/Games/Quake

Monday, January 14, 2013

Erg Amigo is Born!

A couple of posts ago (that's simply, "Couple posts ago" to any Americans reading) I mentioned that I had found a way to get data from my Concept 2 rowing erg using a Python script called PyRow. Since then I have started making a little application to make erg training more fun and yesterday I christened it Erg Amigo and set up a repository on GitHub.

Whilst it's currently not a lot more than a tool to log workout data from the erg and draw little graphs, I plan to expand it into a proper application that can run real-time logs of multiple connected ergs and perhaps add racing functionality. It will almost certainly never be as functional as the official RowPro software that Concept 2 sell on their website, but at least it will work on non-Windows systems.


Here's the first mind-blowing screenshot of my progress showing a plot of multiple force curves overlaid on top of one another. The erg monitor already displays single force curves, along with a host of other information, but I want to make interactive logs so that the user can see how consistent their strokes are and how close to an ideal curve they are hitting throughout their session. When I add a graph to show other variables, such as strokes per minute, power and pace over the course of an entire session, the ability to view force curves for any point in time and overlay them should be quite useful.

Python is pretty fun by the way. I recommend giving it a whirl with some small project to see how you like it. There are built in libraries for just about everything, so it's a huge difference from using something like c++, where you have to write everything yourself, or find, download, configure and compile existing ones. I doubt you are going to write God of War in Python, but for little projects where raw performance and the ability to do extremely custom or low-level stuff are not important, it's ideal.

Saturday, January 12, 2013

Python Script to Convert MP4 Video to MP3 Audio

Earlier today, at around midday, I was going to do some exercise, but since I don't like to use my rowing erg without something to listen to, I thought I'd listen to some TED Talks via iPod Touch to Bluetooth headset. Unfortunately, I couldn't get the damned headphones to connect to my laptop, iPod or Nexus 7, though they were detected by all. The Nexus connected, but the playback cut out every few seconds, the iPod connected, but didn't work after that, and my laptop was only able to find my Nexus 7 and not the headphones.

This was really annoying as the headphones used to work fine with my iPod. I don't know what happened, but I expect that the headphones just decided to stop working today for the hell of it, despite them being fine just recently.

So I decided to go old skool and use my ancient iPod Nano instead. Unfortunately, due to my own inability to calmly handle minor problems, the fact I couldn't quickly filter downloaded Podcasts in Banshee from those I had yet to download, made me so angry I started to look for other solutions. That I had downloaded video podcasts in the belief that they were audio only podcasts just made me angrier and I started to find other ways to get audio only TED Talks.

In the end, I got so pissed off that I spent hours writing a Python script to convert the video podcasts into mp3 audio. It took so long partly because I am stupid, but also partly because I spent a lot of that time learning new things in Python and digging through the magnificent Stack Overflow for help.

Here is the script for anyone it might help. Note that you need to have mplayer, lame and python 2.x installed for this script to work.
sudo apt-get install mplayer
sudo apt-get install lame
sudo apt-get install python2.7
Then simply run
python mp4tomp3.py [input_directory [output_directory]]
This will convert all mp4 files in the input directory into an mp3 file in the output directory, ignoring any files that have been previously converted. The input and output directories are optional; Input will default to the current directory and output will default to the same as input.

So now I have a folder full of mp3 audio only TED Talk podcasts. I still don't know how I'm going to get them on my iPod though. There must be something similar to Sharepod available for Linux. I guess finding that is my next task.

I'm never going to buy another fucking iDevice again.

Update: Once I'd converted the videos to mp3s, I imported them into Banshee and from there it was quite trivial to get them onto my iPod. I think the main problem I had was that there was no filter for downloaded files. Also, I discovered that my 3rd generation Nano can play mp4 videos, so I just wasted half a day fucking around wisely spent half a day learning new things.

Sunday, January 6, 2013

Learning Some Python

I was bored last night and for some reason the site Learn Python The Hard Way was open on my laptop. I think I'd found it a while ago, and like most things I find on the net, I thought "this looks interesting. I look at it later and maybe learn some stuff!", pinned the tab and then forgot about it. Last night I was just bored enough to try the first few exercises. Next thing I know, I'm at exercise 32, and well on my way to having a working knowledge of Python!

Also, I managed to finally get my ass on my rowing erg to finally do my first workout of the new year (got to get in shape for naked man festival) and since my body is basically fucked at the moment, I only did 2000m and it took a whopping 7 minutes 45 seconds. Still, I've got time to improve.


So what do rowing and Python have in common? Well, Concept 2, the company that made the erg has logging software that allows you to record your time and lots and lots of other stats such as the force you are applying each stroke, your speed throughout the entire workout etc. Unfortunately, this software is only available for Windows. I have a laptop with Windows XP on it, but it's depressing having to fire up XP just to log some stats, which might explain why I've only ever done it once and completely forgotten all my Concept 2 site login details...

I Googled to see if I could find any software for Linux, but I didn't have much luck. However, I did find this thread on the Concept 2 forums, containing a link to a utility that makes it possible to access data from the erg via the standard USB connection using Python. OMG! New mini project! As if I don't have enough stupid things to distract me from actually finishing any one thing, now I have a new project, and a bit more motivation to keep up with the erg training.

So the past hour or two I've been just playing around getting PyRow and the required USB to Python interface set up using pyusb, and testing it out to make sure it works with my erg. So far it's all good!

Since I was looking at QT5 recently, I am thinking I might see if QT and Python are a good match and try and make a simple logging application for recording my workouts. WxPython (very tasteful site) would be another option worth investigating for making a GUI with graphs and stuff.

By the way, if you want to learn some Python, I can recommend Learn Python The Hard Way. If you have any programming experience whatsoever you should breeze quickly through the exercises, and if you have none, then you are the target audience and it should be a perfect tutorial to get started with. I was also reading through the Python chapter in the recently released Raspberry Pi Education Manual. This manual deals specifically with programming in Python on a Raspberry Pi using IDLE (whatever the fuck that is... The LPTHW guy is constantly saying "Don't use IDLE"), and is aimed at children with little to no programming experience, but it seemed well written and had some entertaining projects such as a simple ski-free style game using PyGame, a simple web server and a section on using the GPIO interface to make real world objects do stuff.

Wednesday, January 2, 2013

A Gameboy Tetris Clone in Javascript

Like many children of the 90s, I had a Gameboy, and like just about everyone else that had a Gameboy, I had a copy of the insanely addictive puzzle game Tetris. The Gameboy version of Tetris was not the original version, but due to its insane popularity and catchy theme tune, a version of which  hit the UK Charts  in 1992*, it remains the one with which most people are familiar.


One of the small projects I worked on last year was to figure out how Tetris worked and write my own version in Javascript. There are already billions of Tetris clones (including this version, which fits into 1k of Javascript), but I didn't care, because like most of the people writing these clones, the purpose was simply for programming practice and fun. Because I remembered the Gameboy version of the game being so damned addictive, and also because it is one of the simplest, with no smooth movement or aftertouch on placed blocks or other recent "enhancements" to the original game, I thought I would try to clone it as closely as possible. This went as far as looking up details on scoring, game speed and other small details on the Tetris wiki, and of course, the dubious practice of ripping as much sound and graphics as possible from screenshots and videos of the game available on the internet.

The Github repository is here. You can play it for yourself by clicking this link (note that it might not load especially quickly).

Although a very simple project to handle, there were a few elements to the project that I found interesting to code, such as the randomiser, which must avoid giving the player the same shape too many times, or not enough of another shape, which are potential problems with selecting a Tetrimono completely at random each time a new one is required.

To solve this problem, I used a simple randomiser that stores all the valid shapes in an array, and an index into the array. Each time a new shape is required, the randomiser just returns the current shape in the array and increments the index. When the index reaches the end of the array, the randomiser randomly reorders the shapes and the index resets to zero. This way, the maximum number of times any shape can appear in a row is  twice - in the case it happens to be the last item in the array, and then the first after the array is reordered. This means that you always know that eventually the straight piece will arrive, but also that you are guaranteed to have an S and a Z for every one of them!


The entire randomiser code is here. Feel free to use it, or any of the other code in your own projects. Note that it's kind of badly written, so you'll probably need to rewrite it to support different sizes and get rid of some of the weird stuff like the way I pass this.bag as an argument to some of the functions instead of just doing var bag = this.bag at the beginning of the function. Have fun!

*Written by Andrew Lloyd Webber under the Pseudonym "Doctor Spin"

Tuesday, January 1, 2013

Happy New Year!

It seems that we made it through 2012 alive. Thankfully, the Mayan long count calendar's lack of support for dates greater than 21st December 2012 did not cause anyone significant harm. Since I am still alive, I thought now would be a great time to start blogging about some of the random stuff I am interested in.

To begin with, however, I'm just going to write up a short list of the things I want to achieve this year.

Do the things I want to do instead of just thinking about doing them. I have many amazing world-changing ideas that are going to make me a billionaire. The only reason I'm not currently blogging from the top of Palmer Tower, which would be built right next to Trump Tower and just slightly higher, in order to block the best views from Donald Trump's offices is that when I have good ideas, I don't try and do anything about them.
Target :  Talk to more people. Spend less time thinking about things and more time doing them. Less giving up. Less self-discouragement. Doing this will ensure I can do anything on this list.

Daily exercise. In preparation for the Saidaiji naked man festival, I need to shake off my Winter fat soon. One might imagine that fat would help keep me warm, but I figure that it's going to be more embarrassing to trot out my mostly naked white arse in the freezing cold if said arse is wobbling more than need be. I also need to make more use of that rowing machine that I bought last year in order to stay in shape in the Winter, that I haven't been using because it's too cold. DOH!
Target : No belly fat and down to overall body weight of 74kg by February. Continue exercise throughout the year.

Finally win the battle against my toe dwelling fungal nemesis. Although athlete's foot is not a particularly troublesome affliction - especially when you have a very mild case, it is bloody annoying, and extremely difficult to get rid of completely.
Target : No fungus by summer.

Finish all the Quake levels I started. I like making Quake levels. I've been doing this as a hobby for about 16 years now, and it helped me get a job in the gaming industry. However, I would like to stop eventually and concentrate on other interests such as programming. I already made some positive steps toward this aim by finishing a level I started a long time ago, and releasing another two that are part of a deathmatch to single-player remake series. However, I still have a lot more work to do, as there are four levels remaining.
Target : Release all remaining DM#RMX maps before the end of June.

Release an Android game. Game programming (for simple games) is not that difficult. I've shown to myself through various home projects in 2012 that I can do it, and I'm doing more programming at work than ever (note, I am a designer/artist normally), so I would like to focus on one simple game project and release it. Don't fuck about reinventing the wheel with tech, even though a lot can be learned this way. Just use Unity!
Target : Release a game sometime in the year.

Other targets: Study more, save more money, buy house (no evil loans), write more about what I'm doing and share things I've learned with others (this blog), do more baking.

Hopefully by writing this blog I'll also get better at writing English, which somewhat embarrassingly, is my native language :)