#ff0000 4  2005 . - #000655  3D   J2ME. M3G 
#def 3D 
,   3D     3D Studio Max.           M3G  (,   JSR 184).           .   3D Studio Max    . 

 Superscape      Swerve (Swerve Studio, Swerve Client  Swerve Content).      Java 3D .   Swerve Studio    ,    Superscape. 

   :       Blender. Blender -  3D    .       3d  -        .     Blender    M3G,      ( Blender   ). 


  M3G   MIDP ?     M3G ,  3D .       ,  Google,   ,    Wireless Toolkit 2.2 (  Demo3D).        ()  Pogoroo,  Sun.   ,      . 
 

       M3G .  pogoroo.m3g     .       .     load()

 1.  

try {
 //    M3D 
 myWorld = (World)Loader.load("/pogoroo.m3g")[0];
 getObjects();
 setupAspectRatio();
}
catch(Exception e) {
 e.printStackTrace();
}
   

 ,      (.  2).      ,        .      find().

 2.    

try {
 tRoo      = (Group) myWorld.find(POGOROO);
 tCams     = (Group) myWorld.find(CAMERA);
 acRoo = (Group) myWorld.find(TRANSFORM);
 animRoo = (AnimationController) myWorld.find(ROO);

 //   
 AnimationTrack track = acRoo.getAnimationTrack(0);
 animLength = 1000; //    1 
 if (track != null) {
  KeyframeSequence ks = track.getKeyframeSequence();
  if (ks != null) animLength = ks.getDuration();
 }

 }
catch(Exception e) {
  e.printStackTrace();
}
  

      ,    .            Sun.    canvas,        .

 3.   

void setupAspectRatio() {
 viewport_x = 0;
 viewport_y = 0;
 viewport_width = myCanvas.getWidth();
 viewport_height = myCanvas.getHeight();
 Camera cam = myWorld.getActiveCamera();
 float[] params = new float[4];
 int type = cam.getProjection(params);
 if(type != Camera.GENERIC) {
  //  
  float waspect=viewport_width/viewport_height;
  if (waspect<params[1]) {
   float height = viewport_width/params[1];
   viewport_height=(int)height;
   viewport_y=(myCanvas.getHeight()-viewport_height)/2;
  }
  else {
   float width = viewport_height*params[1];
   viewport_width=(int)width;
   viewport_x=(myCanvas.getWidth()-viewport_width)/2;
  }
 }
}
 

    ,   TimerTask    repaint().   -   Thread  ExampleCanvas.

 4.  

private class RefreshTask extends TimerTask
{
 public void run(){
  if(myCanvas != null && myGraphics3D != null && myWorld != null) {
 int startTime = (int)System.currentTimeMillis();
 int validity = myWorld.animate(startTime);
 myCanvas.repaint(viewport_x, viewport_y, viewport_width, 
   viewport_height);
  }
 }
}
  

        .   ,        Sun.    MIDP       .

 5.   

package com.kontio;

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import java.lang.IllegalArgumentException;
import java.io.*;
import java.util.*;
import javax.microedition.m3g.*;

public class Example3D extends MIDlet implements CommandListener{
 // ID ,   .
 static final int POGOROO = 554921620;
 static final int CAMERA = 769302310;
 static final int TRANSFORM = 347178853;
 static final int ROO = 418071423;

 private Display myDisplay = null;
 private ExampleCanvas myCanvas = null;

 private Timer myRefreshTimer = new Timer();
 private TimerTask myRefreshTask = null;

 private Command exitCommand = new Command("Exit", Command.ITEM, 1);

 Graphics3D myGraphics3D = Graphics3D.getInstance();
 World myWorld = null;

 private AnimationController animRoo = null;
 private Group tRoo = null;
 private Group tCams = null;
 private Group acRoo = null;

 private int animLength = 0;

 int viewport_x;
 int viewport_y;
 int viewport_width;
 int viewport_height;

 public Example3D(){
  super();
  myDisplay = Display.getDisplay(this);
  myCanvas = new ExampleCanvas(this);
  myCanvas.setCommandListener(this);
  myCanvas.addCommand(exitCommand);
 }

