unity2018.4.3_Unity 2018.3 Beta中的物理变化

unity2018.4.3

The main change Unity 2018.3 brings to physics is the 3D physics engine upgrade, from PhysX 3.3.3 to PhysX 3.4.2. It’s the first time we ship the latest available version of PhysX to date. We aim to improve performance and stability and make it extremely easy for you to upgrade your project. Read this post to learn more about the upgrade and all the specific changes and new features related to working with physics in 2018.3.

Unity 2018.3给物理带来的主要变化是3D物理引擎升级,从PhysX 3.3.3升级到PhysX 3.4.2。 迄今为止,这是我们第一次发布PhysX的最新可用版本。 我们旨在提高性能和稳定性,并使您的项目升级变得非常容易。 阅读这篇文章以了解有关2018.3.2中与物理相关的升级以及所有特定更改和新功能的更多信息。

PhysX 3.4 represents several years of progress in the area of computational physics. We used to wait for a year or so to let the new version of PhysX mature, before shipping it in Unity. This time around we’re shipping the latest one, after having put as much effort into testing as possible.

PhysX 3.4代表了计算物理学领域的几年进步。 我们过去通常需要等待一年左右的时间才能使新版本的PhysX成熟,然后再将其发布到Unity中。 这次我们将尽最大努力进行测试,然后再发布最新的。

We’re also going light on new features this time around, to pay more attention to the core stuff that was already working. We aim at as fewer regressions as possible. Join the Unity 2018.3 beta and try it for yourself!

这次,我们还将介绍新功能,以更多地关注已经在工作的核心内容。 我们的目标是尽可能减少回归。 加入Unity 2018.3 beta并亲自尝试!

PhysX 3.4升级 (PhysX 3.4 upgrade)

PhysX 3.4 is a big release that brings visible improvement in a whole bunch of various ways. Firstly, it addresses a significant amount of bugs. For instance, it significantly improves convex-convex collision detection and feedback, so that there are no more any odd bumps from the ground when the PCM collision detection is enabled. Physics queries against thin and long tri angles have been improved. Another example is the improved precision of contacts computation with Terrain. Secondly, the physics engine now saturates the threads with physics jobs much better. Broadphase, collision detection and the solver were re-written to be decomposed into as many atomic jobs as possible. As a result, you should see the time it took to simulate a frame to be lower than before.

PhysX 3.4是一个重要版本,以各种方式带来了明显的改进。 首先,它解决了大量的错误。 例如,它显着改善了凹凸碰撞检测和反馈,从而在启用PCM碰撞检测时不再有来自地面的奇异凸起。 针对细和长三角的物理查询已得到改进。 另一个例子是使用Terrain改进了联系人计算的精度。 其次,物理引擎现在可以更好地使线程充满物理工作。 重写了广相,碰撞检测和求解器,以分解为尽可能多的原子作业。 结果,您应该看到模拟框架所花费的时间比以前要少。

Thirdly, the physics queries module is now up to two times faster than before.

第三,物理查询模块现在的速度比以前快了两倍。

There are a lot of great new things added to PhysX 3.4, read on to learn more about the features that we support in Unity 2018.3.

PhysX 3.4中添加了很多很棒的新东西,请继续阅读以了解有关Unity 2018.3中我们支持的功能的更多信息。

多场景物理 (Multi-scene physics)

We used to have only one physics scene that we populated with all the bodies and colliders from all your Unity scenes. Certainly, there are particular cases where this is limiting, so we have now enabled you to create multiple physics scenes. With that change, you can now specify whether a given Unity scene uses the default physics scene, or needs its own local one. The extra scenes are just like the default one, with the exception that all the usual Physics.* APIs will ignore them, because all the scenes are created completely independent. There is a number of ways to use the extra scenes. You can simulate them with PhysicsScene.Simulate on any frequency (think multiple parts of your world simulated with different frequencies). Another interesting option is to create an invisible physics scene to predict trajectories. This improvement is available to both 3D and 2D physics.

我们过去只有一个物理场景,其中填充了所有Unity场景中的所有物体和对撞机。 当然,在某些情况下这是有限制的,因此我们现在使您能够创建多个物理场景。 进行更改后,您现在可以指定给定的Unity场景是使用默认物理场景,还是需要自己的局部场景。 除了所有通常的Physics。* API都会忽略它们之外,其他场景与默认场景一样,因为所有场景都是完全独立创建的。 有多种使用额外场景的方法。 您可以使用PhysicsScene对其进行仿真。可以在任何频率上进行仿真(请考虑使用不同的频率对您的世界进行模拟)。 另一个有趣的选择是创建一个不可见的物理场景来预测轨迹。 此改进适用于3D和2D物理。

更多批处理查询 (More batched queries)

