diff --git a/app/src/main/java/com/hmwl/face_sdk/InitArg.java b/app/src/main/java/com/hmwl/face_sdk/InitArg.java new file mode 100644 index 0000000..3c311f5 --- /dev/null +++ b/app/src/main/java/com/hmwl/face_sdk/InitArg.java @@ -0,0 +1,20 @@ +package com.hmwl.face_sdk; +import org.json.JSONObject; + +public class InitArg { + public int action_fps; + public float zoom; + public Motion motion; + public String toJson() { + try { + JSONObject jsonObject = new JSONObject(); + jsonObject.put("action_fps", action_fps); + jsonObject.put("zoom", zoom); + jsonObject.put("motion", motion.toJsonObject()); + return jsonObject.toString(); + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } +} diff --git a/app/src/main/java/com/hmwl/face_sdk/Motion.java b/app/src/main/java/com/hmwl/face_sdk/Motion.java new file mode 100644 index 0000000..5c65c86 --- /dev/null +++ b/app/src/main/java/com/hmwl/face_sdk/Motion.java @@ -0,0 +1,36 @@ +package com.hmwl.face_sdk; +import org.json.JSONObject; + +public class Motion { + public String type; + public String technique; + public String step; + public String show_type; + public String png_name; + public int png_num; + + public JSONObject toJsonObject() { + try { + JSONObject jsonObject = new JSONObject(); + jsonObject.put("type", type); + jsonObject.put("technique", technique); + jsonObject.put("step", step); + jsonObject.put("show_type", show_type); + jsonObject.put("png_name", png_name); + jsonObject.put("png_num", png_num); + return jsonObject; + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } + + public String toJson() { + try { + return toJsonObject().toString(); + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } +}; diff --git a/example/src/main/assets/底妆/基础上妆/2按压/区域示意图/pic0.png b/example/src/main/assets/底妆/基础上妆/2按压/区域示意图/pic0.png new file mode 100644 index 0000000..add9422 Binary files /dev/null and b/example/src/main/assets/底妆/基础上妆/2按压/区域示意图/pic0.png differ diff --git a/example/src/main/assets/底妆/基础上妆/2按压/区域示意图/pic0_thick.png b/example/src/main/assets/底妆/基础上妆/2按压/区域示意图/pic0_thick.png new file mode 100644 index 0000000..1a55a07 Binary files /dev/null and b/example/src/main/assets/底妆/基础上妆/2按压/区域示意图/pic0_thick.png differ diff --git a/example/src/main/assets/底妆/基础上妆/2按压/方向示意图/demo0.png b/example/src/main/assets/底妆/基础上妆/2按压/方向示意图/demo0.png new file mode 100644 index 0000000..c9e5244 Binary files /dev/null and b/example/src/main/assets/底妆/基础上妆/2按压/方向示意图/demo0.png differ diff --git a/example/src/main/assets/底妆/基础上妆/2按压/方向示意图/demo0_thick.png b/example/src/main/assets/底妆/基础上妆/2按压/方向示意图/demo0_thick.png new file mode 100644 index 0000000..4cbe056 Binary files /dev/null and b/example/src/main/assets/底妆/基础上妆/2按压/方向示意图/demo0_thick.png differ diff --git a/example/src/main/assets/底妆/基础上妆/2按压/方向示意图/pic0.png b/example/src/main/assets/底妆/基础上妆/2按压/方向示意图/pic0.png new file mode 100644 index 0000000..5e96f81 Binary files /dev/null and b/example/src/main/assets/底妆/基础上妆/2按压/方向示意图/pic0.png differ diff --git a/example/src/main/assets/底妆/基础上妆/2按压/方向示意图/pic0_thick.png b/example/src/main/assets/底妆/基础上妆/2按压/方向示意图/pic0_thick.png new file mode 100644 index 0000000..3a076eb Binary files /dev/null and b/example/src/main/assets/底妆/基础上妆/2按压/方向示意图/pic0_thick.png differ diff --git a/example/src/main/assets/底妆/基础上妆/2按压/方向示意图/pic1.png b/example/src/main/assets/底妆/基础上妆/2按压/方向示意图/pic1.png new file mode 100644 index 0000000..3af6c63 Binary files /dev/null and b/example/src/main/assets/底妆/基础上妆/2按压/方向示意图/pic1.png differ diff --git a/example/src/main/assets/底妆/基础上妆/2按压/方向示意图/pic1_thick.png b/example/src/main/assets/底妆/基础上妆/2按压/方向示意图/pic1_thick.png new file mode 100644 index 0000000..66d4024 Binary files /dev/null and b/example/src/main/assets/底妆/基础上妆/2按压/方向示意图/pic1_thick.png differ diff --git a/example/src/main/assets/底妆/基础上妆/2按压/方向示意图/pic2.png b/example/src/main/assets/底妆/基础上妆/2按压/方向示意图/pic2.png new file mode 100644 index 0000000..85b1564 Binary files /dev/null and b/example/src/main/assets/底妆/基础上妆/2按压/方向示意图/pic2.png differ diff --git a/example/src/main/assets/底妆/基础上妆/2按压/方向示意图/pic2_thick.png b/example/src/main/assets/底妆/基础上妆/2按压/方向示意图/pic2_thick.png new file mode 100644 index 0000000..fea7c4f Binary files /dev/null and b/example/src/main/assets/底妆/基础上妆/2按压/方向示意图/pic2_thick.png differ diff --git a/example/src/main/assets/底妆/基础上妆/2按压/方向示意图/test0.png b/example/src/main/assets/底妆/基础上妆/2按压/方向示意图/test0.png new file mode 100644 index 0000000..acbb2d2 Binary files /dev/null and b/example/src/main/assets/底妆/基础上妆/2按压/方向示意图/test0.png differ diff --git a/example/src/main/java/com/hmwl/example/MainActivity.java b/example/src/main/java/com/hmwl/example/MainActivity.java index 121cfcf..826d64e 100644 --- a/example/src/main/java/com/hmwl/example/MainActivity.java +++ b/example/src/main/java/com/hmwl/example/MainActivity.java @@ -2,16 +2,30 @@ package com.hmwl.example; import android.os.Bundle; +import com.hmwl.face_sdk.InitArg; +import com.hmwl.face_sdk.Motion; + + import com.hmwl.face_sdk.FaceActivity; public class MainActivity extends FaceActivity{ + @Override protected void onCreate(Bundle savedInstanceState) { - SetInitArg("{\"action_fps\":3,\"motion\":{\"png_name\":\"test\",\"png_num\":1,\"show_type\":\"direction\",\"step\":\"press2\",\"technique\":\"base_makeup\",\"type\":\"bottom_makeup\"},\"zoom\":1.5}"); + Motion motion = new Motion(); + motion.type = "底妆"; + motion.technique = "基础上妆"; + motion.step = "2按压"; + motion.show_type = "方向示意图"; + motion.png_name = "test"; + motion.png_num = 1; + + InitArg initArg = new InitArg(); + initArg.action_fps = 3; + initArg.zoom = 1.5f; + initArg.motion = motion; + SetInitArg(initArg.toJson()); super.onCreate(savedInstanceState); - //这个是设置接口的参数,采用json传递,可以保证接口灵活性 - //比如设置对应的化妆步骤为 - ChangeState("{\"step\":\"0\"}"); } } diff --git a/vulkan/AppBase.cpp b/vulkan/AppBase.cpp index 5018ff1..541fc24 100644 --- a/vulkan/AppBase.cpp +++ b/vulkan/AppBase.cpp @@ -21,6 +21,34 @@ void VK_CHECK(VkResult ret) //#endif // return path; //} +#ifdef _WIN32 +std::vector AppBase::readFileUnsignedCharWin32(const std::wstring path, bool example) +{ + std::vector buffer; + + std::wstring enginePath = L"app/src/main/assets/" + path; + if (example) + { + enginePath = L"example/src/main/assets/" + path; + } + std::ifstream file{ enginePath, std::ios::ate | std::ios::binary }; + + if (!file.is_open()) + { + throw std::runtime_error("failed to open file: "); + } + + size_t fileSize = static_cast(file.tellg()); + buffer.resize(fileSize); + + file.seekg(0); + file.read((char*)buffer.data(), fileSize); + file.close(); + + + return buffer; +} +#endif // _WIN32 std::vector AppBase::readFileUnsignedChar(const std::string& path, bool example) { diff --git a/vulkan/AppBase.h b/vulkan/AppBase.h index 0ab5c52..bfd2df3 100644 --- a/vulkan/AppBase.h +++ b/vulkan/AppBase.h @@ -17,6 +17,7 @@ #define logOut std::cout #define GLFW_INCLUDE_VULKAN #include + #include #else #include "../app/src/main/cpp/AndroidOut.h" #define logOut aout @@ -69,7 +70,7 @@ public: //std::string getPath(const std::string path); VkShaderModule createShaderModule(VkDevice& device, const std::vector& code); const std::vector validationLayers = {"VK_LAYER_KHRONOS_validation"}; -protected: + long long getCurrentTimeMillis() { auto now = std::chrono::system_clock::now(); auto duration = now.time_since_epoch(); @@ -87,6 +88,23 @@ protected: void pickPhysicalDevice(VkPhysicalDevice& physicalDevice, VkSurfaceKHR& surface); #ifdef _WIN32 GLFWwindow *window; + std::vector readFileUnsignedCharWin32(const std::wstring path, bool example); + static std::wstring UTF8ToWideString(const std::string& utf8str) + { + if (utf8str.empty()) return L""; + + int wideLen = MultiByteToWideChar(CP_UTF8, 0, utf8str.c_str(), + -1, nullptr, 0); + if (wideLen == 0) { + throw std::runtime_error("UTF-8转换失败"); + } + + std::vector buffer(wideLen); + MultiByteToWideChar(CP_UTF8, 0, utf8str.c_str(), -1, + buffer.data(), wideLen); + + return std::wstring(buffer.data()); + } #endif bool enableValidationLayers = true; diff --git a/vulkan/Application.cpp b/vulkan/Application.cpp index b49e22d..d3a5122 100644 --- a/vulkan/Application.cpp +++ b/vulkan/Application.cpp @@ -639,10 +639,10 @@ Texture Application::loadTexture(std::string path, Texture& tex, bool srgb) processWithVulkan(image.data(), w, h, w * 4, image.size(), tex, srgb); return tex; } - -Texture Application::loadTextureExample(std::string path, Texture& tex, bool srgb) +#ifdef _WIN32 +Texture Application::loadTextureExample(std::wstring path, Texture& tex, bool srgb) { - std::vector data = readFileUnsignedChar(path, true); + std::vector data = readFileUnsignedCharWin32(path, true); std::vector image; unsigned w, h; unsigned error = lodepng::decode(image, w, h, data, LCT_RGBA, 8); @@ -650,6 +650,10 @@ Texture Application::loadTextureExample(std::string path, Texture& tex, bool srg return tex; } +#endif // _WIN32 + + + void Application::createTexture(VkDevice device, VkPhysicalDevice physicalDevice, int width, int height, Texture& texture, bool srgb) { diff --git a/vulkan/Application.h b/vulkan/Application.h index a316774..1c71661 100644 --- a/vulkan/Application.h +++ b/vulkan/Application.h @@ -75,7 +75,9 @@ protected: protected: Texture loadTexture(std::string path, Texture& tex, bool srgb); - Texture loadTextureExample(std::string path, Texture& tex, bool srgb); +#ifdef _WIN32 + Texture loadTextureExample(std::wstring path, Texture& tex, bool srgb); +#endif uint32_t findMemoryType(VkPhysicalDevice physicalDevice, uint32_t typeFilter, VkMemoryPropertyFlags properties); diff --git a/vulkan/FaceApp.cpp b/vulkan/FaceApp.cpp index a4b8378..8b03f8a 100644 --- a/vulkan/FaceApp.cpp +++ b/vulkan/FaceApp.cpp @@ -1146,16 +1146,19 @@ void FaceApp::changeMotion(Motion& motion) _curMotion = _initArg.motion; for (int i = 0; i < _curMotion.png_num; ++i) { + +#ifdef _WIN32 string path = _curMotion.type + "/" + _curMotion.technique + "/" + _curMotion.step + "/" + _curMotion.show_type; string path_name = path + "/" + _curMotion.png_name + std::to_string(i) + ".png"; -#ifdef _WIN32 - loadTextureExample(path_name, m_texs[i], true); + loadTextureExample(UTF8ToWideString(path_name), m_texs[i], true); if (kThick) { string path_name_ex = path + "/" + _curMotion.png_name + std::to_string(i) + "_thick.png"; - loadTextureExample(path_name_ex, m_texs_ex[i], true); + loadTextureExample(UTF8ToWideString(path_name_ex), m_texs_ex[i], true); } #else + 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); if (kThick) { diff --git a/vulkan/main.cpp b/vulkan/main.cpp index c316b8c..c6665de 100644 --- a/vulkan/main.cpp +++ b/vulkan/main.cpp @@ -1,23 +1,8 @@  #include "FaceApp.h" -#include -std::wstring UTF8ToWideString(const std::string& utf8str) -{ - if (utf8str.empty()) return L""; - - int wideLen = MultiByteToWideChar(CP_UTF8, 0, utf8str.c_str(), - -1, nullptr, 0); - if (wideLen == 0) { - throw std::runtime_error("UTF-8转换失败"); - } - - std::vector buffer(wideLen); - MultiByteToWideChar(CP_UTF8, 0, utf8str.c_str(), -1, - buffer.data(), wideLen); - - return std::wstring(buffer.data()); -} + + std::wstring ReadUTF8File(const std::string& filePath) { @@ -32,7 +17,7 @@ std::wstring ReadUTF8File(const std::string& filePath) file.close(); // 将UTF-8字符串转换为宽字符串 - return UTF8ToWideString(content); + return AppBase::UTF8ToWideString(content); } @@ -51,23 +36,23 @@ std::wstring ReadFileWithChinesePath(const std::wstring& filePath) { file.seekg(0, std::ios::beg); file.read(&context[0], context.size()); file.close(); - return UTF8ToWideString(context); + return AppBase::UTF8ToWideString(context); } int main() { - std::string path = "chinese.txt"; - std::wstring chinese = ReadUTF8File(path); - std::wstring chinese_path = UTF8ToWideString("d:/测试目录/中文文件.txt"); - std::wstring content = ReadFileWithChinesePath(chinese_path); + //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 = "bottom_makeup"; - motion.technique = "base_makeup"; - motion.step = "press2"; - motion.show_type = "direction"; + motion.type = "底妆"; + motion.technique = "基础上妆"; + motion.step = "2按压"; + motion.show_type = "方向示意图"; motion.png_name = "test"; motion.png_num = 1; #