Friday, May 13, 2011

Pina Collada

-Sorry if you see this post twice... Blogger suddenly removed it, so let's post it again-

Programmers are stubborn. nerdy, pimply, annoying persons. Ok, that might be too much of a stereotype, but stubborn we certainly are. No miracle, because when working with computers there are 7 million different ways leading to Rome. There are no single, simple, comprehensive solutions in computer-land. If someone asks how to implement a small administrative database for the local kebab store, You can’t just point to a single book which has the universal explanation for such a task.

For a start, what hardware/platform to chose? A MacBook? Unix station, PLC, Microcontroller, Industrial PC, Gameboy Advance? Next step, which programming language do we use? .NET, Java or are we going to print good old IBM Punch cards? Those who read some technical forums, know these discussions are guaranteed for some hot nerd-fights. Hail Linux! Windows 4Eva! Pic16F microchip for real yo. The funny thing is, after choosing your hardware and development platform, you still have nothing; the program has yet to be made. So, unless you need some very specific hardware, stop arguing and just pick the tools you are comfortable with, because it gives the best chance of actually succeeding.

Then when it comes to programming itself, again we have an infinite amount of strategies. OOP programming? Functional programming? Design patterns, or something very different? Do you use existing frameworks, or do you make your own components? A* pathfinding or Dijkstra pathfinding? OpenGL versus DirectX. XML files or binary files. Sigh.

Off topic. The Radar Station test-map in progress. This map will be a playground for the Object Editor. Plenty of stairs to torture ragdolls. This is a not an Engine render by the way.

Honestly I never really readed books about programming (except some Delphi beginner books a LONG time ago), and developed my own "style" throughout the years. A mixture of Karate, Jujitsu, and Turkish oil wrestling. And I guess that's how most programmers do it, more or less. Following advises from the books or not, at some point we'll have to decide whether to go left or right. And after X years you have a portfolio filled with a couple of languages, hardware, platforms and techniques you'd prefer. Which hopefully gives you a nose for things.

And that's how we become stubborn. Because with so many other techniques out there, we have to defend our chosen methods continuously. If some Cobol fanboy touches Delphi, he touches me. C'mon, you and me, after schooltime! Nah, but if you can't convince yourself walking the right path, you'll be lost in no time. It's not there are just one or two other alternatives you can try.... There are one or two THOUSAND alternatives to try, and each takes days, weeks or even years to master. It's just too much. You can ask around on the forums for some guidance (C++ or Java, OpenGL or DirectX?), but in the end you'll have to throw up a coin, or follow your heart. And don't forget that these forum guys, also the experts, are biased just as well. John Carmack’s advise will probably be very different from Tim Sweeney.

And of course, you'll be making wrong decisions now and then. Linux sucks after all ( :) ), Windows can't run 24/7 without a crash, OpenGL may become obsolete, DX doesn't run on your target platform, C++ was too difficult, Java too slow, Delphi not 64 bit. Whatever. But don't worry, making faults is a crucial part of the learning process. You can’t become a boxer without ever getting punched on the nose. Nevertheless... it hurts to discard a technique you spend many, many hours or even months on. Which is why programmers are even more stubborn than the average Joe. Don't admit your faults and fight till the very last man. Americans in Bagdad? Where? Russians in Berlin? We'll show them. Now you know why programmers have entrenched habits, and are deaf to criticism sometimes :)

You may have read the title, "Collada", and now you think "What the hell has a tropical drink / file format to do with the personal problems of a programmer?". Well, as said, Collada is a file format. For 3D related stuff to be more precise. These files can contain geometry data, materials, physical properties of a mesh, scene setup and animations I believe. Right, so we have 3DS, OBJ, LWO, MS3D, X and a few billion other 3D file formats. What format to chose?! Arh, another decision to make. And yes, it does matter what you pick. Some formats are more mature than others. And more important, you'll be telling which tools to use. If you make an *.MS3D (Milkshape) file importer, your modelers will need Milkshape or at least a (good working) exporter plug-in in their software. Unfortunately, plug-ins often include errors (outdated), and tossing around converted models from package to
package requires extra (annoying) time and is prone to mistakes.

