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