Meshes 网格

优质
小牛编辑
131浏览
2023-12-01

At the core of any 3D game are Meshes - objects consisting of triangles, with textures applied.

任何3D游戏的核心是网格——物体由三角形组成并带有纹理。

Meshes in Unity are rendered with renderer components. Although there may be many variations, a Mesh Renderer is the most commonly used.

Unity中的网格使用渲染组件来呈现。虽然可能有许多变化,但一个网格渲染器是最常用的。

  • The renderer displays the mesh at the GameObject's position.
    渲染器在游戏对象的位置显示网格。
  • The appearance of the mesh is controlled through the renderer's Materials.
    网格的外观是通过渲染的材质来控制的。

网格过滤器 网格渲染器
A Mesh Filter together with Mesh Renderer makes the model appear on screen.
一个网格过滤器再加上网格渲染器,使模型显示在屏幕上。

Meshes 网格

Meshes make up a large part of your 3D worlds. You don't build your meshes in Unity, but in another application.

网格构成了你的3D世界的很大一部分。你不能在Unity中创建网格,除非使用其它应用程序。

In Unity, we have done everything in our power to make this process as simple as possible. There are a lot of details, but the following pages should address all specificities of the common 3D art packages:

在Unity中,我们已经尽我们所能尽可能地简化这个过程中的一切。下面是常见3D美术包的具体地址,列出了很多细节:

Other applications 其它程序

Unity can read .FBX, .dae (Collada), .3DS, .dxf and .obj files, so if your program can export to this format you're home free. FBX exporters for popular 3D packages can be found here. Many packages also have a Collada exporter available.

Unity可以读取.FBX、.dae(Collada)、.3DS、.dxf和.obj文件,所以如果你的程序可以导出为此格式,你就胜利在望了。流行3D软件包的FBX导出(插件)可以在这里找到。许多软件包也有一个Collada导出可供使用。(COLLADA是一个开放的标准,最初用于3D软件数据交换,由SCEA发起,现在则被许多著名厂家支持如Autodesk、XSI等。COLLADA不仅仅可以用于建模工具之间交换数据之用,也可以作为场景描述语言用于小规模的实时渲染。你在3D软件建立好的模型,只要通过COLLADA的外挂插件就可以输出成.dae的文档,这个文档包含的内容是以XML文字资料形式来描述的。)

Textures 纹理

Unity will attempt to hook up materials to your imported scenes automatically. To take advantage of this, place your textures in a folder called "Textures" next to the scene file, or in any folder above it.

Unity会自动将材质和你的导入场景联接起来。要利用这一点,把你的纹理放置到紧靠场景文件名为"Textures(纹理)"的文件夹中,或在它上面的任何文件夹中。

纹理 资源级别
Place your textures in a Textures folder at or above the asset's level
放置你的纹理到一个"纹理"文件夹中或者资源级别(文件夹)的上面

Import settings 导入设置

To access the Import Settings for a 3D mesh file, select it and the relevant options will appear in the Inspector.

要访问三维网格文件的导入设置,选择它,有关选项将出现在检视视图中。