A (love) letter to Julio who made this model. The trick is to put as much as info as possible in a model. Engine22 objects aren't just meshes with a texture. It also contains physical info (collision shapes & hitzones), Level of Detail variants so we can use a lower-resolution mesh for distant rendering, attachments such as lamps or particle generators. And eventually sub-objects that are connected with physical joints such as a door hinge.

This is why Collada was made; an attempt to create an universal, simple, all-round file format that will be supported by all 3D packages. Now I'm not sure if they actually accomplished that goal, but at least Blender and 3DS Max support this format, and newer version of Lightwave as well I believe. Yet, I made a Lightwave (LWO) importer ~6 years ago. A logical decision, since I used Lightwave. But from all formats, the LWO is one tough son of a bitch. And at this point, I'm forcing my fellow helpers (who use Blender and Max) to either find a LWO exporter, or we mess around with the OBJ format. Max to OBJ, to LWO, to Tower22. Bleh.

Wouldn't it be smarter to write a Collada importer then? Maybe, but this is where my stubborn, defensive programmer instinct comes around the corner again:
..A: I spend many f#cking hours in thet LWO importer, it finally works now :(
..B: Collada, pfff, don't let me laugh.

For one thing, I just don't like the name "Collada". It sounds like a tropical alcohol free drink or a kids icecream you buy on vacation. But what struck me more was the XML format. Yes, Collada files are just XML files. Which mean you can actually open the file as a text, or view it as a tree structure in any internet browser. I’m more a binary-format man. Never followed the Extensible Markup Language(XML) hype. Text formats… pfff. 50% of those files is overhead you don't need. Instead of just loading array's of data, you'll be "parsing" a whole pile of shit before you finally found something useful. It takes time, extra storage space, extra code to “understand” the file… No sir, I'm no fan of XML. And therefore neither of that Icecream format.

Fair enough? Maybe not. Just because I don't like it, doesn't mean it's rubbish. But it's just the way how my programming career got raised, people are afraid for changes, forgive me. Fact is that XML is used in many applications. Fact is also that Pina Collada is used in several 3D packages, at least more than my beloved Lightwave LWO format. Live with it. So, after many years, I finally decided to take a look at it... And with the Delphi TLibXMLparser it took me 6 whole hours to make a (basic) Collada importer for the Object Editor. The LWO format took me 6 light(wave)years...

Ok, ok, I've done this so many times that I can write file importers while sitting on the toilet, reading a Chuck Norris article. But I'll confess: I was wrong. I can hardly get it out my hands on the keyboard, but here you go: Boys and girls, if you need to pick a fileformat for an environment with a variety of 3D software packages, Collada is a good choice, and programming your own importer isn't so hard, certainly not if you can find a nice XML reader. Happy now?

There will be water and ice here. Gives a nice chance to play with water shaders and low-friction. You know what... I might just make a tech-movie once this map is up and running...


  1. Another great and well documented work you've done, keep it up !

  2. I use to love xml whenever xpath queries are available : ) take a look on 'em if your xml library supports 'em

  3. Thank you farcodev :)

    xpath queries... have to admit I never heard of them. Last XML lesson I had was on school, 5 years ago. Right then I decided I didn't like the format (talking about stuborn), hehe. But after a little search, XPath is like SQL for searching data in XML documents right? I don't think XMLParser for Delphi has this utility, or they named it different...


    check the black bold xpath queries used to match the current red selections

    if u read the whole sample set you will notice its such a powerful tool. no more tree walking.

    being myself another stuborn coder as well, I strongly suggest u to give it a try.
    you will love xpath sooner or later, i guess : )