Problem with Picking 3DS files

Hi,there



I build a simple 3DS model in 3dMax.I can't pick the model in jme.



Here is code.



public class MousePick extends MouseInputAction
{
       @Override
       public void performAction(InputActionEvent evt)
       {
   if( MouseInput.get().isButtonDown(0))
   {
      Vector2f screenPos = new Vector2f();
      // Get the position that the mouse is pointing to
      screenPos.set(am.getHotSpotPosition().x, am.getHotSpotPosition().y);
      // Get the world location of that X,Y value
      Vector3f worldCoords = display.getWorldCoordinates(screenPos, 0);
      Vector3f worldCoords2 = display.getWorldCoordinates(screenPos, 1);
      Ray ray = new Ray(worldCoords, worldCoords2.subtractLocal(worldCoords));
            
               PickResults results = new BoundingPickResults();
               results.setCheckDistance(true);
               rootNode.findPick(ray,results);

               if(results.getNumber() > 0)
               {
                                    ......
               }
               results.clear();
   }
}



results.getNumber()  always equals to 0 when I click the model. And there is no problem when I use the 3ds files from internet.

Some simple questions that you probably already considered…  Have you tried rendering the bounds to ensure they are there and you are clicking inside of them?  Also, is your 3ds model in rootnode?  Finally, did you by any chance use the setCollidable method in your code?

I load the model as an node.




Node s = loadModel("jmetest/data/model/server/server1.3DS");
s.setLocalScale(0.01f);
s.setIsCollidable(true);

rootNode.attachChild(s);

/**
 * LOAD MODELS
 * @param url THE LOCATION OF THE MODEL
 * @return
 */
private Node loadModel(String url)
{
   try
   {
      Node temp;
      MaxToJme C1=new MaxToJme();
                                ByteArrayOutputStream BO=new ByteArrayOutputStream();
                   URL maxFile=TestMaxJmeWrite.class.getClassLoader().getResource(url);
                   C1.convert(new BufferedInputStream(maxFile.openStream()),BO);
                   JmeBinaryReader jbr=new JmeBinaryReader();
                   jbr.setProperty("bound","box");
                   temp = jbr.loadBinaryFormat(new ByteArrayInputStream(BO.toByteArray()));
                   return temp;
   }
   catch(Exception e)
   {
      e.printStackTrace();
   }
   return null;
}



Does the node automatically have bounding volume added when initializing?

The JmeBinaryReader will apply bounds.  You can call temp.updateWorldBound() just to be sure I suppose.  Have you tried using Debugger to draw the bounds yet?

The debugger tells that in this piece of code,


public void findPick(Ray toTest, PickResults results) {
        if (getWorldBound() != null && isCollidable) {
            if (getWorldBound().intersects(toTest)) {
                // further checking needed.
                for (int i = 0; i < getQuantity(); i++) {
                    ((Spatial) children.get(i)).findPick(toTest, results);
                }
            }
        }
    }



getWorldBound().intersects(toTest)) always return false when I pick the model.

But I can pick the "jmetest/data/model/Character.3DS" using the same code. I think mabe there is somthing wrong with the model.

Do you probably use negative scale in that model? I noticed the bounds being wrong some time with negative scale. Visualize your bounds to check that (if you are using SimpleGame press B)