private SceneGraphPath[] pickGeomAllSorted(int xpos, int ypos)
    {
      Node obj;
      int i, cnt=0;
      double dist[] = new double[1];

      // System.out.print("In pickGeomAllSorted\n");
      pickRay = (PickRay) generatePickRay(xpos, ypos);
      sceneGraphPathArr = pickRoot.pickAll(pickRay);

      if(sceneGraphPathArr == null)
	return null;

      boolean found[] = new boolean[sceneGraphPathArr.length];
      double distArr[] = new double[sceneGraphPathArr.length];

      for(i=0; i<sceneGraphPathArr.length; i++) {
        obj = sceneGraphPathArr[i].getObject();
	if(obj instanceof Shape3D) {
	  found[i] = ((Shape3D) obj).intersect(sceneGraphPathArr[i],
					       pickRay, dist);
	  distArr[i] = dist[0];
	} else if(obj instanceof Morph) {
	  found[i] = ((Morph) obj).intersect(sceneGraphPathArr[i],
					     pickRay, dist);
	  distArr[i] = dist[0];
	}
	if(found[i] == true)
	  cnt++;
      }

      if(cnt == 0)
	return null;

      SceneGraphPath newSceneGraphPathArr[] = new SceneGraphPath[cnt];
      distance = new double[cnt];

      cnt = 0; // reset for reuse.
      for(i=0; i<sceneGraphPathArr.length; i++) {
	if(found[i] == true) {
	  newSceneGraphPathArr[cnt] = sceneGraphPathArr[i];
	  distance[cnt++] = distArr[i];
	}
      }

      return sort(newSceneGraphPathArr);
    }