Subscribe to News

J2ME : Creating M3G Models

Author : Jbuenol

From TechnologicalWiki

Jump to: navigation, search


Contents

[edit] Introduction

M3G ( Mobile 3D Graphics ) is a specification defining an API for writing Java programs that produce 3D computer graphics. The objects and the background are created in 2 ways in a M3G enviroment :

  • Directly using the API M3G Objects.
  • Importing the models into the application from the outside.

This article is focused on to know how to create the graphics using the second way. It's possible thanks to the M3G files. These files define a 3D scene which can be imported by the M3G API to create the scenes.

[edit] Main concepts in 3d Design

A scene in 3D is compound by several independent objects which interact with each other to create the scene building ( movement, transformation, lighting ... ). Each one of these objects has a specific objective in the scene.

The list of the main types of objects and their descriptions is shown below :

  • Background : Defines whether and how to clear the viewport.
  • Camera : An object that defines the position of the viewer in the scene and the projection from 3D to 2D. You can create several cameras and move them over the scene. One of the cameras is always the active one on the scene.
  • Light : A scene graph object that represents different kinds of light sources.
    • ambient : The effect of this light affects the whole scene. This is not established in anyplace.
    • omnidirectional : The behaviour of this kind of light is like a bell. It is situated in a point and the objects which are near light are iluminated.
    • spot : The source of this light is a circle which is projected to illuminate a part of the surface.
    • directional : This is like a spot light, but the only difference is that the source is a point which opens forming a circle at the end of the focus.

The RGB intensity contributed to the lighting calculation by a Light is (IR, IG, IB), where I is the intensity of the Light and (R, G, B) is its color.

In the case of an ambient light source, the final RGB intensity represents the ambient color component only; the diffuse and specular components are implicitly set to zero. In the case of a directional, omni or spot light, the final intensity represents both the diffuse and specular components, while the ambient component is correspondingly set to zero.

  • Fog : Represents a layer of fog.

3D design covers basic object creation or complex object creation.

Among the basic objects you can build are :

  • 2D-Objects : (Lines, Circles, Rectangles, Triangles ...)
  • 3D-Objects : (Cilynders, Spheres, Cubes, Pyramids ...)

Other complex objects can be created using other simple objects. The meshes are used to create a complex object. A set of vertex object forms the meshes. A vertex is not more than a point ( x,y,z ) in the scene.

[edit] Appareance

  • Material : A component for lighting computations ( textures, ligths intensity , ...).

[edit] Transfomations

Other "entities" exist which represent transformations of other objects :

  • Rotation : This transformation is applied to the object to rotate it in the scene.
  • Traslation : This transformation is applied to the object to traslate it in the scene.
  • Escalation : This transformation is applied to the object to change the size of the object.

You can combine these transfomations to create an animated object through a Time-Line. A Time-Line is a period of time defined for an scene. In it, Several transformations can be defined for each object (Objects, Lights, Cameras, ...) of the scene.

e.g. Imagine your created object is a kangaroo. You can create a set of tranformations for it so that an animation will be created and the kangaroo jumps automatically.


Class Summary

[edit] Creation tools

There are a lot of tools to create M3G scenes. Many of the usual tools to design 3D Objects have support to export the scene to M3G files. This is the easiest form to create your scenes in mobile J2ME devices.

The main tools to develop in 3D are the next ones ( M3G compatibles ) :

[edit] Propietary tools

[edit] Free Open Source tools

  • Blender.The models of each tool can be exported to other tools. For example, 3D Studio Max and Autodesk's Maya works with .max and .ma files, which are a representation of a scene. It's possible to export them to others extensions which can be imported by others tools.
    • .3ds FILES (3DStudio files) , 3D image format used by Autodesk 3D Studio; contains mesh data, material attributes, bitmap references, smoothing group data, viewport configurations, camera locations, and lighting information; it may also include object animation data.
    • .obj FILES , a geometry definition file format first developed by Wavefront Technologies for its Advanced Visualizer animation package. The file format is open and has been adopted by other 3D graphics application vendors and can be imported/exported from Cheetah3D, Daz3d'sDazStudios, e-Frontier's Poser, Autodesk's Maya, Avid's Softimage|XSI, Blender, MeshLab, Misfit Model 3D, 3DStudioMax, and Rhinoceros 3D, Hexagon, Newtek Lightwave, Art of Illusion, GLC_Player etc. For the most part it is a universally accepted format. The OBJ file format is a simple data-format that represents 3D geometry alone — namely, the position of each vertex, the texture coordinate associated with a vertex, the normal at each vertex, and the faces that make each polygon.

[edit] Exporting models

To successfully export a scene to an m3g file it is helpfull to note the following:

  • M3G imposes the following restrictions when assigning textures to a model:
    • The dimensions must be powers of two (4, 8, 16, 32, 64, 128...).
    • Texture dimensions are limited to a 256x256 maximum.

Note: Use small textures if possible to reduce the m3g file size. Use paletized images (256 colours).

  • Do not use procedural textures or materials.
  • Add a background to the scene. To avoid a the white background, try setting the ambient environment in the scene, or alternatively some surface or a skybox as background.
  • Add a camera into the scene.
  • Add a light source into the scene.
  • It is better to export simple scenes or single models.
  • Do not compress the m3g file.

[edit] Exporting from Blender

[edit] Installation

It's very easy to export the models from Blender. You can export a 3D model from Blender using its own application. So, The export process is free of charge using Blender (Open Source Application).


[edit] Exporting

1. The File menu allows exporting in another formats. There are a lot of possibilities :

.m3g, ( 3D Studio) .3ds, ( AC3D ) .ac, ( DirectX ) .x, ( VRML ) .wrl, ( xfig port ) .fig , ( Wavefront ) .obj ... and many more...

