Jme3 and octree


I'm would like to use jme3 for a project to have a basic representation of the world for server side checks.

I was hoping to use the Octree partitioning included in jme3 but i've encontred some difficulties.

I can create my octree just fine, but it don't seem to folow my world transformations. I create a sphere and create an octree from it, but if i scale of move my sphere, the octree stay in (0,0,0) and never move.

When looking at in source code, i see several line desactivated, is the algorythm not yet finished or am i missing something ?

Here is my code to create the octree :

Spatial sphere = (Spatial) assetManager.loadModel("Scenes/Sphere.mesh.xml");
//        sphere.scale(100, 100, 100);
        sphere.setLocalTranslation(1, 0, 0);

        tree = new Octree(sphere,5);

and here is the one to render it :

    public void postQueue(RenderQueue rq) {

            tree.generateRenderSet(renderSet, cam);
    //        System.out.println("Geoms: "+renderSet.size());
            int tris = 0;

            for (Geometry geom : renderSet){
                tris += geom.getTriangleCount();
    //            geom.setMaterial(mat2);
                rq.addToQueue(geom, geom.getQueueBucket());

            Matrix4f transform = new Matrix4f();
    //        transform.setScale(0.2f, 0.2f, 0.2f);
    //        System.out.println("Tris: "+tris);

            tree.renderBounds(rq, transform, box, mat);

    //        renderManager.flushQueue(viewPort);

This problem can be fixed by modifying the "" class.

The author of this class had left some evidences :

(around lines 90, …)

//                geom.getWorldTransform().transformVector(t.get1(), t.get1());
//                geom.getWorldTransform().transformVector(t.get2(), t.get2());
//                geom.getWorldTransform().transformVector(t.get3(), t.get3());

Here is the fix we made to get the stuff working :

(starting from line 55)

    public Octree(String octname, Spatial scene, int minTrisPerNode){
        name = octname;

        List<Geometry> geomsList = getGeometries(scene);
        geoms = new Geometry[geomsList.size()];
        // generate bound box for all geom
        bbox = new BoundingBox();
        for (Geometry geom : geoms){
            BoundingVolume bv = geom.getWorldBound();
            System.out.println("Geom World Bounds : " + geom.getWorldBound().toString());

        // set largest extent
        float extent = Math.max(bbox.getXExtent(), Math.max(bbox.getYExtent(), bbox.getZExtent()));

        this.minTrisPerNode = minTrisPerNode;

        //Transform trans = bbox.
        Triangle t = new Triangle();
        for (int g = 0; g < geoms.length; g++){
            Mesh m = geoms[g].getMesh();
            for (int i = 0; i < m.getTriangleCount(); i++){
                m.getTriangle(i, t);
                // convert triangle to world space
                geoms[g].getWorldTransform().transformVector(t.get1(), t.get1());
                geoms[g].getWorldTransform().transformVector(t.get2(), t.get2());
                geoms[g].getWorldTransform().transformVector(t.get3(), t.get3());
                OCTTriangle ot = new OCTTriangle(t.get1(), t.get2(), t.get3(), i, g);
                //System.out.println("x = " + t.get1().getX());
//                geom.getWorldTransform().transformVector(t.get1(), t.get1());
//                geom.getWorldTransform().transformVector(t.get2(), t.get2());
//                geom.getWorldTransform().transformVector(t.get3(), t.get3());

We are still testing this set of classes and we encounter some difficulties with the "intersect" behaviour. May be the modifications we made in the "Octree" class are not so clean, may be the algorithm is unfinished. Does anyone knows if the set of classes given with the jm3tools package are reliable and ready to use ? If not, is there another way (maybe an external lib to join to jme3) to work with octrees under jme3 ? (I know that simple physix, which implements octrees, was included with jme2, but what about jme3) ?

Thanks a lot for any help.

Gauthier BOAGLIO

The Octree implementation works, its just that some parts are a bit unfinished. The TestOctree test works for example, and actually runs faster on Intel cards than ATI/NVIDIA (!)

I am not sure what kind of issues might be encountered with transforming the octree tris into world space, and why it was commented. I wrote those classes a while ago.

The need for scene partitioning seems to be less and less with time, as video cards are able to handle larger batches of triangles without partitioning, for that reason I have put improvements on the octree system as low priority.

Also, note that the SimplePhysics system uses Octree only for collision, not for rendering, and thus it is probably not very useful for your needs.

OK, thanks for your answers.

After testing, it seems that transforming the tris into world space is ok.

Our needs are server side needs, as we work on a Multi-player game and use jme features only for collisions and those collisions have to be as lightweighted as possible. So SimplePhysics seems to cover our needs. So, I think we are going to roll back to JME2, at the moment.

Thanks again for your precisons.