Files
face_sdk/vulkan/main.cpp
T
2025-11-29 23:44:22 +08:00

110 lines
2.8 KiB
C++

#include "FaceApp.h"
std::wstring ReadUTF8File(const std::string& filePath)
{
std::ifstream file(filePath, std::ios::binary);
if (!file.is_open()) {
throw std::runtime_error("无法打开UTF-8文件: " + filePath);
}
// 读取文件所有内容
std::string content((std::istreambuf_iterator<char>(file)),
std::istreambuf_iterator<char>());
file.close();
// 将UTF-8字符串转换为宽字符串
return AppBase::UTF8ToWideString(content);
}
std::wstring ReadFileWithChinesePath(const std::wstring& filePath) {
// 使用二进制模式打开文件
std::ifstream file(filePath, std::ios::binary);
if (!file.is_open()) {
std::wcout << L"无法打开文件: " << filePath << std::endl;
return L"";
}
// 读取文件内容到std::string
std::string context;
file.seekg(0, std::ios::end);
context.resize(file.tellg());
file.seekg(0, std::ios::beg);
file.read(&context[0], context.size());
file.close();
return AppBase::UTF8ToWideString(context);
}
FaceApp* g_app;
void CppCallback(const string& motion_type)
{
g_app->changeMotion(motion_type.c_str());
}
int main() {
//std::string path = "chinese.txt";
//std::wstring chinese = ReadUTF8File(path);
//std::wstring chinese_path = AppBase::UTF8ToWideString("d:/测试目录/中文文件.txt");
//std::wstring content = ReadFileWithChinesePath(chinese_path);
InitArg init_arg;
Motion motion;
motion.type = "4";
motion.png_names.push_back("4.png");
for (int i = 0; i < 25; ++i)
{
if (i < 10)
{
motion.png_names.push_back("00000" + std::to_string(i) + ".png");
}
else
{
motion.png_names.push_back("0000" + std::to_string(i) + ".png");
}
}
#
//init_arg.motion = motion;
init_arg.action_fps = 10;
init_arg.zoom = 1.5f;
string json_str = json(init_arg).dump();
FaceApp app;
g_app = &app;
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;
}
app.preReadyMotion(motion_str, CppCallback);
app.mainLoop();
//try {
// app.mainLoop();
//} catch (const std::exception& e) {
// std::cerr << e.what() << std::endl;
// return EXIT_FAILURE;
//}
app.cleanup();
return EXIT_SUCCESS;
}