Three.js:减少模型文件大小的方法? [英] Three.js: ways to reduce file size of models?

查看:1515
本文介绍了Three.js:减少模型文件大小的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前,我使用ObjectLoader将所有模型加载到场景中.我还使用Three.js编辑器来应用我的纹理.目前,我的方法是从3Ds Max中导出OBJ文件,并将其导入到Three.js在线编辑器中,然后在其中添加纹理.

Currently I use the ObjectLoader to load all my models into the scene. I also use the Three.js editor to apply my textures. The way I do it currently is by exporting a OBJ file from 3Ds Max and importing it into the Three.js online editor where I then add the texture.

OBJ文件约为30mb,但导出的JSON文件几乎为100mb.怎么会有如此巨大的差异?纹理大小非常小,这不是原因.有没有人对此有任何见识或有更好的方法呢?

The OBJ file is around 30mb but the exported JSON file is almost 100mb. How can there be such a huge difference? The texture size is very low so that isn't the reason. Does anyone have any insight on this or have a better way to do this?

推荐答案

您的原始obj文件可能不包含法线和UV列表.添加纹理时,仅凭这一事实就可以轻松地将文件的大小推高到300%.

Your origin obj file may not contain normals and UV lists. This fact alone could easily push a file to 300% size when you add textures.

OBJ是传统的逐行格式. JSON是一个多维对象,包含所有内容. JSON中的数组和对象在不考虑时会占用很大的占用空间,例如逗号,引号,括号和重要的换行符,以及潜在的重复标记. Three.js开发人员非常聪明地采用了3d json格式,不重复元信息.

OBJ is a legacy line by line format. JSON is a multidimensional object, with all that entails. Arrays and Objects in JSON carry significant footprints such as commas, quotes, brackets and significant line breaks when not considered, as well as potential for repeated tokens. The three.js developers have been very clever in the 3d json format not to repeat meta information.

相反,OBJ格式在每行仅使用简单的一个和两个字母指示符,并在每行上使用空格分隔值.

In contrast, the OBJ format uses only simple one and two letter indicators at each line with space delimited values on each line.

例如:

f v1 v2 v3

尽管已精简,但这使OBJ文件更难以使用,并且在加载json文件时不存在的Three.js中ObjLoader和ObjLoader2的加载限制.

Although streamlined, This makes OBJ files more difficult to work with and there are loading limitations with ObjLoader and ObjLoader2 in three.js that don't exist when loading a json file.

您可以选择哪种文件类型. Threejs具有用于各种格式(例如STL和Collada)的加载程序和导出程序,并包括obj导出.

Which filetype you choose is up to you. Threejs has loaders and exporters for various formats, such as STL and Collada, and includes obj export.

导出器

加载器

无论使用json还是obj,向浏览器提供3d模型时,使用JIT GZIP正确设置服务器都是至关重要的.请参阅这篇不错的文章通过谷歌.这样可以简化3d数据的提供.

In either case of using json or obj, when serving 3d models to the browser, it is critical that your server is setup properly with JIT GZIP. See this decent article I just found via google. This will streamline serving of 3d data.

减小3d模型尺寸以在网络上或游戏中交付的正确方法是

The proper way to go about reduction of 3d model size for delivery on the web or in a game is to use mesh decimation plugins.

没关系,但是我更喜欢在整个数据流中使用OBJ来兼容各种3d工具集,因为它得到了广泛的支持.

Not that it matters, but I prefer using OBJ throughout my data flow for compliance with various 3d toolsets since it's so widely supported.

这篇关于Three.js:减少模型文件大小的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