130 lines
2.4 KiB
C++
130 lines
2.4 KiB
C++
#include "dl_actor.h"
|
|
|
|
#include <btBulletDynamicsCommon.h>
|
|
|
|
namespace dl
|
|
{
|
|
|
|
void Test()
|
|
{
|
|
btDefaultCollisionConfiguration* collisionConfiguration = new
|
|
btDefaultCollisionConfiguration();
|
|
}
|
|
|
|
void Actor::Update(real_time dt /*= 0*/)
|
|
{
|
|
if (!_boneAnimation)
|
|
{
|
|
debug_warn("角色没有蒙皮动画,不需要调用Update!");
|
|
return;
|
|
}
|
|
//更新蒙皮
|
|
//更新对应位置ubo
|
|
if (dt == 0)
|
|
dt = g_time->GetDelta();
|
|
_boneAnimation->Update(dt);
|
|
|
|
g_vk->UpdateUboBone(_boneAnimation->_id, _boneAnimation->_finalTrans);
|
|
}
|
|
|
|
|
|
void Actor::Render()
|
|
{
|
|
//--------------------rigidBody----------
|
|
if (_rigidBody)
|
|
{
|
|
g_physics->UpdateRigidBody(_rigidBody->GetImp(), _trans);
|
|
}
|
|
|
|
//--------------------render-------------
|
|
FactoryImp* imp = g_factory->GetImp();
|
|
|
|
dnd_assert(_idModel < imp->_allMulModel.size());
|
|
vector<Model*>& mul_model = imp->_allMulModel[_idModel];
|
|
|
|
//ub骨骼id
|
|
size_t id_bone = _boneAnimation ? _boneAnimation->_id : -1;
|
|
|
|
{
|
|
size_t id = g_vk->GetPushConstantNext();
|
|
VK::PushConstantData* p = g_vk->GetPushConstant(id);
|
|
if (p == nullptr)
|
|
{
|
|
debug_warn("Actor绘制数量过多,多余的将不会绘制!");
|
|
return;
|
|
}
|
|
p->_model = _trans->GetMatrixToWorld();
|
|
|
|
if (_color)
|
|
{
|
|
p->_color = *_color;
|
|
}
|
|
else
|
|
p->_color = { 1.0f, 1.0f, 1.0f, 1.0f };
|
|
|
|
for (auto& iter : mul_model)
|
|
iter->_mulNode.push_back({ id, id_bone });
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
size_t Actor::GetAniSize()
|
|
{
|
|
if (!_boneAnimation)
|
|
return 0;
|
|
BoneData* bone_data = _boneAnimation->_skinndeData;
|
|
return bone_data->_allAnimation.size();
|
|
}
|
|
|
|
std::string Actor::GetAniName(size_t i)
|
|
{
|
|
if (_no_bone_animation())
|
|
return {};
|
|
BoneData* bone_data = _boneAnimation->_skinndeData;
|
|
if (i >= bone_data->_allAnimation.size())
|
|
{
|
|
debug_err(format("动画下标越界:{}/{}", i, bone_data->_allAnimation.size()));
|
|
return {};
|
|
}
|
|
auto iter = bone_data->_allAnimation.begin();
|
|
advance(iter, i);
|
|
return iter->first;
|
|
}
|
|
void Actor::SwitchAni(string_view name)
|
|
{
|
|
if (_no_bone_animation())
|
|
return;
|
|
_boneAnimation->Set(name, -1.0f);
|
|
}
|
|
|
|
std::string Actor::GetAniCurrent()
|
|
{
|
|
if (_no_bone_animation())
|
|
return {};
|
|
return _boneAnimation->_clipName;
|
|
}
|
|
|
|
void Actor::CreateRigidBody()
|
|
{
|
|
dnd_assert(!_rigidBody);
|
|
_rigidBody = g_physics->CreateRigidBodyDefault(_trans);
|
|
}
|
|
|
|
Actor::~Actor()
|
|
{
|
|
delete _rigidBody;
|
|
delete _boneAnimation;
|
|
delete _trans;
|
|
}
|
|
|
|
bool Actor::_no_bone_animation()
|
|
{
|
|
if (!_boneAnimation)
|
|
{
|
|
debug_err("角色不存在骨骼动画!");
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
} |