findPick on a ParticleMesh causes Exception

hello there…

it seems that findPick on a ParticleMesh throws a class cast exception due to the fact that CollisionTree.construct method expects a TriMesh as opposed to a Geometry…

this is easily fixed by changing the parent member of CollisionTree to the Geometry type…then altering the relevant functions…

also i couldn't check out the latest jmonkey from cvs…i got this error



cvs [checkout aborted]: cannot rename file CVS/Entries.Backup to CVS/Entries: No such file or directory



thanks…

Hmmm, I must be missing something (which is quite possible, believe me). CollisionTree creates a tree structure from a collection of triangles for each batch in the picked object. The only batch that contains a list of triangles is TriangleBatch which is in TriMesh. How did switching to Geometry fix your picking issue? Although I will agree that a ClassCastException needs to be fixed, I'm just confused how switching to Geometry did it.

well ParticleMesh can contain a TriangleBatch…

but the main issue was that the parent geometry member in CollisionTree was expecting a TriMesh so therefore any attempts to pick a ParticleMesh caused the exception…

by changing this member to Geometry the reconstruct method would not throw the exception and continue to pick correctly (provided of course that the ParticleMesh geomBatch was TriangleBatch)…

i.e.



construct(TriangleBatch batch, TriMesh parent, boolean doSort)



into



construct(TriangleBatch batch, Geometry parent, boolean doSort)




Change made, should be in next contribution to CVS.

mojomonk said:

Change made, should be in next contribution to CVS.


My apologies in advance for bringing up an old threat alive, but I'm having the same problem. I looked over the code for the CollisionTree class, and I looked inside the constructors and it seems to me that this issue hasn't been fixed yet. The methods construct inside collisiontree.java:

 public void construct(int childIndex, Node parent, boolean doSort) {

        Spatial spat = parent.getChild(childIndex);
        if (spat instanceof TriMesh) {
            mesh = (TriMesh) spat;
            triIndex = mesh.getTriangleIndices(triIndex);
            createTree(0, triIndex.length, doSort);
        }
    }
public void construct(TriMesh mesh, boolean doSort) {
        this.mesh = mesh;
        triIndex = mesh.getTriangleIndices(triIndex);
        createTree(0, triIndex.length, doSort);
    }



inside the CollisionTree class still gives me an error when using a ParticleMesh since ParticleMesh is not of instance TriMesh.

The error I'm getting is this.

SEVERE: Exception in game loop
java.lang.ClassCastException: com.jmex.effects.particles.ParticleMesh cannot be cast to com.jme.scene.TriMesh
at com.jme.bounding.CollisionTreeManager.generateCollisionTree(Unknown Source)
at com.jme.bounding.CollisionTreeManager.generateCollisionTree(Unknown Source)
at com.jme.bounding.CollisionTreeManager.getCollisionTree(Unknown Source)
at com.jme.scene.batch.TriangleBatch.findTrianglePick(Unknown Source)
at com.jme.intersection.TrianglePickResults.addPick(Unknown Source)
at com.jme.scene.batch.GeomBatch.findPick(Unknown Source)
at com.jme.scene.Geometry.findPick(Unknown Source)
at com.jme.scene.Node.findPick(Unknown Source)
at com.jme.scene.Node.findPick(Unknown Source)
at com.jme.scene.Node.findPick(Unknown Source)
at edu.ucsd.ccdb.ontomorph2.view.View3DMouseListener.getPickResults(View3DMouseListener.java:468)
at edu.ucsd.ccdb.ontomorph2.view.View3DMouseListener.psuedoPick(View3DMouseListener.java:333)
at edu.ucsd.ccdb.ontomorph2.view.View3DMouseListener.onMouseRelease(View3DMouseListener.java:254)
at edu.ucsd.ccdb.ontomorph2.view.View3DMouseListener.onButton(View3DMouseListener.java:115)
at com.jme.input.lwjgl.LWJGLMouseInput.update(Unknown Source)
at com.jme.input.InputSystem.update(Unknown Source)
at com.jme.app.BaseGame.start(Unknown Source)
at edu.ucsd.ccdb.ontomorph2.app.OntoMorph2.main(OntoMorph2.java:61)

Could we have a case inside one of the construct method in which if a Trimesh is not necessary or if it isn't trimesh type then don't try overcasting?

thank you in advance


P.S. Edit. So I looked into older revisions of CollisionTree.java on GoogleCode and it seems that it was changed at some point (oct 19, 2007 at revision 3800) to what this thread originally said it will change to. However, it was changed back again to the code that it's originally in the CVS (the two methods i posted up above)

This were the methods that were changed in order to take particlemeshes but that are not available anymore.

  /**
         * Recreate this Collision Tree for the given TriMesh and batch
         * index.
         *
         * @param batchIndex the index of the batch to generate the tree for.
         * @param parent
         *            The Geometry that this OBBTree should represent.
         * @param doSort true to sort triangles during creation, false otherwise
         */
        public void construct(int batchIndex, Geometry parent, boolean doSort) {
               
                GeomBatch gb = parent.getBatch(batchIndex);
                if(gb instanceof TriangleBatch) {
                        batch = (TriangleBatch)gb;
                        triIndex = batch.getTriangleIndices(triIndex);
                        createTree(0, triIndex.length, doSort);
                }
        }

        /**
         * Recreate this Collision Tree for the given TriMesh and batch.
         *
         * @param batch the batch to generate the tree for.
         * @param parent
         *            The trimesh that this OBBTree should represent.
         * @param doSort true to sort triangles during creation, false otherwise
         */
        public void construct(TriangleBatch batch, TriMesh parent, boolean doSort) {
                this.parent = parent;
                this.batch = batch;
                triIndex = batch.getTriangleIndices(triIndex);
                createTree(0, triIndex.length, doSort);
        }