Optimize flushing active transform of physically simulated actors

This commit is contained in:
2021-07-07 16:45:35 +02:00
parent d7b47d7d05
commit d1b7b2d26d
4 changed files with 21 additions and 19 deletions
@@ -22,6 +22,7 @@
#include "Engine/Scripting/Scripting.h"
#include "Engine/Scripting/Script.h"
#include "Engine/Engine/EngineService.h"
#include "Engine/Profiler/ProfilerCPU.h"
#include "Engine/Level/Level.h"
#include "FlaxEngine.Gen.h"
@@ -212,6 +213,7 @@ void ScriptsBuilder::Compile()
bool ScriptsBuilder::RunBuildTool(const StringView& args)
{
PROFILE_CPU();
const String buildToolPath = Globals::StartupFolder / TEXT("Binaries/Tools/Flax.Build.exe");
if (!FileSystem::FileExists(buildToolPath))
{
@@ -269,6 +271,7 @@ void ScriptsBuilderImpl::GetClassName(const MString& fullname, MString& classNam
MClass* ScriptsBuilder::FindScript(const StringView& scriptName)
{
PROFILE_CPU();
const MString scriptNameStd = scriptName.ToStringAnsi();
const ScriptingTypeHandle scriptingType = Scripting::FindScriptingType(scriptNameStd);
@@ -409,7 +409,9 @@ void CharacterController::OnTransformChanged()
const PxExtendedVec3 pos(_transform.Translation.X, _transform.Translation.Y, _transform.Translation.Z);
_controller->setPosition(pos);
UpdateScale();
const Vector3 scale = GetScale();
if (!Vector3::NearEqual(_cachedScale, scale))
UpdateGeometry();
UpdateBounds();
}
else if (!_controller)
+13 -13
View File
@@ -233,21 +233,13 @@ void Collider::Attach(RigidBody* rigidBody)
// Attach
rigidBody->GetPhysXRigidActor()->attachShape(*_shape);
_shape->setLocalPose(PxTransform(C2P((_localTransform.Translation + _localTransform.Orientation * _center) * rigidBody->GetScale()), C2P(_localTransform.Orientation)));
_cachedLocalPosePos = (_localTransform.Translation + _localTransform.Orientation * _center) * rigidBody->GetScale();
_cachedLocalPoseRot = _localTransform.Orientation;
_shape->setLocalPose(PxTransform(C2P(_cachedLocalPosePos), C2P(_cachedLocalPoseRot)));
if (rigidBody->IsDuringPlay())
rigidBody->UpdateBounds();
}
void Collider::UpdateScale()
{
const Vector3 scale = GetScale();
if (Vector3::NearEqual(_cachedScale, scale))
return;
// Recreate shape geometry
UpdateGeometry();
}
void Collider::UpdateLayerBits()
{
ASSERT(_shape);
@@ -519,10 +511,18 @@ void Collider::OnTransformChanged()
}
else if (const RigidBody* rigidBody = GetAttachedRigidBody())
{
_shape->setLocalPose(PxTransform(C2P((_localTransform.Translation + _localTransform.Orientation * _center) * rigidBody->GetScale()), C2P(_localTransform.Orientation)));
const Vector3 localPosePos = (_localTransform.Translation + _localTransform.Orientation * _center) * rigidBody->GetScale();
if (_cachedLocalPosePos != localPosePos || _cachedLocalPoseRot != _localTransform.Orientation)
{
_cachedLocalPosePos = localPosePos;
_cachedLocalPoseRot = _localTransform.Orientation;
_shape->setLocalPose(PxTransform(C2P(localPosePos), C2P(_cachedLocalPoseRot)));
}
}
UpdateScale();
const Vector3 scale = GetScale();
if (!Vector3::NearEqual(_cachedScale, scale))
UpdateGeometry();
UpdateBounds();
}
+2 -5
View File
@@ -26,6 +26,8 @@ protected:
PxRigidStatic* _staticActor;
Vector3 _cachedScale;
float _contactOffset;
Vector3 _cachedLocalPosePos;
Quaternion _cachedLocalPoseRot;
public:
@@ -166,11 +168,6 @@ public:
protected:
/// <summary>
/// Updates the shape scale (may be modified when actor transformation changes).
/// </summary>
void UpdateScale();
/// <summary>
/// Updates the shape actor collisions/queries layer mask bits.
/// </summary>