'Load a series of 3D models using OpenGL (Streaming 3D model?)
My application produces a stream of 3D models, say in .obj format. Each model is a 3D mesh with texture. I wonder how I can display/visualize a stream of 3D models using OpenGL. My thought is just to load the 3D models sequentially, but I am not sure how to achieve that.
Solution 1:[1]
You will need code for loading a 3D model from obj file. Either write it yourself, or find an implementation online. Search for e.g. "obj model parsing c++".
For the specification of the obj format you can have a look here: https://en.wikipedia.org/wiki/Wavefront_.obj_file
Each model should probably be loaded into an instance of a class like this:
class Model { public: bool LoadObj(std::string const & filename); using VertexPosition = std::array<float, 3>; std::vector<VertexPosition> const & GetVerticesPositions(); using VertexColor = std::array<unsigned char, 4>; std::vector<VertexColor> const & GetVerticesColors(); using FaceIndices = std::array<int, 3>; std::vector<FaceIndices> const & GetFacesIndices(); using VertexUV = std::array<float, 2>; std::vector<VertexUV> const & GetVerticesUVs(); int GetTextureWidth(); int GetTextureHeight(); unsigned char const * GetTextureData(); // etc... };
All the models can be stored in a
std::vector<Model>.Your application should have a timer for rendering. Each time you need to render a frame you need to determine which model to render, based on the time passed and frames-per-second. When you pick a model, you can render it using the interface of
Model.If you have many models and do not want to require too much memory, you can do a delay load (load from file only when yo need it). This technique requires to load some frames in advance, on a separate thread (i.e. buffering). Otherwise your playing will not be smooth as you will need to wait to load the obj file which can take some time.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
