tags:

views:

204

answers:

1

I'm using Blender to create m3g files and then I load them in a java program.
Which is the best way to find an object (a Mesh) in the World? (How should I "build" a world?)

Should I create separate classes for every object and then add them to one World object or should I assign IDs to the objects in Blender and find them in the program by ID?
Or export every object to a separate M3G file?
(Or some other way?)

+1  A: 

Q1. If you know the ID of the 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. Load a basic 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 into the world The API documentation covers this in depth:

Q3. Assign them in Blender, then use the find method to get the exact instance of Object3D you need.

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

Dave Jarvis