 public void startApp() throws MIDletStateChangeException{
  myDisplay.setCurrent(myCanvas);

  try{
   //    M3D 
   myWorld = (World)Loader.load("/pogoroo.m3g")[0];
   getObjects();
   setupAspectRatio();
  }
  catch(Exception e){
   e.printStackTrace();
  }

  myRefreshTask = new RefreshTask();

  //  ,   20   .
  myRefreshTimer.schedule(myRefreshTask, 0, 50);
 }

 void setupAspectRatio(){
  viewport_x = 0;
  viewport_y = 0;
  viewport_width = myCanvas.getWidth();
  viewport_height = myCanvas.getHeight();

  Camera cam = myWorld.getActiveCamera();

  float[] params = new float[4];
  int type = cam.getProjection(params);
  if(type != Camera.GENERIC){
   //  
   float waspect=viewport_width/viewport_height;

   if (waspect<params[1]){
    float height = viewport_width/params[1];
    viewport_height=(int)height;
    viewport_y=(myCanvas.getHeight()-viewport_height)/2;
   }
   else{
    float width = viewport_height*params[1];
    viewport_width=(int)width;
    viewport_x=(myCanvas.getWidth()-viewport_width)/2;
   }
  }
 }

 public void getObjects(){
  try{
   tRoo = (Group) myWorld.find(POGOROO);
   tCams = (Group) myWorld.find(CAMERA);
   acRoo = (Group) myWorld.find(TRANSFORM);
   animRoo = (AnimationController) myWorld.find(ROO);

   //   
   AnimationTrack track = acRoo.getAnimationTrack(0);
   animLength = 1000; //   - 1 .
   if (track != null){
     KeyframeSequence ks = track.getKeyframeSequence();
    if (ks != null)
     animLength = ks.getDuration();
   }

  }
  catch(Exception e){
   e.printStackTrace();
  }
 }

 public void pauseApp(){
 }

 public void destroyApp(boolean unconditional) throws 
        MIDletStateChangeException{
  myRefreshTimer.cancel();
  myRefreshTimer = null;
  myRefreshTask = null;
 }

 public void paint(Graphics g){
  if(g.getClipWidth() != viewport_width ||
    g.getClipHeight() != viewport_height ||
    g.getClipX() != viewport_x ||
    g.getClipY() != viewport_y){
   g.setColor(0x00);
   g.fillRect(0, 0, myCanvas.getWidth(), myCanvas.getHeight());
  }

  if ((myGraphics3D != null) && (myWorld != null)){
   myGraphics3D.bindTarget(g);
   myGraphics3D.setViewport(viewport_x, viewport_y, 
               &n bsp; viewport_width, viewport_height);
   myGraphics3D.render(myWorld);
   myGraphics3D.releaseTarget();
  }
 }

 public void commandAction(Command cmd, Displayable disp)
 {
  if (cmd == exitCommand){
   try{
    destroyApp(false);
    notifyDestroyed();
   }
   catch(Exception e){
    e.printStackTrace();
   }
  }
 }

 private class RefreshTask extends TimerTask{
  public void run(){
   if(myCanvas !=null && myGraphics3D != null && myWorld != null{
    int startTime = (int)System.currentTimeMillis();
    int validity = myWorld.animate(startTime);
    myCanvas.repaint(viewport_x, viewport_y, 
               vie wport_width, viewport_height);
   }
  }
 }

 class ExampleCanvas extends Canvas{
  Example3D myRooMIDlet;
  int i = 0;

  ExampleCanvas(Example3D Testlet) { myRooMIDlet = Testlet; }

  void init() { }

  void destroy() { }

  protected void paint(Graphics g) { myRooMIDlet.paint(g); }

  protected void keyPressed(int i) { }

  protected void keyReleased(int i) { }

  protected void keyRepeated(int i) { }

  protected void pointerDragged(int x, int y) { }

  protected void pointerPressed(int x, int y) { }

  protected void pointerReleased(int x, int y) { }
 }
}

     



,          3D    JSR 184 (Mobile 3D API). ,   ,  3d  "",      M3G .          .

     :  3D   J2ME.  3D .