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; }
/** * <code>detachChild</code> removes a given child from the node's list. This child will no longe be maintained. Only * the first child with a matching name is removed. * * @param childName * the child to remove. * @return the index the child was at. -1 if the child was not in the list. */ public int detachChildNamed(final String childName) { if (childName == null) { return -1; } for (int i = getNumberOfChildren() - 1; i >= 0; i--) { final Spatial child = _children.get(i); if (childName.equals(child.getName())) { detachChildAt(i); return i; } } return -1; }
/** * <code>detachChild</code> removes a given child from the node's list. This child will no longe be maintained. Only * the first child with a matching name is removed. * * @param childName * the child to remove. * @return the index the child was at. -1 if the child was not in the list. */ public int detachChildNamed(final String childName) { if (childName == null) { return -1; } for (int i = getNumberOfChildren() - 1; i >= 0; i--) { final Spatial child = _children.get(i); if (childName.equals(child.getName())) { detachChildAt(i); return i; } } return -1; }
/** * <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; }
/** * * <code>attachChildAt</code> attaches a child to this node at an index. This node becomes the child's parent. The * current number of children maintained is returned. <br> * If the child already had a parent it is detached from that former parent. * * @param child * the child to attach to this node. * @return the number of children maintained by this node. */ public int attachChildAt(final Spatial child, final int index) { if (child != null) { if (child == this || (child instanceof Node && hasAncestor((Node) child))) { throw new IllegalArgumentException("Child is already part of this hierarchy."); } if (child.getParent() != this) { if (child.getParent() != null) { child.getParent().detachChild(child); } child.setParent(this); _children.add(index, child); child.markDirty(DirtyType.Attached); if (logger.isLoggable(Level.FINE)) { logger.fine("Child (" + child.getName() + ") attached to this" + " node (" + getName() + ")"); } } } return _children.size(); }
/** * * <code>attachChild</code> attaches a child to this node. This node becomes the child's parent. The current number * of children maintained is returned. <br> * If the child already had a parent it is detached from that former parent. * * @param child * the child to attach to this node. * @return the number of children maintained by this node. */ public int attachChild(final Spatial child) { if (child != null) { if (child == this || (child instanceof Node && hasAncestor((Node) child))) { throw new IllegalArgumentException("Child is already part of this hierarchy."); } if (child.getParent() != this) { if (child.getParent() != null) { child.getParent().detachChild(child); } child.setParent(this); _children.add(child); child.markDirty(DirtyType.Attached); if (logger.isLoggable(Level.FINE)) { logger.fine("Child (" + child.getName() + ") attached to this" + " node (" + getName() + ")"); } } } return _children.size(); }
/** * * <code>attachChild</code> attaches a child to this node. This node becomes the child's parent. The current number * of children maintained is returned. <br> * If the child already had a parent it is detached from that former parent. * * @param child * the child to attach to this node. * @return the number of children maintained by this node. */ public int attachChild(final Spatial child) { if (child != null) { if (child == this || (child instanceof Node && hasAncestor((Node) child))) { throw new IllegalArgumentException("Child is already part of this hierarchy."); } if (child.getParent() != this) { if (child.getParent() != null) { child.getParent().detachChild(child); } child.setParent(this); _children.add(child); child.markDirty(DirtyType.Attached); if (logger.isLoggable(Level.FINE)) { logger.fine("Child (" + child.getName() + ") attached to this" + " node (" + getName() + ")"); } } } return _children.size(); }
/** * * <code>attachChildAt</code> attaches a child to this node at an index. This node becomes the child's parent. The * current number of children maintained is returned. <br> * If the child already had a parent it is detached from that former parent. * * @param child * the child to attach to this node. * @return the number of children maintained by this node. */ public int attachChildAt(final Spatial child, final int index) { if (child != null) { if (child == this || (child instanceof Node && hasAncestor((Node) child))) { throw new IllegalArgumentException("Child is already part of this hierarchy."); } if (child.getParent() != this) { if (child.getParent() != null) { child.getParent().detachChild(child); } child.setParent(this); _children.add(index, child); child.markDirty(DirtyType.Attached); if (logger.isLoggable(Level.FINE)) { logger.fine("Child (" + child.getName() + ") attached to this" + " node (" + getName() + ")"); } } } return _children.size(); }
/** * Creates and returns a new instance of this spatial. Used for instanced rendering. All instances visible on the * screen will be drawn in one draw call. The new instance will share all data (meshData and renderStates) with the * current mesh and all other instances created from this spatial. * * @return an instanced copy of this node */ public Spatial makeInstanced() { final Spatial spat = duplicate(); // copy basic spatial info spat.setName(getName()); spat._sceneHints = _sceneHints; spat.setTransform(_localTransform); // copy local render states spat._renderStateList = _renderStateList; // copy controllers if (_controllers != null) { for (final SpatialController<?> sc : _controllers) { spat.addController(sc); } } return spat; }
/** * Creates and returns a new instance of this spatial. Used for instanced rendering. All instances visible on the * screen will be drawn in one draw call. The new instance will share all data (meshData and renderStates) with the * current mesh and all other instances created from this spatial. * * @return an instanced copy of this node */ public Spatial makeInstanced() { final Spatial spat = duplicate(); // copy basic spatial info spat.setName(getName()); spat._sceneHints = _sceneHints; spat.setTransform(_localTransform); // copy local render states spat._renderStateList = _renderStateList; // copy controllers if (_controllers != null) { for (final SpatialController<?> sc : _controllers) { spat.addController(sc); } } return spat; }
/** * Create a copy of this spatial. * * @param shareGeometricData * if true, reuse any data fields describing the geometric shape of the spatial, as applicable. * @return the copy as described. */ public Spatial makeCopy(final boolean shareGeometricData) { final Spatial spat = duplicate(); // copy basic spatial info spat.setName(getName()); spat.getSceneHints().set(_sceneHints); spat.setTransform(_localTransform); // copy local render states for (final StateType type : _renderStateList.keySet()) { final RenderState state = _renderStateList.get(type); if (state != null) { spat.setRenderState(state); } } // copy controllers if (_controllers != null) { for (final SpatialController<?> sc : _controllers) { spat.addController(sc); } } return spat; }
/** * Create a copy of this spatial. * * @param shareGeometricData * if true, reuse any data fields describing the geometric shape of the spatial, as applicable. * @return the copy as described. */ public Spatial makeCopy(final boolean shareGeometricData) { final Spatial spat = duplicate(); // copy basic spatial info spat.setName(getName()); spat.getSceneHints().set(_sceneHints); spat.setTransform(_localTransform); // copy local render states for (final StateType type : _renderStateList.keySet()) { final RenderState state = _renderStateList.get(type); if (state != null) { spat.setRenderState(state); } } // copy controllers if (_controllers != null) { for (final SpatialController<?> sc : _controllers) { spat.addController(sc); } } return spat; }