3DSFile atOpenGLRead in and display
learnedBlenderAfter that, I really want to load my own model into my own program, so I consider the more common ones.3DSfile format. This time I will try3DSFile loaded by myselfOpenGLThe program is displayed.

Demo download address:Here
Source code download address:Here
I first found a lot of ready-made loads.3DSThe format example, found that only one program is runable, so take the source code of this program for research. Also check some foreign format documentation, combinedBlenderinOutlinerIn the organization of the data, I began to understand3DSHow the format is organized.
3DSThe file is binary and isAutodeskPrivate format, many compatible software is read according to the content of the known crack, so different software will have different effects on it. Experts recommend only exporting the mesh model to3DSBecause the light source and camera cannot be saved.
3DSThere is a kind of "block" inside the file (chunk"" structure, used to illustrate a variety of objects in a three-dimensional scene. In fact, the "block" andwavThe blocks in the file are almost the same, all contain the header (header) and content (content)。3DSThe header of the block in it containsID(occupies two bytes) and length (four bytes), where the length is the entire length of the block. And the content length of the block is the entire length of the block minus6byte.
As an example, the main blockIDYes0x4D4D, we can do this: read the blockIDTwo bytes, then read the length of the four-byte block (setlength), so we know that we still need to read at most (length- 6) bytes.
3DSThe data organization structure is tree-like, and each node in the tree is a block structure. Because of the similarity of each level in the tree, according to the knowledge of traversing the tree in the data structure, we can write a depth-first search algorithm and use recursive Thought to complete.
3DSLeaf nodes in a tree usually have a specific resolution method. For example, read the vertices (IDYes0x4110), asking us to read the number of vertices of two bytes firstnRecyclingnRead each vertexxyzcoordinate.
3DSThe coordinate system in the fileOpenGLwithDirect3DDifferent,XYThe axis determines the horizontal plane,ZThe axis is vertical. In the early days of parsing, I also used all of its vertices.XYZValues are replaced by swapping and de-reversing, but a model matrix needs to be parsed later. If only the axis is replaced without replacing the model matrix, then the model formed after parsing will be misaligned. This can become very troublesome. Even before you can modify the model matrix3×3Partly to achieve the goal, I still think that when modeling, by converting the coordinate system of the model intoDirect3DLeft-handed coordinate system orOpenGLThe right-handed coordinate system will be better, and some unnecessary conversion work will be eliminated.
After parsing3DSI need to display it after the file, unfortunately, I am currently usingBlenderExported3DSNo lights and cameras, so there is no effectBlenderEdited so well in the software. In addition,3DSThe default primitive is a triangle, which means that polygons are subdivided into triangles when they are exported. Thus, inOpenGLDirect designationglBegin(GL_TRIANGLES );Enough.
Here is what I am atBlenderEdited image:

The figure below is the result of the program.

Reprinted: Since opengl does not originally support this model, importing is a hassle, but there are many models in this format. This time I especially want to use it when doing major graphics homewor...
I have been writing a thesis for a while, and I haven't studied programming for a long time. I suddenly feel that I can't start. I opened the code I wrote before to practice my hands, and recorded it ...
This paper describes displayed STL model files with OpenGL. STL model file:Android OpenGL STL Explanation Android OpenGL junior developers:Android OpenGL GLSurfaceView of use to create a 3D rotating g...
Although the title says to display any 3D file, this article mainly uses the STL format file as an example. The other formats are essentially the same, only the code of the parsing part is different. ...
First, configure OpenGL and VS2015 Reference: https://blog.csdn.net/qq_24990189/Article/details/89631111 Second, all the code:...
In the project, there is a task that requires importing the model built by SOLIDWORKS into Opengl to realize the visualization of the operating equipment. The following is the specific implementation ...
reads and displays each line of the file...