Quantcast
Channel: GameDev.net
Viewing all articles
Browse latest Browse all 17825

Mesh data and flexible data structure

$
0
0
Hi all, I'm struggling with the following workflow I have in my engine: 1. Prepare mesh in my asset tool, resulting in a nicely organized/ stripped chunk of mesh data (in a binary file) 2. Load the binary file with meshdata (deserialization) 3. Create a mesh object with it's GPU buffers etc. Currently I've split the deserialization from the mesh class, because I think it's a good idea to have all binary IO/ serealization code separated from the logics that use the data. When something has to change on the IO side, I can simply change that piece of code. The downside of this, is that steps 2 and 3 need some intermediate data structure, where the mesh data is stored, and which is then used by the mesh class for creating buffers, setting properties etc. Consider this struct: struct MESHDATA { std::vector<Vertex::PosNormTanTex> VerticesA; std::vector<uint> Indices; uint NrChunks; PHYSMATH::CR_BV BoundingVolume; std::vector<SUBMESH> Chunks; MESHDATA() : NrChunks(0) { } }; This all works fine as long as the mesh's vertices have a Position, Normal, Tangent and texcoord. One solution would be to give the meshdata struct a vector of the 'maxxed out' vertex type (with all possible elements), and then only store the elements that are available (leaving the rest empty). This would work, but then right before I create the GPU vertexbuffer, I would need to copy over all data to a vector of the right struct, before I create the buffer. My goal is to prevent this additional copy of all vertices on the CPU side. The only solution I've come up with so far, is this: struct MESHDATA { std::vector<Vertex::PosNormTanTex> VerticesA; std::vector<Vertex::PosNormCol> VerticesB; std::vector<Vertex::PosNormCol> .... ; // for all vertex types Vertex::Type VertexType; // used to select the applicable std::vector std::vector<uint> Indices; uint NrChunks; PHYSMATH::CR_BV BoundingVolume; std::vector<SUBMESH> Chunks; MESHDATA() : VertexType(Vertex::Type::UNKNOWN), NrChunks(0) { } }; I know this works, but I was wondering if someone has better thoughts on how to tackle this. The only downside here, I think, is having a bunch of unused std::vector's, but this doesn't really has to be an issue since it's only temporary/ on the stack when I load up meshes. Note; I understand how I can determine the inputlayout/ vertexlayout, it's just that I'm looking for a way to store the data in the intermediate datastructure, and being able to use the data directly for sending it to the GPU (in the right format/ struct). Any input is appreciated.

Viewing all articles
Browse latest Browse all 17825

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>