3ds Max File Format (Part 1: The outer file format; OLE2)

The 3ds Max file format, not too much documentation to be found about it. There are some hints here and there about how it’s built up, but there exists no central documentation on it.

Right now we are in the following situation. A few thousand of max files, created by a very old version of max (3.x), containing path references to textures and other max files that have been renamed and relocated or which simply no longer exist. Yes, we have a maxscript that can go through them all, and that manages to fix a large number of paths. However, there are a lot of paths that are stored as part as fields in plugins and material scripts that don’t get noticed, and the performance of opening and closing this number of files from 3ds Max directly is horrible. The obvious solution? Figure out how we can read and save the max file with modified contents, without having to understand all of the actual data it contains. Fortunately, this is actually possible without too much work.

Some research online brings up the following blog post, relating to a change in the max file format in version 2010, which would make it easier to update asset paths: http://www.the-area.com/blogs/chris/reading_and_modifying_asset_file_paths_in_the_3ds_max_file. That’s nice and all, but it’s only from version 2010 on, and it very likely won’t contain any assets referenced by path by old plugins and such.

So, starting at the beginning. The blog post I referred to above nicely hints us to the OLE structured file format. Since there exist a wide range of implementations for that, we can pretty much skip that, and accept that it’s basically a filesystem in a file, so it’s a file containing multiple file streams. A reliable open source implementation of this container format can be found in libgsf. When scanning a fairly recent max file, using the command @@gsf [email protected]@, we can find the following streams inside this file:


1

2

3

4

5

6

7

8

9

f         52 VideoPostQueue

f     147230 Scene

f        366 FileAssetMetaData2

f       2198 DllDirectory

f      29605 Config

f       3438 ClassDirectory3

f        691 ClassData

f      29576 SummaryInformation

f       2320 DocumentSummaryInformation

The FileAssetMetaData2 is new in 3ds Max 2010.

One step further, we can start examining the contents of these streams. And it’s usually easiest to start off with one of the more simple ones. VideoPostQueue seems small enough to figure out the overall logic of the file format, hoping that the rest is serialized in a similar way. Using the command @@gsf [email protected]@ we can get a hex output of one of the streams, and using a simple text editor we can find how it’s structured. Binary formats often contain 32 bit length values, which are usually easy to spot in small files, since they’ll contain a large number of 00 values. It’s basically a matter of finding possible 32bit length integers, and matching them together with various fixed length fields and other typical binary file contents, until something programatically logical turns up. Here’s a manually parsed VideoPostQueue storage stream:


1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

[

    50 00 (id: 0x0050)

    0a 00 00 00 (size: 10 - 6 = 4)

    [

        01 00 00 00 (value: 1)

    ]

]

[

    60 00 (id: 0x0060)

    2a 00 00 80 (size: 42 - 6 = 36) (note: negative bit = container)

    [

        10 00 (id: 0x0010)

        1e 00 00 00 (size: 30 - 6 = 24)

        [

            07 00 00 00 (value: 7)

            01 00 00 00 (value: 1)

            00 00 00 00

            00 00 00 00

            20 12 00 00 (value: 4610)

            00 00 00 00

        ]

        20 00 (id: 0x0020)

        06 00 00 00 (size: 6 - 6 = 0)

    ]

]

The storage streams in the max container file contain a fairly simple chunk based file format (and in fact similar in format to the fairly well known .3ds file format). Being based on chunks is what allows 3ds Max to open a file for which certain plugins are missing. It’s basically a tree structured format where every entry has an identifier and a size, so when an identifier is unknown, or when it’s contents are incompatible, it can simply be kept as is or discarded. The only exceptions in the file that don’t use this structure are SummaryInformation and DocumentSummaryInformation, which are supposedly in a standard Windows format, and the new FileAssetMetaData2 section is formatted differently as well unfortunately.

In this format, the chunk header consists of a 2-byte unsigned integer which is the identifier, and a 4-byte unsigned integer, where the 31 least significant bits are the size and the msb is a flag that helpfully lets us know if the chunk itself contains more chunks, and thus is a container, or not. For very large files, where 31 bits is insufficient for the size, the entire size field is set to 0, and the header increases with an additional 64-bit unsigned integer field which is similarly structured as the 32-bit size field. The size field includes the size of the header.


1

2

3

0 | 0f 20 (id)

          00 00 00 00 (size missing)

                      17 fe 01 00 00 00 00 80 (size in 64 bits)

With this information it is possible to read a max file, modify the binary contents of chunks (most of them are fairly basic of format), and we should be able to re-save the max file with our modified data. The DllDirectory section, for example, parsed programatically starts like this:


1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

CStorageContainer - items: 20

    [0x21C0] CStorageValue - bytes: 4

    786432216

    [0x2038] CStorageContainer - items: 2

        [0x2039] CStorageUCString - length: 39

        Viewport Manager for DirectX (Autodesk)

        [0x2037] CStorageUCString - length: 19

        ViewportManager.gup

    [0x2038] CStorageContainer - items: 2

        [0x2039] CStorageUCString - length: 49

        mental ray: Material Custom Attributes (Autodesk)

        [0x2037] CStorageUCString - length: 21

        mrMaterialAttribs.gup

    [0x2038] CStorageContainer - items: 2

        [0x2039] CStorageUCString - length: 37

        Custom Attribute Container (Autodesk)

        [0x2037] CStorageUCString - length: 23

        CustAttribContainer.dlo

...

Of course, it would be interesting if we could go further, and directly manipulate the parameters of our own plugins and scripts from our own tools back into the max files so that everything is centrally stored without any duplicate source data in the way. And that’s exactly what I’ll be doing next.

