Ported the actor and a few other places
* Fixed a bug with updating the static aabb for actors. It called that before the mesh was loaded resulting in an invalid aabb. * Ported a few more places to AZ::Aabb from MCore::AABB Signed-off-by: Benjamin Jillich <jillich@amazon.com>
This commit is contained in:
@@ -83,10 +83,10 @@ namespace AZ
|
||||
// Update RenderActorInstance world bounding box
|
||||
// The bounding box is moving with the actor instance.
|
||||
// The entity and actor transforms are kept in sync already.
|
||||
m_worldAABB = AZ::Aabb::CreateFromMinMax(m_actorInstance->GetAABB().GetMin(), m_actorInstance->GetAABB().GetMax());
|
||||
m_worldAABB = m_actorInstance->GetAabb();
|
||||
|
||||
// Update RenderActorInstance local bounding box
|
||||
// NB: computing the local bbox from the world bbox makes the local bbox artifically larger than it should be
|
||||
// NB: computing the local bbox from the world bbox makes the local bbox artificially larger than it should be
|
||||
// instead EMFX should support getting the local bbox from the actor instance directly
|
||||
m_localAABB = m_worldAABB.GetTransformedAabb(m_transformInterface->GetWorldTM().GetInverse());
|
||||
|
||||
@@ -107,9 +107,8 @@ namespace AZ
|
||||
{
|
||||
if (debugOptions.m_drawAABB)
|
||||
{
|
||||
const MCore::AABB emfxAabb = m_actorInstance->GetAABB();
|
||||
const AZ::Aabb azAabb = AZ::Aabb::CreateFromMinMax(emfxAabb.GetMin(), emfxAabb.GetMax());
|
||||
auxGeom->DrawAabb(azAabb, AZ::Color(0.0f, 1.0f, 1.0f, 1.0f), RPI::AuxGeomDraw::DrawStyle::Line);
|
||||
const AZ::Aabb& aabb = m_actorInstance->GetAabb();
|
||||
auxGeom->DrawAabb(aabb, AZ::Color(0.0f, 1.0f, 1.0f, 1.0f), RPI::AuxGeomDraw::DrawStyle::Line);
|
||||
}
|
||||
|
||||
if (debugOptions.m_drawSkeleton)
|
||||
|
||||
@@ -1063,11 +1063,10 @@ namespace CommandSystem
|
||||
continue;
|
||||
}
|
||||
|
||||
MCore::AABB newAABB;
|
||||
actorInstance->SetStaticBasedAABB(actor->GetStaticAABB()); // this is needed as the CalcStaticBasedAABB uses the current AABB as starting point
|
||||
actorInstance->CalcStaticBasedAABB(&newAABB);
|
||||
actorInstance->SetStaticBasedAABB(newAABB);
|
||||
//actorInstance->UpdateVisualizeScale();
|
||||
actorInstance->SetStaticBasedAabb(actor->GetStaticAabb()); // this is needed as the CalcStaticBasedAabb uses the current AABB as starting point
|
||||
AZ::Aabb newAabb;
|
||||
actorInstance->CalcStaticBasedAabb(&newAabb);
|
||||
actorInstance->SetStaticBasedAabb(newAabb);
|
||||
|
||||
const float factor = (float)MCore::Distance::GetConversionFactor(beforeUnitType, targetUnitType);
|
||||
actorInstance->SetVisualizeScale(actorInstance->GetVisualizeScale() * factor);
|
||||
|
||||
@@ -184,12 +184,12 @@ namespace ExporterLib
|
||||
EMotionFX::FileFormat::Actor_Nodes nodesChunk;
|
||||
nodesChunk.mNumNodes = numNodes;
|
||||
nodesChunk.mNumRootNodes = actor->GetSkeleton()->GetNumRootNodes();
|
||||
nodesChunk.mStaticBoxMin.mX = actor->GetStaticAABB().GetMin().GetX();
|
||||
nodesChunk.mStaticBoxMin.mY = actor->GetStaticAABB().GetMin().GetY();
|
||||
nodesChunk.mStaticBoxMin.mZ = actor->GetStaticAABB().GetMin().GetZ();
|
||||
nodesChunk.mStaticBoxMax.mX = actor->GetStaticAABB().GetMax().GetX();
|
||||
nodesChunk.mStaticBoxMax.mY = actor->GetStaticAABB().GetMax().GetY();
|
||||
nodesChunk.mStaticBoxMax.mZ = actor->GetStaticAABB().GetMax().GetZ();
|
||||
nodesChunk.mStaticBoxMin.mX = actor->GetStaticAabb().GetMin().GetX();
|
||||
nodesChunk.mStaticBoxMin.mY = actor->GetStaticAabb().GetMin().GetY();
|
||||
nodesChunk.mStaticBoxMin.mZ = actor->GetStaticAabb().GetMin().GetZ();
|
||||
nodesChunk.mStaticBoxMax.mX = actor->GetStaticAabb().GetMax().GetX();
|
||||
nodesChunk.mStaticBoxMax.mY = actor->GetStaticAabb().GetMax().GetY();
|
||||
nodesChunk.mStaticBoxMax.mZ = actor->GetStaticAabb().GetMax().GetZ();
|
||||
|
||||
// endian conversion and write it
|
||||
ConvertUnsignedInt(&nodesChunk.mNumNodes, targetEndianType);
|
||||
|
||||
@@ -97,6 +97,7 @@ namespace EMotionFX
|
||||
mID = MCore::GetIDGenerator().GenerateID();
|
||||
mUnitType = GetEMotionFX().GetUnitType();
|
||||
mFileUnitType = mUnitType;
|
||||
m_staticAabb = AZ::Aabb::CreateNull();
|
||||
|
||||
mUsedForVisualization = false;
|
||||
mDirtyFlag = false;
|
||||
@@ -148,7 +149,7 @@ namespace EMotionFX
|
||||
result->mMotionExtractionNode = mMotionExtractionNode;
|
||||
result->mUnitType = mUnitType;
|
||||
result->mFileUnitType = mFileUnitType;
|
||||
result->mStaticAABB = mStaticAABB;
|
||||
result->m_staticAabb = m_staticAabb;
|
||||
result->mRetargetRootNode = mRetargetRootNode;
|
||||
result->mInvBindPoseTransforms = mInvBindPoseTransforms;
|
||||
result->m_optimizeSkeleton = m_optimizeSkeleton;
|
||||
@@ -1405,10 +1406,6 @@ namespace EMotionFX
|
||||
|
||||
m_simulatedObjectSetup->InitAfterLoad(this);
|
||||
|
||||
// build the static axis aligned bounding box by creating an actor instance (needed to perform cpu skinning mesh deforms and mesh scaling etc)
|
||||
// then copy it over to the actor
|
||||
UpdateStaticAABB();
|
||||
|
||||
// rescale all content if needed
|
||||
if (convertUnitType)
|
||||
{
|
||||
@@ -1526,6 +1523,10 @@ namespace EMotionFX
|
||||
mMorphSetups[i] = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
// build the static axis aligned bounding box by creating an actor instance (needed to perform cpu skinning mesh deforms and mesh scaling etc)
|
||||
// then copy it over to the actor
|
||||
UpdateStaticAabb();
|
||||
}
|
||||
|
||||
m_isReady = true;
|
||||
@@ -1534,16 +1535,13 @@ namespace EMotionFX
|
||||
}
|
||||
|
||||
// update the static AABB (very heavy as it has to create an actor instance, update mesh deformers, calculate the mesh based bounds etc)
|
||||
void Actor::UpdateStaticAABB()
|
||||
void Actor::UpdateStaticAabb()
|
||||
{
|
||||
if (!mStaticAABB.CheckIfIsValid())
|
||||
{
|
||||
ActorInstance* actorInstance = ActorInstance::Create(this, nullptr, mThreadIndex);
|
||||
//actorInstance->UpdateMeshDeformers(0.0f);
|
||||
//actorInstance->UpdateStaticBasedAABBDimensions();
|
||||
actorInstance->GetStaticBasedAABB(&mStaticAABB);
|
||||
actorInstance->Destroy();
|
||||
}
|
||||
ActorInstance* actorInstance = ActorInstance::Create(this, nullptr, mThreadIndex);
|
||||
actorInstance->UpdateMeshDeformers(0.0f);
|
||||
actorInstance->UpdateStaticBasedAabbDimensions();
|
||||
actorInstance->GetStaticBasedAabb(&m_staticAabb);
|
||||
actorInstance->Destroy();
|
||||
}
|
||||
|
||||
|
||||
@@ -2206,14 +2204,14 @@ namespace EMotionFX
|
||||
#endif
|
||||
}
|
||||
|
||||
const MCore::AABB& Actor::GetStaticAABB() const
|
||||
const AZ::Aabb& Actor::GetStaticAabb() const
|
||||
{
|
||||
return mStaticAABB;
|
||||
return m_staticAabb;
|
||||
}
|
||||
|
||||
void Actor::SetStaticAABB(const MCore::AABB& box)
|
||||
void Actor::SetStaticAabb(const AZ::Aabb& aabb)
|
||||
{
|
||||
mStaticAABB = box;
|
||||
m_staticAabb = aabb;
|
||||
}
|
||||
|
||||
//---------------------------------
|
||||
@@ -2422,8 +2420,8 @@ namespace EMotionFX
|
||||
}
|
||||
|
||||
// update static aabb
|
||||
mStaticAABB.SetMin(mStaticAABB.GetMin() * scaleFactor);
|
||||
mStaticAABB.SetMax(mStaticAABB.GetMax() * scaleFactor);
|
||||
m_staticAabb.SetMin(m_staticAabb.GetMin() * scaleFactor);
|
||||
m_staticAabb.SetMax(m_staticAabb.GetMax() * scaleFactor);
|
||||
|
||||
// update mesh data for all LOD levels
|
||||
const uint32 numLODs = GetNumLODLevels();
|
||||
|
||||
@@ -16,11 +16,11 @@
|
||||
#include <AzCore/std/smart_ptr/unique_ptr.h>
|
||||
#include <AzCore/std/string/string.h>
|
||||
#include <AzCore/std/typetraits/integral_constant.h>
|
||||
#include <AzCore/Math/AABB.h>
|
||||
#include <AzCore/Math/Vector3.h>
|
||||
#include <AzCore/Math/Color.h>
|
||||
|
||||
// include MCore related files
|
||||
#include <MCore/Source/AABB.h>
|
||||
#include <MCore/Source/Vector.h>
|
||||
#include <MCore/Source/Array.h>
|
||||
#include <MCore/Source/SmallArray.h>
|
||||
@@ -781,9 +781,9 @@ namespace EMotionFX
|
||||
void ResizeTransformData();
|
||||
void CopyTransformsFrom(const Actor* other);
|
||||
|
||||
const MCore::AABB& GetStaticAABB() const;
|
||||
void SetStaticAABB(const MCore::AABB& box);
|
||||
void UpdateStaticAABB(); // VERY heavy operation, you shouldn't call this ever (internally creates an actor instance, updates mesh deformers, calcs a mesh based aabb, destroys the actor instance again)
|
||||
const AZ::Aabb& GetStaticAabb() const;
|
||||
void SetStaticAabb(const AZ::Aabb& aabb);
|
||||
void UpdateStaticAabb(); // VERY heavy operation, you shouldn't call this ever (internally creates an actor instance, updates mesh deformers, calcs a mesh based aabb, destroys the actor instance again)
|
||||
|
||||
void SetThreadIndex(uint32 index) { mThreadIndex = index; }
|
||||
uint32 GetThreadIndex() const { return mThreadIndex; }
|
||||
@@ -985,7 +985,7 @@ namespace EMotionFX
|
||||
uint32 mRetargetRootNode; /**< The retarget root node, which controls the height displacement of the character. This is most likely the hip or pelvis node. */
|
||||
uint32 mID; /**< The unique identification number for the actor. */
|
||||
uint32 mThreadIndex; /**< The thread number we are running on, which is a value starting at 0, up to the number of threads in the job system. */
|
||||
MCore::AABB mStaticAABB; /**< The static AABB. */
|
||||
AZ::Aabb m_staticAabb; /**< The static AABB. */
|
||||
bool mDirtyFlag; /**< The dirty flag which indicates whether the user has made changes to the actor since the last file save operation. */
|
||||
bool mUsedForVisualization; /**< Indicates if the actor is used for visualization specific things and is not used as a normal in-game actor. */
|
||||
bool m_optimizeSkeleton; /**< Indicates if we should perform/ */
|
||||
|
||||
Reference in New Issue
Block a user