asdf
This commit is contained in:
@@ -125,6 +125,7 @@ void Application::createFramebuffers() {
|
||||
void Application::mainLoop()
|
||||
{
|
||||
#ifdef _WIN32
|
||||
static int testFrame = 0;
|
||||
while (!glfwWindowShouldClose(window))
|
||||
{
|
||||
auto cur_time = getCurrentTimeMillis();
|
||||
@@ -132,6 +133,9 @@ void Application::mainLoop()
|
||||
auto functionTime = (cur_time - _lastDrawFrameTime);
|
||||
_lastDrawFrameTime = getCurrentTimeMillis();
|
||||
drawFrame(functionTime); // 在这里调用
|
||||
if (testFrame++ == 300) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
#else
|
||||
|
||||
|
||||
+69
-31
@@ -17,7 +17,17 @@ FaceApp::FaceApp(/* args */)
|
||||
|
||||
FaceApp::~FaceApp()
|
||||
{
|
||||
if (worker_.joinable()) {
|
||||
if(worker_.joinable())
|
||||
{
|
||||
worker_.join();
|
||||
}
|
||||
}
|
||||
|
||||
void FaceApp::Stop()
|
||||
{
|
||||
_running = false;
|
||||
if(worker_.joinable())
|
||||
{
|
||||
worker_.join();
|
||||
}
|
||||
}
|
||||
@@ -595,7 +605,7 @@ void FaceApp::setup_descriptor_set()
|
||||
|
||||
void FaceApp::update_descriptor_set(vector<Texture>& texs, vector<VkDescriptorSet>& descriptSet)
|
||||
{
|
||||
for (int i = 0; i < kTextureMax; ++i)
|
||||
for (int i = 0; i < texs.size(); ++i)
|
||||
{
|
||||
if (texs[i].image == VK_NULL_HANDLE)
|
||||
{
|
||||
@@ -731,7 +741,7 @@ void FaceApp::render(VkCommandBuffer commandBuffer, long long frameTime)
|
||||
#ifdef _WIN32
|
||||
vkCmdDrawIndexed(commandBuffer, obj_indices.size(), 1, 0, 0, 0);
|
||||
#else
|
||||
if (getCurrentTimeMillis() - last_update_time < 2000)
|
||||
//if (getCurrentTimeMillis() - last_update_time < 2000)
|
||||
{
|
||||
vkCmdDrawIndexed(commandBuffer, obj_indices.size(), 1, 0, 0, 0);
|
||||
}
|
||||
@@ -767,9 +777,10 @@ void FaceApp::createVmaAllocator()
|
||||
void FaceApp::initVulkan()
|
||||
{
|
||||
Application::initVulkan();
|
||||
|
||||
createVmaAllocator();
|
||||
LoadOBJ("face_picture_3dmax.obj", obj_vertices, obj_indices);
|
||||
m_texs_left.resize(kTextureMax);
|
||||
//m_texs_left.resize(kTextureMax);
|
||||
//m_texs_right.resize(kTextureMax);
|
||||
if (kThick)
|
||||
{
|
||||
@@ -807,8 +818,8 @@ void FaceApp::initVulkan()
|
||||
last_update_time = getCurrentTimeMillis();
|
||||
|
||||
//changeMotion(_initArg.motion);
|
||||
_running = true;
|
||||
faceAppInited = true;
|
||||
Start();
|
||||
|
||||
#if _WIN32
|
||||
std::vector<float> floatArray;
|
||||
std::string& str = HardCodeData::Get().face_result_point_str;
|
||||
@@ -823,6 +834,11 @@ void FaceApp::initVulkan()
|
||||
#endif
|
||||
}
|
||||
|
||||
void FaceApp::Start()
|
||||
{
|
||||
_running = true;
|
||||
}
|
||||
|
||||
void FaceApp::update_uniform_buffers()
|
||||
{
|
||||
uint32_t width = 480;
|
||||
@@ -892,6 +908,9 @@ void FaceApp::uploadVertexData() {
|
||||
|
||||
void FaceApp::update_face_vertex_buffer(float* pos, int pointCount)
|
||||
{
|
||||
if (pointCount == 0x33435342) {
|
||||
return;
|
||||
}
|
||||
if(!isInited())
|
||||
{
|
||||
return;
|
||||
@@ -1437,10 +1456,14 @@ string FaceApp::preLoadMotionList(string motion_list_str, Callback callback)
|
||||
}
|
||||
_isLoadMotion = true;
|
||||
_callback_loadfinish = callback;
|
||||
_loadMotions.clear();
|
||||
_curLoadMotionList.clear();
|
||||
json j = json::parse(motion_list_str);
|
||||
MotionList motion_list = j.get<MotionList>();
|
||||
_loadMotions = motion_list.motions;
|
||||
_curLoadMotionList = motion_list.motions;
|
||||
if (worker_.joinable())
|
||||
{
|
||||
worker_.join();
|
||||
}
|
||||
worker_ = std::thread(&FaceApp::loadMotionThread, this);
|
||||
return "ok";
|
||||
}
|
||||
@@ -1452,37 +1475,59 @@ void FaceApp::loadMotionThread()
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(50));
|
||||
}
|
||||
|
||||
vector<Texture>* load_text = nullptr;
|
||||
//vector<Texture>* load_text = nullptr;
|
||||
//if (cur_left)
|
||||
//{
|
||||
// load_text = &m_texs_right;
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
load_text = &m_texs_left;
|
||||
// load_text = &m_texs_left;
|
||||
//}
|
||||
|
||||
vector<Texture>& pre_texs = *load_text;
|
||||
for (int i = 0; i < _loadMotions.size(); ++i)
|
||||
{
|
||||
if (pre_texs[i].image == VK_NULL_HANDLE)
|
||||
//vector<Texture>& pre_texs = *load_text;
|
||||
for (auto m : _curLoadMotionList) {
|
||||
string name = m.name;
|
||||
if (motion_list_map.find(name) != motion_list_map.end())
|
||||
{
|
||||
loadTexture(dummy_data, dummy_data.size(), dummy_w, dummy_h, pre_texs[i], true, commandPool, "");
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
m_texs_left.push_back(Texture());
|
||||
Texture& newTex = m_texs_left[m_texs_left.size() - 1];
|
||||
loadTexture(dummy_data, dummy_data.size(), dummy_w, dummy_h, newTex, true, commandPool, "");
|
||||
#ifdef _WIN32
|
||||
string path = "pic";
|
||||
string path_name = path + "/" + _loadMotions[i].name + "ex.png";
|
||||
loadTextureExample(UTF8ToWideString(path_name), pre_texs[i], true, commandPool_ex);
|
||||
string path_name = path + "/" + name + "ex.png";
|
||||
loadTextureExample(UTF8ToWideString(path_name), newTex, true, commandPool_ex);
|
||||
#else
|
||||
string path = "pic";
|
||||
string path_name = path + "/" + _loadMotions[i].name + "ex.png";
|
||||
loadTexture(path_name, pre_texs[i], true, commandPool_ex);
|
||||
string path_name = path + "/" + name + "ex.png";
|
||||
loadTexture(path_name, newTex, true, commandPool_ex);
|
||||
#endif // _WIN32
|
||||
|
||||
motion_list_map[_loadMotions[i].name] = i;
|
||||
motion_list_map[name] = m_texs_left.size() - 1;
|
||||
_loadMotionMap[name] = m;
|
||||
}
|
||||
|
||||
// for (int i = 0; i < _loadMotions.size(); ++i)
|
||||
// {
|
||||
// if (pre_texs[i].image == VK_NULL_HANDLE)
|
||||
// {
|
||||
// loadTexture(dummy_data, dummy_data.size(), dummy_w, dummy_h, pre_texs[i], true, commandPool, "");
|
||||
// }
|
||||
//
|
||||
//
|
||||
//#ifdef _WIN32
|
||||
// string path = "pic";
|
||||
// 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 + "/" + _loadMotions[i].name + "ex.png";
|
||||
// loadTexture(path_name, pre_texs[i], true, commandPool_ex);
|
||||
//#endif // _WIN32
|
||||
//
|
||||
// motion_list_map[_loadMotions[i].name] = i;
|
||||
// }
|
||||
update_descriptor_set(m_texs_left, m_descriptor_sets_left);
|
||||
_isLoadMotion = false;
|
||||
_callback_loadfinish();
|
||||
@@ -1491,14 +1536,7 @@ void FaceApp::loadMotionThread()
|
||||
|
||||
Motion FaceApp::getMotionByName(string name)
|
||||
{
|
||||
for (auto m : _loadMotions)
|
||||
{
|
||||
if (m.name == name)
|
||||
{
|
||||
return m;
|
||||
}
|
||||
}
|
||||
return Motion();
|
||||
return _loadMotionMap[name];
|
||||
}
|
||||
|
||||
void FaceApp::changeMotionList(vector<string> motions, AnimationFinishedCallback callback, bool loop)
|
||||
|
||||
+6
-3
@@ -71,7 +71,7 @@ public:
|
||||
static FaceApp* Get() { return faceIns; }
|
||||
void update_face_vertex_buffer(float* pos, int pointCount);
|
||||
|
||||
virtual bool isInited() override { return inited && faceAppInited; }
|
||||
virtual bool isInited() override { return inited; }
|
||||
virtual void cleanup() override;
|
||||
|
||||
Texture tex_bg = {};
|
||||
@@ -147,7 +147,7 @@ private:
|
||||
void createUniformBuffer();
|
||||
|
||||
|
||||
bool faceAppInited = false;
|
||||
|
||||
|
||||
float myFloatValue = 1.5f;
|
||||
|
||||
@@ -163,6 +163,8 @@ private:
|
||||
|
||||
|
||||
public:
|
||||
void Start();
|
||||
void Stop();
|
||||
void loadMotionThread();
|
||||
std::thread worker_;
|
||||
bool _isLoadMotion = false;
|
||||
@@ -172,7 +174,8 @@ public:
|
||||
bool _animationLoop = true;
|
||||
string preLoadMotionList(string motion_list_str, Callback callback);
|
||||
Motion getMotionByName(string name);
|
||||
vector<Motion>_loadMotions;
|
||||
map<string, Motion>_loadMotionMap;
|
||||
vector<Motion> _curLoadMotionList;
|
||||
vector<Motion>_curMotions;
|
||||
void changeMotionList(vector<string> motions, AnimationFinishedCallback callback, bool loop);
|
||||
|
||||
|
||||
+32
-15
@@ -53,6 +53,12 @@ void CppCallback()
|
||||
g_app->changeMotionList(motions, CppAnimationFinishedCallback, true);
|
||||
}
|
||||
|
||||
void CppCallback2()
|
||||
{
|
||||
vector<string> motions = { "11" };
|
||||
g_app->changeMotionList(motions, CppAnimationFinishedCallback, true);
|
||||
}
|
||||
|
||||
// 读取JSON文件并填充到motions容器中
|
||||
void loadMotions(const std::string& filePath, std::map<std::string, Motion>& motions) {
|
||||
// 读取json文件
|
||||
@@ -118,8 +124,8 @@ int main() {
|
||||
//std::wstring content = ReadFileWithChinesePath(chinese_path);
|
||||
|
||||
InitArg init_arg;
|
||||
Motion motion;
|
||||
motion.name = "4";
|
||||
//Motion motion;
|
||||
//motion.name = "4";
|
||||
//motion.png_names.push_back("4.png");
|
||||
//for (int i = 1; i < 61; ++i)
|
||||
//{
|
||||
@@ -152,15 +158,15 @@ int main() {
|
||||
app.SetInitArg(json_str.c_str());
|
||||
app.initVulkan();
|
||||
app._running = true;
|
||||
auto motion_json = json(motion);
|
||||
if (!motion_json.is_object()) {
|
||||
std::cout << "Invalid JSON structure" << std::endl;
|
||||
}
|
||||
std::string motion_str = motion_json.dump();
|
||||
// 添加完整性检查
|
||||
if (motion_str.empty()) {
|
||||
std::cout << "Warning: Empty motion string" << std::endl;
|
||||
}
|
||||
//auto motion_json = json(motion);
|
||||
//if (!motion_json.is_object()) {
|
||||
// std::cout << "Invalid JSON structure" << std::endl;
|
||||
//}
|
||||
//std::string motion_str = motion_json.dump();
|
||||
//// 添加完整性检查
|
||||
//if (motion_str.empty()) {
|
||||
// std::cout << "Warning: Empty motion string" << std::endl;
|
||||
//}
|
||||
|
||||
MotionList s_motions;
|
||||
s_motions.motions.push_back(motions["4"]);
|
||||
@@ -170,17 +176,28 @@ int main() {
|
||||
auto s = j.dump();
|
||||
|
||||
app.preLoadMotionList(s, CppCallback);
|
||||
threadRun = true;
|
||||
std::thread t(threadFunction);
|
||||
//threadRun = true;
|
||||
//std::thread t(threadFunction);
|
||||
app.mainLoop();
|
||||
threadRun = false;
|
||||
t.join();
|
||||
//threadRun = false;
|
||||
//t.join();
|
||||
//try {
|
||||
// app.mainLoop();
|
||||
//} catch (const std::exception& e) {
|
||||
// std::cerr << e.what() << std::endl;
|
||||
// return EXIT_FAILURE;
|
||||
//}
|
||||
|
||||
s_motions.motions.push_back(motions["4"]);
|
||||
s_motions.motions.push_back(motions["5"]);
|
||||
s_motions.motions.push_back(motions["13"]);
|
||||
s_motions.motions.push_back(motions["11"]);
|
||||
j = s_motions;
|
||||
s = j.dump();
|
||||
|
||||
app.preLoadMotionList(s, CppCallback2);
|
||||
app.mainLoop();
|
||||
|
||||
app.cleanup();
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
Reference in New Issue
Block a user