Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Scene Graph Root Node


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
9 replies to this topic

#1 Alundra   Members   -  Reputation: 917

Like
0Likes
Like

Posted 08 December 2012 - 09:55 AM

Hi,
When a scene graph is implemented, the most of time there is a root node.
Is the root node really needed ?
Is it bad to have an array of node with parent to NULL who store children array pointer ?

Thanks

Edited by Alundra, 08 December 2012 - 09:56 AM.


Sponsor:

#2 wqking   Members   -  Reputation: 756

Like
0Likes
Like

Posted 08 December 2012 - 10:17 AM

The good of a root node is you can apply any algorithm on a node to the root, you can not do it for an array.
For example, assume you have a function to find a special child node, you can call it on the root.

http://www.cpgf.org/
cpgf library -- free C++ open source library for reflection, serialization, script binding, callbacks, and meta data for OpenGL Box2D, SFML and Irrlicht.
v1.5.5 was released. Now supports tween and timeline for ease animation.


#3 kunos   Crossbones+   -  Reputation: 2207

Like
2Likes
Like

Posted 08 December 2012 - 10:23 AM

Is it bad to have an array of node with parent to NULL who store children array pointer ?


how is this different from having a root node that, incidentally, already has an array to children nodes?

anyway.. ya,it can be done if you really like duplicating code and functionality around for no good reason whatsoever.

Edited by kunos, 08 December 2012 - 10:24 AM.

Stefano Casillo
Lead Programmer
TWITTER: @KunosStefano
AssettoCorsa - netKar PRO - Kunos Simulazioni

#4 Jake Rivers   Members   -  Reputation: 324

Like
0Likes
Like

Posted 08 December 2012 - 10:58 AM

The difference is merely a conceptual issue... the only difference is that your application would be the "root", instead of having a well defined struct/class..

programatically there would be no difference, but it's cleaner and more intuitive for other programmers to have a root node from which everything "spawns"...

