形状
While a body simulates various types of physical behavior, a shape represents the volume of space occupied by a physical body. A physically simulated object usually has one body and one or several shapes which allow objects to collide with each other (therefore, shapes are often referred as collision shapes). Objects with shapes also fall under gravity, bounce off static surfaces or slide along them. A body without a single shape assigned behaves as a dummy body that can be connected to other bodies using joints, but does not collide and is immune to gravity.当身体模拟各种类型的身体行为时,形状表示身体所占据的空间量。物理模拟的对象通常具有一个主体和一个或多个形状,这些形状允许对象彼此碰撞(因此,形状通常称为碰撞形状)。具有形状的物体也会在重力作用下掉落,从静态表面反弹或沿其滑动。没有分配单一形状的物体的行为类似于虚拟物体,可以使用关节连接到其他物体,但是不会碰撞并且不受重力的影响。
Basic shape types are as follows:基本形状类型如下:
- Simple primitives. They are very fast and memory efficient. Simple primitives should be used whenever possible.
- Sphere (uses continuous collision detection) Sphere (uses continuous collision detection)
- Capsule (uses continuous collision detection) Capsule (uses continuous collision detection)
- Cylinder Cylinder
- Box Box
- Complex collision shapes composed of triangles. These shapes are slower and more memory demanding.
- Convex hullConvex hull
- A set of autogenerated convex hullsA set of autogenerated convex hulls
- Convex hull 凸包
- A set of autogenerated convex hulls一组自动生成的凸包
Simple primitives make collision calculations easier while keeping performance high and accuracy acceptable. Convex hulls provide higher precision, however, continuous collision detection is not available for this type of shape. Therefore, convex hulls should not be used for fast-moving objects.简单的原语使碰撞计算更容易,同时保持高性能和准确性。凸包可提供更高的精度,但是,这种类型的形状无法进行连续碰撞检测。因此,不应该将凸包用于快速移动的对象。
The number of shapes should be kept as low as possible. Otherwise, heavy physics calculations will decrease the performance. 形状不必复制它近似的网格。建议使用简单的原语。即使它们不精确,在大多数情况下它们也可以提供可接受的结果。
形状的数量应尽可能保持低。否则,繁琐的物理计算会降低性能。
A shape cannot be created without a body and does not have its own position in world coordinates. It is always assigned to a body and positioned relative to it.没有身体就无法创建形状,并且在世界坐标中没有自己的位置。始终将其分配给主体并相对于它定位。
See also也可以看看#
Programming implementation:编程实现:
- Shape class
- ShapeSphere class
- ShapeCapsule class
- ShapeCylinder class
- ShapeBox class
- ShapeConvex class
- A fragment of video tutorial on physics illustrating the concept of shape. 物理视频教程的片段说明了形状的概念。
Shape Parameters形状参数#
All shapes regardless of their type have the following common parameters所有形状,无论其类型如何,均具有以下通用参数
Enabled | A flag indicating if a shape is enabled.一个标志,指示是否启用了形状。 |
Continuous | A flag indicating if the continuous collision detection is enabled for the shape. Continuous collision detection is available for sphere and capsule shapes only.Continuous collision detection is available for sphere and capsule shapes only. Continuous collision detection is available for sphere and capsule shapes only.连续碰撞检测仅适用于球形和胶囊形。 |
Mass | Mass of the shape. Changing the mass influences the density, which is calculated by dividing the mass by shape volume. In case if there are several shapes assigned to a body (e.g. a set of convex hulls)形状的质量。改变质量会影响密度,密度是通过将质量除以形状体积而得出的。如果有几种形状分配给主体(例如一组凸包) |
Density | Density of the shape. Changing the density influences the mass, which is calculated by multiplying shape volume by density.形状的密度。更改密度会影响质量,质量是通过将形状体积乘以密度来计算的。 |
Friction | Coefficient of friction of the shape. Defines how rough the shape's surface is. The higher the value, the less tendency the shape has to slide.
In case if an object contains a surface and a shape, both with specified friction parameter, only the shape's parameter will be used.形状的摩擦系数。定义形状表面的粗糙度。值越高,形状滑动的趋势越少。
|
Restitution | Coefficient of restitution of the shape. Defines how bouncy the shape is when colliding.
The minimum value of 0 indicates inelastic collisions (a piece of soft clay hitting the floor)The maximum value of 1 represents highly elastic collisions (a rubber ball bouncing off a wall)In case if an object contains a surface and a shape, both with specified restitution parameter, only the shape's parameter will be used.恢复形状的系数。定义碰撞时形状的弹性。
|
Position | Position of the shape in the coordinates of the body.形状在 body 坐标中的位置。 |
Rotation | Rotation of the shape in the coordinates of the body.在 body 的坐标中旋转形状。 |
Physics Intersection mask | Physics Intersection bit mask of the shape. Physics Intersection形状的位掩码。 |
Collision mask | Collision bit mask of the shape. This mask is used to specify collisions of the shape with other ones.形状的碰撞位掩码。此蒙版用于指定形状与其他形状的碰撞。 |
Exclusion mask | Exclusion bit mask of the shape. This mask is used to prevent collisions of the shape with other ones.形状的排除位掩码。此蒙版用于防止形状与其他形状发生碰撞。 |
Our video tutorial on physics contains an overview of the shape parameters and clarification on how to use the Exclusion and Collision masks.我們的物理視頻教程包含形狀參數的概述,並闡明瞭如何使用Exclusion和Collision蒙版。
Adding a Shape添加形状#
To add a shape via UnigineEditor, perform the following steps:要通过 UnigineEditor 添加形状,请执行以下步骤:
- Open the World Hierarchy window Open the World Hierarchy window
- Select an object you want to assign a physical shape to.选择要为其分配物理形状的对象。
- Go to the Physics tab in the Parameters window and assign a physical body to the selected object: a rigid body, ragdoll body or a dummy body. 转到菜单中的Physics标签Parameters窗口,然后为选定的对象分配物理主体:刚性主体,布娃娃主体或虚拟主体。
- In the Shapes section below choose an appropriate type of shape and click Add. 在下面的Shapes部分中,选择适当的形状类型,然后单击Add。
- Set necessary shape parameters.设置必要的形状参数。
You can enable visualization of shapes by checking Helpers panel → Physics item → Shapes option (Visualizer should be enabled).您可以通过选中Helpers面板→Physics项目→Shapes选项(应启用Visualizer)来启用形状的可视化。
Sphere领域#
A sphere is the simplest and the fastest shape, as it has only one parameter: a radius. Continuous collision detection is available for spherical shapes. Therefore, passing through other objects even when moving at a high speed is avoided. 球体是最简单,最快的形状,因为它只有一个参数:半径。连续碰撞检测可用于球形。因此,即使在高速移动时也避免穿过其他物体。
Using the spherical shape for any arbitrary mesh ensures that its collisions will always be detected.将球形用于任何任意网格可确保始终检测到其碰撞。
For a shape to fit your object, you can adjust the Radius of the sphere.要使形状适合您的对象,可以调整球体的 Radius 。
Capsule胶囊#
A capsule is also a very fast collision shape with continuous collision detection available. Capsules are convenient for approximation of elongated objects (pillars, etc.) as well as humanoid characters, because it allows them to go up and down the stairs smoothly, without stumbling at each step (if the steps are not too high). It also ensures that character's limb will not get stuck somewhere unexpectedly. 胶囊也是一种非常快速的碰撞形状,具有连续碰撞检测功能。胶囊便于拉长物体(支柱等)和类人动物角色,因为它使它们可以平稳地上下楼梯,而不会在每个步骤中绊脚(如果步骤不太高)。它还可以确保角色的肢体不会意外卡在某处。
For a shape to fit your object, you can adjust the Radius and the Height of the capsule.要使形状适合您的对象,您可以调整胶囊的半径和高度。
Cylinder圆筒#
A cylinder can be used to approximate elongated shapes with flat ends (e.g. a shafts, pylons, etc.). It is similar to a box shape. 圆柱可用于近似具有平坦端部的细长形状(例如,杆,塔等)。类似于盒子形状。
For a shape to fit your object, you can adjust the Radius and the Height of the cylinder.要使形状适合您的对象,可以调整圆柱的半径和高度。
Box框#
A box is a cuboid shape which can be used for approximation of volume of various objects. it is suitable for walls, doors, stairs, parts of mechanisms, car bodies, and many other things. The length of a box shape in each dimension can be chosen arbitrarily. 盒子是一个长方体形状,可用于近似各种对象的体积。它适用于墙壁,门,楼梯,机械零件,车身以及许多其他物体。每个尺寸的盒子形状的长度都可以任意选择。
For a shape to fit your object, you can adjust the size of the box along each axis: Size X, Size Y, Size Y.为使形状适合您的对象,您可以沿每个轴调整框的大小:Size X, Size Y, Size Y。
Convex Hull凸包#
Convex hull is the slowest of all shapes and is used for objects having complex geometry. The created shape will always be convex, that is, holes and cavities of the mesh are ignored when generating a convex hull. Instead, they are included into the shape volume. Convex shape is the smallest shape that can enclose vertices of the approximated mesh. Convex hull是所有形状中最慢的,用于具有复杂几何形状的对象。创建的形状将始终是凸形的,即,在生成凸包时,将忽略网格的孔和腔。而是将它们包含在形状体积中。凸形是可以包围近似网格顶点的最小形状。
To generate a convex hull specify an approximation error value:要生成凸包,请指定一个近似误差值:
The Approximation error parameter makes it possible to reduce the number of vertices of the created shape. Simple and rough convex hulls with small number of vertices are processed faster, therefore, it is recommended to keep the number of vertices as low as possible.使用Approximation error参数可以减少所创建形状的顶点数量。顶点数量少的简单且粗糙的凸包处理速度更快,因此,建议将顶点数量保持尽可能低。
- By the value of 0, the shape precisely duplicates the mesh; the whole volume of it is enclosed. 通过值 0 ,形状精确地复制了网格;它的全部体积都封闭起来。
- The higher the value, the less vertices there are in the created shape, but the more details are skipped.值越高,所创建的形状中的顶点越少,但是跳过的细节越多。
Approximation error = 0近似错误= 0
|
Approximation error = 0.1近似误差= 0.1
|
Autogenerated自动生成#
To approximate a complex concave object and exclude cavities from its volume, use a set of autogenerated convex hulls.要近似复杂的凹形对象并从其体积中排除腔,请使用组自动生成的凸形壳。
To add an autogenerated set of shapes specify the following parameters:要添加一组自动生成的形状,请指定以下参数:
Recursion depth determines the degree of mesh decomposition. If 0 or a negative value is provided, only one shape will be created. The higher the value, the more convex shapes are to be generated Recursion depth确定网格分解的程度。如果提供 0 或负值,则只会创建一个形状。值更高,将生成更多凸形
Approximation error makes it possible to reduce the number of vertices of generated shapes. Simple and rough convex hulls with small number of vertices are processed faster, therefore, it is recommended to keep the number of vertices as low as possible. Approximation error可以减少所生成形状的顶点数量。顶点数量少的简单且粗糙的凸包处理速度更快,因此,建议将顶点数量保持尽可能低。
- By the value of 0, the shape precisely duplicates the mesh; the whole volume of it is enclosed. 通过值 0 ,形状精确地复制了网格;它的全部体积都封闭起来。
- The higher the value, the less vertices there are in the created shape, but the more details are skipped.值更高,创建的形状中存在少个顶点,但是跳过了更多详细信息。
Merging threshold determines the volume threshold for merging convex shapes after decomposition and can be used to reduce the number of generated shapes: the higher the value, the less convex shapes are to be generated. Merging threshold确定分解后合并凸形的体积阈值,可用于减少生成的形状的数量:较高的值,较小的凸形是