We've seen how to create the streams of data for a cube in code, and to be honest it's not pretty! Even a simple shape such as a cube requires so much data that it becomes very difficult for us to keep track of it all and almost impossible to create a more complex 3D shape.
Luckily there is an easier way. We can use a 3D modeling package to create, color, and texture a 3D model and export all the required data in a format that Marmalade can then load and use.
Marmalade comes with exporter plugins for the two modeling packages used in most professional game development studios—Maya and 3DS Max. The details in the following sections apply equally to the exporters for both of these modeling packages.
The exporter plugins are installed to your computer when you install the main SDK, but they are not automatically installed into the modeling package for use. In order to use the exporters, we must use the Marmalade Launch Pad program to set them up, as shown in the following steps:
With the plugin installed, start up your 3D modeling package and create or load a model that you wish to export. Since this is a coding book, we won't be going into any details about how to create a 3D model.
If you are a programmer by trade and have no idea how to use a 3D modeling package, don't feel bad. I have seen some truly terrible "programmer art" over the years; so think of this lack of knowledge as a good thing and get a real artist involved in making the artwork for your game. You'll be glad you did!
Assuming you have a 3D model ready to export, let's get the Marmalade exporter plugin going. The exporter window itself is shown in the following figure:
The manner in which the exporter window will be displayed depends on the modeling package you are using.
The exporter window should now be on screen, and as you can see there are a great many options available. We can do without most of them for now, so we'll only cover the ones we need in order to export a non-animated 3D model.
The first thing we need to set is the Current Project field. The exporter maintains a list of projects that, at its simplest level, is just a quick way of choosing a directory where the exported model files will be created.
Since we've not yet created an exporter project, let's do so by clicking on the button labeled Set Project. The following dialog will appear:
To create a new project click on the Add… button at the bottom of the dialog and you will be prompted to enter a name for the project. Once you've accepted the name, the project will appear in the Projects: list.
Click on the Browse… button and locate the data
directory in our code project. All resource files need to reside with our code project's data
directory; this will make exporting model files to the correct place much easier.
For now we will ignore the other settings in this dialog as they are beyond the scope of this chapter; so click the OK button to return to the main exporter window, which should now have our newly created project selected in the Current Project drop-down list and the data
directory we set above in the Project Data Directory field.
With the project set, we can now follow these steps to export the model:
There's no doubt that both Maya and 3DS Max are superb products, but it's also true that they carry a fairly hefty price tag. Unfortunately, Marmalade does kind of rely on using one of these two heavyweight packages.
Admittedly, Marmalade does also ship with a converter for Collada , a file format that was created to enable the interchange of 3D models between different packages. I hesitate to recommend this approach however, as at the time of writing, the Collada converter that ships with Marmalade is known to be a little buggy, particularly when it comes to exporting animations.
Luckily there is a cheaper alternative. There is a 3D modeling package by the name of Blender, which is free to download and use; however, the Blender team is always happy to accept donations to continuously improve the product, so if you find it useful do consider helping them out.
The Marmalade SDK does not come with support for Blender, but thankfully due to the efforts of Benoit Muller there is a rather groovy exporter plugin that does a great job of replacing the 3DS Max and Maya exporters.
If you do not already have Blender installed, head over to the Blender website and download a copy. The URL is as follows:
Installing Blender is just a case of executing the downloaded installer and following the on-screen instructions.
With Blender installed, we now need to get hold of the exporter plugin, which can be found at the following URL:
http://wiki.blender.org/index.php/Extensions:2.6/Py/Scripts/Import-Export/Marmalade_Exporter
The plugin is a Python script that can be installed into Blender using the following steps:
io_export_marmalade.py
into the Blender plugins directory. On Windows this will normally be something like C:Program FilesBlender FoundationBlender2.63scriptsaddons
.To export a 3D model using the Blender exporter, follow these steps:
.group
.3.142.173.238