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:54:33.576439332 +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 2021-01-02 11:34:29.022662427 +0000
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,30 +131,14 @@ 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, bool useOldParamId)
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 - _models.PushBack(new LAppModel());
383 + _models.PushBack(new LAppModel(useOldParamId));
384 _models[0]->LoadAssets(modelPath.c_str(), modelJsonName.c_str());
387 @@ -193,7 +160,7 @@ void LAppLive2DManager::ChangeScene(Csm:
389 #if defined(USE_RENDER_TARGET) || defined(USE_MODEL_RENDER_TARGET)
390 // モデル個別にαを付けるサンプルとして、もう1体モデルを作成し、少し位置をずらす
391 - _models.PushBack(new LAppModel());
392 + _models.PushBack(new LAppModel(useOldParamId));
393 _models[1]->LoadAssets(modelPath.c_str(), modelJsonName.c_str());
394 _models[1]->GetModelMatrix()->TranslateX(0.2f);
396 @@ -215,3 +182,20 @@ csmUint32 LAppLive2DManager::GetModelNum
398 return _models.GetSize();
401 +void LAppLive2DManager::SetTracker(MouseCursorTracker *tracker)
403 + for (auto it = _models.Begin(); it != _models.End(); ++it)
405 + (*it)->SetTracker(tracker);
409 +void LAppLive2DManager::SetProjectionScaleTranslate(float scaleFactor,
413 + _projScaleFactor = scaleFactor;
414 + _translateX = translateX;
415 + _translateY = translateY;
417 diff -pruN --exclude build ./demo_clean/src/LAppLive2DManager.hpp ./demo_dev/src/LAppLive2DManager.hpp
418 --- ./demo_clean/src/LAppLive2DManager.hpp 2020-10-01 22:47:25.846828066 +0100
419 +++ ./demo_dev/src/LAppLive2DManager.hpp 2021-01-02 11:29:57.666035355 +0000
425 #include <CubismFramework.hpp>
426 #include <Math/CubismMatrix44.hpp>
427 #include <Type/csmVector.hpp>
431 +class MouseCursorTracker;
434 * @brief サンプルアプリケーションにおいてCubismModelを管理するクラス<br>
435 * モデル生成と破棄、タップイベントの処理、モデル切り替えを行う。
436 @@ -72,16 +75,14 @@ public:
437 void OnUpdate() const;
440 - * @brief 次のシーンに切り替える<br>
441 - * サンプルアプリケーションではモデルセットの切り替えを行う。
446 - * @brief シーンを切り替える<br>
447 - * サンプルアプリケーションではモデルセットの切り替えを行う。
449 - void ChangeScene(Csm::csmInt32 index);
450 + * @brief Set model data
452 + * @param[in] modelName : Name of model, should be the same for both
453 + * the directory and the model3.json file
454 + * @param[in] useOldParamId : If true, translate new (Cubism 3+)
455 + * parameter IDs to old (Cubism 2.1) ones
457 + void SetModel(std::string modelName, bool useOldParamId);
461 @@ -89,6 +90,24 @@ public:
463 Csm::csmUint32 GetModelNum() const;
466 + * @brief Set the pointer to the MouseCursorTracker instance
468 + * @param[in] tracker : Pointer to MouseCursorTracker instance
470 + void SetTracker(MouseCursorTracker *tracker);
473 + * @brief Set projection scale factor and translation parameters
475 + * @param[in] scaleFactor : Scale factor applied in both X and Y directions
476 + * @param[in] translateX : Translation in X direction
477 + * @param[in] translateY : Translation in Y direction
479 + void SetProjectionScaleTranslate(float scaleFactor,
486 @@ -102,5 +121,8 @@ private:
488 Csm::CubismMatrix44* _viewMatrix; ///< モデル描画に用いるView行列
489 Csm::csmVector<LAppModel*> _models; ///< モデルインスタンスのコンテナ
490 - Csm::csmInt32 _sceneIndex; ///< 表示するシーンのインデックス値
492 + float _projScaleFactor;
496 diff -pruN --exclude build ./demo_clean/src/LAppModel.cpp ./demo_dev/src/LAppModel.cpp
497 --- ./demo_clean/src/LAppModel.cpp 2020-10-01 22:47:25.850827994 +0100
498 +++ ./demo_dev/src/LAppModel.cpp 2021-01-02 11:32:50.632989855 +0000
500 #include "LAppTextureManager.hpp"
501 #include "LAppDelegate.hpp"
503 +#include "mouse_cursor_tracker.h"
507 using namespace Live2D::Cubism::Framework;
508 using namespace Live2D::Cubism::Framework::DefaultParameterId;
509 using namespace LAppDefine;
510 @@ -45,22 +49,24 @@ namespace {
514 -LAppModel::LAppModel()
515 +LAppModel::LAppModel(bool useOldParamId)
517 , _modelSetting(NULL)
518 , _userTimeSeconds(0.0f)
519 + , _tracker(nullptr)
520 + , _useOldParamId(useOldParamId)
527 - _idParamAngleX = CubismFramework::GetIdManager()->GetId(ParamAngleX);
528 - _idParamAngleY = CubismFramework::GetIdManager()->GetId(ParamAngleY);
529 - _idParamAngleZ = CubismFramework::GetIdManager()->GetId(ParamAngleZ);
530 - _idParamBodyAngleX = CubismFramework::GetIdManager()->GetId(ParamBodyAngleX);
531 - _idParamEyeBallX = CubismFramework::GetIdManager()->GetId(ParamEyeBallX);
532 - _idParamEyeBallY = CubismFramework::GetIdManager()->GetId(ParamEyeBallY);
533 + _idParamAngleX = CubismFramework::GetIdManager()->GetId(_(ParamAngleX));
534 + _idParamAngleY = CubismFramework::GetIdManager()->GetId(_(ParamAngleY));
535 + _idParamAngleZ = CubismFramework::GetIdManager()->GetId(_(ParamAngleZ));
536 + _idParamBodyAngleX = CubismFramework::GetIdManager()->GetId(_(ParamBodyAngleX));
537 + _idParamEyeBallX = CubismFramework::GetIdManager()->GetId(_(ParamEyeBallX));
538 + _idParamEyeBallY = CubismFramework::GetIdManager()->GetId(_(ParamEyeBallY));
541 LAppModel::~LAppModel()
542 @@ -190,7 +196,7 @@ void LAppModel::SetupModel(ICubismModelS
543 breathParameters.PushBack(CubismBreath::BreathParameterData(_idParamAngleY, 0.0f, 8.0f, 3.5345f, 0.5f));
544 breathParameters.PushBack(CubismBreath::BreathParameterData(_idParamAngleZ, 0.0f, 10.0f, 5.5345f, 0.5f));
545 breathParameters.PushBack(CubismBreath::BreathParameterData(_idParamBodyAngleX, 0.0f, 4.0f, 15.5345f, 0.5f));
546 - breathParameters.PushBack(CubismBreath::BreathParameterData(CubismFramework::GetIdManager()->GetId(ParamBreath), 0.5f, 0.5f, 3.2345f, 0.5f));
547 + breathParameters.PushBack(CubismBreath::BreathParameterData(CubismFramework::GetIdManager()->GetId(_(ParamBreath)), 0.5f, 0.5f, 3.2345f, 0.5f));
549 _breath->SetParameters(breathParameters);
551 @@ -335,59 +341,110 @@ void LAppModel::Update()
552 const csmFloat32 deltaTimeSeconds = LAppPal::GetDeltaTime();
553 _userTimeSeconds += deltaTimeSeconds;
555 - _dragManager->Update(deltaTimeSeconds);
556 - _dragX = _dragManager->GetX();
557 - _dragY = _dragManager->GetY();
559 - // モーションによるパラメータ更新の有無
560 - csmBool motionUpdated = false;
562 - //-----------------------------------------------------------------
563 - _model->LoadParameters(); // 前回セーブされた状態をロード
564 - if (_motionManager->IsFinished())
566 - // モーションの再生がない場合、待機モーションの中からランダムで再生する
567 - StartRandomMotion(MotionGroupIdle, PriorityIdle);
572 - motionUpdated = _motionManager->UpdateMotion(_model, deltaTimeSeconds); // モーションを更新
574 - _model->SaveParameters(); // 状態を保存
575 - //-----------------------------------------------------------------
576 + auto idMan = CubismFramework::GetIdManager();
577 + auto params = _tracker->getParams();
580 - if (!motionUpdated)
582 - if (_eyeBlink != NULL)
583 + _model->LoadParameters(); // 前回セーブされた状態をロード
585 + int paramsMotionPriority = static_cast<int>(params.motionPriority);
587 + if (paramsMotionPriority != PriorityNone)
589 - // メインモーションの更新がないとき
590 - _eyeBlink->UpdateParameters(_model, deltaTimeSeconds); // 目パチ
591 + StartMotion(params.motionGroup.c_str(), params.motionNumber,
592 + paramsMotionPriority);
594 + else if (params.randomIdleMotion && _motionManager->IsFinished())
596 + // モーションの再生がない場合、待機モーションの中からランダムで再生する
597 + StartRandomMotion(MotionGroupIdle, PriorityIdle);
601 - if (_expressionManager != NULL)
603 - _expressionManager->UpdateMotion(_model, deltaTimeSeconds); // 表情でパラメータ更新(相対変化)
605 + // FIXME pose does not return to normal after motion
606 + // if we don't have randomIdleMotion set
609 + _motionManager->UpdateMotion(_model, deltaTimeSeconds); // モーションを更新
611 + _model->SaveParameters(); // 状態を保存
615 - _model->AddParameterValue(_idParamAngleX, _dragX * 30); // -30から30の値を加える
616 - _model->AddParameterValue(_idParamAngleY, _dragY * 30);
617 - _model->AddParameterValue(_idParamAngleZ, _dragX * _dragY * -30);
618 + if (params.expression != "")
620 + SetExpression(params.expression.c_str());
622 + if (_expressionManager != NULL)
624 + _expressionManager->UpdateMotion(_model, deltaTimeSeconds); // 表情でパラメータ更新(相対変化)
628 - _model->AddParameterValue(_idParamBodyAngleX, _dragX * 10); // -10から10の値を加える
629 + bool autoBlink = params.autoBlink && _eyeBlink;
630 + auto eyeLOpenIt = params.live2d.find("ParamEyeLOpen");
631 + auto eyeROpenIt = params.live2d.find("ParamEyeROpen");
634 - _model->AddParameterValue(_idParamEyeBallX, _dragX); // -1から1の値を加える
635 - _model->AddParameterValue(_idParamEyeBallY, _dragY);
638 + // Handle blink first
639 + _eyeBlink->UpdateParameters(_model, deltaTimeSeconds);
643 - if (_breath != NULL)
645 - _breath->UpdateParameters(_model, deltaTimeSeconds);
646 + if (eyeLOpenIt != params.live2d.end())
648 + // If value specified, override blinking
649 + _model->SetParameterValue(idMan->GetId(_("ParamEyeLOpen")),
650 + eyeLOpenIt->second);
652 + else if (!autoBlink)
654 + // If no value specified and no auto blink, set to 1
655 + _model->SetParameterValue(idMan->GetId(_("ParamEyeLOpen")), 1);
659 + if (eyeROpenIt != params.live2d.end())
661 + _model->SetParameterValue(idMan->GetId(_("ParamEyeROpen")),
662 + eyeROpenIt->second);
664 + else if (!autoBlink)
666 + _model->SetParameterValue(idMan->GetId(_("ParamEyeROpen")), 1);
670 + if (params.useLipSync && _lipSync)
672 + csmFloat32 value = params.lipSyncParam; // 0 to 1
674 + for (csmUint32 i = 0; i < _lipSyncIds.GetSize(); ++i)
676 + _model->AddParameterValue(_lipSyncIds[i], value, 0.8f);
681 + _model->SetParameterValue(idMan->GetId(_("ParamMouthOpenY")),
682 + params.live2d["ParamMouthOpenY"]);
685 + for (auto const &entry : params.live2d)
687 + std::string key = entry.first;
688 + double val = entry.second;
690 + if (key != "ParamEyeLOpen" && key != "ParamEyeROpen" &&
691 + key != "ParamMouthOpenY")
693 + _model->SetParameterValue(idMan->GetId(_(key)), val);
697 + if (params.autoBreath && _breath)
699 + // Note: _model->LoadParameters and SaveParameters is needed
700 + // before - see above.
701 + _breath->UpdateParameters(_model, deltaTimeSeconds);
706 @@ -396,17 +453,6 @@ void LAppModel::Update()
707 _physics->Evaluate(_model, deltaTimeSeconds);
713 - csmFloat32 value = 0; // リアルタイムでリップシンクを行う場合、システムから音量を取得して0〜1の範囲で値を入力します。
715 - for (csmUint32 i = 0; i < _lipSyncIds.GetSize(); ++i)
717 - _model->AddParameterValue(_lipSyncIds[i], value, 0.8f);
724 @@ -626,3 +672,42 @@ Csm::Rendering::CubismOffscreenFrame_Ope
726 return _renderBuffer;
729 +void LAppModel::SetTracker(MouseCursorTracker *tracker)
731 + _tracker = tracker;
734 +Csm::ICubismModelSetting* LAppModel::GetModelSetting(void) const
736 + return _modelSetting;
739 +Csm::csmString LAppModel::_(std::string s)
742 + if (_useOldParamId)
744 + if (s == "ParamTere")
746 + ans = "PARAM_CHEEK";
750 + for (size_t i = 0; i < s.size(); i++)
752 + if (std::isupper(s[i]) && i != 0)
756 + ans += std::toupper(s[i]);
764 + return csmString(ans.c_str());
767 diff -pruN --exclude build ./demo_clean/src/LAppModel.hpp ./demo_dev/src/LAppModel.hpp
768 --- ./demo_clean/src/LAppModel.hpp 2020-10-01 22:47:25.850827994 +0100
769 +++ ./demo_dev/src/LAppModel.hpp 2021-01-02 11:33:23.417547739 +0000
771 #include <Type/csmRectF.hpp>
772 #include <Rendering/OpenGL/CubismOffscreenSurface_OpenGLES2.hpp>
774 +#include "mouse_cursor_tracker.h"
777 * @brief ユーザーが実際に使用するモデルの実装クラス<br>
778 @@ -24,8 +25,11 @@ class LAppModel : public Csm::CubismUser
783 + * @param[in] useOldParamId : If true, translate new (Cubism 3+)
784 + * parameter IDs to old (Cubism 2.1) ones
787 + LAppModel(bool useOldParamId);
791 @@ -113,6 +117,15 @@ public:
793 Csm::Rendering::CubismOffscreenFrame_OpenGLES2& GetRenderBuffer();
796 + * @brief Set the pointer to the MouseCursorTracker instance
798 + * @param[in] tracker : Pointer to MouseCursorTracker instance
800 + void SetTracker(MouseCursorTracker *tracker);
802 + Csm::ICubismModelSetting* GetModelSetting(void) const;
806 * @brief モデルを描画する処理。モデルを描画する空間のView-Projection行列を渡す。
807 @@ -166,6 +179,17 @@ private:
809 void ReleaseExpressions();
812 + * @brief Translate new (Cubism 3+) parameter IDs to old (Cubism 2.1) ones
814 + * @param[in] s : New parameter ID
816 + * @return Old parameter ID
818 + Csm::csmString _(std::string s);
820 + bool _useOldParamId;
822 Csm::ICubismModelSetting* _modelSetting; ///< モデルセッティング情報
823 Csm::csmString _modelHomeDir; ///< モデルセッティングが置かれたディレクトリ
824 Csm::csmFloat32 _userTimeSeconds; ///< デルタ時間の積算値[秒]
825 @@ -183,6 +207,8 @@ private:
826 const Csm::CubismId* _idParamEyeBallY; ///< パラメータID: ParamEyeBallXY
828 Csm::Rendering::CubismOffscreenFrame_OpenGLES2 _renderBuffer; ///< フレームバッファ以外の描画先
830 + MouseCursorTracker *_tracker;
834 diff -pruN --exclude build ./demo_clean/src/LAppPal.cpp ./demo_dev/src/LAppPal.cpp
835 --- ./demo_clean/src/LAppPal.cpp 2020-10-01 22:47:25.850827994 +0100
836 +++ ./demo_dev/src/LAppPal.cpp 2020-10-18 04:57:43.289600308 +0100
840 #include "LAppPal.hpp"
841 +#include <stdexcept>
845 @@ -36,7 +37,6 @@ csmByte* LAppPal::LoadFileAsBytes(const
846 if (stat(path, &statBuf) == 0)
848 size = statBuf.st_size;
853 @@ -45,10 +45,7 @@ csmByte* LAppPal::LoadFileAsBytes(const
854 file.open(path, std::ios::in | std::ios::binary);
857 - if (DebugLogEnable)
859 - PrintLog("file open error");
861 + throw std::runtime_error("Failed to open file " + filePath);
864 file.read(buf, size);
865 diff -pruN --exclude build ./demo_clean/src/LAppTextureManager.cpp ./demo_dev/src/LAppTextureManager.cpp
866 --- ./demo_clean/src/LAppTextureManager.cpp 2020-10-01 22:47:25.850827994 +0100
867 +++ ./demo_dev/src/LAppTextureManager.cpp 2020-10-01 22:47:24.654849690 +0100
868 @@ -96,6 +96,46 @@ LAppTextureManager::TextureInfo* LAppTex
872 +LAppTextureManager::TextureInfo* LAppTextureManager::CreateTextureFromColor(
873 + uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha
876 + int width = 8, height = 8;
878 + uint8_t pixels[height][width][4];
879 + for (std::size_t h = 0; h < height; h++)
881 + for (std::size_t w = 0; w < width; w++)
883 + pixels[h][w][0] = red;
884 + pixels[h][w][1] = green;
885 + pixels[h][w][2] = blue;
886 + pixels[h][w][3] = alpha;
891 + glGenTextures(1, &textureId);
892 + glBindTexture(GL_TEXTURE_2D, textureId);
893 + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
895 + glGenerateMipmap(GL_TEXTURE_2D);
896 + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
897 + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
898 + glBindTexture(GL_TEXTURE_2D, 0);
901 + LAppTextureManager::TextureInfo* textureInfo = new LAppTextureManager::TextureInfo();
902 + textureInfo->fileName = "";
903 + textureInfo->width = width;
904 + textureInfo->height = height;
905 + textureInfo->id = textureId;
907 + _textures.PushBack(textureInfo);
909 + return textureInfo;
912 void LAppTextureManager::ReleaseTextures()
914 for (Csm::csmUint32 i = 0; i < _textures.GetSize(); i++)
915 diff -pruN --exclude build ./demo_clean/src/LAppTextureManager.hpp ./demo_dev/src/LAppTextureManager.hpp
916 --- ./demo_clean/src/LAppTextureManager.hpp 2020-10-01 22:47:25.846828066 +0100
917 +++ ./demo_dev/src/LAppTextureManager.hpp 2020-10-01 22:47:24.786847290 +0100
918 @@ -72,6 +72,8 @@ public:
920 TextureInfo* CreateTextureFromPngFile(std::string fileName);
922 + TextureInfo *CreateTextureFromColor(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha = 255);
927 diff -pruN --exclude build ./demo_clean/src/LAppView.cpp ./demo_dev/src/LAppView.cpp
928 --- ./demo_clean/src/LAppView.cpp 2020-10-01 22:47:25.850827994 +0100
929 +++ ./demo_dev/src/LAppView.cpp 2020-10-01 22:47:24.602850636 +0100
931 #include "LAppLive2DManager.hpp"
932 #include "LAppTextureManager.hpp"
933 #include "LAppDefine.hpp"
934 -#include "TouchManager.hpp"
935 #include "LAppSprite.hpp"
936 #include "LAppModel.hpp"
938 @@ -26,8 +25,6 @@ using namespace LAppDefine;
939 LAppView::LAppView():
945 _renderTarget(SelectTarget_None)
947 @@ -35,8 +32,6 @@ LAppView::LAppView():
948 _clearColor[1] = 1.0f;
949 _clearColor[2] = 1.0f;
950 _clearColor[3] = 0.0f;
952 - _touchManager = new TouchManager();
954 // デバイス座標からスクリーン座標に変換するための
955 _deviceToScreen = new CubismMatrix44();
956 @@ -52,10 +47,7 @@ LAppView::~LAppView()
959 delete _deviceToScreen;
960 - delete _touchManager;
966 void LAppView::Initialize()
967 @@ -97,9 +89,6 @@ void LAppView::Initialize()
968 void LAppView::Render()
975 LAppLive2DManager* Live2DManager = LAppLive2DManager::GetInstance();
977 @@ -139,35 +128,17 @@ void LAppView::InitializeSprite()
978 glfwGetWindowSize(LAppDelegate::GetInstance()->GetWindow(), &width, &height);
980 LAppTextureManager* textureManager = LAppDelegate::GetInstance()->GetTextureManager();
981 - const string resourcesPath = LAppDelegate::GetInstance()->GetRootDirectory() + ResourcesPath;
983 - string imageName = BackImageName;
984 - LAppTextureManager::TextureInfo* backgroundTexture = textureManager->CreateTextureFromPngFile(resourcesPath + imageName);
986 + LAppTextureManager::TextureInfo* backgroundTexture =
987 + textureManager->CreateTextureFromColor(0, 255, 0);
989 float x = width * 0.5f;
990 float y = height * 0.5f;
991 - float fWidth = static_cast<float>(backgroundTexture->width * 2.0f);
992 - float fHeight = static_cast<float>(height) * 0.95f;
993 + float fWidth = static_cast<float>(width);
994 + float fHeight = static_cast<float>(height);
995 _back = new LAppSprite(x, y, fWidth, fHeight, backgroundTexture->id, _programId);
997 - imageName = GearImageName;
998 - LAppTextureManager::TextureInfo* gearTexture = textureManager->CreateTextureFromPngFile(resourcesPath + imageName);
1000 - x = static_cast<float>(width - gearTexture->width * 0.5f);
1001 - y = static_cast<float>(height - gearTexture->height * 0.5f);
1002 - fWidth = static_cast<float>(gearTexture->width);
1003 - fHeight = static_cast<float>(gearTexture->height);
1004 - _gear = new LAppSprite(x, y, fWidth, fHeight, gearTexture->id, _programId);
1006 - imageName = PowerImageName;
1007 - LAppTextureManager::TextureInfo* powerTexture = textureManager->CreateTextureFromPngFile(resourcesPath + imageName);
1009 - x = static_cast<float>(width - powerTexture->width * 0.5f);
1010 - y = static_cast<float>(powerTexture->height * 0.5f);
1011 - fWidth = static_cast<float>(powerTexture->width);
1012 - fHeight = static_cast<float>(powerTexture->height);
1013 - _power = new LAppSprite(x, y, fWidth, fHeight, powerTexture->id, _programId);
1018 @@ -175,52 +146,6 @@ void LAppView::InitializeSprite()
1022 -void LAppView::OnTouchesBegan(float px, float py) const
1024 - _touchManager->TouchesBegan(px, py);
1027 -void LAppView::OnTouchesMoved(float px, float py) const
1029 - float viewX = this->TransformViewX(_touchManager->GetX());
1030 - float viewY = this->TransformViewY(_touchManager->GetY());
1032 - _touchManager->TouchesMoved(px, py);
1034 - LAppLive2DManager* Live2DManager = LAppLive2DManager::GetInstance();
1035 - Live2DManager->OnDrag(viewX, viewY);
1038 -void LAppView::OnTouchesEnded(float px, float py) const
1041 - LAppLive2DManager* live2DManager = LAppLive2DManager::GetInstance();
1042 - live2DManager->OnDrag(0.0f, 0.0f);
1046 - float x = _deviceToScreen->TransformX(_touchManager->GetX()); // 論理座標変換した座標を取得。
1047 - float y = _deviceToScreen->TransformY(_touchManager->GetY()); // 論理座標変換した座標を取得。
1048 - if (DebugTouchLogEnable)
1050 - LAppPal::PrintLog("[APP]touchesEnded x:%.2f y:%.2f", x, y);
1052 - live2DManager->OnTap(x, y);
1055 - if (_gear->IsHit(px, py))
1057 - live2DManager->NextScene();
1061 - if (_power->IsHit(px, py))
1063 - LAppDelegate::GetInstance()->AppEnd();
1068 float LAppView::TransformViewX(float deviceX) const
1070 float screenX = _deviceToScreen->TransformX(deviceX); // 論理座標変換した座標を取得。
1071 @@ -362,32 +287,4 @@ void LAppView::ResizeSprite()
1072 _back->ResetRect(x, y, fWidth, fHeight);
1078 - GLuint id = _power->GetTextureId();
1079 - LAppTextureManager::TextureInfo* texInfo = textureManager->GetTextureInfoById(id);
1082 - x = static_cast<float>(width - texInfo->width * 0.5f);
1083 - y = static_cast<float>(texInfo->height * 0.5f);
1084 - fWidth = static_cast<float>(texInfo->width);
1085 - fHeight = static_cast<float>(texInfo->height);
1086 - _power->ResetRect(x, y, fWidth, fHeight);
1092 - GLuint id = _gear->GetTextureId();
1093 - LAppTextureManager::TextureInfo* texInfo = textureManager->GetTextureInfoById(id);
1096 - x = static_cast<float>(width - texInfo->width * 0.5f);
1097 - y = static_cast<float>(height - texInfo->height * 0.5f);
1098 - fWidth = static_cast<float>(texInfo->width);
1099 - fHeight = static_cast<float>(texInfo->height);
1100 - _gear->ResetRect(x, y, fWidth, fHeight);
1104 diff -pruN --exclude build ./demo_clean/src/LAppView.hpp ./demo_dev/src/LAppView.hpp
1105 --- ./demo_clean/src/LAppView.hpp 2020-10-01 22:47:25.846828066 +0100
1106 +++ ./demo_dev/src/LAppView.hpp 2020-10-01 22:47:24.802846999 +0100
1108 #include "CubismFramework.hpp"
1109 #include <Rendering/OpenGL/CubismOffscreenSurface_OpenGLES2.hpp>
1111 -class TouchManager;
1115 @@ -66,30 +65,6 @@ public:
1116 void ResizeSprite();
1119 - * @brief タッチされたときに呼ばれる。
1121 - * @param[in] pointX スクリーンX座標
1122 - * @param[in] pointY スクリーンY座標
1124 - void OnTouchesBegan(float pointX, float pointY) const;
1127 - * @brief タッチしているときにポインタが動いたら呼ばれる。
1129 - * @param[in] pointX スクリーンX座標
1130 - * @param[in] pointY スクリーンY座標
1132 - void OnTouchesMoved(float pointX, float pointY) const;
1135 - * @brief タッチが終了したら呼ばれる。
1137 - * @param[in] pointX スクリーンX座標
1138 - * @param[in] pointY スクリーンY座標
1140 - void OnTouchesEnded(float pointX, float pointY) const;
1143 * @brief X座標をView座標に変換する。
1145 * @param[in] deviceX デバイスX座標
1146 @@ -147,13 +122,10 @@ public:
1147 void SetRenderTargetClearColor(float r, float g, float b);
1150 - TouchManager* _touchManager; ///< タッチマネージャー
1151 Csm::CubismMatrix44* _deviceToScreen; ///< デバイスからスクリーンへの行列
1152 Csm::CubismViewMatrix* _viewMatrix; ///< viewMatrix
1153 GLuint _programId; ///< シェーダID
1154 LAppSprite* _back; ///< 背景画像
1155 - LAppSprite* _gear; ///< ギア画像
1156 - LAppSprite* _power; ///< 電源画像
1158 // レンダリング先を別ターゲットにする方式の場合に使用
1159 LAppSprite* _renderSprite; ///< モードによっては_renderBufferのテクスチャを描画
1160 diff -pruN --exclude build ./demo_clean/src/main.cpp ./demo_dev/src/main.cpp
1161 --- ./demo_clean/src/main.cpp 2020-10-01 22:47:25.846828066 +0100
1162 +++ ./demo_dev/src/main.cpp 2021-01-02 11:41:01.033288228 +0000
1164 * that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html.
1168 +#include <stdexcept>
1174 +#ifdef __cpp_lib_filesystem
1175 +#include <filesystem>
1176 +namespace fs = std::filesystem;
1178 +#include <experimental/filesystem>
1179 +namespace fs = std::experimental::filesystem;
1182 +#include "ICubismModelSetting.hpp"
1183 #include "LAppDelegate.hpp"
1184 +#include "LAppLive2DManager.hpp"
1185 +#include "LAppModel.hpp"
1186 +#include "mouse_cursor_tracker.h"
1192 + std::string windowTitle;
1193 + std::string rootDir;
1194 + float scaleFactor;
1197 + std::string modelName;
1198 + bool oldId; // If true, translate new (Cubism 3+) parameter IDs to old (Cubism 2.1) IDs
1199 + std::string cfgPath; // Path to config file for MouseCursorTracker
1202 +CmdArgs parseArgv(int argc, char *argv[])
1204 + // I think the command-line args are simple enough to not justify using a library...
1206 + // Set default values
1207 + cmdArgs.windowWidth = 600;
1208 + cmdArgs.windowHeight = 600;
1209 + cmdArgs.windowTitle = "MouseTrackerForCubism example";
1210 + cmdArgs.rootDir = fs::current_path();
1211 + cmdArgs.scaleFactor = 8.0f;
1212 + cmdArgs.translateX = 0.0f;
1213 + cmdArgs.translateY = -2.8f;
1214 + cmdArgs.modelName = "Haru";
1215 + cmdArgs.oldId = false;
1216 + cmdArgs.cfgPath = "";
1221 + std::string arg = argv[i];
1222 + std::stringstream ss;
1224 + if (arg == "--window-width" || arg == "-W") // capital W for consistency with height
1226 + ss << argv[i + 1];
1227 + if (!(ss >> cmdArgs.windowWidth))
1229 + throw std::runtime_error("Invalid argument for window width");
1232 + else if (arg == "--window-height" || arg == "-H") // avoiding "-h", typically for help
1234 + ss << argv[i + 1];
1235 + if (!(ss >> cmdArgs.windowHeight))
1237 + throw std::runtime_error("Invalid argument for window height");
1240 + else if (arg == "--window-title" || arg == "-t")
1242 + cmdArgs.windowTitle = argv[i + 1];
1244 + else if (arg == "--root-dir" || arg == "-d")
1246 + cmdArgs.rootDir = argv[i + 1];
1248 + else if (arg == "--scale-factor" || arg == "-f")
1250 + ss << argv[i + 1];
1251 + if (!(ss >> cmdArgs.scaleFactor))
1253 + throw std::runtime_error("Invalid argument for scale factor");
1256 + else if (arg == "--translate-x" || arg == "-x")
1258 + ss << argv[i + 1];
1259 + if (!(ss >> cmdArgs.translateX))
1261 + throw std::runtime_error("Invalid argument for translate X");
1264 + else if (arg == "--translate-y" || arg == "-y")
1266 + ss << argv[i + 1];
1267 + if (!(ss >> cmdArgs.translateY))
1269 + throw std::runtime_error("Invalid argument for translate Y");
1272 + else if (arg == "--model" || arg == "-m")
1274 + cmdArgs.modelName = argv[i + 1];
1276 + else if (arg == "--config" || arg == "-c")
1278 + cmdArgs.cfgPath = argv[i + 1];
1280 + else if (arg == "--old-param-id" || arg == "-o")
1282 + cmdArgs.oldId = (argv[i + 1][0] == '1');
1286 + throw std::runtime_error("Unrecognized argument: " + arg);
1295 int main(int argc, char* argv[])
1297 - // create the application instance
1298 - if (LAppDelegate::GetInstance()->Initialize() == GL_FALSE)
1299 + auto cmdArgs = parseArgv(argc, argv);
1301 + LAppDelegate *delegate = LAppDelegate::GetInstance();
1303 + if (!delegate->Initialize(cmdArgs.windowWidth,
1304 + cmdArgs.windowHeight,
1305 + cmdArgs.windowTitle.c_str()))
1308 + throw std::runtime_error("Unable to initialize LAppDelegate");
1311 - LAppDelegate::GetInstance()->Run();
1312 + delegate->SetRootDirectory(cmdArgs.rootDir);
1314 + LAppLive2DManager *manager = LAppLive2DManager::GetInstance();
1315 + manager->SetModel(cmdArgs.modelName, cmdArgs.oldId);
1317 + manager->SetProjectionScaleTranslate(cmdArgs.scaleFactor,
1318 + cmdArgs.translateX,
1319 + cmdArgs.translateY);
1321 + LAppModel *model = manager->GetModel(0);
1322 + if (!model) throw std::runtime_error("model is null");
1324 + Live2D::Cubism::Framework::ICubismModelSetting *modelSetting = model->GetModelSetting();
1325 + if (!modelSetting) throw std::runtime_error("modelSetting is null");
1327 + std::vector<std::pair<std::string, int> > motions;
1328 + int motionGroupCount = modelSetting->GetMotionGroupCount();
1329 + for (int i = 0; i < motionGroupCount; i++)
1331 + const char *motionGroup = modelSetting->GetMotionGroupName(i);
1332 + int motionCount = modelSetting->GetMotionCount(motionGroup);
1333 + motions.push_back(std::make_pair(std::string(motionGroup), motionCount));
1336 + std::vector<std::string> expressions;
1337 + int expCount = modelSetting->GetExpressionCount();
1338 + for (int i = 0; i < expCount; i++)
1340 + const char *expName = modelSetting->GetExpressionName(i);
1341 + expressions.push_back(std::string(expName));
1344 + MouseCursorTracker tracker(cmdArgs.cfgPath, motions, expressions);
1346 + std::thread trackerThread(&MouseCursorTracker::mainLoop, &tracker);
1347 + manager->SetTracker(&tracker);
1352 + trackerThread.join();