3DS File on Spinach website Development OpenGL read-in and display

Source: Internet
Author: User

The development of Spinach Web site dsluntan.com vx:17061863513 after the blender, I would like to design a model to load their own program, so consider the more common 3DS file format. This attempts to load the 3DS file into its own OpenGL program and display it.

We first looked at many examples of ready-to-load 3DS formats, and found that only one program could be run, so we took the program's source code for research. While looking at some foreign format documentation, combined with the organization of data in Outliner in Blender, I began to understand how the 3DS format was organized.

3DS files are binary, and are Autodesk private format, many compatible software is based on known cracked content to read, so different software for it to read the effect will be different, experts recommend only to export mesh model to 3DS, because the light source and camera can not be saved.

The interior of the 3DS file is called a "block (chunk)" structure used to illustrate the various objects in a three-dimensional scene. In fact, the "block" here is similar to the block in the WAV file, which contains the header and content. The head of a block in 3DS contains an ID (two bytes) and a length (four bytes), where the length is the entire length of the block. The content length of the block minus 6 bytes for the entire length of the block.

For example, the ID of the main block is 0x4d4d, and we can do this: read the Block ID two bytes, then read the length of the four-byte block (set to long), so that we know the maximum number of bytes to read (length-6).

The data organization structure in 3DS is tree, and each node in the tree is a block structure, because of the similarity of each level in the tree, we can write the depth-first search algorithm according to the knowledge of the data structure, and use recursive idea to complete.

Leaf nodes in 3DS trees often have a specific parsing method. For example, reading the vertex (ID is 0x4110) requires that we first read the number of vertices of two bytes n, and then loop n times to read the XYZ coordinates of each vertex.

The coordinate system within the 3DS file differs from OpenGL and Direct3D, the XY axis determines the horizontal plane, and the z axis is vertical. At the beginning of the parsing, I also used the XYZ value of all its vertices to replace the axes by swapping and de-inverting, but then we need to parse a model matrix, if we just replace the axes and not replace the model matrix, then the parsed model will appear dislocation. This can become very troublesome. Even if the goal can be achieved by modifying the first 3x3 part of the model matrix, I still feel that modeling is better by converting the model's coordinate system to Direct3D's left-handed or OpenGL's right-hand coordinate system, while also eliminating unnecessary conversion work.

After parsing the 3DS file, you need to show it, unfortunately, I am currently using the blender exported 3DS does not contain lights and cameras, so the effect is not as good as the editor in the Blender software. In addition, the default entity in 3DS is a triangle, which means that polygon elements are broken down into triangles to save when exporting. Therefore, the direct designation of Glbegin (Gl_triangles) in OpenGL is fine.

3DS File on Spinach website Development OpenGL read-in and display

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.