Noob question: Node finding

Hi!

Sorry I didn’t find a sufficient answer to my simple question, thanks for your help!

i simply want to find out if a Node with a special name is within a certain area. For example, when I have a torch in my hands,I want to know if a Node called “TorchAttachPoint#x” is within an invisible(or wired) Box in front of my player. Is there a possibility to do that directly? If not, would you think it is better to solve this probem mathematically (Saving all coordinates in an Array and iterate), or just give each AttachNode an collision Shape and collide with that?

May i ask, what you need this for?
Is it for Bloxel-Terrain? If so… you got your underlying Voxel data to work with. Otherwise: Depends.

it is a chunk based world, so i can basically search the nearby chunks. But that means I have to include moving object Node searching. So would it be ok (considering performance) to iterate all nearby AttachNodes with Node.getWorldTranslation()?

The existing collision stuff may well do this for you. Just create a mathematical cube and intersect it with the root node and see what pings then search those things for the matching node.

On the other hand I think you are probably going the long way around doing this. Why not just register a list of torch attachment points somewhere and scan that list? It will be a much smaller list than the list of everything in the scene graph…
.

You could even build a tree around that and sort by distance to [0,0,0] or stuff. You could skip things that are way off from the estimated distance and therefore gain some more performance.

That depends on how many such objects there are. Even for up to 100 objects just scanning an arraylist is probably as fast as anything once you consider the overheads of other methods.

Extend the Node class and add your own search methods for sibling, children, parent, etc. You have a specific need… accommodate yourself!

Now… read the posts below this to hear all the reasons you shouldn’t extend the Node class :stuck_out_tongue: I’m such a rebel

1 Like

im gonna post a patch and make Node final to spite everyone :evil: Happy Easter!!

@KuroSei said: You could even build a tree around that and sort by distance to [0,0,0] or stuff. You could skip things that are way off from the estimated distance and therefore gain some more performance.

do you know a good method to do that?

Its usefullness totally depends on how many nodes you’ve got in the scene, exactly as @zarch said.
If you want to use such a method use range trees or similar stuff. There are plenty implementations on the internet, so go ahead and search. Let the mighty internet inspire you!

Honestly, this all reads like premature optimisations. Just create an arraylist, throw the torche sockets in there, search through the list and compare lengthsquared on each.

Only later on if you find out that this is a performance issue do you need to do anything more…