8f072566ba6e163288bdd60ac3eb078964ea11de
[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 2020-01-30 05:45:00.000000000 +0000
3 +++ ./demo_dev/CMakeLists.txt   2020-10-02 02:10:49.198928000 +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.1)
10  set(CORE_PATH ${SDK_ROOT_PATH}/Core)
11  set(FRAMEWORK_PATH ${SDK_ROOT_PATH}/Framework)
12  set(THIRD_PARTY_PATH ${SDK_ROOT_PATH}/Samples/OpenGL/thirdParty)
13 @@ -32,7 +32,7 @@ set(GLFW_INSTALL OFF CACHE BOOL "" FORCE
14  set(BUILD_UTILS OFF CACHE BOOL "" FORCE)
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 @@ -86,6 +91,17 @@ add_custom_command(
46        copy_directory ${RES_PATH} $<TARGET_FILE_DIR:${APP_NAME}>/Resources
47  )
48  
49 +# Copy shape predictor trained dataset to build directory
50 +set(DLIB_SHAPE_PREDICTOR_DATA ${CMAKE_CURRENT_SOURCE_DIR}/../shape_predictor_68_face_landmarks.dat
51 +    CACHE FILEPATH "Path to dlib shape predictor trained dataset")
52 +add_custom_command(
53 +  TARGET ${APP_NAME}
54 +  POST_BUILD
55 +  COMMAND
56 +    ${CMAKE_COMMAND} -E
57 +      copy ${DLIB_SHAPE_PREDICTOR_DATA} $<TARGET_FILE_DIR:${APP_NAME}>/
58 +)
59 +
60  # You can change target that renderer draws by enabling following definition.
61  #
62  # * USE_RENDER_TARGET
63 diff -pruN --exclude build ./demo_clean/scripts/make_gcc ./demo_dev/scripts/make_gcc
64 --- ./demo_clean/scripts/make_gcc       2020-01-30 05:45:00.000000000 +0000
65 +++ ./demo_dev/scripts/make_gcc 2020-10-02 02:10:49.198928000 +0100
66 @@ -9,5 +9,6 @@ BUILD_PATH=$SCRIPT_PATH/../build/make_gc
67  # Run CMake.
68  cmake -S "$CMAKE_PATH" \
69    -B "$BUILD_PATH" \
70 -  -D CMAKE_BUILD_TYPE=Release
71 -cd "$BUILD_PATH" && make
72 +  -D CMAKE_BUILD_TYPE=Release \
73 +  -D USE_AVX_INSTRUCTIONS=1
74 +cd "$BUILD_PATH" && make -j4
75 diff -pruN --exclude build ./demo_clean/src/CMakeLists.txt ./demo_dev/src/CMakeLists.txt
76 --- ./demo_clean/src/CMakeLists.txt     2020-01-30 05:45:00.000000000 +0000
77 +++ ./demo_dev/src/CMakeLists.txt       2020-10-02 02:10:49.198928000 +0100
78 @@ -19,6 +19,4 @@ target_sources(${APP_NAME}
79      ${CMAKE_CURRENT_SOURCE_DIR}/LAppView.cpp
80      ${CMAKE_CURRENT_SOURCE_DIR}/LAppView.hpp
81      ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp
82 -    ${CMAKE_CURRENT_SOURCE_DIR}/TouchManager.cpp
83 -    ${CMAKE_CURRENT_SOURCE_DIR}/TouchManager.hpp
84  )
85 diff -pruN --exclude build ./demo_clean/src/LAppDelegate.cpp ./demo_dev/src/LAppDelegate.cpp
86 --- ./demo_clean/src/LAppDelegate.cpp   2020-01-30 05:45:00.000000000 +0000
87 +++ ./demo_dev/src/LAppDelegate.cpp     2020-10-02 02:10:49.198928000 +0100
88 @@ -45,7 +45,8 @@ void LAppDelegate::ReleaseInstance()
89      s_instance = NULL;
90  }
91  
92 -bool LAppDelegate::Initialize()
93 +bool LAppDelegate::Initialize(int initWindowWidth, int initWindowHeight,
94 +                              const char *windowTitle)
95  {
96      if (DebugLogEnable)
97      {
98 @@ -63,7 +64,13 @@ bool LAppDelegate::Initialize()
99      }
100  
101      // Windowの生成_
102 -    _window = glfwCreateWindow(RenderTargetWidth, RenderTargetHeight, "SAMPLE", NULL, NULL);
103 +    _window = glfwCreateWindow(
104 +        initWindowWidth ? initWindowWidth : RenderTargetWidth,
105 +        initWindowHeight ? initWindowHeight : RenderTargetHeight,
106 +        windowTitle ? windowTitle : "SAMPLE",
107 +        NULL,
108 +        NULL);
109 +
110      if (_window == NULL)
111      {
112          if (DebugLogEnable)
113 @@ -95,10 +102,6 @@ bool LAppDelegate::Initialize()
114      glEnable(GL_BLEND);
115      glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
116  
117 -    //コールバック関数の登録
118 -    glfwSetMouseButtonCallback(_window, EventHandler::OnMouseCallBack);
119 -    glfwSetCursorPosCallback(_window, EventHandler::OnMouseCallBack);
120 -
121      // ウィンドウサイズ記憶
122      int width, height;
123      glfwGetWindowSize(LAppDelegate::GetInstance()->GetWindow(), &width, &height);
124 @@ -111,8 +114,6 @@ bool LAppDelegate::Initialize()
125      // Cubism3の初期化
126      InitializeCubism();
127  
128 -    SetRootDirectory();
129 -
130      //load model
131      LAppLive2DManager::GetInstance();
132  
133 @@ -214,49 +215,6 @@ void LAppDelegate::InitializeCubism()
134      LAppPal::UpdateTime();
135  }
136  
137 -void LAppDelegate::OnMouseCallBack(GLFWwindow* window, int button, int action, int modify)
138 -{
139 -    if (_view == NULL)
140 -    {
141 -        return;
142 -    }
143 -    if (GLFW_MOUSE_BUTTON_LEFT != button)
144 -    {
145 -        return;
146 -    }
147 -
148 -    if (GLFW_PRESS == action)
149 -    {
150 -        _captured = true;
151 -        _view->OnTouchesBegan(_mouseX, _mouseY);
152 -    }
153 -    else if (GLFW_RELEASE == action)
154 -    {
155 -        if (_captured)
156 -        {
157 -            _captured = false;
158 -            _view->OnTouchesEnded(_mouseX, _mouseY);
159 -        }
160 -    }
161 -}
162 -
163 -void LAppDelegate::OnMouseCallBack(GLFWwindow* window, double x, double y)
164 -{
165 -    _mouseX = static_cast<float>(x);
166 -    _mouseY = static_cast<float>(y);
167 -
168 -    if (!_captured)
169 -    {
170 -        return;
171 -    }
172 -    if (_view == NULL)
173 -    {
174 -        return;
175 -    }
176 -
177 -    _view->OnTouchesMoved(_mouseX, _mouseY);
178 -}
179 -
180  GLuint LAppDelegate::CreateShader()
181  {
182      //バーテックスシェーダのコンパイル
183 @@ -299,29 +257,9 @@ GLuint LAppDelegate::CreateShader()
184      return programId;
185  }
186  
187 -void LAppDelegate::SetRootDirectory()
188 +void LAppDelegate::SetRootDirectory(std::string rootDir)
189  {
190 -    char path[1024];
191 -    ssize_t len = readlink("/proc/self/exe", path, 1024 - 1);
192 -
193 -    if (len != -1)
194 -    {
195 -        path[len] = '\0';
196 -    }
197 -
198 -    std::string pathString(path);
199 -
200 -    pathString = pathString.substr(0, pathString.rfind("Demo"));
201 -    Csm::csmVector<string> splitStrings = this->Split(pathString, '/');
202 -
203 -    this->_rootDirectory = "";
204 -
205 -    for(int i = 0; i < splitStrings.GetSize(); i++)
206 -    {
207 -        this->_rootDirectory = this->_rootDirectory + "/" +splitStrings[i];
208 -    }
209 -
210 -    this->_rootDirectory += "/";
211 +    this->_rootDirectory = rootDir + "/";
212  }
213  
214  Csm::csmVector<string> LAppDelegate::Split(const std::string& baseString, char delimiter)
215 diff -pruN --exclude build ./demo_clean/src/LAppDelegate.hpp ./demo_dev/src/LAppDelegate.hpp
216 --- ./demo_clean/src/LAppDelegate.hpp   2020-01-30 05:45:00.000000000 +0000
217 +++ ./demo_dev/src/LAppDelegate.hpp     2020-10-02 02:10:49.198928000 +0100
218 @@ -40,7 +40,8 @@ public:
219      /**
220      * @brief   APPに必要なものを初期化する。
221      */
222 -    bool Initialize();
223 +    bool Initialize(int initWindowWidth = 0, int initWindowHeight = 0,
224 +                    const char *windowTitle = "SAMPLE");
225  
226      /**
227      * @brief   解放する。
228 @@ -53,25 +54,6 @@ public:
229      void Run();
230  
231      /**
232 -    * @brief   OpenGL用 glfwSetMouseButtonCallback用関数。
233 -    *
234 -    * @param[in]       window            コールバックを呼んだWindow情報
235 -    * @param[in]       button            ボタン種類
236 -    * @param[in]       action            実行結果
237 -    * @param[in]       modify
238 -    */
239 -    void OnMouseCallBack(GLFWwindow* window, int button, int action, int modify);
240 -
241 -    /**
242 -    * @brief   OpenGL用 glfwSetCursorPosCallback用関数。
243 -    *
244 -    * @param[in]       window            コールバックを呼んだWindow情報
245 -    * @param[in]       x                 x座標
246 -    * @param[in]       y                 x座標
247 -    */
248 -    void OnMouseCallBack(GLFWwindow* window, double x, double y);
249 -
250 -    /**
251      * @brief シェーダーを登録する。
252      */
253      GLuint CreateShader();
254 @@ -98,8 +80,10 @@ public:
255  
256      /**
257       * @brief   ルートディレクトリを設定する。
258 +     *
259 +     * @param[in] rootDir : The root directory to set to.
260       */
261 -    void SetRootDirectory();
262 +    void SetRootDirectory(std::string rootDir);
263  
264      /**
265       * @brief   ルートディレクトリを取得する。
266 @@ -146,24 +130,3 @@ private:
267      int _windowWidth;                            ///< Initialize関数で設定したウィンドウ幅
268      int _windowHeight;                           ///< Initialize関数で設定したウィンドウ高さ
269  };
270 -
271 -class EventHandler
272 -{
273 -public:
274 -    /**
275 -    * @brief   glfwSetMouseButtonCallback用コールバック関数。
276 -    */
277 -    static void OnMouseCallBack(GLFWwindow* window, int button, int action, int modify)
278 -    {
279 -        LAppDelegate::GetInstance()->OnMouseCallBack(window, button, action, modify);
280 -    }
281 -
282 -    /**
283 -    * @brief   glfwSetCursorPosCallback用コールバック関数。
284 -    */
285 -    static void OnMouseCallBack(GLFWwindow* window, double x, double y)
286 -    {
287 -         LAppDelegate::GetInstance()->OnMouseCallBack(window, x, y);
288 -    }
289 -
290 -};
291 diff -pruN --exclude build ./demo_clean/src/LAppLive2DManager.cpp ./demo_dev/src/LAppLive2DManager.cpp
292 --- ./demo_clean/src/LAppLive2DManager.cpp      2020-01-30 05:45:00.000000000 +0000
293 +++ ./demo_dev/src/LAppLive2DManager.cpp        2021-01-02 12:03:47.315569210 +0000
294 @@ -52,9 +52,10 @@ void LAppLive2DManager::ReleaseInstance(
295  
296  LAppLive2DManager::LAppLive2DManager()
297      : _viewMatrix(NULL)
298 -    , _sceneIndex(0)
299 +    , _projScaleFactor(1.0f)
300 +    , _translateX(0.0f)
301 +    , _translateY(0.0f)
302  {
303 -    ChangeScene(_sceneIndex);
304  }
305  
306  LAppLive2DManager::~LAppLive2DManager()
307 @@ -98,26 +99,6 @@ void LAppLive2DManager::OnTap(csmFloat32
308      {
309          LAppPal::PrintLog("[APP]tap point: {x:%.2f y:%.2f}", x, y);
310      }
311 -
312 -    for (csmUint32 i = 0; i < _models.GetSize(); i++)
313 -    {
314 -        if (_models[i]->HitTest(HitAreaNameHead, x, y))
315 -        {
316 -            if (DebugLogEnable)
317 -            {
318 -                LAppPal::PrintLog("[APP]hit area: [%s]", HitAreaNameHead);
319 -            }
320 -            _models[i]->SetRandomExpression();
321 -        }
322 -        else if (_models[i]->HitTest(HitAreaNameBody, x, y))
323 -        {
324 -            if (DebugLogEnable)
325 -            {
326 -                LAppPal::PrintLog("[APP]hit area: [%s]", HitAreaNameBody);
327 -            }
328 -            _models[i]->StartRandomMotion(MotionGroupTapBody, PriorityNormal, FinishedMotion);
329 -        }
330 -    }
331  }
332  
333  void LAppLive2DManager::OnUpdate() const
334 @@ -125,7 +106,9 @@ void LAppLive2DManager::OnUpdate() const
335      CubismMatrix44 projection;
336      int width, height;
337      glfwGetWindowSize(LAppDelegate::GetInstance()->GetWindow(), &width, &height);
338 -    projection.Scale(1.0f, static_cast<float>(width) / static_cast<float>(height));
339 +    projection.Scale(_projScaleFactor,
340 +                     _projScaleFactor * static_cast<float>(width) / static_cast<float>(height));
341 +    projection.Translate(_translateX, _translateY);
342  
343      if (_viewMatrix != NULL)
344      {
345 @@ -148,30 +131,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 @@ -193,7 +160,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 @@ -215,3 +182,20 @@ csmUint32 LAppLive2DManager::GetModelNum
390  {
391      return _models.GetSize();
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      2020-01-30 05:45:00.000000000 +0000
412 +++ ./demo_dev/src/LAppLive2DManager.hpp        2021-01-02 12:04:05.551573634 +0000
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 @@ -89,6 +90,24 @@ public:
455       */
456      Csm::csmUint32 GetModelNum() const;
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 @@ -102,5 +121,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      2020-01-30 05:45:00.000000000 +0000
491 +++ ./demo_dev/src/LAppModel.cpp        2021-01-02 12:07:31.408109737 +0000
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,17 +365,6 @@ void LAppModel::Update()
695          _physics->Evaluate(_model, deltaTimeSeconds);
696      }
697  
698 -    // リップシンクの設定
699 -    if (_lipSync)
700 -    {
701 -        csmFloat32 value = 0; // リアルタイムでリップシンクを行う場合、システムから音量を取得して0〜1の範囲で値を入力します。
702 -
703 -        for (csmUint32 i = 0; i < _lipSyncIds.GetSize(); ++i)
704 -        {
705 -            _model->AddParameterValue(_lipSyncIds[i], value, 0.8f);
706 -        }
707 -    }
708 -
709      // ポーズの設定
710      if (_pose != NULL)
711      {
712 @@ -626,3 +584,37 @@ Csm::Rendering::CubismOffscreenFrame_Ope
713  {
714      return _renderBuffer;
715  }
716 +
717 +void LAppModel::SetFacialLandmarkDetector(FacialLandmarkDetector *detector)
718 +{
719 +    _detector = detector;
720 +}
721 +
722 +Csm::csmString LAppModel::_(std::string s)
723 +{
724 +    std::string ans;
725 +    if (_useOldParamId)
726 +    {
727 +        if (s == "ParamTere")
728 +        {
729 +            ans = "PARAM_CHEEK";
730 +        }
731 +        else
732 +        {
733 +            for (size_t i = 0; i < s.size(); i++)
734 +            {
735 +                if (std::isupper(s[i]) && i != 0)
736 +                {
737 +                    ans += '_';
738 +                }
739 +                ans += std::toupper(s[i]);
740 +            }
741 +        }
742 +    }
743 +    else
744 +    {
745 +        ans = s;
746 +    }
747 +    return csmString(ans.c_str());
748 +}
749 +
750 diff -pruN --exclude build ./demo_clean/src/LAppModel.hpp ./demo_dev/src/LAppModel.hpp
751 --- ./demo_clean/src/LAppModel.hpp      2020-01-30 05:45:00.000000000 +0000
752 +++ ./demo_dev/src/LAppModel.hpp        2021-01-02 12:04:43.079607236 +0000
753 @@ -13,6 +13,7 @@
754  #include <Type/csmRectF.hpp>
755  #include <Rendering/OpenGL/CubismOffscreenSurface_OpenGLES2.hpp>
756  
757 +#include "facial_landmark_detector.h"
758  
759  /**
760   * @brief ユーザーが実際に使用するモデルの実装クラス<br>
761 @@ -24,8 +25,11 @@ class LAppModel : public Csm::CubismUser
762  public:
763      /**
764       * @brief コンストラクタ
765 +     *
766 +     * @param[in] useOldParamId : If true, translate new (Cubism 3+)
767 +     *                            parameter IDs to old (Cubism 2.1)  ones
768       */
769 -    LAppModel();
770 +    LAppModel(bool useOldParamId);
771  
772      /**
773       * @brief デストラクタ
774 @@ -113,6 +117,13 @@ public:
775       */
776      Csm::Rendering::CubismOffscreenFrame_OpenGLES2& GetRenderBuffer();
777  
778 +    /**
779 +     * @brief Set the pointer to the FacialLandmarkDetector instance
780 +     *
781 +     * @param[in] detector : Pointer to FacialLandmarkDetector instance
782 +     */
783 +    void SetFacialLandmarkDetector(FacialLandmarkDetector *detector);
784 +
785  protected:
786      /**
787       *  @brief  モデルを描画する処理。モデルを描画する空間のView-Projection行列を渡す。
788 @@ -166,6 +177,17 @@ private:
789      */
790      void ReleaseExpressions();
791  
792 +    /**
793 +     * @brief Translate new (Cubism 3+) parameter IDs to old (Cubism 2.1) ones
794 +     *
795 +     * @param[in] s : New parameter ID
796 +     *
797 +     * @return Old parameter ID
798 +     */
799 +    Csm::csmString _(std::string s);
800 +
801 +    bool _useOldParamId;
802 +
803      Csm::ICubismModelSetting* _modelSetting; ///< モデルセッティング情報
804      Csm::csmString _modelHomeDir; ///< モデルセッティングが置かれたディレクトリ
805      Csm::csmFloat32 _userTimeSeconds; ///< デルタ時間の積算値[秒]
806 @@ -183,6 +205,8 @@ private:
807      const Csm::CubismId* _idParamEyeBallY; ///< パラメータID: ParamEyeBallXY
808  
809      Csm::Rendering::CubismOffscreenFrame_OpenGLES2 _renderBuffer;   ///< フレームバッファ以外の描画先
810 +
811 +    FacialLandmarkDetector *_detector;
812  };
813  
814  
815 diff -pruN --exclude build ./demo_clean/src/LAppPal.cpp ./demo_dev/src/LAppPal.cpp
816 --- ./demo_clean/src/LAppPal.cpp        2020-01-30 05:45:00.000000000 +0000
817 +++ ./demo_dev/src/LAppPal.cpp  2020-10-02 02:10:49.202928000 +0100
818 @@ -6,6 +6,7 @@
819   */
820  
821  #include "LAppPal.hpp"
822 +#include <stdexcept>
823  #include <stdio.h>
824  #include <stdlib.h>
825  #include <stdarg.h>
826 @@ -45,10 +46,7 @@ csmByte* LAppPal::LoadFileAsBytes(const
827      file.open(path, std::ios::in | std::ios::binary);
828      if (!file.is_open())
829      {
830 -        if (DebugLogEnable)
831 -        {
832 -            PrintLog("file open error");
833 -        }
834 +        throw std::runtime_error("Failed to open file " + filePath);
835          return NULL;
836      }
837      file.read(buf, size);
838 diff -pruN --exclude build ./demo_clean/src/LAppTextureManager.cpp ./demo_dev/src/LAppTextureManager.cpp
839 --- ./demo_clean/src/LAppTextureManager.cpp     2020-01-30 05:45:00.000000000 +0000
840 +++ ./demo_dev/src/LAppTextureManager.cpp       2020-10-02 02:10:49.202928000 +0100
841 @@ -96,6 +96,46 @@ LAppTextureManager::TextureInfo* LAppTex
842  
843  }
844  
845 +LAppTextureManager::TextureInfo* LAppTextureManager::CreateTextureFromColor(
846 +    uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha
847 +)
848 +{
849 +    int width = 8, height = 8;
850 +
851 +    uint8_t pixels[height][width][4];
852 +    for (std::size_t h = 0; h < height; h++)
853 +    {
854 +        for (std::size_t w = 0; w < width; w++)
855 +        {
856 +            pixels[h][w][0] = red;
857 +            pixels[h][w][1] = green;
858 +            pixels[h][w][2] = blue;
859 +            pixels[h][w][3] = alpha;
860 +        }
861 +    }
862 +
863 +    GLuint textureId;
864 +    glGenTextures(1, &textureId);
865 +    glBindTexture(GL_TEXTURE_2D, textureId);
866 +    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
867 +
868 +    glGenerateMipmap(GL_TEXTURE_2D);
869 +    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
870 +    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
871 +    glBindTexture(GL_TEXTURE_2D, 0);
872 +
873 +
874 +    LAppTextureManager::TextureInfo* textureInfo = new LAppTextureManager::TextureInfo();
875 +    textureInfo->fileName = "";
876 +    textureInfo->width = width;
877 +    textureInfo->height = height;
878 +    textureInfo->id = textureId;
879 +
880 +    _textures.PushBack(textureInfo);
881 +
882 +    return textureInfo;
883 +}
884 +
885  void LAppTextureManager::ReleaseTextures()
886  {
887      for (Csm::csmUint32 i = 0; i < _textures.GetSize(); i++)
888 diff -pruN --exclude build ./demo_clean/src/LAppTextureManager.hpp ./demo_dev/src/LAppTextureManager.hpp
889 --- ./demo_clean/src/LAppTextureManager.hpp     2020-01-30 05:45:00.000000000 +0000
890 +++ ./demo_dev/src/LAppTextureManager.hpp       2020-10-02 02:10:49.202928000 +0100
891 @@ -72,6 +72,8 @@ public:
892      */
893      TextureInfo* CreateTextureFromPngFile(std::string fileName);
894  
895 +    TextureInfo *CreateTextureFromColor(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha = 255);
896 +
897      /**
898      * @brief 画像の解放
899      *
900 diff -pruN --exclude build ./demo_clean/src/LAppView.cpp ./demo_dev/src/LAppView.cpp
901 --- ./demo_clean/src/LAppView.cpp       2020-01-30 05:45:00.000000000 +0000
902 +++ ./demo_dev/src/LAppView.cpp 2020-10-02 02:10:49.202928000 +0100
903 @@ -13,7 +13,6 @@
904  #include "LAppLive2DManager.hpp"
905  #include "LAppTextureManager.hpp"
906  #include "LAppDefine.hpp"
907 -#include "TouchManager.hpp"
908  #include "LAppSprite.hpp"
909  #include "LAppModel.hpp"
910  
911 @@ -26,8 +25,6 @@ using namespace LAppDefine;
912  LAppView::LAppView():
913      _programId(0),
914      _back(NULL),
915 -    _gear(NULL),
916 -    _power(NULL),
917      _renderSprite(NULL),
918      _renderTarget(SelectTarget_None)
919  {
920 @@ -35,8 +32,6 @@ LAppView::LAppView():
921      _clearColor[1] = 1.0f;
922      _clearColor[2] = 1.0f;
923      _clearColor[3] = 0.0f;
924 -    // タッチ関係のイベント管理
925 -    _touchManager = new TouchManager();
926  
927      // デバイス座標からスクリーン座標に変換するための
928      _deviceToScreen = new CubismMatrix44();
929 @@ -52,10 +47,7 @@ LAppView::~LAppView()
930  
931      delete _viewMatrix;
932      delete _deviceToScreen;
933 -    delete _touchManager;
934      delete _back;
935 -    delete _gear;
936 -    delete _power;
937  }
938  
939  void LAppView::Initialize()
940 @@ -97,9 +89,6 @@ void LAppView::Initialize()
941  void LAppView::Render()
942  {
943      _back->Render();
944 -    _gear->Render();
945 -    _power->Render();
946 -
947  
948      LAppLive2DManager* Live2DManager = LAppLive2DManager::GetInstance();
949  
950 @@ -139,35 +128,17 @@ void LAppView::InitializeSprite()
951      glfwGetWindowSize(LAppDelegate::GetInstance()->GetWindow(), &width, &height);
952  
953      LAppTextureManager* textureManager = LAppDelegate::GetInstance()->GetTextureManager();
954 -    const string resourcesPath = LAppDelegate::GetInstance()->GetRootDirectory() + ResourcesPath;
955  
956 -    string imageName = BackImageName;
957 -    LAppTextureManager::TextureInfo* backgroundTexture = textureManager->CreateTextureFromPngFile(resourcesPath + imageName);
958 +
959 +    LAppTextureManager::TextureInfo* backgroundTexture =
960 +        textureManager->CreateTextureFromColor(0, 255, 0);
961  
962      float x = width * 0.5f;
963      float y = height * 0.5f;
964 -    float fWidth = static_cast<float>(backgroundTexture->width * 2.0f);
965 -    float fHeight = static_cast<float>(height) * 0.95f;
966 +    float fWidth = static_cast<float>(width);
967 +    float fHeight = static_cast<float>(height);
968      _back = new LAppSprite(x, y, fWidth, fHeight, backgroundTexture->id, _programId);
969  
970 -    imageName = GearImageName;
971 -    LAppTextureManager::TextureInfo* gearTexture = textureManager->CreateTextureFromPngFile(resourcesPath + imageName);
972 -
973 -    x = static_cast<float>(width - gearTexture->width * 0.5f);
974 -    y = static_cast<float>(height - gearTexture->height * 0.5f);
975 -    fWidth = static_cast<float>(gearTexture->width);
976 -    fHeight = static_cast<float>(gearTexture->height);
977 -    _gear = new LAppSprite(x, y, fWidth, fHeight, gearTexture->id, _programId);
978 -
979 -    imageName = PowerImageName;
980 -    LAppTextureManager::TextureInfo* powerTexture = textureManager->CreateTextureFromPngFile(resourcesPath + imageName);
981 -
982 -    x = static_cast<float>(width - powerTexture->width * 0.5f);
983 -    y = static_cast<float>(powerTexture->height * 0.5f);
984 -    fWidth = static_cast<float>(powerTexture->width);
985 -    fHeight = static_cast<float>(powerTexture->height);
986 -    _power = new LAppSprite(x, y, fWidth, fHeight, powerTexture->id, _programId);
987 -
988      // 画面全体を覆うサイズ
989      x = width * 0.5f;
990      y = height * 0.5f;
991 @@ -175,52 +146,6 @@ void LAppView::InitializeSprite()
992  
993  }
994  
995 -void LAppView::OnTouchesBegan(float px, float py) const
996 -{
997 -    _touchManager->TouchesBegan(px, py);
998 -}
999 -
1000 -void LAppView::OnTouchesMoved(float px, float py) const
1001 -{
1002 -    float viewX = this->TransformViewX(_touchManager->GetX());
1003 -    float viewY = this->TransformViewY(_touchManager->GetY());
1004 -
1005 -    _touchManager->TouchesMoved(px, py);
1006 -
1007 -    LAppLive2DManager* Live2DManager = LAppLive2DManager::GetInstance();
1008 -    Live2DManager->OnDrag(viewX, viewY);
1009 -}
1010 -
1011 -void LAppView::OnTouchesEnded(float px, float py) const
1012 -{
1013 -    // タッチ終了
1014 -    LAppLive2DManager* live2DManager = LAppLive2DManager::GetInstance();
1015 -    live2DManager->OnDrag(0.0f, 0.0f);
1016 -    {
1017 -
1018 -        // シングルタップ
1019 -        float x = _deviceToScreen->TransformX(_touchManager->GetX()); // 論理座標変換した座標を取得。
1020 -        float y = _deviceToScreen->TransformY(_touchManager->GetY()); // 論理座標変換した座標を取得。
1021 -        if (DebugTouchLogEnable)
1022 -        {
1023 -            LAppPal::PrintLog("[APP]touchesEnded x:%.2f y:%.2f", x, y);
1024 -        }
1025 -        live2DManager->OnTap(x, y);
1026 -
1027 -        // 歯車にタップしたか
1028 -        if (_gear->IsHit(px, py))
1029 -        {
1030 -            live2DManager->NextScene();
1031 -        }
1032 -
1033 -        // 電源ボタンにタップしたか
1034 -        if (_power->IsHit(px, py))
1035 -        {
1036 -            LAppDelegate::GetInstance()->AppEnd();
1037 -        }
1038 -    }
1039 -}
1040 -
1041  float LAppView::TransformViewX(float deviceX) const
1042  {
1043      float screenX = _deviceToScreen->TransformX(deviceX); // 論理座標変換した座標を取得。
1044 @@ -362,32 +287,4 @@ void LAppView::ResizeSprite()
1045              _back->ResetRect(x, y, fWidth, fHeight);
1046          }
1047      }
1048 -
1049 -    if (_power)
1050 -    {
1051 -        GLuint id = _power->GetTextureId();
1052 -        LAppTextureManager::TextureInfo* texInfo = textureManager->GetTextureInfoById(id);
1053 -        if (texInfo)
1054 -        {
1055 -            x = static_cast<float>(width - texInfo->width * 0.5f);
1056 -            y = static_cast<float>(texInfo->height * 0.5f);
1057 -            fWidth = static_cast<float>(texInfo->width);
1058 -            fHeight = static_cast<float>(texInfo->height);
1059 -            _power->ResetRect(x, y, fWidth, fHeight);
1060 -        }
1061 -    }
1062 -
1063 -    if (_gear)
1064 -    {
1065 -        GLuint id = _gear->GetTextureId();
1066 -        LAppTextureManager::TextureInfo* texInfo = textureManager->GetTextureInfoById(id);
1067 -        if (texInfo)
1068 -        {
1069 -            x = static_cast<float>(width - texInfo->width * 0.5f);
1070 -            y = static_cast<float>(height - texInfo->height * 0.5f);
1071 -            fWidth = static_cast<float>(texInfo->width);
1072 -            fHeight = static_cast<float>(texInfo->height);
1073 -            _gear->ResetRect(x, y, fWidth, fHeight);
1074 -        }
1075 -    }
1076  }
1077 diff -pruN --exclude build ./demo_clean/src/LAppView.hpp ./demo_dev/src/LAppView.hpp
1078 --- ./demo_clean/src/LAppView.hpp       2020-01-30 05:45:00.000000000 +0000
1079 +++ ./demo_dev/src/LAppView.hpp 2020-10-02 02:10:49.202928000 +0100
1080 @@ -14,7 +14,6 @@
1081  #include "CubismFramework.hpp"
1082  #include <Rendering/OpenGL/CubismOffscreenSurface_OpenGLES2.hpp>
1083  
1084 -class TouchManager;
1085  class LAppSprite;
1086  class LAppModel;
1087  
1088 @@ -66,30 +65,6 @@ public:
1089      void ResizeSprite();
1090  
1091      /**
1092 -    * @brief タッチされたときに呼ばれる。
1093 -    *
1094 -    * @param[in]       pointX            スクリーンX座標
1095 -    * @param[in]       pointY            スクリーンY座標
1096 -    */
1097 -    void OnTouchesBegan(float pointX, float pointY) const;
1098 -
1099 -    /**
1100 -    * @brief タッチしているときにポインタが動いたら呼ばれる。
1101 -    *
1102 -    * @param[in]       pointX            スクリーンX座標
1103 -    * @param[in]       pointY            スクリーンY座標
1104 -    */
1105 -    void OnTouchesMoved(float pointX, float pointY) const;
1106 -
1107 -    /**
1108 -    * @brief タッチが終了したら呼ばれる。
1109 -    *
1110 -    * @param[in]       pointX            スクリーンX座標
1111 -    * @param[in]       pointY            スクリーンY座標
1112 -    */
1113 -    void OnTouchesEnded(float pointX, float pointY) const;
1114 -
1115 -    /**
1116      * @brief X座標をView座標に変換する。
1117      *
1118      * @param[in]       deviceX            デバイスX座標
1119 @@ -147,13 +122,10 @@ public:
1120      void SetRenderTargetClearColor(float r, float g, float b);
1121  
1122  private:
1123 -    TouchManager* _touchManager;                 ///< タッチマネージャー
1124      Csm::CubismMatrix44* _deviceToScreen;    ///< デバイスからスクリーンへの行列
1125      Csm::CubismViewMatrix* _viewMatrix;      ///< viewMatrix
1126      GLuint _programId;                       ///< シェーダID
1127      LAppSprite* _back;                       ///< 背景画像
1128 -    LAppSprite* _gear;                       ///< ギア画像
1129 -    LAppSprite* _power;                      ///< 電源画像
1130  
1131      // レンダリング先を別ターゲットにする方式の場合に使用
1132      LAppSprite* _renderSprite;                                  ///< モードによっては_renderBufferのテクスチャを描画
1133 diff -pruN --exclude build ./demo_clean/src/main.cpp ./demo_dev/src/main.cpp
1134 --- ./demo_clean/src/main.cpp   2020-01-30 05:45:00.000000000 +0000
1135 +++ ./demo_dev/src/main.cpp     2021-01-02 12:08:38.440444044 +0000
1136 @@ -5,18 +5,162 @@
1137   * that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html.
1138   */
1139  
1140 +#include <thread>
1141 +#include <stdexcept>
1142 +#include <sstream>
1143 +
1144 +#ifdef __cpp_lib_filesystem
1145 +#include <filesystem>
1146 +namespace fs = std::filesystem;
1147 +#else
1148 +#include <experimental/filesystem>
1149 +namespace fs = std::experimental::filesystem;
1150 +#endif
1151 +
1152 +
1153  #include "LAppDelegate.hpp"
1154 +#include "LAppLive2DManager.hpp"
1155 +#include "facial_landmark_detector.h"
1156 +
1157 +struct CmdArgs
1158 +{
1159 +    int windowWidth;
1160 +    int windowHeight;
1161 +    std::string windowTitle;
1162 +    std::string rootDir;
1163 +    float scaleFactor;
1164 +    float translateX;
1165 +    float translateY;
1166 +    std::string modelName;
1167 +    bool oldId; // If true, translate new (Cubism 3+) parameter IDs to old (Cubism 2.1) IDs
1168 +    std::string cfgPath; // Path to config file for FacialLandmarkDetector
1169 +};
1170 +
1171 +CmdArgs parseArgv(int argc, char *argv[])
1172 +{
1173 +    // I think the command-line args are simple enough to not justify using a library...
1174 +    CmdArgs cmdArgs;
1175 +    // Set default values
1176 +    cmdArgs.windowWidth = 600;
1177 +    cmdArgs.windowHeight = 600;
1178 +    cmdArgs.windowTitle = "FacialLandmarksForCubism example";
1179 +    cmdArgs.rootDir = fs::current_path();
1180 +    cmdArgs.scaleFactor = 8.0f;
1181 +    cmdArgs.translateX = 0.0f;
1182 +    cmdArgs.translateY = -2.8f;
1183 +    cmdArgs.modelName = "Haru";
1184 +    cmdArgs.oldId = false;
1185 +    cmdArgs.cfgPath = "";
1186 +
1187 +    int i = 1;
1188 +    while (i < argc)
1189 +    {
1190 +        std::string arg = argv[i];
1191 +        std::stringstream ss;
1192 +
1193 +        if (arg == "--window-width" || arg == "-W") // capital W for consistency with height
1194 +        {
1195 +            ss << argv[i + 1];
1196 +            if (!(ss >> cmdArgs.windowWidth))
1197 +            {
1198 +                throw std::runtime_error("Invalid argument for window width");
1199 +            }
1200 +        }
1201 +        else if (arg == "--window-height" || arg == "-H") // avoiding "-h", typically for help
1202 +        {
1203 +            ss << argv[i + 1];
1204 +            if (!(ss >> cmdArgs.windowHeight))
1205 +            {
1206 +                throw std::runtime_error("Invalid argument for window height");
1207 +            }
1208 +        }
1209 +        else if (arg == "--window-title" || arg == "-t")
1210 +        {
1211 +            cmdArgs.windowTitle = argv[i + 1];
1212 +        }
1213 +        else if (arg == "--root-dir" || arg == "-d")
1214 +        {
1215 +            cmdArgs.rootDir = argv[i + 1];
1216 +        }
1217 +        else if (arg == "--scale-factor" || arg == "-f")
1218 +        {
1219 +            ss << argv[i + 1];
1220 +            if (!(ss >> cmdArgs.scaleFactor))
1221 +            {
1222 +                throw std::runtime_error("Invalid argument for scale factor");
1223 +            }
1224 +        }
1225 +        else if (arg == "--translate-x" || arg == "-x")
1226 +        {
1227 +            ss << argv[i + 1];
1228 +            if (!(ss >> cmdArgs.translateX))
1229 +            {
1230 +                throw std::runtime_error("Invalid argument for translate X");
1231 +            }
1232 +        }
1233 +        else if (arg == "--translate-y" || arg == "-y")
1234 +        {
1235 +            ss << argv[i + 1];
1236 +            if (!(ss >> cmdArgs.translateY))
1237 +            {
1238 +                throw std::runtime_error("Invalid argument for translate Y");
1239 +            }
1240 +        }
1241 +        else if (arg == "--model" || arg == "-m")
1242 +        {
1243 +            cmdArgs.modelName = argv[i + 1];
1244 +        }
1245 +        else if (arg == "--config" || arg == "-c")
1246 +        {
1247 +            cmdArgs.cfgPath = argv[i + 1];
1248 +        }
1249 +        else if (arg == "--old-param-id" || arg == "-o")
1250 +        {
1251 +            cmdArgs.oldId = (argv[i + 1][0] == '1');
1252 +        }
1253 +        else
1254 +        {
1255 +            throw std::runtime_error("Unrecognized argument: " + arg);
1256 +        }
1257 +
1258 +        i += 2;
1259 +    }
1260 +
1261 +    return cmdArgs;
1262 +}
1263  
1264  int main(int argc, char* argv[])
1265  {
1266 -    // create the application instance
1267 -    if (LAppDelegate::GetInstance()->Initialize() == GL_FALSE)
1268 +    auto cmdArgs = parseArgv(argc, argv);
1269 +
1270 +    LAppDelegate *delegate = LAppDelegate::GetInstance();
1271 +
1272 +    if (!delegate->Initialize(cmdArgs.windowWidth,
1273 +                              cmdArgs.windowHeight,
1274 +                              cmdArgs.windowTitle.c_str()))
1275      {
1276 -        return 1;
1277 +        throw std::runtime_error("Unable to initialize LAppDelegate");
1278      }
1279  
1280 -    LAppDelegate::GetInstance()->Run();
1281 +    delegate->SetRootDirectory(cmdArgs.rootDir);
1282 +
1283 +    FacialLandmarkDetector detector(cmdArgs.cfgPath);
1284 +
1285 +    std::thread detectorThread(&FacialLandmarkDetector::mainLoop,
1286 +                               &detector);
1287 +
1288 +    LAppLive2DManager *manager = LAppLive2DManager::GetInstance();
1289 +    manager->SetModel(cmdArgs.modelName, cmdArgs.oldId);
1290 +
1291 +    manager->SetProjectionScaleTranslate(cmdArgs.scaleFactor,
1292 +                                         cmdArgs.translateX,
1293 +                                         cmdArgs.translateY);
1294 +    manager->SetFacialLandmarkDetector(&detector);
1295 +
1296 +    delegate->Run();
1297 +
1298 +    detector.stop();
1299 +    detectorThread.join();
1300  
1301      return 0;
1302  }
1303 -