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