most of the time you will have to take desisions between two options which both work ok (and there's no performance gain/loss between them), but with the question of which way would you leave a be better experience to the people who might be using your code.. ;)
"lots of shoulddas, coulddas, woulddas in the air, thinking about things they shouldda couldda wouldda donne, however all those shoulddas coulddas woulddas ran away when they saw the little did to come"

#5 Radikalizm   Crossbones+   -  Reputation: 2973

Like
0Likes
Like

Posted 08 December 2012 - 10:58 AM

This depends on what kind of behaviour you want to get out of your scene graph.
In a lot of cases where a hierarchical scene system is implemented the word 'graph' is actually a misnomer, as most of those implementations are tree structures (since it doesn't really make sense in most cases to have cycles in a scene graph unless you're doing some really funky stuff), and to build a tree structure you need a root node.

Of course you could store multiple trees, which is basically what you're presenting. If you store parentless nodes with children in an array you're basically building a forest, and each of these nodes will become roots for their own trees in that forest.
So if you want your scene to be divided into different independent trees, then it isn't necessarily 'bad' to store your different tree roots in an array like you said.

However, the fact that you're trying to do something like this should trigger an alarm-bell. You're trying to 'break the rules' of your chosen data structure to get some kind of different behaviour, which basically tells me that the data structure you've initially chosen (being a scene tree) isn't a good choice for the problem you're trying to solve.

Is there any reason why you need hierarchy within your scene as a default rule, rather than as an exceptional case?
I think a lot of people on these forums will agree with me that the concept of using just a scene tree/graph is starting to get outdated, as the concept of having a hierarchy between objects just plain doesn't make sense in a lot of cases.

Different systems will need different representations of your scene, a physics engine might need to have some sort of partitioned scene structure containing shape and transformation data so it can optimize its collision detection algorithms, while a rendering engine just needs a list of visual data and transformations to crunch. Culling algorithms might need another partitioned structure containing bounding volumes, which again is completely different from what the rendering and physics engine need.
I could go on like this for a while, but I think my point should be somewhat clear by now.

Basically what I'm trying to say is that it doesn't take all too long for the "stick it all in a tree" approach to start breaking down, so if you're at the point where you're trying to somewhat break free from this approach you should maybe try to rethink how you want to handle your scene entirely instead of trying to bend and twist your current approach in ways it wasn't designed for.

I gets all your texture budgets!


#6 Matias Goldberg   Crossbones+   -  Reputation: 3694

Like
1Likes
Like

Posted 08 December 2012 - 01:12 PM

It's a conceptual difference, but there's also subtle but important details:

1. A node that is not part of the root node (an orphan node) is not in the scene and hence should not be rendered (this is important when Parent nodes don't own the memory of their children, but rather just have a pointer to it).


2. Consistency. If you create a new node you should call sceneGraph->createNode( pos, rot )->attachObject( myObj );
But if you're creating a child, you should call parent->createChildNode()->attachObject( myObj );
or call parent->addChild( myChild ); after creating it with sceneGraph::createNode (two ways of doing the same, and in both ways the code for creating a child is different from creating a parent-less node)

However, if there is a root node, your code is always the same:
parent->createChildNode()->attachObject( myObj );

Just feed the proper parent (which could be the root node) and you get a consistent behavior.


3. Many implementations are tree-based, like Radikalizm said. And trees start with a root node.

Having this said, you're not forced to have one root node. But I'm just answering your question (why so many implementations start from a root node). It's not bad to have an array of objects like you said. Particularly, I think reason #2 is a very good reason to use a root node for writing clean code. Reason #1 is just a convention & conceptual. Reason #3 depends on the implementation, it also depends on the literature being consulted (Which is often about having a root node, because the problem to solve is abstract, not specific towards graphics & scene management).

Cheers
Dark Sylinc

#7 Alundra   Members   -  Reputation: 917

Like
0Likes
Like

Posted 08 December 2012 - 05:54 PM

Using a tree, recursive function is used to render the scene and find an object by name.
Is it bad to use recursive function for these operations ?

Thanks

#8 Bacterius   Crossbones+   -  Reputation: 9261

Like
2Likes
Like

Posted 08 December 2012 - 06:17 PM

Using a tree, recursive function is used to render the scene and find an object by name.
Is it bad to use recursive function for these operations ?

Thanks

Trees lend themselves well to recursive algorithms, which makes implementation easier, however going recursive has a few disadvantages:
- it is often a bit slower than an iterative algorithm where you maintain your own stack
- because it is stack-based, it may not be easily implemented on platforms where a stack isn't readily available (e.g. GPU's)

On the other hand, non-recursive approaches can be a real pain to get right.

The slowsort algorithm is a perfect illustration of the multiply and surrender paradigm, which is perhaps the single most important paradigm in the development of reluctant algorithms. The basic multiply and surrender strategy consists in replacing the problem at hand by two or more subproblems, each slightly simpler than the original, and continue multiplying subproblems and subsubproblems recursively in this fashion as long as possible. At some point the subproblems will all become so simple that their solution can no longer be postponed, and we will have to surrender. Experience shows that, in most cases, by the time this point is reached the total work will be substantially higher than what could have been wasted by a more direct approach.

 

- Pessimal Algorithms and Simplexity Analysis


#9 JohnnyCode   Members   -  Reputation: 290

Like
0Likes
Like

Posted 08 December 2012 - 06:40 PM

in my case, I have implemented dynamic scene with world register, a tree. If you have all root node, you can implement special exeptional logic to it, for example, if you scan register as what nodes to remove from game scene based on distance, you will not examine the root, for if player get distant from root too much, it would have to disappear and remove whole subtree (everything). You should take care as what you implement , but I would advice you to use unique root, for you can get catching your hair if you implement multiple nodes, as you develop aplication further, but I cannot think of how you could get screwed if you implement an all root.

#10 Shannon Barber   Moderators   -  Reputation: 1390

Like
0Likes
Like

Posted 18 December 2012 - 09:27 PM

That's the start of a "b-tree". You still have a root-node, it's just an array instead of one node.
If you make all your nodes arrays then it's a b-tree.
For many applications b-trees are a superior design. They offer the recursive power of trees and the cache-coherency of arrays.

Edited by Shannon Barber, 18 December 2012 - 09:30 PM.

- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS