Crude optimizations

From testing with model of around 50 bones, I could get 64+ animated models on the screen with 150fps+
This commit is contained in:
Antoine Pilote
2023-09-08 00:33:57 -04:00
parent 36646a0990
commit 190c36b910
4 changed files with 17 additions and 5 deletions

View File

@@ -13,5 +13,6 @@ namespace Nuake
std::vector<SkeletonNode> Children;
Matrix4 FinalTransform = Matrix4(1.0f);
int32_t Id = -1;
int32_t EntityHandle = 0;
};
}

View File

@@ -24,7 +24,11 @@ namespace Nuake
{
BEGIN_SERIALIZE();
SERIALIZE_VAL(ModelPath);
SERIALIZE_OBJECT(ModelResource);
if (ModelResource)
{
SERIALIZE_OBJECT(ModelResource);
}
END_SERIALIZE();
}

View File

@@ -484,9 +484,11 @@ namespace Nuake
auto& skeletonRoot = component.ModelResource->GetSkeletonRootNode();
Entity skeletonRootEntity = CreateEntity(skeletonRoot.Name);
skeletonRootEntity.AddComponent<BoneComponent>();
skeletonRootEntity.AddComponent<BoneComponent>().Name = skeletonRoot.Name;
skeletonRoot.EntityHandle = skeletonRootEntity.GetHandle();
entity.AddChild(skeletonRootEntity);
Vector3 bonePosition;
Quat boneRotation;
Vector3 boneScale;
@@ -509,6 +511,8 @@ namespace Nuake
boneEntity.AddComponent<BoneComponent>();
entity.AddChild(boneEntity);
c.EntityHandle = boneEntity.GetHandle();
Vector3 bonePosition;
Quat boneRotation;
Vector3 boneScale;

View File

@@ -50,12 +50,14 @@ namespace Nuake
auto& animationTrack = animation->GetTrack(boneName);
Entity& boneEntity = m_Scene->GetEntity(boneName);
if (boneEntity.GetHandle() != -1)
Entity& boneEnt = Entity{ (entt::entity)bone.EntityHandle, m_Scene };
///assert(boneEnt.GetHandle() == boneEntity.GetHandle());
if (boneEnt.GetHandle() != 0)
{
auto& transformComponent = boneEntity.GetComponent<TransformComponent>();
auto& transformComponent = boneEnt.GetComponent<TransformComponent>();
bone.FinalTransform = transformComponent.GetGlobalTransform() * bone.Offset;
if (!animationTrack.IsEmpty())
//if (!animationTrack.IsEmpty())
{
// Get Update transform
animationTrack.Update(time);
@@ -74,6 +76,7 @@ namespace Nuake
transformComponent.Dirty = false;
}
}
for (auto& childBone : bone.Children)
{
UpdateBonePositionTraversal(childBone, animation, time);