Batched physics queries is a way to run physics queries off the main thread. This API is needed because one can’t execute the usual API from another thread. In Unity 2018.1, we shipped RaycastCommand.ScheduleBatch that helps to compute raycasts off the main thread. In Unity 2018.3, we’re extending this to add the other single-result queries like SphereCast, CapsuleCast and BoxCast. We’re figuring out the technical limitations that prevent us from exposing the multiple-result queries like overlaps and sweeps for future releases.

批处理物理查询是一种在主线程之外运行物理查询的方法。 需要该API,因为一个人不能从另一个线程执行通常的API。 在Unity 2018.1中,我们发布了RaycastCommand.ScheduleBatch,可帮助计算主线程的射线广播。 在Unity 2018.3中,我们将其扩展为添加其他单结果查询,例如SphereCast,CapsuleCast和BoxCast。 我们正在解决一些技术限制,这些技术限制使我们无法为将来的版本公开多重结果查询,例如重叠和清除。

增强的确定性 (Enhanced determinism)

PhysX guarantees the same simulation result when all the inputs are exactly the same. However, many things are considered “input” from the perspective of the physics engine. One such thing is the physics scene itself. Before 2018.3, it wasn’t possible to destroy the implicit physics scene. One could only destroy all the objects in it, which formally wasn’t enough. With multi-scene physics, this is easy to work around. However, another frequent issue was that adding a new body located somewhere far away and seemingly not interacting with the other objects also had the potential to change the simulation outcome. That was because of the way PhysX in Unity grouped objects internally. This is now possible to overcome by enabling a special option in the physics settings. It’s not free in terms of performance, but it shouldn’t slow your project down significantly.

当所有输入完全相同时,PhysX保证相同的仿真结果。 但是,从物理引擎的角度来看,许多东西被认为是“输入”。 其中之一就是物理场景本身。 在2018.3之前,不可能破坏隐式物理场景。 一个人只能摧毁其中的所有物体,这还远远不够。 使用多场景物理,这很容易解决。 但是,另一个经常出现的问题是,添加一个位于较远某处且似乎不与其他对象相互作用的新物体也可能会更改模拟结果。 这是因为Unity中PhysX在内部对对象进行分组的方式。 现在,可以通过在物理设置中启用特殊选项来克服这一问题。 就性能而言,它不是免费的,但不应显着降低项目速度。

统一的高度图 (Unified heightmaps)

TerrainCollider used a special collision detection algorithm that revolved around some inaccurate assumptions when computing contacts as well as a few unobvious features alike terrain thickness. In Unity 2018.3, the collision detection approach used is the same as when computing contacts with meshes.

TerrainCollider使用了一种特殊的碰撞检测算法,该算法围绕计算接触时的一些不准确假设以及地形厚度等一些不明显的特征展开。 在Unity 2018.3中,使用的碰撞检测方法与计算带有网格的接触时相同。

推测性连续碰撞检测 (Speculative continuous collision detection)

Continuous collision detection has been an option in Unity for a while. However, the linear nature of the process was a common problem. All it did internally was to sweep the bodies some specific distance forward along the velocity vector to compute the time until next hit. This model didn’t allow for rotations support.

一段时间以来,连续碰撞检测一直是Unity中的一个选项。 但是,该方法的线性性质是一个普遍的问题。 它在内部所做的只是将物体沿速度矢量向前扫过特定距离,以计算直到下一次命中的时间。 此模型不允许旋转支持。

The simplest example of a game where that’s problematic is Pinball, where the flippers rotate fast while not being linearly moving at all. This is no longer a problem with the alternative continuous collision detection algorithm added in the 2018.3 release. It works by inflating the contact offsets that affect the generation of contact points. It generates the actual contact manifold once the objects are close enough according to that inflated distance. The predictive linear sweeps are no longer used in that mode, so it tends to be more accurate by detecting overlaps with all sorts of bodies being rotated or moved in a fast manner.

问题最简单的游戏示例是弹球游戏(Pinball),其中脚蹼快速旋转而完全不线性移动。 对于2018.3版本中添加的替代连续碰撞检测算法,这不再是问题。 它通过增加影响接触点生成的接触偏移来工作。 一旦物体根据膨胀距离足够近,它将生成实际的接触歧管。 预测线性扫描不再在该模式下使用,因此通过检测与快速旋转或移动的各种物体的重叠而趋向于更加精确。

Before: After:
之前 : 后:

方向摩擦 (Directional friction)

We’re introducing new friction modes: single-directional friction and two-directional friction. The default friction model works by creating up to four scalar constraints per contact pair. This is the fastest model to compute, and it also converges fast, not requiring too many solver iterations. Both of the single-directional and two-directional friction modes work on a per contact point basis, not per contact pair. It’s potentially more accurate, but also requires more solver iterations to converge and, in case your project generates many contact points per contact pair, it can slow your project down.

我们正在引入新的摩擦模式:单向摩擦和双向摩擦。 默认的摩擦模型通过每个接触对最多创建四个标量约束来工作。 这是计算速度最快的模型,并且收敛速度很快,不需要太多的求解器迭代。 单向和双向摩擦模式均基于每个触点而不是每个触点对工作。 它可能更准确,但是也需要更多的求解器迭代才能收敛,并且如果您的项目为每个联系对生成许多联系点,则可能会使您的项目放慢速度。

