CSharpGL(5)解析3DS文件并用CSharpGL渲染

我曾经写过一个简单的*.3ds文件的解析器,但是只能解析最基本的顶点、索引信息,且此解析器是仿照别人的C++代码改写的,设计的也不好,不方便扩展。

现在我重新设计实现了一个*.3ds文件的解析器,它能解析的Chunk类型更多,且容易扩展。以后需要解析更多类型的Chunk时比较简单。

+BIT祝威+悄悄在此留下版了个权的信息说:

这个3DS解析器现在不是CSharpGL的一部分,CSharpGL已在GitHub开源,欢迎对OpenGL有兴趣的同学加入(https://github.com/bitzhuwei/CSharpGL

本文代码可在(https://github.com/bitzhuwei/CSharpGL2)找到。

本文所用的3ds文件您可以在此(http://www.cgrealm.org/d/downpage.php?n=2&id=15764::1326768548)下载,由于文件比较大我就不上传了。

+BIT祝威+悄悄在此留下版了个权的信息说:

3DS文件格式

CSharpGL(5)解析3DS文件并用CSharpGL渲染

3ds文件是二进制的。3ds格式的基本单元叫块(chunk)。我们就是读这样一块一块的信息。目录树如下,缩进风格体现了块的父子关系。可见3ds模型文件和XML文件类似,都是只有1个根结点的树状结构。

 1 0x4D4D // Main Chunk
 2 ├─ 0x0002 // M3D Version
 3 ├─ 0x3D3D // 3D Editor Chunk
 4 │  ├─ 0x4000 // Object Block
 5 │  │  ├─ 0x4100 // Triangular Mesh
 6 │  │  │  ├─ 0x4110 // Vertices List
 7 │  │  │  ├─ 0x4120 // Faces Description
 8 │  │  │  │  ├─ 0x4130 // Faces Material
 9 │  │  │  │  └─ 0x4150 // Smoothing Group List
10 │  │  │  ├─ 0x4140 // Mapping Coordinates List
11 │  │  │  └─ 0x4160 // Local Coordinates System
12 │  │  ├─ 0x4600 // Light
13 │  │  │  └─ 0x4610 // Spotlight
14 │  │  └─ 0x4700 // Camera
15 │  └─ 0xAFFF // Material Block
16 │     ├─ 0xA000 // Material Name
17 │     ├─ 0xA010 // Ambient Color
18 │     ├─ 0xA020 // Diffuse Color
19 │     ├─ 0xA030 // Specular Color
20 │     ├─ 0xA200 // Texture Map 1
21 │     ├─ 0xA230 // Bump Map
22 │     └─ 0xA220 // Reflection Map
23 │        │  // Sub Chunks For Each Map 
24 │        ├─ 0xA300 // Mapping Filename
25 │        └─ 0xA351 // Mapping Parameters
26 └─ 0xB000 // Keyframer Chunk
27    ├─ 0xB002 // Mesh Information Block
28    ├─ 0xB007 // Spot Light Information Block
29    └─ 0xB008 // Frames (Start and End)
30       ├─ 0xB010 // Object Name
31       ├─ 0xB013 // Object Pivot Point
32       ├─ 0xB020 // Position Track
33       ├─ 0xB021 // Rotation Track
34       ├─ 0xB022 // Scale Track
35       └─ 0xB030 // Hierarchy Position
Chunk树

相关文章:

  • 2021-09-23
  • 2022-02-08
  • 2022-02-08
  • 2021-07-16
  • 2021-07-22
  • 2022-12-23
猜你喜欢
  • 2022-02-08
  • 2021-10-12
  • 2021-08-13
  • 2021-05-30
  • 2021-12-25
  • 2021-06-12
  • 2021-12-15
相关资源
相似解决方案