com.ardor3d.scenegraph.Node.getChild()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(9.6k)|赞(0)|评价(0)|浏览(253)

本文整理了Java中com.ardor3d.scenegraph.Node.getChild()方法的一些代码示例,展示了Node.getChild()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Node.getChild()方法的具体详情如下:
包路径:com.ardor3d.scenegraph.Node
类名称:Node
方法名:getChild

Node.getChild介绍

[英]getChild returns a child at a given index.
[中]getChild返回给定索引处的子级。

代码示例

代码示例来源:origin: Renanse/Ardor3D

  1. public Object getChild(final Object parent, final int index) {
  2. if (parent instanceof UIFrame) {
  3. return index == 0 ? ((UIFrame) parent).getContentPanel() : null;
  4. }
  5. if (parent instanceof Node) {
  6. final Node parentNode = (Node) parent;
  7. return parentNode.getChild(index);
  8. }
  9. return null;
  10. }

代码示例来源:origin: com.ardor3d/ardor3d-animation

  1. private Spatial findChild(final Spatial root, final String key) {
  2. if (_spatialCache.containsKey(key)) {
  3. return _spatialCache.get(key);
  4. }
  5. if (key.equals(root.getName())) {
  6. _spatialCache.put(key, root);
  7. return root;
  8. } else if (root instanceof Node) {
  9. final Spatial spat = ((Node) root).getChild(key);
  10. if (spat != null) {
  11. _spatialCache.put(key, spat);
  12. return spat;
  13. }
  14. }
  15. return null;
  16. }

代码示例来源:origin: Renanse/Ardor3D

  1. private Spatial findChild(final Spatial root, final String key) {
  2. if (_spatialCache.containsKey(key)) {
  3. return _spatialCache.get(key);
  4. }
  5. if (key.equals(root.getName())) {
  6. _spatialCache.put(key, root);
  7. return root;
  8. } else if (root instanceof Node) {
  9. final Spatial spat = ((Node) root).getChild(key);
  10. if (spat != null) {
  11. _spatialCache.put(key, spat);
  12. return spat;
  13. }
  14. }
  15. return null;
  16. }

代码示例来源:origin: Renanse/Ardor3D

  1. @Override
  2. public void sortLights() {
  3. for (int i = getNumberOfChildren() - 1; i >= 0; i--) {
  4. final Spatial pkChild = getChild(i);
  5. if (pkChild != null) {
  6. pkChild.sortLights();
  7. }
  8. }
  9. }

代码示例来源:origin: com.ardor3d/ardor3d-core

  1. @Override
  2. protected void updateChildren(final double time) {
  3. for (int i = getNumberOfChildren() - 1; i >= 0; i--) {
  4. final Spatial pkChild = getChild(i);
  5. if (pkChild != null) {
  6. pkChild.updateGeometricState(time, false);
  7. }
  8. }
  9. }

代码示例来源:origin: com.ardor3d/ardor3d-core

  1. @Override
  2. public void sortLights() {
  3. for (int i = getNumberOfChildren() - 1; i >= 0; i--) {
  4. final Spatial pkChild = getChild(i);
  5. if (pkChild != null) {
  6. pkChild.sortLights();
  7. }
  8. }
  9. }

代码示例来源:origin: Renanse/Ardor3D

  1. @Override
  2. protected void updateChildren(final double time) {
  3. for (int i = getNumberOfChildren() - 1; i >= 0; i--) {
  4. final Spatial pkChild = getChild(i);
  5. if (pkChild != null) {
  6. pkChild.updateGeometricState(time, false);
  7. }
  8. }
  9. }

代码示例来源:origin: com.ardor3d/ardor3d-core

  1. /**
  2. * <code>getChild</code> returns the first child found with exactly the given name (case sensitive.) If our children
  3. * are Nodes, we will search their children as well.
  4. *
  5. * @param name
  6. * the name of the child to retrieve. If null, we'll return null.
  7. * @return the child if found, or null.
  8. */
  9. public Spatial getChild(final String name) {
  10. if (name == null) {
  11. return null;
  12. }
  13. for (int i = getNumberOfChildren() - 1; i >= 0; i--) {
  14. final Spatial child = _children.get(i);
  15. if (name.equals(child.getName())) {
  16. return child;
  17. } else if (child instanceof Node) {
  18. final Spatial out = ((Node) child).getChild(name);
  19. if (out != null) {
  20. return out;
  21. }
  22. }
  23. }
  24. return null;
  25. }

代码示例来源:origin: Renanse/Ardor3D

  1. /**
  2. * <code>getChild</code> returns the first child found with exactly the given name (case sensitive.) If our children
  3. * are Nodes, we will search their children as well.
  4. *
  5. * @param name
  6. * the name of the child to retrieve. If null, we'll return null.
  7. * @return the child if found, or null.
  8. */
  9. public Spatial getChild(final String name) {
  10. if (name == null) {
  11. return null;
  12. }
  13. for (int i = getNumberOfChildren() - 1; i >= 0; i--) {
  14. final Spatial child = _children.get(i);
  15. if (name.equals(child.getName())) {
  16. return child;
  17. } else if (child instanceof Node) {
  18. final Spatial out = ((Node) child).getChild(name);
  19. if (out != null) {
  20. return out;
  21. }
  22. }
  23. }
  24. return null;
  25. }

