private static void addLeafWithNonExistingParents(Spatial root,Spatial leaf){
  if (!(root instanceof Node)) {
    logger.log(Level.WARNING,"Cannot add new Leaf {0} to {1}, is not a Node!",new Object[]{leaf.getName(),root.getName()});
    return;
  }
  for (Spatial s=leaf; s.getParent() != null; s=s.getParent()) {
    Spatial parent=s.getParent();
    Spatial other=findTaggedSpatial(root,parent);
    if (other == null) {
      continue;
    }
    if (other instanceof Node) {
      logger.log(Level.INFO,"Attaching {0} to {1} in root {2} to add leaf {3}",new Object[]{s,other,root,leaf});
      for (Spatial spt=leaf; spt != parent; spt=spt.getParent()) {
        spt.setUserData(ORIGINAL_NAME,spt.getName());
        spt.setUserData(ORIGINAL_PATH,getSpatialPath(spt));
        spt=spt.getParent();
      }
      Node otherNode=(Node)other;
      otherNode.attachChild(s);
      logger.log(LogLevel.USERINFO,"Attached Node {0} with leaf {0}",new Object[]{other.getName(),leaf.getName()});
      return;
    }
 else {
      logger.log(Level.WARNING,"Cannot attach leaf {0} to found spatial {1} in root {2}, not a node.",new Object[]{leaf,other,root});
    }
  }
  logger.log(Level.WARNING,"Could not attach new Leaf {0}, no root node found.",leaf.getName());
}

private static void addLeafWithNonExistingParents ( Spatial root , Spatial leaf ) { if ( ! ( root instanceof Node ) ) { logger . log ( Level . WARNING , "Cannot add new Leaf {0} to {1}, is not a Node!" , new Object [ ] { leaf . getName ( ) , root . getName ( ) } ) ; return ; } for ( Spatial s = leaf ; s . getParent ( ) != null ; s = s . getParent ( ) ) { Spatial parent = s . getParent ( ) ; Spatial other = findTaggedSpatial ( root , parent ) ; if ( other == null ) { continue ; } if ( other instanceof Node ) { logger . log ( Level . INFO , "Attaching {0} to {1} in root {2} to add leaf {3}" , new Object [ ] { s , other , root , leaf } ) ; for ( Spatial spt = leaf ; spt != parent ; spt = spt . getParent ( ) ) { spt . setUserData ( ORIGINAL_NAME , spt . getName ( ) ) ; spt . setUserData ( ORIGINAL_PATH , getSpatialPath ( spt ) ) ; spt = spt . getParent ( ) ; } Node otherNode = ( Node ) other ; otherNode . attachChild ( s ) ; logger . log ( LogLevel . USERINFO , "Attached Node {0} with leaf {0}" , new Object [ ] { other . getName ( ) , leaf . getName ( ) } ) ; return ; } else { logger . log ( Level . WARNING , "Cannot attach leaf {0} to found spatial {1} in root {2}, not a node." , new Object [ ] { leaf , other , root } ) ; } } logger . log ( Level . WARNING , "Could not attach new Leaf {0}, no root node found." , leaf . getName ( ) ) ; }
adds a leaf to a spatial , including all nonexisting parents .
