1 diff -pruN --exclude build ./demo_clean/CMakeLists.txt ./demo_dev/CMakeLists.txt
2 --- ./demo_clean/CMakeLists.txt 2023-05-18 09:58:50.000000000 +0100
3 +++ ./demo_dev/CMakeLists.txt 2023-05-28 08:11:25.750067591 +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.7)
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 2023-05-18 09:58:50.000000000 +0100
47 +++ ./demo_dev/scripts/make_gcc 2023-05-28 08:11:25.750067591 +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 2023-05-18 09:58:50.000000000 +0100
94 +++ ./demo_dev/src/CMakeLists.txt 2023-05-28 08:11:25.750067591 +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 2023-05-18 09:58:50.000000000 +0100
160 +++ ./demo_dev/src/LAppDelegate.cpp 2023-05-28 08:11:25.750067591 +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 2023-05-18 09:58:50.000000000 +0100
304 +++ ./demo_dev/src/LAppDelegate.hpp 2023-05-28 08:11:25.754067666 +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 2023-05-18 09:58:50.000000000 +0100
380 +++ ./demo_dev/src/LAppLive2DManager.cpp 2023-05-28 08:11:25.754067666 +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 2023-05-18 09:58:50.000000000 +0100
520 +++ ./demo_dev/src/LAppLive2DManager.hpp 2023-05-28 08:11:25.750067591 +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 2023-05-18 09:58:50.000000000 +0100
599 +++ ./demo_dev/src/LAppModel.cpp 2023-05-28 08:18:01.721395676 +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,62 +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 - _opacity = _model->GetModelOpacity();
748 - if (!motionUpdated)
750 - if (_eyeBlink != NULL)
751 + // NOTE: Apparently, this LoadParameters/SaveParameters pair
752 + // is needed for auto breath to work.
753 + _model->LoadParameters(); // 前回セーブされた状態をロード
754 + if (_motionManager->IsFinished() && params.randomMotion)
756 - // メインモーションの更新がないとき
757 - _eyeBlink->UpdateParameters(_model, deltaTimeSeconds); // 目パチ
758 + // モーションの再生がない場合、待機モーションの中からランダムで再生する
759 + StartRandomMotion(MotionGroupIdle, PriorityIdle);
763 - if (_expressionManager != NULL)
765 - _expressionManager->UpdateMotion(_model, deltaTimeSeconds); // 表情でパラメータ更新(相対変化)
770 - _model->AddParameterValue(_idParamAngleX, _dragX * 30); // -30から30の値を加える
771 - _model->AddParameterValue(_idParamAngleY, _dragY * 30);
772 - _model->AddParameterValue(_idParamAngleZ, _dragX * _dragY * -30);
775 - _model->AddParameterValue(_idParamBodyAngleX, _dragX * 10); // -10から10の値を加える
778 + _motionManager->UpdateMotion(_model, deltaTimeSeconds); // モーションを更新
780 + _model->SaveParameters(); // 状態を保存
783 - _model->AddParameterValue(_idParamEyeBallX, _dragX); // -1から1の値を加える
784 - _model->AddParameterValue(_idParamEyeBallY, _dragY);
787 - if (_breath != NULL)
789 - _breath->UpdateParameters(_model, deltaTimeSeconds);
790 + if (params.autoBlink && _eyeBlink)
792 + _eyeBlink->UpdateParameters(_model, deltaTimeSeconds);
796 + _model->SetParameterValue(idMan->GetId(_("ParamEyeLOpen")),
797 + params.leftEyeOpenness);
798 + _model->SetParameterValue(idMan->GetId(_("ParamEyeROpen")),
799 + params.rightEyeOpenness);
801 + _model->SetParameterValue(idMan->GetId(_("ParamMouthForm")),
803 + _model->SetParameterValue(idMan->GetId(_("ParamMouthOpenY")),
804 + params.mouthOpenness);
805 + _model->SetParameterValue(idMan->GetId(_("ParamEyeLSmile")),
806 + params.leftEyeSmile);
807 + _model->SetParameterValue(idMan->GetId(_("ParamEyeRSmile")),
808 + params.rightEyeSmile);
809 + _model->SetParameterValue(idMan->GetId(_("ParamAngleX")),
810 + params.faceXAngle);
811 + _model->SetParameterValue(idMan->GetId(_("ParamAngleY")),
812 + params.faceYAngle);
813 + _model->SetParameterValue(idMan->GetId(_("ParamAngleZ")),
814 + params.faceZAngle);
815 + if (params.autoBreath && _breath)
817 + // Note: _model->LoadParameters and SaveParameters is needed
818 + // before - see above.
819 + _breath->UpdateParameters(_model, deltaTimeSeconds);
824 @@ -411,22 +365,6 @@ void LAppModel::Update()
825 _physics->Evaluate(_model, deltaTimeSeconds);
831 - // リアルタイムでリップシンクを行う場合、システムから音量を取得して0〜1の範囲で値を入力します。
832 - csmFloat32 value = 0.0f;
835 - _wavFileHandler.Update(deltaTimeSeconds);
836 - value = _wavFileHandler.GetRms();
838 - for (csmUint32 i = 0; i < _lipSyncIds.GetSize(); ++i)
840 - _model->AddParameterValue(_lipSyncIds[i], value, 0.8f);
847 @@ -495,7 +433,6 @@ CubismMotionQueueEntryHandle LAppModel::
849 csmString path = voice;
850 path = _modelHomeDir + path;
851 - _wavFileHandler.Start(path);
855 @@ -647,3 +584,37 @@ Csm::Rendering::CubismOffscreenFrame_Ope
857 return _renderBuffer;
860 +void LAppModel::SetFacialLandmarkDetector(FacialLandmarkDetector *detector)
862 + _detector = detector;
865 +Csm::csmString LAppModel::_(std::string s)
868 + if (_useOldParamId)
870 + if (s == "ParamTere")
872 + ans = "PARAM_CHEEK";
876 + for (size_t i = 0; i < s.size(); i++)
878 + if (std::isupper(s[i]) && i != 0)
882 + ans += std::toupper(s[i]);
890 + return csmString(ans.c_str());
893 diff -pruN --exclude build ./demo_clean/src/LAppModel.hpp ./demo_dev/src/LAppModel.hpp
894 --- ./demo_clean/src/LAppModel.hpp 2023-05-18 09:58:50.000000000 +0100
895 +++ ./demo_dev/src/LAppModel.hpp 2023-05-28 08:11:25.754067666 +0100
897 #include <Type/csmRectF.hpp>
898 #include <Rendering/OpenGL/CubismOffscreenSurface_OpenGLES2.hpp>
900 -#include "LAppWavFileHandler.hpp"
901 +#include "facial_landmark_detector.h"
904 * @brief ユーザーが実際に使用するモデルの実装クラス<br>
905 @@ -25,8 +25,11 @@ class LAppModel : public Csm::CubismUser
910 + * @param[in] useOldParamId : If true, translate new (Cubism 3+)
911 + * parameter IDs to old (Cubism 2.1) ones
914 + LAppModel(bool useOldParamId);
918 @@ -114,6 +117,13 @@ public:
920 Csm::Rendering::CubismOffscreenFrame_OpenGLES2& GetRenderBuffer();
923 + * @brief Set the pointer to the FacialLandmarkDetector instance
925 + * @param[in] detector : Pointer to FacialLandmarkDetector instance
927 + void SetFacialLandmarkDetector(FacialLandmarkDetector *detector);
931 * @brief モデルを描画する処理。モデルを描画する空間のView-Projection行列を渡す。
932 @@ -167,6 +177,17 @@ private:
934 void ReleaseExpressions();
937 + * @brief Translate new (Cubism 3+) parameter IDs to old (Cubism 2.1) ones
939 + * @param[in] s : New parameter ID
941 + * @return Old parameter ID
943 + Csm::csmString _(std::string s);
945 + bool _useOldParamId;
947 Csm::ICubismModelSetting* _modelSetting; ///< モデルセッティング情報
948 Csm::csmString _modelHomeDir; ///< モデルセッティングが置かれたディレクトリ
949 Csm::csmFloat32 _userTimeSeconds; ///< デルタ時間の積算値[秒]
950 @@ -183,9 +204,9 @@ private:
951 const Csm::CubismId* _idParamEyeBallX; ///< パラメータID: ParamEyeBallX
952 const Csm::CubismId* _idParamEyeBallY; ///< パラメータID: ParamEyeBallXY
954 - LAppWavFileHandler _wavFileHandler; ///< wavファイルハンドラ
956 Csm::Rendering::CubismOffscreenFrame_OpenGLES2 _renderBuffer; ///< フレームバッファ以外の描画先
958 + FacialLandmarkDetector *_detector;
962 diff -pruN --exclude build ./demo_clean/src/LAppPal.cpp ./demo_dev/src/LAppPal.cpp
963 --- ./demo_clean/src/LAppPal.cpp 2023-05-18 09:58:50.000000000 +0100
964 +++ ./demo_dev/src/LAppPal.cpp 2023-05-28 08:11:25.750067591 +0100
968 #include "LAppPal.hpp"
969 +#include <stdexcept>
973 @@ -45,10 +46,7 @@ csmByte* LAppPal::LoadFileAsBytes(const
974 file.open(path, std::ios::in | std::ios::binary);
977 - if (DebugLogEnable)
979 - PrintLog("file open error");
981 + throw std::runtime_error("Failed to open file " + filePath);
984 file.read(buf, size);
985 diff -pruN --exclude build ./demo_clean/src/LAppTextureManager.cpp ./demo_dev/src/LAppTextureManager.cpp
986 --- ./demo_clean/src/LAppTextureManager.cpp 2023-05-18 09:58:50.000000000 +0100
987 +++ ./demo_dev/src/LAppTextureManager.cpp 2023-05-28 08:11:25.754067666 +0100
988 @@ -96,6 +96,46 @@ LAppTextureManager::TextureInfo* LAppTex
992 +LAppTextureManager::TextureInfo* LAppTextureManager::CreateTextureFromColor(
993 + uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha
996 + int width = 8, height = 8;
998 + uint8_t pixels[height][width][4];
999 + for (std::size_t h = 0; h < height; h++)
1001 + for (std::size_t w = 0; w < width; w++)
1003 + pixels[h][w][0] = red;
1004 + pixels[h][w][1] = green;
1005 + pixels[h][w][2] = blue;
1006 + pixels[h][w][3] = alpha;
1011 + glGenTextures(1, &textureId);
1012 + glBindTexture(GL_TEXTURE_2D, textureId);
1013 + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
1015 + glGenerateMipmap(GL_TEXTURE_2D);
1016 + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
1017 + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
1018 + glBindTexture(GL_TEXTURE_2D, 0);
1021 + LAppTextureManager::TextureInfo* textureInfo = new LAppTextureManager::TextureInfo();
1022 + textureInfo->fileName = "";
1023 + textureInfo->width = width;
1024 + textureInfo->height = height;
1025 + textureInfo->id = textureId;
1027 + _textures.PushBack(textureInfo);
1029 + return textureInfo;
1032 void LAppTextureManager::ReleaseTextures()
1034 for (Csm::csmUint32 i = 0; i < _textures.GetSize(); i++)
1035 diff -pruN --exclude build ./demo_clean/src/LAppTextureManager.hpp ./demo_dev/src/LAppTextureManager.hpp
1036 --- ./demo_clean/src/LAppTextureManager.hpp 2023-05-18 09:58:50.000000000 +0100
1037 +++ ./demo_dev/src/LAppTextureManager.hpp 2023-05-28 08:11:25.750067591 +0100
1038 @@ -72,6 +72,8 @@ public:
1040 TextureInfo* CreateTextureFromPngFile(std::string fileName);
1042 + TextureInfo *CreateTextureFromColor(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha = 255);
1047 diff -pruN --exclude build ./demo_clean/src/LAppView.cpp ./demo_dev/src/LAppView.cpp
1048 --- ./demo_clean/src/LAppView.cpp 2023-05-18 09:58:50.000000000 +0100
1049 +++ ./demo_dev/src/LAppView.cpp 2023-05-28 08:11:25.750067591 +0100
1051 #include "LAppLive2DManager.hpp"
1052 #include "LAppTextureManager.hpp"
1053 #include "LAppDefine.hpp"
1054 -#include "TouchManager.hpp"
1055 #include "LAppSprite.hpp"
1056 #include "LAppModel.hpp"
1058 @@ -26,8 +25,6 @@ using namespace LAppDefine;
1059 LAppView::LAppView():
1064 _renderSprite(NULL),
1065 _renderTarget(SelectTarget_None)
1067 @@ -35,8 +32,6 @@ LAppView::LAppView():
1068 _clearColor[1] = 1.0f;
1069 _clearColor[2] = 1.0f;
1070 _clearColor[3] = 0.0f;
1072 - _touchManager = new TouchManager();
1074 // デバイス座標からスクリーン座標に変換するための
1075 _deviceToScreen = new CubismMatrix44();
1076 @@ -52,10 +47,7 @@ LAppView::~LAppView()
1079 delete _deviceToScreen;
1080 - delete _touchManager;
1086 void LAppView::Initialize()
1087 @@ -107,9 +99,6 @@ void LAppView::Initialize()
1088 void LAppView::Render()
1095 LAppLive2DManager* Live2DManager = LAppLive2DManager::GetInstance();
1097 @@ -151,35 +140,17 @@ void LAppView::InitializeSprite()
1098 glfwGetWindowSize(LAppDelegate::GetInstance()->GetWindow(), &width, &height);
1100 LAppTextureManager* textureManager = LAppDelegate::GetInstance()->GetTextureManager();
1101 - const string resourcesPath = LAppDelegate::GetInstance()->GetRootDirectory() + ResourcesPath;
1103 - string imageName = BackImageName;
1104 - LAppTextureManager::TextureInfo* backgroundTexture = textureManager->CreateTextureFromPngFile(resourcesPath + imageName);
1106 + LAppTextureManager::TextureInfo* backgroundTexture =
1107 + textureManager->CreateTextureFromColor(0, 255, 0);
1109 float x = width * 0.5f;
1110 float y = height * 0.5f;
1111 - float fWidth = static_cast<float>(backgroundTexture->width * 2.0f);
1112 - float fHeight = static_cast<float>(height) * 0.95f;
1113 + float fWidth = static_cast<float>(width);
1114 + float fHeight = static_cast<float>(height);
1115 _back = new LAppSprite(x, y, fWidth, fHeight, backgroundTexture->id, _programId);
1117 - imageName = GearImageName;
1118 - LAppTextureManager::TextureInfo* gearTexture = textureManager->CreateTextureFromPngFile(resourcesPath + imageName);
1120 - x = static_cast<float>(width - gearTexture->width * 0.5f);
1121 - y = static_cast<float>(height - gearTexture->height * 0.5f);
1122 - fWidth = static_cast<float>(gearTexture->width);
1123 - fHeight = static_cast<float>(gearTexture->height);
1124 - _gear = new LAppSprite(x, y, fWidth, fHeight, gearTexture->id, _programId);
1126 - imageName = PowerImageName;
1127 - LAppTextureManager::TextureInfo* powerTexture = textureManager->CreateTextureFromPngFile(resourcesPath + imageName);
1129 - x = static_cast<float>(width - powerTexture->width * 0.5f);
1130 - y = static_cast<float>(powerTexture->height * 0.5f);
1131 - fWidth = static_cast<float>(powerTexture->width);
1132 - fHeight = static_cast<float>(powerTexture->height);
1133 - _power = new LAppSprite(x, y, fWidth, fHeight, powerTexture->id, _programId);
1138 @@ -187,52 +158,6 @@ void LAppView::InitializeSprite()
1142 -void LAppView::OnTouchesBegan(float px, float py) const
1144 - _touchManager->TouchesBegan(px, py);
1147 -void LAppView::OnTouchesMoved(float px, float py) const
1149 - float viewX = this->TransformViewX(_touchManager->GetX());
1150 - float viewY = this->TransformViewY(_touchManager->GetY());
1152 - _touchManager->TouchesMoved(px, py);
1154 - LAppLive2DManager* Live2DManager = LAppLive2DManager::GetInstance();
1155 - Live2DManager->OnDrag(viewX, viewY);
1158 -void LAppView::OnTouchesEnded(float px, float py) const
1161 - LAppLive2DManager* live2DManager = LAppLive2DManager::GetInstance();
1162 - live2DManager->OnDrag(0.0f, 0.0f);
1166 - float x = _deviceToScreen->TransformX(_touchManager->GetX()); // 論理座標変換した座標を取得。
1167 - float y = _deviceToScreen->TransformY(_touchManager->GetY()); // 論理座標変換した座標を取得。
1168 - if (DebugTouchLogEnable)
1170 - LAppPal::PrintLog("[APP]touchesEnded x:%.2f y:%.2f", x, y);
1172 - live2DManager->OnTap(x, y);
1175 - if (_gear->IsHit(px, py))
1177 - live2DManager->NextScene();
1181 - if (_power->IsHit(px, py))
1183 - LAppDelegate::GetInstance()->AppEnd();
1188 float LAppView::TransformViewX(float deviceX) const
1190 float screenX = _deviceToScreen->TransformX(deviceX); // 論理座標変換した座標を取得。
1191 @@ -374,32 +299,4 @@ void LAppView::ResizeSprite()
1192 _back->ResetRect(x, y, fWidth, fHeight);
1198 - GLuint id = _power->GetTextureId();
1199 - LAppTextureManager::TextureInfo* texInfo = textureManager->GetTextureInfoById(id);
1202 - x = static_cast<float>(width - texInfo->width * 0.5f);
1203 - y = static_cast<float>(texInfo->height * 0.5f);
1204 - fWidth = static_cast<float>(texInfo->width);
1205 - fHeight = static_cast<float>(texInfo->height);
1206 - _power->ResetRect(x, y, fWidth, fHeight);
1212 - GLuint id = _gear->GetTextureId();
1213 - LAppTextureManager::TextureInfo* texInfo = textureManager->GetTextureInfoById(id);
1216 - x = static_cast<float>(width - texInfo->width * 0.5f);
1217 - y = static_cast<float>(height - texInfo->height * 0.5f);
1218 - fWidth = static_cast<float>(texInfo->width);
1219 - fHeight = static_cast<float>(texInfo->height);
1220 - _gear->ResetRect(x, y, fWidth, fHeight);
1224 diff -pruN --exclude build ./demo_clean/src/LAppView.hpp ./demo_dev/src/LAppView.hpp
1225 --- ./demo_clean/src/LAppView.hpp 2023-05-18 09:58:50.000000000 +0100
1226 +++ ./demo_dev/src/LAppView.hpp 2023-05-28 08:11:25.750067591 +0100
1228 #include "CubismFramework.hpp"
1229 #include <Rendering/OpenGL/CubismOffscreenSurface_OpenGLES2.hpp>
1231 -class TouchManager;
1235 @@ -66,30 +65,6 @@ public:
1236 void ResizeSprite();
1239 - * @brief タッチされたときに呼ばれる。
1241 - * @param[in] pointX スクリーンX座標
1242 - * @param[in] pointY スクリーンY座標
1244 - void OnTouchesBegan(float pointX, float pointY) const;
1247 - * @brief タッチしているときにポインタが動いたら呼ばれる。
1249 - * @param[in] pointX スクリーンX座標
1250 - * @param[in] pointY スクリーンY座標
1252 - void OnTouchesMoved(float pointX, float pointY) const;
1255 - * @brief タッチが終了したら呼ばれる。
1257 - * @param[in] pointX スクリーンX座標
1258 - * @param[in] pointY スクリーンY座標
1260 - void OnTouchesEnded(float pointX, float pointY) const;
1263 * @brief X座標をView座標に変換する。
1265 * @param[in] deviceX デバイスX座標
1266 @@ -147,13 +122,10 @@ public:
1267 void SetRenderTargetClearColor(float r, float g, float b);
1270 - TouchManager* _touchManager; ///< タッチマネージャー
1271 Csm::CubismMatrix44* _deviceToScreen; ///< デバイスからスクリーンへの行列
1272 Csm::CubismViewMatrix* _viewMatrix; ///< viewMatrix
1273 GLuint _programId; ///< シェーダID
1274 LAppSprite* _back; ///< 背景画像
1275 - LAppSprite* _gear; ///< ギア画像
1276 - LAppSprite* _power; ///< 電源画像
1278 // レンダリング先を別ターゲットにする方式の場合に使用
1279 LAppSprite* _renderSprite; ///< モードによっては_renderBufferのテクスチャを描画
1280 diff -pruN --exclude build ./demo_clean/src/main.cpp ./demo_dev/src/main.cpp
1281 --- ./demo_clean/src/main.cpp 2023-05-18 09:58:50.000000000 +0100
1282 +++ ./demo_dev/src/main.cpp 2023-05-28 08:11:25.750067591 +0100
1284 * that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html.
1288 +#include <stdexcept>
1291 +#ifdef __cpp_lib_filesystem
1292 +#include <filesystem>
1293 +namespace fs = std::filesystem;
1295 +#include <experimental/filesystem>
1296 +namespace fs = std::experimental::filesystem;
1300 #include "LAppDelegate.hpp"
1301 +#include "LAppLive2DManager.hpp"
1302 +#include "facial_landmark_detector.h"
1308 + std::string windowTitle;
1309 + std::string rootDir;
1310 + float scaleFactor;
1313 + std::string modelName;
1314 + bool oldId; // If true, translate new (Cubism 3+) parameter IDs to old (Cubism 2.1) IDs
1315 + std::string cfgPath; // Path to config file for FacialLandmarkDetector
1318 +CmdArgs parseArgv(int argc, char *argv[])
1320 + // I think the command-line args are simple enough to not justify using a library...
1322 + // Set default values
1323 + cmdArgs.windowWidth = 600;
1324 + cmdArgs.windowHeight = 600;
1325 + cmdArgs.windowTitle = "FacialLandmarksForCubism example";
1326 + cmdArgs.rootDir = fs::current_path();
1327 + cmdArgs.scaleFactor = 4.5f;
1328 + cmdArgs.translateX = 0.0f;
1329 + cmdArgs.translateY = -3.1f;
1330 + cmdArgs.modelName = "Haru";
1331 + cmdArgs.oldId = false;
1332 + cmdArgs.cfgPath = "";
1337 + std::string arg = argv[i];
1338 + std::stringstream ss;
1340 + if (arg == "--window-width" || arg == "-W") // capital W for consistency with height
1342 + ss << argv[i + 1];
1343 + if (!(ss >> cmdArgs.windowWidth))
1345 + throw std::runtime_error("Invalid argument for window width");
1348 + else if (arg == "--window-height" || arg == "-H") // avoiding "-h", typically for help
1350 + ss << argv[i + 1];
1351 + if (!(ss >> cmdArgs.windowHeight))
1353 + throw std::runtime_error("Invalid argument for window height");
1356 + else if (arg == "--window-title" || arg == "-t")
1358 + cmdArgs.windowTitle = argv[i + 1];
1360 + else if (arg == "--root-dir" || arg == "-d")
1362 + cmdArgs.rootDir = argv[i + 1];
1364 + else if (arg == "--scale-factor" || arg == "-f")
1366 + ss << argv[i + 1];
1367 + if (!(ss >> cmdArgs.scaleFactor))
1369 + throw std::runtime_error("Invalid argument for scale factor");
1372 + else if (arg == "--translate-x" || arg == "-x")
1374 + ss << argv[i + 1];
1375 + if (!(ss >> cmdArgs.translateX))
1377 + throw std::runtime_error("Invalid argument for translate X");
1380 + else if (arg == "--translate-y" || arg == "-y")
1382 + ss << argv[i + 1];
1383 + if (!(ss >> cmdArgs.translateY))
1385 + throw std::runtime_error("Invalid argument for translate Y");
1388 + else if (arg == "--model" || arg == "-m")
1390 + cmdArgs.modelName = argv[i + 1];
1392 + else if (arg == "--config" || arg == "-c")
1394 + cmdArgs.cfgPath = argv[i + 1];
1396 + else if (arg == "--old-param-id" || arg == "-o")
1398 + cmdArgs.oldId = (argv[i + 1][0] == '1');
1402 + throw std::runtime_error("Unrecognized argument: " + arg);
1411 int main(int argc, char* argv[])
1413 - // create the application instance
1414 - if (LAppDelegate::GetInstance()->Initialize() == GL_FALSE)
1415 + auto cmdArgs = parseArgv(argc, argv);
1417 + LAppDelegate *delegate = LAppDelegate::GetInstance();
1419 + if (!delegate->Initialize(cmdArgs.windowWidth,
1420 + cmdArgs.windowHeight,
1421 + cmdArgs.windowTitle.c_str()))
1424 + throw std::runtime_error("Unable to initialize LAppDelegate");
1427 - LAppDelegate::GetInstance()->Run();
1428 + delegate->SetRootDirectory(cmdArgs.rootDir);
1430 + FacialLandmarkDetector detector(cmdArgs.cfgPath);
1432 + std::thread detectorThread(&FacialLandmarkDetector::mainLoop,
1435 + LAppLive2DManager *manager = LAppLive2DManager::GetInstance();
1436 + manager->SetModel(cmdArgs.modelName, cmdArgs.oldId);
1438 + manager->SetProjectionScaleTranslate(cmdArgs.scaleFactor,
1439 + cmdArgs.translateX,
1440 + cmdArgs.translateY);
1441 + manager->SetFacialLandmarkDetector(&detector);
1446 + detectorThread.join();