1 diff -pruN --exclude build ./demo_clean/CMakeLists.txt ./demo_dev/CMakeLists.txt
2 --- ./demo_clean/CMakeLists.txt 2021-12-09 00:50:34.000000000 +0000
3 +++ ./demo_dev/CMakeLists.txt 2022-01-02 01:25:07.078550112 +0000
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.4)
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 2021-12-09 00:50:34.000000000 +0000
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 2021-12-09 00:50:34.000000000 +0000
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 2021-12-09 00:50:34.000000000 +0000
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 2021-12-09 00:50:34.000000000 +0000
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 2021-12-09 00:50:34.000000000 +0000
380 +++ ./demo_dev/src/LAppLive2DManager.cpp 2021-04-28 11:49:43.166296000 +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,21 +107,24 @@ 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);
433 if (model->GetModel()->GetCanvasWidth() > 1.0f && width < height)
435 // 横に長いモデルを縦長ウィンドウに表示する際モデルの横サイズでscaleを算出する
436 model->GetModelMatrix()->SetWidth(2.0f);
437 - projection.Scale(1.0f, static_cast<float>(width) / static_cast<float>(height));
438 + projection.Scale(_projScaleFactor,
439 + _projScaleFactor * static_cast<float>(width) / static_cast<float>(height));
443 - projection.Scale(static_cast<float>(height) / static_cast<float>(width), 1.0f);
444 + projection.Scale(_projScaleFactor * static_cast<float>(height) / static_cast<float>(width),
447 + projection.Translate(_translateX, _translateY);
450 if (_viewMatrix != NULL)
451 @@ -158,30 +141,14 @@ void LAppLive2DManager::OnUpdate() const
455 -void LAppLive2DManager::NextScene()
457 - csmInt32 no = (_sceneIndex + 1) % ModelDirSize;
461 -void LAppLive2DManager::ChangeScene(Csm::csmInt32 index)
462 +void LAppLive2DManager::SetModel(std::string modelName, bool useOldParamId)
464 - _sceneIndex = index;
465 - if (DebugLogEnable)
467 - LAppPal::PrintLog("[APP]model index: %d", _sceneIndex);
470 - // ModelDir[]に保持したディレクトリ名から
471 - // model3.jsonのパスを決定する.
472 - // ディレクトリ名とmodel3.jsonの名前を一致させておくこと.
473 - std::string model = ModelDir[index];
474 - std::string modelPath = LAppDelegate::GetInstance()->GetRootDirectory() + ResourcesPath + model + "/";
475 - std::string modelJsonName = ModelDir[index];
476 + std::string modelPath = LAppDelegate::GetInstance()->GetRootDirectory() + ResourcesPath + modelName + "/";
477 + std::string modelJsonName = modelName;
478 modelJsonName += ".model3.json";
481 - _models.PushBack(new LAppModel());
482 + _models.PushBack(new LAppModel(useOldParamId));
483 _models[0]->LoadAssets(modelPath.c_str(), modelJsonName.c_str());
486 @@ -203,7 +170,7 @@ void LAppLive2DManager::ChangeScene(Csm:
488 #if defined(USE_RENDER_TARGET) || defined(USE_MODEL_RENDER_TARGET)
489 // モデル個別にαを付けるサンプルとして、もう1体モデルを作成し、少し位置をずらす
490 - _models.PushBack(new LAppModel());
491 + _models.PushBack(new LAppModel(useOldParamId));
492 _models[1]->LoadAssets(modelPath.c_str(), modelJsonName.c_str());
493 _models[1]->GetModelMatrix()->TranslateX(0.2f);
495 @@ -232,3 +199,20 @@ void LAppLive2DManager::SetViewMatrix(Cu
496 _viewMatrix->GetArray()[i] = m->GetArray()[i];
500 +void LAppLive2DManager::SetFacialLandmarkDetector(FacialLandmarkDetector *detector)
502 + for (auto it = _models.Begin(); it != _models.End(); ++it)
504 + (*it)->SetFacialLandmarkDetector(detector);
508 +void LAppLive2DManager::SetProjectionScaleTranslate(float scaleFactor,
512 + _projScaleFactor = scaleFactor;
513 + _translateX = translateX;
514 + _translateY = translateY;
516 diff -pruN --exclude build ./demo_clean/src/LAppLive2DManager.hpp ./demo_dev/src/LAppLive2DManager.hpp
517 --- ./demo_clean/src/LAppLive2DManager.hpp 2021-12-09 00:50:34.000000000 +0000
518 +++ ./demo_dev/src/LAppLive2DManager.hpp 2021-04-28 11:49:43.166296000 +0100
524 #include <CubismFramework.hpp>
525 #include <Math/CubismMatrix44.hpp>
526 #include <Type/csmVector.hpp>
530 +class FacialLandmarkDetector;
533 * @brief サンプルアプリケーションにおいてCubismModelを管理するクラス<br>
534 * モデル生成と破棄、タップイベントの処理、モデル切り替えを行う。
535 @@ -72,16 +75,14 @@ public:
536 void OnUpdate() const;
539 - * @brief 次のシーンに切り替える<br>
540 - * サンプルアプリケーションではモデルセットの切り替えを行う。
545 - * @brief シーンを切り替える<br>
546 - * サンプルアプリケーションではモデルセットの切り替えを行う。
548 - void ChangeScene(Csm::csmInt32 index);
549 + * @brief Set model data
551 + * @param[in] modelName : Name of model, should be the same for both
552 + * the directory and the model3.json file
553 + * @param[in] useOldParamId : If true, translate new (Cubism 3+)
554 + * parameter IDs to old (Cubism 2.1) ones
556 + void SetModel(std::string modelName, bool useOldParamId);
560 @@ -94,6 +95,24 @@ public:
562 void SetViewMatrix(Live2D::Cubism::Framework::CubismMatrix44* m);
565 + * @brief Set the pointer to the FacialLandmarkDetector instance
567 + * @param[in] detector : Pointer to FacialLandmarkDetector instance
569 + void SetFacialLandmarkDetector(FacialLandmarkDetector *detector);
572 + * @brief Set projection scale factor and translation parameters
574 + * @param[in] scaleFactor : Scale factor applied in both X and Y directions
575 + * @param[in] translateX : Translation in X direction
576 + * @param[in] translateY : Translation in Y direction
578 + void SetProjectionScaleTranslate(float scaleFactor,
585 @@ -107,5 +126,8 @@ private:
587 Csm::CubismMatrix44* _viewMatrix; ///< モデル描画に用いるView行列
588 Csm::csmVector<LAppModel*> _models; ///< モデルインスタンスのコンテナ
589 - Csm::csmInt32 _sceneIndex; ///< 表示するシーンのインデックス値
591 + float _projScaleFactor;
595 diff -pruN --exclude build ./demo_clean/src/LAppModel.cpp ./demo_dev/src/LAppModel.cpp
596 --- ./demo_clean/src/LAppModel.cpp 2021-12-09 00:50:34.000000000 +0000
597 +++ ./demo_dev/src/LAppModel.cpp 2021-04-28 11:49:43.166296000 +0100
599 #include "LAppTextureManager.hpp"
600 #include "LAppDelegate.hpp"
602 +#include "facial_landmark_detector.h"
604 using namespace Live2D::Cubism::Framework;
605 using namespace Live2D::Cubism::Framework::DefaultParameterId;
606 using namespace LAppDefine;
607 @@ -45,22 +47,24 @@ namespace {
611 -LAppModel::LAppModel()
612 +LAppModel::LAppModel(bool useOldParamId)
614 , _modelSetting(NULL)
615 , _userTimeSeconds(0.0f)
616 + , _detector(nullptr)
617 + , _useOldParamId(useOldParamId)
624 - _idParamAngleX = CubismFramework::GetIdManager()->GetId(ParamAngleX);
625 - _idParamAngleY = CubismFramework::GetIdManager()->GetId(ParamAngleY);
626 - _idParamAngleZ = CubismFramework::GetIdManager()->GetId(ParamAngleZ);
627 - _idParamBodyAngleX = CubismFramework::GetIdManager()->GetId(ParamBodyAngleX);
628 - _idParamEyeBallX = CubismFramework::GetIdManager()->GetId(ParamEyeBallX);
629 - _idParamEyeBallY = CubismFramework::GetIdManager()->GetId(ParamEyeBallY);
630 + _idParamAngleX = CubismFramework::GetIdManager()->GetId(_(ParamAngleX));
631 + _idParamAngleY = CubismFramework::GetIdManager()->GetId(_(ParamAngleY));
632 + _idParamAngleZ = CubismFramework::GetIdManager()->GetId(_(ParamAngleZ));
633 + _idParamBodyAngleX = CubismFramework::GetIdManager()->GetId(_(ParamBodyAngleX));
634 + _idParamEyeBallX = CubismFramework::GetIdManager()->GetId(_(ParamEyeBallX));
635 + _idParamEyeBallY = CubismFramework::GetIdManager()->GetId(_(ParamEyeBallY));
638 LAppModel::~LAppModel()
639 @@ -128,30 +132,6 @@ void LAppModel::SetupModel(ICubismModelS
640 DeleteBuffer(buffer, path.GetRawString());
644 - if (_modelSetting->GetExpressionCount() > 0)
646 - const csmInt32 count = _modelSetting->GetExpressionCount();
647 - for (csmInt32 i = 0; i < count; i++)
649 - csmString name = _modelSetting->GetExpressionName(i);
650 - csmString path = _modelSetting->GetExpressionFileName(i);
651 - path = _modelHomeDir + path;
653 - buffer = CreateBuffer(path.GetRawString(), &size);
654 - ACubismMotion* motion = LoadExpression(buffer, size, name.GetRawString());
656 - if (_expressions[name] != NULL)
658 - ACubismMotion::Delete(_expressions[name]);
659 - _expressions[name] = NULL;
661 - _expressions[name] = motion;
663 - DeleteBuffer(buffer, path.GetRawString());
668 if (strcmp(_modelSetting->GetPhysicsFileName(), "") != 0)
670 @@ -190,7 +170,7 @@ void LAppModel::SetupModel(ICubismModelS
671 breathParameters.PushBack(CubismBreath::BreathParameterData(_idParamAngleY, 0.0f, 8.0f, 3.5345f, 0.5f));
672 breathParameters.PushBack(CubismBreath::BreathParameterData(_idParamAngleZ, 0.0f, 10.0f, 5.5345f, 0.5f));
673 breathParameters.PushBack(CubismBreath::BreathParameterData(_idParamBodyAngleX, 0.0f, 4.0f, 15.5345f, 0.5f));
674 - breathParameters.PushBack(CubismBreath::BreathParameterData(CubismFramework::GetIdManager()->GetId(ParamBreath), 0.5f, 0.5f, 3.2345f, 0.5f));
675 + breathParameters.PushBack(CubismBreath::BreathParameterData(CubismFramework::GetIdManager()->GetId(_(ParamBreath)), 0.5f, 0.5f, 3.2345f, 0.5f));
677 _breath->SetParameters(breathParameters);
679 @@ -214,15 +194,6 @@ void LAppModel::SetupModel(ICubismModelS
685 - csmInt32 lipSyncIdCount = _modelSetting->GetLipSyncParameterCount();
686 - for (csmInt32 i = 0; i < lipSyncIdCount; ++i)
688 - _lipSyncIds.PushBack(_modelSetting->GetLipSyncParameterId(i));
693 csmMap<csmString, csmFloat32> layout;
694 _modelSetting->GetLayoutMap(layout);
695 @@ -335,59 +306,57 @@ void LAppModel::Update()
696 const csmFloat32 deltaTimeSeconds = LAppPal::GetDeltaTime();
697 _userTimeSeconds += deltaTimeSeconds;
699 - _dragManager->Update(deltaTimeSeconds);
700 - _dragX = _dragManager->GetX();
701 - _dragY = _dragManager->GetY();
703 - // モーションによるパラメータ更新の有無
704 - csmBool motionUpdated = false;
706 - //-----------------------------------------------------------------
707 - _model->LoadParameters(); // 前回セーブされた状態をロード
708 - if (_motionManager->IsFinished())
710 - // モーションの再生がない場合、待機モーションの中からランダムで再生する
711 - StartRandomMotion(MotionGroupIdle, PriorityIdle);
716 - motionUpdated = _motionManager->UpdateMotion(_model, deltaTimeSeconds); // モーションを更新
718 - _model->SaveParameters(); // 状態を保存
719 - //-----------------------------------------------------------------
720 + auto idMan = CubismFramework::GetIdManager();
721 + auto params = _detector->getParams();
724 - if (!motionUpdated)
726 - if (_eyeBlink != NULL)
727 + // NOTE: Apparently, this LoadParameters/SaveParameters pair
728 + // is needed for auto breath to work.
729 + _model->LoadParameters(); // 前回セーブされた状態をロード
730 + if (_motionManager->IsFinished() && params.randomMotion)
732 - // メインモーションの更新がないとき
733 - _eyeBlink->UpdateParameters(_model, deltaTimeSeconds); // 目パチ
734 + // モーションの再生がない場合、待機モーションの中からランダムで再生する
735 + StartRandomMotion(MotionGroupIdle, PriorityIdle);
739 - if (_expressionManager != NULL)
741 - _expressionManager->UpdateMotion(_model, deltaTimeSeconds); // 表情でパラメータ更新(相対変化)
746 - _model->AddParameterValue(_idParamAngleX, _dragX * 30); // -30から30の値を加える
747 - _model->AddParameterValue(_idParamAngleY, _dragY * 30);
748 - _model->AddParameterValue(_idParamAngleZ, _dragX * _dragY * -30);
751 - _model->AddParameterValue(_idParamBodyAngleX, _dragX * 10); // -10から10の値を加える
754 + _motionManager->UpdateMotion(_model, deltaTimeSeconds); // モーションを更新
756 + _model->SaveParameters(); // 状態を保存
759 - _model->AddParameterValue(_idParamEyeBallX, _dragX); // -1から1の値を加える
760 - _model->AddParameterValue(_idParamEyeBallY, _dragY);
763 - if (_breath != NULL)
765 - _breath->UpdateParameters(_model, deltaTimeSeconds);
766 + if (params.autoBlink && _eyeBlink)
768 + _eyeBlink->UpdateParameters(_model, deltaTimeSeconds);
772 + _model->SetParameterValue(idMan->GetId(_("ParamEyeLOpen")),
773 + params.leftEyeOpenness);
774 + _model->SetParameterValue(idMan->GetId(_("ParamEyeROpen")),
775 + params.rightEyeOpenness);
777 + _model->SetParameterValue(idMan->GetId(_("ParamMouthForm")),
779 + _model->SetParameterValue(idMan->GetId(_("ParamMouthOpenY")),
780 + params.mouthOpenness);
781 + _model->SetParameterValue(idMan->GetId(_("ParamEyeLSmile")),
782 + params.leftEyeSmile);
783 + _model->SetParameterValue(idMan->GetId(_("ParamEyeRSmile")),
784 + params.rightEyeSmile);
785 + _model->SetParameterValue(idMan->GetId(_("ParamAngleX")),
786 + params.faceXAngle);
787 + _model->SetParameterValue(idMan->GetId(_("ParamAngleY")),
788 + params.faceYAngle);
789 + _model->SetParameterValue(idMan->GetId(_("ParamAngleZ")),
790 + params.faceZAngle);
791 + if (params.autoBreath && _breath)
793 + // Note: _model->LoadParameters and SaveParameters is needed
794 + // before - see above.
795 + _breath->UpdateParameters(_model, deltaTimeSeconds);
800 @@ -396,22 +365,6 @@ void LAppModel::Update()
801 _physics->Evaluate(_model, deltaTimeSeconds);
807 - // リアルタイムでリップシンクを行う場合、システムから音量を取得して0〜1の範囲で値を入力します。
808 - csmFloat32 value = 0.0f;
811 - _wavFileHandler.Update(deltaTimeSeconds);
812 - value = _wavFileHandler.GetRms();
814 - for (csmUint32 i = 0; i < _lipSyncIds.GetSize(); ++i)
816 - _model->AddParameterValue(_lipSyncIds[i], value, 0.8f);
823 @@ -480,7 +433,6 @@ CubismMotionQueueEntryHandle LAppModel::
825 csmString path = voice;
826 path = _modelHomeDir + path;
827 - _wavFileHandler.Start(path);
831 @@ -632,3 +584,37 @@ Csm::Rendering::CubismOffscreenFrame_Ope
833 return _renderBuffer;
836 +void LAppModel::SetFacialLandmarkDetector(FacialLandmarkDetector *detector)
838 + _detector = detector;
841 +Csm::csmString LAppModel::_(std::string s)
844 + if (_useOldParamId)
846 + if (s == "ParamTere")
848 + ans = "PARAM_CHEEK";
852 + for (size_t i = 0; i < s.size(); i++)
854 + if (std::isupper(s[i]) && i != 0)
858 + ans += std::toupper(s[i]);
866 + return csmString(ans.c_str());
869 diff -pruN --exclude build ./demo_clean/src/LAppModel.hpp ./demo_dev/src/LAppModel.hpp
870 --- ./demo_clean/src/LAppModel.hpp 2021-12-09 00:50:34.000000000 +0000
871 +++ ./demo_dev/src/LAppModel.hpp 2021-04-28 11:49:43.166296000 +0100
873 #include <Type/csmRectF.hpp>
874 #include <Rendering/OpenGL/CubismOffscreenSurface_OpenGLES2.hpp>
876 -#include "LAppWavFileHandler.hpp"
877 +#include "facial_landmark_detector.h"
880 * @brief ユーザーが実際に使用するモデルの実装クラス<br>
881 @@ -25,8 +25,11 @@ class LAppModel : public Csm::CubismUser
886 + * @param[in] useOldParamId : If true, translate new (Cubism 3+)
887 + * parameter IDs to old (Cubism 2.1) ones
890 + LAppModel(bool useOldParamId);
894 @@ -114,6 +117,13 @@ public:
896 Csm::Rendering::CubismOffscreenFrame_OpenGLES2& GetRenderBuffer();
899 + * @brief Set the pointer to the FacialLandmarkDetector instance
901 + * @param[in] detector : Pointer to FacialLandmarkDetector instance
903 + void SetFacialLandmarkDetector(FacialLandmarkDetector *detector);
907 * @brief モデルを描画する処理。モデルを描画する空間のView-Projection行列を渡す。
908 @@ -167,6 +177,17 @@ private:
910 void ReleaseExpressions();
913 + * @brief Translate new (Cubism 3+) parameter IDs to old (Cubism 2.1) ones
915 + * @param[in] s : New parameter ID
917 + * @return Old parameter ID
919 + Csm::csmString _(std::string s);
921 + bool _useOldParamId;
923 Csm::ICubismModelSetting* _modelSetting; ///< モデルセッティング情報
924 Csm::csmString _modelHomeDir; ///< モデルセッティングが置かれたディレクトリ
925 Csm::csmFloat32 _userTimeSeconds; ///< デルタ時間の積算値[秒]
926 @@ -183,9 +204,9 @@ private:
927 const Csm::CubismId* _idParamEyeBallX; ///< パラメータID: ParamEyeBallX
928 const Csm::CubismId* _idParamEyeBallY; ///< パラメータID: ParamEyeBallXY
930 - LAppWavFileHandler _wavFileHandler; ///< wavファイルハンドラ
932 Csm::Rendering::CubismOffscreenFrame_OpenGLES2 _renderBuffer; ///< フレームバッファ以外の描画先
934 + FacialLandmarkDetector *_detector;
938 diff -pruN --exclude build ./demo_clean/src/LAppPal.cpp ./demo_dev/src/LAppPal.cpp
939 --- ./demo_clean/src/LAppPal.cpp 2021-12-09 00:50:34.000000000 +0000
940 +++ ./demo_dev/src/LAppPal.cpp 2021-04-28 11:49:43.170296000 +0100
944 #include "LAppPal.hpp"
945 +#include <stdexcept>
949 @@ -45,10 +46,7 @@ csmByte* LAppPal::LoadFileAsBytes(const
950 file.open(path, std::ios::in | std::ios::binary);
953 - if (DebugLogEnable)
955 - PrintLog("file open error");
957 + throw std::runtime_error("Failed to open file " + filePath);
960 file.read(buf, size);
961 diff -pruN --exclude build ./demo_clean/src/LAppTextureManager.cpp ./demo_dev/src/LAppTextureManager.cpp
962 --- ./demo_clean/src/LAppTextureManager.cpp 2021-12-09 00:50:34.000000000 +0000
963 +++ ./demo_dev/src/LAppTextureManager.cpp 2021-04-28 11:49:43.178296000 +0100
964 @@ -96,6 +96,46 @@ LAppTextureManager::TextureInfo* LAppTex
968 +LAppTextureManager::TextureInfo* LAppTextureManager::CreateTextureFromColor(
969 + uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha
972 + int width = 8, height = 8;
974 + uint8_t pixels[height][width][4];
975 + for (std::size_t h = 0; h < height; h++)
977 + for (std::size_t w = 0; w < width; w++)
979 + pixels[h][w][0] = red;
980 + pixels[h][w][1] = green;
981 + pixels[h][w][2] = blue;
982 + pixels[h][w][3] = alpha;
987 + glGenTextures(1, &textureId);
988 + glBindTexture(GL_TEXTURE_2D, textureId);
989 + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
991 + glGenerateMipmap(GL_TEXTURE_2D);
992 + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
993 + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
994 + glBindTexture(GL_TEXTURE_2D, 0);
997 + LAppTextureManager::TextureInfo* textureInfo = new LAppTextureManager::TextureInfo();
998 + textureInfo->fileName = "";
999 + textureInfo->width = width;
1000 + textureInfo->height = height;
1001 + textureInfo->id = textureId;
1003 + _textures.PushBack(textureInfo);
1005 + return textureInfo;
1008 void LAppTextureManager::ReleaseTextures()
1010 for (Csm::csmUint32 i = 0; i < _textures.GetSize(); i++)
1011 diff -pruN --exclude build ./demo_clean/src/LAppTextureManager.hpp ./demo_dev/src/LAppTextureManager.hpp
1012 --- ./demo_clean/src/LAppTextureManager.hpp 2021-12-09 00:50:34.000000000 +0000
1013 +++ ./demo_dev/src/LAppTextureManager.hpp 2021-04-28 11:49:43.178296000 +0100
1014 @@ -72,6 +72,8 @@ public:
1016 TextureInfo* CreateTextureFromPngFile(std::string fileName);
1018 + TextureInfo *CreateTextureFromColor(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha = 255);
1023 diff -pruN --exclude build ./demo_clean/src/LAppView.cpp ./demo_dev/src/LAppView.cpp
1024 --- ./demo_clean/src/LAppView.cpp 2021-12-09 00:50:34.000000000 +0000
1025 +++ ./demo_dev/src/LAppView.cpp 2021-04-28 11:49:43.178296000 +0100
1027 #include "LAppLive2DManager.hpp"
1028 #include "LAppTextureManager.hpp"
1029 #include "LAppDefine.hpp"
1030 -#include "TouchManager.hpp"
1031 #include "LAppSprite.hpp"
1032 #include "LAppModel.hpp"
1034 @@ -26,8 +25,6 @@ using namespace LAppDefine;
1035 LAppView::LAppView():
1040 _renderSprite(NULL),
1041 _renderTarget(SelectTarget_None)
1043 @@ -35,8 +32,6 @@ LAppView::LAppView():
1044 _clearColor[1] = 1.0f;
1045 _clearColor[2] = 1.0f;
1046 _clearColor[3] = 0.0f;
1048 - _touchManager = new TouchManager();
1050 // デバイス座標からスクリーン座標に変換するための
1051 _deviceToScreen = new CubismMatrix44();
1052 @@ -52,10 +47,7 @@ LAppView::~LAppView()
1055 delete _deviceToScreen;
1056 - delete _touchManager;
1062 void LAppView::Initialize()
1063 @@ -107,9 +99,6 @@ void LAppView::Initialize()
1064 void LAppView::Render()
1071 LAppLive2DManager* Live2DManager = LAppLive2DManager::GetInstance();
1073 @@ -151,35 +140,17 @@ void LAppView::InitializeSprite()
1074 glfwGetWindowSize(LAppDelegate::GetInstance()->GetWindow(), &width, &height);
1076 LAppTextureManager* textureManager = LAppDelegate::GetInstance()->GetTextureManager();
1077 - const string resourcesPath = LAppDelegate::GetInstance()->GetRootDirectory() + ResourcesPath;
1079 - string imageName = BackImageName;
1080 - LAppTextureManager::TextureInfo* backgroundTexture = textureManager->CreateTextureFromPngFile(resourcesPath + imageName);
1082 + LAppTextureManager::TextureInfo* backgroundTexture =
1083 + textureManager->CreateTextureFromColor(0, 255, 0);
1085 float x = width * 0.5f;
1086 float y = height * 0.5f;
1087 - float fWidth = static_cast<float>(backgroundTexture->width * 2.0f);
1088 - float fHeight = static_cast<float>(height) * 0.95f;
1089 + float fWidth = static_cast<float>(width);
1090 + float fHeight = static_cast<float>(height);
1091 _back = new LAppSprite(x, y, fWidth, fHeight, backgroundTexture->id, _programId);
1093 - imageName = GearImageName;
1094 - LAppTextureManager::TextureInfo* gearTexture = textureManager->CreateTextureFromPngFile(resourcesPath + imageName);
1096 - x = static_cast<float>(width - gearTexture->width * 0.5f);
1097 - y = static_cast<float>(height - gearTexture->height * 0.5f);
1098 - fWidth = static_cast<float>(gearTexture->width);
1099 - fHeight = static_cast<float>(gearTexture->height);
1100 - _gear = new LAppSprite(x, y, fWidth, fHeight, gearTexture->id, _programId);
1102 - imageName = PowerImageName;
1103 - LAppTextureManager::TextureInfo* powerTexture = textureManager->CreateTextureFromPngFile(resourcesPath + imageName);
1105 - x = static_cast<float>(width - powerTexture->width * 0.5f);
1106 - y = static_cast<float>(powerTexture->height * 0.5f);
1107 - fWidth = static_cast<float>(powerTexture->width);
1108 - fHeight = static_cast<float>(powerTexture->height);
1109 - _power = new LAppSprite(x, y, fWidth, fHeight, powerTexture->id, _programId);
1114 @@ -187,52 +158,6 @@ void LAppView::InitializeSprite()
1118 -void LAppView::OnTouchesBegan(float px, float py) const
1120 - _touchManager->TouchesBegan(px, py);
1123 -void LAppView::OnTouchesMoved(float px, float py) const
1125 - float viewX = this->TransformViewX(_touchManager->GetX());
1126 - float viewY = this->TransformViewY(_touchManager->GetY());
1128 - _touchManager->TouchesMoved(px, py);
1130 - LAppLive2DManager* Live2DManager = LAppLive2DManager::GetInstance();
1131 - Live2DManager->OnDrag(viewX, viewY);
1134 -void LAppView::OnTouchesEnded(float px, float py) const
1137 - LAppLive2DManager* live2DManager = LAppLive2DManager::GetInstance();
1138 - live2DManager->OnDrag(0.0f, 0.0f);
1142 - float x = _deviceToScreen->TransformX(_touchManager->GetX()); // 論理座標変換した座標を取得。
1143 - float y = _deviceToScreen->TransformY(_touchManager->GetY()); // 論理座標変換した座標を取得。
1144 - if (DebugTouchLogEnable)
1146 - LAppPal::PrintLog("[APP]touchesEnded x:%.2f y:%.2f", x, y);
1148 - live2DManager->OnTap(x, y);
1151 - if (_gear->IsHit(px, py))
1153 - live2DManager->NextScene();
1157 - if (_power->IsHit(px, py))
1159 - LAppDelegate::GetInstance()->AppEnd();
1164 float LAppView::TransformViewX(float deviceX) const
1166 float screenX = _deviceToScreen->TransformX(deviceX); // 論理座標変換した座標を取得。
1167 @@ -374,32 +299,4 @@ void LAppView::ResizeSprite()
1168 _back->ResetRect(x, y, fWidth, fHeight);
1174 - GLuint id = _power->GetTextureId();
1175 - LAppTextureManager::TextureInfo* texInfo = textureManager->GetTextureInfoById(id);
1178 - x = static_cast<float>(width - texInfo->width * 0.5f);
1179 - y = static_cast<float>(texInfo->height * 0.5f);
1180 - fWidth = static_cast<float>(texInfo->width);
1181 - fHeight = static_cast<float>(texInfo->height);
1182 - _power->ResetRect(x, y, fWidth, fHeight);
1188 - GLuint id = _gear->GetTextureId();
1189 - LAppTextureManager::TextureInfo* texInfo = textureManager->GetTextureInfoById(id);
1192 - x = static_cast<float>(width - texInfo->width * 0.5f);
1193 - y = static_cast<float>(height - texInfo->height * 0.5f);
1194 - fWidth = static_cast<float>(texInfo->width);
1195 - fHeight = static_cast<float>(texInfo->height);
1196 - _gear->ResetRect(x, y, fWidth, fHeight);
1200 diff -pruN --exclude build ./demo_clean/src/LAppView.hpp ./demo_dev/src/LAppView.hpp
1201 --- ./demo_clean/src/LAppView.hpp 2021-12-09 00:50:34.000000000 +0000
1202 +++ ./demo_dev/src/LAppView.hpp 2021-04-28 11:49:43.178296000 +0100
1204 #include "CubismFramework.hpp"
1205 #include <Rendering/OpenGL/CubismOffscreenSurface_OpenGLES2.hpp>
1207 -class TouchManager;
1211 @@ -66,30 +65,6 @@ public:
1212 void ResizeSprite();
1215 - * @brief タッチされたときに呼ばれる。
1217 - * @param[in] pointX スクリーンX座標
1218 - * @param[in] pointY スクリーンY座標
1220 - void OnTouchesBegan(float pointX, float pointY) const;
1223 - * @brief タッチしているときにポインタが動いたら呼ばれる。
1225 - * @param[in] pointX スクリーンX座標
1226 - * @param[in] pointY スクリーンY座標
1228 - void OnTouchesMoved(float pointX, float pointY) const;
1231 - * @brief タッチが終了したら呼ばれる。
1233 - * @param[in] pointX スクリーンX座標
1234 - * @param[in] pointY スクリーンY座標
1236 - void OnTouchesEnded(float pointX, float pointY) const;
1239 * @brief X座標をView座標に変換する。
1241 * @param[in] deviceX デバイスX座標
1242 @@ -147,13 +122,10 @@ public:
1243 void SetRenderTargetClearColor(float r, float g, float b);
1246 - TouchManager* _touchManager; ///< タッチマネージャー
1247 Csm::CubismMatrix44* _deviceToScreen; ///< デバイスからスクリーンへの行列
1248 Csm::CubismViewMatrix* _viewMatrix; ///< viewMatrix
1249 GLuint _programId; ///< シェーダID
1250 LAppSprite* _back; ///< 背景画像
1251 - LAppSprite* _gear; ///< ギア画像
1252 - LAppSprite* _power; ///< 電源画像
1254 // レンダリング先を別ターゲットにする方式の場合に使用
1255 LAppSprite* _renderSprite; ///< モードによっては_renderBufferのテクスチャを描画
1256 diff -pruN --exclude build ./demo_clean/src/main.cpp ./demo_dev/src/main.cpp
1257 --- ./demo_clean/src/main.cpp 2021-12-09 00:50:34.000000000 +0000
1258 +++ ./demo_dev/src/main.cpp 2021-04-28 11:49:43.178296000 +0100
1260 * that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html.
1264 +#include <stdexcept>
1267 +#ifdef __cpp_lib_filesystem
1268 +#include <filesystem>
1269 +namespace fs = std::filesystem;
1271 +#include <experimental/filesystem>
1272 +namespace fs = std::experimental::filesystem;
1276 #include "LAppDelegate.hpp"
1277 +#include "LAppLive2DManager.hpp"
1278 +#include "facial_landmark_detector.h"
1284 + std::string windowTitle;
1285 + std::string rootDir;
1286 + float scaleFactor;
1289 + std::string modelName;
1290 + bool oldId; // If true, translate new (Cubism 3+) parameter IDs to old (Cubism 2.1) IDs
1291 + std::string cfgPath; // Path to config file for FacialLandmarkDetector
1294 +CmdArgs parseArgv(int argc, char *argv[])
1296 + // I think the command-line args are simple enough to not justify using a library...
1298 + // Set default values
1299 + cmdArgs.windowWidth = 600;
1300 + cmdArgs.windowHeight = 600;
1301 + cmdArgs.windowTitle = "FacialLandmarksForCubism example";
1302 + cmdArgs.rootDir = fs::current_path();
1303 + cmdArgs.scaleFactor = 4.5f;
1304 + cmdArgs.translateX = 0.0f;
1305 + cmdArgs.translateY = -3.1f;
1306 + cmdArgs.modelName = "Haru";
1307 + cmdArgs.oldId = false;
1308 + cmdArgs.cfgPath = "";
1313 + std::string arg = argv[i];
1314 + std::stringstream ss;
1316 + if (arg == "--window-width" || arg == "-W") // capital W for consistency with height
1318 + ss << argv[i + 1];
1319 + if (!(ss >> cmdArgs.windowWidth))
1321 + throw std::runtime_error("Invalid argument for window width");
1324 + else if (arg == "--window-height" || arg == "-H") // avoiding "-h", typically for help
1326 + ss << argv[i + 1];
1327 + if (!(ss >> cmdArgs.windowHeight))
1329 + throw std::runtime_error("Invalid argument for window height");
1332 + else if (arg == "--window-title" || arg == "-t")
1334 + cmdArgs.windowTitle = argv[i + 1];
1336 + else if (arg == "--root-dir" || arg == "-d")
1338 + cmdArgs.rootDir = argv[i + 1];
1340 + else if (arg == "--scale-factor" || arg == "-f")
1342 + ss << argv[i + 1];
1343 + if (!(ss >> cmdArgs.scaleFactor))
1345 + throw std::runtime_error("Invalid argument for scale factor");
1348 + else if (arg == "--translate-x" || arg == "-x")
1350 + ss << argv[i + 1];
1351 + if (!(ss >> cmdArgs.translateX))
1353 + throw std::runtime_error("Invalid argument for translate X");
1356 + else if (arg == "--translate-y" || arg == "-y")
1358 + ss << argv[i + 1];
1359 + if (!(ss >> cmdArgs.translateY))
1361 + throw std::runtime_error("Invalid argument for translate Y");
1364 + else if (arg == "--model" || arg == "-m")
1366 + cmdArgs.modelName = argv[i + 1];
1368 + else if (arg == "--config" || arg == "-c")
1370 + cmdArgs.cfgPath = argv[i + 1];
1372 + else if (arg == "--old-param-id" || arg == "-o")
1374 + cmdArgs.oldId = (argv[i + 1][0] == '1');
1378 + throw std::runtime_error("Unrecognized argument: " + arg);
1387 int main(int argc, char* argv[])
1389 - // create the application instance
1390 - if (LAppDelegate::GetInstance()->Initialize() == GL_FALSE)
1391 + auto cmdArgs = parseArgv(argc, argv);
1393 + LAppDelegate *delegate = LAppDelegate::GetInstance();
1395 + if (!delegate->Initialize(cmdArgs.windowWidth,
1396 + cmdArgs.windowHeight,
1397 + cmdArgs.windowTitle.c_str()))
1400 + throw std::runtime_error("Unable to initialize LAppDelegate");
1403 - LAppDelegate::GetInstance()->Run();
1404 + delegate->SetRootDirectory(cmdArgs.rootDir);
1406 + FacialLandmarkDetector detector(cmdArgs.cfgPath);
1408 + std::thread detectorThread(&FacialLandmarkDetector::mainLoop,
1411 + LAppLive2DManager *manager = LAppLive2DManager::GetInstance();
1412 + manager->SetModel(cmdArgs.modelName, cmdArgs.oldId);
1414 + manager->SetProjectionScaleTranslate(cmdArgs.scaleFactor,
1415 + cmdArgs.translateX,
1416 + cmdArgs.translateY);
1417 + manager->SetFacialLandmarkDetector(&detector);
1422 + detectorThread.join();