Move managed code into native impl for #2063
This commit is contained in:
@@ -1,56 +0,0 @@
|
|||||||
#if FLAX_EDITOR
|
|
||||||
using FlaxEditor.CustomEditors;
|
|
||||||
using FlaxEditor.CustomEditors.Dedicated;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace FlaxEngine
|
|
||||||
{
|
|
||||||
partial class BoxCollider
|
|
||||||
{
|
|
||||||
private void BoxExcluding(Actor target, ref BoundingBox output, Actor excluded)
|
|
||||||
{
|
|
||||||
foreach (Actor child in target.Children)
|
|
||||||
{
|
|
||||||
if (child == excluded)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
output = BoundingBox.Merge(output, child.Box);
|
|
||||||
BoxExcluding(child, ref output, excluded);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Resizes the box collider based on the bounds of it's parent.
|
|
||||||
/// </summary>
|
|
||||||
public void AutoResize()
|
|
||||||
{
|
|
||||||
if (Parent is Scene)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
LocalPosition = Vector3.Zero;
|
|
||||||
|
|
||||||
Vector3 parentScale = Parent.Scale;
|
|
||||||
BoundingBox parentBox = Parent.Box;
|
|
||||||
BoxExcluding(Parent, ref parentBox, this);
|
|
||||||
|
|
||||||
Vector3 parentSize = parentBox.Size;
|
|
||||||
Vector3 parentCenter = parentBox.Center - Parent.Position;
|
|
||||||
|
|
||||||
// Avoid division by zero
|
|
||||||
if (parentScale.X == 0 || parentScale.Y == 0 || parentScale.Z == 0)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Size = parentSize / parentScale;
|
|
||||||
Center = parentCenter / parentScale;
|
|
||||||
|
|
||||||
// Undo Rotation
|
|
||||||
Orientation *= Quaternion.Invert(Orientation);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include "BoxCollider.h"
|
#include "BoxCollider.h"
|
||||||
#include "Engine/Physics/PhysicsBackend.h"
|
#include "Engine/Physics/PhysicsBackend.h"
|
||||||
|
#include "Engine/Level/Scene/Scene.h"
|
||||||
|
|
||||||
BoxCollider::BoxCollider(const SpawnParams& params)
|
BoxCollider::BoxCollider(const SpawnParams& params)
|
||||||
: Collider(params)
|
: Collider(params)
|
||||||
@@ -19,6 +20,32 @@ void BoxCollider::SetSize(const Float3& value)
|
|||||||
UpdateBounds();
|
UpdateBounds();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BoxCollider::AutoResize()
|
||||||
|
{
|
||||||
|
Actor* parent = GetParent();
|
||||||
|
if (Cast<Scene>(parent))
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Get bounds of all siblings (excluding itself)
|
||||||
|
const Vector3 parentScale = parent->GetScale();
|
||||||
|
if (parentScale.IsAnyZero())
|
||||||
|
return; // Avoid division by zero
|
||||||
|
BoundingBox parentBox = parent->GetBox();
|
||||||
|
for (const Actor* sibling : parent->Children)
|
||||||
|
{
|
||||||
|
if (sibling != this)
|
||||||
|
BoundingBox::Merge(parentBox, sibling->GetBoxWithChildren(), parentBox);
|
||||||
|
}
|
||||||
|
const Vector3 parentSize = parentBox.GetSize();
|
||||||
|
const Vector3 parentCenter = parentBox.GetCenter() - parent->GetPosition();
|
||||||
|
|
||||||
|
// Update bounds
|
||||||
|
SetLocalPosition(Vector3::Zero);
|
||||||
|
SetSize(parentSize / parentScale);
|
||||||
|
SetCenter(parentCenter / parentScale);
|
||||||
|
SetOrientation(GetOrientation() * Quaternion::Invert(GetOrientation()));
|
||||||
|
}
|
||||||
|
|
||||||
#if USE_EDITOR
|
#if USE_EDITOR
|
||||||
|
|
||||||
#include "Engine/Debug/DebugDraw.h"
|
#include "Engine/Debug/DebugDraw.h"
|
||||||
|
|||||||
@@ -43,6 +43,11 @@ public:
|
|||||||
return _bounds;
|
return _bounds;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Resizes the collider based on the bounds of it's parent to contain it whole (including any siblings).
|
||||||
|
/// </summary>
|
||||||
|
API_FUNCTION() void AutoResize();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// [Collider]
|
// [Collider]
|
||||||
#if USE_EDITOR
|
#if USE_EDITOR
|
||||||
|
|||||||
Reference in New Issue
Block a user