Import settings 导入设置
The Mesh Import Settings dialog 网格导入设置对话框

  • Meshes 网格
  • Scale Factor
    缩放系数 Unity's physics system expects 1 meter in the game world to be 1 unit in the imported file. If you like to model at a different scale, this is the place to fix it.
    Unity的物理系统预定义游戏世界的1米是导入文件的1个单位。如果你想要一个不同比例的模型,在这个地方来修改。
  • Use File Units
    使用文件单位 This option is available only for 3dsMax files. If enabled it imports 3dsMax file as 1FileUnit=1UnityUnit, otherwise it imports as 1cm=1UnityUnit.
    Unity的物理系统预定义游戏世界的1米是导入文件的1个单位。如果你想要一个不同比例的模型,在这个地方来修改。
  • Mesh Compression
    网格压缩 Turning this up will reduce the file size of the mesh, but might introduce irregularities. It's best to turn it up as high as possible without the mesh looking too different from the uncompressed version. This is useful for optimizing game size.
    这个选项会减少网格文件的大小,但可能会导致网格不平整。最好是在不影响网格外观的前提下尽可能高的压缩。这对于优化游戏的大小非常有用。
  • Generate Colliders
    产生碰撞 If this is enabled, your meshes will be imported with Mesh Colliders automatically attached. This is useful for quickly generating a collision mesh for environment geometry, but should be avoided for geometry you will be moving. For more info see Colliders below.
    如果启用,你的网格将在导入时自动附加网格碰撞。这对于快速生成几何边界网格的碰撞是很有用的,除非你要避免移动中的几何碰撞。(也不知道理解的对不对)更多信息见后面Colliders。
  • Swap UVs
    交换Uv Use this if lightmapped objects pick up wrong UV channels. This will swap your primary and secondary UV channels.
    如果光照贴图对象拾取错误的UV通道,使用此选项。这将交换你的主要和次要UV通道。
  • Generate Lightmap UVs
    产生光照贴图Uv Use this to create UV2 to be used for Lightmapping.
    使用它来建立要用于光照贴图的UV2
  •     Advanced Options 高级选项 See Lightmapping UVs document.
  • Normals & Tangents 法线和切线
  • Normals 法线 Defines if and how normals should be calculated. This is useful for optimizing game size.
    定义法线应如何计算。这对于优化游戏的大小有用。
  •     Import 导入 Default option. Imports normals from the file.
    默认选项。从文件导入法线。
  •     Calculate 计算 Calculates normals based on Smoothing angle. If selected, the Smoothing Angle becomes enabled.
    基于平滑角计算法线。如果选中,平滑角成为启用状态。
  •     None 不使用 Disables normals. Use this option if the mesh is neither normal mapped nor affected by realtime lighting.
    禁用法线。如果网格既不是法线映射也不受实时照明的影响,使用此选项。
  • Tangents 切线 Defines if and how tangents and binormals should be calculated. This is useful for optimizing game size.
    定义切线和副法线应如何计算。这对于优化游戏的大小有用。
  •     Import 导入 Imports tangents and binormals from the file. This option is available only for FBX, Maya and 3dsMax files and only when normals are imported from the file.
    从文件导入切线和副法线。此选项仅用于FBX,Maya和3dsMax文件,并且只适用于从文件中导入法线时的情况。
  •     Calculate 计算 Default option. Calculates tangents and binormals. This option is available only when normals are either imported or calculated.
    默认选项。计算切线和副法线。此选项仅用于法线选项是导入或计算时。
  •     None 不使用 Disables tangents and binormals. The mesh will have no Tangents, so won't work with normal-mapped shaders.
    禁用切线和副法线。网格将没有切线,所以不会使用法线贴图着色。
  • Smoothing Angle 平滑角 Sets how sharp an edge has to be to be treated as a hard edge. It is also used to split normal map tangents.
    设置如何锐化边缘使之被视为一个硬边。它也可以用来分离法线贴图切线。
  • Split Tangents 分离切线 Enable this if normal map lighting is broken by seams on your mesh. This usually only applies to characters.
    如果网格接缝破坏了法线贴图照明,启用此项。通常只用于字符(角色)。
  • Materials 材质
  • Generation 生成 Controls how materials are generated: 控制如何生成材质:
  •     Off 关闭 This will not generate materials at all. 该选项根本不会生成材质。
  •     Per Texture 根据纹理 Enable this to generate material files near the found texture files. When enabled, different scenes will share the same material settings when they use the same textures. For the precise rules, see Material Generation below.
    启用此项在找到的纹理文件旁生成材质文件。启用时,不同的场景将共享相同的材质设置,当它们使用相同纹理时。精确规则,查看后面的材质生成。
  •     Per Material 根据材质 This will generate materials per scene, so only this scene uses them.
    这将根据场景生成材质,所以只有这个场景能使用。
  • Animations 动画
  • Generation 生成 Controls how animations are imported: 控制如何导入动画:
  •     Don't Import 不导入 No animation or skinning is imported. 没有动画或蒙皮导入。
  •     Store in Original Roots
        存储在原始根对象中 Animations are stored in root objects of your animation package (these might be different from root objects in Unity).
    动画存储在你的动画包的根对象中(这与Unity中的根对象不同)。
  •     Store in Nodes
        存储在节点中 Animations are stored together with the objects they animate. Use this when you have a complex animation setup and want full scripting control.
    动画与对象存储在一起进行动作。当你有一个复杂的动画设置,并希望全脚本控制时,使用此项。
  •      Store in Root
         存储在根对象中 Animations are stored in the scene's transform root objects. Use this when animating anything that has a hierarchy.
    动画存储在场景的变换根对象中。当动画对象有有层次结构时,使用该项。
  • Bake Animations
    烘焙动画 When using IK or simulation in your animation package, enable this. Unity will convert to FK on import. This option is available only for Maya, 3dsMax and Cinema4D files.
    在你的动画包中使用IK或仿真时,启用该项。Unity将转换为FK导入。此选项仅适用于Maya、3dsMax和Cinema4D文件。(在三维动画中,IK是指反向动力学,FK是指正向动力学)
  • Animation Wrap mode
    动画循环模式 The default Wrap Mode for the animation in the mesh being imported
    在网格被导入时动画的默认循环模式。
  • Split Animations
    分割动画 If you have multiple animations in a single file, here you can split it into multiple clips.
    如果你有包含多动画的单一文件,在这里你可以将它分割成多个片段。
  •     Name 名称 Name of the split animation clip 分割的动画片段的名称
  •     Start 开始 First frame of this clip in the model file 在这个模型文件中该片段的第一帧
  •     End 结束 Last frame of this clip in the model file 在这个模型文件中该片段的最后一帧
  •     WrapMode 循环模式 What the split clip does when the end of the animation is reached
    当到达动画结尾时分割片段该做什么。
  •     Loop 循环 Depending on how the animation was created, one extra frame of animation may be required for the split clip to loop properly. If your looping animation doesn't look correct, try enabling this option.
    根据动画是如何创建的来确定,为使分割片段循环正常,动画的一个额外帧可能是必需的。如果你的循环动画看起来不正确,尝试启用该选项。
  • Animation Compression 动画压缩
  • Anim. Compression
    动画压缩 What type of compression will be applied to this mesh's animation(s)
    什么压缩类型将被应用到这个网格的动画
  •     Off 关闭 Disables animation compression. This means that Unity doesn't reduce keyframe count on import, which leads to the highest precision animations, but slower performance and bigger file and runtime memory size. It's not recommended to use this option - if you need higher precision animation, you should enable keyframe reduction and lower allowed Animation Compression Error values instead.
    禁用动画压缩。这意味着Unity并没有在导入时减少关键帧数,从而导致最高精度的动画,除非(因为)较慢的性能、更大的文件、运行时的内存大小(而使用该项)。不推荐使用这个选项——如果你需要更高精度的动画,你应该启用减少关键帧和降低允许的动画压缩误差值来替代。
  •     Keyframe Reduction 关键帧减少 Reduces keyframes on import. If selected, the Animation Compression Errors options are displayed.
    减少导入关键帧。如果选中,动画压缩误差选项将显示出来。
  •     Keyframe Reduction and
        Compression
         关键帧减少并压缩 Reduces keyframes on import and compresses keyframes when storing animations in files. This affects only file size - the runtime memory size is the same as Keyframe Reduction. If selected, the Animation Compression Errors options are displayed.
    减少导入关键帧并在存储动画到文件中时压缩关键帧。这仅影响文件大小——运行时内存大小等同于关键帧减少。如果选中,动画压缩误差选项将显示出来
  • Animation Compression Errors
    动画压缩误差 These options are available only when keyframe reduction is enabled.
    这些选项仅用于启用关键帧减少时。
  •     Rotation Error 旋转误差 Defines how much rotation curves should be reduced. The smaller value you use - the higher precision you get.
    定义应该减少多少旋转曲线。使用较小的值——得到较高的精度。
  •     Position Error 位置误差 Defines how much position curves should be reduced. The smaller value you use - the higher precision you get.
    定义应该减少多少位置曲线。使用较小的值——得到较高的精度。
  •     Scale Error 缩放误差 Defines how much scale curves should be reduced. The smaller value you use - the higher precision you get.
    定义应该减少多少缩放曲线。使用较小的值——得到较高的精度。

