Visiting scene graph

I sometime find some scene graph nodes which have specific conditions such as name, class, etc.

And sometimes need to do the same task for them.

Is there something like this except Node.getChild(String).

It would be good to have Visitor interface.

Hm? there is a getchildnamed or similar?

or do you want to search the scenegraph?



findx(String x,Spatial child){

if(child == null){ child = rootnode}

if(child instance of Node){

Node bla = (Node) child

for(Spatial c:bla:GetChildren())

findx(x,c)

}

else if(child.getname == x)return child)



}

@EmpirePhoenix the getChild(String name) already scans the whole subtree.

k, then I don’t understand the question

It would be something like an iterator for lists. But I dont know if thats really necessary. The objects you use frequently in games should not really be spatials but rather extend or wrap them I guess… So you have either game entites that reference a spatial as their visual appearance or you extend spatial and give it methods that fit best to your game and search options. Still might be a nice thing to have…

jME is based on scene graph then people will need a extendable way to handle scene graph.

I encountered a requirement for this and now I’m handling this by my own utility class.

Actually, there is no problem. But if there is standard way to do this, it’ll make user life easier.



My use case is

  1. Find node by substring.
  • used in debugging tool to find node easily.
  • used to restructure scene graph
  1. Find node by application-specific node type



    As jme is used for various type of application, not just for games, the requirement will grow more I guess.

Ok I think I see what you’re talking about. You’re talking about a filtering functionality, no? I’m not sure that I would clutter Node with this, but a general TreeUtil with a few static methods could definitely be useful. I’ve for some time been doing custom variables in Spatial naming just using ("$"+my_custom_parameter).



Anyway, perhaps some methods like:



[java]

public static List getAllChildrenWithNamesContaining(Node searchScope, String searchTerm);

public static List getAllChildrenWithNumericIdentifier(Node searchScope, String identifierPrefix, int number);

public static List getAllChildrenOfType(Node searchScope, Class searchType);

[/java]



Edit: Weird, the syntax highlighter won’t let me supply a type argument for the returned List :frowning:

TreeUtil sounds good.

@sbook: The code tags remove tags atm :frowning:

TreeUtil sounds good to me also.

But It would be good to add generic interface to the functions above.

For example,

[java]

public static List getAllChildren(Node searchScope, Filter filter);



interface Filter {

public boolean accept(Spatial s);

}

[/java]

or

[java]

public static void depthFirstSearch(Spatial searchScope, Visitor visitor);

public static void breadthFirstSearch(Spatial searchScope, Visitor visitor);

[/java]

@mulova We would supply a few built in Visitors as well I guess?