1 diff -pruN --exclude build ./demo_clean/CMakeLists.txt ./demo_dev/CMakeLists.txt
2 --- ./demo_clean/CMakeLists.txt 2025-05-28 10:36:54.000000000 +0100
3 +++ ./demo_dev/CMakeLists.txt 2025-05-30 00:21:21.567335561 +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-5-r.4)
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 @@ -35,7 +35,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 @@ -67,6 +67,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})
31 # Add common source files.
32 @@ -79,9 +82,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 2025-05-28 10:36:54.000000000 +0100
47 +++ ./demo_dev/scripts/make_gcc 2023-05-28 08:11:25.750067591 +0100
48 @@ -5,42 +5,9 @@ set -ue
49 SCRIPT_PATH=$(cd $(dirname $0) && pwd)
50 CMAKE_PATH=$SCRIPT_PATH/..
51 BUILD_PATH=$SCRIPT_PATH/../build/make_gcc
55 -if [ "$#" -ne 0 ]; then
62 - if [ -z "$DATA" ]; then
63 - echo "Choose which format you would like to create the demo."
64 - echo "Full version : 1"
65 - echo "Minimum version : 2"
66 - read -p "Your Choice : " DATA
71 - echo "Making Full Demo"
75 - echo "Making Minimum Demo"
79 - echo "You need to enter a valid number."
85 cmake -S "$CMAKE_PATH" \
87 - -D CMAKE_BUILD_TYPE=Release \
88 - -D CSM_MINIMUM_DEMO=$MINIMUM_DEMO \
89 - -D GLFW_BUILD_WAYLAND=OFF
90 -cd "$BUILD_PATH" && make
91 + -D CMAKE_BUILD_TYPE=Release
92 +cd "$BUILD_PATH" && make -j4
93 diff -pruN --exclude build ./demo_clean/src/LAppDelegate.cpp ./demo_dev/src/LAppDelegate.cpp
94 --- ./demo_clean/src/LAppDelegate.cpp 2025-05-28 10:36:54.000000000 +0100
95 +++ ./demo_dev/src/LAppDelegate.cpp 2025-05-30 00:26:43.606709298 +0100
96 @@ -46,7 +46,8 @@ void LAppDelegate::ReleaseInstance()
100 -bool LAppDelegate::Initialize()
101 +bool LAppDelegate::Initialize(int initWindowWidth, int initWindowHeight,
102 + const char *windowTitle)
106 @@ -64,7 +65,13 @@ bool LAppDelegate::Initialize()
110 - _window = glfwCreateWindow(RenderTargetWidth, RenderTargetHeight, "SAMPLE", NULL, NULL);
111 + _window = glfwCreateWindow(
112 + initWindowWidth ? initWindowWidth : RenderTargetWidth,
113 + initWindowHeight ? initWindowHeight : RenderTargetHeight,
114 + windowTitle ? windowTitle : "SAMPLE",
121 @@ -96,10 +103,6 @@ bool LAppDelegate::Initialize()
123 glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
126 - glfwSetMouseButtonCallback(_window, EventHandler::OnMouseCallBack);
127 - glfwSetCursorPosCallback(_window, EventHandler::OnMouseCallBack);
131 glfwGetWindowSize(LAppDelegate::GetInstance()->GetWindow(), &width, &height);
132 diff -pruN --exclude build ./demo_clean/src/LAppDelegate.hpp ./demo_dev/src/LAppDelegate.hpp
133 --- ./demo_clean/src/LAppDelegate.hpp 2025-05-28 10:36:54.000000000 +0100
134 +++ ./demo_dev/src/LAppDelegate.hpp 2025-05-30 00:27:33.073033913 +0100
135 @@ -40,7 +40,8 @@ public:
137 * @brief APPに必要なものを初期化する。
140 + bool Initialize(int initWindowWidth = 0, int initWindowHeight = 0,
141 + const char *windowTitle = "SAMPLE");
145 diff -pruN --exclude build ./demo_clean/src/LAppLive2DManager.cpp ./demo_dev/src/LAppLive2DManager.cpp
146 --- ./demo_clean/src/LAppLive2DManager.cpp 2025-05-28 10:36:54.000000000 +0100
147 +++ ./demo_dev/src/LAppLive2DManager.cpp 2025-05-30 00:44:31.339709983 +0100
151 #include "LAppLive2DManager.hpp"
161 #include <GLFW/glfw3.h>
162 #include <Rendering/CubismRenderer.hpp>
163 @@ -68,12 +62,11 @@ void LAppLive2DManager::ReleaseInstance(
165 LAppLive2DManager::LAppLive2DManager()
168 + , _projScaleFactor(1.0f)
169 + , _translateX(0.0f)
170 + , _translateY(0.0f)
172 _viewMatrix = new CubismMatrix44();
175 - ChangeScene(_sceneIndex);
178 LAppLive2DManager::~LAppLive2DManager()
179 @@ -92,60 +85,6 @@ void LAppLive2DManager::ReleaseAllModel(
183 -void LAppLive2DManager::SetUpModel()
185 - // ResourcesPathの中にあるフォルダ名を全てクロールし、モデルが存在するフォルダを定義する。
186 - // フォルダはあるが同名の.model3.jsonが見つからなかった場合はリストに含めない。
187 - struct dirent *dirent;
188 - csmString crawlPath(LAppDelegate::GetInstance()->GetExecuteAbsolutePath().c_str());
189 - crawlPath += ResourcesPath;
191 - DIR *pDir = opendir(crawlPath.GetRawString());
192 - if (pDir == NULL) return;
196 - while ((dirent = readdir(pDir)) != NULL)
198 - if ((dirent->d_type & DT_DIR) && strcmp(dirent->d_name, "..") != 0)
200 - // フォルダと同名の.model3.jsonがあるか探索する
201 - struct dirent *dirent2;
203 - csmString modelName(dirent->d_name);
205 - csmString modelPath(crawlPath);
206 - modelPath += modelName;
207 - modelPath.Append(1, '/');
209 - csmString model3jsonName(modelName);
210 - model3jsonName += ".model3.json";
212 - DIR *pDir2 = opendir(modelPath.GetRawString());
213 - while ((dirent2 = readdir(pDir2)) != NULL)
215 - if (strcmp(dirent2->d_name, model3jsonName.GetRawString()) == 0)
217 - _modelDir.PushBack(csmString(dirent->d_name));
224 - qsort(_modelDir.GetPtr(), _modelDir.GetSize(), sizeof(csmString), CompareCsmString);
227 -csmVector<csmString> LAppLive2DManager::GetModelDir() const
232 -csmInt32 LAppLive2DManager::GetModelDirSize() const
234 - return _modelDir.GetSize();
237 LAppModel* LAppLive2DManager::GetModel(csmUint32 no) const
239 if (no < _models.GetSize())
240 @@ -172,26 +111,6 @@ void LAppLive2DManager::OnTap(csmFloat32
242 LAppPal::PrintLogLn("[APP]tap point: {x:%.2f y:%.2f}", x, y);
245 - for (csmUint32 i = 0; i < _models.GetSize(); i++)
247 - if (_models[i]->HitTest(HitAreaNameHead, x, y))
249 - if (DebugLogEnable)
251 - LAppPal::PrintLogLn("[APP]hit area: [%s]", HitAreaNameHead);
253 - _models[i]->SetRandomExpression();
255 - else if (_models[i]->HitTest(HitAreaNameBody, x, y))
257 - if (DebugLogEnable)
259 - LAppPal::PrintLogLn("[APP]hit area: [%s]", HitAreaNameBody);
261 - _models[i]->StartRandomMotion(MotionGroupTapBody, PriorityNormal, FinishedMotion, BeganMotion);
266 void LAppLive2DManager::OnUpdate() const
267 @@ -215,12 +134,15 @@ void LAppLive2DManager::OnUpdate() const
269 // 横に長いモデルを縦長ウィンドウに表示する際モデルの横サイズでscaleを算出する
270 model->GetModelMatrix()->SetWidth(2.0f);
271 - projection.Scale(1.0f, static_cast<float>(width) / static_cast<float>(height));
272 + projection.Scale(_projScaleFactor,
273 + _projScaleFactor * static_cast<float>(width) / static_cast<float>(height));
277 - projection.Scale(static_cast<float>(height) / static_cast<float>(width), 1.0f);
278 + projection.Scale(_projScaleFactor * static_cast<float>(height) / static_cast<float>(width),
281 + projection.Translate(_translateX, _translateY);
284 if (_viewMatrix != NULL)
285 @@ -237,37 +159,15 @@ void LAppLive2DManager::OnUpdate() const
289 -void LAppLive2DManager::NextScene()
290 +void LAppLive2DManager::SetModel(std::string modelName, bool useOldParamId)
292 - csmInt32 no = (_sceneIndex + 1) % GetModelDirSize();
296 -void LAppLive2DManager::ChangeScene(Csm::csmInt32 index)
298 - _sceneIndex = index;
299 - if (DebugLogEnable)
301 - LAppPal::PrintLogLn("[APP]model index: %d", _sceneIndex);
304 - // ModelDir[]に保持したディレクトリ名から
305 - // model3.jsonのパスを決定する.
306 - // ディレクトリ名とmodel3.jsonの名前を一致させておくこと.
307 - const csmString& model = _modelDir[index];
308 - LAppPal::PrintLogLn("[APP]_modelDir: %s", model.GetRawString());
310 - csmString modelPath(LAppDelegate::GetInstance()->GetExecuteAbsolutePath().c_str());
311 - modelPath += ResourcesPath;
312 - modelPath += model;
313 - modelPath.Append(1, '/');
315 - csmString modelJsonName(model);
316 + std::string modelPath = LAppDelegate::GetInstance()->GetExecuteAbsolutePath() + ResourcesPath + modelName + "/";
317 + std::string modelJsonName = modelName;
318 modelJsonName += ".model3.json";
321 - _models.PushBack(new LAppModel());
322 - _models[0]->LoadAssets(modelPath.GetRawString(), modelJsonName.GetRawString());
323 + _models.PushBack(new LAppModel(useOldParamId));
324 + _models[0]->LoadAssets(modelPath.c_str(), modelJsonName.c_str());
327 * モデル半透明表示を行うサンプルを提示する。
328 @@ -288,8 +188,8 @@ void LAppLive2DManager::ChangeScene(Csm:
330 #if defined(USE_RENDER_TARGET) || defined(USE_MODEL_RENDER_TARGET)
331 // モデル個別にαを付けるサンプルとして、もう1体モデルを作成し、少し位置をずらす
332 - _models.PushBack(new LAppModel());
333 - _models[1]->LoadAssets(modelPath.GetRawString(), modelJsonName.GetRawString());
334 + _models.PushBack(new LAppModel(useOldParamId));
335 + _models[1]->LoadAssets(modelPath.c_str(), modelJsonName.c_str());
336 _models[1]->GetModelMatrix()->TranslateX(0.2f);
339 @@ -317,3 +217,20 @@ void LAppLive2DManager::SetViewMatrix(Cu
340 _viewMatrix->GetArray()[i] = m->GetArray()[i];
344 +void LAppLive2DManager::SetFacialLandmarkDetector(FacialLandmarkDetector *detector)
346 + for (auto it = _models.Begin(); it != _models.End(); ++it)
348 + (*it)->SetFacialLandmarkDetector(detector);
352 +void LAppLive2DManager::SetProjectionScaleTranslate(float scaleFactor,
356 + _projScaleFactor = scaleFactor;
357 + _translateX = translateX;
358 + _translateY = translateY;
360 diff -pruN --exclude build ./demo_clean/src/LAppLive2DManager.hpp ./demo_dev/src/LAppLive2DManager.hpp
361 --- ./demo_clean/src/LAppLive2DManager.hpp 2025-05-28 10:36:54.000000000 +0100
362 +++ ./demo_dev/src/LAppLive2DManager.hpp 2025-05-30 00:29:35.257630136 +0100
368 #include <CubismFramework.hpp>
369 #include <Math/CubismMatrix44.hpp>
370 #include <Type/csmVector.hpp>
374 +class FacialLandmarkDetector;
377 * @brief サンプルアプリケーションにおいてCubismModelを管理するクラス<br>
378 * モデル生成と破棄、タップイベントの処理、モデル切り替えを行う。
379 @@ -36,24 +39,6 @@ public:
380 static void ReleaseInstance();
383 - * @brief Resources フォルダにあるモデルフォルダ名をセットする
389 - * @brief Resources フォルダにあるモデルフォルダ名を取得する
392 - Csm::csmVector<Csm::csmString> GetModelDir() const;
395 - * @brief Resources フォルダにあるモデルフォルダのサイズを取得する
398 - Csm::csmInt32 GetModelDirSize() const;
401 * @brief 現在のシーンで保持しているモデルを返す
403 * @param[in] no モデルリストのインデックス値
404 @@ -90,16 +75,14 @@ public:
405 void OnUpdate() const;
408 - * @brief 次のシーンに切り替える<br>
409 - * サンプルアプリケーションではモデルセットの切り替えを行う。
414 - * @brief シーンを切り替える<br>
415 - * サンプルアプリケーションではモデルセットの切り替えを行う。
417 - void ChangeScene(Csm::csmInt32 index);
418 + * @brief Set model data
420 + * @param[in] modelName : Name of model, should be the same for both
421 + * the directory and the model3.json file
422 + * @param[in] useOldParamId : If true, translate new (Cubism 3+)
423 + * parameter IDs to old (Cubism 2.1) ones
425 + void SetModel(std::string modelName, bool useOldParamId);
429 @@ -112,6 +95,24 @@ public:
431 void SetViewMatrix(Live2D::Cubism::Framework::CubismMatrix44* m);
434 + * @brief Set the pointer to the FacialLandmarkDetector instance
436 + * @param[in] detector : Pointer to FacialLandmarkDetector instance
438 + void SetFacialLandmarkDetector(FacialLandmarkDetector *detector);
441 + * @brief Set projection scale factor and translation parameters
443 + * @param[in] scaleFactor : Scale factor applied in both X and Y directions
444 + * @param[in] translateX : Translation in X direction
445 + * @param[in] translateY : Translation in Y direction
447 + void SetProjectionScaleTranslate(float scaleFactor,
454 @@ -125,7 +126,8 @@ private:
456 Csm::CubismMatrix44* _viewMatrix; ///< モデル描画に用いるView行列
457 Csm::csmVector<LAppModel*> _models; ///< モデルインスタンスのコンテナ
458 - Csm::csmInt32 _sceneIndex; ///< 表示するシーンのインデックス値
460 - Csm::csmVector<Csm::csmString> _modelDir; ///< モデルディレクトリ名のコンテナ
461 + float _projScaleFactor;
465 diff -pruN --exclude build ./demo_clean/src/LAppModel.cpp ./demo_dev/src/LAppModel.cpp
466 --- ./demo_clean/src/LAppModel.cpp 2025-05-28 10:36:54.000000000 +0100
467 +++ ./demo_dev/src/LAppModel.cpp 2025-05-30 00:31:25.128030278 +0100
469 #include "LAppTextureManager.hpp"
470 #include "LAppDelegate.hpp"
472 +#include "facial_landmark_detector.h"
474 using namespace Live2D::Cubism::Framework;
475 using namespace Live2D::Cubism::Framework::DefaultParameterId;
476 using namespace LAppDefine;
478 -LAppModel::LAppModel()
479 +LAppModel::LAppModel(bool useOldParamId)
481 , _modelSetting(NULL)
482 , _userTimeSeconds(0.0f)
483 + , _detector(nullptr)
484 + , _useOldParamId(useOldParamId)
491 - _idParamAngleX = CubismFramework::GetIdManager()->GetId(ParamAngleX);
492 - _idParamAngleY = CubismFramework::GetIdManager()->GetId(ParamAngleY);
493 - _idParamAngleZ = CubismFramework::GetIdManager()->GetId(ParamAngleZ);
494 - _idParamBodyAngleX = CubismFramework::GetIdManager()->GetId(ParamBodyAngleX);
495 - _idParamEyeBallX = CubismFramework::GetIdManager()->GetId(ParamEyeBallX);
496 - _idParamEyeBallY = CubismFramework::GetIdManager()->GetId(ParamEyeBallY);
497 + _idParamAngleX = CubismFramework::GetIdManager()->GetId(_(ParamAngleX));
498 + _idParamAngleY = CubismFramework::GetIdManager()->GetId(_(ParamAngleY));
499 + _idParamAngleZ = CubismFramework::GetIdManager()->GetId(_(ParamAngleZ));
500 + _idParamBodyAngleX = CubismFramework::GetIdManager()->GetId(_(ParamBodyAngleX));
501 + _idParamEyeBallX = CubismFramework::GetIdManager()->GetId(_(ParamEyeBallX));
502 + _idParamEyeBallY = CubismFramework::GetIdManager()->GetId(_(ParamEyeBallY));
505 LAppModel::~LAppModel()
506 @@ -114,33 +118,6 @@ void LAppModel::SetupModel(ICubismModelS
507 DeleteBuffer(buffer, path.GetRawString());
511 - if (_modelSetting->GetExpressionCount() > 0)
513 - const csmInt32 count = _modelSetting->GetExpressionCount();
514 - for (csmInt32 i = 0; i < count; i++)
516 - csmString name = _modelSetting->GetExpressionName(i);
517 - csmString path = _modelSetting->GetExpressionFileName(i);
518 - path = _modelHomeDir + path;
520 - buffer = CreateBuffer(path.GetRawString(), &size);
521 - ACubismMotion* motion = LoadExpression(buffer, size, name.GetRawString());
525 - if (_expressions[name] != NULL)
527 - ACubismMotion::Delete(_expressions[name]);
528 - _expressions[name] = NULL;
530 - _expressions[name] = motion;
533 - DeleteBuffer(buffer, path.GetRawString());
538 if (strcmp(_modelSetting->GetPhysicsFileName(), "") != 0)
540 @@ -179,7 +156,7 @@ void LAppModel::SetupModel(ICubismModelS
541 breathParameters.PushBack(CubismBreath::BreathParameterData(_idParamAngleY, 0.0f, 8.0f, 3.5345f, 0.5f));
542 breathParameters.PushBack(CubismBreath::BreathParameterData(_idParamAngleZ, 0.0f, 10.0f, 5.5345f, 0.5f));
543 breathParameters.PushBack(CubismBreath::BreathParameterData(_idParamBodyAngleX, 0.0f, 4.0f, 15.5345f, 0.5f));
544 - breathParameters.PushBack(CubismBreath::BreathParameterData(CubismFramework::GetIdManager()->GetId(ParamBreath), 0.5f, 0.5f, 3.2345f, 0.5f));
545 + breathParameters.PushBack(CubismBreath::BreathParameterData(CubismFramework::GetIdManager()->GetId(_(ParamBreath)), 0.5f, 0.5f, 3.2345f, 0.5f));
547 _breath->SetParameters(breathParameters);
549 @@ -203,21 +180,6 @@ void LAppModel::SetupModel(ICubismModelS
555 - csmInt32 lipSyncIdCount = _modelSetting->GetLipSyncParameterCount();
556 - for (csmInt32 i = 0; i < lipSyncIdCount; ++i)
558 - _lipSyncIds.PushBack(_modelSetting->GetLipSyncParameterId(i));
562 - if (_modelSetting == NULL || _modelMatrix == NULL)
564 - LAppPal::PrintLogLn("Failed to SetupModel().");
569 csmMap<csmString, csmFloat32> layout;
570 _modelSetting->GetLayoutMap(layout);
571 @@ -322,62 +284,57 @@ void LAppModel::Update()
572 const csmFloat32 deltaTimeSeconds = LAppPal::GetDeltaTime();
573 _userTimeSeconds += deltaTimeSeconds;
575 - _dragManager->Update(deltaTimeSeconds);
576 - _dragX = _dragManager->GetX();
577 - _dragY = _dragManager->GetY();
579 - // モーションによるパラメータ更新の有無
580 - csmBool motionUpdated = false;
582 - //-----------------------------------------------------------------
583 - _model->LoadParameters(); // 前回セーブされた状態をロード
584 - if (_motionManager->IsFinished())
587 - // モーションの再生がない場合、待機モーションの中からランダムで再生する
588 - StartRandomMotion(MotionGroupIdle, PriorityIdle);
592 - motionUpdated = _motionManager->UpdateMotion(_model, deltaTimeSeconds); // モーションを更新
594 - _model->SaveParameters(); // 状態を保存
595 - //-----------------------------------------------------------------
596 + auto idMan = CubismFramework::GetIdManager();
597 + auto params = _detector->getParams();
600 - _opacity = _model->GetModelOpacity();
603 - if (!motionUpdated)
605 - if (_eyeBlink != NULL)
606 + // NOTE: Apparently, this LoadParameters/SaveParameters pair
607 + // is needed for auto breath to work.
608 + _model->LoadParameters(); // 前回セーブされた状態をロード
609 + if (_motionManager->IsFinished() && params.randomMotion)
611 - // メインモーションの更新がないとき
612 - _eyeBlink->UpdateParameters(_model, deltaTimeSeconds); // 目パチ
613 + // モーションの再生がない場合、待機モーションの中からランダムで再生する
614 + StartRandomMotion(MotionGroupIdle, PriorityIdle);
618 - if (_expressionManager != NULL)
620 - _expressionManager->UpdateMotion(_model, deltaTimeSeconds); // 表情でパラメータ更新(相対変化)
625 - _model->AddParameterValue(_idParamAngleX, _dragX * 30); // -30から30の値を加える
626 - _model->AddParameterValue(_idParamAngleY, _dragY * 30);
627 - _model->AddParameterValue(_idParamAngleZ, _dragX * _dragY * -30);
630 - _model->AddParameterValue(_idParamBodyAngleX, _dragX * 10); // -10から10の値を加える
633 + _motionManager->UpdateMotion(_model, deltaTimeSeconds); // モーションを更新
635 + _model->SaveParameters(); // 状態を保存
638 - _model->AddParameterValue(_idParamEyeBallX, _dragX); // -1から1の値を加える
639 - _model->AddParameterValue(_idParamEyeBallY, _dragY);
642 - if (_breath != NULL)
644 - _breath->UpdateParameters(_model, deltaTimeSeconds);
645 + if (params.autoBlink && _eyeBlink)
647 + _eyeBlink->UpdateParameters(_model, deltaTimeSeconds);
651 + _model->SetParameterValue(idMan->GetId(_("ParamEyeLOpen")),
652 + params.leftEyeOpenness);
653 + _model->SetParameterValue(idMan->GetId(_("ParamEyeROpen")),
654 + params.rightEyeOpenness);
656 + _model->SetParameterValue(idMan->GetId(_("ParamMouthForm")),
658 + _model->SetParameterValue(idMan->GetId(_("ParamMouthOpenY")),
659 + params.mouthOpenness);
660 + _model->SetParameterValue(idMan->GetId(_("ParamEyeLSmile")),
661 + params.leftEyeSmile);
662 + _model->SetParameterValue(idMan->GetId(_("ParamEyeRSmile")),
663 + params.rightEyeSmile);
664 + _model->SetParameterValue(idMan->GetId(_("ParamAngleX")),
665 + params.faceXAngle);
666 + _model->SetParameterValue(idMan->GetId(_("ParamAngleY")),
667 + params.faceYAngle);
668 + _model->SetParameterValue(idMan->GetId(_("ParamAngleZ")),
669 + params.faceZAngle);
670 + if (params.autoBreath && _breath)
672 + // Note: _model->LoadParameters and SaveParameters is needed
673 + // before - see above.
674 + _breath->UpdateParameters(_model, deltaTimeSeconds);
679 @@ -386,22 +343,6 @@ void LAppModel::Update()
680 _physics->Evaluate(_model, deltaTimeSeconds);
686 - // リアルタイムでリップシンクを行う場合、システムから音量を取得して0〜1の範囲で値を入力します。
687 - csmFloat32 value = 0.0f;
690 - _wavFileHandler.Update(deltaTimeSeconds);
691 - value = _wavFileHandler.GetRms();
693 - for (csmUint32 i = 0; i < _lipSyncIds.GetSize(); ++i)
695 - _model->AddParameterValue(_lipSyncIds[i], value, 0.8f);
702 @@ -464,7 +405,6 @@ CubismMotionQueueEntryHandle LAppModel::
704 csmString path = voice;
705 path = _modelHomeDir + path;
706 - _wavFileHandler.Start(path);
710 @@ -616,3 +556,37 @@ Csm::Rendering::CubismOffscreenSurface_O
712 return _renderBuffer;
715 +void LAppModel::SetFacialLandmarkDetector(FacialLandmarkDetector *detector)
717 + _detector = detector;
720 +Csm::csmString LAppModel::_(std::string s)
723 + if (_useOldParamId)
725 + if (s == "ParamTere")
727 + ans = "PARAM_CHEEK";
731 + for (size_t i = 0; i < s.size(); i++)
733 + if (std::isupper(s[i]) && i != 0)
737 + ans += std::toupper(s[i]);
745 + return csmString(ans.c_str());
748 diff -pruN --exclude build ./demo_clean/src/LAppModel.hpp ./demo_dev/src/LAppModel.hpp
749 --- ./demo_clean/src/LAppModel.hpp 2025-05-28 10:36:54.000000000 +0100
750 +++ ./demo_dev/src/LAppModel.hpp 2025-05-30 00:31:59.753598558 +0100
752 #include <Type/csmRectF.hpp>
753 #include <Rendering/OpenGL/CubismOffscreenSurface_OpenGLES2.hpp>
755 -#include "LAppWavFileHandler_Common.hpp"
756 #include "LAppModel_Common.hpp"
757 +#include "facial_landmark_detector.h"
760 * @brief ユーザーが実際に使用するモデルの実装クラス<br>
761 @@ -25,8 +25,11 @@ class LAppModel : public LAppModel_Commo
766 + * @param[in] useOldParamId : If true, translate new (Cubism 3+)
767 + * parameter IDs to old (Cubism 2.1) ones
770 + LAppModel(bool useOldParamId);
774 @@ -116,6 +119,13 @@ public:
776 Csm::Rendering::CubismOffscreenSurface_OpenGLES2& GetRenderBuffer();
779 + * @brief Set the pointer to the FacialLandmarkDetector instance
781 + * @param[in] detector : Pointer to FacialLandmarkDetector instance
783 + void SetFacialLandmarkDetector(FacialLandmarkDetector *detector);
787 * @brief モデルを描画する処理。モデルを描画する空間のView-Projection行列を渡す。
788 @@ -169,6 +179,17 @@ private:
790 void ReleaseExpressions();
793 + * @brief Translate new (Cubism 3+) parameter IDs to old (Cubism 2.1) ones
795 + * @param[in] s : New parameter ID
797 + * @return Old parameter ID
799 + Csm::csmString _(std::string s);
801 + bool _useOldParamId;
803 Csm::ICubismModelSetting* _modelSetting; ///< モデルセッティング情報
804 Csm::csmString _modelHomeDir; ///< モデルセッティングが置かれたディレクトリ
805 Csm::csmFloat32 _userTimeSeconds; ///< デルタ時間の積算値[秒]
806 @@ -185,7 +206,10 @@ private:
807 const Csm::CubismId* _idParamEyeBallX; ///< パラメータID: ParamEyeBallX
808 const Csm::CubismId* _idParamEyeBallY; ///< パラメータID: ParamEyeBallXY
810 - LAppWavFileHandler_Common _wavFileHandler; ///< wavファイルハンドラ
812 Csm::Rendering::CubismOffscreenSurface_OpenGLES2 _renderBuffer; ///< フレームバッファ以外の描画先
814 + FacialLandmarkDetector *_detector;
819 diff -pruN --exclude build ./demo_clean/src/LAppTextureManager.cpp ./demo_dev/src/LAppTextureManager.cpp
820 --- ./demo_clean/src/LAppTextureManager.cpp 2025-05-28 10:36:54.000000000 +0100
821 +++ ./demo_dev/src/LAppTextureManager.cpp 2025-05-30 00:33:38.759669165 +0100
822 @@ -96,6 +96,46 @@ LAppTextureManager::TextureInfo* LAppTex
826 +LAppTextureManager::TextureInfo* LAppTextureManager::CreateTextureFromColor(
827 + uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha
830 + int width = 8, height = 8;
832 + uint8_t pixels[height][width][4];
833 + for (std::size_t h = 0; h < height; h++)
835 + for (std::size_t w = 0; w < width; w++)
837 + pixels[h][w][0] = red;
838 + pixels[h][w][1] = green;
839 + pixels[h][w][2] = blue;
840 + pixels[h][w][3] = alpha;
845 + glGenTextures(1, &textureId);
846 + glBindTexture(GL_TEXTURE_2D, textureId);
847 + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
849 + glGenerateMipmap(GL_TEXTURE_2D);
850 + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
851 + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
852 + glBindTexture(GL_TEXTURE_2D, 0);
855 + LAppTextureManager::TextureInfo* textureInfo = new LAppTextureManager::TextureInfo();
856 + textureInfo->fileName = "";
857 + textureInfo->width = width;
858 + textureInfo->height = height;
859 + textureInfo->id = textureId;
861 + _texturesInfo.PushBack(textureInfo);
863 + return textureInfo;
866 void LAppTextureManager::ReleaseTextures()
868 for (Csm::csmUint32 i = 0; i < _texturesInfo.GetSize(); i++)
869 diff -pruN --exclude build ./demo_clean/src/LAppTextureManager.hpp ./demo_dev/src/LAppTextureManager.hpp
870 --- ./demo_clean/src/LAppTextureManager.hpp 2025-05-28 10:36:54.000000000 +0100
871 +++ ./demo_dev/src/LAppTextureManager.hpp 2025-05-30 00:33:05.342204345 +0100
872 @@ -41,6 +41,8 @@ public:
874 TextureInfo* CreateTextureFromPngFile(std::string fileName);
876 + TextureInfo *CreateTextureFromColor(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha = 255);
881 diff -pruN --exclude build ./demo_clean/src/LAppView.cpp ./demo_dev/src/LAppView.cpp
882 --- ./demo_clean/src/LAppView.cpp 2025-05-28 10:36:54.000000000 +0100
883 +++ ./demo_dev/src/LAppView.cpp 2025-05-30 00:38:38.310466491 +0100
884 @@ -81,9 +81,6 @@ void LAppView::Initialize(int width, int
885 void LAppView::Render()
892 LAppLive2DManager* Live2DManager = LAppLive2DManager::GetInstance();
894 @@ -125,35 +122,17 @@ void LAppView::InitializeSprite()
895 glfwGetWindowSize(LAppDelegate::GetInstance()->GetWindow(), &width, &height);
897 LAppTextureManager* textureManager = LAppDelegate::GetInstance()->GetTextureManager();
898 - const string resourcesPath = LAppDelegate::GetInstance()->GetExecuteAbsolutePath() + ResourcesPath;
900 - string imageName = BackImageName;
901 - LAppTextureManager::TextureInfo* backgroundTexture = textureManager->CreateTextureFromPngFile(resourcesPath + imageName);
903 + LAppTextureManager::TextureInfo* backgroundTexture =
904 + textureManager->CreateTextureFromColor(0, 255, 0);
906 float x = width * 0.5f;
907 float y = height * 0.5f;
908 - float fWidth = static_cast<float>(backgroundTexture->width * 2.0f);
909 - float fHeight = static_cast<float>(height) * 0.95f;
910 + float fWidth = static_cast<float>(width);
911 + float fHeight = static_cast<float>(height);
912 _back = new LAppSprite(x, y, fWidth, fHeight, backgroundTexture->id, programId);
914 - imageName = GearImageName;
915 - LAppTextureManager::TextureInfo* gearTexture = textureManager->CreateTextureFromPngFile(resourcesPath + imageName);
917 - x = static_cast<float>(width - gearTexture->width * 0.5f);
918 - y = static_cast<float>(height - gearTexture->height * 0.5f);
919 - fWidth = static_cast<float>(gearTexture->width);
920 - fHeight = static_cast<float>(gearTexture->height);
921 - _gear = new LAppSprite(x, y, fWidth, fHeight, gearTexture->id, programId);
923 - imageName = PowerImageName;
924 - LAppTextureManager::TextureInfo* powerTexture = textureManager->CreateTextureFromPngFile(resourcesPath + imageName);
926 - x = static_cast<float>(width - powerTexture->width * 0.5f);
927 - y = static_cast<float>(powerTexture->height * 0.5f);
928 - fWidth = static_cast<float>(powerTexture->width);
929 - fHeight = static_cast<float>(powerTexture->height);
930 - _power = new LAppSprite(x, y, fWidth, fHeight, powerTexture->id, programId);
935 @@ -192,18 +171,6 @@ void LAppView::OnTouchesEnded(float px,
936 LAppPal::PrintLogLn("[APP]touchesEnded x:%.2f y:%.2f", x, y);
938 live2DManager->OnTap(x, y);
941 - if (_gear->IsHit(px, py))
943 - live2DManager->NextScene();
947 - if (_power->IsHit(px, py))
949 - LAppDelegate::GetInstance()->AppEnd();
954 diff -pruN --exclude build ./demo_clean/src/main.cpp ./demo_dev/src/main.cpp
955 --- ./demo_clean/src/main.cpp 2025-05-28 10:36:54.000000000 +0100
956 +++ ./demo_dev/src/main.cpp 2025-05-30 00:34:06.180000583 +0100
958 * that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html.
962 +#include <stdexcept>
965 +#ifdef __cpp_lib_filesystem
966 +#include <filesystem>
967 +namespace fs = std::filesystem;
969 +#include <experimental/filesystem>
970 +namespace fs = std::experimental::filesystem;
974 #include "LAppDelegate.hpp"
975 +#include "LAppLive2DManager.hpp"
976 +#include "facial_landmark_detector.h"
982 + std::string windowTitle;
983 + std::string rootDir;
987 + std::string modelName;
988 + bool oldId; // If true, translate new (Cubism 3+) parameter IDs to old (Cubism 2.1) IDs
989 + std::string cfgPath; // Path to config file for FacialLandmarkDetector
992 +CmdArgs parseArgv(int argc, char *argv[])
994 + // I think the command-line args are simple enough to not justify using a library...
996 + // Set default values
997 + cmdArgs.windowWidth = 600;
998 + cmdArgs.windowHeight = 600;
999 + cmdArgs.windowTitle = "FacialLandmarksForCubism example";
1000 + cmdArgs.rootDir = fs::current_path();
1001 + cmdArgs.scaleFactor = 4.5f;
1002 + cmdArgs.translateX = 0.0f;
1003 + cmdArgs.translateY = -3.1f;
1004 + cmdArgs.modelName = "Haru";
1005 + cmdArgs.oldId = false;
1006 + cmdArgs.cfgPath = "";
1011 + std::string arg = argv[i];
1012 + std::stringstream ss;
1014 + if (arg == "--window-width" || arg == "-W") // capital W for consistency with height
1016 + ss << argv[i + 1];
1017 + if (!(ss >> cmdArgs.windowWidth))
1019 + throw std::runtime_error("Invalid argument for window width");
1022 + else if (arg == "--window-height" || arg == "-H") // avoiding "-h", typically for help
1024 + ss << argv[i + 1];
1025 + if (!(ss >> cmdArgs.windowHeight))
1027 + throw std::runtime_error("Invalid argument for window height");
1030 + else if (arg == "--window-title" || arg == "-t")
1032 + cmdArgs.windowTitle = argv[i + 1];
1034 + else if (arg == "--root-dir" || arg == "-d")
1036 + cmdArgs.rootDir = argv[i + 1];
1038 + else if (arg == "--scale-factor" || arg == "-f")
1040 + ss << argv[i + 1];
1041 + if (!(ss >> cmdArgs.scaleFactor))
1043 + throw std::runtime_error("Invalid argument for scale factor");
1046 + else if (arg == "--translate-x" || arg == "-x")
1048 + ss << argv[i + 1];
1049 + if (!(ss >> cmdArgs.translateX))
1051 + throw std::runtime_error("Invalid argument for translate X");
1054 + else if (arg == "--translate-y" || arg == "-y")
1056 + ss << argv[i + 1];
1057 + if (!(ss >> cmdArgs.translateY))
1059 + throw std::runtime_error("Invalid argument for translate Y");
1062 + else if (arg == "--model" || arg == "-m")
1064 + cmdArgs.modelName = argv[i + 1];
1066 + else if (arg == "--config" || arg == "-c")
1068 + cmdArgs.cfgPath = argv[i + 1];
1070 + else if (arg == "--old-param-id" || arg == "-o")
1072 + cmdArgs.oldId = (argv[i + 1][0] == '1');
1076 + throw std::runtime_error("Unrecognized argument: " + arg);
1085 int main(int argc, char* argv[])
1087 - // create the application instance
1088 - if (LAppDelegate::GetInstance()->Initialize() == GL_FALSE)
1089 + auto cmdArgs = parseArgv(argc, argv);
1091 + LAppDelegate *delegate = LAppDelegate::GetInstance();
1093 + if (!delegate->Initialize(cmdArgs.windowWidth,
1094 + cmdArgs.windowHeight,
1095 + cmdArgs.windowTitle.c_str()))
1098 + throw std::runtime_error("Unable to initialize LAppDelegate");
1101 - LAppDelegate::GetInstance()->Run();
1102 + FacialLandmarkDetector detector(cmdArgs.cfgPath);
1104 + std::thread detectorThread(&FacialLandmarkDetector::mainLoop,
1107 + LAppLive2DManager *manager = LAppLive2DManager::GetInstance();
1108 + manager->SetModel(cmdArgs.modelName, cmdArgs.oldId);
1110 + manager->SetProjectionScaleTranslate(cmdArgs.scaleFactor,
1111 + cmdArgs.translateX,
1112 + cmdArgs.translateY);
1113 + manager->SetFacialLandmarkDetector(&detector);
1118 + detectorThread.join();