Material Generation 材质生成

Materials are found based on the following rules:

基于以下规则找到材质:

  • Unity gets the name of the main diffuse material bound to the objects in the scene.
    Unity获取在场景中的绑定到对象的主要散射材质的名称。
  • Unity looks for a material with this name in a Folder called Materials next to the scene.
    Unity用该名字查找紧靠场景文件夹的名为材质的文件夹中的材质。
  • Unity goes up the project folders, looking for the Material in each Materials folder along the way.
    Unity建立起项目文件夹,在每个材质文件夹中寻找材质。

If Unity can't find the Material, it tries to create one from the texture:

如果Unity无法找到材质,它将尝试通过纹理创建一个:

  • Unity checks for a texture with the correct name in the same folder as the scene.
    Unity检查与场景同名的文件夹中的恰当名称的纹理。
  • Unity checks for a texture with the correct name in a folder called Textures next to the scene.
    Unity检查紧靠场景的名为纹理的文件夹中的恰当名称的纹理。
  • Unity goes up the project folders, looking for the correct texture in each Textures folder along the way.
    Unity建立起项目文件夹,在每个纹理文件夹中寻找恰当的纹理。
  • If Unity finds the texture, it creates a Materials folder next to it and creates a material in there.
    如果Unity找到纹理,它将创建一个紧靠它的材质文件夹,并在那里创建一个材质。