Image:Blender1.jpg


2. The options of exportation can be enabled or disabled clicking on the options:

Image:menuExport.jpg


The next link represents a demo about the physics in Blender. In addition to export the model to M3G format, you have the possibility to export it to a java file, to manage the model in the java application without the need of having to export. For this, enable the "As Java Source" option in the last menu.


[edit] Exporting from Maya

M3GExport enables developers to export complex 3D animated scenes from Maya® directly to Mobile 3D Graphics file format (M3G). M3GExport lets use sophisticated features of M3G format like skeletal animation, morphing meshes, triangle stripping and other useful optimisations. M3GExport for Maya is available in two editions, Limited and Standard. The Standard version contains sophisticated optimisation options used mostly by commercial game developers. The non-commercial Limited edition contains almost every feature found in the full commercial Standard version and can be upgraded later.


[edit] Installation

1. Unzip M3GExport.zip to your personal folder


2. Copy the plug-in file from M3GExport1.X.X\Windows\MayaX.X\m3gExportLimitedMayaX.X.mll to your Maya's plugin directory. (Usually C:\Program Files\Autodesk\MayaX.X\bin\plug-ins or C:\Program Files\Alias\MayaX.X\bin\plug-ins or C:\Program Files\AliasWavefront\Maya5.0\bin\plug-ins)


3. Delete old m3gExport.mll (if you have earlier version) in the same plugin directory


4. Copy the M3GExport options file from M3GExport1.X.X\Windows\CommonFiles\m3gExportOptions.mel to your Maya's script directory. (Usually C:\Program Files\Autodesk\MayaX.X\scripts\others or C:\Program Files\Alias\MayaX.X\scripts\others or C:\Program Files\AliasWavefront\Maya5.0\scripts\others)


5. Copy the dll files from M3GExport1.X.X\Windows\CommonFiles\Libs.zip to C:\Program Files\Autodesk\MayaX.X\bin or C:\Program Files\Alias\MayaX.X\bin or C:\Program Files\AliasWavefront\Maya5.0\bin (you'll probably already have some of them). You may install the dll files directly to C:\WINDOWS\system32 folder.


6. Start Maya and add m3gExportLimitedMayaX.x plug-in (Windows->Settings/Preferences->Plug-in Manager)


7. "Reset Settings" in Export menu (File->Export All…->Export All option box) before first use.


You can find some tutorials clicking here

[edit] Exporting from 3DS MAX

This section is concerned with showing how to export a m3g model from 3DS MAX using the EXPORT 184 plug-in, a plug-in for 3DS MAX version 6 and higher. This tool is not free.

The information below is based on 3DS MAX 7 (EXPORT 184 plug-in valid from 3DS MAX 6).

3DS MAX 7 supports developing mobile games using the JSR-184 format. The exported m3g file can be previewed using the JSR 184 Standalone Player. Included with EXPORT 184 plug-in is an independant player to view models and animation sequences. The exporter and player are developed by Digital Element.


We are going to learn how to export the model in the following lines :

[edit] Installation

1. Download the plug-in and then, execute the installer.

[edit] Exporting


1. To export the 3dsmax model, choose menu: File > Export.


2. Locate a directory where you want to store the m3g file. Enter a filename, for example: teapot1

Choose save as type: JSR 184 (*.M3G)

Press Save button.


The JSR-184 exporter dialog is shown, displaying the scene hierarchy. Here below an example:

Image:Screen1.gif

By default, all of the elements in your scene are also listed for export in the JSR-184 scene. If you wish to export a particular object in your scene, use File > Export Selected, or delete the objects you do not wish to export by clicking it. If an object is a descendant within a hierarchy, it will be exported with its hierarchy. The same applies for objects in a group.


3. In the JSR 184 scene window, select an [Active Camera]. In this example only 2 cameras are added to the scene of which Camera01 is selected.

Image:Screen2.gif


4. Change the Export Settings in the tool and click on EXPORT button.

Image:table.gif


5. After exporting two files are created (no messages are displayed during exportation), for example:

teapot1.m3g teapot1.html (build log)

The log file (teapot1.html) is saved in the same directory as the M3G file. The log file contains an entry for all the objects exported to the M3G file format.

  • Layer : Indicates the layer value.
  • Object Name : Contains the name of the corresponding 3ds max object.
  • Object Type : Indicates the type of saved object.
  • User ID : Displays the User ID for the object.
  • Object Size : Shows the object size (in kilobytes) for the object.
  • Comments : Displays additional information such as errors and warnings.

6. Preview the exported JSR-184 scene in the standalone M3G Player.

You can find the player in Start > Programs > discreet > 3ds max 7 > JSR-184 Player

Image:TeaPotModel.gif

[edit] Limitations

The M3G exporter tool has some limitations:

  • Integer precision: This limits the accuracy of small meshes of only a few units in size. For best results, use relatively large meshes. Scaled objects also might exhibit precision problems.
  • Linear interpolation: Smoothly curved paths defined by only a few keys are not supported.
  • No support for shadows.

[edit] See also

http://en.wikipedia.org/wiki/3D_computer_graphics_software

http://www.digi-element.ru/download/export184/Export184.pdf

http://www.java4ever.com/index.php?section=j2me&project=m3gtoolkit&menu=main&lang=_en

http://sourceforge.net/projects/juinness/

http://www.mascotcapsule.com/en/index.php

[edit] References

http://www.m3gexport.com/index.jsp

http://www.digi-element.com/

http://www.mobilefish.com/tutorials/3dsmax/3dsmax_quickguide_export_184.html

Main Collaborators