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; }
/** * Calculates the distance from a spatial to the camera. Distance is a squared distance. * * @param spat Spatial to check distance. * @return Distance from Spatial to current context's camera. */ protected double distanceToCam(final Spatial spat) { if (spat._queueDistance != Double.NEGATIVE_INFINITY) { return spat._queueDistance; } final Camera cam = Camera.getCurrentCamera(); if (spat.getWorldBound() != null && Vector3.isValid(spat.getWorldBound().getCenter())) { spat._queueDistance = spat.getWorldBound().distanceToEdge(cam.getLocation()); } else { final ReadOnlyVector3 spatPosition = spat.getWorldTranslation(); if (!Vector3.isValid(spatPosition)) { spat._queueDistance = Double.POSITIVE_INFINITY; } else { spat._queueDistance = cam.getLocation().distance(spatPosition); } } return spat._queueDistance; }
public void valueChanged(final TreeSelectionEvent e) { if (e.getNewLeadSelectionPath() == null || e.getNewLeadSelectionPath().getLastPathComponent() == null) { return; } final Spatial spatial = (Spatial) e.getNewLeadSelectionPath().getLastPathComponent(); final StringBuilder str = new StringBuilder(); str.append(spatial.getName()); str.append(" - "); str.append(spatial.getClass().getName()).append('\n'); if (spatial instanceof Mesh) { final Mesh mesh = (Mesh) spatial; str.append("Primitives: "); str.append(mesh.getMeshData().getTotalPrimitiveCount()).append('\n'); str.append("Index mode: "); str.append(mesh.getMeshData().getIndexMode(0)).append('\n'); } str.append(spatial.getTransform()).append('\n'); if (spatial.getWorldBound() != null) { str.append(spatial.getWorldBound()).append('\n'); } str.append('\n'); final SceneHints sceneHints = spatial.getSceneHints(); str.append("Cull hint: "); str.append(sceneHints.getCullHint()).append('\n'); str.append("Bucket: "); str.append(sceneHints.getRenderBucketType()).append('\n'); textArea.setText(str.toString()); }