Colliders 碰撞器

Unity features two primary types of colliders: Mesh Colliders and Primitive Colliders. Mesh colliders are components that use imported mesh data and can be used for environment collision. When you enable Generate Colliders in the Import Settings, a Mesh collider is automatically added when the mesh is added to the Scene. It will be considered solid as far as the physics system is concerned.

Unity有两种基本类型的碰撞:网格碰撞与简单碰撞。网格碰撞是使用导入的网格数据而且可用于环境(边界)碰撞的组件。当你在导入设置中启用了产生碰撞选项,在网格被添加到场景时,一个网格碰撞将自动被添加。考虑将它用于固体的物理系统方面。

If you are moving the object around (a car for example), you can not use Mesh colliders. Instead, you will have to use Primitive colliders. In this case you should disable the Generate Colliders setting.

如果你要到处移动对象(例如汽车),你不能使用网格碰撞,相反,你必须使用简单碰撞。在这种情况下,你应该禁用产生碰撞设置。

Animations 动画

Animations are automatically imported from the scene. For more details about animation import options see the Animation Import chapter.

动画会自动从场景导入。有关动画导入选项的详细资料请参阅动画导入章节。

Normal mapping and characters 法线贴图和角色

If you have a character with a normal map that was generated from a high-polygon version of the model, you should import the game-quality version with a Smoothing angle of 180 degrees. This will prevent odd-looking seams in lighting due to tangent splitting. If the seams are still present with these settings, enable Split tangents across UV seams.

如果你有一个使用法线贴图的角色,该贴图是从模型的一个高多边形版本生成的,你应该导入使用180度平滑角的游戏品质版本。这将防止由于切线分离(而产生的)在光线中的古怪接缝。如果使用这些设置接缝仍然存在,启用穿过UV接缝分离切线。

If you are converting a greyscale image into a normal map, you don't need to worry about this.

如果你转换一个灰度图像成为一个法线贴图,那么你不必担心这个。

Hints 提示

  • Merge your meshes together as much as possible. Make them share materials and textures. This has a huge performance benefit.
    尽可能将你的网格合并在一起,让他们分享材质和纹理。这样做具有巨大的性能优势。
  • If you need to set up your objects further in Unity (adding physics, scripts or other coolness), save yourself a world of pain and name your objects properly in your 3D application. Working with lots of pCube17 or Box42-like objects is not fun.
    如果你需要进一步在Unity中设置你的对象(添加物理、脚本或其它coolness),节省自己大量的辛苦(时间)并在你的3D程序中恰当地命名对象。使用诸如pCube17或Box42这样的对象(名称)并不是有趣的事。
  • Make your meshes be centered on the world origin in your 3D app. This will make them easier to place in Unity.
    使网格在3D程序的世界原点的中心,这将使导入Unity比较容易。

The Unity Editor shows too many triangles (compared to what my 3D app says)
Unity编辑器显示过多三角形(相比于我的3D软件所表明的)

This is correct. What you are looking at is the amount of triangles actually being sent to OpenGLES for rendering. In addition to case where something like the material requires them to be sent twice, other things like hard-normals and non contiguous UV increase vertex/triangle counts significantly compared to what a modeling app or Unity tells you. Triangles need to be contiguous in both 3D and UV space to form a strip, so when you have UV seams, degenerate triangles have to be made to form strips - this bumps up the count. Previously Unity would report triangle counts incorrectly. This was fixed first in the run-time, and recently in the Editor. Now both will report the correct amount of triangles *actually* being sent to OpenGLES for rendering.

这是正常的。你现在看到的三角形的数量实际上是被送往OpenGLES渲染的。除此之外,诸如材质的事物需要它们被发送两次,其它的像硬法线和非连续UV增加顶点/三角形数量要比建模程序或Unity告诉你的更为重要(不明白什么意思)。三角形需要在三维和UV空间中邻接以形成条状,所以当你有UV接缝,退化三角形,必须构建成条状——这将提高数量。以前Unity将错误地报告三角形数量。最近在编辑器中,这是首次在运行期修正。现在,两者将报告正确的实际上是被送往OpenGLES渲染的三角形总数。

See Also 参见