public Object getChild(final Object parent, final int index) { if (parent instanceof UIFrame) { return index == 0 ? ((UIFrame) parent).getContentPanel() : null; } if (parent instanceof Node) { final Node parentNode = (Node) parent; return parentNode.getChild(index); } return null; }
private Spatial findChild(final Spatial root, final String key) { if (_spatialCache.containsKey(key)) { return _spatialCache.get(key); } if (key.equals(root.getName())) { _spatialCache.put(key, root); return root; } else if (root instanceof Node) { final Spatial spat = ((Node) root).getChild(key); if (spat != null) { _spatialCache.put(key, spat); return spat; } } return null; }
private Spatial findChild(final Spatial root, final String key) { if (_spatialCache.containsKey(key)) { return _spatialCache.get(key); } if (key.equals(root.getName())) { _spatialCache.put(key, root); return root; } else if (root instanceof Node) { final Spatial spat = ((Node) root).getChild(key); if (spat != null) { _spatialCache.put(key, spat); return spat; } } return null; }
@Override public void sortLights() { for (int i = getNumberOfChildren() - 1; i >= 0; i--) { final Spatial pkChild = getChild(i); if (pkChild != null) { pkChild.sortLights(); } } }
@Override protected void updateChildren(final double time) { for (int i = getNumberOfChildren() - 1; i >= 0; i--) { final Spatial pkChild = getChild(i); if (pkChild != null) { pkChild.updateGeometricState(time, false); } } }
@Override public void sortLights() { for (int i = getNumberOfChildren() - 1; i >= 0; i--) { final Spatial pkChild = getChild(i); if (pkChild != null) { pkChild.sortLights(); } } }
@Override protected void updateChildren(final double time) { for (int i = getNumberOfChildren() - 1; i >= 0; i--) { final Spatial pkChild = getChild(i); if (pkChild != null) { pkChild.updateGeometricState(time, false); } } }
/** * <code>getChild</code> returns the first child found with exactly the given name (case sensitive.) If our children * are Nodes, we will search their children as well. * * @param name * the name of the child to retrieve. If null, we'll return null. * @return the child if found, or null. */ public Spatial getChild(final String name) { if (name == null) { return null; } for (int i = getNumberOfChildren() - 1; i >= 0; i--) { final Spatial child = _children.get(i); if (name.equals(child.getName())) { return child; } else if (child instanceof Node) { final Spatial out = ((Node) child).getChild(name); if (out != null) { return out; } } } return null; }
/** * <code>getChild</code> returns the first child found with exactly the given name (case sensitive.) If our children * are Nodes, we will search their children as well. * * @param name * the name of the child to retrieve. If null, we'll return null. * @return the child if found, or null. */ public Spatial getChild(final String name) { if (name == null) { return null; } for (int i = getNumberOfChildren() - 1; i >= 0; i--) { final Spatial child = _children.get(i); if (name.equals(child.getName())) { return child; } else if (child instanceof Node) { final Spatial out = ((Node) child).getChild(name); if (out != null) { return out; } } } return null; }
/** * removes all collision trees associated with a Spatial object. * * @param object * the spatial to remove all collision trees from. */ public void removeCollisionTree(final Spatial object) { if (object instanceof Node) { final Node n = (Node) object; for (int i = n.getNumberOfChildren() - 1; i >= 0; i--) { removeCollisionTree(n.getChild(i)); } } else if (object instanceof Mesh) { removeCollisionTree((Mesh) object); } }
/** * removes all collision trees associated with a Spatial object. * * @param object * the spatial to remove all collision trees from. */ public void removeCollisionTree(final Spatial object) { if (object instanceof Node) { final Node n = (Node) object; for (int i = n.getNumberOfChildren() - 1; i >= 0; i--) { removeCollisionTree(n.getChild(i)); } } else if (object instanceof Mesh) { removeCollisionTree((Mesh) object); } }
/** * updates the existing tree(s) for a supplied spatial. If this tree does not exist, the tree is not updated. If the * tree is not in the cache, no further operations are handled. * * @param object * the object on which to update the tree. */ public void updateCollisionTree(final Spatial object) { if (object instanceof Node) { final Node n = (Node) object; for (int i = n.getNumberOfChildren() - 1; i >= 0; i--) { updateCollisionTree(n.getChild(i)); } } else if (object instanceof Mesh) { updateCollisionTree((Mesh) object); } }
/** * updates the existing tree(s) for a supplied spatial. If this tree does not exist, the tree is not updated. If the * tree is not in the cache, no further operations are handled. * * @param object * the object on which to update the tree. */ public void updateCollisionTree(final Spatial object) { if (object instanceof Node) { final Node n = (Node) object; for (int i = n.getNumberOfChildren() - 1; i >= 0; i--) { updateCollisionTree(n.getChild(i)); } } else if (object instanceof Mesh) { updateCollisionTree((Mesh) object); } }
public static void trimEmptyBranches(final Spatial spatial) { if (spatial instanceof Node) { final Node node = (Node) spatial; for (int i = node.getNumberOfChildren(); --i >= 0;) { trimEmptyBranches(node.getChild(i)); } if (node.getNumberOfChildren() <= 0) { spatial.removeFromParent(); } } }
public static void trimEmptyBranches(final Spatial spatial) { if (spatial instanceof Node) { final Node node = (Node) spatial; for (int i = node.getNumberOfChildren(); --i >= 0;) { trimEmptyBranches(node.getChild(i)); } if (node.getNumberOfChildren() <= 0) { spatial.removeFromParent(); } } } }
/** * Recreate this Collision Tree for the given Node and child index. * * @param childIndex * the index of the child to generate the tree for. * @param parent * The Node that this tree should represent. * @param doSort * true to sort primitives during creation, false otherwise */ public void construct(final int childIndex, final int section, final Node parent, final boolean doSort) { final Spatial spat = parent.getChild(childIndex); if (spat instanceof Mesh) { _mesh = makeRef((Mesh) spat); _primitiveIndices = new int[((Mesh) spat).getMeshData().getPrimitiveCount(section)]; for (int i = 0; i < _primitiveIndices.length; i++) { _primitiveIndices[i] = i; } createTree(section, 0, _primitiveIndices.length, doSort); } }
/** * Recreate this Collision Tree for the given Node and child index. * * @param childIndex * the index of the child to generate the tree for. * @param parent * The Node that this tree should represent. * @param doSort * true to sort primitives during creation, false otherwise */ public void construct(final int childIndex, final int section, final Node parent, final boolean doSort) { final Spatial spat = parent.getChild(childIndex); if (spat instanceof Mesh) { _mesh = makeRef((Mesh) spat); _primitiveIndices = new int[((Mesh) spat).getMeshData().getPrimitiveCount(section)]; for (int i = 0; i < _primitiveIndices.length; i++) { _primitiveIndices[i] = i; } createTree(section, 0, _primitiveIndices.length, doSort); } }
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); } } } }
/** * Finds a pick using the given ray starting at the scenegraph given as spatial. Results are stored in the given * results value. * * @param spatial * @param ray * @param results * @param ignoreCulled * if true, Spatials with CullHint ALWAYS will be skipped. */ public static void findPick(final Spatial spatial, final Ray3 ray, final PickResults results, final boolean ignoreCulled) { if (spatial == null || !spatial.getSceneHints().isPickingHintEnabled(PickingHint.Pickable) || (ignoreCulled && spatial.getSceneHints().getCullHint() == CullHint.Always) || spatial.getWorldBound() == null || !spatial.getWorldBound().intersects(ray)) { return; } if (spatial instanceof Pickable) { results.addPick(ray, (Pickable) spatial); } else if (spatial instanceof Node) { final Node node = (Node) spatial; for (int i = node.getNumberOfChildren() - 1; i >= 0; i--) { findPick(node.getChild(i), ray, results, ignoreCulled); } } }
/** * Finds a pick using the given ray starting at the scenegraph given as spatial. Results are stored in the given * results value. * * @param spatial * @param ray * @param results * @param ignoreCulled * if true, Spatials with CullHint ALWAYS will be skipped. */ public static void findPick(final Spatial spatial, final Ray3 ray, final PickResults results, final boolean ignoreCulled) { if (spatial == null || !spatial.getSceneHints().isPickingHintEnabled(PickingHint.Pickable) || (ignoreCulled && spatial.getSceneHints().getCullHint() == CullHint.Always) || spatial.getWorldBound() == null || !spatial.getWorldBound().intersects(ray)) { return; } if (spatial instanceof Pickable) { results.addPick(ray, (Pickable) spatial); } else if (spatial instanceof Node) { final Node node = (Node) spatial; for (int i = node.getNumberOfChildren() - 1; i >= 0; i--) { findPick(node.getChild(i), ray, results, ignoreCulled); } } }