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 11:11:14.995691070 +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 @@ -64,6 +64,11 @@ target_link_libraries(Framework Live2DCu
23 # Find opengl libraries.
24 find_package(OpenGL REQUIRED)
26 +# Add MouseTrackerForCubism
27 +find_package(PkgConfig)
28 +pkg_check_modules(GTKMM gtkmm-3.0)
29 +add_subdirectory(../.. MouseTrackerForCubism_build)
31 # Make executable app.
32 add_executable(${APP_NAME})
34 @@ -73,9 +78,20 @@ target_link_libraries(${APP_NAME}
38 + MouseTrackerForCubism
41 # Specify include directories.
42 -target_include_directories(${APP_NAME} PRIVATE ${STB_PATH})
43 +target_include_directories(${APP_NAME} PRIVATE ${STB_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/../../include ${GTKMM_INCLUDE_DIRS})
45 +# Copy GUI to build directory
51 + copy ${CMAKE_CURRENT_SOURCE_DIR}/../../src/gui.glade $<TARGET_FILE_DIR:${APP_NAME}>/gui.glade
54 # Copy resource directory to build directory.
56 diff -pruN --exclude build ./demo_clean/scripts/make_gcc ./demo_dev/scripts/make_gcc
57 --- ./demo_clean/scripts/make_gcc 2020-10-01 22:47:25.854827921 +0100
58 +++ ./demo_dev/scripts/make_gcc 2021-01-01 11:34:25.583684883 +0000
59 @@ -10,4 +10,4 @@ BUILD_PATH=$SCRIPT_PATH/../build/make_gc
60 cmake -S "$CMAKE_PATH" \
62 -D CMAKE_BUILD_TYPE=Release
63 -cd "$BUILD_PATH" && make
64 +cd "$BUILD_PATH" && make -j4
65 diff -pruN --exclude build ./demo_clean/src/CMakeLists.txt ./demo_dev/src/CMakeLists.txt
66 --- ./demo_clean/src/CMakeLists.txt 2020-10-01 22:47:25.850827994 +0100
67 +++ ./demo_dev/src/CMakeLists.txt 2020-10-01 22:47:24.842846271 +0100
68 @@ -19,6 +19,4 @@ target_sources(${APP_NAME}
69 ${CMAKE_CURRENT_SOURCE_DIR}/LAppView.cpp
70 ${CMAKE_CURRENT_SOURCE_DIR}/LAppView.hpp
71 ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp
72 - ${CMAKE_CURRENT_SOURCE_DIR}/TouchManager.cpp
73 - ${CMAKE_CURRENT_SOURCE_DIR}/TouchManager.hpp
75 diff -pruN --exclude build ./demo_clean/src/LAppDefine.cpp ./demo_dev/src/LAppDefine.cpp
76 --- ./demo_clean/src/LAppDefine.cpp 2020-10-01 22:47:25.850827994 +0100
77 +++ ./demo_dev/src/LAppDefine.cpp 2020-10-18 04:59:13.238452938 +0100
78 @@ -61,11 +61,11 @@ namespace LAppDefine {
79 const csmInt32 PriorityForce = 3;
82 - const csmBool DebugLogEnable = true;
83 + const csmBool DebugLogEnable = false;
84 const csmBool DebugTouchLogEnable = false;
86 // Frameworkから出力するログのレベル設定
87 - const CubismFramework::Option::LogLevel CubismLoggingLevel = CubismFramework::Option::LogLevel_Verbose;
88 + const CubismFramework::Option::LogLevel CubismLoggingLevel = CubismFramework::Option::LogLevel_Warning;
91 const csmInt32 RenderTargetWidth = 1900;
92 diff -pruN --exclude build ./demo_clean/src/LAppDelegate.cpp ./demo_dev/src/LAppDelegate.cpp
93 --- ./demo_clean/src/LAppDelegate.cpp 2020-10-01 22:47:25.850827994 +0100
94 +++ ./demo_dev/src/LAppDelegate.cpp 2020-10-01 22:47:24.698848890 +0100
95 @@ -45,7 +45,8 @@ void LAppDelegate::ReleaseInstance()
99 -bool LAppDelegate::Initialize()
100 +bool LAppDelegate::Initialize(int initWindowWidth, int initWindowHeight,
101 + const char *windowTitle)
105 @@ -63,7 +64,13 @@ bool LAppDelegate::Initialize()
109 - _window = glfwCreateWindow(RenderTargetWidth, RenderTargetHeight, "SAMPLE", NULL, NULL);
110 + _window = glfwCreateWindow(
111 + initWindowWidth ? initWindowWidth : RenderTargetWidth,
112 + initWindowHeight ? initWindowHeight : RenderTargetHeight,
113 + windowTitle ? windowTitle : "SAMPLE",
120 @@ -95,10 +102,6 @@ bool LAppDelegate::Initialize()
122 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
125 - glfwSetMouseButtonCallback(_window, EventHandler::OnMouseCallBack);
126 - glfwSetCursorPosCallback(_window, EventHandler::OnMouseCallBack);
130 glfwGetWindowSize(LAppDelegate::GetInstance()->GetWindow(), &width, &height);
131 @@ -111,8 +114,6 @@ bool LAppDelegate::Initialize()
135 - SetRootDirectory();
138 LAppLive2DManager::GetInstance();
140 @@ -214,49 +215,6 @@ void LAppDelegate::InitializeCubism()
141 LAppPal::UpdateTime();
144 -void LAppDelegate::OnMouseCallBack(GLFWwindow* window, int button, int action, int modify)
150 - if (GLFW_MOUSE_BUTTON_LEFT != button)
155 - if (GLFW_PRESS == action)
158 - _view->OnTouchesBegan(_mouseX, _mouseY);
160 - else if (GLFW_RELEASE == action)
165 - _view->OnTouchesEnded(_mouseX, _mouseY);
170 -void LAppDelegate::OnMouseCallBack(GLFWwindow* window, double x, double y)
172 - _mouseX = static_cast<float>(x);
173 - _mouseY = static_cast<float>(y);
184 - _view->OnTouchesMoved(_mouseX, _mouseY);
187 GLuint LAppDelegate::CreateShader()
190 @@ -299,29 +257,9 @@ GLuint LAppDelegate::CreateShader()
194 -void LAppDelegate::SetRootDirectory()
195 +void LAppDelegate::SetRootDirectory(std::string rootDir)
198 - ssize_t len = readlink("/proc/self/exe", path, 1024 - 1);
205 - std::string pathString(path);
207 - pathString = pathString.substr(0, pathString.rfind("Demo"));
208 - Csm::csmVector<string> splitStrings = this->Split(pathString, '/');
210 - this->_rootDirectory = "";
212 - for(int i = 0; i < splitStrings.GetSize(); i++)
214 - this->_rootDirectory = this->_rootDirectory + "/" +splitStrings[i];
217 - this->_rootDirectory += "/";
218 + this->_rootDirectory = rootDir + "/";
221 Csm::csmVector<string> LAppDelegate::Split(const std::string& baseString, char delimiter)
222 diff -pruN --exclude build ./demo_clean/src/LAppDelegate.hpp ./demo_dev/src/LAppDelegate.hpp
223 --- ./demo_clean/src/LAppDelegate.hpp 2020-10-01 22:47:25.850827994 +0100
224 +++ ./demo_dev/src/LAppDelegate.hpp 2020-10-01 22:47:24.842846271 +0100
225 @@ -40,7 +40,8 @@ public:
227 * @brief APPに必要なものを初期化する。
230 + bool Initialize(int initWindowWidth = 0, int initWindowHeight = 0,
231 + const char *windowTitle = "SAMPLE");
235 @@ -53,25 +54,6 @@ public:
239 - * @brief OpenGL用 glfwSetMouseButtonCallback用関数。
241 - * @param[in] window コールバックを呼んだWindow情報
242 - * @param[in] button ボタン種類
243 - * @param[in] action 実行結果
244 - * @param[in] modify
246 - void OnMouseCallBack(GLFWwindow* window, int button, int action, int modify);
249 - * @brief OpenGL用 glfwSetCursorPosCallback用関数。
251 - * @param[in] window コールバックを呼んだWindow情報
255 - void OnMouseCallBack(GLFWwindow* window, double x, double y);
260 GLuint CreateShader();
261 @@ -98,8 +80,10 @@ public:
264 * @brief ルートディレクトリを設定する。
266 + * @param[in] rootDir : The root directory to set to.
268 - void SetRootDirectory();
269 + void SetRootDirectory(std::string rootDir);
272 * @brief ルートディレクトリを取得する。
273 @@ -146,24 +130,3 @@ private:
274 int _windowWidth; ///< Initialize関数で設定したウィンドウ幅
275 int _windowHeight; ///< Initialize関数で設定したウィンドウ高さ
282 - * @brief glfwSetMouseButtonCallback用コールバック関数。
284 - static void OnMouseCallBack(GLFWwindow* window, int button, int action, int modify)
286 - LAppDelegate::GetInstance()->OnMouseCallBack(window, button, action, modify);
290 - * @brief glfwSetCursorPosCallback用コールバック関数。
292 - static void OnMouseCallBack(GLFWwindow* window, double x, double y)
294 - LAppDelegate::GetInstance()->OnMouseCallBack(window, x, y);
298 diff -pruN --exclude build ./demo_clean/src/LAppLive2DManager.cpp ./demo_dev/src/LAppLive2DManager.cpp
299 --- ./demo_clean/src/LAppLive2DManager.cpp 2020-10-01 22:47:25.850827994 +0100
300 +++ ./demo_dev/src/LAppLive2DManager.cpp 2020-10-02 02:00:49.961556700 +0100
301 @@ -52,9 +52,10 @@ void LAppLive2DManager::ReleaseInstance(
303 LAppLive2DManager::LAppLive2DManager()
306 + , _projScaleFactor(1.0f)
307 + , _translateX(0.0f)
308 + , _translateY(0.0f)
310 - ChangeScene(_sceneIndex);
313 LAppLive2DManager::~LAppLive2DManager()
314 @@ -98,26 +99,6 @@ void LAppLive2DManager::OnTap(csmFloat32
316 LAppPal::PrintLog("[APP]tap point: {x:%.2f y:%.2f}", x, y);
319 - for (csmUint32 i = 0; i < _models.GetSize(); i++)
321 - if (_models[i]->HitTest(HitAreaNameHead, x, y))
323 - if (DebugLogEnable)
325 - LAppPal::PrintLog("[APP]hit area: [%s]", HitAreaNameHead);
327 - _models[i]->SetRandomExpression();
329 - else if (_models[i]->HitTest(HitAreaNameBody, x, y))
331 - if (DebugLogEnable)
333 - LAppPal::PrintLog("[APP]hit area: [%s]", HitAreaNameBody);
335 - _models[i]->StartRandomMotion(MotionGroupTapBody, PriorityNormal, FinishedMotion);
340 void LAppLive2DManager::OnUpdate() const
341 @@ -125,7 +106,9 @@ void LAppLive2DManager::OnUpdate() const
342 CubismMatrix44 projection;
344 glfwGetWindowSize(LAppDelegate::GetInstance()->GetWindow(), &width, &height);
345 - projection.Scale(1.0f, static_cast<float>(width) / static_cast<float>(height));
346 + projection.Scale(_projScaleFactor,
347 + _projScaleFactor * static_cast<float>(width) / static_cast<float>(height));
348 + projection.Translate(_translateX, _translateY);
350 if (_viewMatrix != NULL)
352 @@ -148,26 +131,10 @@ void LAppLive2DManager::OnUpdate() const
356 -void LAppLive2DManager::NextScene()
358 - csmInt32 no = (_sceneIndex + 1) % ModelDirSize;
362 -void LAppLive2DManager::ChangeScene(Csm::csmInt32 index)
363 +void LAppLive2DManager::SetModel(std::string modelName)
365 - _sceneIndex = index;
366 - if (DebugLogEnable)
368 - LAppPal::PrintLog("[APP]model index: %d", _sceneIndex);
371 - // ModelDir[]に保持したディレクトリ名から
372 - // model3.jsonのパスを決定する.
373 - // ディレクトリ名とmodel3.jsonの名前を一致させておくこと.
374 - std::string model = ModelDir[index];
375 - std::string modelPath = LAppDelegate::GetInstance()->GetRootDirectory() + ResourcesPath + model + "/";
376 - std::string modelJsonName = ModelDir[index];
377 + std::string modelPath = LAppDelegate::GetInstance()->GetRootDirectory() + ResourcesPath + modelName + "/";
378 + std::string modelJsonName = modelName;
379 modelJsonName += ".model3.json";
382 @@ -215,3 +182,20 @@ csmUint32 LAppLive2DManager::GetModelNum
384 return _models.GetSize();
387 +void LAppLive2DManager::SetTracker(MouseCursorTracker *tracker)
389 + for (auto it = _models.Begin(); it != _models.End(); ++it)
391 + (*it)->SetTracker(tracker);
395 +void LAppLive2DManager::SetProjectionScaleTranslate(float scaleFactor,
399 + _projScaleFactor = scaleFactor;
400 + _translateX = translateX;
401 + _translateY = translateY;
403 diff -pruN --exclude build ./demo_clean/src/LAppLive2DManager.hpp ./demo_dev/src/LAppLive2DManager.hpp
404 --- ./demo_clean/src/LAppLive2DManager.hpp 2020-10-01 22:47:25.846828066 +0100
405 +++ ./demo_dev/src/LAppLive2DManager.hpp 2020-10-01 23:36:24.583055381 +0100
411 #include <CubismFramework.hpp>
412 #include <Math/CubismMatrix44.hpp>
413 #include <Type/csmVector.hpp>
417 +class MouseCursorTracker;
420 * @brief サンプルアプリケーションにおいてCubismModelを管理するクラス<br>
421 * モデル生成と破棄、タップイベントの処理、モデル切り替えを行う。
422 @@ -72,16 +75,12 @@ public:
423 void OnUpdate() const;
426 - * @brief 次のシーンに切り替える<br>
427 - * サンプルアプリケーションではモデルセットの切り替えを行う。
432 - * @brief シーンを切り替える<br>
433 - * サンプルアプリケーションではモデルセットの切り替えを行う。
435 - void ChangeScene(Csm::csmInt32 index);
436 + * @brief Set model data
438 + * @param[in] modelName : Name of model, should be the same for both
439 + * the directory and the model3.json file
441 + void SetModel(std::string modelName);
445 @@ -89,6 +88,24 @@ public:
447 Csm::csmUint32 GetModelNum() const;
450 + * @brief Set the pointer to the MouseCursorTracker instance
452 + * @param[in] tracker : Pointer to MouseCursorTracker instance
454 + void SetTracker(MouseCursorTracker *tracker);
457 + * @brief Set projection scale factor and translation parameters
459 + * @param[in] scaleFactor : Scale factor applied in both X and Y directions
460 + * @param[in] translateX : Translation in X direction
461 + * @param[in] translateY : Translation in Y direction
463 + void SetProjectionScaleTranslate(float scaleFactor,
470 @@ -102,5 +119,8 @@ private:
472 Csm::CubismMatrix44* _viewMatrix; ///< モデル描画に用いるView行列
473 Csm::csmVector<LAppModel*> _models; ///< モデルインスタンスのコンテナ
474 - Csm::csmInt32 _sceneIndex; ///< 表示するシーンのインデックス値
476 + float _projScaleFactor;
480 diff -pruN --exclude build ./demo_clean/src/LAppModel.cpp ./demo_dev/src/LAppModel.cpp
481 --- ./demo_clean/src/LAppModel.cpp 2020-10-01 22:47:25.850827994 +0100
482 +++ ./demo_dev/src/LAppModel.cpp 2020-10-18 09:26:08.998822685 +0100
484 #include "LAppTextureManager.hpp"
485 #include "LAppDelegate.hpp"
487 +#include "mouse_cursor_tracker.h"
491 using namespace Live2D::Cubism::Framework;
492 using namespace Live2D::Cubism::Framework::DefaultParameterId;
493 using namespace LAppDefine;
494 @@ -49,6 +53,7 @@ LAppModel::LAppModel()
496 , _modelSetting(NULL)
497 , _userTimeSeconds(0.0f)
498 + , _tracker(nullptr)
502 @@ -335,59 +340,110 @@ void LAppModel::Update()
503 const csmFloat32 deltaTimeSeconds = LAppPal::GetDeltaTime();
504 _userTimeSeconds += deltaTimeSeconds;
506 - _dragManager->Update(deltaTimeSeconds);
507 - _dragX = _dragManager->GetX();
508 - _dragY = _dragManager->GetY();
510 - // モーションによるパラメータ更新の有無
511 - csmBool motionUpdated = false;
513 - //-----------------------------------------------------------------
514 - _model->LoadParameters(); // 前回セーブされた状態をロード
515 - if (_motionManager->IsFinished())
517 - // モーションの再生がない場合、待機モーションの中からランダムで再生する
518 - StartRandomMotion(MotionGroupIdle, PriorityIdle);
523 - motionUpdated = _motionManager->UpdateMotion(_model, deltaTimeSeconds); // モーションを更新
525 - _model->SaveParameters(); // 状態を保存
526 - //-----------------------------------------------------------------
527 + auto idMan = CubismFramework::GetIdManager();
528 + auto params = _tracker->getParams();
531 - if (!motionUpdated)
533 - if (_eyeBlink != NULL)
534 + _model->LoadParameters(); // 前回セーブされた状態をロード
536 + int paramsMotionPriority = static_cast<int>(params.motionPriority);
538 + if (paramsMotionPriority != PriorityNone)
540 - // メインモーションの更新がないとき
541 - _eyeBlink->UpdateParameters(_model, deltaTimeSeconds); // 目パチ
542 + StartMotion(params.motionGroup.c_str(), params.motionNumber,
543 + paramsMotionPriority);
545 + else if (params.randomIdleMotion && _motionManager->IsFinished())
547 + // モーションの再生がない場合、待機モーションの中からランダムで再生する
548 + StartRandomMotion(MotionGroupIdle, PriorityIdle);
552 - if (_expressionManager != NULL)
554 - _expressionManager->UpdateMotion(_model, deltaTimeSeconds); // 表情でパラメータ更新(相対変化)
556 + // FIXME pose does not return to normal after motion
557 + // if we don't have randomIdleMotion set
560 + _motionManager->UpdateMotion(_model, deltaTimeSeconds); // モーションを更新
562 + _model->SaveParameters(); // 状態を保存
566 - _model->AddParameterValue(_idParamAngleX, _dragX * 30); // -30から30の値を加える
567 - _model->AddParameterValue(_idParamAngleY, _dragY * 30);
568 - _model->AddParameterValue(_idParamAngleZ, _dragX * _dragY * -30);
569 + if (params.expression != "")
571 + SetExpression(params.expression.c_str());
573 + if (_expressionManager != NULL)
575 + _expressionManager->UpdateMotion(_model, deltaTimeSeconds); // 表情でパラメータ更新(相対変化)
579 - _model->AddParameterValue(_idParamBodyAngleX, _dragX * 10); // -10から10の値を加える
580 + bool autoBlink = params.autoBlink && _eyeBlink;
581 + auto eyeLOpenIt = params.live2d.find("ParamEyeLOpen");
582 + auto eyeROpenIt = params.live2d.find("ParamEyeROpen");
585 - _model->AddParameterValue(_idParamEyeBallX, _dragX); // -1から1の値を加える
586 - _model->AddParameterValue(_idParamEyeBallY, _dragY);
589 + // Handle blink first
590 + _eyeBlink->UpdateParameters(_model, deltaTimeSeconds);
594 - if (_breath != NULL)
596 - _breath->UpdateParameters(_model, deltaTimeSeconds);
597 + if (eyeLOpenIt != params.live2d.end())
599 + // If value specified, override blinking
600 + _model->SetParameterValue(idMan->GetId("ParamEyeLOpen"),
601 + eyeLOpenIt->second);
603 + else if (!autoBlink)
605 + // If no value specified and no auto blink, set to 1
606 + _model->SetParameterValue(idMan->GetId("ParamEyeLOpen"), 1);
610 + if (eyeROpenIt != params.live2d.end())
612 + _model->SetParameterValue(idMan->GetId("ParamEyeROpen"),
613 + eyeROpenIt->second);
615 + else if (!autoBlink)
617 + _model->SetParameterValue(idMan->GetId("ParamEyeROpen"), 1);
621 + if (params.useLipSync && _lipSync)
623 + csmFloat32 value = params.lipSyncParam; // 0 to 1
625 + for (csmUint32 i = 0; i < _lipSyncIds.GetSize(); ++i)
627 + _model->AddParameterValue(_lipSyncIds[i], value, 0.8f);
632 + _model->SetParameterValue(idMan->GetId("ParamMouthOpenY"),
633 + params.live2d["ParamMouthOpenY"]);
636 + for (auto const &entry : params.live2d)
638 + std::string key = entry.first;
639 + double val = entry.second;
641 + if (key != "ParamEyeLOpen" && key != "ParamEyeROpen" &&
642 + key != "ParamMouthOpenY")
644 + _model->SetParameterValue(idMan->GetId(key.c_str()), val);
648 + if (params.autoBreath && _breath)
650 + // Note: _model->LoadParameters and SaveParameters is needed
651 + // before - see above.
652 + _breath->UpdateParameters(_model, deltaTimeSeconds);
657 @@ -396,17 +452,6 @@ void LAppModel::Update()
658 _physics->Evaluate(_model, deltaTimeSeconds);
664 - csmFloat32 value = 0; // リアルタイムでリップシンクを行う場合、システムから音量を取得して0〜1の範囲で値を入力します。
666 - for (csmUint32 i = 0; i < _lipSyncIds.GetSize(); ++i)
668 - _model->AddParameterValue(_lipSyncIds[i], value, 0.8f);
675 @@ -626,3 +671,14 @@ Csm::Rendering::CubismOffscreenFrame_Ope
677 return _renderBuffer;
680 +void LAppModel::SetTracker(MouseCursorTracker *tracker)
682 + _tracker = tracker;
685 +Csm::ICubismModelSetting* LAppModel::GetModelSetting(void) const
687 + return _modelSetting;
690 diff -pruN --exclude build ./demo_clean/src/LAppModel.hpp ./demo_dev/src/LAppModel.hpp
691 --- ./demo_clean/src/LAppModel.hpp 2020-10-01 22:47:25.850827994 +0100
692 +++ ./demo_dev/src/LAppModel.hpp 2020-10-18 03:04:52.142045751 +0100
694 #include <Type/csmRectF.hpp>
695 #include <Rendering/OpenGL/CubismOffscreenSurface_OpenGLES2.hpp>
697 +#include "mouse_cursor_tracker.h"
700 * @brief ユーザーが実際に使用するモデルの実装クラス<br>
701 @@ -113,6 +114,15 @@ public:
703 Csm::Rendering::CubismOffscreenFrame_OpenGLES2& GetRenderBuffer();
706 + * @brief Set the pointer to the MouseCursorTracker instance
708 + * @param[in] tracker : Pointer to MouseCursorTracker instance
710 + void SetTracker(MouseCursorTracker *tracker);
712 + Csm::ICubismModelSetting* GetModelSetting(void) const;
716 * @brief モデルを描画する処理。モデルを描画する空間のView-Projection行列を渡す。
717 @@ -183,6 +193,8 @@ private:
718 const Csm::CubismId* _idParamEyeBallY; ///< パラメータID: ParamEyeBallXY
720 Csm::Rendering::CubismOffscreenFrame_OpenGLES2 _renderBuffer; ///< フレームバッファ以外の描画先
722 + MouseCursorTracker *_tracker;
726 diff -pruN --exclude build ./demo_clean/src/LAppPal.cpp ./demo_dev/src/LAppPal.cpp
727 --- ./demo_clean/src/LAppPal.cpp 2020-10-01 22:47:25.850827994 +0100
728 +++ ./demo_dev/src/LAppPal.cpp 2020-10-18 04:57:43.289600308 +0100
732 #include "LAppPal.hpp"
733 +#include <stdexcept>
737 @@ -36,7 +37,6 @@ csmByte* LAppPal::LoadFileAsBytes(const
738 if (stat(path, &statBuf) == 0)
740 size = statBuf.st_size;
745 @@ -45,10 +45,7 @@ csmByte* LAppPal::LoadFileAsBytes(const
746 file.open(path, std::ios::in | std::ios::binary);
749 - if (DebugLogEnable)
751 - PrintLog("file open error");
753 + throw std::runtime_error("Failed to open file " + filePath);
756 file.read(buf, size);
757 diff -pruN --exclude build ./demo_clean/src/LAppTextureManager.cpp ./demo_dev/src/LAppTextureManager.cpp
758 --- ./demo_clean/src/LAppTextureManager.cpp 2020-10-01 22:47:25.850827994 +0100
759 +++ ./demo_dev/src/LAppTextureManager.cpp 2020-10-01 22:47:24.654849690 +0100
760 @@ -96,6 +96,46 @@ LAppTextureManager::TextureInfo* LAppTex
764 +LAppTextureManager::TextureInfo* LAppTextureManager::CreateTextureFromColor(
765 + uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha
768 + int width = 8, height = 8;
770 + uint8_t pixels[height][width][4];
771 + for (std::size_t h = 0; h < height; h++)
773 + for (std::size_t w = 0; w < width; w++)
775 + pixels[h][w][0] = red;
776 + pixels[h][w][1] = green;
777 + pixels[h][w][2] = blue;
778 + pixels[h][w][3] = alpha;
783 + glGenTextures(1, &textureId);
784 + glBindTexture(GL_TEXTURE_2D, textureId);
785 + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
787 + glGenerateMipmap(GL_TEXTURE_2D);
788 + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
789 + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
790 + glBindTexture(GL_TEXTURE_2D, 0);
793 + LAppTextureManager::TextureInfo* textureInfo = new LAppTextureManager::TextureInfo();
794 + textureInfo->fileName = "";
795 + textureInfo->width = width;
796 + textureInfo->height = height;
797 + textureInfo->id = textureId;
799 + _textures.PushBack(textureInfo);
801 + return textureInfo;
804 void LAppTextureManager::ReleaseTextures()
806 for (Csm::csmUint32 i = 0; i < _textures.GetSize(); i++)
807 diff -pruN --exclude build ./demo_clean/src/LAppTextureManager.hpp ./demo_dev/src/LAppTextureManager.hpp
808 --- ./demo_clean/src/LAppTextureManager.hpp 2020-10-01 22:47:25.846828066 +0100
809 +++ ./demo_dev/src/LAppTextureManager.hpp 2020-10-01 22:47:24.786847290 +0100
810 @@ -72,6 +72,8 @@ public:
812 TextureInfo* CreateTextureFromPngFile(std::string fileName);
814 + TextureInfo *CreateTextureFromColor(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha = 255);
819 diff -pruN --exclude build ./demo_clean/src/LAppView.cpp ./demo_dev/src/LAppView.cpp
820 --- ./demo_clean/src/LAppView.cpp 2020-10-01 22:47:25.850827994 +0100
821 +++ ./demo_dev/src/LAppView.cpp 2020-10-01 22:47:24.602850636 +0100
823 #include "LAppLive2DManager.hpp"
824 #include "LAppTextureManager.hpp"
825 #include "LAppDefine.hpp"
826 -#include "TouchManager.hpp"
827 #include "LAppSprite.hpp"
828 #include "LAppModel.hpp"
830 @@ -26,8 +25,6 @@ using namespace LAppDefine;
831 LAppView::LAppView():
837 _renderTarget(SelectTarget_None)
839 @@ -35,8 +32,6 @@ LAppView::LAppView():
840 _clearColor[1] = 1.0f;
841 _clearColor[2] = 1.0f;
842 _clearColor[3] = 0.0f;
844 - _touchManager = new TouchManager();
846 // デバイス座標からスクリーン座標に変換するための
847 _deviceToScreen = new CubismMatrix44();
848 @@ -52,10 +47,7 @@ LAppView::~LAppView()
851 delete _deviceToScreen;
852 - delete _touchManager;
858 void LAppView::Initialize()
859 @@ -97,9 +89,6 @@ void LAppView::Initialize()
860 void LAppView::Render()
867 LAppLive2DManager* Live2DManager = LAppLive2DManager::GetInstance();
869 @@ -139,35 +128,17 @@ void LAppView::InitializeSprite()
870 glfwGetWindowSize(LAppDelegate::GetInstance()->GetWindow(), &width, &height);
872 LAppTextureManager* textureManager = LAppDelegate::GetInstance()->GetTextureManager();
873 - const string resourcesPath = LAppDelegate::GetInstance()->GetRootDirectory() + ResourcesPath;
875 - string imageName = BackImageName;
876 - LAppTextureManager::TextureInfo* backgroundTexture = textureManager->CreateTextureFromPngFile(resourcesPath + imageName);
878 + LAppTextureManager::TextureInfo* backgroundTexture =
879 + textureManager->CreateTextureFromColor(0, 255, 0);
881 float x = width * 0.5f;
882 float y = height * 0.5f;
883 - float fWidth = static_cast<float>(backgroundTexture->width * 2.0f);
884 - float fHeight = static_cast<float>(height) * 0.95f;
885 + float fWidth = static_cast<float>(width);
886 + float fHeight = static_cast<float>(height);
887 _back = new LAppSprite(x, y, fWidth, fHeight, backgroundTexture->id, _programId);
889 - imageName = GearImageName;
890 - LAppTextureManager::TextureInfo* gearTexture = textureManager->CreateTextureFromPngFile(resourcesPath + imageName);
892 - x = static_cast<float>(width - gearTexture->width * 0.5f);
893 - y = static_cast<float>(height - gearTexture->height * 0.5f);
894 - fWidth = static_cast<float>(gearTexture->width);
895 - fHeight = static_cast<float>(gearTexture->height);
896 - _gear = new LAppSprite(x, y, fWidth, fHeight, gearTexture->id, _programId);
898 - imageName = PowerImageName;
899 - LAppTextureManager::TextureInfo* powerTexture = textureManager->CreateTextureFromPngFile(resourcesPath + imageName);
901 - x = static_cast<float>(width - powerTexture->width * 0.5f);
902 - y = static_cast<float>(powerTexture->height * 0.5f);
903 - fWidth = static_cast<float>(powerTexture->width);
904 - fHeight = static_cast<float>(powerTexture->height);
905 - _power = new LAppSprite(x, y, fWidth, fHeight, powerTexture->id, _programId);
910 @@ -175,52 +146,6 @@ void LAppView::InitializeSprite()
914 -void LAppView::OnTouchesBegan(float px, float py) const
916 - _touchManager->TouchesBegan(px, py);
919 -void LAppView::OnTouchesMoved(float px, float py) const
921 - float viewX = this->TransformViewX(_touchManager->GetX());
922 - float viewY = this->TransformViewY(_touchManager->GetY());
924 - _touchManager->TouchesMoved(px, py);
926 - LAppLive2DManager* Live2DManager = LAppLive2DManager::GetInstance();
927 - Live2DManager->OnDrag(viewX, viewY);
930 -void LAppView::OnTouchesEnded(float px, float py) const
933 - LAppLive2DManager* live2DManager = LAppLive2DManager::GetInstance();
934 - live2DManager->OnDrag(0.0f, 0.0f);
938 - float x = _deviceToScreen->TransformX(_touchManager->GetX()); // 論理座標変換した座標を取得。
939 - float y = _deviceToScreen->TransformY(_touchManager->GetY()); // 論理座標変換した座標を取得。
940 - if (DebugTouchLogEnable)
942 - LAppPal::PrintLog("[APP]touchesEnded x:%.2f y:%.2f", x, y);
944 - live2DManager->OnTap(x, y);
947 - if (_gear->IsHit(px, py))
949 - live2DManager->NextScene();
953 - if (_power->IsHit(px, py))
955 - LAppDelegate::GetInstance()->AppEnd();
960 float LAppView::TransformViewX(float deviceX) const
962 float screenX = _deviceToScreen->TransformX(deviceX); // 論理座標変換した座標を取得。
963 @@ -362,32 +287,4 @@ void LAppView::ResizeSprite()
964 _back->ResetRect(x, y, fWidth, fHeight);
970 - GLuint id = _power->GetTextureId();
971 - LAppTextureManager::TextureInfo* texInfo = textureManager->GetTextureInfoById(id);
974 - x = static_cast<float>(width - texInfo->width * 0.5f);
975 - y = static_cast<float>(texInfo->height * 0.5f);
976 - fWidth = static_cast<float>(texInfo->width);
977 - fHeight = static_cast<float>(texInfo->height);
978 - _power->ResetRect(x, y, fWidth, fHeight);
984 - GLuint id = _gear->GetTextureId();
985 - LAppTextureManager::TextureInfo* texInfo = textureManager->GetTextureInfoById(id);
988 - x = static_cast<float>(width - texInfo->width * 0.5f);
989 - y = static_cast<float>(height - texInfo->height * 0.5f);
990 - fWidth = static_cast<float>(texInfo->width);
991 - fHeight = static_cast<float>(texInfo->height);
992 - _gear->ResetRect(x, y, fWidth, fHeight);
996 diff -pruN --exclude build ./demo_clean/src/LAppView.hpp ./demo_dev/src/LAppView.hpp
997 --- ./demo_clean/src/LAppView.hpp 2020-10-01 22:47:25.846828066 +0100
998 +++ ./demo_dev/src/LAppView.hpp 2020-10-01 22:47:24.802846999 +0100
1000 #include "CubismFramework.hpp"
1001 #include <Rendering/OpenGL/CubismOffscreenSurface_OpenGLES2.hpp>
1003 -class TouchManager;
1007 @@ -66,30 +65,6 @@ public:
1008 void ResizeSprite();
1011 - * @brief タッチされたときに呼ばれる。
1013 - * @param[in] pointX スクリーンX座標
1014 - * @param[in] pointY スクリーンY座標
1016 - void OnTouchesBegan(float pointX, float pointY) const;
1019 - * @brief タッチしているときにポインタが動いたら呼ばれる。
1021 - * @param[in] pointX スクリーンX座標
1022 - * @param[in] pointY スクリーンY座標
1024 - void OnTouchesMoved(float pointX, float pointY) const;
1027 - * @brief タッチが終了したら呼ばれる。
1029 - * @param[in] pointX スクリーンX座標
1030 - * @param[in] pointY スクリーンY座標
1032 - void OnTouchesEnded(float pointX, float pointY) const;
1035 * @brief X座標をView座標に変換する。
1037 * @param[in] deviceX デバイスX座標
1038 @@ -147,13 +122,10 @@ public:
1039 void SetRenderTargetClearColor(float r, float g, float b);
1042 - TouchManager* _touchManager; ///< タッチマネージャー
1043 Csm::CubismMatrix44* _deviceToScreen; ///< デバイスからスクリーンへの行列
1044 Csm::CubismViewMatrix* _viewMatrix; ///< viewMatrix
1045 GLuint _programId; ///< シェーダID
1046 LAppSprite* _back; ///< 背景画像
1047 - LAppSprite* _gear; ///< ギア画像
1048 - LAppSprite* _power; ///< 電源画像
1050 // レンダリング先を別ターゲットにする方式の場合に使用
1051 LAppSprite* _renderSprite; ///< モードによっては_renderBufferのテクスチャを描画
1052 diff -pruN --exclude build ./demo_clean/src/main.cpp ./demo_dev/src/main.cpp
1053 --- ./demo_clean/src/main.cpp 2020-10-01 22:47:25.846828066 +0100
1054 +++ ./demo_dev/src/main.cpp 2020-10-18 07:03:46.194220443 +0100
1056 * that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html.
1060 +#include <stdexcept>
1066 +#ifdef __cpp_lib_filesystem
1067 +#include <filesystem>
1068 +namespace fs = std::filesystem;
1070 +#include <experimental/filesystem>
1071 +namespace fs = std::experimental::filesystem;
1074 +#include "ICubismModelSetting.hpp"
1075 #include "LAppDelegate.hpp"
1076 +#include "LAppLive2DManager.hpp"
1077 +#include "LAppModel.hpp"
1078 +#include "mouse_cursor_tracker.h"
1084 + std::string windowTitle;
1085 + std::string rootDir;
1086 + float scaleFactor;
1089 + std::string modelName;
1090 + std::string cfgPath; // Path to config file for MouseCursorTracker
1093 +CmdArgs parseArgv(int argc, char *argv[])
1095 + // I think the command-line args are simple enough to not justify using a library...
1097 + // Set default values
1098 + cmdArgs.windowWidth = 600;
1099 + cmdArgs.windowHeight = 600;
1100 + cmdArgs.windowTitle = "MouseTrackerForCubism example";
1101 + cmdArgs.rootDir = fs::current_path();
1102 + cmdArgs.scaleFactor = 8.0f;
1103 + cmdArgs.translateX = 0.0f;
1104 + cmdArgs.translateY = -2.8f;
1105 + cmdArgs.modelName = "Haru";
1106 + cmdArgs.cfgPath = "";
1111 + std::string arg = argv[i];
1112 + std::stringstream ss;
1114 + if (arg == "--window-width" || arg == "-W") // capital W for consistency with height
1116 + ss << argv[i + 1];
1117 + if (!(ss >> cmdArgs.windowWidth))
1119 + throw std::runtime_error("Invalid argument for window width");
1122 + else if (arg == "--window-height" || arg == "-H") // avoiding "-h", typically for help
1124 + ss << argv[i + 1];
1125 + if (!(ss >> cmdArgs.windowHeight))
1127 + throw std::runtime_error("Invalid argument for window height");
1130 + else if (arg == "--window-title" || arg == "-t")
1132 + cmdArgs.windowTitle = argv[i + 1];
1134 + else if (arg == "--root-dir" || arg == "-d")
1136 + cmdArgs.rootDir = argv[i + 1];
1138 + else if (arg == "--scale-factor" || arg == "-f")
1140 + ss << argv[i + 1];
1141 + if (!(ss >> cmdArgs.scaleFactor))
1143 + throw std::runtime_error("Invalid argument for scale factor");
1146 + else if (arg == "--translate-x" || arg == "-x")
1148 + ss << argv[i + 1];
1149 + if (!(ss >> cmdArgs.translateX))
1151 + throw std::runtime_error("Invalid argument for translate X");
1154 + else if (arg == "--translate-y" || arg == "-y")
1156 + ss << argv[i + 1];
1157 + if (!(ss >> cmdArgs.translateY))
1159 + throw std::runtime_error("Invalid argument for translate Y");
1162 + else if (arg == "--model" || arg == "-m")
1164 + cmdArgs.modelName = argv[i + 1];
1166 + else if (arg == "--config" || arg == "-c")
1168 + cmdArgs.cfgPath = argv[i + 1];
1172 + throw std::runtime_error("Unrecognized argument: " + arg);
1181 int main(int argc, char* argv[])
1183 - // create the application instance
1184 - if (LAppDelegate::GetInstance()->Initialize() == GL_FALSE)
1185 + auto cmdArgs = parseArgv(argc, argv);
1187 + LAppDelegate *delegate = LAppDelegate::GetInstance();
1189 + if (!delegate->Initialize(cmdArgs.windowWidth,
1190 + cmdArgs.windowHeight,
1191 + cmdArgs.windowTitle.c_str()))
1194 + throw std::runtime_error("Unable to initialize LAppDelegate");
1197 - LAppDelegate::GetInstance()->Run();
1198 + delegate->SetRootDirectory(cmdArgs.rootDir);
1200 + LAppLive2DManager *manager = LAppLive2DManager::GetInstance();
1201 + manager->SetModel(cmdArgs.modelName);
1203 + manager->SetProjectionScaleTranslate(cmdArgs.scaleFactor,
1204 + cmdArgs.translateX,
1205 + cmdArgs.translateY);
1207 + LAppModel *model = manager->GetModel(0);
1208 + if (!model) throw std::runtime_error("model is null");
1210 + Live2D::Cubism::Framework::ICubismModelSetting *modelSetting = model->GetModelSetting();
1211 + if (!modelSetting) throw std::runtime_error("modelSetting is null");
1213 + std::vector<std::pair<std::string, int> > motions;
1214 + int motionGroupCount = modelSetting->GetMotionGroupCount();
1215 + for (int i = 0; i < motionGroupCount; i++)
1217 + const char *motionGroup = modelSetting->GetMotionGroupName(i);
1218 + int motionCount = modelSetting->GetMotionCount(motionGroup);
1219 + motions.push_back(std::make_pair(std::string(motionGroup), motionCount));
1222 + std::vector<std::string> expressions;
1223 + int expCount = modelSetting->GetExpressionCount();
1224 + for (int i = 0; i < expCount; i++)
1226 + const char *expName = modelSetting->GetExpressionName(i);
1227 + expressions.push_back(std::string(expName));
1230 + MouseCursorTracker tracker(cmdArgs.cfgPath, motions, expressions);
1232 + std::thread trackerThread(&MouseCursorTracker::mainLoop, &tracker);
1233 + manager->SetTracker(&tracker);
1238 + trackerThread.join();