Version: 2017.4
铰链关节
刚体

网格碰撞体 (Mesh Collider)

Mesh Collider 采用网格资源并基于该网格构建其碰撞体。在进行碰撞检测时,Mesh Collider 比使用复杂网格的基元要准确得多。标记为 Convex 的 Mesh Collider 可与其他 Mesh Collider 发生碰撞。

属性

Property Function
Convex Tick the checkbox to enable Convex. If enabled, this Mesh Collider collides with other Mesh Colliders. Convex Mesh Colliders are limited to 255 triangles.
Is Trigger If enabled, Unity uses this Collider for triggering events, and the physics engine ignores it.
Cooking Options Enable or disable the Mesh cooking options that affect how the physics engine processes Meshes.
None Disable all of the Cooking Options listed below.
Everything Enable all of the Cooking Options listed below.
Inflate Convex Mesh Allow the physics engine to increase the volume of the input Mesh, to generate a valid convex mesh.
Cook for Faster Simulation Make the physics engine cook Meshes for faster simulation. When enabled, this runs some extra steps to guarantee the resulting Mesh is optimal for run-time performance. This affects the performance of the physics queries and contacts generation. When this setting is disabled, the physics engine uses a faster cooking time instead, and produces results as fast as possible. Consequently, the cooked Mesh Collider might not be optimal.
Enable Mesh Cleaning Make the physics engine clean Meshes. When enabled, the cooking process tries to eliminate degenerate triangles of the Mesh, as well as other geometrical artifacts. This results in a Mesh that is better suited for use in collision detection and tends to produce more accurate hit points.
Weld Colocated Vertices Make the physics engine remove equal vertices in the Meshes. When enabled, the physics engine combines the vertices that have the same position. This is important for the collision feedback that happens at run time.
Material Reference to the Physics Material that determines how this Collider interacts with others.
Mesh Reference to the Mesh to use for collisions.

详细信息

Mesh Collider 从附加到游戏对象的网格构建其碰撞表示,并读取附加的变换组件的属性以正确设置其位置和缩放。这样做的好处是可以使碰撞体的形状与游戏对象可见网格的形状完全相同,从而产生更精确和真实的碰撞。但是,伴随这种精度的不足之处是,与涉及原始碰撞体(例如球体、盒体和胶囊体)的碰撞相比,处理开销会更高,因此最好谨慎使用 Mesh Collider。

碰撞网格中的面为单面。这意味着,对象可从一个方向穿过这些面,但从另一个方向会与这些面碰撞。

网格烹制

网格烹制将常规网格更改为可以在物理引擎中使用的网格。烹制会构建用于物理查询的空间搜索结构(如 Physics.Raycast)以及用于接触生成的支持结构。Unity 在碰撞检测中使用网格之前烹制所有这些网格。这可在导入时 (Import Settings > Model > Generate Colliders) 或运行时进行。

如果要在运行时生成网格(例如,对于程序化表面),设置 Cooking Options 以更快地生成结果并禁用清理过程的其他数据清理步骤将非常有用。缺点是需要生成无退化三角形和非同位顶点,但烹制的运行速度更快。

如果禁用 Enable Mesh CleaningWeld Colocated Vertices__,则需要确保未使用那些算法在其他情况下可能会过滤的数据。如果禁用了 Weld Colocated Vertices__,请确保没有任何同位顶点,如果启用了 __Enable Mesh Cleaning__,确保没有面积接近零的小三角形,没有狭长的三角形,也没有面积接近于无限大的大三角形。

注意:将 Cooking Options 设置为除默认设置之外的任何其他值意味着 Mesh Collider 必须使用一个 isReadable 值为 true 的网格。

限制

使用 Mesh Collider 时有一些限制:

  • Mesh Colliders that do not have Convex enabled are only supported on GameObjects without a Rigidbody component. To apply a Mesh Collider to a Rigidbody component, tick the Convex checkbox.
  • In certain cases, for a Mesh Collider to work properly, you need to tick the Read/Write Enabled checkbox in the Mesh Import Settings. These cases include:
    • Negative scaling (for example, (–1, 1, 1)).
    • Shear transform (for example, when a rotated Mesh has a scaled parent transform).

优化技巧:__如果网格仅由 Mesh Collider 使用,则可以在 Import Settings__ 中禁用 __Normals__,因为物理系统不需要它们。


  • 2018–06–07 页面已修订并进行了编辑审查

  • 2017.3 版中添加了网格的 Cooking Options NewIn20173

  • 在 2018.1 版中更新了功能

铰链关节
刚体
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961