3DS file structure

Source: Internet
Author: User

Http://hi.baidu.com/yiyibeibei/item/928b2660bea9652669105b82

 

0x4d4d is the file header, and its size is the size of the entire file.

There are also two main blocks: 3D editing blocks and key frame blocks:
0x3d3d: a 3D editing block that describes the data of a 3D object. 3D objects are in this place.
0xb000: Key Frame block, which describes the key frame data.

There are some data blocks after a major block. These should be other data that is allowed within the main block (see the chart ).
0x3d3d child blocks:
Id description
0100 Configuration
1100 unknown
1200 background color
1201 unknown
1300 unknown
1400 unknown
1420 unknown
1450 unknown
1500 unknown
2100 environment colors
2200 fog?
2201 fog?
2210 fog?
2300 unknown
3000 unknown
3d3e configuration editing Block
4000 object data blocks
AFFF material list

3d3e configuration editing block:
Id description
7001 view indicator
7011 view definition (Type 2)
7012 view definition (type 1)
7020 view definition (Type 3)

There are a lot of abnormal data in the 3d3e block, of which only 7020 are important. This block defines four active views. Assume thatProgramThe editing program configuration contains 5 7020 and 5 7011. However, in fact, only the first four 7020 blocks have an impact on the user's view appearance. The others only contain some additional information. The 6, 7 bytes of the block indicate the view type, valid ID, and corresponding view as follows:
Id description
Top 0001
Bottom 0002
0003 left
0004 right
Before 0005
After 0006
0007 users
FFFF camera
0009 Light Source
0010 invalid

 

AFFF material block
Defines the material. The sub-block a000 defines the material name. The material name is an ascll character, ending with 0x00.
Generally, we use the diffuse attribute defined textures.
Main3ds (0x4d4d)
|
+ -- Edit3ds (0x3d3d)
|
| + -- Edit_material (0 xafff)
| + -- 0xa000 material name, which is a string ending with null and unique in this file

|, You can use it to mark the material object.
+ -- 0xa010 ambiet Block
+ -- 0xa020 diffuse Block
+ -- 0xa030 specular Block
+ -- 0xa040 shininess Block
+ -- 0xa100 defines the material type (such as phong and flat)
+ -- 0xa200 texture block 1. The texture defined by diffuse is stored in this block.
+ -- 0xa300 (string) Another NULL terminated string -- Name of the texture file,

| Note: the file name here does not contain a path.
+ -- 0xa351 (Word) Texture option block, which is 1-9 Characters meaningful according to the MLI document.

| Do not represent attributes of several textures (such as tiling or mirror)
| This part can be ignored as long as you pay attention to it during modeling.

| For example, mirror can be solved by replacing two tiling values with negative values.
+ -- 0xa353 (float) is not clear about the meaning of this component.
+ -- Tiling value of 0xa354 (float) u
+ -- Tiling value in the direction of 0xa356 (float) V
+ -- 0xa358 (float) U direction Offset Value
+ -- Offset value in the direction of 0xa35a (float) v. Note that the value of voffset read here is the same as that of 3DS.

| The value displayed in the table is a different symbol.
+ -- 0 x C (float 4 bytes) W direction rotate value, the same is also a different symbol.

 

4000 is an object description block.

The beginning of the block is a string ending with 0, which describes the name of the object. Remember that an object is not only an object, but also a light source or a camera:
Id description
4010 unknown
4012 shadow?
4100 Triangle List
4600 Light Source
4700 camera

 

4100 subblock in the Triangle List: Grid Model Information
Main3ds (0x4d4d)
|
+-Edit3ds (0x3d3d)
|
| + -- Edit_object (0X4000)
|
| + -- Obj_trimesh (0x4100)
| (Number of bytes) 2 3 3 3 3 3 3 3
| + -- Tri_vertexl (0x4110) vertex list [num, X, Y, Z, x, y, z ......]
| + -- Tri_vertexoptions (0x4111) vertex options
|

| + -- Tri_mappingcoors (0x4140) texture coordinate [num, U, V, U, V ......]
| + -- Tri_mappingstandard (0x4170) Standard ing

| + -- Tri_facel1 (0x4120) surface list
| + -- Tri_smooth (0x4150) plane smoothing Group
| + -- Tri_material (0x4130) surface material
| + -- Tri_trmatrix (0x4160) translation matrix
| + -- Tri_visible (0x4165) object visibility

 

The data in the 4110 vertex list block is as follows:
Data type size name
Ushort 2-byte vertex count
Float 4-byte X coordinate
Float 4-byte y coordinate
Float 4-byte zcoordinate
X, Y, and Z always repeat the number of vertices, so that all vertices are obtained.

 

4111 vertex option block:
This block is composed of integers. The first integer indicates the number of vertices, and each vertex is represented by an integer. 0 ~ 7, 11 ~ 12-bit affects object visibility, 8-bit ~ 10 digits are random information, 13 ~ 15 digits indicate whether the vertex is selected in a selection set. This block is not very important. Even if this block is lost, 3DS can still load the file correctly.

4120 area list block:
data type size name
unsigned short 2-byte number
index of unsigned short 2-byte Vertex a
index of unsigned short 2-byte vertex B
index of unsigned short 2-byte vertex C
unsigned short 2-byte Information
Vertex, b, C, and the information repeat several times to obtain all the faces. The meaning of the area information is as follows:
the order of digits
1. If it is a-> C, it is 1.
2 BC edge order. If it is B-> C, it is 1.
order of the 3 AB edge. If it is a-> B, it is 1.
4 ing
5 not used
6. above
7. above
8. above
9. above
10. Chaos
11 chaos
12 0
13 0
14. Whether to be selected in select set 3
15. Whether to be selected in select set 2
16. Whether to be selected set 1 Selected

 