代码示例来源:origin: com.ardor3d/ardor3d-core

  1. /**
  2. * removes all collision trees associated with a Spatial object.
  3. *
  4. * @param object
  5. * the spatial to remove all collision trees from.
  6. */
  7. public void removeCollisionTree(final Spatial object) {
  8. if (object instanceof Node) {
  9. final Node n = (Node) object;
  10. for (int i = n.getNumberOfChildren() - 1; i >= 0; i--) {
  11. removeCollisionTree(n.getChild(i));
  12. }
  13. } else if (object instanceof Mesh) {
  14. removeCollisionTree((Mesh) object);
  15. }
  16. }

代码示例来源:origin: Renanse/Ardor3D

  1. /**
  2. * removes all collision trees associated with a Spatial object.
  3. *
  4. * @param object
  5. * the spatial to remove all collision trees from.
  6. */
  7. public void removeCollisionTree(final Spatial object) {
  8. if (object instanceof Node) {
  9. final Node n = (Node) object;
  10. for (int i = n.getNumberOfChildren() - 1; i >= 0; i--) {
  11. removeCollisionTree(n.getChild(i));
  12. }
  13. } else if (object instanceof Mesh) {
  14. removeCollisionTree((Mesh) object);
  15. }
  16. }

代码示例来源:origin: Renanse/Ardor3D

  1. /**
  2. * updates the existing tree(s) for a supplied spatial. If this tree does not exist, the tree is not updated. If the
  3. * tree is not in the cache, no further operations are handled.
  4. *
  5. * @param object
  6. * the object on which to update the tree.
  7. */
  8. public void updateCollisionTree(final Spatial object) {
  9. if (object instanceof Node) {
  10. final Node n = (Node) object;
  11. for (int i = n.getNumberOfChildren() - 1; i >= 0; i--) {
  12. updateCollisionTree(n.getChild(i));
  13. }
  14. } else if (object instanceof Mesh) {
  15. updateCollisionTree((Mesh) object);
  16. }
  17. }

代码示例来源:origin: com.ardor3d/ardor3d-core

  1. /**
  2. * updates the existing tree(s) for a supplied spatial. If this tree does not exist, the tree is not updated. If the
  3. * tree is not in the cache, no further operations are handled.
  4. *
  5. * @param object
  6. * the object on which to update the tree.
  7. */
  8. public void updateCollisionTree(final Spatial object) {
  9. if (object instanceof Node) {
  10. final Node n = (Node) object;
  11. for (int i = n.getNumberOfChildren() - 1; i >= 0; i--) {
  12. updateCollisionTree(n.getChild(i));
  13. }
  14. } else if (object instanceof Mesh) {
  15. updateCollisionTree((Mesh) object);
  16. }
  17. }

代码示例来源:origin: Renanse/Ardor3D

  1. public static void trimEmptyBranches(final Spatial spatial) {
  2. if (spatial instanceof Node) {
  3. final Node node = (Node) spatial;
  4. for (int i = node.getNumberOfChildren(); --i >= 0;) {
  5. trimEmptyBranches(node.getChild(i));
  6. }
  7. if (node.getNumberOfChildren() <= 0) {
  8. spatial.removeFromParent();
  9. }
  10. }
  11. }

代码示例来源:origin: com.ardor3d/ardor3d-core

  1. public static void trimEmptyBranches(final Spatial spatial) {
  2. if (spatial instanceof Node) {
  3. final Node node = (Node) spatial;
  4. for (int i = node.getNumberOfChildren(); --i >= 0;) {
  5. trimEmptyBranches(node.getChild(i));
  6. }
  7. if (node.getNumberOfChildren() <= 0) {
  8. spatial.removeFromParent();
  9. }
  10. }
  11. }
  12. }

代码示例来源:origin: Renanse/Ardor3D

  1. /**
  2. * Recreate this Collision Tree for the given Node and child index.
  3. *
  4. * @param childIndex
  5. * the index of the child to generate the tree for.
  6. * @param parent
  7. * The Node that this tree should represent.
  8. * @param doSort
  9. * true to sort primitives during creation, false otherwise
  10. */
  11. public void construct(final int childIndex, final int section, final Node parent, final boolean doSort) {
  12. final Spatial spat = parent.getChild(childIndex);
  13. if (spat instanceof Mesh) {
  14. _mesh = makeRef((Mesh) spat);
  15. _primitiveIndices = new int[((Mesh) spat).getMeshData().getPrimitiveCount(section)];
  16. for (int i = 0; i < _primitiveIndices.length; i++) {
  17. _primitiveIndices[i] = i;
  18. }
  19. createTree(section, 0, _primitiveIndices.length, doSort);
  20. }
  21. }

