Jme3 and octree

Hi,

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 Octree.java 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);
        sphere.updateGeometricState();
        rootNode.attachChild(sphere);

        tree = new Octree(sphere,5);
        tree.construct();




and here is the one to render it :

    public void postQueue(RenderQueue rq) {

            renderSet.clear();
            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 "Octree.java" 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){
        scene.updateGeometricState();
       
        name = octname;

        List<Geometry> geomsList = getGeometries(scene);
        geoms = new Geometry[geomsList.size()];
        geomsList.toArray(geoms);
        // 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());
            bbox.mergeLocal(bv);
        }

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

        this.minTrisPerNode = minTrisPerNode;

        //Transform trans = bbox.
        Triangle t = new Triangle();
        for (int g = 0; g < geoms.length; g++){
            //geoms[g].setLocalTransform(transform);
            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());
                allTris.add(ot);
               
//                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

http://industriesindigenes.com

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.