Finding Objects in J2ME M3G

I am using Blender to create m3g files and then load them into a java program.
What is the best way to find object (s Mesh

) in World

? (How do I "build" the world?)

Should I create separate classes for each object and then add them to one object, World

or assign IDs to objects in Blender and find them in the program by ID?
Or export each object to a separate M3G file?
(Or in some other way?)

+2


a source to share


1 answer


Q1. If you know the identifier Mesh

( MESH_ID

), then:

try {
  Object3D[] roots = Loader.load( "http://www.example.com/scene.m3g" );

  World world = roots[0];
  Mesh mesh = world.find( MESH_ID );
}
catch( Exception e ) {
  // Handle it
}

      

Q2. Download the basic one World

:

public class MyCanvas extends Canvas
    Graphics3D g3d;
    World world;
    int currentTime = 0;

    public MyCanvas() {
        g3d = Graphics3D.create();
        Object root[] = Loader.load("world.m3g");
        world = root[0];
    }

    protected void paint(Graphics g) {
        g3d.bindTarget(g);
        world.animate(currentTime);
        currentTime += 50;
        g3d.render(world);
        g3d.releaseTarget();
    }
}

      



Then use the API to create and add more objects to the world. The API documentation details this:

Q3. Assign them in Blender, then use the method find

to get the exact instance Object3D

you want.

Q4. If you plan on reusing cells (for different applications), organize them into separate files, load them separately during application initialization, and then insert them into the world.

+1


a source







All Articles