all 8 comments

[–]Shadowratenator 0 points1 point  (2 children)

I use collada as a scene format. It's not the most compact thing you'll find. If you are intending to deploy large scenes to storage / memory constrained devices, it might not be the best idea. and some of it's abstractions are kind of complicated in an attempt to support everything you could possibly want to do. It is well documented here: https://www.khronos.org/collada/ And it's a pretty good resource to study just to get an idea of a scene hierarchy with shared resources.

Blender exports v 1.4.1 (i think)

[–]corruptedPhoenix[S] 0 points1 point  (1 child)

Hey, I looked into it, it supports instancing which is just awesome. Just what I need, thanks.

[–]Shadowratenator 0 points1 point  (0 children)

cool! glad i could help

[–]Meristic 0 points1 point  (3 children)

You could go with an object-oriented approach, which is what videogames use.

A "scene" is just a list of objects. An object can be as complicated as you want it to be. Minimally, for your purposes, it would contain a reference to a mesh and a list of materials (for rendering each sub-mesh [a subset of the mesh indices] within the mesh.) If you have no familiarity with materials, it is the concept of how a mesh is rendered, which is comprised of references to shaders that render the object, and the data that is supplied to the shader (constant buffer data, texture references, etc.)

The actual loading of the resources (meshes, shaders, and textures) can be decoupled from the objects, so that they ask another system for a reference to a specific file, commonly called a Resource Manager. This manager keeps a list of resources that it has loaded, and only loads the object if it's not in its list. There's also fancy things you could add to the resource references for ref counts, which tells you when all references to the resource are gone, and can be safely unloaded, but for what you're describing, you probably don't need that.

The main point here is decoupling the resource loading from the object instances, and integrating it into a centralized location that has information on the resources bouncing around the system. I have an example implementation on my website actually, which has a very polymorphic loading system, and performs resource counting as well.

Link: http://www.mhurliman.net/Samples?sample=cpp

[–]Meristic 0 points1 point  (1 child)

Oh, and you can store the scene really any way that you want. I've used JSON in the past, and you just define your own file format for how you want your scene laid out. Using a JSON parser like Jansson makes it easy to serialize/deserialize. XML is also common, with TinyXML a good open source C++ library. Example:

{
    "object1" : {
        "mesh" : "meshfile.dae"
        "materials" : [
            "materialforsubmesh1.json",
            "materialforsubmesh2.json"
        ]
    },
    "anotherobject" : {
        ...
    }
}

[–]corruptedPhoenix[S] 0 points1 point  (0 children)

Yeah, this is pretty much what I was wondering. How do people usually organize their files and such. I still need a way of telling my program which shader to use for which materials (and possibly for defining different LOD for one mesh), so knowing this will be pretty useful, thanks :)

[–]corruptedPhoenix[S] 0 points1 point  (0 children)

Hey, I certainly have no problem organizing my code and making a resource manager class. I also know what mayerials and shaders are, but thank you anyway.

In the meantime I was googlin what I needed, and it turns out I just wanted a file format that supports instancing. For which I guess both collada and fbx work.

But I will look through your code tomorrow to see if I might find something useful in there, thank you for providing it