6 thoughts on “3ds Max File Format (Part 1: The outer file format; OLE2)”

  1. Pingback: 3ds Max File Format (Part 2: The first inner structures; DllDirectory, ClassDirectory3) | Kaetemi
  2. Pingback: 3ds Max File Format (Part 3: The department of redundancy department; Config) | Kaetemi
  3. Pingback: 3ds Max File Format (Part 4: The first useful data; Scene, AppData, Animatable) | Kaetemi
  4. Pingback: 3ds Max File Format (Part 5: How it all links together; ReferenceMaker, INode) | Kaetemi
  5. Pingback: 3ds Max File Format (Part 6: We get signal) | Kaetemi
  6. Pingback: Reverse engineering the Max file format | Neil Marshall‘s Tech Art Blog

【转】http://www.kaetemi.be/wp/2012/08/17/3ds-max-file-format-part-1-outer-file-format-ole2/

时间: 2024-12-28 01:17:06

3ds Max File Format (Part 1: The outer file format; OLE2)的相关文章

[iTyran原创]iPhone中OpenGL ES显示3DS MAX模型之一:OBJ格式分析

[iTyran原创]iPhone中OpenGL ES显示3DS MAX模型之一:OBJ文件格式分析作者:yuezang - iTyran 在iOS的3D开发中常常需要导入通过3DS MAX之类的3D设计软件生成的模型.因为OpenGL ES是不能直接读取这些文件的,所以常常需要开发人员增加接口来导入.通常的做法是在建模软件中建立3D模型之后在OpenGL ES中导入并进行控制.    3DS MAX通常的保存格式有*.max(现在生成的版本的格式),*.3ds(低版本的3ds Max生成的格式)

Reading and Modifying Asset File Paths in the 3ds Max File

Some people found the following information in the MAXScript reference for 2010: NEW in 3ds Max 2010: The 3ds Max scene file now provides Asset Metadata in a separate stream which can be accessed and modified by external applications. The Asset data

AVEVA PDMS to 3ds Max - RvmTranslator6.0beta

AVEVA PDMS to 3ds Max - RvmTranslator6.0beta [email protected] RvmTranslato6.0 translate PDMS RVM to 3ds Max by MAXScript. The MAXScipt is like the PML of PDMS. MAXScript can be used as a high-level scene import utility for 3ds Max. By outputting MAX

25 things you probably didn't know about the 3ds Max SDK

I've adventured deep into the darkest corners of the 3ds Max SDK to bring you a set of largely unknown but useful tips and tricks. Use the 3ds Max SDK from MAXScript by loading the Autodesk.Max.dll. Add the following MAXScript to your start-up script

panda插件介绍-3DS MAX导出x模型文件骨骼动画蒙皮等

1.about选项卡 2.X File Settings选项卡 3.Textures & .fx files选项卡 4.Animation选项卡 5.Mesh选项卡 6.3DS Max Objects

万圣节福利:红孩儿3D引擎开发课程《3ds max导出插件初步》

红孩儿3D引擎开发课堂 QQ群:275220292 国内最详尽教授怎样开发3D引擎的地方!揭开3D引擎开发最不为人知的秘密! 万圣节福利,国内最详尽的3ds max导出插件编程指南0基础篇免费发放!            前言:今天网易的<乱斗西游>上线AppStore ,将继完美世界<黑暗黎明>后再次证明自研引擎的实力!假设你想成为引擎研发高手,那么,一切,将从3ds max导出插件起步~ 第九章课程<3ds max导出插件初步> 一.3ds max导出插件简单介绍:

VRay 2.0 SP1 2.10.01 for 3ds max 9/2008/2009/2010/2011/2012 32/64位 顶渲简体中文版+英文版[中国室内设计论坛-室内人]

VRay 2.0 SP1 2.10.01 for 3ds max 9/2008/2009/2010/2011/2012 32/64位 顶渲简体中文版+英文版[中国室内设计论坛-室内人] 对最新版本的V-Ray2.0 SP1的所有版本,重新进行了一次彻底的汉化,继以前版本的彻底.稳定之处特点外,还对所发生的Bug进行了彻底排查,能正常支持V-Ray RT.分布渲染.材质烘焙.渲染元素等V-Ray全部功能.顶渲简体中文版,还剔除了原程序中用于二次开的SDK包,正常用户不需要此开发包,这使程序更加紧凑

【Unity】3.3 用3ds Max 2015制作模型并将其导入到Unity

分类:Unity.C#.VS2015 创建日期:2016-04-05 一.常用三维软件简介 由于游戏引擎本身的建模功能相对较弱,无论是专业性还是自由度都无法同专业的三维软件相比,所以大多数游戏中的模型.动画等资源都是通过专业的三维软件来制作的,制作完成后再将其导入到Unity中使用就行了. Unity支持几乎所有主流的三维文件格式,例如.FBX..dae.3Ds..dxf..obj等.其中,最常用的三维建模软件有:3Ds Max.Blender.Maya.--等. 用户在3Ds Max.Blen

3ds Max从入门到精通

1. 软件的下载与安装 这里用的是3ds Max2009简体中文版 32位 在 Win7上运行记得打上sp2补丁,不然会有bug. 2. 3ds Max的历史 3ds Max前身为运行于PC机DOS平台上的3D Studio,不断地升级换代与革新,现已成为成熟的大型三维制作软件,可应用于游戏.动画.建筑设计等,应用可以说非常广.游戏上,比如魔兽争霸.魔兽世界.古墓丽影.红警.战争机器.虚拟人生.Halo.细胞分裂.辐射3和刺客信条等等基本上所有的游戏都有max的身影,电影上<剑鱼行动 >.&l