代码示例来源:origin: com.ardor3d/ardor3d-core

  1. /**
  2. * Recreate this Collision Tree for the given Node and child index.
  3. *
  4. * @param childIndex
  5. * the index of the child to generate the tree for.
  6. * @param parent
  7. * The Node that this tree should represent.
  8. * @param doSort
  9. * true to sort primitives during creation, false otherwise
  10. */
  11. public void construct(final int childIndex, final int section, final Node parent, final boolean doSort) {
  12. final Spatial spat = parent.getChild(childIndex);
  13. if (spat instanceof Mesh) {
  14. _mesh = makeRef((Mesh) spat);
  15. _primitiveIndices = new int[((Mesh) spat).getMeshData().getPrimitiveCount(section)];
  16. for (int i = 0; i < _primitiveIndices.length; i++) {
  17. _primitiveIndices[i] = i;
  18. }
  19. createTree(section, 0, _primitiveIndices.length, doSort);
  20. }
  21. }

代码示例来源:origin: Renanse/Ardor3D

  1. public static void findCollisions(final Spatial spatial, final Spatial scene, final CollisionResults results) {
  2. if (spatial == scene || spatial.getWorldBound() == null
  3. || !spatial.getSceneHints().isPickingHintEnabled(PickingHint.Collidable)
  4. || !scene.getSceneHints().isPickingHintEnabled(PickingHint.Collidable)) {
  5. return;
  6. }
  7. if (spatial instanceof Node) {
  8. final Node node = (Node) spatial;
  9. if (node.getWorldBound().intersects(scene.getWorldBound())) {
  10. // further checking needed.
  11. for (int i = 0; i < node.getNumberOfChildren(); i++) {
  12. PickingUtil.findCollisions(node.getChild(i), scene, results);
  13. }
  14. }
  15. } else if (spatial instanceof Mesh) {
  16. final Mesh mesh = (Mesh) spatial;
  17. if (mesh.getWorldBound().intersects(scene.getWorldBound())) {
  18. if (scene instanceof Node) {
  19. final Node parent = (Node) scene;
  20. for (int i = 0; i < parent.getNumberOfChildren(); i++) {
  21. PickingUtil.findCollisions(mesh, parent.getChild(i), results);
  22. }
  23. } else {
  24. results.addCollision(mesh, (Mesh) scene);
  25. }
  26. }
  27. }
  28. }

代码示例来源:origin: com.ardor3d/ardor3d-core

  1. /**
  2. * Finds a pick using the given ray starting at the scenegraph given as spatial. Results are stored in the given
  3. * results value.
  4. *
  5. * @param spatial
  6. * @param ray
  7. * @param results
  8. * @param ignoreCulled
  9. * if true, Spatials with CullHint ALWAYS will be skipped.
  10. */
  11. public static void findPick(final Spatial spatial, final Ray3 ray, final PickResults results,
  12. final boolean ignoreCulled) {
  13. if (spatial == null || !spatial.getSceneHints().isPickingHintEnabled(PickingHint.Pickable)
  14. || (ignoreCulled && spatial.getSceneHints().getCullHint() == CullHint.Always)
  15. || spatial.getWorldBound() == null || !spatial.getWorldBound().intersects(ray)) {
  16. return;
  17. }
  18. if (spatial instanceof Pickable) {
  19. results.addPick(ray, (Pickable) spatial);
  20. } else if (spatial instanceof Node) {
  21. final Node node = (Node) spatial;
  22. for (int i = node.getNumberOfChildren() - 1; i >= 0; i--) {
  23. findPick(node.getChild(i), ray, results, ignoreCulled);
  24. }
  25. }
  26. }

代码示例来源:origin: Renanse/Ardor3D

  1. /**
  2. * Finds a pick using the given ray starting at the scenegraph given as spatial. Results are stored in the given
  3. * results value.
  4. *
  5. * @param spatial
  6. * @param ray
  7. * @param results
  8. * @param ignoreCulled
  9. * if true, Spatials with CullHint ALWAYS will be skipped.
  10. */
  11. public static void findPick(final Spatial spatial, final Ray3 ray, final PickResults results,
  12. final boolean ignoreCulled) {
  13. if (spatial == null || !spatial.getSceneHints().isPickingHintEnabled(PickingHint.Pickable)
  14. || (ignoreCulled && spatial.getSceneHints().getCullHint() == CullHint.Always)
  15. || spatial.getWorldBound() == null || !spatial.getWorldBound().intersects(ray)) {
  16. return;
  17. }
  18. if (spatial instanceof Pickable) {
  19. results.addPick(ray, (Pickable) spatial);
  20. } else if (spatial instanceof Node) {
  21. final Node node = (Node) spatial;
  22. for (int i = node.getNumberOfChildren() - 1; i >= 0; i--) {
  23. findPick(node.getChild(i), ray, results, ignoreCulled);
  24. }
  25. }
  26. }

相关文章