Archive

Archive for the ‘jPCT-AE’ Category

Creating A Demo Scene In 3D Studio Max

August 15, 2011 1 comment

My apologies for the slow pacing of this series. Things are pretty hectic for me at the moment, with work and personal circumstances. Fortunately today I had some spare time to put the following together:

Scene render

The above was created in 3D Studio Max 2010. it consists out of four rectangles: floor, large side, small side and window. Further two instanced pillars and a tilted pyramid are used. The two small sides/walls are instances of each other, meaning that they’ll mirror each other’s appearance and other qualities except for position and orientation. When you copy a selected item using Ctrl+v, you get offered to either make a copy or an instance. A copy is independent, an instance is as described earlier. Using the right choice here can make life much easier 🙂

To prepare the elements of this scene for use with jPCT-AE we will have to export each of them to a suitable 3D object file format. I picked OBJ (Wavefront .obj file) because it’s the most common and light-weight of all: http://en.wikipedia.org/wiki/Wavefront_.obj_file

The demo provided on the jPCT-AE page uses 3DS format files, which are relatively huge and complex to parse. OBJ on the other hand are ASCII format and can be read and corrected by a human with a text editor. This makes them far easier to debug as well. Another thing the demo does is serialize the 3D object files using a serialize function only available in the desktop version of the engine. We’ll look at that one later as it can provide a nice speed boost to the loading of resources. For now we’ll keep it simple.

In 3D Studio Max you can export to OBJ files using the standard export feature which I assume you can find. Select the mesh you wish to export, go to export and select ‘Export Selected’. On the next screen pick a name for the mesh and select OBJ as the file type. After clicking next, you get the OBJ export dialogue. The default settings are fine, although you want to make sure you’re exporting materials too (first two checkboxes). Check the 3DS manual if you want to know what each feature does. Do be sure to click the Map Export button. On this screen you’ll want to disable ‘use map-path’, enable ‘extended map-params’, ‘convert bitmaps’ and then pick a suitable map format. This will be used for the textures added to the mesh. I picked PNG here since that’s a nice portable and small format for mobile applications. TGA is more suitable for high-end purposes, and isn’t as widely supported.

Now, just keep exporting each mesh in the scene until you’re done and have a folder filled with OBJ, MTL (material) and PNG files. In the next installment I’ll show you how to take all these loose bits and reassemble it into a coherent whole again, inside the game environment 🙂

Until then,

Maya

Getting Started With jPCT-AE 3D Game Engine

August 9, 2011 1 comment

Today I got started with the jPCT-AE game engine for Android (http://www.jpct.net/jpct-ae/). Even with the shortage of documentation, it’s not too hard to figure out how to use it. Download the release, get the single JAR file and put it into a ‘libs’ folder you create in the root folder of the Android project. In Eclipse you then open the project properties, Java Build Path option and add the JAR from there to the project. Congratulations, you just installed jPCT for Android 🙂

The ‘Hello World’ demo project as presented in the jPCT wiki shows quite well how to use the API, though you have to use the documentation provided in the release ZIP file to get a full understanding of its workings. I won’t replicate the entire demo project here, but you can find it in the wiki: http://www.jpct.net/wiki/index.php/Hello_World_for_Android

You first initialize the engine, set up  (http://developer.android.com/reference/android/opengl/GLSurfaceView.html) to act as a rendering surface for the renderer. The renderer is connected to this surface and everything moves from there. You can use the input events from the touchscreen (touch, move, etc.) to manipulate the game world.

The basics of the renderer function are as follows:

world = new World();
world.setAmbientLight(20, 20, 20);

sun = new Light(world);
sun.setIntensity(250, 250, 250);

// Create a texture out of the icon...:-)
Texture texture = new Texture(BitmapHelper.rescale(BitmapHelper.convert(getResources().getDrawable(R.drawable.icon)), 64, 64));
TextureManager.getInstance().addTexture("texture", texture);

cube = Primitives.getCube(10);
cube.calcTextureWrapSpherical();
cube.setTexture("texture");
cube.strip();
cube.build();

world.addObject(cube);

Camera cam = world.getCamera();
cam.moveCamera(Camera.CAMERA_MOVEOUT, 50);
cam.lookAt(cube.getTransformedCenter());

SimpleVector sv = new SimpleVector();
sv.set(cube.getTransformedCenter());
sv.y -= 100;
sv.z -= 100;
sun.setPosition(sv);

Very easy to get started with. With the demo running, you’ll see a cube on the screen with the standard Android icon used as texture. Touching the screen allows you to spin and manipulate the cube. Hello indeed 🙂

Next up is creating something more closely resembling a game world, and play with the lighting. Expect screenshots soon 🙂

Until then,

Maya

Categories: Android, jPCT-AE, programming