From 5665ff4105678a6abce09f8be8fc087502ffe53b Mon Sep 17 00:00:00 2001 From: ink-soul Date: Mon, 12 Jun 2023 11:05:10 +0800 Subject: [PATCH 1/4] switch chinese UI asset path fix complete allow asset path check more data path --- CMakeLists.txt | 2 +- base/VulkanTools.cpp | 24 +++++++++++++++++++++++- base/ui.hpp | 4 ++-- src/render/render.cpp | 27 ++++++++++++++++----------- src/render/render.h | 20 ++++++++++---------- 5 files changed, 52 insertions(+), 25 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 248c860..4167589 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.4 FATAL_ERROR) cmake_policy(VERSION 2.8) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake") -set(NAME games_106) +set(NAME PlumageRender) project(${NAME}) diff --git a/base/VulkanTools.cpp b/base/VulkanTools.cpp index dc3e8bf..148a1b5 100644 --- a/base/VulkanTools.cpp +++ b/base/VulkanTools.cpp @@ -3,6 +3,7 @@ #if !(defined(VK_USE_PLATFORM_IOS_MVK) || defined(VK_USE_PLATFORM_MACOS_MVK)) // iOS & macOS: VulkanExampleBase::getAssetPath() implemented externally to allow access to Objective-C components + const std::string getAssetPath() { #if defined(VK_USE_PLATFORM_ANDROID_KHR) @@ -10,7 +11,28 @@ const std::string getAssetPath() #elif defined(VK_EXAMPLE_DATA_DIR) return VK_EXAMPLE_DATA_DIR; #else - return "./../data/"; + + if (_access("./../data/", 0) != -1) + { + + return "./../data/"; + } + else if (_access("./data/", 0) != -1) + { + + return "./data/"; + } + else if (_access("./../../data/", 0) != -1) + { + + return "../../data/"; + } + else + { + + return "./../../../data"; + } + #endif } #endif diff --git a/base/ui.hpp b/base/ui.hpp index b01d924..53bec17 100644 --- a/base/ui.hpp +++ b/base/ui.hpp @@ -1,4 +1,4 @@ -/* +/* * Vulkan Example - Physical based rendering a glTF 2.0 model with image based lighting * * Copyright (C) 2018 by Sascha Willems - www.saschawillems.de @@ -68,7 +68,7 @@ public: delete[] fontAsset; #else std::string ttfFilePath = getAssetPath() + "/STXINWEI.TTF"; - io.Fonts->AddFontFromFileTTF(ttfFilePath.data(), 16.0f); + io.Fonts->AddFontFromFileTTF(ttfFilePath.data(), 16.0f,NULL, io.Fonts->GetGlyphRangesChineseSimplifiedCommon()); #endif io.Fonts->GetTexDataAsRGBA32(&fontData, &texWidth, &texHeight); fontTexture.loadFromBuffer(fontData, texWidth * texHeight * 4 * sizeof(char), VK_FORMAT_R8G8B8A8_UNORM, texWidth, texHeight, vulkanDevice, queue); diff --git a/src/render/render.cpp b/src/render/render.cpp index dc39d91..f124bcf 100644 --- a/src/render/render.cpp +++ b/src/render/render.cpp @@ -1,4 +1,4 @@ - + #ifndef TINYGLTF_IMPLEMENTATION @@ -222,7 +222,12 @@ PlumageRender::PlumageRender() if (_access(assetpath.c_str(),0) != 0) { std::string msg = "Could not locate asset path in \"" + assetpath + "\".\nMake sure binary is run from correct relative directory!"; std::cerr << msg << std::endl; - exit(-1); + system("pause"); + //exit(-1); + } + else { + std::string msg = "asset path check " + assetpath; + std::cout << msg << std::endl; } readDirectory(assetpath + "environments", "*.ktx", environments, false); @@ -1680,8 +1685,8 @@ PlumageRender::PlumageRender() gui->text("%.1d fps (%.2f ms)", lastFPS, (1000.0f / lastFPS)); - if (gui->header("model")) { - if (gui->button(gui->string_to_utf8("open gltf model").c_str())) { + if (gui->header(chineseUI.model)) { + if (gui->button(chineseUI.openNewModel)) { std::string filename = ""; char buffer[MAX_PATH]; OPENFILENAME ofn; @@ -1703,7 +1708,7 @@ PlumageRender::PlumageRender() updateCBs = true; } } - if (gui->combo("Environment", selectedEnvironment, environments)) { + if (gui->combo(chineseUI.environmentMap, selectedEnvironment, environments)) { vkDeviceWaitIdle(device); loadEnvironment(environments[selectedEnvironment]); setupDescriptors(); @@ -1711,7 +1716,7 @@ PlumageRender::PlumageRender() } } - if (gui->header("Environment")) { + if (gui->header(chineseUI.environment)) { if (gui->checkbox("Background", &displayBackground)) { updateShaderParams = true; } @@ -1730,27 +1735,27 @@ PlumageRender::PlumageRender() const std::vector debugNamesInputs = { "none", "Base color", "Normal", "Occlusion", "Emissive", "Metallic", "Roughness" }; - if (gui->combo("input", &debugViewInputs, debugNamesInputs)) { + if (gui->combo(chineseUI.debugInput, &debugViewInputs, debugNamesInputs)) { shaderData.debugViewInputs = static_cast(debugViewInputs); updateShaderParams = true; } const std::vector debugNamesEquation = { "none", "Diff (l,n)", "F (l,h)", "G (l,v,h)", "D (h)", "Specular" }; - if (gui->combo("PBR equation", &debugViewEquation, debugNamesEquation)) { + if (gui->combo(chineseUI.debugPBREquation, &debugViewEquation, debugNamesEquation)) { shaderData.debugViewEquation = static_cast(debugViewEquation); updateShaderParams = true; } } if (models.scene.animations.size() > 0) { - if (gui->header("animation")) { - gui->checkbox("pause", &animate); + if (gui->header(chineseUI.animation)) { + gui->checkbox(chineseUI.pauseAnimation, &animate); std::vector animationNames; for (auto animation : models.scene.animations) { animationNames.push_back(animation.name); } - gui->combo("animation", &animationIndex, animationNames); + gui->combo(chineseUI.animationSeq, &animationIndex, animationNames); } } diff --git a/src/render/render.h b/src/render/render.h index ac1c411..aeeeac6 100644 --- a/src/render/render.h +++ b/src/render/render.h @@ -1,4 +1,4 @@ -#pragma once +#pragma once #include #include @@ -62,15 +62,15 @@ public: } shaderData; struct ChinesesUI { - const char * model = "u8ģ"; - const char* openNewModel = "gltfģ"; - const char* environmentMap = "ͼ"; - const char* environment = ""; - const char* debugInput = ""; - const char* debugPBREquation = "PBR"; - const char* animation = ""; - const char* pauseAnimation = "ͣ"; - const char* animationSeq = ""; + const char * model = "模型"; + const char* openNewModel = "打开新gltf模型"; + const char* environmentMap = "环境贴图"; + const char* environment = "环境光照"; + const char* debugInput = "输入"; + const char* debugPBREquation = "PBR计算参数"; + const char* animation = "动画"; + const char* pauseAnimation = "启用动画"; + const char* animationSeq = "动画序列"; }chineseUI; struct UniformBufferSet { From a8fe315be6b70358b6a0ba2bdb1519e916f8f38e Mon Sep 17 00:00:00 2001 From: ink-soul Date: Mon, 12 Jun 2023 11:10:07 +0800 Subject: [PATCH 2/4] bug fix : allow directory defined in cmakelist --- base/VulkanTools.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/base/VulkanTools.cpp b/base/VulkanTools.cpp index 148a1b5..8368d50 100644 --- a/base/VulkanTools.cpp +++ b/base/VulkanTools.cpp @@ -9,9 +9,7 @@ const std::string getAssetPath() #if defined(VK_USE_PLATFORM_ANDROID_KHR) return ""; #elif defined(VK_EXAMPLE_DATA_DIR) - return VK_EXAMPLE_DATA_DIR; -#else - + if (_access("./../data/", 0) != -1) { @@ -30,7 +28,7 @@ const std::string getAssetPath() else { - return "./../../../data"; + return VK_EXAMPLE_DATA_DIR; } #endif From 4d567bf64a07d4adcc831989cfc26043162a820d Mon Sep 17 00:00:00 2001 From: ink-soul Date: Mon, 12 Jun 2023 11:11:52 +0800 Subject: [PATCH 3/4] fix log complain --- base/VulkanTools.cpp | 2 +- src/render/render.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/base/VulkanTools.cpp b/base/VulkanTools.cpp index 8368d50..33bb259 100644 --- a/base/VulkanTools.cpp +++ b/base/VulkanTools.cpp @@ -30,7 +30,7 @@ const std::string getAssetPath() return VK_EXAMPLE_DATA_DIR; } - + #endif } #endif diff --git a/src/render/render.cpp b/src/render/render.cpp index f124bcf..c55b3b6 100644 --- a/src/render/render.cpp +++ b/src/render/render.cpp @@ -226,7 +226,7 @@ PlumageRender::PlumageRender() //exit(-1); } else { - std::string msg = "asset path check " + assetpath; + std::string msg = "asset path get " + assetpath; std::cout << msg << std::endl; } From 5c30ea82f78d6c362fc3e8836da89c527a8f2aef Mon Sep 17 00:00:00 2001 From: ink-soul Date: Mon, 12 Jun 2023 14:56:43 +0800 Subject: [PATCH 4/4] Update render.cpp --- src/render/render.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/render/render.cpp b/src/render/render.cpp index c55b3b6..be54f49 100644 --- a/src/render/render.cpp +++ b/src/render/render.cpp @@ -1684,7 +1684,7 @@ PlumageRender::PlumageRender() gui->text("%.1d fps (%.2f ms)", lastFPS, (1000.0f / lastFPS)); - + // TO DO : language switch if (gui->header(chineseUI.model)) { if (gui->button(chineseUI.openNewModel)) { std::string filename = "";