4130 surface material blocks:
Each surface material block starts with a NULL terminated string, followed by a number indicating the number of surfaces using the material (2 bytes ). The following table stores the indexes of these indexes. Each index contains 2 bytes.

 

4140 texture ing block:
The first two bytes indicate the number of vertices, and then define the texture coordinates of two floating point numbers for each vertex. That is to say, if the texture of a vertex is mapped to the center of the texture, the coordinates are (0.5, 0.5 ).

 

4150 smooth block (Translator: I do not know the usefulness of this block so far ......) :
The number of faces multiplied by four bytes, that is, each data is a 4-byte integer. The N number indicates whether the surface belongs to the N smoothing group.

 

4160 translation matrix block:
The three floating point numbers at the beginning define the position of the object's local coordinates in the absolute coordinate, and the last three floating point numbers define the local center of the object.

 

4170 standard ing block (Translator: I do not know the usefulness of this block so far ......) :
The first two bytes indicate the ing type: 0 indicating plane ing or specified ing; 1: cylindrical ing; 2: ball ing. Then, 21 floating point numbers are used to describe the ing.

 

4600 light source block:
Three floating point numbers (12 bytes in total) are used to describe the X, Y, and zcoordinate positions of the light source. The following data blocks are used:
Id description
0010 RGB color
0011 24-digit Color Block
4610 this light source is a spotlight
A boolean value of 4620 indicates the validity of the light source.

Among them, 4610 pieces of data:
The three floating point numbers at the beginning indicate the direction (x, y, z) pointed by the spotlight ). The next floating point number represents the hotspot. The last floating point number represents divergence (TRANSLATOR: It seems to be the angle of concentration ).

0010 RGB Color Block:
Three floating point numbers are used to represent the R, G, and B colors of an object.

0011 24-digit Color Block:
The R, G, and B colors of an object are described in three bytes ).

 

4700 camera blocks:
The three floating point numbers at the beginning represent the camera position (x, y, z), and the three floating point numbers in the middle represent the camera's position (x, y, z ), the next floating point number represents the Rotation Angle of the camera ......), The last floating point number represents the camera's lens angle ).

 

L3DSFile structure

 

A 3DS file contains a series of information used to describe all the details of a 3D scene consisting of one or more objects. A 3DS file contains a series of chunks. So what are included in these blocks? It is all information that needs to be described in the scenario: the name of each object, vertex coordinates, ing coordinates, polygon list, surface color, animation key frames, Etc...

 

These chunks do not have a linear structure. This means that some chunks depend on other chunks and can be read only after their parent chunks are read. There is no need to read all chunks. Here we only consider the most important. I have explained in detail the structure of all chunks based on the information contained in 3dsinfo.txt. Jochen wjlhelmy.

 

A chunk contains four fields:

 

-Identifier: a two-byte hexadecimal number to identify the chunk. This information immediately tells us whether the chunk is useful for our intention. If we need this chunk, we can extract (extrapoate) information contained in this chunk and possible sub-Chunk. If we do not need this chunk, we will use the information to skip it...

 

-Length of the chunk: A 4-byte number, indicating the length of the chunk and the total length of all its sub-Chunk.

 

-Chunk data: this field has a variable length and contains all the data in the scenario.

 

The following table shows the offset and length (in bytes) of each field in a typical chunk ).

 

 

We can clearly see from the last row of the table how some chunks depend on other chunks: each chunk is actually included in the "sub-chunks" Field of the parent chunk.

 

The following are the most important chunks in a 3DS file. Note the hierarchical relationship between different elements:

 

Main chunk 0x4d4d
3D editor chunk 0x3d3d
Object Block 0X4000
Triangular Mesh 0x4100
Vertices list 0x4110
Faces description 0x4120
Faces material 0x4130
Mapping coordinates list 0x4140
Smoothing group list 0x4150
Local coordinates system 0x4160
Light 0x4600
Spotlight 0x4610
Camera 0x4700
Material Block 0 xafff
Material name 0xa000
Ambient color 0xa010
Diffuse color 0xa020
Specular color 0xa030
Texture map 1 0xa200
Bump Map 0xa230
Reflection map 0xa220
[Sub chunks for each map]
Mapping filename 0xa300
Mapping parameters 0xa351
Keyframer chunk 0xb000
Mesh information block 0xb002
Spot light information block 0xb007
Frames (start and end) 0xb008
Object Name 0xb010
Object upload point 0xb013
Position track 0xb020
Rotation track 0xb021
Scale track 0xb022
Hierarchy position 0xb030

 

As mentioned above, if we want to read a special chunk, we must first read its parent chunk. Imagine that the 3DS file is a tree, and the chunk we want to read is a leaf (and we are a small ant on the ground ). To reach the leaves, we need to start from the trunk and pass through all the branches leading to the leaves. For example, if we want to reach the chunk vertices list, we must first read the main chunk, then the 3D editor chunk, the object block, and finally the chunk triangular mesh. Other chunks can be safely skipped.

 

Now let's cut out the trees, leaving only the branches that will be used in this tutorial: "vertices", "faces", "mapping coordinates" and their parent chunks.

 

Main chunk 0x4d4d
3D editor chunk 0x3d3d
Object Block 0X4000
Triangular Mesh 0x4100
Vertices list 0x4110
Faces description 0x4120
Mapping coordinates list 0x4140

 

Introduced by NeteaseThe light is like a dreamBlog.

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.