Skip to main content
gamedev.net
🔒 Locked 🎮 Unity

Scene Graph

Started by Kasya Oct 1, 2008 at 6:11 AM 6 replies 1.1k views
Original Post
Kasya
Kasya
Hello, I want to write a scene graph. I read lots of resources about Scene Graph. And i know how to implement it. But when people write something about Nodes, like i really don't understand what is it. Is that a part of Scene Graph? And my second question is: For example i wrote a code:


class SceneGraph {/* Code Inside */};

class SomeNode1 {
/* If my previous question is right */ 
/* Code inside */ 
}


For using SceneGraph in my Application i need to do something like that:


SceneGraph * scene = new SceneGraph;
SomeNode1 * car = new SomeNode1;
SomeNode2 * node2 = new SomeNode2;
SomeNode3 * node3 = new SomeNode3;

void CApp::Init() {

scene->AddChild(node1);
scene->AddChild(node2);
scene->AddChild(node3);

}

void CApp::Render() {

scene->Update();

//Example for using it Dynamic:

if(i_destroyed_the_car) {

scene->DeleteNode(car);

}

if(i_create_the_car) {

scene->AddNode(car);

}


}

void CApp::Release() {

scene->ReleaseAllChildren();

}


? And if i am right about these questions, nodes need to have position and orientation right (excluding SceneGraph class itself) ? Thanks, Kasya
dmatter
dmatter
Quote:
Original post by Kasya
Hello,
I want to write a scene graph. I read lots of resources about Scene Graph. And i know how to implement it. But when people write something about Nodes, like i really don't understand what is it. Is that a part of Scene Graph?
Putting scene-graphs aside, take a minute to read the informal description about graphs from Wikipedia. Now a scene-graph is merely a graph like any other so all the terminology still applies. There are different types of graphs, in fact scene-graphs may often a type of Directed Acyclic Graph.

Quote:
And my second question is:

For example i wrote a code:

*** Source Snippet Removed ***

For using SceneGraph in my Application i need to do something like that:

*** Source Snippet Removed ***

?
Sorry, I don't really follow what your question is.

Quote:
And if i am right about these questions, nodes need to have position and orientation right (excluding SceneGraph class itself) ?
It depends on what the node represents. If it represent a spatial entity then that entity will probably need a position and orientation, yes. There is nothing that says every node must represent objects in space, e.g. a ScriptNode does not have a spatial representation.
mmakrzem
mmakrzem
Nodes are just "points" found inside of the graph.

They can be used to represent many different things. In the scene graph that I developed I have the following nodes:

transform - contains position/rotation information
material - contains color information
texture - contains texture data
textureTransform - transformation specific to textures
shape - general geometry node used to render to the screen.
Kasya
Kasya
@dmatter & @mmakrzem:

Quote:
Sorry, I don't really follow what your question is.


My question was "I need to have one SceneGraph and nodes right". But i just asked my uncle about Scene Graphs and he told me about what i wanted to know.

For my understanding:

There must be one Scene Graph and and Nodes which are attached to it. And i need to Render Scene Graph like that:

void SceneGraph::Render() {    for(_uint i = 0; i < m_children.size(); i++) m_children->Render();}


Nodes can be anything:
Material, Texture, Geometry, Camera, Terrain, Animation, Skeleton, Physics, Particle etc. etc.

Is my understanding right?

Thanks,
Kasya
MJP
MJP
Quote:
Original post by Kasya
There must be one Scene Graph


There's nothing at all wrong with multiple scene graphs. In fact...I've never done it any other way. Think about it: do all of your sub-systems need your scene data organized in the same way? For example your rendering sub-system probably wants things organized in such a way that state changes are minimized. Is this necessarily going to correspond to what's optimal for your collision detection? Probably not at all. After all for collision detection it will location and size that's important, and that will have absolutely nothing to do with whatever arbitrary render states your rendering sub-system cares about.



swiftcoder
swiftcoder
Quote:
Original post by Kasya
There must be one Scene Graph and and Nodes which are attached to it. And i need to Render Scene Graph like that:
void SceneGraph::Render() {    for(_uint i = 0; i < m_children.size(); i++) m_children->Render();}
A scene graph is meant to be a graph - what you have there is a list. While a list is technically a restricted form of a graph, a scene graph is typically hierarchical - i.e. nodes have children of their own.
Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]
haegarr
haegarr
Scene graphs are a ever lasting issue... :)

Quote:
Original post by Kasya
Nodes can be anything:
Material, Texture, Geometry, Camera, Terrain, Animation, Skeleton, Physics, Particle etc. etc.

The problem with this thinking is how particular nodes are used sensefully by their respective parental node. The main issues are: (1) Does it make sense to be able to plug in any kind of node into any (group) kind of node? (2) How is the role of a node determined if several nodes of the same type are plugged in?

E.g. think of the Texture node. A combination may be to plug a Texture node into a Geometry node with the purpose of defining the diffuse material color. Err, wait, "material color" hints at plugging the Texture better into the Material node. Textures plugged into Geometry could instead be bump maps, or normal maps, or displacement maps, or ... And the Material can work with diffuse texturing, and reflection texturing, and ... So it isn't enough to drop the Texture somewhere. Moreover, textures need to be mapped. And it is possible to map several textures even for the same purpose (e.g. texture splatting). So, how do you ensure that the Texture is used in the intended manner? A raw scene graph is not suitable to define roles of their nodes!

Moreover, a Texture is IMHO a Resource and as such not suitable to appear in a scene graph at all. A TextureMapping may be more suited. Similarly, a Particle should be part of a ParticleSystem. Making a Particle a "heavy weight" scene graph node would probably be too costly. Other "inner" hierarchies may be more clear. E.g. the skeleton's bone hierarchy, or the Geometry's (sub)meshes. These are hierarchies by their own, too.

Next, Animation is a time based thing (Kasya, you remember that I mentioned the Timeline in the animation blending thread?), Geometry (and many others) a spatial thing. Some nodes are visible, others not (e.g. Camera, Animation, Skeleton), and other are only visible in combination (e.g. Material combined with Geometry).

So, what does your SceneGraph express? Is it a logical description, a spatial description, a temporal description, or all at once? Is it meant to drive graphics rendering, culling, collision detection, all at once?

This is the well known discussion of omni-potent scene graphs vs. multiple but specialized management structures. Be sure to understand the implications before deciding on the one or other kind.

Just my 2 Euro-Cent.
Kasya
Kasya
@swiftcoder

Quote:
A scene graph is meant to be a graph - what you have there is a list. While a list is technically a restricted form of a graph, a scene graph is typically hierarchical - i.e. nodes have children of their own.


its hierarchial because i used here

class CSceneGraph {public://c'tors and destructorsvoid AddChild(CSceneGraph *node) {m_children.push_back(node);}virtual void Update() {for(uint i=0; i<m_children.size(); i++) {m_children->Update();}}protected:std::vector<CSceneGraph *> m_children;};//If i will have a node:class CNode : public CSceneGraph {public:void Update() {//Do something}};


m_children list contains SceneGraphs then that means they have children too. But i think we don't need hierarchy for every node. I mean for example if i use CameraNode where i'll use Hierarchy. But when i use Skeleton System it has hierarchy (parent-child bones). Am i right about that?

@haegarr

Quote:
So, what does your SceneGraph express? Is it a logical description, a spatial description, a temporal description, or all at once? Is it meant to drive graphics rendering, culling, collision detection, all at once?


I haven't finished it. But i think its better to use SceneGraphs in once. Then i'll just go with all at once method.

Thanks,
Kasya

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.