Jump to content

  • Log In with Google      Sign In   
  • Create Account


Structuring a scene


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
3 replies to this topic

#1 KaiserJohan   Members   -  Reputation: 1126

Like
0Likes
Like

Posted 03 March 2013 - 04:26 AM

Hello,

I have made a basic scenegraph, with a Scene and SceneNodes. The Scene has a root SceneNode and each SceneNode has a parent and a number of child nodes. Each SceneNode has a transform related to its parent aswell. 

 

 

 
    

 

/* Scene definition */
    class Scene
    {
    public:
        Scene(const std::string& sceneName);
        ~Scene();


        Camera& GetSceneCamera();
        SceneNode& GetRootNode();
        const std::string& GetSceneName() const;


        bool operator==(const Scene& s1);
        bool operator==(const std::string& sceneName);


    private:
        const std::string mName;
        size_t mHashedID;
        Camera mSceneCamera;
        SceneNode mRootNode;
    };
 

 

 

/* SceneNode definition */
    class SceneNode
    {
    public:
        SceneNode(const std::string& nodeName);
        ~SceneNode();


        SceneNode* CreateChildNode(const std::string& nodeName);
        SceneNode* FindChildNode(const std::string& nodeName);
        bool DeleteChildNode(const std::string& nodeName);
        bool DeleteChildNode(SceneNode* node);


        void Scale(const Vec3& scaleVec);
        void Translate(const Vec3& translateVec);
        void Rotate(const float angle, const Vec3& rotateVec);


        void UpdateModelMatrix(const Mat4& parentModelMatrix);


        const Mat4& GetModelMatrix() const;
        const std::string& GetNodeName() const;
        const vector<SceneNode*>& GetChildNodes() const;


        bool operator==(const SceneNode& s1);
        bool operator==(const std::string& nodeName);




    private:
        const std::string mName;
        size_t mHashedID;
        vector<SceneNode*> mChildNodes;
        IMemoryAllocator& mMemoryAllocator;


        Mat4 mModelMatrix;
        Quaternion mOrientation;
        Vec3 mScale;
        Vec3 mTranslation;
    };
 

 

 
 

Now I want to start adding things like meshes (and later lights all such things), but I'm unsure how to best structure it. For example should I add components like meshes directly into the SceneNodes themselves, or should I keep them in the Scene and have them refer to a SceneNode? What is the best practice when it comes to this?

 

Also, what is an 'entity' and how is it generally used?



Sponsor:

#2 haegarr   Crossbones+   -  Reputation: 4203

Like
1Likes
Like

Posted 03 March 2013 - 06:23 AM

In the traditional sense of "scene graph" we are speaking of a "one-for-all" structure, where each and everything is pressed into this one structure. You may gather from this wording already that I'm not a fan of scene graphs ;)

An "entity" is even less well defined. An entity on the sense of the nowadays somewhat popular "component based entity system" (CES for short) is just a placeholder or identifier or sometimes a container of components, perhaps with message distribution functionality. The is no standard, and a best practice does not exist IMHO.

So, if you mean those both concepts, you are already speaking of very different things. Furthermore, in a traditional scene graph a mesh would be an own node inside the graph. When you say "storing the mesh anywhere outside the graph but in the scene and letting them refer to the scene node" it sounds to me that this is just another kind of concept. I.e. it sounds that what you call the scene graph is just a tree of FK ("parenting") dependencies, while the meshes may be organized in another way, perhaps in a spatial structure.

Being confused of what you are actually doing, I recommend to not follow the traditional scene graph but to use a couple of specialized structures to organize the scene. I personally prefer CES as one of the aforementioned specializations when it comes to structuring game entities. I further prefer the entity not being explicit, and the components being managed in sub-systems. However, it makes no sense to program a (highly) complex solution for a game with low scene complexity; so you still have to decide...

Edited by haegarr, 03 March 2013 - 06:24 AM.


#3 KaiserJohan   Members   -  Reputation: 1126

Like
0Likes
Like

Posted 03 March 2013 - 07:53 AM

I'm thinking of making the Scene somwhat like Ogre3ds SceneManager, i.e it manages the entities/lights/meshes etc alongside the scenenodes. Is there any good alternative?



#4 EWClay   Members   -  Reputation: 659

Like
1Likes
Like

Posted 03 March 2013 - 09:58 AM

I'm thinking of making the Scene somwhat like Ogre3ds SceneManager, i.e it manages the entities/lights/meshes etc alongside the scenenodes. Is there any good alternative?


Yes. The scene graph doesn't need to be explicit. All you need is the ability to set parent transformations and this can be handled by the entity system. All the renderer needs is the final transformation of the mesh. It shouldn't care about relationships between game objects.

The renderer can use whatever structure you like internally, but there's no need to expose it because what's most efficient for rendering is not necessarily the best for scene management.




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