完成动画序列播放

This commit is contained in:
xsl
2025-12-22 00:40:45 +08:00
parent 7b07e7fbc1
commit 29e0c1e9a8
775 changed files with 3022 additions and 654 deletions
+80 -46
View File
@@ -588,9 +588,9 @@ void FaceApp::setup_descriptor_set()
update_descriptor_set(m_texs_left, m_descriptor_sets_left);
m_descriptor_sets_right.resize(kTextureMax);
VK_CHECK(vkAllocateDescriptorSets(device, &alloc_info, m_descriptor_sets_right.data()));
update_descriptor_set(m_texs_left, m_descriptor_sets_right);
//m_descriptor_sets_right.resize(kTextureMax);
//VK_CHECK(vkAllocateDescriptorSets(device, &alloc_info, m_descriptor_sets_right.data()));
//update_descriptor_set(m_texs_left, m_descriptor_sets_right);
}
void FaceApp::update_descriptor_set(vector<Texture>& texs, vector<VkDescriptorSet>& descriptSet)
@@ -675,6 +675,7 @@ void FaceApp::render(VkCommandBuffer commandBuffer, long long frameTime)
std::unique_lock<std::mutex> lock(mtx);
std::unique_lock<std::mutex> lock_point(mtx_point);
std::unique_lock<std::mutex> lock_changeMotion(changeMotionMtx);
//Application::render(commandBuffer);
@@ -686,15 +687,19 @@ void FaceApp::render(VkCommandBuffer commandBuffer, long long frameTime)
vkCmdDraw(commandBuffer, 6, 1, 0, 0);
if (!_isChangeMostion)
{
return;
}
if (cur_left)
//if (cur_left)
{
vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, m_pipelineLayout, 0, 1, &m_descriptor_sets_left[_curMotionIndex], 0, NULL);
}
else
{
vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, m_pipelineLayout, 0, 1, &m_descriptor_sets_right[_curMotionIndex], 0, NULL);
}
//else
//{
// vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, m_pipelineLayout, 0, 1, &m_descriptor_sets_right[_curMotionIndex], 0, NULL);
//}
float fsValues[3] = { myFloatValue, 0 , 0};
if (_curMotionIndex < _curMotions.size())
@@ -763,7 +768,7 @@ void FaceApp::initVulkan()
createVmaAllocator();
LoadOBJ("face_picture_3dmax.obj", obj_vertices, obj_indices);
m_texs_left.resize(kTextureMax);
m_texs_right.resize(kTextureMax);
//m_texs_right.resize(kTextureMax);
if (kThick)
{
m_texs_thick.resize(kTextureMax);
@@ -774,12 +779,12 @@ void FaceApp::initVulkan()
for (int i = 0; i < kTextureInit; ++i)
{
string id_str = std::to_string(i);
loadTexture(dummy_data, dummy_data.size(), dummy_w, dummy_h, m_texs_left[i], true, commandPool, "dummy.png_left_" + id_str);
loadTexture(dummy_data, dummy_data.size(), dummy_w, dummy_h, m_texs_right[i], true, commandPool, "dummy.png_right_" + id_str);
//string id_str = std::to_string(i);
//loadTexture(dummy_data, dummy_data.size(), dummy_w, dummy_h, m_texs_left[i], true, commandPool, "dummy.png_left_" + id_str);
//loadTexture(dummy_data, dummy_data.size(), dummy_w, dummy_h, m_texs_right[i], true, commandPool, "dummy.png_right_" + id_str);
if (kThick)
{
loadTexture(dummy_data, dummy_data.size(), dummy_w, dummy_h, m_texs_thick[i], true, commandPool, "dummy.png_thick_" + id_str);
//loadTexture(dummy_data, dummy_data.size(), dummy_w, dummy_h, m_texs_thick[i], true, commandPool, "dummy.png_thick_" + id_str);
}
}
@@ -1286,7 +1291,7 @@ void FaceApp::cleanupResources(VkDevice device, VmaAllocator allocator) {
// 清空描述符集列表(不需要单独销毁,由描述符池管理)
m_descriptor_sets_left.clear();
m_descriptor_sets_right.clear();
//m_descriptor_sets_right.clear();
}
void FaceApp::cleanup()
@@ -1312,10 +1317,10 @@ void FaceApp::cleanup()
destroyTexture(device, m_texs_left[i]);
}
for (int i = 0; i < this->m_texs_right.size(); ++i)
{
destroyTexture(device, m_texs_right[i]);
}
//for (int i = 0; i < this->m_texs_right.size(); ++i)
//{
// destroyTexture(device, m_texs_right[i]);
//}
destroyTexture(device, tex_bg);
vkDestroyCommandPool(device, commandPool, nullptr);
@@ -1369,13 +1374,14 @@ void FaceApp::drawFrame(long long frameTime)
// }
// }
std::unique_lock lock(changeMotionMtx);
if (_curMotions.size() > 0)
{
static long long game_time = 0;
game_time += frameTime;
if (_playMotion)
{
game_time += frameTime;
}
long long actionTime = (1000 / _initArg.action_fps);
if (game_time > actionTime)
{
@@ -1429,10 +1435,10 @@ string FaceApp::preLoadMotionList(string motion_list_str, Callback callback)
}
_isLoadMotion = true;
_callback_loadfinish = callback;
_preLoadMotions.clear();
_loadMotions.clear();
json j = json::parse(motion_list_str);
MotionList motion_list = j.get<MotionList>();
_preLoadMotions = motion_list.motions;
_loadMotions = motion_list.motions;
worker_ = std::thread(&FaceApp::loadMotionThread, this);
return "ok";
}
@@ -1445,17 +1451,17 @@ void FaceApp::loadMotionThread()
}
vector<Texture>* load_text = nullptr;
if (cur_left)
{
load_text = &m_texs_right;
}
else
{
//if (cur_left)
//{
// load_text = &m_texs_right;
//}
//else
//{
load_text = &m_texs_left;
}
//}
vector<Texture>& pre_texs = *load_text;
for (int i = 0; i < _preLoadMotions.size(); ++i)
for (int i = 0; i < _loadMotions.size(); ++i)
{
if (pre_texs[i].image == VK_NULL_HANDLE)
{
@@ -1465,11 +1471,11 @@ void FaceApp::loadMotionThread()
#ifdef _WIN32
string path = "pic";
string path_name = path + "/" + _preLoadMotions[i].name + "/" + _preLoadMotions[i].name + "ex.png";
string path_name = path + "/" + _loadMotions[i].name + "ex.png";
loadTextureExample(UTF8ToWideString(path_name), pre_texs[i], true, commandPool_ex);
#else
string path = "pic";
string path_name = path + "/" + _preLoadMotions[i].name + "/" + _preLoadMotions[i].name + "ex.png";
string path_name = path + "/" + _loadMotions[i].name + "ex.png";
loadTexture(path_name, pre_texs[i], true, commandPool_ex);
#endif // _WIN32
}
@@ -1479,7 +1485,19 @@ void FaceApp::loadMotionThread()
}
void FaceApp::changeMotionList(AnimationFinishedCallback callback, bool loop)
Motion FaceApp::getMotionByName(string name)
{
for (auto m : _loadMotions)
{
if (m.name == name)
{
return m;
}
}
return Motion();
}
void FaceApp::changeMotionList(vector<string> motions, AnimationFinishedCallback callback, bool loop)
{
if (_isLoadMotion)
{
@@ -1499,26 +1517,42 @@ void FaceApp::changeMotionList(AnimationFinishedCallback callback, bool loop)
// //m_texs_next[i].reset();
//}
vector<Motion> motion_list;
for (auto ms : motions) {
Motion m = getMotionByName(ms);
motion_list.push_back(m);
}
if (cur_left)
{
update_descriptor_set(m_texs_right, m_descriptor_sets_right);
cur_left = false;
}
else
{
_curMotions = motion_list;
//if (cur_left)
//{
// update_descriptor_set(m_texs_right, m_descriptor_sets_right);
// cur_left = false;
//}
//else
//{
update_descriptor_set(m_texs_left, m_descriptor_sets_left);
cur_left = true;
}
// cur_left = true;
//}
_curMotions = _preLoadMotions;
_curFrameIndex = 0;
_curMotionIndex = 0;
_animationFinishedCallback = callback;
_animationLoop = loop;
_isChangeMostion = true;
}
}
void FaceApp::StopMotion() {
_playMotion = false;
}
void FaceApp::ResumeMotion() {
_playMotion = true;
}