Merge branch 'multiple_physics_scenes' of git://github.com/iainmckay/FlaxEngine into iainmckay-multiple_physics_scenes

This commit is contained in:
Wojtek Figat
2022-01-10 20:13:55 +01:00
29 changed files with 2359 additions and 1350 deletions

View File

@@ -17,6 +17,7 @@
#include "Engine/Debug/Exceptions/JsonParseException.h"
#include "Engine/Graphics/RenderTask.h"
#include "Engine/Graphics/RenderView.h"
#include "Engine/Physics/Physics.h"
#include "Engine/Profiler/ProfilerCPU.h"
#include "Engine/Scripting/Scripting.h"
#include "Engine/Serialization/ISerializeModifier.h"
@@ -77,6 +78,7 @@ Actor::Actor(const SpawnParams& params)
, _transform(Transform::Identity)
, _sphere(BoundingSphere::Empty)
, _box(BoundingBox::Zero)
, _physicsScene(nullptr)
, HideFlags(HideFlags::None)
{
}
@@ -1809,3 +1811,28 @@ void Actor::FromJson(const StringAnsiView& json)
Scripting::ObjectsLookupIdMapping.Set(nullptr);
OnTransformChanged();
}
void Actor::SetPhysicsScene(PhysicsScene* scene)
{
ASSERT(scene);
auto previous = GetPhysicsScene();
_physicsScene = scene;
if (previous != _physicsScene)
{
OnPhysicsSceneChanged(previous);
// cascade
for (auto child : Children)
child->SetPhysicsScene(scene);
}
}
PhysicsScene* Actor::GetPhysicsScene()
{
if (_physicsScene == nullptr)
_physicsScene = Physics::DefaultScene;
return _physicsScene;
}

View File

@@ -14,6 +14,7 @@ struct RenderView;
struct RenderContext;
class GPUContext;
class MemoryWriteStream;
class PhysicsScene;
class SceneRendering;
class SceneRenderTask;
@@ -47,6 +48,7 @@ protected:
BoundingSphere _sphere;
BoundingBox _box;
String _name;
PhysicsScene* _physicsScene;
private:
@@ -959,6 +961,20 @@ public:
/// <returns>The scene rendering interface.</returns>
SceneRendering* GetSceneRendering() const;
public:
/// <summary>
/// Set the physics world the controller is part of.
/// </summary>
API_PROPERTY(Attributes="HideInEditor") void SetPhysicsScene(PhysicsScene* scene);
/// <summary>
/// Get the physics world the controller is part of.
/// </summary>
API_PROPERTY(Attributes="HideInEditor") PhysicsScene* GetPhysicsScene();
protected:
virtual void OnPhysicsSceneChanged(PhysicsScene* previous) {};
private:
void SetSceneInHierarchy(Scene* scene);

View File

@@ -181,6 +181,8 @@ bool LevelImpl::spawnActor(Actor* actor, Actor* parent)
}
if (parent == nullptr)
parent = Level::Scenes[0];
actor->SetPhysicsScene(parent->GetPhysicsScene());
actor->SetParent(parent, true, true);
}