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)
8 -set(SDK_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../..)
9 +set(SDK_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../CubismSdkForNative-4-r.5.1)
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)
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)
22 @@ -64,6 +64,9 @@ target_link_libraries(Framework Live2DCu
23 # Find opengl libraries.
24 find_package(OpenGL REQUIRED)
26 +# Add FacialLandmarksForCubism
27 +add_subdirectory(../.. FacialLandmarksForCubism_build)
29 # Make executable app.
30 add_executable(${APP_NAME})
32 @@ -73,9 +76,11 @@ target_link_libraries(${APP_NAME}
36 + FacialLandmarksForCubism
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)
43 # Copy resource directory to build directory.
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
55 -if [ "$#" -ne 0 ]; then
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
71 - echo "Making Full Demo"
75 - echo "Making Minimum Demo"
79 - echo "You need to enter a valid number."
85 cmake -S "$CMAKE_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
96 -if (CSM_MINIMUM_DEMO)
97 - target_sources(${APP_NAME}
98 +target_sources(${APP_NAME}
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
127 - target_sources(${APP_NAME}
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
154 + ${CMAKE_CURRENT_SOURCE_DIR}/LAppView.cpp
155 + ${CMAKE_CURRENT_SOURCE_DIR}/LAppView.hpp
156 + ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp
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()
165 -bool LAppDelegate::Initialize()
166 +bool LAppDelegate::Initialize(int initWindowWidth, int initWindowHeight,
167 + const char *windowTitle)
171 @@ -63,7 +64,13 @@ bool LAppDelegate::Initialize()
175 - _window = glfwCreateWindow(RenderTargetWidth, RenderTargetHeight, "SAMPLE", NULL, NULL);
176 + _window = glfwCreateWindow(
177 + initWindowWidth ? initWindowWidth : RenderTargetWidth,
178 + initWindowHeight ? initWindowHeight : RenderTargetHeight,
179 + windowTitle ? windowTitle : "SAMPLE",
186 @@ -95,16 +102,11 @@ bool LAppDelegate::Initialize()
188 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
191 - glfwSetMouseButtonCallback(_window, EventHandler::OnMouseCallBack);
192 - glfwSetCursorPosCallback(_window, EventHandler::OnMouseCallBack);
196 glfwGetWindowSize(LAppDelegate::GetInstance()->GetWindow(), &width, &height);
197 _windowWidth = width;
198 _windowHeight = height;
199 - glViewport(0, 0, _windowWidth, _windowHeight);
203 @@ -112,8 +114,6 @@ bool LAppDelegate::Initialize()
207 - SetRootDirectory();
210 LAppLive2DManager::GetInstance();
212 @@ -155,7 +155,6 @@ void LAppDelegate::Run()
213 _windowWidth = width;
214 _windowHeight = height;
216 - glViewport(0, 0, _windowWidth, _windowHeight);
219 LAppPal::UpdateTime();
220 @@ -216,49 +215,6 @@ void LAppDelegate::InitializeCubism()
221 LAppPal::UpdateTime();
224 -void LAppDelegate::OnMouseCallBack(GLFWwindow* window, int button, int action, int modify)
230 - if (GLFW_MOUSE_BUTTON_LEFT != button)
235 - if (GLFW_PRESS == action)
238 - _view->OnTouchesBegan(_mouseX, _mouseY);
240 - else if (GLFW_RELEASE == action)
245 - _view->OnTouchesEnded(_mouseX, _mouseY);
250 -void LAppDelegate::OnMouseCallBack(GLFWwindow* window, double x, double y)
252 - _mouseX = static_cast<float>(x);
253 - _mouseY = static_cast<float>(y);
264 - _view->OnTouchesMoved(_mouseX, _mouseY);
267 GLuint LAppDelegate::CreateShader()
270 @@ -301,29 +257,9 @@ GLuint LAppDelegate::CreateShader()
274 -void LAppDelegate::SetRootDirectory()
275 +void LAppDelegate::SetRootDirectory(std::string rootDir)
278 - ssize_t len = readlink("/proc/self/exe", path, 1024 - 1);
285 - std::string pathString(path);
287 - pathString = pathString.substr(0, pathString.rfind("Demo"));
288 - Csm::csmVector<string> splitStrings = this->Split(pathString, '/');
290 - this->_rootDirectory = "";
292 - for(int i = 0; i < splitStrings.GetSize(); i++)
294 - this->_rootDirectory = this->_rootDirectory + "/" +splitStrings[i];
297 - this->_rootDirectory += "/";
298 + this->_rootDirectory = rootDir + "/";
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:
307 * @brief APPに必要なものを初期化する。
310 + bool Initialize(int initWindowWidth = 0, int initWindowHeight = 0,
311 + const char *windowTitle = "SAMPLE");
315 @@ -53,25 +54,6 @@ public:
319 - * @brief OpenGL用 glfwSetMouseButtonCallback用関数。
321 - * @param[in] window コールバックを呼んだWindow情報
322 - * @param[in] button ボタン種類
323 - * @param[in] action 実行結果
324 - * @param[in] modify
326 - void OnMouseCallBack(GLFWwindow* window, int button, int action, int modify);
329 - * @brief OpenGL用 glfwSetCursorPosCallback用関数。
331 - * @param[in] window コールバックを呼んだWindow情報
335 - void OnMouseCallBack(GLFWwindow* window, double x, double y);
340 GLuint CreateShader();
341 @@ -98,8 +80,10 @@ public:
344 * @brief ルートディレクトリを設定する。
346 + * @param[in] rootDir : The root directory to set to.
348 - void SetRootDirectory();
349 + void SetRootDirectory(std::string rootDir);
352 * @brief ルートディレクトリを取得する。
353 @@ -146,24 +130,3 @@ private:
354 int _windowWidth; ///< Initialize関数で設定したウィンドウ幅
355 int _windowHeight; ///< Initialize関数で設定したウィンドウ高さ
362 - * @brief glfwSetMouseButtonCallback用コールバック関数。
364 - static void OnMouseCallBack(GLFWwindow* window, int button, int action, int modify)
366 - LAppDelegate::GetInstance()->OnMouseCallBack(window, button, action, modify);
370 - * @brief glfwSetCursorPosCallback用コールバック関数。
372 - static void OnMouseCallBack(GLFWwindow* window, double x, double y)
374 - LAppDelegate::GetInstance()->OnMouseCallBack(window, x, y);
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(
383 LAppLive2DManager::LAppLive2DManager()
386 + , _projScaleFactor(1.0f)
387 + , _translateX(0.0f)
388 + , _translateY(0.0f)
390 _viewMatrix = new CubismMatrix44();
392 - ChangeScene(_sceneIndex);
395 LAppLive2DManager::~LAppLive2DManager()
396 @@ -100,26 +100,6 @@ void LAppLive2DManager::OnTap(csmFloat32
398 LAppPal::PrintLog("[APP]tap point: {x:%.2f y:%.2f}", x, y);
401 - for (csmUint32 i = 0; i < _models.GetSize(); i++)
403 - if (_models[i]->HitTest(HitAreaNameHead, x, y))
405 - if (DebugLogEnable)
407 - LAppPal::PrintLog("[APP]hit area: [%s]", HitAreaNameHead);
409 - _models[i]->SetRandomExpression();
411 - else if (_models[i]->HitTest(HitAreaNameBody, x, y))
413 - if (DebugLogEnable)
415 - LAppPal::PrintLog("[APP]hit area: [%s]", HitAreaNameBody);
417 - _models[i]->StartRandomMotion(MotionGroupTapBody, PriorityNormal, FinishedMotion);
422 void LAppLive2DManager::OnUpdate() const
423 @@ -127,10 +107,10 @@ void LAppLive2DManager::OnUpdate() const
425 glfwGetWindowSize(LAppDelegate::GetInstance()->GetWindow(), &width, &height);
427 + CubismMatrix44 projection;
428 csmUint32 modelCount = _models.GetSize();
429 for (csmUint32 i = 0; i < modelCount; ++i)
431 - CubismMatrix44 projection;
432 LAppModel* model = GetModel(i);
434 if (model->GetModel() == NULL)
435 @@ -143,12 +123,15 @@ void LAppLive2DManager::OnUpdate() const
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));
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),
449 + projection.Translate(_translateX, _translateY);
452 if (_viewMatrix != NULL)
453 @@ -165,30 +148,14 @@ void LAppLive2DManager::OnUpdate() const
457 -void LAppLive2DManager::NextScene()
459 - csmInt32 no = (_sceneIndex + 1) % ModelDirSize;
463 -void LAppLive2DManager::ChangeScene(Csm::csmInt32 index)
464 +void LAppLive2DManager::SetModel(std::string modelName, bool useOldParamId)
466 - _sceneIndex = index;
467 - if (DebugLogEnable)
469 - LAppPal::PrintLog("[APP]model index: %d", _sceneIndex);
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";
483 - _models.PushBack(new LAppModel());
484 + _models.PushBack(new LAppModel(useOldParamId));
485 _models[0]->LoadAssets(modelPath.c_str(), modelJsonName.c_str());
488 @@ -210,7 +177,7 @@ void LAppLive2DManager::ChangeScene(Csm:
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);
497 @@ -239,3 +206,20 @@ void LAppLive2DManager::SetViewMatrix(Cu
498 _viewMatrix->GetArray()[i] = m->GetArray()[i];
502 +void LAppLive2DManager::SetFacialLandmarkDetector(FacialLandmarkDetector *detector)
504 + for (auto it = _models.Begin(); it != _models.End(); ++it)
506 + (*it)->SetFacialLandmarkDetector(detector);
510 +void LAppLive2DManager::SetProjectionScaleTranslate(float scaleFactor,
514 + _projScaleFactor = scaleFactor;
515 + _translateX = translateX;
516 + _translateY = translateY;
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
526 #include <CubismFramework.hpp>
527 #include <Math/CubismMatrix44.hpp>
528 #include <Type/csmVector.hpp>
532 +class FacialLandmarkDetector;
535 * @brief サンプルアプリケーションにおいてCubismModelを管理するクラス<br>
536 * モデル生成と破棄、タップイベントの処理、モデル切り替えを行う。
537 @@ -72,16 +75,14 @@ public:
538 void OnUpdate() const;
541 - * @brief 次のシーンに切り替える<br>
542 - * サンプルアプリケーションではモデルセットの切り替えを行う。
547 - * @brief シーンを切り替える<br>
548 - * サンプルアプリケーションではモデルセットの切り替えを行う。
550 - void ChangeScene(Csm::csmInt32 index);
551 + * @brief Set model data
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
558 + void SetModel(std::string modelName, bool useOldParamId);
562 @@ -94,6 +95,24 @@ public:
564 void SetViewMatrix(Live2D::Cubism::Framework::CubismMatrix44* m);
567 + * @brief Set the pointer to the FacialLandmarkDetector instance
569 + * @param[in] detector : Pointer to FacialLandmarkDetector instance
571 + void SetFacialLandmarkDetector(FacialLandmarkDetector *detector);
574 + * @brief Set projection scale factor and translation parameters
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
580 + void SetProjectionScaleTranslate(float scaleFactor,
587 @@ -107,5 +126,8 @@ private:
589 Csm::CubismMatrix44* _viewMatrix; ///< モデル描画に用いるView行列
590 Csm::csmVector<LAppModel*> _models; ///< モデルインスタンスのコンテナ
591 - Csm::csmInt32 _sceneIndex; ///< 表示するシーンのインデックス値
593 + float _projScaleFactor;
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
601 #include "LAppTextureManager.hpp"
602 #include "LAppDelegate.hpp"
604 +#include "facial_landmark_detector.h"
606 using namespace Live2D::Cubism::Framework;
607 using namespace Live2D::Cubism::Framework::DefaultParameterId;
608 using namespace LAppDefine;
609 @@ -45,22 +47,24 @@ namespace {
613 -LAppModel::LAppModel()
614 +LAppModel::LAppModel(bool useOldParamId)
616 , _modelSetting(NULL)
617 , _userTimeSeconds(0.0f)
618 + , _detector(nullptr)
619 + , _useOldParamId(useOldParamId)
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));
640 LAppModel::~LAppModel()
641 @@ -96,12 +100,6 @@ void LAppModel::LoadAssets(const csmChar
645 - if (_model == NULL)
647 - LAppPal::PrintLog("Failed to LoadAssets().");
654 @@ -134,30 +132,6 @@ void LAppModel::SetupModel(ICubismModelS
655 DeleteBuffer(buffer, path.GetRawString());
659 - if (_modelSetting->GetExpressionCount() > 0)
661 - const csmInt32 count = _modelSetting->GetExpressionCount();
662 - for (csmInt32 i = 0; i < count; i++)
664 - csmString name = _modelSetting->GetExpressionName(i);
665 - csmString path = _modelSetting->GetExpressionFileName(i);
666 - path = _modelHomeDir + path;
668 - buffer = CreateBuffer(path.GetRawString(), &size);
669 - ACubismMotion* motion = LoadExpression(buffer, size, name.GetRawString());
671 - if (_expressions[name] != NULL)
673 - ACubismMotion::Delete(_expressions[name]);
674 - _expressions[name] = NULL;
676 - _expressions[name] = motion;
678 - DeleteBuffer(buffer, path.GetRawString());
683 if (strcmp(_modelSetting->GetPhysicsFileName(), "") != 0)
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));
692 _breath->SetParameters(breathParameters);
694 @@ -220,21 +194,6 @@ void LAppModel::SetupModel(ICubismModelS
700 - csmInt32 lipSyncIdCount = _modelSetting->GetLipSyncParameterCount();
701 - for (csmInt32 i = 0; i < lipSyncIdCount; ++i)
703 - _lipSyncIds.PushBack(_modelSetting->GetLipSyncParameterId(i));
707 - if (_modelSetting == NULL || _modelMatrix == NULL)
709 - LAppPal::PrintLog("Failed to SetupModel().");
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;
720 - _dragManager->Update(deltaTimeSeconds);
721 - _dragX = _dragManager->GetX();
722 - _dragY = _dragManager->GetY();
724 - // モーションによるパラメータ更新の有無
725 - csmBool motionUpdated = false;
727 - //-----------------------------------------------------------------
728 - _model->LoadParameters(); // 前回セーブされた状態をロード
729 - if (_motionManager->IsFinished())
731 - // モーションの再生がない場合、待機モーションの中からランダムで再生する
732 - StartRandomMotion(MotionGroupIdle, PriorityIdle);
737 - motionUpdated = _motionManager->UpdateMotion(_model, deltaTimeSeconds); // モーションを更新
739 - _model->SaveParameters(); // 状態を保存
740 - //-----------------------------------------------------------------
741 + auto idMan = CubismFramework::GetIdManager();
742 + auto params = _detector->getParams();
745 - if (!motionUpdated)
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)
753 - // メインモーションの更新がないとき
754 - _eyeBlink->UpdateParameters(_model, deltaTimeSeconds); // 目パチ
755 + // モーションの再生がない場合、待機モーションの中からランダムで再生する
756 + StartRandomMotion(MotionGroupIdle, PriorityIdle);
760 - if (_expressionManager != NULL)
762 - _expressionManager->UpdateMotion(_model, deltaTimeSeconds); // 表情でパラメータ更新(相対変化)
767 - _model->AddParameterValue(_idParamAngleX, _dragX * 30); // -30から30の値を加える
768 - _model->AddParameterValue(_idParamAngleY, _dragY * 30);
769 - _model->AddParameterValue(_idParamAngleZ, _dragX * _dragY * -30);
772 - _model->AddParameterValue(_idParamBodyAngleX, _dragX * 10); // -10から10の値を加える
775 + _motionManager->UpdateMotion(_model, deltaTimeSeconds); // モーションを更新
777 + _model->SaveParameters(); // 状態を保存
780 - _model->AddParameterValue(_idParamEyeBallX, _dragX); // -1から1の値を加える
781 - _model->AddParameterValue(_idParamEyeBallY, _dragY);
784 - if (_breath != NULL)
786 - _breath->UpdateParameters(_model, deltaTimeSeconds);
787 + if (params.autoBlink && _eyeBlink)
789 + _eyeBlink->UpdateParameters(_model, deltaTimeSeconds);
793 + _model->SetParameterValue(idMan->GetId(_("ParamEyeLOpen")),
794 + params.leftEyeOpenness);
795 + _model->SetParameterValue(idMan->GetId(_("ParamEyeROpen")),
796 + params.rightEyeOpenness);
798 + _model->SetParameterValue(idMan->GetId(_("ParamMouthForm")),
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)
814 + // Note: _model->LoadParameters and SaveParameters is needed
815 + // before - see above.
816 + _breath->UpdateParameters(_model, deltaTimeSeconds);
821 @@ -408,22 +365,6 @@ void LAppModel::Update()
822 _physics->Evaluate(_model, deltaTimeSeconds);
828 - // リアルタイムでリップシンクを行う場合、システムから音量を取得して0〜1の範囲で値を入力します。
829 - csmFloat32 value = 0.0f;
832 - _wavFileHandler.Update(deltaTimeSeconds);
833 - value = _wavFileHandler.GetRms();
835 - for (csmUint32 i = 0; i < _lipSyncIds.GetSize(); ++i)
837 - _model->AddParameterValue(_lipSyncIds[i], value, 0.8f);
844 @@ -492,7 +433,6 @@ CubismMotionQueueEntryHandle LAppModel::
846 csmString path = voice;
847 path = _modelHomeDir + path;
848 - _wavFileHandler.Start(path);
852 @@ -644,3 +584,37 @@ Csm::Rendering::CubismOffscreenFrame_Ope
854 return _renderBuffer;
857 +void LAppModel::SetFacialLandmarkDetector(FacialLandmarkDetector *detector)
859 + _detector = detector;
862 +Csm::csmString LAppModel::_(std::string s)
865 + if (_useOldParamId)
867 + if (s == "ParamTere")
869 + ans = "PARAM_CHEEK";
873 + for (size_t i = 0; i < s.size(); i++)
875 + if (std::isupper(s[i]) && i != 0)
879 + ans += std::toupper(s[i]);
887 + return csmString(ans.c_str());
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
894 #include <Type/csmRectF.hpp>
895 #include <Rendering/OpenGL/CubismOffscreenSurface_OpenGLES2.hpp>
897 -#include "LAppWavFileHandler.hpp"
898 +#include "facial_landmark_detector.h"
901 * @brief ユーザーが実際に使用するモデルの実装クラス<br>
902 @@ -25,8 +25,11 @@ class LAppModel : public Csm::CubismUser
907 + * @param[in] useOldParamId : If true, translate new (Cubism 3+)
908 + * parameter IDs to old (Cubism 2.1) ones
911 + LAppModel(bool useOldParamId);
915 @@ -114,6 +117,13 @@ public:
917 Csm::Rendering::CubismOffscreenFrame_OpenGLES2& GetRenderBuffer();
920 + * @brief Set the pointer to the FacialLandmarkDetector instance
922 + * @param[in] detector : Pointer to FacialLandmarkDetector instance
924 + void SetFacialLandmarkDetector(FacialLandmarkDetector *detector);
928 * @brief モデルを描画する処理。モデルを描画する空間のView-Projection行列を渡す。
929 @@ -167,6 +177,17 @@ private:
931 void ReleaseExpressions();
934 + * @brief Translate new (Cubism 3+) parameter IDs to old (Cubism 2.1) ones
936 + * @param[in] s : New parameter ID
938 + * @return Old parameter ID
940 + Csm::csmString _(std::string s);
942 + bool _useOldParamId;
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
951 - LAppWavFileHandler _wavFileHandler; ///< wavファイルハンドラ
953 Csm::Rendering::CubismOffscreenFrame_OpenGLES2 _renderBuffer; ///< フレームバッファ以外の描画先
955 + FacialLandmarkDetector *_detector;
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
965 #include "LAppPal.hpp"
966 +#include <stdexcept>
970 @@ -45,10 +46,7 @@ csmByte* LAppPal::LoadFileAsBytes(const
971 file.open(path, std::ios::in | std::ios::binary);
974 - if (DebugLogEnable)
976 - PrintLog("file open error");
978 + throw std::runtime_error("Failed to open file " + filePath);
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
989 +LAppTextureManager::TextureInfo* LAppTextureManager::CreateTextureFromColor(
990 + uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha
993 + int width = 8, height = 8;
995 + uint8_t pixels[height][width][4];
996 + for (std::size_t h = 0; h < height; h++)
998 + for (std::size_t w = 0; w < width; w++)
1000 + pixels[h][w][0] = red;
1001 + pixels[h][w][1] = green;
1002 + pixels[h][w][2] = blue;
1003 + pixels[h][w][3] = alpha;
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);
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);
1018 + LAppTextureManager::TextureInfo* textureInfo = new LAppTextureManager::TextureInfo();
1019 + textureInfo->fileName = "";
1020 + textureInfo->width = width;
1021 + textureInfo->height = height;
1022 + textureInfo->id = textureId;
1024 + _textures.PushBack(textureInfo);
1026 + return textureInfo;
1029 void LAppTextureManager::ReleaseTextures()
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:
1037 TextureInfo* CreateTextureFromPngFile(std::string fileName);
1039 + TextureInfo *CreateTextureFromColor(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha = 255);
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
1048 #include "LAppLive2DManager.hpp"
1049 #include "LAppTextureManager.hpp"
1050 #include "LAppDefine.hpp"
1051 -#include "TouchManager.hpp"
1052 #include "LAppSprite.hpp"
1053 #include "LAppModel.hpp"
1055 @@ -26,8 +25,6 @@ using namespace LAppDefine;
1056 LAppView::LAppView():
1061 _renderSprite(NULL),
1062 _renderTarget(SelectTarget_None)
1064 @@ -35,8 +32,6 @@ LAppView::LAppView():
1065 _clearColor[1] = 1.0f;
1066 _clearColor[2] = 1.0f;
1067 _clearColor[3] = 0.0f;
1069 - _touchManager = new TouchManager();
1071 // デバイス座標からスクリーン座標に変換するための
1072 _deviceToScreen = new CubismMatrix44();
1073 @@ -52,10 +47,7 @@ LAppView::~LAppView()
1076 delete _deviceToScreen;
1077 - delete _touchManager;
1083 void LAppView::Initialize()
1084 @@ -107,9 +99,6 @@ void LAppView::Initialize()
1085 void LAppView::Render()
1092 LAppLive2DManager* Live2DManager = LAppLive2DManager::GetInstance();
1094 @@ -151,35 +140,17 @@ void LAppView::InitializeSprite()
1095 glfwGetWindowSize(LAppDelegate::GetInstance()->GetWindow(), &width, &height);
1097 LAppTextureManager* textureManager = LAppDelegate::GetInstance()->GetTextureManager();
1098 - const string resourcesPath = LAppDelegate::GetInstance()->GetRootDirectory() + ResourcesPath;
1100 - string imageName = BackImageName;
1101 - LAppTextureManager::TextureInfo* backgroundTexture = textureManager->CreateTextureFromPngFile(resourcesPath + imageName);
1103 + LAppTextureManager::TextureInfo* backgroundTexture =
1104 + textureManager->CreateTextureFromColor(0, 255, 0);
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);
1114 - imageName = GearImageName;
1115 - LAppTextureManager::TextureInfo* gearTexture = textureManager->CreateTextureFromPngFile(resourcesPath + imageName);
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);
1123 - imageName = PowerImageName;
1124 - LAppTextureManager::TextureInfo* powerTexture = textureManager->CreateTextureFromPngFile(resourcesPath + imageName);
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);
1135 @@ -187,52 +158,6 @@ void LAppView::InitializeSprite()
1139 -void LAppView::OnTouchesBegan(float px, float py) const
1141 - _touchManager->TouchesBegan(px, py);
1144 -void LAppView::OnTouchesMoved(float px, float py) const
1146 - float viewX = this->TransformViewX(_touchManager->GetX());
1147 - float viewY = this->TransformViewY(_touchManager->GetY());
1149 - _touchManager->TouchesMoved(px, py);
1151 - LAppLive2DManager* Live2DManager = LAppLive2DManager::GetInstance();
1152 - Live2DManager->OnDrag(viewX, viewY);
1155 -void LAppView::OnTouchesEnded(float px, float py) const
1158 - LAppLive2DManager* live2DManager = LAppLive2DManager::GetInstance();
1159 - live2DManager->OnDrag(0.0f, 0.0f);
1163 - float x = _deviceToScreen->TransformX(_touchManager->GetX()); // 論理座標変換した座標を取得。
1164 - float y = _deviceToScreen->TransformY(_touchManager->GetY()); // 論理座標変換した座標を取得。
1165 - if (DebugTouchLogEnable)
1167 - LAppPal::PrintLog("[APP]touchesEnded x:%.2f y:%.2f", x, y);
1169 - live2DManager->OnTap(x, y);
1172 - if (_gear->IsHit(px, py))
1174 - live2DManager->NextScene();
1178 - if (_power->IsHit(px, py))
1180 - LAppDelegate::GetInstance()->AppEnd();
1185 float LAppView::TransformViewX(float deviceX) const
1187 float screenX = _deviceToScreen->TransformX(deviceX); // 論理座標変換した座標を取得。
1188 @@ -374,32 +299,4 @@ void LAppView::ResizeSprite()
1189 _back->ResetRect(x, y, fWidth, fHeight);
1195 - GLuint id = _power->GetTextureId();
1196 - LAppTextureManager::TextureInfo* texInfo = textureManager->GetTextureInfoById(id);
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);
1209 - GLuint id = _gear->GetTextureId();
1210 - LAppTextureManager::TextureInfo* texInfo = textureManager->GetTextureInfoById(id);
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);
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
1225 #include "CubismFramework.hpp"
1226 #include <Rendering/OpenGL/CubismOffscreenSurface_OpenGLES2.hpp>
1228 -class TouchManager;
1232 @@ -66,30 +65,6 @@ public:
1233 void ResizeSprite();
1236 - * @brief タッチされたときに呼ばれる。
1238 - * @param[in] pointX スクリーンX座標
1239 - * @param[in] pointY スクリーンY座標
1241 - void OnTouchesBegan(float pointX, float pointY) const;
1244 - * @brief タッチしているときにポインタが動いたら呼ばれる。
1246 - * @param[in] pointX スクリーンX座標
1247 - * @param[in] pointY スクリーンY座標
1249 - void OnTouchesMoved(float pointX, float pointY) const;
1252 - * @brief タッチが終了したら呼ばれる。
1254 - * @param[in] pointX スクリーンX座標
1255 - * @param[in] pointY スクリーンY座標
1257 - void OnTouchesEnded(float pointX, float pointY) const;
1260 * @brief X座標をView座標に変換する。
1262 * @param[in] deviceX デバイスX座標
1263 @@ -147,13 +122,10 @@ public:
1264 void SetRenderTargetClearColor(float r, float g, float b);
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; ///< 電源画像
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
1281 * that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html.
1285 +#include <stdexcept>
1288 +#ifdef __cpp_lib_filesystem
1289 +#include <filesystem>
1290 +namespace fs = std::filesystem;
1292 +#include <experimental/filesystem>
1293 +namespace fs = std::experimental::filesystem;
1297 #include "LAppDelegate.hpp"
1298 +#include "LAppLive2DManager.hpp"
1299 +#include "facial_landmark_detector.h"
1305 + std::string windowTitle;
1306 + std::string rootDir;
1307 + float scaleFactor;
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
1315 +CmdArgs parseArgv(int argc, char *argv[])
1317 + // I think the command-line args are simple enough to not justify using a library...
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 = "";
1334 + std::string arg = argv[i];
1335 + std::stringstream ss;
1337 + if (arg == "--window-width" || arg == "-W") // capital W for consistency with height
1339 + ss << argv[i + 1];
1340 + if (!(ss >> cmdArgs.windowWidth))
1342 + throw std::runtime_error("Invalid argument for window width");
1345 + else if (arg == "--window-height" || arg == "-H") // avoiding "-h", typically for help
1347 + ss << argv[i + 1];
1348 + if (!(ss >> cmdArgs.windowHeight))
1350 + throw std::runtime_error("Invalid argument for window height");
1353 + else if (arg == "--window-title" || arg == "-t")
1355 + cmdArgs.windowTitle = argv[i + 1];
1357 + else if (arg == "--root-dir" || arg == "-d")
1359 + cmdArgs.rootDir = argv[i + 1];
1361 + else if (arg == "--scale-factor" || arg == "-f")
1363 + ss << argv[i + 1];
1364 + if (!(ss >> cmdArgs.scaleFactor))
1366 + throw std::runtime_error("Invalid argument for scale factor");
1369 + else if (arg == "--translate-x" || arg == "-x")
1371 + ss << argv[i + 1];
1372 + if (!(ss >> cmdArgs.translateX))
1374 + throw std::runtime_error("Invalid argument for translate X");
1377 + else if (arg == "--translate-y" || arg == "-y")
1379 + ss << argv[i + 1];
1380 + if (!(ss >> cmdArgs.translateY))
1382 + throw std::runtime_error("Invalid argument for translate Y");
1385 + else if (arg == "--model" || arg == "-m")
1387 + cmdArgs.modelName = argv[i + 1];
1389 + else if (arg == "--config" || arg == "-c")
1391 + cmdArgs.cfgPath = argv[i + 1];
1393 + else if (arg == "--old-param-id" || arg == "-o")
1395 + cmdArgs.oldId = (argv[i + 1][0] == '1');
1399 + throw std::runtime_error("Unrecognized argument: " + arg);
1408 int main(int argc, char* argv[])
1410 - // create the application instance
1411 - if (LAppDelegate::GetInstance()->Initialize() == GL_FALSE)
1412 + auto cmdArgs = parseArgv(argc, argv);
1414 + LAppDelegate *delegate = LAppDelegate::GetInstance();
1416 + if (!delegate->Initialize(cmdArgs.windowWidth,
1417 + cmdArgs.windowHeight,
1418 + cmdArgs.windowTitle.c_str()))
1421 + throw std::runtime_error("Unable to initialize LAppDelegate");
1424 - LAppDelegate::GetInstance()->Run();
1425 + delegate->SetRootDirectory(cmdArgs.rootDir);
1427 + FacialLandmarkDetector detector(cmdArgs.cfgPath);
1429 + std::thread detectorThread(&FacialLandmarkDetector::mainLoop,
1432 + LAppLive2DManager *manager = LAppLive2DManager::GetInstance();
1433 + manager->SetModel(cmdArgs.modelName, cmdArgs.oldId);
1435 + manager->SetProjectionScaleTranslate(cmdArgs.scaleFactor,
1436 + cmdArgs.translateX,
1437 + cmdArgs.translateY);
1438 + manager->SetFacialLandmarkDetector(&detector);
1443 + detectorThread.join();