1 diff -pruN --exclude build ./demo_clean/CMakeLists.txt ./demo_dev/CMakeLists.txt
2 --- ./demo_clean/CMakeLists.txt 2021-01-13 16:58:08.359828681 +0000
3 +++ ./demo_dev/CMakeLists.txt 2021-01-13 17:22:01.166356692 +0000
5 -cmake_minimum_required(VERSION 3.16)
6 +cmake_minimum_required(VERSION 3.13)
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.1)
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)
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)
25 @@ -42,7 +42,7 @@ add_library(Live2DCubismCore STATIC IMPO
27 set_target_properties(Live2DCubismCore
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
34 @@ -64,6 +64,11 @@ target_link_libraries(Framework Live2DCu
35 # Find opengl libraries.
36 find_package(OpenGL REQUIRED)
38 +# Add MouseTrackerForCubism
39 +find_package(PkgConfig)
40 +pkg_check_modules(GTKMM gtkmm-3.0)
41 +add_subdirectory(../.. MouseTrackerForCubism_build)
43 # Make executable app.
44 add_executable(${APP_NAME})
46 @@ -73,9 +78,20 @@ target_link_libraries(${APP_NAME}
50 + MouseTrackerForCubism
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})
57 +# Copy GUI to build directory
63 + copy ${CMAKE_CURRENT_SOURCE_DIR}/../../src/gui.glade $<TARGET_FILE_DIR:${APP_NAME}>/gui.glade
66 # Copy resource directory to build directory.
68 diff -pruN --exclude build ./demo_clean/scripts/make_gcc ./demo_dev/scripts/make_gcc
69 --- ./demo_clean/scripts/make_gcc 2020-10-01 22:47:25.854827921 +0100
70 +++ ./demo_dev/scripts/make_gcc 2021-01-01 11:34:25.583684883 +0000
71 @@ -10,4 +10,4 @@ BUILD_PATH=$SCRIPT_PATH/../build/make_gc
72 cmake -S "$CMAKE_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 2020-10-01 22:47:25.850827994 +0100
79 +++ ./demo_dev/src/CMakeLists.txt 2020-10-01 22:47:24.842846271 +0100
80 @@ -19,6 +19,4 @@ target_sources(${APP_NAME}
81 ${CMAKE_CURRENT_SOURCE_DIR}/LAppView.cpp
82 ${CMAKE_CURRENT_SOURCE_DIR}/LAppView.hpp
83 ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp
84 - ${CMAKE_CURRENT_SOURCE_DIR}/TouchManager.cpp
85 - ${CMAKE_CURRENT_SOURCE_DIR}/TouchManager.hpp
87 diff -pruN --exclude build ./demo_clean/src/LAppDefine.cpp ./demo_dev/src/LAppDefine.cpp
88 --- ./demo_clean/src/LAppDefine.cpp 2020-10-01 22:47:25.850827994 +0100
89 +++ ./demo_dev/src/LAppDefine.cpp 2020-10-18 04:59:13.238452938 +0100
90 @@ -61,11 +61,11 @@ namespace LAppDefine {
91 const csmInt32 PriorityForce = 3;
94 - const csmBool DebugLogEnable = true;
95 + const csmBool DebugLogEnable = false;
96 const csmBool DebugTouchLogEnable = false;
98 // Frameworkから出力するログのレベル設定
99 - const CubismFramework::Option::LogLevel CubismLoggingLevel = CubismFramework::Option::LogLevel_Verbose;
100 + const CubismFramework::Option::LogLevel CubismLoggingLevel = CubismFramework::Option::LogLevel_Warning;
102 // デフォルトのレンダーターゲットサイズ
103 const csmInt32 RenderTargetWidth = 1900;
104 diff -pruN --exclude build ./demo_clean/src/LAppDelegate.cpp ./demo_dev/src/LAppDelegate.cpp
105 --- ./demo_clean/src/LAppDelegate.cpp 2020-10-01 22:47:25.850827994 +0100
106 +++ ./demo_dev/src/LAppDelegate.cpp 2020-10-01 22:47:24.698848890 +0100
107 @@ -45,7 +45,8 @@ void LAppDelegate::ReleaseInstance()
111 -bool LAppDelegate::Initialize()
112 +bool LAppDelegate::Initialize(int initWindowWidth, int initWindowHeight,
113 + const char *windowTitle)
117 @@ -63,7 +64,13 @@ bool LAppDelegate::Initialize()
121 - _window = glfwCreateWindow(RenderTargetWidth, RenderTargetHeight, "SAMPLE", NULL, NULL);
122 + _window = glfwCreateWindow(
123 + initWindowWidth ? initWindowWidth : RenderTargetWidth,
124 + initWindowHeight ? initWindowHeight : RenderTargetHeight,
125 + windowTitle ? windowTitle : "SAMPLE",
132 @@ -95,10 +102,6 @@ bool LAppDelegate::Initialize()
134 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
137 - glfwSetMouseButtonCallback(_window, EventHandler::OnMouseCallBack);
138 - glfwSetCursorPosCallback(_window, EventHandler::OnMouseCallBack);
142 glfwGetWindowSize(LAppDelegate::GetInstance()->GetWindow(), &width, &height);
143 @@ -111,8 +114,6 @@ bool LAppDelegate::Initialize()
147 - SetRootDirectory();
150 LAppLive2DManager::GetInstance();
152 @@ -214,49 +215,6 @@ void LAppDelegate::InitializeCubism()
153 LAppPal::UpdateTime();
156 -void LAppDelegate::OnMouseCallBack(GLFWwindow* window, int button, int action, int modify)
162 - if (GLFW_MOUSE_BUTTON_LEFT != button)
167 - if (GLFW_PRESS == action)
170 - _view->OnTouchesBegan(_mouseX, _mouseY);
172 - else if (GLFW_RELEASE == action)
177 - _view->OnTouchesEnded(_mouseX, _mouseY);
182 -void LAppDelegate::OnMouseCallBack(GLFWwindow* window, double x, double y)
184 - _mouseX = static_cast<float>(x);
185 - _mouseY = static_cast<float>(y);
196 - _view->OnTouchesMoved(_mouseX, _mouseY);
199 GLuint LAppDelegate::CreateShader()
202 @@ -299,29 +257,9 @@ GLuint LAppDelegate::CreateShader()
206 -void LAppDelegate::SetRootDirectory()
207 +void LAppDelegate::SetRootDirectory(std::string rootDir)
210 - ssize_t len = readlink("/proc/self/exe", path, 1024 - 1);
217 - std::string pathString(path);
219 - pathString = pathString.substr(0, pathString.rfind("Demo"));
220 - Csm::csmVector<string> splitStrings = this->Split(pathString, '/');
222 - this->_rootDirectory = "";
224 - for(int i = 0; i < splitStrings.GetSize(); i++)
226 - this->_rootDirectory = this->_rootDirectory + "/" +splitStrings[i];
229 - this->_rootDirectory += "/";
230 + this->_rootDirectory = rootDir + "/";
233 Csm::csmVector<string> LAppDelegate::Split(const std::string& baseString, char delimiter)
234 diff -pruN --exclude build ./demo_clean/src/LAppDelegate.hpp ./demo_dev/src/LAppDelegate.hpp
235 --- ./demo_clean/src/LAppDelegate.hpp 2020-10-01 22:47:25.850827994 +0100
236 +++ ./demo_dev/src/LAppDelegate.hpp 2020-10-01 22:47:24.842846271 +0100
237 @@ -40,7 +40,8 @@ public:
239 * @brief APPに必要なものを初期化する。
242 + bool Initialize(int initWindowWidth = 0, int initWindowHeight = 0,
243 + const char *windowTitle = "SAMPLE");
247 @@ -53,25 +54,6 @@ public:
251 - * @brief OpenGL用 glfwSetMouseButtonCallback用関数。
253 - * @param[in] window コールバックを呼んだWindow情報
254 - * @param[in] button ボタン種類
255 - * @param[in] action 実行結果
256 - * @param[in] modify
258 - void OnMouseCallBack(GLFWwindow* window, int button, int action, int modify);
261 - * @brief OpenGL用 glfwSetCursorPosCallback用関数。
263 - * @param[in] window コールバックを呼んだWindow情報
267 - void OnMouseCallBack(GLFWwindow* window, double x, double y);
272 GLuint CreateShader();
273 @@ -98,8 +80,10 @@ public:
276 * @brief ルートディレクトリを設定する。
278 + * @param[in] rootDir : The root directory to set to.
280 - void SetRootDirectory();
281 + void SetRootDirectory(std::string rootDir);
284 * @brief ルートディレクトリを取得する。
285 @@ -146,24 +130,3 @@ private:
286 int _windowWidth; ///< Initialize関数で設定したウィンドウ幅
287 int _windowHeight; ///< Initialize関数で設定したウィンドウ高さ
294 - * @brief glfwSetMouseButtonCallback用コールバック関数。
296 - static void OnMouseCallBack(GLFWwindow* window, int button, int action, int modify)
298 - LAppDelegate::GetInstance()->OnMouseCallBack(window, button, action, modify);
302 - * @brief glfwSetCursorPosCallback用コールバック関数。
304 - static void OnMouseCallBack(GLFWwindow* window, double x, double y)
306 - LAppDelegate::GetInstance()->OnMouseCallBack(window, x, y);
310 diff -pruN --exclude build ./demo_clean/src/LAppLive2DManager.cpp ./demo_dev/src/LAppLive2DManager.cpp
311 --- ./demo_clean/src/LAppLive2DManager.cpp 2020-10-01 22:47:25.850827994 +0100
312 +++ ./demo_dev/src/LAppLive2DManager.cpp 2020-10-02 02:00:49.961556700 +0100
313 @@ -52,9 +52,10 @@ void LAppLive2DManager::ReleaseInstance(
315 LAppLive2DManager::LAppLive2DManager()
318 + , _projScaleFactor(1.0f)
319 + , _translateX(0.0f)
320 + , _translateY(0.0f)
322 - ChangeScene(_sceneIndex);
325 LAppLive2DManager::~LAppLive2DManager()
326 @@ -98,26 +99,6 @@ void LAppLive2DManager::OnTap(csmFloat32
328 LAppPal::PrintLog("[APP]tap point: {x:%.2f y:%.2f}", x, y);
331 - for (csmUint32 i = 0; i < _models.GetSize(); i++)
333 - if (_models[i]->HitTest(HitAreaNameHead, x, y))
335 - if (DebugLogEnable)
337 - LAppPal::PrintLog("[APP]hit area: [%s]", HitAreaNameHead);
339 - _models[i]->SetRandomExpression();
341 - else if (_models[i]->HitTest(HitAreaNameBody, x, y))
343 - if (DebugLogEnable)
345 - LAppPal::PrintLog("[APP]hit area: [%s]", HitAreaNameBody);
347 - _models[i]->StartRandomMotion(MotionGroupTapBody, PriorityNormal, FinishedMotion);
352 void LAppLive2DManager::OnUpdate() const
353 @@ -125,7 +106,9 @@ void LAppLive2DManager::OnUpdate() const
354 CubismMatrix44 projection;
356 glfwGetWindowSize(LAppDelegate::GetInstance()->GetWindow(), &width, &height);
357 - projection.Scale(1.0f, static_cast<float>(width) / static_cast<float>(height));
358 + projection.Scale(_projScaleFactor,
359 + _projScaleFactor * static_cast<float>(width) / static_cast<float>(height));
360 + projection.Translate(_translateX, _translateY);
362 if (_viewMatrix != NULL)
364 @@ -148,26 +131,10 @@ void LAppLive2DManager::OnUpdate() const
368 -void LAppLive2DManager::NextScene()
370 - csmInt32 no = (_sceneIndex + 1) % ModelDirSize;
374 -void LAppLive2DManager::ChangeScene(Csm::csmInt32 index)
375 +void LAppLive2DManager::SetModel(std::string modelName)
377 - _sceneIndex = index;
378 - if (DebugLogEnable)
380 - LAppPal::PrintLog("[APP]model index: %d", _sceneIndex);
383 - // ModelDir[]に保持したディレクトリ名から
384 - // model3.jsonのパスを決定する.
385 - // ディレクトリ名とmodel3.jsonの名前を一致させておくこと.
386 - std::string model = ModelDir[index];
387 - std::string modelPath = LAppDelegate::GetInstance()->GetRootDirectory() + ResourcesPath + model + "/";
388 - std::string modelJsonName = ModelDir[index];
389 + std::string modelPath = LAppDelegate::GetInstance()->GetRootDirectory() + ResourcesPath + modelName + "/";
390 + std::string modelJsonName = modelName;
391 modelJsonName += ".model3.json";
394 @@ -215,3 +182,20 @@ csmUint32 LAppLive2DManager::GetModelNum
396 return _models.GetSize();
399 +void LAppLive2DManager::SetTracker(MouseCursorTracker *tracker)
401 + for (auto it = _models.Begin(); it != _models.End(); ++it)
403 + (*it)->SetTracker(tracker);
407 +void LAppLive2DManager::SetProjectionScaleTranslate(float scaleFactor,
411 + _projScaleFactor = scaleFactor;
412 + _translateX = translateX;
413 + _translateY = translateY;
415 diff -pruN --exclude build ./demo_clean/src/LAppLive2DManager.hpp ./demo_dev/src/LAppLive2DManager.hpp
416 --- ./demo_clean/src/LAppLive2DManager.hpp 2020-10-01 22:47:25.846828066 +0100
417 +++ ./demo_dev/src/LAppLive2DManager.hpp 2020-10-01 23:36:24.583055381 +0100
423 #include <CubismFramework.hpp>
424 #include <Math/CubismMatrix44.hpp>
425 #include <Type/csmVector.hpp>
429 +class MouseCursorTracker;
432 * @brief サンプルアプリケーションにおいてCubismModelを管理するクラス<br>
433 * モデル生成と破棄、タップイベントの処理、モデル切り替えを行う。
434 @@ -72,16 +75,12 @@ public:
435 void OnUpdate() const;
438 - * @brief 次のシーンに切り替える<br>
439 - * サンプルアプリケーションではモデルセットの切り替えを行う。
444 - * @brief シーンを切り替える<br>
445 - * サンプルアプリケーションではモデルセットの切り替えを行う。
447 - void ChangeScene(Csm::csmInt32 index);
448 + * @brief Set model data
450 + * @param[in] modelName : Name of model, should be the same for both
451 + * the directory and the model3.json file
453 + void SetModel(std::string modelName);
457 @@ -89,6 +88,24 @@ public:
459 Csm::csmUint32 GetModelNum() const;
462 + * @brief Set the pointer to the MouseCursorTracker instance
464 + * @param[in] tracker : Pointer to MouseCursorTracker instance
466 + void SetTracker(MouseCursorTracker *tracker);
469 + * @brief Set projection scale factor and translation parameters
471 + * @param[in] scaleFactor : Scale factor applied in both X and Y directions
472 + * @param[in] translateX : Translation in X direction
473 + * @param[in] translateY : Translation in Y direction
475 + void SetProjectionScaleTranslate(float scaleFactor,
482 @@ -102,5 +119,8 @@ private:
484 Csm::CubismMatrix44* _viewMatrix; ///< モデル描画に用いるView行列
485 Csm::csmVector<LAppModel*> _models; ///< モデルインスタンスのコンテナ
486 - Csm::csmInt32 _sceneIndex; ///< 表示するシーンのインデックス値
488 + float _projScaleFactor;
492 diff -pruN --exclude build ./demo_clean/src/LAppModel.cpp ./demo_dev/src/LAppModel.cpp
493 --- ./demo_clean/src/LAppModel.cpp 2020-10-01 22:47:25.850827994 +0100
494 +++ ./demo_dev/src/LAppModel.cpp 2020-10-18 09:26:08.998822685 +0100
496 #include "LAppTextureManager.hpp"
497 #include "LAppDelegate.hpp"
499 +#include "mouse_cursor_tracker.h"
503 using namespace Live2D::Cubism::Framework;
504 using namespace Live2D::Cubism::Framework::DefaultParameterId;
505 using namespace LAppDefine;
506 @@ -49,6 +53,7 @@ LAppModel::LAppModel()
508 , _modelSetting(NULL)
509 , _userTimeSeconds(0.0f)
510 + , _tracker(nullptr)
514 @@ -335,59 +340,110 @@ void LAppModel::Update()
515 const csmFloat32 deltaTimeSeconds = LAppPal::GetDeltaTime();
516 _userTimeSeconds += deltaTimeSeconds;
518 - _dragManager->Update(deltaTimeSeconds);
519 - _dragX = _dragManager->GetX();
520 - _dragY = _dragManager->GetY();
522 - // モーションによるパラメータ更新の有無
523 - csmBool motionUpdated = false;
525 - //-----------------------------------------------------------------
526 - _model->LoadParameters(); // 前回セーブされた状態をロード
527 - if (_motionManager->IsFinished())
529 - // モーションの再生がない場合、待機モーションの中からランダムで再生する
530 - StartRandomMotion(MotionGroupIdle, PriorityIdle);
535 - motionUpdated = _motionManager->UpdateMotion(_model, deltaTimeSeconds); // モーションを更新
537 - _model->SaveParameters(); // 状態を保存
538 - //-----------------------------------------------------------------
539 + auto idMan = CubismFramework::GetIdManager();
540 + auto params = _tracker->getParams();
543 - if (!motionUpdated)
545 - if (_eyeBlink != NULL)
546 + _model->LoadParameters(); // 前回セーブされた状態をロード
548 + int paramsMotionPriority = static_cast<int>(params.motionPriority);
550 + if (paramsMotionPriority != PriorityNone)
552 - // メインモーションの更新がないとき
553 - _eyeBlink->UpdateParameters(_model, deltaTimeSeconds); // 目パチ
554 + StartMotion(params.motionGroup.c_str(), params.motionNumber,
555 + paramsMotionPriority);
557 + else if (params.randomIdleMotion && _motionManager->IsFinished())
559 + // モーションの再生がない場合、待機モーションの中からランダムで再生する
560 + StartRandomMotion(MotionGroupIdle, PriorityIdle);
564 - if (_expressionManager != NULL)
566 - _expressionManager->UpdateMotion(_model, deltaTimeSeconds); // 表情でパラメータ更新(相対変化)
568 + // FIXME pose does not return to normal after motion
569 + // if we don't have randomIdleMotion set
572 + _motionManager->UpdateMotion(_model, deltaTimeSeconds); // モーションを更新
574 + _model->SaveParameters(); // 状態を保存
578 - _model->AddParameterValue(_idParamAngleX, _dragX * 30); // -30から30の値を加える
579 - _model->AddParameterValue(_idParamAngleY, _dragY * 30);
580 - _model->AddParameterValue(_idParamAngleZ, _dragX * _dragY * -30);
581 + if (params.expression != "")
583 + SetExpression(params.expression.c_str());
585 + if (_expressionManager != NULL)
587 + _expressionManager->UpdateMotion(_model, deltaTimeSeconds); // 表情でパラメータ更新(相対変化)
591 - _model->AddParameterValue(_idParamBodyAngleX, _dragX * 10); // -10から10の値を加える
592 + bool autoBlink = params.autoBlink && _eyeBlink;
593 + auto eyeLOpenIt = params.live2d.find("ParamEyeLOpen");
594 + auto eyeROpenIt = params.live2d.find("ParamEyeROpen");
597 - _model->AddParameterValue(_idParamEyeBallX, _dragX); // -1から1の値を加える
598 - _model->AddParameterValue(_idParamEyeBallY, _dragY);
601 + // Handle blink first
602 + _eyeBlink->UpdateParameters(_model, deltaTimeSeconds);
606 - if (_breath != NULL)
608 - _breath->UpdateParameters(_model, deltaTimeSeconds);
609 + if (eyeLOpenIt != params.live2d.end())
611 + // If value specified, override blinking
612 + _model->SetParameterValue(idMan->GetId("ParamEyeLOpen"),
613 + eyeLOpenIt->second);
615 + else if (!autoBlink)
617 + // If no value specified and no auto blink, set to 1
618 + _model->SetParameterValue(idMan->GetId("ParamEyeLOpen"), 1);
622 + if (eyeROpenIt != params.live2d.end())
624 + _model->SetParameterValue(idMan->GetId("ParamEyeROpen"),
625 + eyeROpenIt->second);
627 + else if (!autoBlink)
629 + _model->SetParameterValue(idMan->GetId("ParamEyeROpen"), 1);
633 + if (params.useLipSync && _lipSync)
635 + csmFloat32 value = params.lipSyncParam; // 0 to 1
637 + for (csmUint32 i = 0; i < _lipSyncIds.GetSize(); ++i)
639 + _model->AddParameterValue(_lipSyncIds[i], value, 0.8f);
644 + _model->SetParameterValue(idMan->GetId("ParamMouthOpenY"),
645 + params.live2d["ParamMouthOpenY"]);
648 + for (auto const &entry : params.live2d)
650 + std::string key = entry.first;
651 + double val = entry.second;
653 + if (key != "ParamEyeLOpen" && key != "ParamEyeROpen" &&
654 + key != "ParamMouthOpenY")
656 + _model->SetParameterValue(idMan->GetId(key.c_str()), val);
660 + if (params.autoBreath && _breath)
662 + // Note: _model->LoadParameters and SaveParameters is needed
663 + // before - see above.
664 + _breath->UpdateParameters(_model, deltaTimeSeconds);
669 @@ -396,17 +452,6 @@ void LAppModel::Update()
670 _physics->Evaluate(_model, deltaTimeSeconds);
676 - csmFloat32 value = 0; // リアルタイムでリップシンクを行う場合、システムから音量を取得して0〜1の範囲で値を入力します。
678 - for (csmUint32 i = 0; i < _lipSyncIds.GetSize(); ++i)
680 - _model->AddParameterValue(_lipSyncIds[i], value, 0.8f);
687 @@ -626,3 +671,14 @@ Csm::Rendering::CubismOffscreenFrame_Ope
689 return _renderBuffer;
692 +void LAppModel::SetTracker(MouseCursorTracker *tracker)
694 + _tracker = tracker;
697 +Csm::ICubismModelSetting* LAppModel::GetModelSetting(void) const
699 + return _modelSetting;
702 diff -pruN --exclude build ./demo_clean/src/LAppModel.hpp ./demo_dev/src/LAppModel.hpp
703 --- ./demo_clean/src/LAppModel.hpp 2020-10-01 22:47:25.850827994 +0100
704 +++ ./demo_dev/src/LAppModel.hpp 2020-10-18 03:04:52.142045751 +0100
706 #include <Type/csmRectF.hpp>
707 #include <Rendering/OpenGL/CubismOffscreenSurface_OpenGLES2.hpp>
709 +#include "mouse_cursor_tracker.h"
712 * @brief ユーザーが実際に使用するモデルの実装クラス<br>
713 @@ -113,6 +114,15 @@ public:
715 Csm::Rendering::CubismOffscreenFrame_OpenGLES2& GetRenderBuffer();
718 + * @brief Set the pointer to the MouseCursorTracker instance
720 + * @param[in] tracker : Pointer to MouseCursorTracker instance
722 + void SetTracker(MouseCursorTracker *tracker);
724 + Csm::ICubismModelSetting* GetModelSetting(void) const;
728 * @brief モデルを描画する処理。モデルを描画する空間のView-Projection行列を渡す。
729 @@ -183,6 +193,8 @@ private:
730 const Csm::CubismId* _idParamEyeBallY; ///< パラメータID: ParamEyeBallXY
732 Csm::Rendering::CubismOffscreenFrame_OpenGLES2 _renderBuffer; ///< フレームバッファ以外の描画先
734 + MouseCursorTracker *_tracker;
738 diff -pruN --exclude build ./demo_clean/src/LAppPal.cpp ./demo_dev/src/LAppPal.cpp
739 --- ./demo_clean/src/LAppPal.cpp 2020-10-01 22:47:25.850827994 +0100
740 +++ ./demo_dev/src/LAppPal.cpp 2020-10-18 04:57:43.289600308 +0100
744 #include "LAppPal.hpp"
745 +#include <stdexcept>
749 @@ -36,7 +37,6 @@ csmByte* LAppPal::LoadFileAsBytes(const
750 if (stat(path, &statBuf) == 0)
752 size = statBuf.st_size;
757 @@ -45,10 +45,7 @@ csmByte* LAppPal::LoadFileAsBytes(const
758 file.open(path, std::ios::in | std::ios::binary);
761 - if (DebugLogEnable)
763 - PrintLog("file open error");
765 + throw std::runtime_error("Failed to open file " + filePath);
768 file.read(buf, size);
769 diff -pruN --exclude build ./demo_clean/src/LAppTextureManager.cpp ./demo_dev/src/LAppTextureManager.cpp
770 --- ./demo_clean/src/LAppTextureManager.cpp 2020-10-01 22:47:25.850827994 +0100
771 +++ ./demo_dev/src/LAppTextureManager.cpp 2020-10-01 22:47:24.654849690 +0100
772 @@ -96,6 +96,46 @@ LAppTextureManager::TextureInfo* LAppTex
776 +LAppTextureManager::TextureInfo* LAppTextureManager::CreateTextureFromColor(
777 + uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha
780 + int width = 8, height = 8;
782 + uint8_t pixels[height][width][4];
783 + for (std::size_t h = 0; h < height; h++)
785 + for (std::size_t w = 0; w < width; w++)
787 + pixels[h][w][0] = red;
788 + pixels[h][w][1] = green;
789 + pixels[h][w][2] = blue;
790 + pixels[h][w][3] = alpha;
795 + glGenTextures(1, &textureId);
796 + glBindTexture(GL_TEXTURE_2D, textureId);
797 + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
799 + glGenerateMipmap(GL_TEXTURE_2D);
800 + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
801 + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
802 + glBindTexture(GL_TEXTURE_2D, 0);
805 + LAppTextureManager::TextureInfo* textureInfo = new LAppTextureManager::TextureInfo();
806 + textureInfo->fileName = "";
807 + textureInfo->width = width;
808 + textureInfo->height = height;
809 + textureInfo->id = textureId;
811 + _textures.PushBack(textureInfo);
813 + return textureInfo;
816 void LAppTextureManager::ReleaseTextures()
818 for (Csm::csmUint32 i = 0; i < _textures.GetSize(); i++)
819 diff -pruN --exclude build ./demo_clean/src/LAppTextureManager.hpp ./demo_dev/src/LAppTextureManager.hpp
820 --- ./demo_clean/src/LAppTextureManager.hpp 2020-10-01 22:47:25.846828066 +0100
821 +++ ./demo_dev/src/LAppTextureManager.hpp 2020-10-01 22:47:24.786847290 +0100
822 @@ -72,6 +72,8 @@ public:
824 TextureInfo* CreateTextureFromPngFile(std::string fileName);
826 + TextureInfo *CreateTextureFromColor(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha = 255);
831 diff -pruN --exclude build ./demo_clean/src/LAppView.cpp ./demo_dev/src/LAppView.cpp
832 --- ./demo_clean/src/LAppView.cpp 2020-10-01 22:47:25.850827994 +0100
833 +++ ./demo_dev/src/LAppView.cpp 2020-10-01 22:47:24.602850636 +0100
835 #include "LAppLive2DManager.hpp"
836 #include "LAppTextureManager.hpp"
837 #include "LAppDefine.hpp"
838 -#include "TouchManager.hpp"
839 #include "LAppSprite.hpp"
840 #include "LAppModel.hpp"
842 @@ -26,8 +25,6 @@ using namespace LAppDefine;
843 LAppView::LAppView():
849 _renderTarget(SelectTarget_None)
851 @@ -35,8 +32,6 @@ LAppView::LAppView():
852 _clearColor[1] = 1.0f;
853 _clearColor[2] = 1.0f;
854 _clearColor[3] = 0.0f;
856 - _touchManager = new TouchManager();
858 // デバイス座標からスクリーン座標に変換するための
859 _deviceToScreen = new CubismMatrix44();
860 @@ -52,10 +47,7 @@ LAppView::~LAppView()
863 delete _deviceToScreen;
864 - delete _touchManager;
870 void LAppView::Initialize()
871 @@ -97,9 +89,6 @@ void LAppView::Initialize()
872 void LAppView::Render()
879 LAppLive2DManager* Live2DManager = LAppLive2DManager::GetInstance();
881 @@ -139,35 +128,17 @@ void LAppView::InitializeSprite()
882 glfwGetWindowSize(LAppDelegate::GetInstance()->GetWindow(), &width, &height);
884 LAppTextureManager* textureManager = LAppDelegate::GetInstance()->GetTextureManager();
885 - const string resourcesPath = LAppDelegate::GetInstance()->GetRootDirectory() + ResourcesPath;
887 - string imageName = BackImageName;
888 - LAppTextureManager::TextureInfo* backgroundTexture = textureManager->CreateTextureFromPngFile(resourcesPath + imageName);
890 + LAppTextureManager::TextureInfo* backgroundTexture =
891 + textureManager->CreateTextureFromColor(0, 255, 0);
893 float x = width * 0.5f;
894 float y = height * 0.5f;
895 - float fWidth = static_cast<float>(backgroundTexture->width * 2.0f);
896 - float fHeight = static_cast<float>(height) * 0.95f;
897 + float fWidth = static_cast<float>(width);
898 + float fHeight = static_cast<float>(height);
899 _back = new LAppSprite(x, y, fWidth, fHeight, backgroundTexture->id, _programId);
901 - imageName = GearImageName;
902 - LAppTextureManager::TextureInfo* gearTexture = textureManager->CreateTextureFromPngFile(resourcesPath + imageName);
904 - x = static_cast<float>(width - gearTexture->width * 0.5f);
905 - y = static_cast<float>(height - gearTexture->height * 0.5f);
906 - fWidth = static_cast<float>(gearTexture->width);
907 - fHeight = static_cast<float>(gearTexture->height);
908 - _gear = new LAppSprite(x, y, fWidth, fHeight, gearTexture->id, _programId);
910 - imageName = PowerImageName;
911 - LAppTextureManager::TextureInfo* powerTexture = textureManager->CreateTextureFromPngFile(resourcesPath + imageName);
913 - x = static_cast<float>(width - powerTexture->width * 0.5f);
914 - y = static_cast<float>(powerTexture->height * 0.5f);
915 - fWidth = static_cast<float>(powerTexture->width);
916 - fHeight = static_cast<float>(powerTexture->height);
917 - _power = new LAppSprite(x, y, fWidth, fHeight, powerTexture->id, _programId);
922 @@ -175,52 +146,6 @@ void LAppView::InitializeSprite()
926 -void LAppView::OnTouchesBegan(float px, float py) const
928 - _touchManager->TouchesBegan(px, py);
931 -void LAppView::OnTouchesMoved(float px, float py) const
933 - float viewX = this->TransformViewX(_touchManager->GetX());
934 - float viewY = this->TransformViewY(_touchManager->GetY());
936 - _touchManager->TouchesMoved(px, py);
938 - LAppLive2DManager* Live2DManager = LAppLive2DManager::GetInstance();
939 - Live2DManager->OnDrag(viewX, viewY);
942 -void LAppView::OnTouchesEnded(float px, float py) const
945 - LAppLive2DManager* live2DManager = LAppLive2DManager::GetInstance();
946 - live2DManager->OnDrag(0.0f, 0.0f);
950 - float x = _deviceToScreen->TransformX(_touchManager->GetX()); // 論理座標変換した座標を取得。
951 - float y = _deviceToScreen->TransformY(_touchManager->GetY()); // 論理座標変換した座標を取得。
952 - if (DebugTouchLogEnable)
954 - LAppPal::PrintLog("[APP]touchesEnded x:%.2f y:%.2f", x, y);
956 - live2DManager->OnTap(x, y);
959 - if (_gear->IsHit(px, py))
961 - live2DManager->NextScene();
965 - if (_power->IsHit(px, py))
967 - LAppDelegate::GetInstance()->AppEnd();
972 float LAppView::TransformViewX(float deviceX) const
974 float screenX = _deviceToScreen->TransformX(deviceX); // 論理座標変換した座標を取得。
975 @@ -362,32 +287,4 @@ void LAppView::ResizeSprite()
976 _back->ResetRect(x, y, fWidth, fHeight);
982 - GLuint id = _power->GetTextureId();
983 - LAppTextureManager::TextureInfo* texInfo = textureManager->GetTextureInfoById(id);
986 - x = static_cast<float>(width - texInfo->width * 0.5f);
987 - y = static_cast<float>(texInfo->height * 0.5f);
988 - fWidth = static_cast<float>(texInfo->width);
989 - fHeight = static_cast<float>(texInfo->height);
990 - _power->ResetRect(x, y, fWidth, fHeight);
996 - GLuint id = _gear->GetTextureId();
997 - LAppTextureManager::TextureInfo* texInfo = textureManager->GetTextureInfoById(id);
1000 - x = static_cast<float>(width - texInfo->width * 0.5f);
1001 - y = static_cast<float>(height - texInfo->height * 0.5f);
1002 - fWidth = static_cast<float>(texInfo->width);
1003 - fHeight = static_cast<float>(texInfo->height);
1004 - _gear->ResetRect(x, y, fWidth, fHeight);
1008 diff -pruN --exclude build ./demo_clean/src/LAppView.hpp ./demo_dev/src/LAppView.hpp
1009 --- ./demo_clean/src/LAppView.hpp 2020-10-01 22:47:25.846828066 +0100
1010 +++ ./demo_dev/src/LAppView.hpp 2020-10-01 22:47:24.802846999 +0100
1012 #include "CubismFramework.hpp"
1013 #include <Rendering/OpenGL/CubismOffscreenSurface_OpenGLES2.hpp>
1015 -class TouchManager;
1019 @@ -66,30 +65,6 @@ public:
1020 void ResizeSprite();
1023 - * @brief タッチされたときに呼ばれる。
1025 - * @param[in] pointX スクリーンX座標
1026 - * @param[in] pointY スクリーンY座標
1028 - void OnTouchesBegan(float pointX, float pointY) const;
1031 - * @brief タッチしているときにポインタが動いたら呼ばれる。
1033 - * @param[in] pointX スクリーンX座標
1034 - * @param[in] pointY スクリーンY座標
1036 - void OnTouchesMoved(float pointX, float pointY) const;
1039 - * @brief タッチが終了したら呼ばれる。
1041 - * @param[in] pointX スクリーンX座標
1042 - * @param[in] pointY スクリーンY座標
1044 - void OnTouchesEnded(float pointX, float pointY) const;
1047 * @brief X座標をView座標に変換する。
1049 * @param[in] deviceX デバイスX座標
1050 @@ -147,13 +122,10 @@ public:
1051 void SetRenderTargetClearColor(float r, float g, float b);
1054 - TouchManager* _touchManager; ///< タッチマネージャー
1055 Csm::CubismMatrix44* _deviceToScreen; ///< デバイスからスクリーンへの行列
1056 Csm::CubismViewMatrix* _viewMatrix; ///< viewMatrix
1057 GLuint _programId; ///< シェーダID
1058 LAppSprite* _back; ///< 背景画像
1059 - LAppSprite* _gear; ///< ギア画像
1060 - LAppSprite* _power; ///< 電源画像
1062 // レンダリング先を別ターゲットにする方式の場合に使用
1063 LAppSprite* _renderSprite; ///< モードによっては_renderBufferのテクスチャを描画
1064 diff -pruN --exclude build ./demo_clean/src/main.cpp ./demo_dev/src/main.cpp
1065 --- ./demo_clean/src/main.cpp 2020-10-01 22:47:25.846828066 +0100
1066 +++ ./demo_dev/src/main.cpp 2020-10-18 07:03:46.194220443 +0100
1068 * that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html.
1072 +#include <stdexcept>
1078 +#ifdef __cpp_lib_filesystem
1079 +#include <filesystem>
1080 +namespace fs = std::filesystem;
1082 +#include <experimental/filesystem>
1083 +namespace fs = std::experimental::filesystem;
1086 +#include "ICubismModelSetting.hpp"
1087 #include "LAppDelegate.hpp"
1088 +#include "LAppLive2DManager.hpp"
1089 +#include "LAppModel.hpp"
1090 +#include "mouse_cursor_tracker.h"
1096 + std::string windowTitle;
1097 + std::string rootDir;
1098 + float scaleFactor;
1101 + std::string modelName;
1102 + std::string cfgPath; // Path to config file for MouseCursorTracker
1105 +CmdArgs parseArgv(int argc, char *argv[])
1107 + // I think the command-line args are simple enough to not justify using a library...
1109 + // Set default values
1110 + cmdArgs.windowWidth = 600;
1111 + cmdArgs.windowHeight = 600;
1112 + cmdArgs.windowTitle = "MouseTrackerForCubism example";
1113 + cmdArgs.rootDir = fs::current_path();
1114 + cmdArgs.scaleFactor = 8.0f;
1115 + cmdArgs.translateX = 0.0f;
1116 + cmdArgs.translateY = -2.8f;
1117 + cmdArgs.modelName = "Haru";
1118 + cmdArgs.cfgPath = "";
1123 + std::string arg = argv[i];
1124 + std::stringstream ss;
1126 + if (arg == "--window-width" || arg == "-W") // capital W for consistency with height
1128 + ss << argv[i + 1];
1129 + if (!(ss >> cmdArgs.windowWidth))
1131 + throw std::runtime_error("Invalid argument for window width");
1134 + else if (arg == "--window-height" || arg == "-H") // avoiding "-h", typically for help
1136 + ss << argv[i + 1];
1137 + if (!(ss >> cmdArgs.windowHeight))
1139 + throw std::runtime_error("Invalid argument for window height");
1142 + else if (arg == "--window-title" || arg == "-t")
1144 + cmdArgs.windowTitle = argv[i + 1];
1146 + else if (arg == "--root-dir" || arg == "-d")
1148 + cmdArgs.rootDir = argv[i + 1];
1150 + else if (arg == "--scale-factor" || arg == "-f")
1152 + ss << argv[i + 1];
1153 + if (!(ss >> cmdArgs.scaleFactor))
1155 + throw std::runtime_error("Invalid argument for scale factor");
1158 + else if (arg == "--translate-x" || arg == "-x")
1160 + ss << argv[i + 1];
1161 + if (!(ss >> cmdArgs.translateX))
1163 + throw std::runtime_error("Invalid argument for translate X");
1166 + else if (arg == "--translate-y" || arg == "-y")
1168 + ss << argv[i + 1];
1169 + if (!(ss >> cmdArgs.translateY))
1171 + throw std::runtime_error("Invalid argument for translate Y");
1174 + else if (arg == "--model" || arg == "-m")
1176 + cmdArgs.modelName = argv[i + 1];
1178 + else if (arg == "--config" || arg == "-c")
1180 + cmdArgs.cfgPath = argv[i + 1];
1184 + throw std::runtime_error("Unrecognized argument: " + arg);
1193 int main(int argc, char* argv[])
1195 - // create the application instance
1196 - if (LAppDelegate::GetInstance()->Initialize() == GL_FALSE)
1197 + auto cmdArgs = parseArgv(argc, argv);
1199 + LAppDelegate *delegate = LAppDelegate::GetInstance();
1201 + if (!delegate->Initialize(cmdArgs.windowWidth,
1202 + cmdArgs.windowHeight,
1203 + cmdArgs.windowTitle.c_str()))
1206 + throw std::runtime_error("Unable to initialize LAppDelegate");
1209 - LAppDelegate::GetInstance()->Run();
1210 + delegate->SetRootDirectory(cmdArgs.rootDir);
1212 + LAppLive2DManager *manager = LAppLive2DManager::GetInstance();
1213 + manager->SetModel(cmdArgs.modelName);
1215 + manager->SetProjectionScaleTranslate(cmdArgs.scaleFactor,
1216 + cmdArgs.translateX,
1217 + cmdArgs.translateY);
1219 + LAppModel *model = manager->GetModel(0);
1220 + if (!model) throw std::runtime_error("model is null");
1222 + Live2D::Cubism::Framework::ICubismModelSetting *modelSetting = model->GetModelSetting();
1223 + if (!modelSetting) throw std::runtime_error("modelSetting is null");
1225 + std::vector<std::pair<std::string, int> > motions;
1226 + int motionGroupCount = modelSetting->GetMotionGroupCount();
1227 + for (int i = 0; i < motionGroupCount; i++)
1229 + const char *motionGroup = modelSetting->GetMotionGroupName(i);
1230 + int motionCount = modelSetting->GetMotionCount(motionGroup);
1231 + motions.push_back(std::make_pair(std::string(motionGroup), motionCount));
1234 + std::vector<std::string> expressions;
1235 + int expCount = modelSetting->GetExpressionCount();
1236 + for (int i = 0; i < expCount; i++)
1238 + const char *expName = modelSetting->GetExpressionName(i);
1239 + expressions.push_back(std::string(expName));
1242 + MouseCursorTracker tracker(cmdArgs.cfgPath, motions, expressions);
1244 + std::thread trackerThread(&MouseCursorTracker::mainLoop, &tracker);
1245 + manager->SetTracker(&tracker);
1250 + trackerThread.join();