Upgrade to Cubism 5 Release R4.
[facial-landmarks-for-cubism.git] / example / demo.patch
... / ...
CommitLineData
1diff -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)
5 # Set app name.
6 set(APP_NAME Demo)
7 # Set directory paths.
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)
15
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)
21
22@@ -67,6 +67,9 @@ target_link_libraries(Framework Live2DCu
23 # Find opengl libraries.
24 find_package(OpenGL REQUIRED)
25
26+# Add FacialLandmarksForCubism
27+add_subdirectory(../.. FacialLandmarksForCubism_build)
28+
29 # Make executable app.
30 add_executable(${APP_NAME})
31 # Add common source files.
32@@ -79,9 +82,11 @@ target_link_libraries(${APP_NAME}
33 Framework
34 glfw
35 ${OPENGL_LIBRARIES}
36+ FacialLandmarksForCubism
37+ stdc++fs
38 )
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)
42
43 # Copy resource directory to build directory.
44 add_custom_command(
45diff -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
52-MINIMUM_DEMO="OFF"
53-DATA=""
54-
55-if [ "$#" -ne 0 ]; then
56- DATA="$1"
57-fi
58-
59-while :
60-do
61-
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
67- fi
68-
69- case "$DATA" in
70- "1" )
71- echo "Making Full Demo"
72- MINIMUM_DEMO="OFF"
73- break ;;
74- "2" )
75- echo "Making Minimum Demo"
76- MINIMUM_DEMO="ON"
77- break ;;
78- * )
79- echo "You need to enter a valid number."
80- DATA="" ;;
81- esac
82-done
83
84 # Run CMake.
85 cmake -S "$CMAKE_PATH" \
86 -B "$BUILD_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
93diff -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()
97 s_instance = NULL;
98 }
99
100-bool LAppDelegate::Initialize()
101+bool LAppDelegate::Initialize(int initWindowWidth, int initWindowHeight,
102+ const char *windowTitle)
103 {
104 if (DebugLogEnable)
105 {
106@@ -64,7 +65,13 @@ bool LAppDelegate::Initialize()
107 }
108
109 // Windowの生成_
110- _window = glfwCreateWindow(RenderTargetWidth, RenderTargetHeight, "SAMPLE", NULL, NULL);
111+ _window = glfwCreateWindow(
112+ initWindowWidth ? initWindowWidth : RenderTargetWidth,
113+ initWindowHeight ? initWindowHeight : RenderTargetHeight,
114+ windowTitle ? windowTitle : "SAMPLE",
115+ NULL,
116+ NULL);
117+
118 if (_window == NULL)
119 {
120 if (DebugLogEnable)
121@@ -96,10 +103,6 @@ bool LAppDelegate::Initialize()
122 glEnable(GL_BLEND);
123 glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
124
125- //コールバック関数の登録
126- glfwSetMouseButtonCallback(_window, EventHandler::OnMouseCallBack);
127- glfwSetCursorPosCallback(_window, EventHandler::OnMouseCallBack);
128-
129 // ウィンドウサイズ記憶
130 int width, height;
131 glfwGetWindowSize(LAppDelegate::GetInstance()->GetWindow(), &width, &height);
132diff -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:
136 /**
137 * @brief APPに必要なものを初期化する。
138 */
139- bool Initialize();
140+ bool Initialize(int initWindowWidth = 0, int initWindowHeight = 0,
141+ const char *windowTitle = "SAMPLE");
142
143 /**
144 * @brief 解放する。
145diff -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
148@@ -6,13 +6,7 @@
149 */
150
151 #include "LAppLive2DManager.hpp"
152-#include <stdio.h>
153-#include <stdlib.h>
154-#include <string.h>
155-#include <dirent.h>
156-#include <unistd.h>
157-#include <libgen.h>
158-#include <limits.h>
159+#include <string>
160 #include <GL/glew.h>
161 #include <GLFW/glfw3.h>
162 #include <Rendering/CubismRenderer.hpp>
163@@ -68,12 +62,11 @@ void LAppLive2DManager::ReleaseInstance(
164
165 LAppLive2DManager::LAppLive2DManager()
166 : _viewMatrix(NULL)
167- , _sceneIndex(0)
168+ , _projScaleFactor(1.0f)
169+ , _translateX(0.0f)
170+ , _translateY(0.0f)
171 {
172 _viewMatrix = new CubismMatrix44();
173- SetUpModel();
174-
175- ChangeScene(_sceneIndex);
176 }
177
178 LAppLive2DManager::~LAppLive2DManager()
179@@ -92,60 +85,6 @@ void LAppLive2DManager::ReleaseAllModel(
180 _models.Clear();
181 }
182
183-void LAppLive2DManager::SetUpModel()
184-{
185- // ResourcesPathの中にあるフォルダ名を全てクロールし、モデルが存在するフォルダを定義する。
186- // フォルダはあるが同名の.model3.jsonが見つからなかった場合はリストに含めない。
187- struct dirent *dirent;
188- csmString crawlPath(LAppDelegate::GetInstance()->GetExecuteAbsolutePath().c_str());
189- crawlPath += ResourcesPath;
190-
191- DIR *pDir = opendir(crawlPath.GetRawString());
192- if (pDir == NULL) return;
193-
194- _modelDir.Clear();
195-
196- while ((dirent = readdir(pDir)) != NULL)
197- {
198- if ((dirent->d_type & DT_DIR) && strcmp(dirent->d_name, "..") != 0)
199- {
200- // フォルダと同名の.model3.jsonがあるか探索する
201- struct dirent *dirent2;
202-
203- csmString modelName(dirent->d_name);
204-
205- csmString modelPath(crawlPath);
206- modelPath += modelName;
207- modelPath.Append(1, '/');
208-
209- csmString model3jsonName(modelName);
210- model3jsonName += ".model3.json";
211-
212- DIR *pDir2 = opendir(modelPath.GetRawString());
213- while ((dirent2 = readdir(pDir2)) != NULL)
214- {
215- if (strcmp(dirent2->d_name, model3jsonName.GetRawString()) == 0)
216- {
217- _modelDir.PushBack(csmString(dirent->d_name));
218- }
219- }
220- closedir(pDir2);
221- }
222- }
223- closedir(pDir);
224- qsort(_modelDir.GetPtr(), _modelDir.GetSize(), sizeof(csmString), CompareCsmString);
225-}
226-
227-csmVector<csmString> LAppLive2DManager::GetModelDir() const
228-{
229- return _modelDir;
230-}
231-
232-csmInt32 LAppLive2DManager::GetModelDirSize() const
233-{
234- return _modelDir.GetSize();
235-}
236-
237 LAppModel* LAppLive2DManager::GetModel(csmUint32 no) const
238 {
239 if (no < _models.GetSize())
240@@ -172,26 +111,6 @@ void LAppLive2DManager::OnTap(csmFloat32
241 {
242 LAppPal::PrintLogLn("[APP]tap point: {x:%.2f y:%.2f}", x, y);
243 }
244-
245- for (csmUint32 i = 0; i < _models.GetSize(); i++)
246- {
247- if (_models[i]->HitTest(HitAreaNameHead, x, y))
248- {
249- if (DebugLogEnable)
250- {
251- LAppPal::PrintLogLn("[APP]hit area: [%s]", HitAreaNameHead);
252- }
253- _models[i]->SetRandomExpression();
254- }
255- else if (_models[i]->HitTest(HitAreaNameBody, x, y))
256- {
257- if (DebugLogEnable)
258- {
259- LAppPal::PrintLogLn("[APP]hit area: [%s]", HitAreaNameBody);
260- }
261- _models[i]->StartRandomMotion(MotionGroupTapBody, PriorityNormal, FinishedMotion, BeganMotion);
262- }
263- }
264 }
265
266 void LAppLive2DManager::OnUpdate() const
267@@ -215,12 +134,15 @@ void LAppLive2DManager::OnUpdate() const
268 {
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));
274 }
275 else
276 {
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),
279+ _projScaleFactor);
280 }
281+ projection.Translate(_translateX, _translateY);
282
283 // 必要があればここで乗算
284 if (_viewMatrix != NULL)
285@@ -237,37 +159,15 @@ void LAppLive2DManager::OnUpdate() const
286 }
287 }
288
289-void LAppLive2DManager::NextScene()
290+void LAppLive2DManager::SetModel(std::string modelName, bool useOldParamId)
291 {
292- csmInt32 no = (_sceneIndex + 1) % GetModelDirSize();
293- ChangeScene(no);
294-}
295-
296-void LAppLive2DManager::ChangeScene(Csm::csmInt32 index)
297-{
298- _sceneIndex = index;
299- if (DebugLogEnable)
300- {
301- LAppPal::PrintLogLn("[APP]model index: %d", _sceneIndex);
302- }
303-
304- // ModelDir[]に保持したディレクトリ名から
305- // model3.jsonのパスを決定する.
306- // ディレクトリ名とmodel3.jsonの名前を一致させておくこと.
307- const csmString& model = _modelDir[index];
308- LAppPal::PrintLogLn("[APP]_modelDir: %s", model.GetRawString());
309-
310- csmString modelPath(LAppDelegate::GetInstance()->GetExecuteAbsolutePath().c_str());
311- modelPath += ResourcesPath;
312- modelPath += model;
313- modelPath.Append(1, '/');
314-
315- csmString modelJsonName(model);
316+ std::string modelPath = LAppDelegate::GetInstance()->GetExecuteAbsolutePath() + ResourcesPath + modelName + "/";
317+ std::string modelJsonName = modelName;
318 modelJsonName += ".model3.json";
319
320 ReleaseAllModel();
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());
325
326 /*
327 * モデル半透明表示を行うサンプルを提示する。
328@@ -288,8 +188,8 @@ void LAppLive2DManager::ChangeScene(Csm:
329
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);
337 #endif
338
339@@ -317,3 +217,20 @@ void LAppLive2DManager::SetViewMatrix(Cu
340 _viewMatrix->GetArray()[i] = m->GetArray()[i];
341 }
342 }
343+
344+void LAppLive2DManager::SetFacialLandmarkDetector(FacialLandmarkDetector *detector)
345+{
346+ for (auto it = _models.Begin(); it != _models.End(); ++it)
347+ {
348+ (*it)->SetFacialLandmarkDetector(detector);
349+ }
350+}
351+
352+void LAppLive2DManager::SetProjectionScaleTranslate(float scaleFactor,
353+ float translateX,
354+ float translateY)
355+{
356+ _projScaleFactor = scaleFactor;
357+ _translateX = translateX;
358+ _translateY = translateY;
359+}
360diff -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
363@@ -6,12 +6,15 @@
364 */
365 #pragma once
366
367+#include <string>
368 #include <CubismFramework.hpp>
369 #include <Math/CubismMatrix44.hpp>
370 #include <Type/csmVector.hpp>
371
372 class LAppModel;
373
374+class FacialLandmarkDetector;
375+
376 /**
377 * @brief サンプルアプリケーションにおいてCubismModelを管理するクラス<br>
378 * モデル生成と破棄、タップイベントの処理、モデル切り替えを行う。
379@@ -36,24 +39,6 @@ public:
380 static void ReleaseInstance();
381
382 /**
383- * @brief Resources フォルダにあるモデルフォルダ名をセットする
384- *
385- */
386- void SetUpModel();
387-
388- /**
389- * @brief Resources フォルダにあるモデルフォルダ名を取得する
390- *
391- */
392- Csm::csmVector<Csm::csmString> GetModelDir() const;
393-
394- /**
395- * @brief Resources フォルダにあるモデルフォルダのサイズを取得する
396- *
397- */
398- Csm::csmInt32 GetModelDirSize() const;
399-
400- /**
401 * @brief 現在のシーンで保持しているモデルを返す
402 *
403 * @param[in] no モデルリストのインデックス値
404@@ -90,16 +75,14 @@ public:
405 void OnUpdate() const;
406
407 /**
408- * @brief 次のシーンに切り替える<br>
409- * サンプルアプリケーションではモデルセットの切り替えを行う。
410- */
411- void NextScene();
412-
413- /**
414- * @brief シーンを切り替える<br>
415- * サンプルアプリケーションではモデルセットの切り替えを行う。
416- */
417- void ChangeScene(Csm::csmInt32 index);
418+ * @brief Set model data
419+ *
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
424+ */
425+ void SetModel(std::string modelName, bool useOldParamId);
426
427 /**
428 * @brief モデル個数を得る
429@@ -112,6 +95,24 @@ public:
430 */
431 void SetViewMatrix(Live2D::Cubism::Framework::CubismMatrix44* m);
432
433+ /**
434+ * @brief Set the pointer to the FacialLandmarkDetector instance
435+ *
436+ * @param[in] detector : Pointer to FacialLandmarkDetector instance
437+ */
438+ void SetFacialLandmarkDetector(FacialLandmarkDetector *detector);
439+
440+ /**
441+ * @brief Set projection scale factor and translation parameters
442+ *
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
446+ */
447+ void SetProjectionScaleTranslate(float scaleFactor,
448+ float translateX,
449+ float translateY);
450+
451 private:
452 /**
453 * @brief コンストラクタ
454@@ -125,7 +126,8 @@ private:
455
456 Csm::CubismMatrix44* _viewMatrix; ///< モデル描画に用いるView行列
457 Csm::csmVector<LAppModel*> _models; ///< モデルインスタンスのコンテナ
458- Csm::csmInt32 _sceneIndex; ///< 表示するシーンのインデックス値
459
460- Csm::csmVector<Csm::csmString> _modelDir; ///< モデルディレクトリ名のコンテナ
461+ float _projScaleFactor;
462+ float _translateX;
463+ float _translateY;
464 };
465diff -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
468@@ -21,26 +21,30 @@
469 #include "LAppTextureManager.hpp"
470 #include "LAppDelegate.hpp"
471
472+#include "facial_landmark_detector.h"
473+
474 using namespace Live2D::Cubism::Framework;
475 using namespace Live2D::Cubism::Framework::DefaultParameterId;
476 using namespace LAppDefine;
477
478-LAppModel::LAppModel()
479+LAppModel::LAppModel(bool useOldParamId)
480 : LAppModel_Common()
481 , _modelSetting(NULL)
482 , _userTimeSeconds(0.0f)
483+ , _detector(nullptr)
484+ , _useOldParamId(useOldParamId)
485 {
486 if (DebugLogEnable)
487 {
488 _debugMode = true;
489 }
490
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));
503 }
504
505 LAppModel::~LAppModel()
506@@ -114,33 +118,6 @@ void LAppModel::SetupModel(ICubismModelS
507 DeleteBuffer(buffer, path.GetRawString());
508 }
509
510- //Expression
511- if (_modelSetting->GetExpressionCount() > 0)
512- {
513- const csmInt32 count = _modelSetting->GetExpressionCount();
514- for (csmInt32 i = 0; i < count; i++)
515- {
516- csmString name = _modelSetting->GetExpressionName(i);
517- csmString path = _modelSetting->GetExpressionFileName(i);
518- path = _modelHomeDir + path;
519-
520- buffer = CreateBuffer(path.GetRawString(), &size);
521- ACubismMotion* motion = LoadExpression(buffer, size, name.GetRawString());
522-
523- if (motion)
524- {
525- if (_expressions[name] != NULL)
526- {
527- ACubismMotion::Delete(_expressions[name]);
528- _expressions[name] = NULL;
529- }
530- _expressions[name] = motion;
531- }
532-
533- DeleteBuffer(buffer, path.GetRawString());
534- }
535- }
536-
537 //Physics
538 if (strcmp(_modelSetting->GetPhysicsFileName(), "") != 0)
539 {
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));
546
547 _breath->SetParameters(breathParameters);
548 }
549@@ -203,21 +180,6 @@ void LAppModel::SetupModel(ICubismModelS
550 }
551 }
552
553- // LipSyncIds
554- {
555- csmInt32 lipSyncIdCount = _modelSetting->GetLipSyncParameterCount();
556- for (csmInt32 i = 0; i < lipSyncIdCount; ++i)
557- {
558- _lipSyncIds.PushBack(_modelSetting->GetLipSyncParameterId(i));
559- }
560- }
561-
562- if (_modelSetting == NULL || _modelMatrix == NULL)
563- {
564- LAppPal::PrintLogLn("Failed to SetupModel().");
565- return;
566- }
567-
568 //Layout
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;
574
575- _dragManager->Update(deltaTimeSeconds);
576- _dragX = _dragManager->GetX();
577- _dragY = _dragManager->GetY();
578-
579- // モーションによるパラメータ更新の有無
580- csmBool motionUpdated = false;
581-
582- //-----------------------------------------------------------------
583- _model->LoadParameters(); // 前回セーブされた状態をロード
584- if (_motionManager->IsFinished())
585+ if (_detector)
586 {
587- // モーションの再生がない場合、待機モーションの中からランダムで再生する
588- StartRandomMotion(MotionGroupIdle, PriorityIdle);
589- }
590- else
591- {
592- motionUpdated = _motionManager->UpdateMotion(_model, deltaTimeSeconds); // モーションを更新
593- }
594- _model->SaveParameters(); // 状態を保存
595- //-----------------------------------------------------------------
596+ auto idMan = CubismFramework::GetIdManager();
597+ auto params = _detector->getParams();
598
599- // 不透明度
600- _opacity = _model->GetModelOpacity();
601-
602- // まばたき
603- if (!motionUpdated)
604- {
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)
610 {
611- // メインモーションの更新がないとき
612- _eyeBlink->UpdateParameters(_model, deltaTimeSeconds); // 目パチ
613+ // モーションの再生がない場合、待機モーションの中からランダムで再生する
614+ StartRandomMotion(MotionGroupIdle, PriorityIdle);
615 }
616- }
617-
618- if (_expressionManager != NULL)
619- {
620- _expressionManager->UpdateMotion(_model, deltaTimeSeconds); // 表情でパラメータ更新(相対変化)
621- }
622-
623- //ドラッグによる変化
624- //ドラッグによる顔の向きの調整
625- _model->AddParameterValue(_idParamAngleX, _dragX * 30); // -30から30の値を加える
626- _model->AddParameterValue(_idParamAngleY, _dragY * 30);
627- _model->AddParameterValue(_idParamAngleZ, _dragX * _dragY * -30);
628-
629- //ドラッグによる体の向きの調整
630- _model->AddParameterValue(_idParamBodyAngleX, _dragX * 10); // -10から10の値を加える
631+ else
632+ {
633+ _motionManager->UpdateMotion(_model, deltaTimeSeconds); // モーションを更新
634+ }
635+ _model->SaveParameters(); // 状態を保存
636
637- //ドラッグによる目の向きの調整
638- _model->AddParameterValue(_idParamEyeBallX, _dragX); // -1から1の値を加える
639- _model->AddParameterValue(_idParamEyeBallY, _dragY);
640
641- // 呼吸など
642- if (_breath != NULL)
643- {
644- _breath->UpdateParameters(_model, deltaTimeSeconds);
645+ if (params.autoBlink && _eyeBlink)
646+ {
647+ _eyeBlink->UpdateParameters(_model, deltaTimeSeconds);
648+ }
649+ else
650+ {
651+ _model->SetParameterValue(idMan->GetId(_("ParamEyeLOpen")),
652+ params.leftEyeOpenness);
653+ _model->SetParameterValue(idMan->GetId(_("ParamEyeROpen")),
654+ params.rightEyeOpenness);
655+ }
656+ _model->SetParameterValue(idMan->GetId(_("ParamMouthForm")),
657+ params.mouthForm);
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)
671+ {
672+ // Note: _model->LoadParameters and SaveParameters is needed
673+ // before - see above.
674+ _breath->UpdateParameters(_model, deltaTimeSeconds);
675+ }
676 }
677
678 // 物理演算の設定
679@@ -386,22 +343,6 @@ void LAppModel::Update()
680 _physics->Evaluate(_model, deltaTimeSeconds);
681 }
682
683- // リップシンクの設定
684- if (_lipSync)
685- {
686- // リアルタイムでリップシンクを行う場合、システムから音量を取得して0〜1の範囲で値を入力します。
687- csmFloat32 value = 0.0f;
688-
689- // 状態更新/RMS値取得
690- _wavFileHandler.Update(deltaTimeSeconds);
691- value = _wavFileHandler.GetRms();
692-
693- for (csmUint32 i = 0; i < _lipSyncIds.GetSize(); ++i)
694- {
695- _model->AddParameterValue(_lipSyncIds[i], value, 0.8f);
696- }
697- }
698-
699 // ポーズの設定
700 if (_pose != NULL)
701 {
702@@ -464,7 +405,6 @@ CubismMotionQueueEntryHandle LAppModel::
703 {
704 csmString path = voice;
705 path = _modelHomeDir + path;
706- _wavFileHandler.Start(path);
707 }
708
709 if (_debugMode)
710@@ -616,3 +556,37 @@ Csm::Rendering::CubismOffscreenSurface_O
711 {
712 return _renderBuffer;
713 }
714+
715+void LAppModel::SetFacialLandmarkDetector(FacialLandmarkDetector *detector)
716+{
717+ _detector = detector;
718+}
719+
720+Csm::csmString LAppModel::_(std::string s)
721+{
722+ std::string ans;
723+ if (_useOldParamId)
724+ {
725+ if (s == "ParamTere")
726+ {
727+ ans = "PARAM_CHEEK";
728+ }
729+ else
730+ {
731+ for (size_t i = 0; i < s.size(); i++)
732+ {
733+ if (std::isupper(s[i]) && i != 0)
734+ {
735+ ans += '_';
736+ }
737+ ans += std::toupper(s[i]);
738+ }
739+ }
740+ }
741+ else
742+ {
743+ ans = s;
744+ }
745+ return csmString(ans.c_str());
746+}
747+
748diff -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
751@@ -12,8 +12,8 @@
752 #include <Type/csmRectF.hpp>
753 #include <Rendering/OpenGL/CubismOffscreenSurface_OpenGLES2.hpp>
754
755-#include "LAppWavFileHandler_Common.hpp"
756 #include "LAppModel_Common.hpp"
757+#include "facial_landmark_detector.h"
758
759 /**
760 * @brief ユーザーが実際に使用するモデルの実装クラス<br>
761@@ -25,8 +25,11 @@ class LAppModel : public LAppModel_Commo
762 public:
763 /**
764 * @brief コンストラクタ
765+ *
766+ * @param[in] useOldParamId : If true, translate new (Cubism 3+)
767+ * parameter IDs to old (Cubism 2.1) ones
768 */
769- LAppModel();
770+ LAppModel(bool useOldParamId);
771
772 /**
773 * @brief デストラクタ
774@@ -116,6 +119,13 @@ public:
775 */
776 Csm::Rendering::CubismOffscreenSurface_OpenGLES2& GetRenderBuffer();
777
778+ /**
779+ * @brief Set the pointer to the FacialLandmarkDetector instance
780+ *
781+ * @param[in] detector : Pointer to FacialLandmarkDetector instance
782+ */
783+ void SetFacialLandmarkDetector(FacialLandmarkDetector *detector);
784+
785 protected:
786 /**
787 * @brief モデルを描画する処理。モデルを描画する空間のView-Projection行列を渡す。
788@@ -169,6 +179,17 @@ private:
789 */
790 void ReleaseExpressions();
791
792+ /**
793+ * @brief Translate new (Cubism 3+) parameter IDs to old (Cubism 2.1) ones
794+ *
795+ * @param[in] s : New parameter ID
796+ *
797+ * @return Old parameter ID
798+ */
799+ Csm::csmString _(std::string s);
800+
801+ bool _useOldParamId;
802+
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
809
810- LAppWavFileHandler_Common _wavFileHandler; ///< wavファイルハンドラ
811-
812 Csm::Rendering::CubismOffscreenSurface_OpenGLES2 _renderBuffer; ///< フレームバッファ以外の描画先
813+
814+ FacialLandmarkDetector *_detector;
815 };
816+
817+
818+
819diff -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
823
824 }
825
826+LAppTextureManager::TextureInfo* LAppTextureManager::CreateTextureFromColor(
827+ uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha
828+)
829+{
830+ int width = 8, height = 8;
831+
832+ uint8_t pixels[height][width][4];
833+ for (std::size_t h = 0; h < height; h++)
834+ {
835+ for (std::size_t w = 0; w < width; w++)
836+ {
837+ pixels[h][w][0] = red;
838+ pixels[h][w][1] = green;
839+ pixels[h][w][2] = blue;
840+ pixels[h][w][3] = alpha;
841+ }
842+ }
843+
844+ GLuint textureId;
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);
848+
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);
853+
854+
855+ LAppTextureManager::TextureInfo* textureInfo = new LAppTextureManager::TextureInfo();
856+ textureInfo->fileName = "";
857+ textureInfo->width = width;
858+ textureInfo->height = height;
859+ textureInfo->id = textureId;
860+
861+ _texturesInfo.PushBack(textureInfo);
862+
863+ return textureInfo;
864+}
865+
866 void LAppTextureManager::ReleaseTextures()
867 {
868 for (Csm::csmUint32 i = 0; i < _texturesInfo.GetSize(); i++)
869diff -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:
873 */
874 TextureInfo* CreateTextureFromPngFile(std::string fileName);
875
876+ TextureInfo *CreateTextureFromColor(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha = 255);
877+
878 /**
879 * @brief 画像の解放
880 *
881diff -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()
886 {
887 _back->Render();
888- _gear->Render();
889- _power->Render();
890-
891
892 LAppLive2DManager* Live2DManager = LAppLive2DManager::GetInstance();
893
894@@ -125,35 +122,17 @@ void LAppView::InitializeSprite()
895 glfwGetWindowSize(LAppDelegate::GetInstance()->GetWindow(), &width, &height);
896
897 LAppTextureManager* textureManager = LAppDelegate::GetInstance()->GetTextureManager();
898- const string resourcesPath = LAppDelegate::GetInstance()->GetExecuteAbsolutePath() + ResourcesPath;
899
900- string imageName = BackImageName;
901- LAppTextureManager::TextureInfo* backgroundTexture = textureManager->CreateTextureFromPngFile(resourcesPath + imageName);
902+
903+ LAppTextureManager::TextureInfo* backgroundTexture =
904+ textureManager->CreateTextureFromColor(0, 255, 0);
905
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);
913
914- imageName = GearImageName;
915- LAppTextureManager::TextureInfo* gearTexture = textureManager->CreateTextureFromPngFile(resourcesPath + imageName);
916-
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);
922-
923- imageName = PowerImageName;
924- LAppTextureManager::TextureInfo* powerTexture = textureManager->CreateTextureFromPngFile(resourcesPath + imageName);
925-
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);
931-
932 // 画面全体を覆うサイズ
933 x = width * 0.5f;
934 y = height * 0.5f;
935@@ -192,18 +171,6 @@ void LAppView::OnTouchesEnded(float px,
936 LAppPal::PrintLogLn("[APP]touchesEnded x:%.2f y:%.2f", x, y);
937 }
938 live2DManager->OnTap(x, y);
939-
940- // 歯車にタップしたか
941- if (_gear->IsHit(px, py))
942- {
943- live2DManager->NextScene();
944- }
945-
946- // 電源ボタンにタップしたか
947- if (_power->IsHit(px, py))
948- {
949- LAppDelegate::GetInstance()->AppEnd();
950- }
951 }
952 }
953
954diff -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
957@@ -5,18 +5,160 @@
958 * that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html.
959 */
960
961+#include <thread>
962+#include <stdexcept>
963+#include <sstream>
964+
965+#ifdef __cpp_lib_filesystem
966+#include <filesystem>
967+namespace fs = std::filesystem;
968+#else
969+#include <experimental/filesystem>
970+namespace fs = std::experimental::filesystem;
971+#endif
972+
973+
974 #include "LAppDelegate.hpp"
975+#include "LAppLive2DManager.hpp"
976+#include "facial_landmark_detector.h"
977+
978+struct CmdArgs
979+{
980+ int windowWidth;
981+ int windowHeight;
982+ std::string windowTitle;
983+ std::string rootDir;
984+ float scaleFactor;
985+ float translateX;
986+ float translateY;
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
990+};
991+
992+CmdArgs parseArgv(int argc, char *argv[])
993+{
994+ // I think the command-line args are simple enough to not justify using a library...
995+ CmdArgs cmdArgs;
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 = "";
1007+
1008+ int i = 1;
1009+ while (i < argc)
1010+ {
1011+ std::string arg = argv[i];
1012+ std::stringstream ss;
1013+
1014+ if (arg == "--window-width" || arg == "-W") // capital W for consistency with height
1015+ {
1016+ ss << argv[i + 1];
1017+ if (!(ss >> cmdArgs.windowWidth))
1018+ {
1019+ throw std::runtime_error("Invalid argument for window width");
1020+ }
1021+ }
1022+ else if (arg == "--window-height" || arg == "-H") // avoiding "-h", typically for help
1023+ {
1024+ ss << argv[i + 1];
1025+ if (!(ss >> cmdArgs.windowHeight))
1026+ {
1027+ throw std::runtime_error("Invalid argument for window height");
1028+ }
1029+ }
1030+ else if (arg == "--window-title" || arg == "-t")
1031+ {
1032+ cmdArgs.windowTitle = argv[i + 1];
1033+ }
1034+ else if (arg == "--root-dir" || arg == "-d")
1035+ {
1036+ cmdArgs.rootDir = argv[i + 1];
1037+ }
1038+ else if (arg == "--scale-factor" || arg == "-f")
1039+ {
1040+ ss << argv[i + 1];
1041+ if (!(ss >> cmdArgs.scaleFactor))
1042+ {
1043+ throw std::runtime_error("Invalid argument for scale factor");
1044+ }
1045+ }
1046+ else if (arg == "--translate-x" || arg == "-x")
1047+ {
1048+ ss << argv[i + 1];
1049+ if (!(ss >> cmdArgs.translateX))
1050+ {
1051+ throw std::runtime_error("Invalid argument for translate X");
1052+ }
1053+ }
1054+ else if (arg == "--translate-y" || arg == "-y")
1055+ {
1056+ ss << argv[i + 1];
1057+ if (!(ss >> cmdArgs.translateY))
1058+ {
1059+ throw std::runtime_error("Invalid argument for translate Y");
1060+ }
1061+ }
1062+ else if (arg == "--model" || arg == "-m")
1063+ {
1064+ cmdArgs.modelName = argv[i + 1];
1065+ }
1066+ else if (arg == "--config" || arg == "-c")
1067+ {
1068+ cmdArgs.cfgPath = argv[i + 1];
1069+ }
1070+ else if (arg == "--old-param-id" || arg == "-o")
1071+ {
1072+ cmdArgs.oldId = (argv[i + 1][0] == '1');
1073+ }
1074+ else
1075+ {
1076+ throw std::runtime_error("Unrecognized argument: " + arg);
1077+ }
1078+
1079+ i += 2;
1080+ }
1081+
1082+ return cmdArgs;
1083+}
1084
1085 int main(int argc, char* argv[])
1086 {
1087- // create the application instance
1088- if (LAppDelegate::GetInstance()->Initialize() == GL_FALSE)
1089+ auto cmdArgs = parseArgv(argc, argv);
1090+
1091+ LAppDelegate *delegate = LAppDelegate::GetInstance();
1092+
1093+ if (!delegate->Initialize(cmdArgs.windowWidth,
1094+ cmdArgs.windowHeight,
1095+ cmdArgs.windowTitle.c_str()))
1096 {
1097- return 1;
1098+ throw std::runtime_error("Unable to initialize LAppDelegate");
1099 }
1100
1101- LAppDelegate::GetInstance()->Run();
1102+ FacialLandmarkDetector detector(cmdArgs.cfgPath);
1103+
1104+ std::thread detectorThread(&FacialLandmarkDetector::mainLoop,
1105+ &detector);
1106+
1107+ LAppLive2DManager *manager = LAppLive2DManager::GetInstance();
1108+ manager->SetModel(cmdArgs.modelName, cmdArgs.oldId);
1109+
1110+ manager->SetProjectionScaleTranslate(cmdArgs.scaleFactor,
1111+ cmdArgs.translateX,
1112+ cmdArgs.translateY);
1113+ manager->SetFacialLandmarkDetector(&detector);
1114+
1115+ delegate->Run();
1116+
1117+ detector.stop();
1118+ detectorThread.join();
1119
1120 return 0;
1121 }
1122-