So far during development of a 3D game for JME-enabled mobile devices I’ve been using simple theme — single texture in each image. It worked but inevitably I hit texture memory limit on some devices. It turns out that merging several textures into one image (as shown below) indeed reduces memory usage but while doing so I hit an interesting problem with M3G models using such textures. Namely, if mesh is uv-mapped only to a part of texture image it is rendered with different part of texture. Here’s full story and a fix to M3G->Blender exporter.
Usually a mesh uses full texture image…

On the first image you see a model using entire image, it works fine. Second image shows a mesh mapped to a central part of texture image, it works as well.
Now is where things start to get interesting…

Mesh mapped to upper-left part of image appears to use bottom-left part of image when rendered. Oops?
So I thought I’ll make a simple experiment and map mesh to an area near the center, but shifted a bit to the top…

It appears that when a mesh is mapped to area shown on the left image appears rendered as in the right image.
Making long story short, I checked that the horizontal coordinates are fine but center of UV-mapped area is shifted in the wrong direction relative to the vertical center of an image.
It appears that the fix included computing vertical center of UV-mapped area and shifting it to the other part of texture. If vCenter is center of texture-mapped area new v coordinate should be calculated as: v’ = v – ((0.5 – vCenter) * 2.0). No, don’t ask me why it has to be that way but I verified it and it works π
You can find excellent M3G exporter for Blender by Gerhard Voelkl at http://www.nelson-games.de/bl2m3g/
A link to patch fixing V coordinate generation: m3g_export_08_fix_v_coordinate
This text file is in .odt format since WordPress doesn’t allow uploading of plain text files. Please save it as text and you should get a valid patch file.
September 2, 2008 at 3:30 am |
01-09-08
Sir,
I created a simple 3D character using Blender and export it with m3g.
Questions? How do I open it? In the Sum Emulator where do I put it?
In the apps section res or the src file?Is it exported in digital form?
1’s and 0’s?
Thank You,
David
September 2, 2008 at 4:14 pm |
Hi David!
That’s a lot of questions and judging from them you are just starting with M3G. I suggest you google for ‘m3g tutorial’ — you should get quite a few interesting links. You may want to take a look at a series of excellent tutorials from Redikod, first part is here: https://developer.sonyericsson.com/site/global/techsupport/tipstrickscode/mobilejava3d/p_java3d_tutorial_part1_compliments_redikod.jsp
Generally I find SonyEricsson’s http://developer.sonyericsson.com site useful.
Before you try to import M3G files it would be useful if you tried to write some simple apps, for example displaying blue triangle, textured rectangle, play with camera, lighting etc. so you have some experience with the API before you start doing something more involved.
And you can always bother nice folks from FreeNode’s #j2me channel, I often hang around there as well π