1 diff -pruN --exclude build ./demo_clean/CMakeLists.txt ./demo_dev/CMakeLists.txt
2 --- ./demo_clean/CMakeLists.txt 2021-02-17 01:23:17.000000000 +0000
3 +++ ./demo_dev/CMakeLists.txt 2021-05-16 01:44:30.838853280 +0100
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.2)
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,9 @@ target_link_libraries(Framework Live2DCu
23 # Find opengl libraries.
24 find_package(OpenGL REQUIRED)
26 +# Add FacialLandmarksForCubism
27 +add_subdirectory(../.. FacialLandmarksForCubism_build)
29 # Make executable app.
30 add_executable(${APP_NAME})
32 @@ -73,9 +76,11 @@ target_link_libraries(${APP_NAME}
36 + FacialLandmarksForCubism
39 # Specify include directories.
40 -target_include_directories(${APP_NAME} PRIVATE ${STB_PATH})
41 +target_include_directories(${APP_NAME} PRIVATE ${STB_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/../../include)
43 # Copy resource directory to build directory.
45 diff -pruN --exclude build ./demo_clean/scripts/make_gcc ./demo_dev/scripts/make_gcc
46 --- ./demo_clean/scripts/make_gcc 2021-02-17 01:23:17.000000000 +0000
47 +++ ./demo_dev/scripts/make_gcc 2021-05-29 02:04:17.338257917 +0100
48 @@ -10,4 +10,4 @@ BUILD_PATH=$SCRIPT_PATH/../build/make_gc
49 cmake -S "$CMAKE_PATH" \
51 -D CMAKE_BUILD_TYPE=Release
52 -cd "$BUILD_PATH" && make
53 +cd "$BUILD_PATH" && make -j4
54 diff -pruN --exclude build ./demo_clean/src/CMakeLists.txt ./demo_dev/src/CMakeLists.txt
55 --- ./demo_clean/src/CMakeLists.txt 2021-02-17 01:23:17.000000000 +0000
56 +++ ./demo_dev/src/CMakeLists.txt 2021-04-28 11:49:43.166296000 +0100
57 @@ -6,8 +6,6 @@ target_sources(${APP_NAME}
58 ${CMAKE_CURRENT_SOURCE_DIR}/LAppDefine.hpp
59 ${CMAKE_CURRENT_SOURCE_DIR}/LAppDelegate.cpp
60 ${CMAKE_CURRENT_SOURCE_DIR}/LAppDelegate.hpp
61 - ${CMAKE_CURRENT_SOURCE_DIR}/LAppWavFileHandler.cpp
62 - ${CMAKE_CURRENT_SOURCE_DIR}/LAppWavFileHandler.hpp
63 ${CMAKE_CURRENT_SOURCE_DIR}/LAppLive2DManager.cpp
64 ${CMAKE_CURRENT_SOURCE_DIR}/LAppLive2DManager.hpp
65 ${CMAKE_CURRENT_SOURCE_DIR}/LAppModel.cpp
66 @@ -21,6 +19,4 @@ target_sources(${APP_NAME}
67 ${CMAKE_CURRENT_SOURCE_DIR}/LAppView.cpp
68 ${CMAKE_CURRENT_SOURCE_DIR}/LAppView.hpp
69 ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp
70 - ${CMAKE_CURRENT_SOURCE_DIR}/TouchManager.cpp
71 - ${CMAKE_CURRENT_SOURCE_DIR}/TouchManager.hpp
73 diff -pruN --exclude build ./demo_clean/src/LAppDelegate.cpp ./demo_dev/src/LAppDelegate.cpp
74 --- ./demo_clean/src/LAppDelegate.cpp 2021-02-17 01:23:17.000000000 +0000
75 +++ ./demo_dev/src/LAppDelegate.cpp 2021-04-28 11:49:43.166296000 +0100
76 @@ -45,7 +45,8 @@ void LAppDelegate::ReleaseInstance()
80 -bool LAppDelegate::Initialize()
81 +bool LAppDelegate::Initialize(int initWindowWidth, int initWindowHeight,
82 + const char *windowTitle)
86 @@ -63,7 +64,13 @@ bool LAppDelegate::Initialize()
90 - _window = glfwCreateWindow(RenderTargetWidth, RenderTargetHeight, "SAMPLE", NULL, NULL);
91 + _window = glfwCreateWindow(
92 + initWindowWidth ? initWindowWidth : RenderTargetWidth,
93 + initWindowHeight ? initWindowHeight : RenderTargetHeight,
94 + windowTitle ? windowTitle : "SAMPLE",
101 @@ -95,10 +102,6 @@ bool LAppDelegate::Initialize()
103 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
106 - glfwSetMouseButtonCallback(_window, EventHandler::OnMouseCallBack);
107 - glfwSetCursorPosCallback(_window, EventHandler::OnMouseCallBack);
111 glfwGetWindowSize(LAppDelegate::GetInstance()->GetWindow(), &width, &height);
112 @@ -111,8 +114,6 @@ bool LAppDelegate::Initialize()
116 - SetRootDirectory();
119 LAppLive2DManager::GetInstance();
121 @@ -214,49 +215,6 @@ void LAppDelegate::InitializeCubism()
122 LAppPal::UpdateTime();
125 -void LAppDelegate::OnMouseCallBack(GLFWwindow* window, int button, int action, int modify)
131 - if (GLFW_MOUSE_BUTTON_LEFT != button)
136 - if (GLFW_PRESS == action)
139 - _view->OnTouchesBegan(_mouseX, _mouseY);
141 - else if (GLFW_RELEASE == action)
146 - _view->OnTouchesEnded(_mouseX, _mouseY);
151 -void LAppDelegate::OnMouseCallBack(GLFWwindow* window, double x, double y)
153 - _mouseX = static_cast<float>(x);
154 - _mouseY = static_cast<float>(y);
165 - _view->OnTouchesMoved(_mouseX, _mouseY);
168 GLuint LAppDelegate::CreateShader()
171 @@ -299,29 +257,9 @@ GLuint LAppDelegate::CreateShader()
175 -void LAppDelegate::SetRootDirectory()
176 +void LAppDelegate::SetRootDirectory(std::string rootDir)
179 - ssize_t len = readlink("/proc/self/exe", path, 1024 - 1);
186 - std::string pathString(path);
188 - pathString = pathString.substr(0, pathString.rfind("Demo"));
189 - Csm::csmVector<string> splitStrings = this->Split(pathString, '/');
191 - this->_rootDirectory = "";
193 - for(int i = 0; i < splitStrings.GetSize(); i++)
195 - this->_rootDirectory = this->_rootDirectory + "/" +splitStrings[i];
198 - this->_rootDirectory += "/";
199 + this->_rootDirectory = rootDir + "/";
202 Csm::csmVector<string> LAppDelegate::Split(const std::string& baseString, char delimiter)
203 diff -pruN --exclude build ./demo_clean/src/LAppDelegate.hpp ./demo_dev/src/LAppDelegate.hpp
204 --- ./demo_clean/src/LAppDelegate.hpp 2021-02-17 01:23:17.000000000 +0000
205 +++ ./demo_dev/src/LAppDelegate.hpp 2021-04-28 11:49:43.166296000 +0100
206 @@ -40,7 +40,8 @@ public:
208 * @brief APPに必要なものを初期化する。
211 + bool Initialize(int initWindowWidth = 0, int initWindowHeight = 0,
212 + const char *windowTitle = "SAMPLE");
216 @@ -53,25 +54,6 @@ public:
220 - * @brief OpenGL用 glfwSetMouseButtonCallback用関数。
222 - * @param[in] window コールバックを呼んだWindow情報
223 - * @param[in] button ボタン種類
224 - * @param[in] action 実行結果
225 - * @param[in] modify
227 - void OnMouseCallBack(GLFWwindow* window, int button, int action, int modify);
230 - * @brief OpenGL用 glfwSetCursorPosCallback用関数。
232 - * @param[in] window コールバックを呼んだWindow情報
236 - void OnMouseCallBack(GLFWwindow* window, double x, double y);
241 GLuint CreateShader();
242 @@ -98,8 +80,10 @@ public:
245 * @brief ルートディレクトリを設定する。
247 + * @param[in] rootDir : The root directory to set to.
249 - void SetRootDirectory();
250 + void SetRootDirectory(std::string rootDir);
253 * @brief ルートディレクトリを取得する。
254 @@ -146,24 +130,3 @@ private:
255 int _windowWidth; ///< Initialize関数で設定したウィンドウ幅
256 int _windowHeight; ///< Initialize関数で設定したウィンドウ高さ
263 - * @brief glfwSetMouseButtonCallback用コールバック関数。
265 - static void OnMouseCallBack(GLFWwindow* window, int button, int action, int modify)
267 - LAppDelegate::GetInstance()->OnMouseCallBack(window, button, action, modify);
271 - * @brief glfwSetCursorPosCallback用コールバック関数。
273 - static void OnMouseCallBack(GLFWwindow* window, double x, double y)
275 - LAppDelegate::GetInstance()->OnMouseCallBack(window, x, y);
279 diff -pruN --exclude build ./demo_clean/src/LAppLive2DManager.cpp ./demo_dev/src/LAppLive2DManager.cpp
280 --- ./demo_clean/src/LAppLive2DManager.cpp 2021-02-17 01:23:17.000000000 +0000
281 +++ ./demo_dev/src/LAppLive2DManager.cpp 2021-04-28 11:49:43.166296000 +0100
282 @@ -52,11 +52,11 @@ void LAppLive2DManager::ReleaseInstance(
284 LAppLive2DManager::LAppLive2DManager()
287 + , _projScaleFactor(1.0f)
288 + , _translateX(0.0f)
289 + , _translateY(0.0f)
291 _viewMatrix = new CubismMatrix44();
293 - ChangeScene(_sceneIndex);
296 LAppLive2DManager::~LAppLive2DManager()
297 @@ -100,26 +100,6 @@ void LAppLive2DManager::OnTap(csmFloat32
299 LAppPal::PrintLog("[APP]tap point: {x:%.2f y:%.2f}", x, y);
302 - for (csmUint32 i = 0; i < _models.GetSize(); i++)
304 - if (_models[i]->HitTest(HitAreaNameHead, x, y))
306 - if (DebugLogEnable)
308 - LAppPal::PrintLog("[APP]hit area: [%s]", HitAreaNameHead);
310 - _models[i]->SetRandomExpression();
312 - else if (_models[i]->HitTest(HitAreaNameBody, x, y))
314 - if (DebugLogEnable)
316 - LAppPal::PrintLog("[APP]hit area: [%s]", HitAreaNameBody);
318 - _models[i]->StartRandomMotion(MotionGroupTapBody, PriorityNormal, FinishedMotion);
323 void LAppLive2DManager::OnUpdate() const
324 @@ -136,12 +116,15 @@ void LAppLive2DManager::OnUpdate() const
326 // 横に長いモデルを縦長ウィンドウに表示する際モデルの横サイズでscaleを算出する
327 model->GetModelMatrix()->SetWidth(2.0f);
328 - projection.Scale(1.0f, static_cast<float>(width) / static_cast<float>(height));
329 + projection.Scale(_projScaleFactor,
330 + _projScaleFactor * static_cast<float>(width) / static_cast<float>(height));
334 - projection.Scale(static_cast<float>(height) / static_cast<float>(width), 1.0f);
335 + projection.Scale(_projScaleFactor * static_cast<float>(height) / static_cast<float>(width),
338 + projection.Translate(_translateX, _translateY);
341 if (_viewMatrix != NULL)
342 @@ -158,30 +141,14 @@ void LAppLive2DManager::OnUpdate() const
346 -void LAppLive2DManager::NextScene()
348 - csmInt32 no = (_sceneIndex + 1) % ModelDirSize;
352 -void LAppLive2DManager::ChangeScene(Csm::csmInt32 index)
353 +void LAppLive2DManager::SetModel(std::string modelName, bool useOldParamId)
355 - _sceneIndex = index;
356 - if (DebugLogEnable)
358 - LAppPal::PrintLog("[APP]model index: %d", _sceneIndex);
361 - // ModelDir[]に保持したディレクトリ名から
362 - // model3.jsonのパスを決定する.
363 - // ディレクトリ名とmodel3.jsonの名前を一致させておくこと.
364 - std::string model = ModelDir[index];
365 - std::string modelPath = LAppDelegate::GetInstance()->GetRootDirectory() + ResourcesPath + model + "/";
366 - std::string modelJsonName = ModelDir[index];
367 + std::string modelPath = LAppDelegate::GetInstance()->GetRootDirectory() + ResourcesPath + modelName + "/";
368 + std::string modelJsonName = modelName;
369 modelJsonName += ".model3.json";
372 - _models.PushBack(new LAppModel());
373 + _models.PushBack(new LAppModel(useOldParamId));
374 _models[0]->LoadAssets(modelPath.c_str(), modelJsonName.c_str());
377 @@ -203,7 +170,7 @@ void LAppLive2DManager::ChangeScene(Csm:
379 #if defined(USE_RENDER_TARGET) || defined(USE_MODEL_RENDER_TARGET)
380 // モデル個別にαを付けるサンプルとして、もう1体モデルを作成し、少し位置をずらす
381 - _models.PushBack(new LAppModel());
382 + _models.PushBack(new LAppModel(useOldParamId));
383 _models[1]->LoadAssets(modelPath.c_str(), modelJsonName.c_str());
384 _models[1]->GetModelMatrix()->TranslateX(0.2f);
386 @@ -232,3 +199,20 @@ void LAppLive2DManager::SetViewMatrix(Cu
387 _viewMatrix->GetArray()[i] = m->GetArray()[i];
391 +void LAppLive2DManager::SetFacialLandmarkDetector(FacialLandmarkDetector *detector)
393 + for (auto it = _models.Begin(); it != _models.End(); ++it)
395 + (*it)->SetFacialLandmarkDetector(detector);
399 +void LAppLive2DManager::SetProjectionScaleTranslate(float scaleFactor,
403 + _projScaleFactor = scaleFactor;
404 + _translateX = translateX;
405 + _translateY = translateY;
407 diff -pruN --exclude build ./demo_clean/src/LAppLive2DManager.hpp ./demo_dev/src/LAppLive2DManager.hpp
408 --- ./demo_clean/src/LAppLive2DManager.hpp 2021-02-17 01:23:17.000000000 +0000
409 +++ ./demo_dev/src/LAppLive2DManager.hpp 2021-04-28 11:49:43.166296000 +0100
415 #include <CubismFramework.hpp>
416 #include <Math/CubismMatrix44.hpp>
417 #include <Type/csmVector.hpp>
421 +class FacialLandmarkDetector;
424 * @brief サンプルアプリケーションにおいてCubismModelを管理するクラス<br>
425 * モデル生成と破棄、タップイベントの処理、モデル切り替えを行う。
426 @@ -72,16 +75,14 @@ public:
427 void OnUpdate() const;
430 - * @brief 次のシーンに切り替える<br>
431 - * サンプルアプリケーションではモデルセットの切り替えを行う。
436 - * @brief シーンを切り替える<br>
437 - * サンプルアプリケーションではモデルセットの切り替えを行う。
439 - void ChangeScene(Csm::csmInt32 index);
440 + * @brief Set model data
442 + * @param[in] modelName : Name of model, should be the same for both
443 + * the directory and the model3.json file
444 + * @param[in] useOldParamId : If true, translate new (Cubism 3+)
445 + * parameter IDs to old (Cubism 2.1) ones
447 + void SetModel(std::string modelName, bool useOldParamId);
451 @@ -94,6 +95,24 @@ public:
453 void SetViewMatrix(Live2D::Cubism::Framework::CubismMatrix44* m);
456 + * @brief Set the pointer to the FacialLandmarkDetector instance
458 + * @param[in] detector : Pointer to FacialLandmarkDetector instance
460 + void SetFacialLandmarkDetector(FacialLandmarkDetector *detector);
463 + * @brief Set projection scale factor and translation parameters
465 + * @param[in] scaleFactor : Scale factor applied in both X and Y directions
466 + * @param[in] translateX : Translation in X direction
467 + * @param[in] translateY : Translation in Y direction
469 + void SetProjectionScaleTranslate(float scaleFactor,
476 @@ -107,5 +126,8 @@ private:
478 Csm::CubismMatrix44* _viewMatrix; ///< モデル描画に用いるView行列
479 Csm::csmVector<LAppModel*> _models; ///< モデルインスタンスのコンテナ
480 - Csm::csmInt32 _sceneIndex; ///< 表示するシーンのインデックス値
482 + float _projScaleFactor;
486 diff -pruN --exclude build ./demo_clean/src/LAppModel.cpp ./demo_dev/src/LAppModel.cpp
487 --- ./demo_clean/src/LAppModel.cpp 2021-02-17 01:23:17.000000000 +0000
488 +++ ./demo_dev/src/LAppModel.cpp 2021-04-28 11:49:43.166296000 +0100
490 #include "LAppTextureManager.hpp"
491 #include "LAppDelegate.hpp"
493 +#include "facial_landmark_detector.h"
495 using namespace Live2D::Cubism::Framework;
496 using namespace Live2D::Cubism::Framework::DefaultParameterId;
497 using namespace LAppDefine;
498 @@ -45,22 +47,24 @@ namespace {
502 -LAppModel::LAppModel()
503 +LAppModel::LAppModel(bool useOldParamId)
505 , _modelSetting(NULL)
506 , _userTimeSeconds(0.0f)
507 + , _detector(nullptr)
508 + , _useOldParamId(useOldParamId)
515 - _idParamAngleX = CubismFramework::GetIdManager()->GetId(ParamAngleX);
516 - _idParamAngleY = CubismFramework::GetIdManager()->GetId(ParamAngleY);
517 - _idParamAngleZ = CubismFramework::GetIdManager()->GetId(ParamAngleZ);
518 - _idParamBodyAngleX = CubismFramework::GetIdManager()->GetId(ParamBodyAngleX);
519 - _idParamEyeBallX = CubismFramework::GetIdManager()->GetId(ParamEyeBallX);
520 - _idParamEyeBallY = CubismFramework::GetIdManager()->GetId(ParamEyeBallY);
521 + _idParamAngleX = CubismFramework::GetIdManager()->GetId(_(ParamAngleX));
522 + _idParamAngleY = CubismFramework::GetIdManager()->GetId(_(ParamAngleY));
523 + _idParamAngleZ = CubismFramework::GetIdManager()->GetId(_(ParamAngleZ));
524 + _idParamBodyAngleX = CubismFramework::GetIdManager()->GetId(_(ParamBodyAngleX));
525 + _idParamEyeBallX = CubismFramework::GetIdManager()->GetId(_(ParamEyeBallX));
526 + _idParamEyeBallY = CubismFramework::GetIdManager()->GetId(_(ParamEyeBallY));
529 LAppModel::~LAppModel()
530 @@ -128,30 +132,6 @@ void LAppModel::SetupModel(ICubismModelS
531 DeleteBuffer(buffer, path.GetRawString());
535 - if (_modelSetting->GetExpressionCount() > 0)
537 - const csmInt32 count = _modelSetting->GetExpressionCount();
538 - for (csmInt32 i = 0; i < count; i++)
540 - csmString name = _modelSetting->GetExpressionName(i);
541 - csmString path = _modelSetting->GetExpressionFileName(i);
542 - path = _modelHomeDir + path;
544 - buffer = CreateBuffer(path.GetRawString(), &size);
545 - ACubismMotion* motion = LoadExpression(buffer, size, name.GetRawString());
547 - if (_expressions[name] != NULL)
549 - ACubismMotion::Delete(_expressions[name]);
550 - _expressions[name] = NULL;
552 - _expressions[name] = motion;
554 - DeleteBuffer(buffer, path.GetRawString());
559 if (strcmp(_modelSetting->GetPhysicsFileName(), "") != 0)
561 @@ -190,7 +170,7 @@ void LAppModel::SetupModel(ICubismModelS
562 breathParameters.PushBack(CubismBreath::BreathParameterData(_idParamAngleY, 0.0f, 8.0f, 3.5345f, 0.5f));
563 breathParameters.PushBack(CubismBreath::BreathParameterData(_idParamAngleZ, 0.0f, 10.0f, 5.5345f, 0.5f));
564 breathParameters.PushBack(CubismBreath::BreathParameterData(_idParamBodyAngleX, 0.0f, 4.0f, 15.5345f, 0.5f));
565 - breathParameters.PushBack(CubismBreath::BreathParameterData(CubismFramework::GetIdManager()->GetId(ParamBreath), 0.5f, 0.5f, 3.2345f, 0.5f));
566 + breathParameters.PushBack(CubismBreath::BreathParameterData(CubismFramework::GetIdManager()->GetId(_(ParamBreath)), 0.5f, 0.5f, 3.2345f, 0.5f));
568 _breath->SetParameters(breathParameters);
570 @@ -214,15 +194,6 @@ void LAppModel::SetupModel(ICubismModelS
576 - csmInt32 lipSyncIdCount = _modelSetting->GetLipSyncParameterCount();
577 - for (csmInt32 i = 0; i < lipSyncIdCount; ++i)
579 - _lipSyncIds.PushBack(_modelSetting->GetLipSyncParameterId(i));
584 csmMap<csmString, csmFloat32> layout;
585 _modelSetting->GetLayoutMap(layout);
586 @@ -335,59 +306,57 @@ void LAppModel::Update()
587 const csmFloat32 deltaTimeSeconds = LAppPal::GetDeltaTime();
588 _userTimeSeconds += deltaTimeSeconds;
590 - _dragManager->Update(deltaTimeSeconds);
591 - _dragX = _dragManager->GetX();
592 - _dragY = _dragManager->GetY();
594 - // モーションによるパラメータ更新の有無
595 - csmBool motionUpdated = false;
597 - //-----------------------------------------------------------------
598 - _model->LoadParameters(); // 前回セーブされた状態をロード
599 - if (_motionManager->IsFinished())
601 - // モーションの再生がない場合、待機モーションの中からランダムで再生する
602 - StartRandomMotion(MotionGroupIdle, PriorityIdle);
607 - motionUpdated = _motionManager->UpdateMotion(_model, deltaTimeSeconds); // モーションを更新
609 - _model->SaveParameters(); // 状態を保存
610 - //-----------------------------------------------------------------
611 + auto idMan = CubismFramework::GetIdManager();
612 + auto params = _detector->getParams();
615 - if (!motionUpdated)
617 - if (_eyeBlink != NULL)
618 + // NOTE: Apparently, this LoadParameters/SaveParameters pair
619 + // is needed for auto breath to work.
620 + _model->LoadParameters(); // 前回セーブされた状態をロード
621 + if (_motionManager->IsFinished() && params.randomMotion)
623 - // メインモーションの更新がないとき
624 - _eyeBlink->UpdateParameters(_model, deltaTimeSeconds); // 目パチ
625 + // モーションの再生がない場合、待機モーションの中からランダムで再生する
626 + StartRandomMotion(MotionGroupIdle, PriorityIdle);
630 - if (_expressionManager != NULL)
632 - _expressionManager->UpdateMotion(_model, deltaTimeSeconds); // 表情でパラメータ更新(相対変化)
637 - _model->AddParameterValue(_idParamAngleX, _dragX * 30); // -30から30の値を加える
638 - _model->AddParameterValue(_idParamAngleY, _dragY * 30);
639 - _model->AddParameterValue(_idParamAngleZ, _dragX * _dragY * -30);
642 - _model->AddParameterValue(_idParamBodyAngleX, _dragX * 10); // -10から10の値を加える
645 + _motionManager->UpdateMotion(_model, deltaTimeSeconds); // モーションを更新
647 + _model->SaveParameters(); // 状態を保存
650 - _model->AddParameterValue(_idParamEyeBallX, _dragX); // -1から1の値を加える
651 - _model->AddParameterValue(_idParamEyeBallY, _dragY);
654 - if (_breath != NULL)
656 - _breath->UpdateParameters(_model, deltaTimeSeconds);
657 + if (params.autoBlink && _eyeBlink)
659 + _eyeBlink->UpdateParameters(_model, deltaTimeSeconds);
663 + _model->SetParameterValue(idMan->GetId(_("ParamEyeLOpen")),
664 + params.leftEyeOpenness);
665 + _model->SetParameterValue(idMan->GetId(_("ParamEyeROpen")),
666 + params.rightEyeOpenness);
668 + _model->SetParameterValue(idMan->GetId(_("ParamMouthForm")),
670 + _model->SetParameterValue(idMan->GetId(_("ParamMouthOpenY")),
671 + params.mouthOpenness);
672 + _model->SetParameterValue(idMan->GetId(_("ParamEyeLSmile")),
673 + params.leftEyeSmile);
674 + _model->SetParameterValue(idMan->GetId(_("ParamEyeRSmile")),
675 + params.rightEyeSmile);
676 + _model->SetParameterValue(idMan->GetId(_("ParamAngleX")),
677 + params.faceXAngle);
678 + _model->SetParameterValue(idMan->GetId(_("ParamAngleY")),
679 + params.faceYAngle);
680 + _model->SetParameterValue(idMan->GetId(_("ParamAngleZ")),
681 + params.faceZAngle);
682 + if (params.autoBreath && _breath)
684 + // Note: _model->LoadParameters and SaveParameters is needed
685 + // before - see above.
686 + _breath->UpdateParameters(_model, deltaTimeSeconds);
691 @@ -396,22 +365,6 @@ void LAppModel::Update()
692 _physics->Evaluate(_model, deltaTimeSeconds);
698 - // リアルタイムでリップシンクを行う場合、システムから音量を取得して0〜1の範囲で値を入力します。
699 - csmFloat32 value = 0.0f;
702 - _wavFileHandler.Update(deltaTimeSeconds);
703 - value = _wavFileHandler.GetRms();
705 - for (csmUint32 i = 0; i < _lipSyncIds.GetSize(); ++i)
707 - _model->AddParameterValue(_lipSyncIds[i], value, 0.8f);
714 @@ -480,7 +433,6 @@ CubismMotionQueueEntryHandle LAppModel::
716 csmString path = voice;
717 path = _modelHomeDir + path;
718 - _wavFileHandler.Start(path);
722 @@ -632,3 +584,37 @@ Csm::Rendering::CubismOffscreenFrame_Ope
724 return _renderBuffer;
727 +void LAppModel::SetFacialLandmarkDetector(FacialLandmarkDetector *detector)
729 + _detector = detector;
732 +Csm::csmString LAppModel::_(std::string s)
735 + if (_useOldParamId)
737 + if (s == "ParamTere")
739 + ans = "PARAM_CHEEK";
743 + for (size_t i = 0; i < s.size(); i++)
745 + if (std::isupper(s[i]) && i != 0)
749 + ans += std::toupper(s[i]);
757 + return csmString(ans.c_str());
760 diff -pruN --exclude build ./demo_clean/src/LAppModel.hpp ./demo_dev/src/LAppModel.hpp
761 --- ./demo_clean/src/LAppModel.hpp 2021-02-17 01:23:17.000000000 +0000
762 +++ ./demo_dev/src/LAppModel.hpp 2021-04-28 11:49:43.166296000 +0100
764 #include <Type/csmRectF.hpp>
765 #include <Rendering/OpenGL/CubismOffscreenSurface_OpenGLES2.hpp>
767 -#include "LAppWavFileHandler.hpp"
768 +#include "facial_landmark_detector.h"
771 * @brief ユーザーが実際に使用するモデルの実装クラス<br>
772 @@ -25,8 +25,11 @@ class LAppModel : public Csm::CubismUser
777 + * @param[in] useOldParamId : If true, translate new (Cubism 3+)
778 + * parameter IDs to old (Cubism 2.1) ones
781 + LAppModel(bool useOldParamId);
785 @@ -114,6 +117,13 @@ public:
787 Csm::Rendering::CubismOffscreenFrame_OpenGLES2& GetRenderBuffer();
790 + * @brief Set the pointer to the FacialLandmarkDetector instance
792 + * @param[in] detector : Pointer to FacialLandmarkDetector instance
794 + void SetFacialLandmarkDetector(FacialLandmarkDetector *detector);
798 * @brief モデルを描画する処理。モデルを描画する空間のView-Projection行列を渡す。
799 @@ -167,6 +177,17 @@ private:
801 void ReleaseExpressions();
804 + * @brief Translate new (Cubism 3+) parameter IDs to old (Cubism 2.1) ones
806 + * @param[in] s : New parameter ID
808 + * @return Old parameter ID
810 + Csm::csmString _(std::string s);
812 + bool _useOldParamId;
814 Csm::ICubismModelSetting* _modelSetting; ///< モデルセッティング情報
815 Csm::csmString _modelHomeDir; ///< モデルセッティングが置かれたディレクトリ
816 Csm::csmFloat32 _userTimeSeconds; ///< デルタ時間の積算値[秒]
817 @@ -183,9 +204,9 @@ private:
818 const Csm::CubismId* _idParamEyeBallX; ///< パラメータID: ParamEyeBallX
819 const Csm::CubismId* _idParamEyeBallY; ///< パラメータID: ParamEyeBallXY
821 - LAppWavFileHandler _wavFileHandler; ///< wavファイルハンドラ
823 Csm::Rendering::CubismOffscreenFrame_OpenGLES2 _renderBuffer; ///< フレームバッファ以外の描画先
825 + FacialLandmarkDetector *_detector;
829 diff -pruN --exclude build ./demo_clean/src/LAppPal.cpp ./demo_dev/src/LAppPal.cpp
830 --- ./demo_clean/src/LAppPal.cpp 2021-02-17 01:23:17.000000000 +0000
831 +++ ./demo_dev/src/LAppPal.cpp 2021-04-28 11:49:43.170296000 +0100
835 #include "LAppPal.hpp"
836 +#include <stdexcept>
840 @@ -45,10 +46,7 @@ csmByte* LAppPal::LoadFileAsBytes(const
841 file.open(path, std::ios::in | std::ios::binary);
844 - if (DebugLogEnable)
846 - PrintLog("file open error");
848 + throw std::runtime_error("Failed to open file " + filePath);
851 file.read(buf, size);
852 diff -pruN --exclude build ./demo_clean/src/LAppTextureManager.cpp ./demo_dev/src/LAppTextureManager.cpp
853 --- ./demo_clean/src/LAppTextureManager.cpp 2021-02-17 01:23:17.000000000 +0000
854 +++ ./demo_dev/src/LAppTextureManager.cpp 2021-04-28 11:49:43.178296000 +0100
855 @@ -96,6 +96,46 @@ LAppTextureManager::TextureInfo* LAppTex
859 +LAppTextureManager::TextureInfo* LAppTextureManager::CreateTextureFromColor(
860 + uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha
863 + int width = 8, height = 8;
865 + uint8_t pixels[height][width][4];
866 + for (std::size_t h = 0; h < height; h++)
868 + for (std::size_t w = 0; w < width; w++)
870 + pixels[h][w][0] = red;
871 + pixels[h][w][1] = green;
872 + pixels[h][w][2] = blue;
873 + pixels[h][w][3] = alpha;
878 + glGenTextures(1, &textureId);
879 + glBindTexture(GL_TEXTURE_2D, textureId);
880 + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
882 + glGenerateMipmap(GL_TEXTURE_2D);
883 + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
884 + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
885 + glBindTexture(GL_TEXTURE_2D, 0);
888 + LAppTextureManager::TextureInfo* textureInfo = new LAppTextureManager::TextureInfo();
889 + textureInfo->fileName = "";
890 + textureInfo->width = width;
891 + textureInfo->height = height;
892 + textureInfo->id = textureId;
894 + _textures.PushBack(textureInfo);
896 + return textureInfo;
899 void LAppTextureManager::ReleaseTextures()
901 for (Csm::csmUint32 i = 0; i < _textures.GetSize(); i++)
902 diff -pruN --exclude build ./demo_clean/src/LAppTextureManager.hpp ./demo_dev/src/LAppTextureManager.hpp
903 --- ./demo_clean/src/LAppTextureManager.hpp 2021-02-17 01:23:17.000000000 +0000
904 +++ ./demo_dev/src/LAppTextureManager.hpp 2021-04-28 11:49:43.178296000 +0100
905 @@ -72,6 +72,8 @@ public:
907 TextureInfo* CreateTextureFromPngFile(std::string fileName);
909 + TextureInfo *CreateTextureFromColor(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha = 255);
914 diff -pruN --exclude build ./demo_clean/src/LAppView.cpp ./demo_dev/src/LAppView.cpp
915 --- ./demo_clean/src/LAppView.cpp 2021-02-17 01:23:17.000000000 +0000
916 +++ ./demo_dev/src/LAppView.cpp 2021-04-28 11:49:43.178296000 +0100
918 #include "LAppLive2DManager.hpp"
919 #include "LAppTextureManager.hpp"
920 #include "LAppDefine.hpp"
921 -#include "TouchManager.hpp"
922 #include "LAppSprite.hpp"
923 #include "LAppModel.hpp"
925 @@ -26,8 +25,6 @@ using namespace LAppDefine;
926 LAppView::LAppView():
932 _renderTarget(SelectTarget_None)
934 @@ -35,8 +32,6 @@ LAppView::LAppView():
935 _clearColor[1] = 1.0f;
936 _clearColor[2] = 1.0f;
937 _clearColor[3] = 0.0f;
939 - _touchManager = new TouchManager();
941 // デバイス座標からスクリーン座標に変換するための
942 _deviceToScreen = new CubismMatrix44();
943 @@ -52,10 +47,7 @@ LAppView::~LAppView()
946 delete _deviceToScreen;
947 - delete _touchManager;
953 void LAppView::Initialize()
954 @@ -107,9 +99,6 @@ void LAppView::Initialize()
955 void LAppView::Render()
962 LAppLive2DManager* Live2DManager = LAppLive2DManager::GetInstance();
964 @@ -151,35 +140,17 @@ void LAppView::InitializeSprite()
965 glfwGetWindowSize(LAppDelegate::GetInstance()->GetWindow(), &width, &height);
967 LAppTextureManager* textureManager = LAppDelegate::GetInstance()->GetTextureManager();
968 - const string resourcesPath = LAppDelegate::GetInstance()->GetRootDirectory() + ResourcesPath;
970 - string imageName = BackImageName;
971 - LAppTextureManager::TextureInfo* backgroundTexture = textureManager->CreateTextureFromPngFile(resourcesPath + imageName);
973 + LAppTextureManager::TextureInfo* backgroundTexture =
974 + textureManager->CreateTextureFromColor(0, 255, 0);
976 float x = width * 0.5f;
977 float y = height * 0.5f;
978 - float fWidth = static_cast<float>(backgroundTexture->width * 2.0f);
979 - float fHeight = static_cast<float>(height) * 0.95f;
980 + float fWidth = static_cast<float>(width);
981 + float fHeight = static_cast<float>(height);
982 _back = new LAppSprite(x, y, fWidth, fHeight, backgroundTexture->id, _programId);
984 - imageName = GearImageName;
985 - LAppTextureManager::TextureInfo* gearTexture = textureManager->CreateTextureFromPngFile(resourcesPath + imageName);
987 - x = static_cast<float>(width - gearTexture->width * 0.5f);
988 - y = static_cast<float>(height - gearTexture->height * 0.5f);
989 - fWidth = static_cast<float>(gearTexture->width);
990 - fHeight = static_cast<float>(gearTexture->height);
991 - _gear = new LAppSprite(x, y, fWidth, fHeight, gearTexture->id, _programId);
993 - imageName = PowerImageName;
994 - LAppTextureManager::TextureInfo* powerTexture = textureManager->CreateTextureFromPngFile(resourcesPath + imageName);
996 - x = static_cast<float>(width - powerTexture->width * 0.5f);
997 - y = static_cast<float>(powerTexture->height * 0.5f);
998 - fWidth = static_cast<float>(powerTexture->width);
999 - fHeight = static_cast<float>(powerTexture->height);
1000 - _power = new LAppSprite(x, y, fWidth, fHeight, powerTexture->id, _programId);
1005 @@ -187,52 +158,6 @@ void LAppView::InitializeSprite()
1009 -void LAppView::OnTouchesBegan(float px, float py) const
1011 - _touchManager->TouchesBegan(px, py);
1014 -void LAppView::OnTouchesMoved(float px, float py) const
1016 - float viewX = this->TransformViewX(_touchManager->GetX());
1017 - float viewY = this->TransformViewY(_touchManager->GetY());
1019 - _touchManager->TouchesMoved(px, py);
1021 - LAppLive2DManager* Live2DManager = LAppLive2DManager::GetInstance();
1022 - Live2DManager->OnDrag(viewX, viewY);
1025 -void LAppView::OnTouchesEnded(float px, float py) const
1028 - LAppLive2DManager* live2DManager = LAppLive2DManager::GetInstance();
1029 - live2DManager->OnDrag(0.0f, 0.0f);
1033 - float x = _deviceToScreen->TransformX(_touchManager->GetX()); // 論理座標変換した座標を取得。
1034 - float y = _deviceToScreen->TransformY(_touchManager->GetY()); // 論理座標変換した座標を取得。
1035 - if (DebugTouchLogEnable)
1037 - LAppPal::PrintLog("[APP]touchesEnded x:%.2f y:%.2f", x, y);
1039 - live2DManager->OnTap(x, y);
1042 - if (_gear->IsHit(px, py))
1044 - live2DManager->NextScene();
1048 - if (_power->IsHit(px, py))
1050 - LAppDelegate::GetInstance()->AppEnd();
1055 float LAppView::TransformViewX(float deviceX) const
1057 float screenX = _deviceToScreen->TransformX(deviceX); // 論理座標変換した座標を取得。
1058 @@ -374,32 +299,4 @@ void LAppView::ResizeSprite()
1059 _back->ResetRect(x, y, fWidth, fHeight);
1065 - GLuint id = _power->GetTextureId();
1066 - LAppTextureManager::TextureInfo* texInfo = textureManager->GetTextureInfoById(id);
1069 - x = static_cast<float>(width - texInfo->width * 0.5f);
1070 - y = static_cast<float>(texInfo->height * 0.5f);
1071 - fWidth = static_cast<float>(texInfo->width);
1072 - fHeight = static_cast<float>(texInfo->height);
1073 - _power->ResetRect(x, y, fWidth, fHeight);
1079 - GLuint id = _gear->GetTextureId();
1080 - LAppTextureManager::TextureInfo* texInfo = textureManager->GetTextureInfoById(id);
1083 - x = static_cast<float>(width - texInfo->width * 0.5f);
1084 - y = static_cast<float>(height - texInfo->height * 0.5f);
1085 - fWidth = static_cast<float>(texInfo->width);
1086 - fHeight = static_cast<float>(texInfo->height);
1087 - _gear->ResetRect(x, y, fWidth, fHeight);
1091 diff -pruN --exclude build ./demo_clean/src/LAppView.hpp ./demo_dev/src/LAppView.hpp
1092 --- ./demo_clean/src/LAppView.hpp 2021-02-17 01:23:17.000000000 +0000
1093 +++ ./demo_dev/src/LAppView.hpp 2021-04-28 11:49:43.178296000 +0100
1095 #include "CubismFramework.hpp"
1096 #include <Rendering/OpenGL/CubismOffscreenSurface_OpenGLES2.hpp>
1098 -class TouchManager;
1102 @@ -66,30 +65,6 @@ public:
1103 void ResizeSprite();
1106 - * @brief タッチされたときに呼ばれる。
1108 - * @param[in] pointX スクリーンX座標
1109 - * @param[in] pointY スクリーンY座標
1111 - void OnTouchesBegan(float pointX, float pointY) const;
1114 - * @brief タッチしているときにポインタが動いたら呼ばれる。
1116 - * @param[in] pointX スクリーンX座標
1117 - * @param[in] pointY スクリーンY座標
1119 - void OnTouchesMoved(float pointX, float pointY) const;
1122 - * @brief タッチが終了したら呼ばれる。
1124 - * @param[in] pointX スクリーンX座標
1125 - * @param[in] pointY スクリーンY座標
1127 - void OnTouchesEnded(float pointX, float pointY) const;
1130 * @brief X座標をView座標に変換する。
1132 * @param[in] deviceX デバイスX座標
1133 @@ -147,13 +122,10 @@ public:
1134 void SetRenderTargetClearColor(float r, float g, float b);
1137 - TouchManager* _touchManager; ///< タッチマネージャー
1138 Csm::CubismMatrix44* _deviceToScreen; ///< デバイスからスクリーンへの行列
1139 Csm::CubismViewMatrix* _viewMatrix; ///< viewMatrix
1140 GLuint _programId; ///< シェーダID
1141 LAppSprite* _back; ///< 背景画像
1142 - LAppSprite* _gear; ///< ギア画像
1143 - LAppSprite* _power; ///< 電源画像
1145 // レンダリング先を別ターゲットにする方式の場合に使用
1146 LAppSprite* _renderSprite; ///< モードによっては_renderBufferのテクスチャを描画
1147 diff -pruN --exclude build ./demo_clean/src/main.cpp ./demo_dev/src/main.cpp
1148 --- ./demo_clean/src/main.cpp 2021-02-17 01:23:17.000000000 +0000
1149 +++ ./demo_dev/src/main.cpp 2021-04-28 11:49:43.178296000 +0100
1151 * that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html.
1155 +#include <stdexcept>
1158 +#ifdef __cpp_lib_filesystem
1159 +#include <filesystem>
1160 +namespace fs = std::filesystem;
1162 +#include <experimental/filesystem>
1163 +namespace fs = std::experimental::filesystem;
1167 #include "LAppDelegate.hpp"
1168 +#include "LAppLive2DManager.hpp"
1169 +#include "facial_landmark_detector.h"
1175 + std::string windowTitle;
1176 + std::string rootDir;
1177 + float scaleFactor;
1180 + std::string modelName;
1181 + bool oldId; // If true, translate new (Cubism 3+) parameter IDs to old (Cubism 2.1) IDs
1182 + std::string cfgPath; // Path to config file for FacialLandmarkDetector
1185 +CmdArgs parseArgv(int argc, char *argv[])
1187 + // I think the command-line args are simple enough to not justify using a library...
1189 + // Set default values
1190 + cmdArgs.windowWidth = 600;
1191 + cmdArgs.windowHeight = 600;
1192 + cmdArgs.windowTitle = "FacialLandmarksForCubism example";
1193 + cmdArgs.rootDir = fs::current_path();
1194 + cmdArgs.scaleFactor = 4.5f;
1195 + cmdArgs.translateX = 0.0f;
1196 + cmdArgs.translateY = -3.1f;
1197 + cmdArgs.modelName = "Haru";
1198 + cmdArgs.oldId = false;
1199 + cmdArgs.cfgPath = "";
1204 + std::string arg = argv[i];
1205 + std::stringstream ss;
1207 + if (arg == "--window-width" || arg == "-W") // capital W for consistency with height
1209 + ss << argv[i + 1];
1210 + if (!(ss >> cmdArgs.windowWidth))
1212 + throw std::runtime_error("Invalid argument for window width");
1215 + else if (arg == "--window-height" || arg == "-H") // avoiding "-h", typically for help
1217 + ss << argv[i + 1];
1218 + if (!(ss >> cmdArgs.windowHeight))
1220 + throw std::runtime_error("Invalid argument for window height");
1223 + else if (arg == "--window-title" || arg == "-t")
1225 + cmdArgs.windowTitle = argv[i + 1];
1227 + else if (arg == "--root-dir" || arg == "-d")
1229 + cmdArgs.rootDir = argv[i + 1];
1231 + else if (arg == "--scale-factor" || arg == "-f")
1233 + ss << argv[i + 1];
1234 + if (!(ss >> cmdArgs.scaleFactor))
1236 + throw std::runtime_error("Invalid argument for scale factor");
1239 + else if (arg == "--translate-x" || arg == "-x")
1241 + ss << argv[i + 1];
1242 + if (!(ss >> cmdArgs.translateX))
1244 + throw std::runtime_error("Invalid argument for translate X");
1247 + else if (arg == "--translate-y" || arg == "-y")
1249 + ss << argv[i + 1];
1250 + if (!(ss >> cmdArgs.translateY))
1252 + throw std::runtime_error("Invalid argument for translate Y");
1255 + else if (arg == "--model" || arg == "-m")
1257 + cmdArgs.modelName = argv[i + 1];
1259 + else if (arg == "--config" || arg == "-c")
1261 + cmdArgs.cfgPath = argv[i + 1];
1263 + else if (arg == "--old-param-id" || arg == "-o")
1265 + cmdArgs.oldId = (argv[i + 1][0] == '1');
1269 + throw std::runtime_error("Unrecognized argument: " + arg);
1278 int main(int argc, char* argv[])
1280 - // create the application instance
1281 - if (LAppDelegate::GetInstance()->Initialize() == GL_FALSE)
1282 + auto cmdArgs = parseArgv(argc, argv);
1284 + LAppDelegate *delegate = LAppDelegate::GetInstance();
1286 + if (!delegate->Initialize(cmdArgs.windowWidth,
1287 + cmdArgs.windowHeight,
1288 + cmdArgs.windowTitle.c_str()))
1291 + throw std::runtime_error("Unable to initialize LAppDelegate");
1294 - LAppDelegate::GetInstance()->Run();
1295 + delegate->SetRootDirectory(cmdArgs.rootDir);
1297 + FacialLandmarkDetector detector(cmdArgs.cfgPath);
1299 + std::thread detectorThread(&FacialLandmarkDetector::mainLoop,
1302 + LAppLive2DManager *manager = LAppLive2DManager::GetInstance();
1303 + manager->SetModel(cmdArgs.modelName, cmdArgs.oldId);
1305 + manager->SetProjectionScaleTranslate(cmdArgs.scaleFactor,
1306 + cmdArgs.translateX,
1307 + cmdArgs.translateY);
1308 + manager->SetFacialLandmarkDetector(&detector);
1313 + detectorThread.join();