1 diff -pruN --exclude build ./demo_clean/CMakeLists.txt ./demo_dev/CMakeLists.txt
2 --- ./demo_clean/CMakeLists.txt 2020-10-01 22:47:25.846828066 +0100
3 +++ ./demo_dev/CMakeLists.txt 2021-01-01 15:36:14.720039779 +0000
4 @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.16)
8 -set(SDK_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../..)
9 +set(SDK_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../CubismSdkForNative-4-r.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)
16 # Specify version of compiler.
17 -set(CMAKE_CXX_STANDARD 14)
18 +set(CMAKE_CXX_STANDARD 17)
19 set(CMAKE_CXX_STANDARD_REQUIRED ON)
20 set(CMAKE_CXX_EXTENSIONS OFF)
22 @@ -42,7 +42,7 @@ add_library(Live2DCubismCore STATIC IMPO
24 set_target_properties(Live2DCubismCore
26 - IMPORTED_LOCATION ${CORE_PATH}/lib/linux/x86_64/libLive2DCubismCore.a
27 + IMPORTED_LOCATION ${CORE_PATH}/lib/experimental/rpi/libLive2DCubismCore.a
28 INTERFACE_INCLUDE_DIRECTORIES ${CORE_PATH}/include
31 @@ -64,6 +64,11 @@ target_link_libraries(Framework Live2DCu
32 # Find opengl libraries.
33 find_package(OpenGL REQUIRED)
35 +# Add MouseTrackerForCubism
36 +find_package(PkgConfig)
37 +pkg_check_modules(GTKMM gtkmm-3.0)
38 +add_subdirectory(../.. MouseTrackerForCubism_build)
40 # Make executable app.
41 add_executable(${APP_NAME})
43 @@ -73,9 +78,20 @@ target_link_libraries(${APP_NAME}
47 + MouseTrackerForCubism
50 # Specify include directories.
51 -target_include_directories(${APP_NAME} PRIVATE ${STB_PATH})
52 +target_include_directories(${APP_NAME} PRIVATE ${STB_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/../../include ${GTKMM_INCLUDE_DIRS})
54 +# Copy GUI to build directory
60 + copy ${CMAKE_CURRENT_SOURCE_DIR}/../../src/gui.glade $<TARGET_FILE_DIR:${APP_NAME}>/gui.glade
63 # Copy resource directory to build directory.
65 diff -pruN --exclude build ./demo_clean/scripts/make_gcc ./demo_dev/scripts/make_gcc
66 --- ./demo_clean/scripts/make_gcc 2020-10-01 22:47:25.854827921 +0100
67 +++ ./demo_dev/scripts/make_gcc 2021-01-01 11:34:25.583684883 +0000
68 @@ -10,4 +10,4 @@ BUILD_PATH=$SCRIPT_PATH/../build/make_gc
69 cmake -S "$CMAKE_PATH" \
71 -D CMAKE_BUILD_TYPE=Release
72 -cd "$BUILD_PATH" && make
73 +cd "$BUILD_PATH" && make -j4
74 diff -pruN --exclude build ./demo_clean/src/CMakeLists.txt ./demo_dev/src/CMakeLists.txt
75 --- ./demo_clean/src/CMakeLists.txt 2020-10-01 22:47:25.850827994 +0100
76 +++ ./demo_dev/src/CMakeLists.txt 2020-10-01 22:47:24.842846271 +0100
77 @@ -19,6 +19,4 @@ target_sources(${APP_NAME}
78 ${CMAKE_CURRENT_SOURCE_DIR}/LAppView.cpp
79 ${CMAKE_CURRENT_SOURCE_DIR}/LAppView.hpp
80 ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp
81 - ${CMAKE_CURRENT_SOURCE_DIR}/TouchManager.cpp
82 - ${CMAKE_CURRENT_SOURCE_DIR}/TouchManager.hpp
84 diff -pruN --exclude build ./demo_clean/src/LAppDefine.cpp ./demo_dev/src/LAppDefine.cpp
85 --- ./demo_clean/src/LAppDefine.cpp 2020-10-01 22:47:25.850827994 +0100
86 +++ ./demo_dev/src/LAppDefine.cpp 2020-10-18 04:59:13.238452938 +0100
87 @@ -61,11 +61,11 @@ namespace LAppDefine {
88 const csmInt32 PriorityForce = 3;
91 - const csmBool DebugLogEnable = true;
92 + const csmBool DebugLogEnable = false;
93 const csmBool DebugTouchLogEnable = false;
95 // Frameworkから出力するログのレベル設定
96 - const CubismFramework::Option::LogLevel CubismLoggingLevel = CubismFramework::Option::LogLevel_Verbose;
97 + const CubismFramework::Option::LogLevel CubismLoggingLevel = CubismFramework::Option::LogLevel_Warning;
100 const csmInt32 RenderTargetWidth = 1900;
101 diff -pruN --exclude build ./demo_clean/src/LAppDelegate.cpp ./demo_dev/src/LAppDelegate.cpp
102 --- ./demo_clean/src/LAppDelegate.cpp 2020-10-01 22:47:25.850827994 +0100
103 +++ ./demo_dev/src/LAppDelegate.cpp 2020-10-01 22:47:24.698848890 +0100
104 @@ -45,7 +45,8 @@ void LAppDelegate::ReleaseInstance()
108 -bool LAppDelegate::Initialize()
109 +bool LAppDelegate::Initialize(int initWindowWidth, int initWindowHeight,
110 + const char *windowTitle)
114 @@ -63,7 +64,13 @@ bool LAppDelegate::Initialize()
118 - _window = glfwCreateWindow(RenderTargetWidth, RenderTargetHeight, "SAMPLE", NULL, NULL);
119 + _window = glfwCreateWindow(
120 + initWindowWidth ? initWindowWidth : RenderTargetWidth,
121 + initWindowHeight ? initWindowHeight : RenderTargetHeight,
122 + windowTitle ? windowTitle : "SAMPLE",
129 @@ -95,10 +102,6 @@ bool LAppDelegate::Initialize()
131 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
134 - glfwSetMouseButtonCallback(_window, EventHandler::OnMouseCallBack);
135 - glfwSetCursorPosCallback(_window, EventHandler::OnMouseCallBack);
139 glfwGetWindowSize(LAppDelegate::GetInstance()->GetWindow(), &width, &height);
140 @@ -111,8 +114,6 @@ bool LAppDelegate::Initialize()
144 - SetRootDirectory();
147 LAppLive2DManager::GetInstance();
149 @@ -214,49 +215,6 @@ void LAppDelegate::InitializeCubism()
150 LAppPal::UpdateTime();
153 -void LAppDelegate::OnMouseCallBack(GLFWwindow* window, int button, int action, int modify)
159 - if (GLFW_MOUSE_BUTTON_LEFT != button)
164 - if (GLFW_PRESS == action)
167 - _view->OnTouchesBegan(_mouseX, _mouseY);
169 - else if (GLFW_RELEASE == action)
174 - _view->OnTouchesEnded(_mouseX, _mouseY);
179 -void LAppDelegate::OnMouseCallBack(GLFWwindow* window, double x, double y)
181 - _mouseX = static_cast<float>(x);
182 - _mouseY = static_cast<float>(y);
193 - _view->OnTouchesMoved(_mouseX, _mouseY);
196 GLuint LAppDelegate::CreateShader()
199 @@ -299,29 +257,9 @@ GLuint LAppDelegate::CreateShader()
203 -void LAppDelegate::SetRootDirectory()
204 +void LAppDelegate::SetRootDirectory(std::string rootDir)
207 - ssize_t len = readlink("/proc/self/exe", path, 1024 - 1);
214 - std::string pathString(path);
216 - pathString = pathString.substr(0, pathString.rfind("Demo"));
217 - Csm::csmVector<string> splitStrings = this->Split(pathString, '/');
219 - this->_rootDirectory = "";
221 - for(int i = 0; i < splitStrings.GetSize(); i++)
223 - this->_rootDirectory = this->_rootDirectory + "/" +splitStrings[i];
226 - this->_rootDirectory += "/";
227 + this->_rootDirectory = rootDir + "/";
230 Csm::csmVector<string> LAppDelegate::Split(const std::string& baseString, char delimiter)
231 diff -pruN --exclude build ./demo_clean/src/LAppDelegate.hpp ./demo_dev/src/LAppDelegate.hpp
232 --- ./demo_clean/src/LAppDelegate.hpp 2020-10-01 22:47:25.850827994 +0100
233 +++ ./demo_dev/src/LAppDelegate.hpp 2020-10-01 22:47:24.842846271 +0100
234 @@ -40,7 +40,8 @@ public:
236 * @brief APPに必要なものを初期化する。
239 + bool Initialize(int initWindowWidth = 0, int initWindowHeight = 0,
240 + const char *windowTitle = "SAMPLE");
244 @@ -53,25 +54,6 @@ public:
248 - * @brief OpenGL用 glfwSetMouseButtonCallback用関数。
250 - * @param[in] window コールバックを呼んだWindow情報
251 - * @param[in] button ボタン種類
252 - * @param[in] action 実行結果
253 - * @param[in] modify
255 - void OnMouseCallBack(GLFWwindow* window, int button, int action, int modify);
258 - * @brief OpenGL用 glfwSetCursorPosCallback用関数。
260 - * @param[in] window コールバックを呼んだWindow情報
264 - void OnMouseCallBack(GLFWwindow* window, double x, double y);
269 GLuint CreateShader();
270 @@ -98,8 +80,10 @@ public:
273 * @brief ルートディレクトリを設定する。
275 + * @param[in] rootDir : The root directory to set to.
277 - void SetRootDirectory();
278 + void SetRootDirectory(std::string rootDir);
281 * @brief ルートディレクトリを取得する。
282 @@ -146,24 +130,3 @@ private:
283 int _windowWidth; ///< Initialize関数で設定したウィンドウ幅
284 int _windowHeight; ///< Initialize関数で設定したウィンドウ高さ
291 - * @brief glfwSetMouseButtonCallback用コールバック関数。
293 - static void OnMouseCallBack(GLFWwindow* window, int button, int action, int modify)
295 - LAppDelegate::GetInstance()->OnMouseCallBack(window, button, action, modify);
299 - * @brief glfwSetCursorPosCallback用コールバック関数。
301 - static void OnMouseCallBack(GLFWwindow* window, double x, double y)
303 - LAppDelegate::GetInstance()->OnMouseCallBack(window, x, y);
307 diff -pruN --exclude build ./demo_clean/src/LAppLive2DManager.cpp ./demo_dev/src/LAppLive2DManager.cpp
308 --- ./demo_clean/src/LAppLive2DManager.cpp 2020-10-01 22:47:25.850827994 +0100
309 +++ ./demo_dev/src/LAppLive2DManager.cpp 2020-10-02 02:00:49.961556700 +0100
310 @@ -52,9 +52,10 @@ void LAppLive2DManager::ReleaseInstance(
312 LAppLive2DManager::LAppLive2DManager()
315 + , _projScaleFactor(1.0f)
316 + , _translateX(0.0f)
317 + , _translateY(0.0f)
319 - ChangeScene(_sceneIndex);
322 LAppLive2DManager::~LAppLive2DManager()
323 @@ -98,26 +99,6 @@ void LAppLive2DManager::OnTap(csmFloat32
325 LAppPal::PrintLog("[APP]tap point: {x:%.2f y:%.2f}", x, y);
328 - for (csmUint32 i = 0; i < _models.GetSize(); i++)
330 - if (_models[i]->HitTest(HitAreaNameHead, x, y))
332 - if (DebugLogEnable)
334 - LAppPal::PrintLog("[APP]hit area: [%s]", HitAreaNameHead);
336 - _models[i]->SetRandomExpression();
338 - else if (_models[i]->HitTest(HitAreaNameBody, x, y))
340 - if (DebugLogEnable)
342 - LAppPal::PrintLog("[APP]hit area: [%s]", HitAreaNameBody);
344 - _models[i]->StartRandomMotion(MotionGroupTapBody, PriorityNormal, FinishedMotion);
349 void LAppLive2DManager::OnUpdate() const
350 @@ -125,7 +106,9 @@ void LAppLive2DManager::OnUpdate() const
351 CubismMatrix44 projection;
353 glfwGetWindowSize(LAppDelegate::GetInstance()->GetWindow(), &width, &height);
354 - projection.Scale(1.0f, static_cast<float>(width) / static_cast<float>(height));
355 + projection.Scale(_projScaleFactor,
356 + _projScaleFactor * static_cast<float>(width) / static_cast<float>(height));
357 + projection.Translate(_translateX, _translateY);
359 if (_viewMatrix != NULL)
361 @@ -148,26 +131,10 @@ void LAppLive2DManager::OnUpdate() const
365 -void LAppLive2DManager::NextScene()
367 - csmInt32 no = (_sceneIndex + 1) % ModelDirSize;
371 -void LAppLive2DManager::ChangeScene(Csm::csmInt32 index)
372 +void LAppLive2DManager::SetModel(std::string modelName)
374 - _sceneIndex = index;
375 - if (DebugLogEnable)
377 - LAppPal::PrintLog("[APP]model index: %d", _sceneIndex);
380 - // ModelDir[]に保持したディレクトリ名から
381 - // model3.jsonのパスを決定する.
382 - // ディレクトリ名とmodel3.jsonの名前を一致させておくこと.
383 - std::string model = ModelDir[index];
384 - std::string modelPath = LAppDelegate::GetInstance()->GetRootDirectory() + ResourcesPath + model + "/";
385 - std::string modelJsonName = ModelDir[index];
386 + std::string modelPath = LAppDelegate::GetInstance()->GetRootDirectory() + ResourcesPath + modelName + "/";
387 + std::string modelJsonName = modelName;
388 modelJsonName += ".model3.json";
391 @@ -215,3 +182,20 @@ csmUint32 LAppLive2DManager::GetModelNum
393 return _models.GetSize();
396 +void LAppLive2DManager::SetTracker(MouseCursorTracker *tracker)
398 + for (auto it = _models.Begin(); it != _models.End(); ++it)
400 + (*it)->SetTracker(tracker);
404 +void LAppLive2DManager::SetProjectionScaleTranslate(float scaleFactor,
408 + _projScaleFactor = scaleFactor;
409 + _translateX = translateX;
410 + _translateY = translateY;
412 diff -pruN --exclude build ./demo_clean/src/LAppLive2DManager.hpp ./demo_dev/src/LAppLive2DManager.hpp
413 --- ./demo_clean/src/LAppLive2DManager.hpp 2020-10-01 22:47:25.846828066 +0100
414 +++ ./demo_dev/src/LAppLive2DManager.hpp 2020-10-01 23:36:24.583055381 +0100
420 #include <CubismFramework.hpp>
421 #include <Math/CubismMatrix44.hpp>
422 #include <Type/csmVector.hpp>
426 +class MouseCursorTracker;
429 * @brief サンプルアプリケーションにおいてCubismModelを管理するクラス<br>
430 * モデル生成と破棄、タップイベントの処理、モデル切り替えを行う。
431 @@ -72,16 +75,12 @@ public:
432 void OnUpdate() const;
435 - * @brief 次のシーンに切り替える<br>
436 - * サンプルアプリケーションではモデルセットの切り替えを行う。
441 - * @brief シーンを切り替える<br>
442 - * サンプルアプリケーションではモデルセットの切り替えを行う。
444 - void ChangeScene(Csm::csmInt32 index);
445 + * @brief Set model data
447 + * @param[in] modelName : Name of model, should be the same for both
448 + * the directory and the model3.json file
450 + void SetModel(std::string modelName);
454 @@ -89,6 +88,24 @@ public:
456 Csm::csmUint32 GetModelNum() const;
459 + * @brief Set the pointer to the MouseCursorTracker instance
461 + * @param[in] tracker : Pointer to MouseCursorTracker instance
463 + void SetTracker(MouseCursorTracker *tracker);
466 + * @brief Set projection scale factor and translation parameters
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
472 + void SetProjectionScaleTranslate(float scaleFactor,
479 @@ -102,5 +119,8 @@ private:
481 Csm::CubismMatrix44* _viewMatrix; ///< モデル描画に用いるView行列
482 Csm::csmVector<LAppModel*> _models; ///< モデルインスタンスのコンテナ
483 - Csm::csmInt32 _sceneIndex; ///< 表示するシーンのインデックス値
485 + float _projScaleFactor;
489 diff -pruN --exclude build ./demo_clean/src/LAppModel.cpp ./demo_dev/src/LAppModel.cpp
490 --- ./demo_clean/src/LAppModel.cpp 2020-10-01 22:47:25.850827994 +0100
491 +++ ./demo_dev/src/LAppModel.cpp 2020-10-18 09:26:08.998822685 +0100
493 #include "LAppTextureManager.hpp"
494 #include "LAppDelegate.hpp"
496 +#include "mouse_cursor_tracker.h"
500 using namespace Live2D::Cubism::Framework;
501 using namespace Live2D::Cubism::Framework::DefaultParameterId;
502 using namespace LAppDefine;
503 @@ -49,6 +53,7 @@ LAppModel::LAppModel()
505 , _modelSetting(NULL)
506 , _userTimeSeconds(0.0f)
507 + , _tracker(nullptr)
511 @@ -335,59 +340,110 @@ void LAppModel::Update()
512 const csmFloat32 deltaTimeSeconds = LAppPal::GetDeltaTime();
513 _userTimeSeconds += deltaTimeSeconds;
515 - _dragManager->Update(deltaTimeSeconds);
516 - _dragX = _dragManager->GetX();
517 - _dragY = _dragManager->GetY();
519 - // モーションによるパラメータ更新の有無
520 - csmBool motionUpdated = false;
522 - //-----------------------------------------------------------------
523 - _model->LoadParameters(); // 前回セーブされた状態をロード
524 - if (_motionManager->IsFinished())
526 - // モーションの再生がない場合、待機モーションの中からランダムで再生する
527 - StartRandomMotion(MotionGroupIdle, PriorityIdle);
532 - motionUpdated = _motionManager->UpdateMotion(_model, deltaTimeSeconds); // モーションを更新
534 - _model->SaveParameters(); // 状態を保存
535 - //-----------------------------------------------------------------
536 + auto idMan = CubismFramework::GetIdManager();
537 + auto params = _tracker->getParams();
540 - if (!motionUpdated)
542 - if (_eyeBlink != NULL)
543 + _model->LoadParameters(); // 前回セーブされた状態をロード
545 + int paramsMotionPriority = static_cast<int>(params.motionPriority);
547 + if (paramsMotionPriority != PriorityNone)
549 - // メインモーションの更新がないとき
550 - _eyeBlink->UpdateParameters(_model, deltaTimeSeconds); // 目パチ
551 + StartMotion(params.motionGroup.c_str(), params.motionNumber,
552 + paramsMotionPriority);
554 + else if (params.randomIdleMotion && _motionManager->IsFinished())
556 + // モーションの再生がない場合、待機モーションの中からランダムで再生する
557 + StartRandomMotion(MotionGroupIdle, PriorityIdle);
561 - if (_expressionManager != NULL)
563 - _expressionManager->UpdateMotion(_model, deltaTimeSeconds); // 表情でパラメータ更新(相対変化)
565 + // FIXME pose does not return to normal after motion
566 + // if we don't have randomIdleMotion set
569 + _motionManager->UpdateMotion(_model, deltaTimeSeconds); // モーションを更新
571 + _model->SaveParameters(); // 状態を保存
575 - _model->AddParameterValue(_idParamAngleX, _dragX * 30); // -30から30の値を加える
576 - _model->AddParameterValue(_idParamAngleY, _dragY * 30);
577 - _model->AddParameterValue(_idParamAngleZ, _dragX * _dragY * -30);
578 + if (params.expression != "")
580 + SetExpression(params.expression.c_str());
582 + if (_expressionManager != NULL)
584 + _expressionManager->UpdateMotion(_model, deltaTimeSeconds); // 表情でパラメータ更新(相対変化)
588 - _model->AddParameterValue(_idParamBodyAngleX, _dragX * 10); // -10から10の値を加える
589 + bool autoBlink = params.autoBlink && _eyeBlink;
590 + auto eyeLOpenIt = params.live2d.find("ParamEyeLOpen");
591 + auto eyeROpenIt = params.live2d.find("ParamEyeROpen");
594 - _model->AddParameterValue(_idParamEyeBallX, _dragX); // -1から1の値を加える
595 - _model->AddParameterValue(_idParamEyeBallY, _dragY);
598 + // Handle blink first
599 + _eyeBlink->UpdateParameters(_model, deltaTimeSeconds);
603 - if (_breath != NULL)
605 - _breath->UpdateParameters(_model, deltaTimeSeconds);
606 + if (eyeLOpenIt != params.live2d.end())
608 + // If value specified, override blinking
609 + _model->SetParameterValue(idMan->GetId("ParamEyeLOpen"),
610 + eyeLOpenIt->second);
612 + else if (!autoBlink)
614 + // If no value specified and no auto blink, set to 1
615 + _model->SetParameterValue(idMan->GetId("ParamEyeLOpen"), 1);
619 + if (eyeROpenIt != params.live2d.end())
621 + _model->SetParameterValue(idMan->GetId("ParamEyeROpen"),
622 + eyeROpenIt->second);
624 + else if (!autoBlink)
626 + _model->SetParameterValue(idMan->GetId("ParamEyeROpen"), 1);
630 + if (params.useLipSync && _lipSync)
632 + csmFloat32 value = params.lipSyncParam; // 0 to 1
634 + for (csmUint32 i = 0; i < _lipSyncIds.GetSize(); ++i)
636 + _model->AddParameterValue(_lipSyncIds[i], value, 0.8f);
641 + _model->SetParameterValue(idMan->GetId("ParamMouthOpenY"),
642 + params.live2d["ParamMouthOpenY"]);
645 + for (auto const &entry : params.live2d)
647 + std::string key = entry.first;
648 + double val = entry.second;
650 + if (key != "ParamEyeLOpen" && key != "ParamEyeROpen" &&
651 + key != "ParamMouthOpenY")
653 + _model->SetParameterValue(idMan->GetId(key.c_str()), val);
657 + if (params.autoBreath && _breath)
659 + // Note: _model->LoadParameters and SaveParameters is needed
660 + // before - see above.
661 + _breath->UpdateParameters(_model, deltaTimeSeconds);
666 @@ -396,17 +452,6 @@ void LAppModel::Update()
667 _physics->Evaluate(_model, deltaTimeSeconds);
673 - csmFloat32 value = 0; // リアルタイムでリップシンクを行う場合、システムから音量を取得して0〜1の範囲で値を入力します。
675 - for (csmUint32 i = 0; i < _lipSyncIds.GetSize(); ++i)
677 - _model->AddParameterValue(_lipSyncIds[i], value, 0.8f);
684 @@ -626,3 +671,14 @@ Csm::Rendering::CubismOffscreenFrame_Ope
686 return _renderBuffer;
689 +void LAppModel::SetTracker(MouseCursorTracker *tracker)
691 + _tracker = tracker;
694 +Csm::ICubismModelSetting* LAppModel::GetModelSetting(void) const
696 + return _modelSetting;
699 diff -pruN --exclude build ./demo_clean/src/LAppModel.hpp ./demo_dev/src/LAppModel.hpp
700 --- ./demo_clean/src/LAppModel.hpp 2020-10-01 22:47:25.850827994 +0100
701 +++ ./demo_dev/src/LAppModel.hpp 2020-10-18 03:04:52.142045751 +0100
703 #include <Type/csmRectF.hpp>
704 #include <Rendering/OpenGL/CubismOffscreenSurface_OpenGLES2.hpp>
706 +#include "mouse_cursor_tracker.h"
709 * @brief ユーザーが実際に使用するモデルの実装クラス<br>
710 @@ -113,6 +114,15 @@ public:
712 Csm::Rendering::CubismOffscreenFrame_OpenGLES2& GetRenderBuffer();
715 + * @brief Set the pointer to the MouseCursorTracker instance
717 + * @param[in] tracker : Pointer to MouseCursorTracker instance
719 + void SetTracker(MouseCursorTracker *tracker);
721 + Csm::ICubismModelSetting* GetModelSetting(void) const;
725 * @brief モデルを描画する処理。モデルを描画する空間のView-Projection行列を渡す。
726 @@ -183,6 +193,8 @@ private:
727 const Csm::CubismId* _idParamEyeBallY; ///< パラメータID: ParamEyeBallXY
729 Csm::Rendering::CubismOffscreenFrame_OpenGLES2 _renderBuffer; ///< フレームバッファ以外の描画先
731 + MouseCursorTracker *_tracker;
735 diff -pruN --exclude build ./demo_clean/src/LAppPal.cpp ./demo_dev/src/LAppPal.cpp
736 --- ./demo_clean/src/LAppPal.cpp 2020-10-01 22:47:25.850827994 +0100
737 +++ ./demo_dev/src/LAppPal.cpp 2020-10-18 04:57:43.289600308 +0100
741 #include "LAppPal.hpp"
742 +#include <stdexcept>
746 @@ -36,7 +37,6 @@ csmByte* LAppPal::LoadFileAsBytes(const
747 if (stat(path, &statBuf) == 0)
749 size = statBuf.st_size;
754 @@ -45,10 +45,7 @@ csmByte* LAppPal::LoadFileAsBytes(const
755 file.open(path, std::ios::in | std::ios::binary);
758 - if (DebugLogEnable)
760 - PrintLog("file open error");
762 + throw std::runtime_error("Failed to open file " + filePath);
765 file.read(buf, size);
766 diff -pruN --exclude build ./demo_clean/src/LAppTextureManager.cpp ./demo_dev/src/LAppTextureManager.cpp
767 --- ./demo_clean/src/LAppTextureManager.cpp 2020-10-01 22:47:25.850827994 +0100
768 +++ ./demo_dev/src/LAppTextureManager.cpp 2020-10-01 22:47:24.654849690 +0100
769 @@ -96,6 +96,46 @@ LAppTextureManager::TextureInfo* LAppTex
773 +LAppTextureManager::TextureInfo* LAppTextureManager::CreateTextureFromColor(
774 + uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha
777 + int width = 8, height = 8;
779 + uint8_t pixels[height][width][4];
780 + for (std::size_t h = 0; h < height; h++)
782 + for (std::size_t w = 0; w < width; w++)
784 + pixels[h][w][0] = red;
785 + pixels[h][w][1] = green;
786 + pixels[h][w][2] = blue;
787 + pixels[h][w][3] = alpha;
792 + glGenTextures(1, &textureId);
793 + glBindTexture(GL_TEXTURE_2D, textureId);
794 + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
796 + glGenerateMipmap(GL_TEXTURE_2D);
797 + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
798 + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
799 + glBindTexture(GL_TEXTURE_2D, 0);
802 + LAppTextureManager::TextureInfo* textureInfo = new LAppTextureManager::TextureInfo();
803 + textureInfo->fileName = "";
804 + textureInfo->width = width;
805 + textureInfo->height = height;
806 + textureInfo->id = textureId;
808 + _textures.PushBack(textureInfo);
810 + return textureInfo;
813 void LAppTextureManager::ReleaseTextures()
815 for (Csm::csmUint32 i = 0; i < _textures.GetSize(); i++)
816 diff -pruN --exclude build ./demo_clean/src/LAppTextureManager.hpp ./demo_dev/src/LAppTextureManager.hpp
817 --- ./demo_clean/src/LAppTextureManager.hpp 2020-10-01 22:47:25.846828066 +0100
818 +++ ./demo_dev/src/LAppTextureManager.hpp 2020-10-01 22:47:24.786847290 +0100
819 @@ -72,6 +72,8 @@ public:
821 TextureInfo* CreateTextureFromPngFile(std::string fileName);
823 + TextureInfo *CreateTextureFromColor(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha = 255);
828 diff -pruN --exclude build ./demo_clean/src/LAppView.cpp ./demo_dev/src/LAppView.cpp
829 --- ./demo_clean/src/LAppView.cpp 2020-10-01 22:47:25.850827994 +0100
830 +++ ./demo_dev/src/LAppView.cpp 2020-10-01 22:47:24.602850636 +0100
832 #include "LAppLive2DManager.hpp"
833 #include "LAppTextureManager.hpp"
834 #include "LAppDefine.hpp"
835 -#include "TouchManager.hpp"
836 #include "LAppSprite.hpp"
837 #include "LAppModel.hpp"
839 @@ -26,8 +25,6 @@ using namespace LAppDefine;
840 LAppView::LAppView():
846 _renderTarget(SelectTarget_None)
848 @@ -35,8 +32,6 @@ LAppView::LAppView():
849 _clearColor[1] = 1.0f;
850 _clearColor[2] = 1.0f;
851 _clearColor[3] = 0.0f;
853 - _touchManager = new TouchManager();
855 // デバイス座標からスクリーン座標に変換するための
856 _deviceToScreen = new CubismMatrix44();
857 @@ -52,10 +47,7 @@ LAppView::~LAppView()
860 delete _deviceToScreen;
861 - delete _touchManager;
867 void LAppView::Initialize()
868 @@ -97,9 +89,6 @@ void LAppView::Initialize()
869 void LAppView::Render()
876 LAppLive2DManager* Live2DManager = LAppLive2DManager::GetInstance();
878 @@ -139,35 +128,17 @@ void LAppView::InitializeSprite()
879 glfwGetWindowSize(LAppDelegate::GetInstance()->GetWindow(), &width, &height);
881 LAppTextureManager* textureManager = LAppDelegate::GetInstance()->GetTextureManager();
882 - const string resourcesPath = LAppDelegate::GetInstance()->GetRootDirectory() + ResourcesPath;
884 - string imageName = BackImageName;
885 - LAppTextureManager::TextureInfo* backgroundTexture = textureManager->CreateTextureFromPngFile(resourcesPath + imageName);
887 + LAppTextureManager::TextureInfo* backgroundTexture =
888 + textureManager->CreateTextureFromColor(0, 255, 0);
890 float x = width * 0.5f;
891 float y = height * 0.5f;
892 - float fWidth = static_cast<float>(backgroundTexture->width * 2.0f);
893 - float fHeight = static_cast<float>(height) * 0.95f;
894 + float fWidth = static_cast<float>(width);
895 + float fHeight = static_cast<float>(height);
896 _back = new LAppSprite(x, y, fWidth, fHeight, backgroundTexture->id, _programId);
898 - imageName = GearImageName;
899 - LAppTextureManager::TextureInfo* gearTexture = textureManager->CreateTextureFromPngFile(resourcesPath + imageName);
901 - x = static_cast<float>(width - gearTexture->width * 0.5f);
902 - y = static_cast<float>(height - gearTexture->height * 0.5f);
903 - fWidth = static_cast<float>(gearTexture->width);
904 - fHeight = static_cast<float>(gearTexture->height);
905 - _gear = new LAppSprite(x, y, fWidth, fHeight, gearTexture->id, _programId);
907 - imageName = PowerImageName;
908 - LAppTextureManager::TextureInfo* powerTexture = textureManager->CreateTextureFromPngFile(resourcesPath + imageName);
910 - x = static_cast<float>(width - powerTexture->width * 0.5f);
911 - y = static_cast<float>(powerTexture->height * 0.5f);
912 - fWidth = static_cast<float>(powerTexture->width);
913 - fHeight = static_cast<float>(powerTexture->height);
914 - _power = new LAppSprite(x, y, fWidth, fHeight, powerTexture->id, _programId);
919 @@ -175,52 +146,6 @@ void LAppView::InitializeSprite()
923 -void LAppView::OnTouchesBegan(float px, float py) const
925 - _touchManager->TouchesBegan(px, py);
928 -void LAppView::OnTouchesMoved(float px, float py) const
930 - float viewX = this->TransformViewX(_touchManager->GetX());
931 - float viewY = this->TransformViewY(_touchManager->GetY());
933 - _touchManager->TouchesMoved(px, py);
935 - LAppLive2DManager* Live2DManager = LAppLive2DManager::GetInstance();
936 - Live2DManager->OnDrag(viewX, viewY);
939 -void LAppView::OnTouchesEnded(float px, float py) const
942 - LAppLive2DManager* live2DManager = LAppLive2DManager::GetInstance();
943 - live2DManager->OnDrag(0.0f, 0.0f);
947 - float x = _deviceToScreen->TransformX(_touchManager->GetX()); // 論理座標変換した座標を取得。
948 - float y = _deviceToScreen->TransformY(_touchManager->GetY()); // 論理座標変換した座標を取得。
949 - if (DebugTouchLogEnable)
951 - LAppPal::PrintLog("[APP]touchesEnded x:%.2f y:%.2f", x, y);
953 - live2DManager->OnTap(x, y);
956 - if (_gear->IsHit(px, py))
958 - live2DManager->NextScene();
962 - if (_power->IsHit(px, py))
964 - LAppDelegate::GetInstance()->AppEnd();
969 float LAppView::TransformViewX(float deviceX) const
971 float screenX = _deviceToScreen->TransformX(deviceX); // 論理座標変換した座標を取得。
972 @@ -362,32 +287,4 @@ void LAppView::ResizeSprite()
973 _back->ResetRect(x, y, fWidth, fHeight);
979 - GLuint id = _power->GetTextureId();
980 - LAppTextureManager::TextureInfo* texInfo = textureManager->GetTextureInfoById(id);
983 - x = static_cast<float>(width - texInfo->width * 0.5f);
984 - y = static_cast<float>(texInfo->height * 0.5f);
985 - fWidth = static_cast<float>(texInfo->width);
986 - fHeight = static_cast<float>(texInfo->height);
987 - _power->ResetRect(x, y, fWidth, fHeight);
993 - GLuint id = _gear->GetTextureId();
994 - LAppTextureManager::TextureInfo* texInfo = textureManager->GetTextureInfoById(id);
997 - x = static_cast<float>(width - texInfo->width * 0.5f);
998 - y = static_cast<float>(height - texInfo->height * 0.5f);
999 - fWidth = static_cast<float>(texInfo->width);
1000 - fHeight = static_cast<float>(texInfo->height);
1001 - _gear->ResetRect(x, y, fWidth, fHeight);
1005 diff -pruN --exclude build ./demo_clean/src/LAppView.hpp ./demo_dev/src/LAppView.hpp
1006 --- ./demo_clean/src/LAppView.hpp 2020-10-01 22:47:25.846828066 +0100
1007 +++ ./demo_dev/src/LAppView.hpp 2020-10-01 22:47:24.802846999 +0100
1009 #include "CubismFramework.hpp"
1010 #include <Rendering/OpenGL/CubismOffscreenSurface_OpenGLES2.hpp>
1012 -class TouchManager;
1016 @@ -66,30 +65,6 @@ public:
1017 void ResizeSprite();
1020 - * @brief タッチされたときに呼ばれる。
1022 - * @param[in] pointX スクリーンX座標
1023 - * @param[in] pointY スクリーンY座標
1025 - void OnTouchesBegan(float pointX, float pointY) const;
1028 - * @brief タッチしているときにポインタが動いたら呼ばれる。
1030 - * @param[in] pointX スクリーンX座標
1031 - * @param[in] pointY スクリーンY座標
1033 - void OnTouchesMoved(float pointX, float pointY) const;
1036 - * @brief タッチが終了したら呼ばれる。
1038 - * @param[in] pointX スクリーンX座標
1039 - * @param[in] pointY スクリーンY座標
1041 - void OnTouchesEnded(float pointX, float pointY) const;
1044 * @brief X座標をView座標に変換する。
1046 * @param[in] deviceX デバイスX座標
1047 @@ -147,13 +122,10 @@ public:
1048 void SetRenderTargetClearColor(float r, float g, float b);
1051 - TouchManager* _touchManager; ///< タッチマネージャー
1052 Csm::CubismMatrix44* _deviceToScreen; ///< デバイスからスクリーンへの行列
1053 Csm::CubismViewMatrix* _viewMatrix; ///< viewMatrix
1054 GLuint _programId; ///< シェーダID
1055 LAppSprite* _back; ///< 背景画像
1056 - LAppSprite* _gear; ///< ギア画像
1057 - LAppSprite* _power; ///< 電源画像
1059 // レンダリング先を別ターゲットにする方式の場合に使用
1060 LAppSprite* _renderSprite; ///< モードによっては_renderBufferのテクスチャを描画
1061 diff -pruN --exclude build ./demo_clean/src/main.cpp ./demo_dev/src/main.cpp
1062 --- ./demo_clean/src/main.cpp 2020-10-01 22:47:25.846828066 +0100
1063 +++ ./demo_dev/src/main.cpp 2020-10-18 07:03:46.194220443 +0100
1065 * that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html.
1069 +#include <stdexcept>
1075 +#ifdef __cpp_lib_filesystem
1076 +#include <filesystem>
1077 +namespace fs = std::filesystem;
1079 +#include <experimental/filesystem>
1080 +namespace fs = std::experimental::filesystem;
1083 +#include "ICubismModelSetting.hpp"
1084 #include "LAppDelegate.hpp"
1085 +#include "LAppLive2DManager.hpp"
1086 +#include "LAppModel.hpp"
1087 +#include "mouse_cursor_tracker.h"
1093 + std::string windowTitle;
1094 + std::string rootDir;
1095 + float scaleFactor;
1098 + std::string modelName;
1099 + std::string cfgPath; // Path to config file for MouseCursorTracker
1102 +CmdArgs parseArgv(int argc, char *argv[])
1104 + // I think the command-line args are simple enough to not justify using a library...
1106 + // Set default values
1107 + cmdArgs.windowWidth = 600;
1108 + cmdArgs.windowHeight = 600;
1109 + cmdArgs.windowTitle = "MouseTrackerForCubism example";
1110 + cmdArgs.rootDir = fs::current_path();
1111 + cmdArgs.scaleFactor = 8.0f;
1112 + cmdArgs.translateX = 0.0f;
1113 + cmdArgs.translateY = -2.8f;
1114 + cmdArgs.modelName = "Haru";
1115 + cmdArgs.cfgPath = "";
1120 + std::string arg = argv[i];
1121 + std::stringstream ss;
1123 + if (arg == "--window-width" || arg == "-W") // capital W for consistency with height
1125 + ss << argv[i + 1];
1126 + if (!(ss >> cmdArgs.windowWidth))
1128 + throw std::runtime_error("Invalid argument for window width");
1131 + else if (arg == "--window-height" || arg == "-H") // avoiding "-h", typically for help
1133 + ss << argv[i + 1];
1134 + if (!(ss >> cmdArgs.windowHeight))
1136 + throw std::runtime_error("Invalid argument for window height");
1139 + else if (arg == "--window-title" || arg == "-t")
1141 + cmdArgs.windowTitle = argv[i + 1];
1143 + else if (arg == "--root-dir" || arg == "-d")
1145 + cmdArgs.rootDir = argv[i + 1];
1147 + else if (arg == "--scale-factor" || arg == "-f")
1149 + ss << argv[i + 1];
1150 + if (!(ss >> cmdArgs.scaleFactor))
1152 + throw std::runtime_error("Invalid argument for scale factor");
1155 + else if (arg == "--translate-x" || arg == "-x")
1157 + ss << argv[i + 1];
1158 + if (!(ss >> cmdArgs.translateX))
1160 + throw std::runtime_error("Invalid argument for translate X");
1163 + else if (arg == "--translate-y" || arg == "-y")
1165 + ss << argv[i + 1];
1166 + if (!(ss >> cmdArgs.translateY))
1168 + throw std::runtime_error("Invalid argument for translate Y");
1171 + else if (arg == "--model" || arg == "-m")
1173 + cmdArgs.modelName = argv[i + 1];
1175 + else if (arg == "--config" || arg == "-c")
1177 + cmdArgs.cfgPath = argv[i + 1];
1181 + throw std::runtime_error("Unrecognized argument: " + arg);
1190 int main(int argc, char* argv[])
1192 - // create the application instance
1193 - if (LAppDelegate::GetInstance()->Initialize() == GL_FALSE)
1194 + auto cmdArgs = parseArgv(argc, argv);
1196 + LAppDelegate *delegate = LAppDelegate::GetInstance();
1198 + if (!delegate->Initialize(cmdArgs.windowWidth,
1199 + cmdArgs.windowHeight,
1200 + cmdArgs.windowTitle.c_str()))
1203 + throw std::runtime_error("Unable to initialize LAppDelegate");
1206 - LAppDelegate::GetInstance()->Run();
1207 + delegate->SetRootDirectory(cmdArgs.rootDir);
1209 + LAppLive2DManager *manager = LAppLive2DManager::GetInstance();
1210 + manager->SetModel(cmdArgs.modelName);
1212 + manager->SetProjectionScaleTranslate(cmdArgs.scaleFactor,
1213 + cmdArgs.translateX,
1214 + cmdArgs.translateY);
1216 + LAppModel *model = manager->GetModel(0);
1217 + if (!model) throw std::runtime_error("model is null");
1219 + Live2D::Cubism::Framework::ICubismModelSetting *modelSetting = model->GetModelSetting();
1220 + if (!modelSetting) throw std::runtime_error("modelSetting is null");
1222 + std::vector<std::pair<std::string, int> > motions;
1223 + int motionGroupCount = modelSetting->GetMotionGroupCount();
1224 + for (int i = 0; i < motionGroupCount; i++)
1226 + const char *motionGroup = modelSetting->GetMotionGroupName(i);
1227 + int motionCount = modelSetting->GetMotionCount(motionGroup);
1228 + motions.push_back(std::make_pair(std::string(motionGroup), motionCount));
1231 + std::vector<std::string> expressions;
1232 + int expCount = modelSetting->GetExpressionCount();
1233 + for (int i = 0; i < expCount; i++)
1235 + const char *expName = modelSetting->GetExpressionName(i);
1236 + expressions.push_back(std::string(expName));
1239 + MouseCursorTracker tracker(cmdArgs.cfgPath, motions, expressions);
1241 + std::thread trackerThread(&MouseCursorTracker::mainLoop, &tracker);
1242 + manager->SetTracker(&tracker);
1247 + trackerThread.join();