添加了动画,资源也改为英文名了

This commit is contained in:
xsl
2025-10-26 21:54:34 +08:00
parent b2da84f903
commit 57b7c40835
16 changed files with 66 additions and 37 deletions
+9 -7
View File
@@ -127,8 +127,11 @@ void Application::mainLoop()
#ifdef _WIN32
while (!glfwWindowShouldClose(window))
{
auto cur_time = getCurrentTimeMillis();
glfwPollEvents();
drawFrame(); // 在这里调用
auto functionTime = (cur_time - _lastDrawFrameTime);
_lastDrawFrameTime = getCurrentTimeMillis();
drawFrame(functionTime); // 在这里调用
}
#else
@@ -448,7 +451,7 @@ void Application::createSyncObjects()
}
}
void Application::recordCommandBuffer(VkCommandBuffer commandBuffer, uint32_t imageIndex)
void Application::recordCommandBuffer(VkCommandBuffer commandBuffer, uint32_t imageIndex, long long frameTime)
{
VkCommandBufferBeginInfo beginInfo{};
beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
@@ -473,7 +476,7 @@ void Application::recordCommandBuffer(VkCommandBuffer commandBuffer, uint32_t im
vkCmdBeginRenderPass(commandBuffer, &renderPassInfo, VK_SUBPASS_CONTENTS_INLINE);
render(commandBuffer);
render(commandBuffer, frameTime);
// 结束渲染流程
vkCmdEndRenderPass(commandBuffer);
@@ -483,7 +486,7 @@ void Application::recordCommandBuffer(VkCommandBuffer commandBuffer, uint32_t im
}
}
void Application::render(VkCommandBuffer commandBuffer)
void Application::render(VkCommandBuffer commandBuffer, long long frameTime)
{
// 绑定图形管线
vkCmdBindPipeline(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, graphicsPipeline);
@@ -492,7 +495,7 @@ void Application::render(VkCommandBuffer commandBuffer)
vkCmdDraw(commandBuffer, 3, 1, 0, 0);
}
void Application::drawFrame()
void Application::drawFrame(long long frameTime)
{
// 1. 等待前一帧完成
vkWaitForFences(device, 1, &inFlightFences[currentFrame], VK_TRUE, UINT64_MAX);
@@ -517,7 +520,7 @@ void Application::drawFrame()
// 5. 记录命令缓冲区
vkResetCommandBuffer(commandBuffers[currentFrame], 0);
recordCommandBuffer(commandBuffers[currentFrame], imageIndex);
recordCommandBuffer(commandBuffers[currentFrame], imageIndex, frameTime);
// 6. 提交命令缓冲区
VkSubmitInfo submitInfo{};
@@ -561,7 +564,6 @@ void Application::drawFrame()
// 8. 前进到下一帧
currentFrame = (currentFrame + 1) % MAX_FRAMES_IN_FLIGHT;
_lastDrawFrameTime =
}
void DestroyDebugUtilsMessengerEXT(VkInstance instance, VkDebugUtilsMessengerEXT debugMessenger, const VkAllocationCallbacks* pAllocator) {
+3 -3
View File
@@ -37,10 +37,10 @@ public:
void createPipelineLayout();
void createGraphicsPipeline();
void createRenderPass();
void recordCommandBuffer(VkCommandBuffer commandBuffer, uint32_t imageIndex);
void recordCommandBuffer(VkCommandBuffer commandBuffer, uint32_t imageIndex, long long frameTime);
void createSyncObjects();
void drawFrame();
virtual void render(VkCommandBuffer commandBuffer);
void drawFrame(long long frameTime);
virtual void render(VkCommandBuffer commandBuffer, long long frameTime);
virtual bool isInited() { return inited; }
void processWithVulkan(uint8_t* data, int width, int height, int rowStride, size_t dataSize, Texture& out_texture, bool srgb);
+27 -5
View File
@@ -4,7 +4,6 @@
FaceApp* FaceApp::faceIns = nullptr;
FaceApp::FaceApp(/* args */)
@@ -515,8 +514,21 @@ void FaceApp::setup_descriptor_set()
}
void FaceApp::render(VkCommandBuffer commandBuffer)
void FaceApp::render(VkCommandBuffer commandBuffer, long long frameTime)
{
static long long game_time = 0;
game_time += frameTime;
long long actionTime = (1000 / _initArg.action_fps);
if (game_time > actionTime)
{
_curTexIndex++;
if (_curTexIndex >= _curMotion.png_num)
{
_curTexIndex = 0;
}
game_time = game_time - actionTime;
}
std::unique_lock<std::mutex> lock(mtx);
std::unique_lock<std::mutex> lock_point(mtx_point);
//Application::render(commandBuffer);
@@ -527,7 +539,8 @@ void FaceApp::render(VkCommandBuffer commandBuffer)
vkCmdPushConstants(commandBuffer, m_pipelineLayout_bg, VK_SHADER_STAGE_VERTEX_BIT, 0, sizeof(float), &myFloatValue);
//vkCmdDraw(commandBuffer, 6, 1, 0, 0);
vkCmdDraw(commandBuffer, 6, 1, 0, 0);
vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, m_pipelineLayout, 0, 1, &m_descriptor_sets[_curTexIndex], 0, NULL);
@@ -604,8 +617,9 @@ void FaceApp::initVulkan()
uploadVertexData();
last_update_time = getCurrentTimeMillis();
faceAppInited = true;
changeMotion(_initArg.motion);
faceAppInited = true;
#if _WIN32
std::vector<float> floatArray;
std::string& str = HardCodeData::Get().face_result_point_str;
@@ -616,6 +630,7 @@ void FaceApp::initVulkan()
}
//ReceiveFacePoint(floatArray.data(), floatArray.size() / 3, 480, 480);
#endif
}
@@ -1003,8 +1018,15 @@ void FaceApp::changeMotion(Motion& motion)
{
string path = _curMotion.type + "/" + _curMotion.technique + "/" + _curMotion.step + "/" + _curMotion.show_type;
string path_name = path + "/" + _curMotion.png_name + std::to_string(i) + ".png";
loadTexture(path_name, m_texs[i], true);
string path_name_ex = path + "/" + _curMotion.png_name + std::to_string(i) + "_thick.png";
#ifdef _WIN32
loadTextureExample(path_name, m_texs[i], true);
loadTextureExample(path_name_ex, m_texs_ex[i], true);
#else
loadTexture(path_name, m_texs[i], true);
loadTexture(path_name, path_name_ex[i], true);
#endif // _WIN32
}
}
+2 -2
View File
@@ -29,7 +29,7 @@ struct InitArg
int action_fps;
float zoom;
Motion motion;
NLOHMANN_DEFINE_TYPE_INTRUSIVE(InitArg, action_fps, zoom)
NLOHMANN_DEFINE_TYPE_INTRUSIVE(InitArg, action_fps, zoom, motion);
};
@@ -56,7 +56,7 @@ public:
void initVulkan() override;
void render(VkCommandBuffer commandBuffer) override;
void render(VkCommandBuffer commandBuffer, long long frameTime) override;
static FaceApp* Get() { return faceIns; }
void update_face_vertex_buffer(float* pos, int pointCount);
+14 -15
View File
@@ -2,16 +2,16 @@
#include "FaceApp.h"
int main() {
InitArg init_arg;
Motion motion;
motion.type = "底妆";
motion.technique = "基础上妆";
motion.step = "2按压";
motion.show_type = "方向";
motion.png_name = "pic";
motion.png_num = 3;
motion.type = "bottom_makeup";
motion.technique = "base_makeup";
motion.step = "press2";
motion.show_type = "direction";
motion.png_name = "demo";
motion.png_num = 1;
#
init_arg.motion = motion;
@@ -22,8 +22,6 @@ int main() {
//motion.png_name = "pic";
//motion.png_num = 1;
//init_arg.motions.push_back(motion);
init_arg.action_fps = 3;
init_arg.zoom = 1.5f;
@@ -32,12 +30,13 @@ int main() {
FaceApp app;
app.SetInitArg(json_str.c_str());
app.initVulkan();
try {
app.mainLoop();
} catch (const std::exception& e) {
std::cerr << e.what() << std::endl;
return EXIT_FAILURE;
}
app.mainLoop();
//try {
// app.mainLoop();
//} catch (const std::exception& e) {
// std::cerr << e.what() << std::endl;
// return EXIT_FAILURE;
//}
app.cleanup();
return EXIT_SUCCESS;
}