| 1 | diff -pruN --exclude build ./demo_clean/CMakeLists.txt ./demo_dev/CMakeLists.txt |
| 2 | --- ./demo_clean/CMakeLists.txt 2022-09-14 12:08:43.000000000 +0100 |
| 3 | +++ ./demo_dev/CMakeLists.txt 2022-10-11 20:18:15.217358999 +0100 |
| 4 | @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.16) |
| 5 | # Set app name. |
| 6 | set(APP_NAME Demo) |
| 7 | # Set directory paths. |
| 8 | -set(SDK_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../..) |
| 9 | +set(SDK_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../CubismSdkForNative-4-r.6.2) |
| 10 | set(CORE_PATH ${SDK_ROOT_PATH}/Core) |
| 11 | set(FRAMEWORK_PATH ${SDK_ROOT_PATH}/Framework) |
| 12 | set(THIRD_PARTY_PATH ${SDK_ROOT_PATH}/Samples/OpenGL/thirdParty) |
| 13 | @@ -32,7 +32,7 @@ set(GLFW_INSTALL OFF CACHE BOOL "" FORCE |
| 14 | set(BUILD_UTILS OFF CACHE BOOL "" FORCE) |
| 15 | |
| 16 | # Specify version of compiler. |
| 17 | -set(CMAKE_CXX_STANDARD 14) |
| 18 | +set(CMAKE_CXX_STANDARD 17) |
| 19 | set(CMAKE_CXX_STANDARD_REQUIRED ON) |
| 20 | set(CMAKE_CXX_EXTENSIONS OFF) |
| 21 | |
| 22 | @@ -64,6 +64,9 @@ target_link_libraries(Framework Live2DCu |
| 23 | # Find opengl libraries. |
| 24 | find_package(OpenGL REQUIRED) |
| 25 | |
| 26 | +# Add FacialLandmarksForCubism |
| 27 | +add_subdirectory(../.. FacialLandmarksForCubism_build) |
| 28 | + |
| 29 | # Make executable app. |
| 30 | add_executable(${APP_NAME}) |
| 31 | # Add source files. |
| 32 | @@ -73,9 +76,11 @@ target_link_libraries(${APP_NAME} |
| 33 | Framework |
| 34 | glfw |
| 35 | ${OPENGL_LIBRARIES} |
| 36 | + FacialLandmarksForCubism |
| 37 | + stdc++fs |
| 38 | ) |
| 39 | # Specify include directories. |
| 40 | -target_include_directories(${APP_NAME} PRIVATE ${STB_PATH}) |
| 41 | +target_include_directories(${APP_NAME} PRIVATE ${STB_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/../../include) |
| 42 | |
| 43 | # Copy resource directory to build directory. |
| 44 | add_custom_command( |
| 45 | diff -pruN --exclude build ./demo_clean/scripts/make_gcc ./demo_dev/scripts/make_gcc |
| 46 | --- ./demo_clean/scripts/make_gcc 2022-09-14 12:08:43.000000000 +0100 |
| 47 | +++ ./demo_dev/scripts/make_gcc 2021-05-29 02:04:17.338257917 +0100 |
| 48 | @@ -5,41 +5,9 @@ set -ue |
| 49 | SCRIPT_PATH=$(cd $(dirname $0) && pwd) |
| 50 | CMAKE_PATH=$SCRIPT_PATH/.. |
| 51 | BUILD_PATH=$SCRIPT_PATH/../build/make_gcc |
| 52 | -MINIMUM_DEMO="OFF" |
| 53 | -DATA="" |
| 54 | - |
| 55 | -if [ "$#" -ne 0 ]; then |
| 56 | - DATA="$1" |
| 57 | -fi |
| 58 | - |
| 59 | -while : |
| 60 | -do |
| 61 | - |
| 62 | - if [ -z "$DATA" ]; then |
| 63 | - echo "Choose which format you would like to create the demo." |
| 64 | - echo "Full version : 1" |
| 65 | - echo "Minimum version : 2" |
| 66 | - read -p "Your Choice : " DATA |
| 67 | - fi |
| 68 | - |
| 69 | - case "$DATA" in |
| 70 | - "1" ) |
| 71 | - echo "Making Full Demo" |
| 72 | - MINIMUM_DEMO="OFF" |
| 73 | - break ;; |
| 74 | - "2" ) |
| 75 | - echo "Making Minimum Demo" |
| 76 | - MINIMUM_DEMO="ON" |
| 77 | - break ;; |
| 78 | - * ) |
| 79 | - echo "You need to enter a valid number." |
| 80 | - DATA="" ;; |
| 81 | - esac |
| 82 | -done |
| 83 | |
| 84 | # Run CMake. |
| 85 | cmake -S "$CMAKE_PATH" \ |
| 86 | -B "$BUILD_PATH" \ |
| 87 | - -D CMAKE_BUILD_TYPE=Release \ |
| 88 | - -D CSM_MINIMUM_DEMO=$MINIMUM_DEMO |
| 89 | -cd "$BUILD_PATH" && make |
| 90 | + -D CMAKE_BUILD_TYPE=Release |
| 91 | +cd "$BUILD_PATH" && make -j4 |
| 92 | diff -pruN --exclude build ./demo_clean/src/CMakeLists.txt ./demo_dev/src/CMakeLists.txt |
| 93 | --- ./demo_clean/src/CMakeLists.txt 2022-09-14 12:08:43.000000000 +0100 |
| 94 | +++ ./demo_dev/src/CMakeLists.txt 2021-04-28 11:49:43.166296000 +0100 |
| 95 | @@ -1,49 +1,22 @@ |
| 96 | -if (CSM_MINIMUM_DEMO) |
| 97 | - target_sources(${APP_NAME} |
| 98 | +target_sources(${APP_NAME} |
| 99 | PRIVATE |
| 100 | ${CMAKE_CURRENT_SOURCE_DIR}/LAppAllocator.cpp |
| 101 | ${CMAKE_CURRENT_SOURCE_DIR}/LAppAllocator.hpp |
| 102 | ${CMAKE_CURRENT_SOURCE_DIR}/LAppDefine.cpp |
| 103 | ${CMAKE_CURRENT_SOURCE_DIR}/LAppDefine.hpp |
| 104 | + ${CMAKE_CURRENT_SOURCE_DIR}/LAppDelegate.cpp |
| 105 | + ${CMAKE_CURRENT_SOURCE_DIR}/LAppDelegate.hpp |
| 106 | + ${CMAKE_CURRENT_SOURCE_DIR}/LAppLive2DManager.cpp |
| 107 | + ${CMAKE_CURRENT_SOURCE_DIR}/LAppLive2DManager.hpp |
| 108 | + ${CMAKE_CURRENT_SOURCE_DIR}/LAppModel.cpp |
| 109 | + ${CMAKE_CURRENT_SOURCE_DIR}/LAppModel.hpp |
| 110 | ${CMAKE_CURRENT_SOURCE_DIR}/LAppPal.cpp |
| 111 | ${CMAKE_CURRENT_SOURCE_DIR}/LAppPal.hpp |
| 112 | + ${CMAKE_CURRENT_SOURCE_DIR}/LAppSprite.cpp |
| 113 | + ${CMAKE_CURRENT_SOURCE_DIR}/LAppSprite.hpp |
| 114 | ${CMAKE_CURRENT_SOURCE_DIR}/LAppTextureManager.cpp |
| 115 | ${CMAKE_CURRENT_SOURCE_DIR}/LAppTextureManager.hpp |
| 116 | - ${CMAKE_CURRENT_SOURCE_DIR}/mainMinimum.cpp |
| 117 | - ${CMAKE_CURRENT_SOURCE_DIR}/TouchManager.cpp |
| 118 | - ${CMAKE_CURRENT_SOURCE_DIR}/TouchManager.hpp |
| 119 | - ${CMAKE_CURRENT_SOURCE_DIR}/CubismUserModelExtend.cpp |
| 120 | - ${CMAKE_CURRENT_SOURCE_DIR}/CubismUserModelExtend.hpp |
| 121 | - ${CMAKE_CURRENT_SOURCE_DIR}/CubismSampleViewMatrix.cpp |
| 122 | - ${CMAKE_CURRENT_SOURCE_DIR}/CubismSampleViewMatrix.hpp |
| 123 | - ${CMAKE_CURRENT_SOURCE_DIR}/MouseActionManager.cpp |
| 124 | - ${CMAKE_CURRENT_SOURCE_DIR}/MouseActionManager.hpp |
| 125 | - ) |
| 126 | -else () |
| 127 | - target_sources(${APP_NAME} |
| 128 | - PRIVATE |
| 129 | - ${CMAKE_CURRENT_SOURCE_DIR}/LAppAllocator.cpp |
| 130 | - ${CMAKE_CURRENT_SOURCE_DIR}/LAppAllocator.hpp |
| 131 | - ${CMAKE_CURRENT_SOURCE_DIR}/LAppDefine.cpp |
| 132 | - ${CMAKE_CURRENT_SOURCE_DIR}/LAppDefine.hpp |
| 133 | - ${CMAKE_CURRENT_SOURCE_DIR}/LAppDelegate.cpp |
| 134 | - ${CMAKE_CURRENT_SOURCE_DIR}/LAppDelegate.hpp |
| 135 | - ${CMAKE_CURRENT_SOURCE_DIR}/LAppWavFileHandler.cpp |
| 136 | - ${CMAKE_CURRENT_SOURCE_DIR}/LAppWavFileHandler.hpp |
| 137 | - ${CMAKE_CURRENT_SOURCE_DIR}/LAppLive2DManager.cpp |
| 138 | - ${CMAKE_CURRENT_SOURCE_DIR}/LAppLive2DManager.hpp |
| 139 | - ${CMAKE_CURRENT_SOURCE_DIR}/LAppModel.cpp |
| 140 | - ${CMAKE_CURRENT_SOURCE_DIR}/LAppModel.hpp |
| 141 | - ${CMAKE_CURRENT_SOURCE_DIR}/LAppPal.cpp |
| 142 | - ${CMAKE_CURRENT_SOURCE_DIR}/LAppPal.hpp |
| 143 | - ${CMAKE_CURRENT_SOURCE_DIR}/LAppSprite.cpp |
| 144 | - ${CMAKE_CURRENT_SOURCE_DIR}/LAppSprite.hpp |
| 145 | - ${CMAKE_CURRENT_SOURCE_DIR}/LAppTextureManager.cpp |
| 146 | - ${CMAKE_CURRENT_SOURCE_DIR}/LAppTextureManager.hpp |
| 147 | - ${CMAKE_CURRENT_SOURCE_DIR}/LAppView.cpp |
| 148 | - ${CMAKE_CURRENT_SOURCE_DIR}/LAppView.hpp |
| 149 | - ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp |
| 150 | - ${CMAKE_CURRENT_SOURCE_DIR}/TouchManager.cpp |
| 151 | - ${CMAKE_CURRENT_SOURCE_DIR}/TouchManager.hpp |
| 152 | - ) |
| 153 | -endif () |
| 154 | + ${CMAKE_CURRENT_SOURCE_DIR}/LAppView.cpp |
| 155 | + ${CMAKE_CURRENT_SOURCE_DIR}/LAppView.hpp |
| 156 | + ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp |
| 157 | +) |
| 158 | diff -pruN --exclude build ./demo_clean/src/LAppDelegate.cpp ./demo_dev/src/LAppDelegate.cpp |
| 159 | --- ./demo_clean/src/LAppDelegate.cpp 2022-09-14 12:08:43.000000000 +0100 |
| 160 | +++ ./demo_dev/src/LAppDelegate.cpp 2021-04-28 11:49:43.166296000 +0100 |
| 161 | @@ -45,7 +45,8 @@ void LAppDelegate::ReleaseInstance() |
| 162 | s_instance = NULL; |
| 163 | } |
| 164 | |
| 165 | -bool LAppDelegate::Initialize() |
| 166 | +bool LAppDelegate::Initialize(int initWindowWidth, int initWindowHeight, |
| 167 | + const char *windowTitle) |
| 168 | { |
| 169 | if (DebugLogEnable) |
| 170 | { |
| 171 | @@ -63,7 +64,13 @@ bool LAppDelegate::Initialize() |
| 172 | } |
| 173 | |
| 174 | // Windowの生成_ |
| 175 | - _window = glfwCreateWindow(RenderTargetWidth, RenderTargetHeight, "SAMPLE", NULL, NULL); |
| 176 | + _window = glfwCreateWindow( |
| 177 | + initWindowWidth ? initWindowWidth : RenderTargetWidth, |
| 178 | + initWindowHeight ? initWindowHeight : RenderTargetHeight, |
| 179 | + windowTitle ? windowTitle : "SAMPLE", |
| 180 | + NULL, |
| 181 | + NULL); |
| 182 | + |
| 183 | if (_window == NULL) |
| 184 | { |
| 185 | if (DebugLogEnable) |
| 186 | @@ -95,16 +102,11 @@ bool LAppDelegate::Initialize() |
| 187 | glEnable(GL_BLEND); |
| 188 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
| 189 | |
| 190 | - //コールバック関数の登録 |
| 191 | - glfwSetMouseButtonCallback(_window, EventHandler::OnMouseCallBack); |
| 192 | - glfwSetCursorPosCallback(_window, EventHandler::OnMouseCallBack); |
| 193 | - |
| 194 | // ウィンドウサイズ記憶 |
| 195 | int width, height; |
| 196 | glfwGetWindowSize(LAppDelegate::GetInstance()->GetWindow(), &width, &height); |
| 197 | _windowWidth = width; |
| 198 | _windowHeight = height; |
| 199 | - glViewport(0, 0, _windowWidth, _windowHeight); |
| 200 | |
| 201 | //AppViewの初期化 |
| 202 | _view->Initialize(); |
| 203 | @@ -112,8 +114,6 @@ bool LAppDelegate::Initialize() |
| 204 | // Cubism3の初期化 |
| 205 | InitializeCubism(); |
| 206 | |
| 207 | - SetRootDirectory(); |
| 208 | - |
| 209 | //load model |
| 210 | LAppLive2DManager::GetInstance(); |
| 211 | |
| 212 | @@ -155,7 +155,6 @@ void LAppDelegate::Run() |
| 213 | _windowWidth = width; |
| 214 | _windowHeight = height; |
| 215 | } |
| 216 | - glViewport(0, 0, _windowWidth, _windowHeight); |
| 217 | |
| 218 | // 時間更新 |
| 219 | LAppPal::UpdateTime(); |
| 220 | @@ -216,49 +215,6 @@ void LAppDelegate::InitializeCubism() |
| 221 | LAppPal::UpdateTime(); |
| 222 | } |
| 223 | |
| 224 | -void LAppDelegate::OnMouseCallBack(GLFWwindow* window, int button, int action, int modify) |
| 225 | -{ |
| 226 | - if (_view == NULL) |
| 227 | - { |
| 228 | - return; |
| 229 | - } |
| 230 | - if (GLFW_MOUSE_BUTTON_LEFT != button) |
| 231 | - { |
| 232 | - return; |
| 233 | - } |
| 234 | - |
| 235 | - if (GLFW_PRESS == action) |
| 236 | - { |
| 237 | - _captured = true; |
| 238 | - _view->OnTouchesBegan(_mouseX, _mouseY); |
| 239 | - } |
| 240 | - else if (GLFW_RELEASE == action) |
| 241 | - { |
| 242 | - if (_captured) |
| 243 | - { |
| 244 | - _captured = false; |
| 245 | - _view->OnTouchesEnded(_mouseX, _mouseY); |
| 246 | - } |
| 247 | - } |
| 248 | -} |
| 249 | - |
| 250 | -void LAppDelegate::OnMouseCallBack(GLFWwindow* window, double x, double y) |
| 251 | -{ |
| 252 | - _mouseX = static_cast<float>(x); |
| 253 | - _mouseY = static_cast<float>(y); |
| 254 | - |
| 255 | - if (!_captured) |
| 256 | - { |
| 257 | - return; |
| 258 | - } |
| 259 | - if (_view == NULL) |
| 260 | - { |
| 261 | - return; |
| 262 | - } |
| 263 | - |
| 264 | - _view->OnTouchesMoved(_mouseX, _mouseY); |
| 265 | -} |
| 266 | - |
| 267 | GLuint LAppDelegate::CreateShader() |
| 268 | { |
| 269 | //バーテックスシェーダのコンパイル |
| 270 | @@ -301,29 +257,9 @@ GLuint LAppDelegate::CreateShader() |
| 271 | return programId; |
| 272 | } |
| 273 | |
| 274 | -void LAppDelegate::SetRootDirectory() |
| 275 | +void LAppDelegate::SetRootDirectory(std::string rootDir) |
| 276 | { |
| 277 | - char path[1024]; |
| 278 | - ssize_t len = readlink("/proc/self/exe", path, 1024 - 1); |
| 279 | - |
| 280 | - if (len != -1) |
| 281 | - { |
| 282 | - path[len] = '\0'; |
| 283 | - } |
| 284 | - |
| 285 | - std::string pathString(path); |
| 286 | - |
| 287 | - pathString = pathString.substr(0, pathString.rfind("Demo")); |
| 288 | - Csm::csmVector<string> splitStrings = this->Split(pathString, '/'); |
| 289 | - |
| 290 | - this->_rootDirectory = ""; |
| 291 | - |
| 292 | - for(int i = 0; i < splitStrings.GetSize(); i++) |
| 293 | - { |
| 294 | - this->_rootDirectory = this->_rootDirectory + "/" +splitStrings[i]; |
| 295 | - } |
| 296 | - |
| 297 | - this->_rootDirectory += "/"; |
| 298 | + this->_rootDirectory = rootDir + "/"; |
| 299 | } |
| 300 | |
| 301 | Csm::csmVector<string> LAppDelegate::Split(const std::string& baseString, char delimiter) |
| 302 | diff -pruN --exclude build ./demo_clean/src/LAppDelegate.hpp ./demo_dev/src/LAppDelegate.hpp |
| 303 | --- ./demo_clean/src/LAppDelegate.hpp 2022-09-14 12:08:43.000000000 +0100 |
| 304 | +++ ./demo_dev/src/LAppDelegate.hpp 2021-04-28 11:49:43.166296000 +0100 |
| 305 | @@ -40,7 +40,8 @@ public: |
| 306 | /** |
| 307 | * @brief APPに必要なものを初期化する。 |
| 308 | */ |
| 309 | - bool Initialize(); |
| 310 | + bool Initialize(int initWindowWidth = 0, int initWindowHeight = 0, |
| 311 | + const char *windowTitle = "SAMPLE"); |
| 312 | |
| 313 | /** |
| 314 | * @brief 解放する。 |
| 315 | @@ -53,25 +54,6 @@ public: |
| 316 | void Run(); |
| 317 | |
| 318 | /** |
| 319 | - * @brief OpenGL用 glfwSetMouseButtonCallback用関数。 |
| 320 | - * |
| 321 | - * @param[in] window コールバックを呼んだWindow情報 |
| 322 | - * @param[in] button ボタン種類 |
| 323 | - * @param[in] action 実行結果 |
| 324 | - * @param[in] modify |
| 325 | - */ |
| 326 | - void OnMouseCallBack(GLFWwindow* window, int button, int action, int modify); |
| 327 | - |
| 328 | - /** |
| 329 | - * @brief OpenGL用 glfwSetCursorPosCallback用関数。 |
| 330 | - * |
| 331 | - * @param[in] window コールバックを呼んだWindow情報 |
| 332 | - * @param[in] x x座標 |
| 333 | - * @param[in] y x座標 |
| 334 | - */ |
| 335 | - void OnMouseCallBack(GLFWwindow* window, double x, double y); |
| 336 | - |
| 337 | - /** |
| 338 | * @brief シェーダーを登録する。 |
| 339 | */ |
| 340 | GLuint CreateShader(); |
| 341 | @@ -98,8 +80,10 @@ public: |
| 342 | |
| 343 | /** |
| 344 | * @brief ルートディレクトリを設定する。 |
| 345 | + * |
| 346 | + * @param[in] rootDir : The root directory to set to. |
| 347 | */ |
| 348 | - void SetRootDirectory(); |
| 349 | + void SetRootDirectory(std::string rootDir); |
| 350 | |
| 351 | /** |
| 352 | * @brief ルートディレクトリを取得する。 |
| 353 | @@ -146,24 +130,3 @@ private: |
| 354 | int _windowWidth; ///< Initialize関数で設定したウィンドウ幅 |
| 355 | int _windowHeight; ///< Initialize関数で設定したウィンドウ高さ |
| 356 | }; |
| 357 | - |
| 358 | -class EventHandler |
| 359 | -{ |
| 360 | -public: |
| 361 | - /** |
| 362 | - * @brief glfwSetMouseButtonCallback用コールバック関数。 |
| 363 | - */ |
| 364 | - static void OnMouseCallBack(GLFWwindow* window, int button, int action, int modify) |
| 365 | - { |
| 366 | - LAppDelegate::GetInstance()->OnMouseCallBack(window, button, action, modify); |
| 367 | - } |
| 368 | - |
| 369 | - /** |
| 370 | - * @brief glfwSetCursorPosCallback用コールバック関数。 |
| 371 | - */ |
| 372 | - static void OnMouseCallBack(GLFWwindow* window, double x, double y) |
| 373 | - { |
| 374 | - LAppDelegate::GetInstance()->OnMouseCallBack(window, x, y); |
| 375 | - } |
| 376 | - |
| 377 | -}; |
| 378 | diff -pruN --exclude build ./demo_clean/src/LAppLive2DManager.cpp ./demo_dev/src/LAppLive2DManager.cpp |
| 379 | --- ./demo_clean/src/LAppLive2DManager.cpp 2022-09-14 12:08:43.000000000 +0100 |
| 380 | +++ ./demo_dev/src/LAppLive2DManager.cpp 2022-10-11 20:23:29.310727507 +0100 |
| 381 | @@ -52,11 +52,11 @@ void LAppLive2DManager::ReleaseInstance( |
| 382 | |
| 383 | LAppLive2DManager::LAppLive2DManager() |
| 384 | : _viewMatrix(NULL) |
| 385 | - , _sceneIndex(0) |
| 386 | + , _projScaleFactor(1.0f) |
| 387 | + , _translateX(0.0f) |
| 388 | + , _translateY(0.0f) |
| 389 | { |
| 390 | _viewMatrix = new CubismMatrix44(); |
| 391 | - |
| 392 | - ChangeScene(_sceneIndex); |
| 393 | } |
| 394 | |
| 395 | LAppLive2DManager::~LAppLive2DManager() |
| 396 | @@ -100,26 +100,6 @@ void LAppLive2DManager::OnTap(csmFloat32 |
| 397 | { |
| 398 | LAppPal::PrintLog("[APP]tap point: {x:%.2f y:%.2f}", x, y); |
| 399 | } |
| 400 | - |
| 401 | - for (csmUint32 i = 0; i < _models.GetSize(); i++) |
| 402 | - { |
| 403 | - if (_models[i]->HitTest(HitAreaNameHead, x, y)) |
| 404 | - { |
| 405 | - if (DebugLogEnable) |
| 406 | - { |
| 407 | - LAppPal::PrintLog("[APP]hit area: [%s]", HitAreaNameHead); |
| 408 | - } |
| 409 | - _models[i]->SetRandomExpression(); |
| 410 | - } |
| 411 | - else if (_models[i]->HitTest(HitAreaNameBody, x, y)) |
| 412 | - { |
| 413 | - if (DebugLogEnable) |
| 414 | - { |
| 415 | - LAppPal::PrintLog("[APP]hit area: [%s]", HitAreaNameBody); |
| 416 | - } |
| 417 | - _models[i]->StartRandomMotion(MotionGroupTapBody, PriorityNormal, FinishedMotion); |
| 418 | - } |
| 419 | - } |
| 420 | } |
| 421 | |
| 422 | void LAppLive2DManager::OnUpdate() const |
| 423 | @@ -127,10 +107,10 @@ void LAppLive2DManager::OnUpdate() const |
| 424 | int width, height; |
| 425 | glfwGetWindowSize(LAppDelegate::GetInstance()->GetWindow(), &width, &height); |
| 426 | |
| 427 | + CubismMatrix44 projection; |
| 428 | csmUint32 modelCount = _models.GetSize(); |
| 429 | for (csmUint32 i = 0; i < modelCount; ++i) |
| 430 | { |
| 431 | - CubismMatrix44 projection; |
| 432 | LAppModel* model = GetModel(i); |
| 433 | |
| 434 | if (model->GetModel() == NULL) |
| 435 | @@ -143,12 +123,15 @@ void LAppLive2DManager::OnUpdate() const |
| 436 | { |
| 437 | // 横に長いモデルを縦長ウィンドウに表示する際モデルの横サイズでscaleを算出する |
| 438 | model->GetModelMatrix()->SetWidth(2.0f); |
| 439 | - projection.Scale(1.0f, static_cast<float>(width) / static_cast<float>(height)); |
| 440 | + projection.Scale(_projScaleFactor, |
| 441 | + _projScaleFactor * static_cast<float>(width) / static_cast<float>(height)); |
| 442 | } |
| 443 | else |
| 444 | { |
| 445 | - projection.Scale(static_cast<float>(height) / static_cast<float>(width), 1.0f); |
| 446 | + projection.Scale(_projScaleFactor * static_cast<float>(height) / static_cast<float>(width), |
| 447 | + _projScaleFactor); |
| 448 | } |
| 449 | + projection.Translate(_translateX, _translateY); |
| 450 | |
| 451 | // 必要があればここで乗算 |
| 452 | if (_viewMatrix != NULL) |
| 453 | @@ -165,30 +148,14 @@ void LAppLive2DManager::OnUpdate() const |
| 454 | } |
| 455 | } |
| 456 | |
| 457 | -void LAppLive2DManager::NextScene() |
| 458 | -{ |
| 459 | - csmInt32 no = (_sceneIndex + 1) % ModelDirSize; |
| 460 | - ChangeScene(no); |
| 461 | -} |
| 462 | - |
| 463 | -void LAppLive2DManager::ChangeScene(Csm::csmInt32 index) |
| 464 | +void LAppLive2DManager::SetModel(std::string modelName, bool useOldParamId) |
| 465 | { |
| 466 | - _sceneIndex = index; |
| 467 | - if (DebugLogEnable) |
| 468 | - { |
| 469 | - LAppPal::PrintLog("[APP]model index: %d", _sceneIndex); |
| 470 | - } |
| 471 | - |
| 472 | - // ModelDir[]に保持したディレクトリ名から |
| 473 | - // model3.jsonのパスを決定する. |
| 474 | - // ディレクトリ名とmodel3.jsonの名前を一致させておくこと. |
| 475 | - std::string model = ModelDir[index]; |
| 476 | - std::string modelPath = LAppDelegate::GetInstance()->GetRootDirectory() + ResourcesPath + model + "/"; |
| 477 | - std::string modelJsonName = ModelDir[index]; |
| 478 | + std::string modelPath = LAppDelegate::GetInstance()->GetRootDirectory() + ResourcesPath + modelName + "/"; |
| 479 | + std::string modelJsonName = modelName; |
| 480 | modelJsonName += ".model3.json"; |
| 481 | |
| 482 | ReleaseAllModel(); |
| 483 | - _models.PushBack(new LAppModel()); |
| 484 | + _models.PushBack(new LAppModel(useOldParamId)); |
| 485 | _models[0]->LoadAssets(modelPath.c_str(), modelJsonName.c_str()); |
| 486 | |
| 487 | /* |
| 488 | @@ -210,7 +177,7 @@ void LAppLive2DManager::ChangeScene(Csm: |
| 489 | |
| 490 | #if defined(USE_RENDER_TARGET) || defined(USE_MODEL_RENDER_TARGET) |
| 491 | // モデル個別にαを付けるサンプルとして、もう1体モデルを作成し、少し位置をずらす |
| 492 | - _models.PushBack(new LAppModel()); |
| 493 | + _models.PushBack(new LAppModel(useOldParamId)); |
| 494 | _models[1]->LoadAssets(modelPath.c_str(), modelJsonName.c_str()); |
| 495 | _models[1]->GetModelMatrix()->TranslateX(0.2f); |
| 496 | #endif |
| 497 | @@ -239,3 +206,20 @@ void LAppLive2DManager::SetViewMatrix(Cu |
| 498 | _viewMatrix->GetArray()[i] = m->GetArray()[i]; |
| 499 | } |
| 500 | } |
| 501 | + |
| 502 | +void LAppLive2DManager::SetFacialLandmarkDetector(FacialLandmarkDetector *detector) |
| 503 | +{ |
| 504 | + for (auto it = _models.Begin(); it != _models.End(); ++it) |
| 505 | + { |
| 506 | + (*it)->SetFacialLandmarkDetector(detector); |
| 507 | + } |
| 508 | +} |
| 509 | + |
| 510 | +void LAppLive2DManager::SetProjectionScaleTranslate(float scaleFactor, |
| 511 | + float translateX, |
| 512 | + float translateY) |
| 513 | +{ |
| 514 | + _projScaleFactor = scaleFactor; |
| 515 | + _translateX = translateX; |
| 516 | + _translateY = translateY; |
| 517 | +} |
| 518 | diff -pruN --exclude build ./demo_clean/src/LAppLive2DManager.hpp ./demo_dev/src/LAppLive2DManager.hpp |
| 519 | --- ./demo_clean/src/LAppLive2DManager.hpp 2022-09-14 12:08:43.000000000 +0100 |
| 520 | +++ ./demo_dev/src/LAppLive2DManager.hpp 2021-04-28 11:49:43.166296000 +0100 |
| 521 | @@ -6,12 +6,15 @@ |
| 522 | */ |
| 523 | #pragma once |
| 524 | |
| 525 | +#include <string> |
| 526 | #include <CubismFramework.hpp> |
| 527 | #include <Math/CubismMatrix44.hpp> |
| 528 | #include <Type/csmVector.hpp> |
| 529 | |
| 530 | class LAppModel; |
| 531 | |
| 532 | +class FacialLandmarkDetector; |
| 533 | + |
| 534 | /** |
| 535 | * @brief サンプルアプリケーションにおいてCubismModelを管理するクラス<br> |
| 536 | * モデル生成と破棄、タップイベントの処理、モデル切り替えを行う。 |
| 537 | @@ -72,16 +75,14 @@ public: |
| 538 | void OnUpdate() const; |
| 539 | |
| 540 | /** |
| 541 | - * @brief 次のシーンに切り替える<br> |
| 542 | - * サンプルアプリケーションではモデルセットの切り替えを行う。 |
| 543 | - */ |
| 544 | - void NextScene(); |
| 545 | - |
| 546 | - /** |
| 547 | - * @brief シーンを切り替える<br> |
| 548 | - * サンプルアプリケーションではモデルセットの切り替えを行う。 |
| 549 | - */ |
| 550 | - void ChangeScene(Csm::csmInt32 index); |
| 551 | + * @brief Set model data |
| 552 | + * |
| 553 | + * @param[in] modelName : Name of model, should be the same for both |
| 554 | + * the directory and the model3.json file |
| 555 | + * @param[in] useOldParamId : If true, translate new (Cubism 3+) |
| 556 | + * parameter IDs to old (Cubism 2.1) ones |
| 557 | + */ |
| 558 | + void SetModel(std::string modelName, bool useOldParamId); |
| 559 | |
| 560 | /** |
| 561 | * @brief モデル個数を得る |
| 562 | @@ -94,6 +95,24 @@ public: |
| 563 | */ |
| 564 | void SetViewMatrix(Live2D::Cubism::Framework::CubismMatrix44* m); |
| 565 | |
| 566 | + /** |
| 567 | + * @brief Set the pointer to the FacialLandmarkDetector instance |
| 568 | + * |
| 569 | + * @param[in] detector : Pointer to FacialLandmarkDetector instance |
| 570 | + */ |
| 571 | + void SetFacialLandmarkDetector(FacialLandmarkDetector *detector); |
| 572 | + |
| 573 | + /** |
| 574 | + * @brief Set projection scale factor and translation parameters |
| 575 | + * |
| 576 | + * @param[in] scaleFactor : Scale factor applied in both X and Y directions |
| 577 | + * @param[in] translateX : Translation in X direction |
| 578 | + * @param[in] translateY : Translation in Y direction |
| 579 | + */ |
| 580 | + void SetProjectionScaleTranslate(float scaleFactor, |
| 581 | + float translateX, |
| 582 | + float translateY); |
| 583 | + |
| 584 | private: |
| 585 | /** |
| 586 | * @brief コンストラクタ |
| 587 | @@ -107,5 +126,8 @@ private: |
| 588 | |
| 589 | Csm::CubismMatrix44* _viewMatrix; ///< モデル描画に用いるView行列 |
| 590 | Csm::csmVector<LAppModel*> _models; ///< モデルインスタンスのコンテナ |
| 591 | - Csm::csmInt32 _sceneIndex; ///< 表示するシーンのインデックス値 |
| 592 | + |
| 593 | + float _projScaleFactor; |
| 594 | + float _translateX; |
| 595 | + float _translateY; |
| 596 | }; |
| 597 | diff -pruN --exclude build ./demo_clean/src/LAppModel.cpp ./demo_dev/src/LAppModel.cpp |
| 598 | --- ./demo_clean/src/LAppModel.cpp 2022-09-14 12:08:43.000000000 +0100 |
| 599 | +++ ./demo_dev/src/LAppModel.cpp 2021-04-28 11:49:43.166296000 +0100 |
| 600 | @@ -21,6 +21,8 @@ |
| 601 | #include "LAppTextureManager.hpp" |
| 602 | #include "LAppDelegate.hpp" |
| 603 | |
| 604 | +#include "facial_landmark_detector.h" |
| 605 | + |
| 606 | using namespace Live2D::Cubism::Framework; |
| 607 | using namespace Live2D::Cubism::Framework::DefaultParameterId; |
| 608 | using namespace LAppDefine; |
| 609 | @@ -45,22 +47,24 @@ namespace { |
| 610 | } |
| 611 | } |
| 612 | |
| 613 | -LAppModel::LAppModel() |
| 614 | +LAppModel::LAppModel(bool useOldParamId) |
| 615 | : CubismUserModel() |
| 616 | , _modelSetting(NULL) |
| 617 | , _userTimeSeconds(0.0f) |
| 618 | + , _detector(nullptr) |
| 619 | + , _useOldParamId(useOldParamId) |
| 620 | { |
| 621 | if (DebugLogEnable) |
| 622 | { |
| 623 | _debugMode = true; |
| 624 | } |
| 625 | |
| 626 | - _idParamAngleX = CubismFramework::GetIdManager()->GetId(ParamAngleX); |
| 627 | - _idParamAngleY = CubismFramework::GetIdManager()->GetId(ParamAngleY); |
| 628 | - _idParamAngleZ = CubismFramework::GetIdManager()->GetId(ParamAngleZ); |
| 629 | - _idParamBodyAngleX = CubismFramework::GetIdManager()->GetId(ParamBodyAngleX); |
| 630 | - _idParamEyeBallX = CubismFramework::GetIdManager()->GetId(ParamEyeBallX); |
| 631 | - _idParamEyeBallY = CubismFramework::GetIdManager()->GetId(ParamEyeBallY); |
| 632 | + _idParamAngleX = CubismFramework::GetIdManager()->GetId(_(ParamAngleX)); |
| 633 | + _idParamAngleY = CubismFramework::GetIdManager()->GetId(_(ParamAngleY)); |
| 634 | + _idParamAngleZ = CubismFramework::GetIdManager()->GetId(_(ParamAngleZ)); |
| 635 | + _idParamBodyAngleX = CubismFramework::GetIdManager()->GetId(_(ParamBodyAngleX)); |
| 636 | + _idParamEyeBallX = CubismFramework::GetIdManager()->GetId(_(ParamEyeBallX)); |
| 637 | + _idParamEyeBallY = CubismFramework::GetIdManager()->GetId(_(ParamEyeBallY)); |
| 638 | } |
| 639 | |
| 640 | LAppModel::~LAppModel() |
| 641 | @@ -96,12 +100,6 @@ void LAppModel::LoadAssets(const csmChar |
| 642 | |
| 643 | SetupModel(setting); |
| 644 | |
| 645 | - if (_model == NULL) |
| 646 | - { |
| 647 | - LAppPal::PrintLog("Failed to LoadAssets()."); |
| 648 | - return; |
| 649 | - } |
| 650 | - |
| 651 | CreateRenderer(); |
| 652 | |
| 653 | SetupTextures(); |
| 654 | @@ -134,30 +132,6 @@ void LAppModel::SetupModel(ICubismModelS |
| 655 | DeleteBuffer(buffer, path.GetRawString()); |
| 656 | } |
| 657 | |
| 658 | - //Expression |
| 659 | - if (_modelSetting->GetExpressionCount() > 0) |
| 660 | - { |
| 661 | - const csmInt32 count = _modelSetting->GetExpressionCount(); |
| 662 | - for (csmInt32 i = 0; i < count; i++) |
| 663 | - { |
| 664 | - csmString name = _modelSetting->GetExpressionName(i); |
| 665 | - csmString path = _modelSetting->GetExpressionFileName(i); |
| 666 | - path = _modelHomeDir + path; |
| 667 | - |
| 668 | - buffer = CreateBuffer(path.GetRawString(), &size); |
| 669 | - ACubismMotion* motion = LoadExpression(buffer, size, name.GetRawString()); |
| 670 | - |
| 671 | - if (_expressions[name] != NULL) |
| 672 | - { |
| 673 | - ACubismMotion::Delete(_expressions[name]); |
| 674 | - _expressions[name] = NULL; |
| 675 | - } |
| 676 | - _expressions[name] = motion; |
| 677 | - |
| 678 | - DeleteBuffer(buffer, path.GetRawString()); |
| 679 | - } |
| 680 | - } |
| 681 | - |
| 682 | //Physics |
| 683 | if (strcmp(_modelSetting->GetPhysicsFileName(), "") != 0) |
| 684 | { |
| 685 | @@ -196,7 +170,7 @@ void LAppModel::SetupModel(ICubismModelS |
| 686 | breathParameters.PushBack(CubismBreath::BreathParameterData(_idParamAngleY, 0.0f, 8.0f, 3.5345f, 0.5f)); |
| 687 | breathParameters.PushBack(CubismBreath::BreathParameterData(_idParamAngleZ, 0.0f, 10.0f, 5.5345f, 0.5f)); |
| 688 | breathParameters.PushBack(CubismBreath::BreathParameterData(_idParamBodyAngleX, 0.0f, 4.0f, 15.5345f, 0.5f)); |
| 689 | - breathParameters.PushBack(CubismBreath::BreathParameterData(CubismFramework::GetIdManager()->GetId(ParamBreath), 0.5f, 0.5f, 3.2345f, 0.5f)); |
| 690 | + breathParameters.PushBack(CubismBreath::BreathParameterData(CubismFramework::GetIdManager()->GetId(_(ParamBreath)), 0.5f, 0.5f, 3.2345f, 0.5f)); |
| 691 | |
| 692 | _breath->SetParameters(breathParameters); |
| 693 | } |
| 694 | @@ -220,21 +194,6 @@ void LAppModel::SetupModel(ICubismModelS |
| 695 | } |
| 696 | } |
| 697 | |
| 698 | - // LipSyncIds |
| 699 | - { |
| 700 | - csmInt32 lipSyncIdCount = _modelSetting->GetLipSyncParameterCount(); |
| 701 | - for (csmInt32 i = 0; i < lipSyncIdCount; ++i) |
| 702 | - { |
| 703 | - _lipSyncIds.PushBack(_modelSetting->GetLipSyncParameterId(i)); |
| 704 | - } |
| 705 | - } |
| 706 | - |
| 707 | - if (_modelSetting == NULL || _modelMatrix == NULL) |
| 708 | - { |
| 709 | - LAppPal::PrintLog("Failed to SetupModel()."); |
| 710 | - return; |
| 711 | - } |
| 712 | - |
| 713 | //Layout |
| 714 | csmMap<csmString, csmFloat32> layout; |
| 715 | _modelSetting->GetLayoutMap(layout); |
| 716 | @@ -347,59 +306,57 @@ void LAppModel::Update() |
| 717 | const csmFloat32 deltaTimeSeconds = LAppPal::GetDeltaTime(); |
| 718 | _userTimeSeconds += deltaTimeSeconds; |
| 719 | |
| 720 | - _dragManager->Update(deltaTimeSeconds); |
| 721 | - _dragX = _dragManager->GetX(); |
| 722 | - _dragY = _dragManager->GetY(); |
| 723 | - |
| 724 | - // モーションによるパラメータ更新の有無 |
| 725 | - csmBool motionUpdated = false; |
| 726 | - |
| 727 | - //----------------------------------------------------------------- |
| 728 | - _model->LoadParameters(); // 前回セーブされた状態をロード |
| 729 | - if (_motionManager->IsFinished()) |
| 730 | - { |
| 731 | - // モーションの再生がない場合、待機モーションの中からランダムで再生する |
| 732 | - StartRandomMotion(MotionGroupIdle, PriorityIdle); |
| 733 | - } |
| 734 | - else |
| 735 | + if (_detector) |
| 736 | { |
| 737 | - motionUpdated = _motionManager->UpdateMotion(_model, deltaTimeSeconds); // モーションを更新 |
| 738 | - } |
| 739 | - _model->SaveParameters(); // 状態を保存 |
| 740 | - //----------------------------------------------------------------- |
| 741 | + auto idMan = CubismFramework::GetIdManager(); |
| 742 | + auto params = _detector->getParams(); |
| 743 | |
| 744 | - // まばたき |
| 745 | - if (!motionUpdated) |
| 746 | - { |
| 747 | - if (_eyeBlink != NULL) |
| 748 | + // NOTE: Apparently, this LoadParameters/SaveParameters pair |
| 749 | + // is needed for auto breath to work. |
| 750 | + _model->LoadParameters(); // 前回セーブされた状態をロード |
| 751 | + if (_motionManager->IsFinished() && params.randomMotion) |
| 752 | { |
| 753 | - // メインモーションの更新がないとき |
| 754 | - _eyeBlink->UpdateParameters(_model, deltaTimeSeconds); // 目パチ |
| 755 | + // モーションの再生がない場合、待機モーションの中からランダムで再生する |
| 756 | + StartRandomMotion(MotionGroupIdle, PriorityIdle); |
| 757 | } |
| 758 | - } |
| 759 | - |
| 760 | - if (_expressionManager != NULL) |
| 761 | - { |
| 762 | - _expressionManager->UpdateMotion(_model, deltaTimeSeconds); // 表情でパラメータ更新(相対変化) |
| 763 | - } |
| 764 | - |
| 765 | - //ドラッグによる変化 |
| 766 | - //ドラッグによる顔の向きの調整 |
| 767 | - _model->AddParameterValue(_idParamAngleX, _dragX * 30); // -30から30の値を加える |
| 768 | - _model->AddParameterValue(_idParamAngleY, _dragY * 30); |
| 769 | - _model->AddParameterValue(_idParamAngleZ, _dragX * _dragY * -30); |
| 770 | - |
| 771 | - //ドラッグによる体の向きの調整 |
| 772 | - _model->AddParameterValue(_idParamBodyAngleX, _dragX * 10); // -10から10の値を加える |
| 773 | + else |
| 774 | + { |
| 775 | + _motionManager->UpdateMotion(_model, deltaTimeSeconds); // モーションを更新 |
| 776 | + } |
| 777 | + _model->SaveParameters(); // 状態を保存 |
| 778 | |
| 779 | - //ドラッグによる目の向きの調整 |
| 780 | - _model->AddParameterValue(_idParamEyeBallX, _dragX); // -1から1の値を加える |
| 781 | - _model->AddParameterValue(_idParamEyeBallY, _dragY); |
| 782 | |
| 783 | - // 呼吸など |
| 784 | - if (_breath != NULL) |
| 785 | - { |
| 786 | - _breath->UpdateParameters(_model, deltaTimeSeconds); |
| 787 | + if (params.autoBlink && _eyeBlink) |
| 788 | + { |
| 789 | + _eyeBlink->UpdateParameters(_model, deltaTimeSeconds); |
| 790 | + } |
| 791 | + else |
| 792 | + { |
| 793 | + _model->SetParameterValue(idMan->GetId(_("ParamEyeLOpen")), |
| 794 | + params.leftEyeOpenness); |
| 795 | + _model->SetParameterValue(idMan->GetId(_("ParamEyeROpen")), |
| 796 | + params.rightEyeOpenness); |
| 797 | + } |
| 798 | + _model->SetParameterValue(idMan->GetId(_("ParamMouthForm")), |
| 799 | + params.mouthForm); |
| 800 | + _model->SetParameterValue(idMan->GetId(_("ParamMouthOpenY")), |
| 801 | + params.mouthOpenness); |
| 802 | + _model->SetParameterValue(idMan->GetId(_("ParamEyeLSmile")), |
| 803 | + params.leftEyeSmile); |
| 804 | + _model->SetParameterValue(idMan->GetId(_("ParamEyeRSmile")), |
| 805 | + params.rightEyeSmile); |
| 806 | + _model->SetParameterValue(idMan->GetId(_("ParamAngleX")), |
| 807 | + params.faceXAngle); |
| 808 | + _model->SetParameterValue(idMan->GetId(_("ParamAngleY")), |
| 809 | + params.faceYAngle); |
| 810 | + _model->SetParameterValue(idMan->GetId(_("ParamAngleZ")), |
| 811 | + params.faceZAngle); |
| 812 | + if (params.autoBreath && _breath) |
| 813 | + { |
| 814 | + // Note: _model->LoadParameters and SaveParameters is needed |
| 815 | + // before - see above. |
| 816 | + _breath->UpdateParameters(_model, deltaTimeSeconds); |
| 817 | + } |
| 818 | } |
| 819 | |
| 820 | // 物理演算の設定 |
| 821 | @@ -408,22 +365,6 @@ void LAppModel::Update() |
| 822 | _physics->Evaluate(_model, deltaTimeSeconds); |
| 823 | } |
| 824 | |
| 825 | - // リップシンクの設定 |
| 826 | - if (_lipSync) |
| 827 | - { |
| 828 | - // リアルタイムでリップシンクを行う場合、システムから音量を取得して0〜1の範囲で値を入力します。 |
| 829 | - csmFloat32 value = 0.0f; |
| 830 | - |
| 831 | - // 状態更新/RMS値取得 |
| 832 | - _wavFileHandler.Update(deltaTimeSeconds); |
| 833 | - value = _wavFileHandler.GetRms(); |
| 834 | - |
| 835 | - for (csmUint32 i = 0; i < _lipSyncIds.GetSize(); ++i) |
| 836 | - { |
| 837 | - _model->AddParameterValue(_lipSyncIds[i], value, 0.8f); |
| 838 | - } |
| 839 | - } |
| 840 | - |
| 841 | // ポーズの設定 |
| 842 | if (_pose != NULL) |
| 843 | { |
| 844 | @@ -492,7 +433,6 @@ CubismMotionQueueEntryHandle LAppModel:: |
| 845 | { |
| 846 | csmString path = voice; |
| 847 | path = _modelHomeDir + path; |
| 848 | - _wavFileHandler.Start(path); |
| 849 | } |
| 850 | |
| 851 | if (_debugMode) |
| 852 | @@ -644,3 +584,37 @@ Csm::Rendering::CubismOffscreenFrame_Ope |
| 853 | { |
| 854 | return _renderBuffer; |
| 855 | } |
| 856 | + |
| 857 | +void LAppModel::SetFacialLandmarkDetector(FacialLandmarkDetector *detector) |
| 858 | +{ |
| 859 | + _detector = detector; |
| 860 | +} |
| 861 | + |
| 862 | +Csm::csmString LAppModel::_(std::string s) |
| 863 | +{ |
| 864 | + std::string ans; |
| 865 | + if (_useOldParamId) |
| 866 | + { |
| 867 | + if (s == "ParamTere") |
| 868 | + { |
| 869 | + ans = "PARAM_CHEEK"; |
| 870 | + } |
| 871 | + else |
| 872 | + { |
| 873 | + for (size_t i = 0; i < s.size(); i++) |
| 874 | + { |
| 875 | + if (std::isupper(s[i]) && i != 0) |
| 876 | + { |
| 877 | + ans += '_'; |
| 878 | + } |
| 879 | + ans += std::toupper(s[i]); |
| 880 | + } |
| 881 | + } |
| 882 | + } |
| 883 | + else |
| 884 | + { |
| 885 | + ans = s; |
| 886 | + } |
| 887 | + return csmString(ans.c_str()); |
| 888 | +} |
| 889 | + |
| 890 | diff -pruN --exclude build ./demo_clean/src/LAppModel.hpp ./demo_dev/src/LAppModel.hpp |
| 891 | --- ./demo_clean/src/LAppModel.hpp 2022-09-14 12:08:43.000000000 +0100 |
| 892 | +++ ./demo_dev/src/LAppModel.hpp 2021-04-28 11:49:43.166296000 +0100 |
| 893 | @@ -13,7 +13,7 @@ |
| 894 | #include <Type/csmRectF.hpp> |
| 895 | #include <Rendering/OpenGL/CubismOffscreenSurface_OpenGLES2.hpp> |
| 896 | |
| 897 | -#include "LAppWavFileHandler.hpp" |
| 898 | +#include "facial_landmark_detector.h" |
| 899 | |
| 900 | /** |
| 901 | * @brief ユーザーが実際に使用するモデルの実装クラス<br> |
| 902 | @@ -25,8 +25,11 @@ class LAppModel : public Csm::CubismUser |
| 903 | public: |
| 904 | /** |
| 905 | * @brief コンストラクタ |
| 906 | + * |
| 907 | + * @param[in] useOldParamId : If true, translate new (Cubism 3+) |
| 908 | + * parameter IDs to old (Cubism 2.1) ones |
| 909 | */ |
| 910 | - LAppModel(); |
| 911 | + LAppModel(bool useOldParamId); |
| 912 | |
| 913 | /** |
| 914 | * @brief デストラクタ |
| 915 | @@ -114,6 +117,13 @@ public: |
| 916 | */ |
| 917 | Csm::Rendering::CubismOffscreenFrame_OpenGLES2& GetRenderBuffer(); |
| 918 | |
| 919 | + /** |
| 920 | + * @brief Set the pointer to the FacialLandmarkDetector instance |
| 921 | + * |
| 922 | + * @param[in] detector : Pointer to FacialLandmarkDetector instance |
| 923 | + */ |
| 924 | + void SetFacialLandmarkDetector(FacialLandmarkDetector *detector); |
| 925 | + |
| 926 | protected: |
| 927 | /** |
| 928 | * @brief モデルを描画する処理。モデルを描画する空間のView-Projection行列を渡す。 |
| 929 | @@ -167,6 +177,17 @@ private: |
| 930 | */ |
| 931 | void ReleaseExpressions(); |
| 932 | |
| 933 | + /** |
| 934 | + * @brief Translate new (Cubism 3+) parameter IDs to old (Cubism 2.1) ones |
| 935 | + * |
| 936 | + * @param[in] s : New parameter ID |
| 937 | + * |
| 938 | + * @return Old parameter ID |
| 939 | + */ |
| 940 | + Csm::csmString _(std::string s); |
| 941 | + |
| 942 | + bool _useOldParamId; |
| 943 | + |
| 944 | Csm::ICubismModelSetting* _modelSetting; ///< モデルセッティング情報 |
| 945 | Csm::csmString _modelHomeDir; ///< モデルセッティングが置かれたディレクトリ |
| 946 | Csm::csmFloat32 _userTimeSeconds; ///< デルタ時間の積算値[秒] |
| 947 | @@ -183,9 +204,9 @@ private: |
| 948 | const Csm::CubismId* _idParamEyeBallX; ///< パラメータID: ParamEyeBallX |
| 949 | const Csm::CubismId* _idParamEyeBallY; ///< パラメータID: ParamEyeBallXY |
| 950 | |
| 951 | - LAppWavFileHandler _wavFileHandler; ///< wavファイルハンドラ |
| 952 | - |
| 953 | Csm::Rendering::CubismOffscreenFrame_OpenGLES2 _renderBuffer; ///< フレームバッファ以外の描画先 |
| 954 | + |
| 955 | + FacialLandmarkDetector *_detector; |
| 956 | }; |
| 957 | |
| 958 | |
| 959 | diff -pruN --exclude build ./demo_clean/src/LAppPal.cpp ./demo_dev/src/LAppPal.cpp |
| 960 | --- ./demo_clean/src/LAppPal.cpp 2022-09-14 12:08:43.000000000 +0100 |
| 961 | +++ ./demo_dev/src/LAppPal.cpp 2021-04-28 11:49:43.170296000 +0100 |
| 962 | @@ -6,6 +6,7 @@ |
| 963 | */ |
| 964 | |
| 965 | #include "LAppPal.hpp" |
| 966 | +#include <stdexcept> |
| 967 | #include <stdio.h> |
| 968 | #include <stdlib.h> |
| 969 | #include <stdarg.h> |
| 970 | @@ -45,10 +46,7 @@ csmByte* LAppPal::LoadFileAsBytes(const |
| 971 | file.open(path, std::ios::in | std::ios::binary); |
| 972 | if (!file.is_open()) |
| 973 | { |
| 974 | - if (DebugLogEnable) |
| 975 | - { |
| 976 | - PrintLog("file open error"); |
| 977 | - } |
| 978 | + throw std::runtime_error("Failed to open file " + filePath); |
| 979 | return NULL; |
| 980 | } |
| 981 | file.read(buf, size); |
| 982 | diff -pruN --exclude build ./demo_clean/src/LAppTextureManager.cpp ./demo_dev/src/LAppTextureManager.cpp |
| 983 | --- ./demo_clean/src/LAppTextureManager.cpp 2022-09-14 12:08:43.000000000 +0100 |
| 984 | +++ ./demo_dev/src/LAppTextureManager.cpp 2021-04-28 11:49:43.178296000 +0100 |
| 985 | @@ -96,6 +96,46 @@ LAppTextureManager::TextureInfo* LAppTex |
| 986 | |
| 987 | } |
| 988 | |
| 989 | +LAppTextureManager::TextureInfo* LAppTextureManager::CreateTextureFromColor( |
| 990 | + uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha |
| 991 | +) |
| 992 | +{ |
| 993 | + int width = 8, height = 8; |
| 994 | + |
| 995 | + uint8_t pixels[height][width][4]; |
| 996 | + for (std::size_t h = 0; h < height; h++) |
| 997 | + { |
| 998 | + for (std::size_t w = 0; w < width; w++) |
| 999 | + { |
| 1000 | + pixels[h][w][0] = red; |
| 1001 | + pixels[h][w][1] = green; |
| 1002 | + pixels[h][w][2] = blue; |
| 1003 | + pixels[h][w][3] = alpha; |
| 1004 | + } |
| 1005 | + } |
| 1006 | + |
| 1007 | + GLuint textureId; |
| 1008 | + glGenTextures(1, &textureId); |
| 1009 | + glBindTexture(GL_TEXTURE_2D, textureId); |
| 1010 | + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels); |
| 1011 | + |
| 1012 | + glGenerateMipmap(GL_TEXTURE_2D); |
| 1013 | + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); |
| 1014 | + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); |
| 1015 | + glBindTexture(GL_TEXTURE_2D, 0); |
| 1016 | + |
| 1017 | + |
| 1018 | + LAppTextureManager::TextureInfo* textureInfo = new LAppTextureManager::TextureInfo(); |
| 1019 | + textureInfo->fileName = ""; |
| 1020 | + textureInfo->width = width; |
| 1021 | + textureInfo->height = height; |
| 1022 | + textureInfo->id = textureId; |
| 1023 | + |
| 1024 | + _textures.PushBack(textureInfo); |
| 1025 | + |
| 1026 | + return textureInfo; |
| 1027 | +} |
| 1028 | + |
| 1029 | void LAppTextureManager::ReleaseTextures() |
| 1030 | { |
| 1031 | for (Csm::csmUint32 i = 0; i < _textures.GetSize(); i++) |
| 1032 | diff -pruN --exclude build ./demo_clean/src/LAppTextureManager.hpp ./demo_dev/src/LAppTextureManager.hpp |
| 1033 | --- ./demo_clean/src/LAppTextureManager.hpp 2022-09-14 12:08:43.000000000 +0100 |
| 1034 | +++ ./demo_dev/src/LAppTextureManager.hpp 2021-04-28 11:49:43.178296000 +0100 |
| 1035 | @@ -72,6 +72,8 @@ public: |
| 1036 | */ |
| 1037 | TextureInfo* CreateTextureFromPngFile(std::string fileName); |
| 1038 | |
| 1039 | + TextureInfo *CreateTextureFromColor(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha = 255); |
| 1040 | + |
| 1041 | /** |
| 1042 | * @brief 画像の解放 |
| 1043 | * |
| 1044 | diff -pruN --exclude build ./demo_clean/src/LAppView.cpp ./demo_dev/src/LAppView.cpp |
| 1045 | --- ./demo_clean/src/LAppView.cpp 2022-09-14 12:08:43.000000000 +0100 |
| 1046 | +++ ./demo_dev/src/LAppView.cpp 2021-04-28 11:49:43.178296000 +0100 |
| 1047 | @@ -13,7 +13,6 @@ |
| 1048 | #include "LAppLive2DManager.hpp" |
| 1049 | #include "LAppTextureManager.hpp" |
| 1050 | #include "LAppDefine.hpp" |
| 1051 | -#include "TouchManager.hpp" |
| 1052 | #include "LAppSprite.hpp" |
| 1053 | #include "LAppModel.hpp" |
| 1054 | |
| 1055 | @@ -26,8 +25,6 @@ using namespace LAppDefine; |
| 1056 | LAppView::LAppView(): |
| 1057 | _programId(0), |
| 1058 | _back(NULL), |
| 1059 | - _gear(NULL), |
| 1060 | - _power(NULL), |
| 1061 | _renderSprite(NULL), |
| 1062 | _renderTarget(SelectTarget_None) |
| 1063 | { |
| 1064 | @@ -35,8 +32,6 @@ LAppView::LAppView(): |
| 1065 | _clearColor[1] = 1.0f; |
| 1066 | _clearColor[2] = 1.0f; |
| 1067 | _clearColor[3] = 0.0f; |
| 1068 | - // タッチ関係のイベント管理 |
| 1069 | - _touchManager = new TouchManager(); |
| 1070 | |
| 1071 | // デバイス座標からスクリーン座標に変換するための |
| 1072 | _deviceToScreen = new CubismMatrix44(); |
| 1073 | @@ -52,10 +47,7 @@ LAppView::~LAppView() |
| 1074 | |
| 1075 | delete _viewMatrix; |
| 1076 | delete _deviceToScreen; |
| 1077 | - delete _touchManager; |
| 1078 | delete _back; |
| 1079 | - delete _gear; |
| 1080 | - delete _power; |
| 1081 | } |
| 1082 | |
| 1083 | void LAppView::Initialize() |
| 1084 | @@ -107,9 +99,6 @@ void LAppView::Initialize() |
| 1085 | void LAppView::Render() |
| 1086 | { |
| 1087 | _back->Render(); |
| 1088 | - _gear->Render(); |
| 1089 | - _power->Render(); |
| 1090 | - |
| 1091 | |
| 1092 | LAppLive2DManager* Live2DManager = LAppLive2DManager::GetInstance(); |
| 1093 | |
| 1094 | @@ -151,35 +140,17 @@ void LAppView::InitializeSprite() |
| 1095 | glfwGetWindowSize(LAppDelegate::GetInstance()->GetWindow(), &width, &height); |
| 1096 | |
| 1097 | LAppTextureManager* textureManager = LAppDelegate::GetInstance()->GetTextureManager(); |
| 1098 | - const string resourcesPath = LAppDelegate::GetInstance()->GetRootDirectory() + ResourcesPath; |
| 1099 | |
| 1100 | - string imageName = BackImageName; |
| 1101 | - LAppTextureManager::TextureInfo* backgroundTexture = textureManager->CreateTextureFromPngFile(resourcesPath + imageName); |
| 1102 | + |
| 1103 | + LAppTextureManager::TextureInfo* backgroundTexture = |
| 1104 | + textureManager->CreateTextureFromColor(0, 255, 0); |
| 1105 | |
| 1106 | float x = width * 0.5f; |
| 1107 | float y = height * 0.5f; |
| 1108 | - float fWidth = static_cast<float>(backgroundTexture->width * 2.0f); |
| 1109 | - float fHeight = static_cast<float>(height) * 0.95f; |
| 1110 | + float fWidth = static_cast<float>(width); |
| 1111 | + float fHeight = static_cast<float>(height); |
| 1112 | _back = new LAppSprite(x, y, fWidth, fHeight, backgroundTexture->id, _programId); |
| 1113 | |
| 1114 | - imageName = GearImageName; |
| 1115 | - LAppTextureManager::TextureInfo* gearTexture = textureManager->CreateTextureFromPngFile(resourcesPath + imageName); |
| 1116 | - |
| 1117 | - x = static_cast<float>(width - gearTexture->width * 0.5f); |
| 1118 | - y = static_cast<float>(height - gearTexture->height * 0.5f); |
| 1119 | - fWidth = static_cast<float>(gearTexture->width); |
| 1120 | - fHeight = static_cast<float>(gearTexture->height); |
| 1121 | - _gear = new LAppSprite(x, y, fWidth, fHeight, gearTexture->id, _programId); |
| 1122 | - |
| 1123 | - imageName = PowerImageName; |
| 1124 | - LAppTextureManager::TextureInfo* powerTexture = textureManager->CreateTextureFromPngFile(resourcesPath + imageName); |
| 1125 | - |
| 1126 | - x = static_cast<float>(width - powerTexture->width * 0.5f); |
| 1127 | - y = static_cast<float>(powerTexture->height * 0.5f); |
| 1128 | - fWidth = static_cast<float>(powerTexture->width); |
| 1129 | - fHeight = static_cast<float>(powerTexture->height); |
| 1130 | - _power = new LAppSprite(x, y, fWidth, fHeight, powerTexture->id, _programId); |
| 1131 | - |
| 1132 | // 画面全体を覆うサイズ |
| 1133 | x = width * 0.5f; |
| 1134 | y = height * 0.5f; |
| 1135 | @@ -187,52 +158,6 @@ void LAppView::InitializeSprite() |
| 1136 | |
| 1137 | } |
| 1138 | |
| 1139 | -void LAppView::OnTouchesBegan(float px, float py) const |
| 1140 | -{ |
| 1141 | - _touchManager->TouchesBegan(px, py); |
| 1142 | -} |
| 1143 | - |
| 1144 | -void LAppView::OnTouchesMoved(float px, float py) const |
| 1145 | -{ |
| 1146 | - float viewX = this->TransformViewX(_touchManager->GetX()); |
| 1147 | - float viewY = this->TransformViewY(_touchManager->GetY()); |
| 1148 | - |
| 1149 | - _touchManager->TouchesMoved(px, py); |
| 1150 | - |
| 1151 | - LAppLive2DManager* Live2DManager = LAppLive2DManager::GetInstance(); |
| 1152 | - Live2DManager->OnDrag(viewX, viewY); |
| 1153 | -} |
| 1154 | - |
| 1155 | -void LAppView::OnTouchesEnded(float px, float py) const |
| 1156 | -{ |
| 1157 | - // タッチ終了 |
| 1158 | - LAppLive2DManager* live2DManager = LAppLive2DManager::GetInstance(); |
| 1159 | - live2DManager->OnDrag(0.0f, 0.0f); |
| 1160 | - { |
| 1161 | - |
| 1162 | - // シングルタップ |
| 1163 | - float x = _deviceToScreen->TransformX(_touchManager->GetX()); // 論理座標変換した座標を取得。 |
| 1164 | - float y = _deviceToScreen->TransformY(_touchManager->GetY()); // 論理座標変換した座標を取得。 |
| 1165 | - if (DebugTouchLogEnable) |
| 1166 | - { |
| 1167 | - LAppPal::PrintLog("[APP]touchesEnded x:%.2f y:%.2f", x, y); |
| 1168 | - } |
| 1169 | - live2DManager->OnTap(x, y); |
| 1170 | - |
| 1171 | - // 歯車にタップしたか |
| 1172 | - if (_gear->IsHit(px, py)) |
| 1173 | - { |
| 1174 | - live2DManager->NextScene(); |
| 1175 | - } |
| 1176 | - |
| 1177 | - // 電源ボタンにタップしたか |
| 1178 | - if (_power->IsHit(px, py)) |
| 1179 | - { |
| 1180 | - LAppDelegate::GetInstance()->AppEnd(); |
| 1181 | - } |
| 1182 | - } |
| 1183 | -} |
| 1184 | - |
| 1185 | float LAppView::TransformViewX(float deviceX) const |
| 1186 | { |
| 1187 | float screenX = _deviceToScreen->TransformX(deviceX); // 論理座標変換した座標を取得。 |
| 1188 | @@ -374,32 +299,4 @@ void LAppView::ResizeSprite() |
| 1189 | _back->ResetRect(x, y, fWidth, fHeight); |
| 1190 | } |
| 1191 | } |
| 1192 | - |
| 1193 | - if (_power) |
| 1194 | - { |
| 1195 | - GLuint id = _power->GetTextureId(); |
| 1196 | - LAppTextureManager::TextureInfo* texInfo = textureManager->GetTextureInfoById(id); |
| 1197 | - if (texInfo) |
| 1198 | - { |
| 1199 | - x = static_cast<float>(width - texInfo->width * 0.5f); |
| 1200 | - y = static_cast<float>(texInfo->height * 0.5f); |
| 1201 | - fWidth = static_cast<float>(texInfo->width); |
| 1202 | - fHeight = static_cast<float>(texInfo->height); |
| 1203 | - _power->ResetRect(x, y, fWidth, fHeight); |
| 1204 | - } |
| 1205 | - } |
| 1206 | - |
| 1207 | - if (_gear) |
| 1208 | - { |
| 1209 | - GLuint id = _gear->GetTextureId(); |
| 1210 | - LAppTextureManager::TextureInfo* texInfo = textureManager->GetTextureInfoById(id); |
| 1211 | - if (texInfo) |
| 1212 | - { |
| 1213 | - x = static_cast<float>(width - texInfo->width * 0.5f); |
| 1214 | - y = static_cast<float>(height - texInfo->height * 0.5f); |
| 1215 | - fWidth = static_cast<float>(texInfo->width); |
| 1216 | - fHeight = static_cast<float>(texInfo->height); |
| 1217 | - _gear->ResetRect(x, y, fWidth, fHeight); |
| 1218 | - } |
| 1219 | - } |
| 1220 | } |
| 1221 | diff -pruN --exclude build ./demo_clean/src/LAppView.hpp ./demo_dev/src/LAppView.hpp |
| 1222 | --- ./demo_clean/src/LAppView.hpp 2022-09-14 12:08:43.000000000 +0100 |
| 1223 | +++ ./demo_dev/src/LAppView.hpp 2021-04-28 11:49:43.178296000 +0100 |
| 1224 | @@ -14,7 +14,6 @@ |
| 1225 | #include "CubismFramework.hpp" |
| 1226 | #include <Rendering/OpenGL/CubismOffscreenSurface_OpenGLES2.hpp> |
| 1227 | |
| 1228 | -class TouchManager; |
| 1229 | class LAppSprite; |
| 1230 | class LAppModel; |
| 1231 | |
| 1232 | @@ -66,30 +65,6 @@ public: |
| 1233 | void ResizeSprite(); |
| 1234 | |
| 1235 | /** |
| 1236 | - * @brief タッチされたときに呼ばれる。 |
| 1237 | - * |
| 1238 | - * @param[in] pointX スクリーンX座標 |
| 1239 | - * @param[in] pointY スクリーンY座標 |
| 1240 | - */ |
| 1241 | - void OnTouchesBegan(float pointX, float pointY) const; |
| 1242 | - |
| 1243 | - /** |
| 1244 | - * @brief タッチしているときにポインタが動いたら呼ばれる。 |
| 1245 | - * |
| 1246 | - * @param[in] pointX スクリーンX座標 |
| 1247 | - * @param[in] pointY スクリーンY座標 |
| 1248 | - */ |
| 1249 | - void OnTouchesMoved(float pointX, float pointY) const; |
| 1250 | - |
| 1251 | - /** |
| 1252 | - * @brief タッチが終了したら呼ばれる。 |
| 1253 | - * |
| 1254 | - * @param[in] pointX スクリーンX座標 |
| 1255 | - * @param[in] pointY スクリーンY座標 |
| 1256 | - */ |
| 1257 | - void OnTouchesEnded(float pointX, float pointY) const; |
| 1258 | - |
| 1259 | - /** |
| 1260 | * @brief X座標をView座標に変換する。 |
| 1261 | * |
| 1262 | * @param[in] deviceX デバイスX座標 |
| 1263 | @@ -147,13 +122,10 @@ public: |
| 1264 | void SetRenderTargetClearColor(float r, float g, float b); |
| 1265 | |
| 1266 | private: |
| 1267 | - TouchManager* _touchManager; ///< タッチマネージャー |
| 1268 | Csm::CubismMatrix44* _deviceToScreen; ///< デバイスからスクリーンへの行列 |
| 1269 | Csm::CubismViewMatrix* _viewMatrix; ///< viewMatrix |
| 1270 | GLuint _programId; ///< シェーダID |
| 1271 | LAppSprite* _back; ///< 背景画像 |
| 1272 | - LAppSprite* _gear; ///< ギア画像 |
| 1273 | - LAppSprite* _power; ///< 電源画像 |
| 1274 | |
| 1275 | // レンダリング先を別ターゲットにする方式の場合に使用 |
| 1276 | LAppSprite* _renderSprite; ///< モードによっては_renderBufferのテクスチャを描画 |
| 1277 | diff -pruN --exclude build ./demo_clean/src/main.cpp ./demo_dev/src/main.cpp |
| 1278 | --- ./demo_clean/src/main.cpp 2022-09-14 12:08:43.000000000 +0100 |
| 1279 | +++ ./demo_dev/src/main.cpp 2021-04-28 11:49:43.178296000 +0100 |
| 1280 | @@ -5,18 +5,162 @@ |
| 1281 | * that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html. |
| 1282 | */ |
| 1283 | |
| 1284 | +#include <thread> |
| 1285 | +#include <stdexcept> |
| 1286 | +#include <sstream> |
| 1287 | + |
| 1288 | +#ifdef __cpp_lib_filesystem |
| 1289 | +#include <filesystem> |
| 1290 | +namespace fs = std::filesystem; |
| 1291 | +#else |
| 1292 | +#include <experimental/filesystem> |
| 1293 | +namespace fs = std::experimental::filesystem; |
| 1294 | +#endif |
| 1295 | + |
| 1296 | + |
| 1297 | #include "LAppDelegate.hpp" |
| 1298 | +#include "LAppLive2DManager.hpp" |
| 1299 | +#include "facial_landmark_detector.h" |
| 1300 | + |
| 1301 | +struct CmdArgs |
| 1302 | +{ |
| 1303 | + int windowWidth; |
| 1304 | + int windowHeight; |
| 1305 | + std::string windowTitle; |
| 1306 | + std::string rootDir; |
| 1307 | + float scaleFactor; |
| 1308 | + float translateX; |
| 1309 | + float translateY; |
| 1310 | + std::string modelName; |
| 1311 | + bool oldId; // If true, translate new (Cubism 3+) parameter IDs to old (Cubism 2.1) IDs |
| 1312 | + std::string cfgPath; // Path to config file for FacialLandmarkDetector |
| 1313 | +}; |
| 1314 | + |
| 1315 | +CmdArgs parseArgv(int argc, char *argv[]) |
| 1316 | +{ |
| 1317 | + // I think the command-line args are simple enough to not justify using a library... |
| 1318 | + CmdArgs cmdArgs; |
| 1319 | + // Set default values |
| 1320 | + cmdArgs.windowWidth = 600; |
| 1321 | + cmdArgs.windowHeight = 600; |
| 1322 | + cmdArgs.windowTitle = "FacialLandmarksForCubism example"; |
| 1323 | + cmdArgs.rootDir = fs::current_path(); |
| 1324 | + cmdArgs.scaleFactor = 4.5f; |
| 1325 | + cmdArgs.translateX = 0.0f; |
| 1326 | + cmdArgs.translateY = -3.1f; |
| 1327 | + cmdArgs.modelName = "Haru"; |
| 1328 | + cmdArgs.oldId = false; |
| 1329 | + cmdArgs.cfgPath = ""; |
| 1330 | + |
| 1331 | + int i = 1; |
| 1332 | + while (i < argc) |
| 1333 | + { |
| 1334 | + std::string arg = argv[i]; |
| 1335 | + std::stringstream ss; |
| 1336 | + |
| 1337 | + if (arg == "--window-width" || arg == "-W") // capital W for consistency with height |
| 1338 | + { |
| 1339 | + ss << argv[i + 1]; |
| 1340 | + if (!(ss >> cmdArgs.windowWidth)) |
| 1341 | + { |
| 1342 | + throw std::runtime_error("Invalid argument for window width"); |
| 1343 | + } |
| 1344 | + } |
| 1345 | + else if (arg == "--window-height" || arg == "-H") // avoiding "-h", typically for help |
| 1346 | + { |
| 1347 | + ss << argv[i + 1]; |
| 1348 | + if (!(ss >> cmdArgs.windowHeight)) |
| 1349 | + { |
| 1350 | + throw std::runtime_error("Invalid argument for window height"); |
| 1351 | + } |
| 1352 | + } |
| 1353 | + else if (arg == "--window-title" || arg == "-t") |
| 1354 | + { |
| 1355 | + cmdArgs.windowTitle = argv[i + 1]; |
| 1356 | + } |
| 1357 | + else if (arg == "--root-dir" || arg == "-d") |
| 1358 | + { |
| 1359 | + cmdArgs.rootDir = argv[i + 1]; |
| 1360 | + } |
| 1361 | + else if (arg == "--scale-factor" || arg == "-f") |
| 1362 | + { |
| 1363 | + ss << argv[i + 1]; |
| 1364 | + if (!(ss >> cmdArgs.scaleFactor)) |
| 1365 | + { |
| 1366 | + throw std::runtime_error("Invalid argument for scale factor"); |
| 1367 | + } |
| 1368 | + } |
| 1369 | + else if (arg == "--translate-x" || arg == "-x") |
| 1370 | + { |
| 1371 | + ss << argv[i + 1]; |
| 1372 | + if (!(ss >> cmdArgs.translateX)) |
| 1373 | + { |
| 1374 | + throw std::runtime_error("Invalid argument for translate X"); |
| 1375 | + } |
| 1376 | + } |
| 1377 | + else if (arg == "--translate-y" || arg == "-y") |
| 1378 | + { |
| 1379 | + ss << argv[i + 1]; |
| 1380 | + if (!(ss >> cmdArgs.translateY)) |
| 1381 | + { |
| 1382 | + throw std::runtime_error("Invalid argument for translate Y"); |
| 1383 | + } |
| 1384 | + } |
| 1385 | + else if (arg == "--model" || arg == "-m") |
| 1386 | + { |
| 1387 | + cmdArgs.modelName = argv[i + 1]; |
| 1388 | + } |
| 1389 | + else if (arg == "--config" || arg == "-c") |
| 1390 | + { |
| 1391 | + cmdArgs.cfgPath = argv[i + 1]; |
| 1392 | + } |
| 1393 | + else if (arg == "--old-param-id" || arg == "-o") |
| 1394 | + { |
| 1395 | + cmdArgs.oldId = (argv[i + 1][0] == '1'); |
| 1396 | + } |
| 1397 | + else |
| 1398 | + { |
| 1399 | + throw std::runtime_error("Unrecognized argument: " + arg); |
| 1400 | + } |
| 1401 | + |
| 1402 | + i += 2; |
| 1403 | + } |
| 1404 | + |
| 1405 | + return cmdArgs; |
| 1406 | +} |
| 1407 | |
| 1408 | int main(int argc, char* argv[]) |
| 1409 | { |
| 1410 | - // create the application instance |
| 1411 | - if (LAppDelegate::GetInstance()->Initialize() == GL_FALSE) |
| 1412 | + auto cmdArgs = parseArgv(argc, argv); |
| 1413 | + |
| 1414 | + LAppDelegate *delegate = LAppDelegate::GetInstance(); |
| 1415 | + |
| 1416 | + if (!delegate->Initialize(cmdArgs.windowWidth, |
| 1417 | + cmdArgs.windowHeight, |
| 1418 | + cmdArgs.windowTitle.c_str())) |
| 1419 | { |
| 1420 | - return 1; |
| 1421 | + throw std::runtime_error("Unable to initialize LAppDelegate"); |
| 1422 | } |
| 1423 | |
| 1424 | - LAppDelegate::GetInstance()->Run(); |
| 1425 | + delegate->SetRootDirectory(cmdArgs.rootDir); |
| 1426 | + |
| 1427 | + FacialLandmarkDetector detector(cmdArgs.cfgPath); |
| 1428 | + |
| 1429 | + std::thread detectorThread(&FacialLandmarkDetector::mainLoop, |
| 1430 | + &detector); |
| 1431 | + |
| 1432 | + LAppLive2DManager *manager = LAppLive2DManager::GetInstance(); |
| 1433 | + manager->SetModel(cmdArgs.modelName, cmdArgs.oldId); |
| 1434 | + |
| 1435 | + manager->SetProjectionScaleTranslate(cmdArgs.scaleFactor, |
| 1436 | + cmdArgs.translateX, |
| 1437 | + cmdArgs.translateY); |
| 1438 | + manager->SetFacialLandmarkDetector(&detector); |
| 1439 | + |
| 1440 | + delegate->Run(); |
| 1441 | + |
| 1442 | + detector.stop(); |
| 1443 | + detectorThread.join(); |
| 1444 | |
| 1445 | return 0; |
| 1446 | } |
| 1447 | - |