在新项目中没有自动转换同步 (No automatic transform syncing in new projects)

By default, all the changes to Unity transforms were synced to the physics engine right before they might be needed. That is, every time a raycast is run, every time a simulation is run and so on. Syncing isn’t the fastest operation, and it makes sense to reduce the number of times it’s called. For that reason, we have a setting that turns off all the automatic sync points. You’re responsible for calling Physics.SyncTransforms, as otherwise transforms are synced only right before the simulation (=FixedUpdate).

默认情况下,对Unity转换的所有更改都将在需要之前立即同步到物理引擎。 也就是说,每次运行射线广播,每次运行模拟等等。 同步并不是最快的操作,因此减少调用次数是有意义的。 因此,我们有一个关闭所有自动同步点的设置。 您负责调用Physics.SyncTransforms,否则将仅在模拟(= FixedUpdate)之前同步转换。

Another problem with the sync points is that syncing itself can only happen on the main thread. That means, for instance, that you can’t have a raycast that includes syncing. Generally, as Unity becomes a more multi-threaded engine, it’s increasingly more often that new projects need to have the automatic sync points off. That said, we’re changing the default value of Physics.autoSyncTransforms from true to false for all new projects starting this release. This improvement is available to both 3D and 2D physics.

同步点的另一个问题是同步本身只能在主线程上发生。 例如,这意味着您不能进行包含同步的光线广播。 通常,随着Unity成为一个多线程引擎,新项目需要关闭自动同步点的频率越来越高。 也就是说,对于此版本开始的所有新项目,我们将Physics.autoSyncTransforms的默认值从true更改为false。 此改进适用于3D和2D物理。

获得联系而无垃圾 (Obtaining contacts without garbage)

Getting contacts information has always caused some unavoidable managed heap allocations. The allocations were made to pass in the instances of the Collision structure to the handlers in scripts (=OnContactStay for instance), as well as the arrays of contact points. Depending on the frequency of the events, it could hurt performance of certain projects.

获取联系人信息始终会导致一些不可避免的托管堆分配。 进行了分配,以将Collision结构的实例传递给脚本中的处理程序(例如= OnContactStay)以及接触点数组。 根据事件的频率,它可能会损害某些项目的性能。

In 2018.3, we introduce a new property Physics.reuseCollisionCallbacks, which is off by default to keep the behavior consistent when you’re upgrading your existing projects. However, if you turn it on, the Collision instances are going to be shared. Effectively, it means that there is only one instance of the Collision class that is reused every time the callbacks are fired. As a consequence of that, there will no longer be any garbage produced. However, the collision information you receive in the callbacks has to be copied manually if needed. This improvement is available to both 3D and 2D physics.

在2018.3中,我们引入了新属性Physics.reuseCollisionCallbacks,默认情况下该属性处于禁用状态,以在升级现有项目时保持行为一致。 但是,如果打开它,则Collision实例将被共享。 实际上,这意味着每次触发回调时,只有Collision类的一个实例可以重用。 结果,将不再产生任何垃圾。 但是,如果需要,您必须手动复制在回调中收到的冲突信息。 此改进适用于3D和2D物理。

追求品质 (Drive for quality)

We have a goal of making this release very easy to upgrade to. To achieve that, we dedicated a lot more hours of testing and reviewing than ever before. First, we’ve sent out builds to early adopters. Then, we’ve made a limited functionality upgrade work in Unity 2018.2 and made it available for testing as a spin-off build during 2018.2 alpha. Afterward, once 2018.2 went public, we’ve started a forum thread and invited enthusiasts to provide feedback. This resulted in a pretty productive discussion with a few bugs fixed, and some features added too. Once 2018.3 beta became a thing, we’ve merged our upgrade branch there, and right now it’s used in more than 10000 editor sessions a week. We’re still looking for feedback though, so join the beta and talk to us on the Physics forum or the 2018.3 beta forum!

我们的目标是使此版本非常容易升级。 为了实现这一目标,我们投入了比以往更多的时间进行测试和审查。 首先,我们已将构建版本发送给早期采用者。 然后,我们在Unity 2018.2中进行了有限的功能升级工作,并将其作为2018.2 alpha期间的衍生版本进行测试。 之后,一旦2018.2公开,我们就启动了一个论坛主题,并邀请发烧友提供反馈。 这导致了相当有成果的讨论,其中修复了一些错误,并且还添加了一些功能。 一旦2018.3 beta变成了事情,我们就在这里合并了我们的升级分支,现在每周有超过10000次编辑器会话使用它。 我们仍然在寻找反馈,因此请加入Beta版,并在Physics论坛2018.3 Beta版论坛上与我们联系!

翻译自: https://blogs.unity3d.com/2018/11/12/physics-changes-in-unity-2018-3-beta/

unity2018.4.3

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值