Greetings, brothers in the shop, as well as readers who are just interested in mobile platforms and 3D graphics. In the
previous post (as well as in the May issue of the Hacker magazine) I already wrote about how to start working with AirplaySDK (
for some time now it is called Marmalade) - a toolkit that allows you to create a mobile C ++ application once and then compile it into many Platforms: iOS, Android, Windows Mobile, Bada, Symbian, etc. The HelloWorld application is already something, but we don’t like to stop at what you have achieved, and therefore in this article we will talk about creating a small 3D applications. The described SDK has good documentation, and therefore I will limit myself to a small example of creating a 3D model, loading it into our mobile application and changing the camera angle to view the scene. Well, let's get started?
Preparation for work
So, first create a regular box in Maya and paint it blue.

')
With your permission, I will not overload the article with the manual for creating boxes in Maya, since this is not the main topic of our conversation today, and I’m far from being a Maya expert.
So, the box is created. Now we need to install a plugin to export the model in a special format for the Marmalade SDK. To do this, perform the following file copy operations:
<Sdk install> /Tools/Exporters/Maya/ASMaya212Exporter.mll -> <Maya2012Location> / bin / plug-ins
<Sdk install> /Tools/Exporters/Maya/ASExpUI.dll -> <Maya2012Location> / bin / plug-ins
<Sdk install> /Tools/Exporters/Maya/exporter.txt -> <Maya2012Location> / bin / plug-ins
<Sdk install> /Tools/Exporters/Maya/metabase.txt -> <Maya2012Location> / bin / plug-ins
<Sdk install> /s3e/bin/libeay32.dll -> <Maya2012Location> / bin
where
<SDK install> is the path to the folder with the installed SDK,
<Maya2012Location> is the installation folder of Maya 2012. Please note that the installation process is different for different versions of Maya. Read more about this in the
documentation (as well as pay attention to the presence of installation instructions not only for Maya, but also for 3dsMax).
Now open Maya and in the
Windows> Settings / Preferences> Plug-in Manager menu, set the checkboxes
loaded and
auto load in front of
ASMaya212Exporter.mll .
Plugin installed. Open our project with the created box and in the MEL console enter the
ASMayaExporter command.
Export Model
By the command
ASMayaExporter you will see the model export window.

To get started, set the
Project Data Directory parameter to the
data directory of your project. In the
last post we analyzed what the directory is and what it is eaten with. Our 3D model will be saved in it. Also required is the
Asset name field, where you must specify the name of your model. Let's call it
FirstBox , so it will be more convenient.
Now about the optional, but no less important parameters. The words
geometry ,
skeleton ,
animation speak for themselves, but I have already tested the
oneGeo parameter in my own skin. If your model will consist of several component parts - be sure to check this box to get a single GEO file for your model, and not tens for each of the model primitives.
Now press the
Export button and our model appears in the
data directory.
Write the code
Again, in my last article I wrote about how to create a project to work with the SDK. Therefore, I will not describe the whole process in a new way.
To begin with, I will give the source of a single file with the main function
main () :
#include "IwGx.h" #include "IwGraphics.h" #include "IwResManager.h" int main() { IwGxInit(); IwGraphicsInit(); IwGetResManager()->LoadGroup("FirstBox.group"); CIwModel* pModel = (CIwModel*)IwGetResManager()->GetResNamed("FirstBox", "CIwModel"); IwGxSetLightType(1, IW_GX_LIGHT_DIFFUSE); CIwSVec3 dd(0xFF, 0xFF, 0xFF); IwGxSetLightDirn(1, &dd); IwGxSetPerspMul(0xAF); while( !s3eDeviceCheckQuitRequest() ) { IwGxClear( IW_GX_COLOUR_BUFFER_F | IW_GX_DEPTH_BUFFER_F ); IwGxLightingOn(); CIwMat view = CIwMat::g_Identity; view.tz = -80; view.ty = 80; view.tx = -60; view.LookAt(view.GetTrans(), CIwVec3(0, 0, 0), -CIwVec3::g_AxisY); IwGxSetViewMatrix(&view); CIwMat modelMatrix = CIwMat::g_Identity; IwGxSetModelMatrix(&modelMatrix); pModel->Render(); IwGxFlush(); IwGxSwapBuffers(); s3eDeviceYield(0); } IwGraphicsTerminate(); IwGxTerminate(); return 0; }
The code is very simple, even for an inexperienced programmer. But I will explain some points.
After the model is exported, the
FirstBox.group file will appear in the
data folder. Just we load it in the line:
IwGetResManager()->LoadGroup("FirstBox.group");
After downloading the resource file, load directly the model created in Maya:
CIwModel* pModel = (CIwModel*)IwGetResManager()->GetResNamed("FirstBox", "CIwModel");
Also, special attention should be paid to the
IwGxSetPerspMul (...) function. This is a kind of setting the degree of the fish-eye effect. If you leave this option by default, your scenes around the edges of the screen will create the impression of viewing the bottom of a bottle through a
toilet hole .
The
view object is a look at the scene. Its field
t with parameters
x ,
y and
z defines the position of the camera in space. The LookAt method determines the direction of gaze: the first parameter is the position (from) set in the previous three lines, the second is the point in space that you want to look at (to), and the third parameter is the up direction (i.e., if we for example,
if CIwVec3 :: g_AxisY was installed instead of
-CIwVec3 :: g_AxisY , then they would look at the scenes “upside down”).
modelMatrix sets the model transformation matrix. Throwing out of my head such a boring term, I will explain it more simply: with the help of this object we set such parameters as the rotation of the model and the position in space.
And, of course, you should put a screenshot of the scene:

Conclusion
Of course, I didn’t set a goal in this article to tell you about all the possibilities of working with 3D in the Marmalade SDK. The scene is very primitive, but everything else you can learn from the documentation for the toolkit, or if readers are interested in the topic, I will write more articles on this topic. So I hope for your feedback and for the reason that there will be reasons to write a sequel to my articles.
UPD. For some time, the Airplay SDK has been renamed to Marmalade SDK.