public static void findCollisions( final Spatial spatial, final Spatial scene, final CollisionResults results) { if (spatial == scene || spatial.getWorldBound() == null || !spatial.getSceneHints().isPickingHintEnabled(PickingHint.Collidable) || !scene.getSceneHints().isPickingHintEnabled(PickingHint.Collidable)) { return; } if (spatial instanceof Node) { final Node node = (Node) spatial; if (node.getWorldBound().intersects(scene.getWorldBound())) { // further checking needed. for (int i = 0; i < node.getNumberOfChildren(); i++) { PickingUtil.findCollisions(node.getChild(i), scene, results); } } } else if (spatial instanceof Mesh) { final Mesh mesh = (Mesh) spatial; if (mesh.getWorldBound().intersects(scene.getWorldBound())) { if (scene instanceof Node) { final Node parent = (Node) scene; for (int i = 0; i < parent.getNumberOfChildren(); i++) { PickingUtil.findCollisions(mesh, parent.getChild(i), results); } } else { results.addCollision(mesh, (Mesh) scene); } } } }
public static boolean hasCollision( final Spatial spatial, final Spatial scene, final boolean checkPrimitives) { if (spatial == scene || spatial.getWorldBound() == null || !spatial.getSceneHints().isPickingHintEnabled(PickingHint.Collidable) || !scene.getSceneHints().isPickingHintEnabled(PickingHint.Collidable)) { return false; } if (spatial instanceof Node) { final Node node = (Node) spatial; if (node.getWorldBound().intersects(scene.getWorldBound())) { if (node.getNumberOfChildren() == 0 && !checkPrimitives) { return true; } // further checking needed. for (int i = 0; i < node.getNumberOfChildren(); i++) { if (PickingUtil.hasCollision(node.getChild(i), scene, checkPrimitives)) { return true; } } } } else if (spatial instanceof Mesh) { final Mesh mesh = (Mesh) spatial; if (mesh.getWorldBound().intersects(scene.getWorldBound())) { if (scene instanceof Node) { final Node parent = (Node) scene; for (int i = 0; i < parent.getNumberOfChildren(); i++) { if (PickingUtil.hasCollision(mesh, parent.getChild(i), checkPrimitives)) { return true; } } return false; } if (!checkPrimitives) { return true; } return PickingUtil.hasTriangleCollision(mesh, (Mesh) scene); } return false; } return false; }
public static void findPick(final Spatial spatial, final Ray3 ray, final PickResults results) { if (!spatial.getSceneHints().isPickingHintEnabled(PickingHint.Pickable)) { return; } if (spatial instanceof Node) { final Node node = (Node) spatial; if (node.getNumberOfChildren() == 0 || node.getWorldBound() == null) { return; } if (node.getWorldBound().intersects(ray)) { // further checking needed. for (int i = 0; i < node.getNumberOfChildren(); i++) { PickingUtil.findPick(node.getChild(i), ray, results); } } } else if (spatial instanceof Mesh) { final Mesh mesh = (Mesh) spatial; if (mesh.getWorldBound() == null) { return; } if (mesh.getWorldBound().intersects(ray)) { // find the primitive that is being hit. // add this node and the primitive to the PickResults list. results.addPick(ray, mesh); } } }