• Advertisement
Sign in to follow this  

How do I save a scene?

This topic is 3515 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey all, I'm currently working on a game/engine, just for educational sake, and I've come to a hurdle, I want to be able to save and load scenes from a file, I dont care if it is ascii or binary, but as I hope you can see from the scene class below is that the scene has a list of all the meshes, and textures, and a list of "mesh nodes", with each mesh node containing a pointer to a mesh to be rendered, as well as a pointer to the texture to use, and its position and rotation. My main problem is that obviously a dump of a pointer is not going to mean anything when it is reloaded. I've read one of the articles in the enginuity series about data serialization, but it seamed overly complicated, and I was looking at a smaller solution. my scene class...
class Scene
    Scene(Mouse *pMouse, Keyboard *pKeyboard);
    Mesh *addMesh(const char *pFileName);
    void removeMesh(Mesh *pMesh);
    MeshNode *addMeshNode();
    void removeMeshNode(MeshNode *pMeshNode);
    Texture *addTexture(const char *pFileName);
    void removeTexture(Texture *pTexture);

    Camera *setCamera(Vector3f pPosition, float pYaw, float pPitch);
    void update();
    void beginScene();
    void endScene();
    void render();
    void removeAll();
    bool saveScene(const char *pFileName);
    bool loadScene(const char *pFileName);
    Camera mCamera;
    std::list<Mesh *> mMesh;
    std::list<MeshNode *> mMeshNode;
    std::list<Texture *> mTexture;
    Keyboard *mKeyboard;
    Mouse *mMouse;

how I've been creating my scenes so far...
Mesh *mesh = sceneManager->addMesh("data/spaceship.3ds");
Texture *texture = sceneManager->addTexture("data/spaceshiptexture.bmp");

MeshNode *meshNode = sceneManager->addMeshNode();
meshNode->setPosition(Vector3f(-100.0f, 0.0f, 0.0f));
meshNode->setRotation(Vector3f(0.0f, 0.0f, -10.0f));

Thanks in advance

Share this post

Link to post
Share on other sites
Thanks Gage64, I'm reading through the second link that you posted, I'll post what I come up with.

Share this post

Link to post
Share on other sites
I've started saving my scenes in human-readable XML files. Scene graphs translate to XML very nicely.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement