Advertisement
Guest User

jme scenegraph traversal test

a guest
Feb 1st, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.89 KB | None | 0 0
  1. package playground;
  2.  
  3. import com.jme3.app.SimpleApplication;
  4. import com.jme3.scene.Node;
  5. import com.jme3.scene.Spatial;
  6.  
  7. public class TraversalTest extends SimpleApplication {
  8.     @Override
  9.     public void simpleInitApp() {
  10.         Node n_1 = new Node("N-1");
  11.         rootNode.attachChild(n_1);
  12.         Node n_1_1 = new Node("N-1-1");
  13.         n_1.attachChild(n_1_1);
  14.         Node n_1_1_1 = new Node("N-1-1-1");
  15.         n_1_1.attachChild(n_1_1_1);
  16.  
  17.         Node n_2 = new Node("N-2");
  18.         rootNode.attachChild(n_2);
  19.         Node n_2_1 = new Node("N-2-1");
  20.         n_2.attachChild(n_2_1);
  21.         Node n_2_1_1 = new Node("N-2-1-1");
  22.         n_2_1.attachChild(n_2_1_1);
  23.  
  24.         /* Graph:
  25.                 Root Node
  26.                     N-1
  27.                         N-1-1
  28.                             N-1-1-1
  29.                     N-2
  30.                         N-2-1
  31.                             N-2-1-1
  32.         */
  33.  
  34.         /* Expected Order (PRE):
  35.             Root Node
  36.             N-1
  37.             N-1-1
  38.             N-1-1-1
  39.             N-2
  40.             N-2-1
  41.             N-2-1-1
  42.         */
  43.        
  44.         /* Output currently (PRE_ORDER only applied to first call on rootNode):
  45.             Root Node
  46.             N-1-1-1
  47.             N-1-1
  48.             N-1
  49.             N-2-1-1
  50.             N-2-1
  51.             N-2
  52.         */
  53.  
  54.         /* Output after fix (passing mode to recursive calls in Node.depthFirstTraversal):
  55.             Root Node
  56.             N-1
  57.             N-1-1
  58.             N-1-1-1
  59.             N-2
  60.             N-2-1
  61.             N-2-1-1
  62.         */
  63.  
  64.         rootNode.depthFirstTraversal((Spatial spatial) -> {
  65.             System.out.println(spatial.getName());
  66.         }, Spatial.DFSMode.PRE_ORDER);
  67.     }
  68.  
  69.     public static void main(String[] args) {
  70.         TraversalTest app = new TraversalTest();
  71.         app.setShowSettings(false);
  72.         app.start();
  73.     }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement