修复 动画播放 错误的bug

This commit is contained in:
xsl
2025-12-22 14:55:00 +08:00
parent 29e0c1e9a8
commit c83f36c976
3 changed files with 41 additions and 8 deletions
+9 -5
View File
@@ -692,10 +692,12 @@ void FaceApp::render(VkCommandBuffer commandBuffer, long long frameTime)
return; return;
} }
string curMotionName = _curMotions[_curMotionIndex].name;
int loadMotionIndex = motion_list_map[curMotionName];
//if (cur_left) //if (cur_left)
{ //{
vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, m_pipelineLayout, 0, 1, &m_descriptor_sets_left[_curMotionIndex], 0, NULL); vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, m_pipelineLayout, 0, 1, &m_descriptor_sets_left[loadMotionIndex], 0, NULL);
} //}
//else //else
//{ //{
// vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, m_pipelineLayout, 0, 1, &m_descriptor_sets_right[_curMotionIndex], 0, NULL); // vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, m_pipelineLayout, 0, 1, &m_descriptor_sets_right[_curMotionIndex], 0, NULL);
@@ -1478,8 +1480,10 @@ void FaceApp::loadMotionThread()
string path_name = path + "/" + _loadMotions[i].name + "ex.png"; string path_name = path + "/" + _loadMotions[i].name + "ex.png";
loadTexture(path_name, pre_texs[i], true, commandPool_ex); loadTexture(path_name, pre_texs[i], true, commandPool_ex);
#endif // _WIN32 #endif // _WIN32
}
motion_list_map[_loadMotions[i].name] = i;
}
update_descriptor_set(m_texs_left, m_descriptor_sets_left);
_isLoadMotion = false; _isLoadMotion = false;
_callback_loadfinish(); _callback_loadfinish();
} }
@@ -1532,7 +1536,7 @@ void FaceApp::changeMotionList(vector<string> motions, AnimationFinishedCallback
//} //}
//else //else
//{ //{
update_descriptor_set(m_texs_left, m_descriptor_sets_left); // update_descriptor_set(m_texs_left, m_descriptor_sets_left);
// cur_left = true; // cur_left = true;
//} //}
+4
View File
@@ -120,6 +120,10 @@ private:
const uint32_t kTextureInit = 1; const uint32_t kTextureInit = 1;
const uint32_t kTextureMax = 20; const uint32_t kTextureMax = 20;
vector<Texture> m_texs_left; vector<Texture> m_texs_left;
map<string, int> motion_list_map;
//vector<Texture> m_texs_right; //vector<Texture> m_texs_right;
//bool cur_left = true; //bool cur_left = true;
+28 -3
View File
@@ -49,7 +49,7 @@ void CppAnimationFinishedCallback()
void CppCallback() void CppCallback()
{ {
vector<string> motions = {"4", "11", "13"}; vector<string> motions = {"4"};
g_app->changeMotionList(motions, CppAnimationFinishedCallback, true); g_app->changeMotionList(motions, CppAnimationFinishedCallback, true);
} }
@@ -88,6 +88,27 @@ void loadMotions(const std::string& filePath, std::map<std::string, Motion>& mot
} }
} }
bool threadRun = false;
// 线程要执行的函数
void threadFunction() {
int startTime = 0;
for (int i = 0; i < 500; ++i)
{
if (!threadRun)
{
break;
}
startTime += 100;
if (startTime == 10 * 1000)
{
vector<string> motions = { "5" };
g_app->changeMotionList(motions, CppAnimationFinishedCallback, true);
}
std::this_thread::sleep_for(std::chrono::milliseconds(100)); // 暂停200ms
}
}
int main() { int main() {
@@ -143,13 +164,17 @@ int main() {
MotionList s_motions; MotionList s_motions;
s_motions.motions.push_back(motions["4"]); s_motions.motions.push_back(motions["4"]);
s_motions.motions.push_back(motions["11"]); s_motions.motions.push_back(motions["5"]);
s_motions.motions.push_back(motions["13"]); //s_motions.motions.push_back(motions["13"]);
json j = s_motions; json j = s_motions;
auto s = j.dump(); auto s = j.dump();
app.preLoadMotionList(s, CppCallback); app.preLoadMotionList(s, CppCallback);
threadRun = true;
std::thread t(threadFunction);
app.mainLoop(); app.mainLoop();
threadRun = false;
t.join();
//try { //try {
// app.mainLoop(); // app.mainLoop();
//} catch (const std::exception& e) { //} catch (const std::exception& e) {