Commit | Line | Data |
---|---|---|
830d0ba4 | 1 | diff -pruN --exclude build ./demo_clean/CMakeLists.txt ./demo_dev/CMakeLists.txt |
525a4608 AIL |
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 | |
830d0ba4 AIL |
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}/../../../..) | |
525a4608 | 9 | +set(SDK_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../CubismSdkForNative-5-r.4) |
830d0ba4 AIL |
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) | |
525a4608 | 13 | @@ -35,7 +35,7 @@ set(GLFW_INSTALL OFF CACHE BOOL "" FORCE |
830d0ba4 AIL |
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 | ||
525a4608 | 22 | @@ -67,6 +67,9 @@ target_link_libraries(Framework Live2DCu |
830d0ba4 AIL |
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}) | |
525a4608 AIL |
31 | # Add common source files. |
32 | @@ -79,9 +82,11 @@ target_link_libraries(${APP_NAME} | |
bc212fa6 AIL |
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( | |
830d0ba4 | 45 | diff -pruN --exclude build ./demo_clean/scripts/make_gcc ./demo_dev/scripts/make_gcc |
525a4608 | 46 | --- ./demo_clean/scripts/make_gcc 2025-05-28 10:36:54.000000000 +0100 |
6fd3638f | 47 | +++ ./demo_dev/scripts/make_gcc 2023-05-28 08:11:25.750067591 +0100 |
98cde37f | 48 | @@ -5,42 +5,9 @@ set -ue |
5f788e6f AIL |
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. | |
830d0ba4 AIL |
85 | cmake -S "$CMAKE_PATH" \ |
86 | -B "$BUILD_PATH" \ | |
5f788e6f | 87 | - -D CMAKE_BUILD_TYPE=Release \ |
98cde37f AIL |
88 | - -D CSM_MINIMUM_DEMO=$MINIMUM_DEMO \ |
89 | - -D GLFW_BUILD_WAYLAND=OFF | |
830d0ba4 | 90 | -cd "$BUILD_PATH" && make |
5f788e6f | 91 | + -D CMAKE_BUILD_TYPE=Release |
830d0ba4 | 92 | +cd "$BUILD_PATH" && make -j4 |
830d0ba4 | 93 | diff -pruN --exclude build ./demo_clean/src/LAppDelegate.cpp ./demo_dev/src/LAppDelegate.cpp |
525a4608 AIL |
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() | |
830d0ba4 AIL |
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 | { | |
525a4608 | 106 | @@ -64,7 +65,13 @@ bool LAppDelegate::Initialize() |
830d0ba4 AIL |
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) | |
525a4608 | 121 | @@ -96,10 +103,6 @@ bool LAppDelegate::Initialize() |
830d0ba4 | 122 | glEnable(GL_BLEND); |
525a4608 | 123 | glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); |
830d0ba4 AIL |
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); | |
830d0ba4 | 132 | diff -pruN --exclude build ./demo_clean/src/LAppDelegate.hpp ./demo_dev/src/LAppDelegate.hpp |
525a4608 AIL |
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 | |
830d0ba4 AIL |
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 解放する。 | |
830d0ba4 | 145 | diff -pruN --exclude build ./demo_clean/src/LAppLive2DManager.cpp ./demo_dev/src/LAppLive2DManager.cpp |
525a4608 AIL |
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 | |
98cde37f AIL |
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> | |
525a4608 | 163 | @@ -68,12 +62,11 @@ void LAppLive2DManager::ReleaseInstance( |
830d0ba4 AIL |
164 | |
165 | LAppLive2DManager::LAppLive2DManager() | |
166 | : _viewMatrix(NULL) | |
167 | - , _sceneIndex(0) | |
168 | + , _projScaleFactor(1.0f) | |
169 | + , _translateX(0.0f) | |
170 | + , _translateY(0.0f) | |
171 | { | |
261d3d0e | 172 | _viewMatrix = new CubismMatrix44(); |
98cde37f | 173 | - SetUpModel(); |
261d3d0e | 174 | - |
830d0ba4 AIL |
175 | - ChangeScene(_sceneIndex); |
176 | } | |
177 | ||
178 | LAppLive2DManager::~LAppLive2DManager() | |
525a4608 | 179 | @@ -92,60 +85,6 @@ void LAppLive2DManager::ReleaseAllModel( |
98cde37f AIL |
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()) | |
525a4608 | 240 | @@ -172,26 +111,6 @@ void LAppLive2DManager::OnTap(csmFloat32 |
830d0ba4 | 241 | { |
525a4608 AIL |
242 | LAppPal::PrintLogLn("[APP]tap point: {x:%.2f y:%.2f}", x, y); |
243 | } | |
830d0ba4 AIL |
244 | - |
245 | - for (csmUint32 i = 0; i < _models.GetSize(); i++) | |
246 | - { | |
247 | - if (_models[i]->HitTest(HitAreaNameHead, x, y)) | |
248 | - { | |
249 | - if (DebugLogEnable) | |
250 | - { | |
98cde37f | 251 | - LAppPal::PrintLogLn("[APP]hit area: [%s]", HitAreaNameHead); |
830d0ba4 AIL |
252 | - } |
253 | - _models[i]->SetRandomExpression(); | |
254 | - } | |
255 | - else if (_models[i]->HitTest(HitAreaNameBody, x, y)) | |
256 | - { | |
257 | - if (DebugLogEnable) | |
258 | - { | |
98cde37f | 259 | - LAppPal::PrintLogLn("[APP]hit area: [%s]", HitAreaNameBody); |
830d0ba4 | 260 | - } |
bc212fa6 | 261 | - _models[i]->StartRandomMotion(MotionGroupTapBody, PriorityNormal, FinishedMotion, BeganMotion); |
830d0ba4 | 262 | - } |
525a4608 | 263 | - } |
830d0ba4 AIL |
264 | } |
265 | ||
525a4608 AIL |
266 | void LAppLive2DManager::OnUpdate() const |
267 | @@ -215,12 +134,15 @@ void LAppLive2DManager::OnUpdate() const | |
261d3d0e AIL |
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); | |
830d0ba4 | 282 | |
261d3d0e AIL |
283 | // 必要があればここで乗算 |
284 | if (_viewMatrix != NULL) | |
525a4608 | 285 | @@ -237,37 +159,15 @@ void LAppLive2DManager::OnUpdate() const |
830d0ba4 AIL |
286 | } |
287 | } | |
288 | ||
289 | -void LAppLive2DManager::NextScene() | |
525a4608 AIL |
290 | +void LAppLive2DManager::SetModel(std::string modelName, bool useOldParamId) |
291 | { | |
98cde37f | 292 | - csmInt32 no = (_sceneIndex + 1) % GetModelDirSize(); |
830d0ba4 AIL |
293 | - ChangeScene(no); |
294 | -} | |
295 | - | |
296 | -void LAppLive2DManager::ChangeScene(Csm::csmInt32 index) | |
525a4608 | 297 | -{ |
830d0ba4 AIL |
298 | - _sceneIndex = index; |
299 | - if (DebugLogEnable) | |
300 | - { | |
98cde37f | 301 | - LAppPal::PrintLogLn("[APP]model index: %d", _sceneIndex); |
830d0ba4 AIL |
302 | - } |
303 | - | |
304 | - // ModelDir[]に保持したディレクトリ名から | |
305 | - // model3.jsonのパスを決定する. | |
306 | - // ディレクトリ名とmodel3.jsonの名前を一致させておくこと. | |
98cde37f AIL |
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); | |
525a4608 | 316 | + std::string modelPath = LAppDelegate::GetInstance()->GetExecuteAbsolutePath() + ResourcesPath + modelName + "/"; |
830d0ba4 AIL |
317 | + std::string modelJsonName = modelName; |
318 | modelJsonName += ".model3.json"; | |
319 | ||
320 | ReleaseAllModel(); | |
8ff44985 | 321 | - _models.PushBack(new LAppModel()); |
98cde37f | 322 | - _models[0]->LoadAssets(modelPath.GetRawString(), modelJsonName.GetRawString()); |
8ff44985 | 323 | + _models.PushBack(new LAppModel(useOldParamId)); |
98cde37f | 324 | + _models[0]->LoadAssets(modelPath.c_str(), modelJsonName.c_str()); |
8ff44985 AIL |
325 | |
326 | /* | |
98cde37f | 327 | * モデル半透明表示を行うサンプルを提示する。 |
525a4608 | 328 | @@ -288,8 +188,8 @@ void LAppLive2DManager::ChangeScene(Csm: |
8ff44985 AIL |
329 | |
330 | #if defined(USE_RENDER_TARGET) || defined(USE_MODEL_RENDER_TARGET) | |
331 | // モデル個別にαを付けるサンプルとして、もう1体モデルを作成し、少し位置をずらす | |
332 | - _models.PushBack(new LAppModel()); | |
98cde37f | 333 | - _models[1]->LoadAssets(modelPath.GetRawString(), modelJsonName.GetRawString()); |
8ff44985 | 334 | + _models.PushBack(new LAppModel(useOldParamId)); |
98cde37f | 335 | + _models[1]->LoadAssets(modelPath.c_str(), modelJsonName.c_str()); |
8ff44985 AIL |
336 | _models[1]->GetModelMatrix()->TranslateX(0.2f); |
337 | #endif | |
98cde37f | 338 | |
525a4608 | 339 | @@ -317,3 +217,20 @@ void LAppLive2DManager::SetViewMatrix(Cu |
261d3d0e AIL |
340 | _viewMatrix->GetArray()[i] = m->GetArray()[i]; |
341 | } | |
830d0ba4 AIL |
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 | +} | |
360 | diff -pruN --exclude build ./demo_clean/src/LAppLive2DManager.hpp ./demo_dev/src/LAppLive2DManager.hpp | |
525a4608 AIL |
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 | |
830d0ba4 AIL |
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 | * モデル生成と破棄、タップイベントの処理、モデル切り替えを行う。 | |
98cde37f AIL |
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: | |
830d0ba4 AIL |
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 | |
8ff44985 AIL |
422 | + * @param[in] useOldParamId : If true, translate new (Cubism 3+) |
423 | + * parameter IDs to old (Cubism 2.1) ones | |
830d0ba4 | 424 | + */ |
8ff44985 | 425 | + void SetModel(std::string modelName, bool useOldParamId); |
830d0ba4 AIL |
426 | |
427 | /** | |
428 | * @brief モデル個数を得る | |
98cde37f | 429 | @@ -112,6 +95,24 @@ public: |
830d0ba4 | 430 | */ |
261d3d0e | 431 | void SetViewMatrix(Live2D::Cubism::Framework::CubismMatrix44* m); |
830d0ba4 AIL |
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 コンストラクタ | |
525a4608 | 454 | @@ -125,7 +126,8 @@ private: |
830d0ba4 | 455 | |
525a4608 AIL |
456 | Csm::CubismMatrix44* _viewMatrix; ///< モデル描画に用いるView行列 |
457 | Csm::csmVector<LAppModel*> _models; ///< モデルインスタンスのコンテナ | |
98cde37f | 458 | - Csm::csmInt32 _sceneIndex; ///< 表示するシーンのインデックス値 |
98cde37f AIL |
459 | |
460 | - Csm::csmVector<Csm::csmString> _modelDir; ///< モデルディレクトリ名のコンテナ | |
830d0ba4 AIL |
461 | + float _projScaleFactor; |
462 | + float _translateX; | |
463 | + float _translateY; | |
464 | }; | |
465 | diff -pruN --exclude build ./demo_clean/src/LAppModel.cpp ./demo_dev/src/LAppModel.cpp | |
525a4608 AIL |
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 @@ | |
830d0ba4 AIL |
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; | |
8ff44985 AIL |
477 | |
478 | -LAppModel::LAppModel() | |
479 | +LAppModel::LAppModel(bool useOldParamId) | |
525a4608 | 480 | : LAppModel_Common() |
8ff44985 AIL |
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() | |
525a4608 | 506 | @@ -114,33 +118,6 @@ void LAppModel::SetupModel(ICubismModelS |
830d0ba4 AIL |
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 | - | |
98cde37f | 523 | - if (motion) |
830d0ba4 | 524 | - { |
98cde37f AIL |
525 | - if (_expressions[name] != NULL) |
526 | - { | |
527 | - ACubismMotion::Delete(_expressions[name]); | |
528 | - _expressions[name] = NULL; | |
529 | - } | |
530 | - _expressions[name] = motion; | |
830d0ba4 | 531 | - } |
830d0ba4 AIL |
532 | - |
533 | - DeleteBuffer(buffer, path.GetRawString()); | |
534 | - } | |
535 | - } | |
536 | - | |
537 | //Physics | |
538 | if (strcmp(_modelSetting->GetPhysicsFileName(), "") != 0) | |
539 | { | |
525a4608 | 540 | @@ -179,7 +156,7 @@ void LAppModel::SetupModel(ICubismModelS |
8ff44985 AIL |
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 | } | |
525a4608 | 549 | @@ -203,21 +180,6 @@ void LAppModel::SetupModel(ICubismModelS |
2b1f0c7c | 550 | } |
830d0ba4 AIL |
551 | } |
552 | ||
830d0ba4 AIL |
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 | - | |
bc67426f AIL |
562 | - if (_modelSetting == NULL || _modelMatrix == NULL) |
563 | - { | |
98cde37f | 564 | - LAppPal::PrintLogLn("Failed to SetupModel()."); |
bc67426f AIL |
565 | - return; |
566 | - } | |
567 | - | |
830d0ba4 AIL |
568 | //Layout |
569 | csmMap<csmString, csmFloat32> layout; | |
570 | _modelSetting->GetLayoutMap(layout); | |
525a4608 | 571 | @@ -322,62 +284,57 @@ void LAppModel::Update() |
830d0ba4 AIL |
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()) | |
525a4608 AIL |
585 | + if (_detector) |
586 | { | |
830d0ba4 AIL |
587 | - // モーションの再生がない場合、待機モーションの中からランダムで再生する |
588 | - StartRandomMotion(MotionGroupIdle, PriorityIdle); | |
589 | - } | |
590 | - else | |
525a4608 | 591 | - { |
830d0ba4 AIL |
592 | - motionUpdated = _motionManager->UpdateMotion(_model, deltaTimeSeconds); // モーションを更新 |
593 | - } | |
594 | - _model->SaveParameters(); // 状態を保存 | |
595 | - //----------------------------------------------------------------- | |
2b1f0c7c AIL |
596 | + auto idMan = CubismFramework::GetIdManager(); |
597 | + auto params = _detector->getParams(); | |
598 | ||
525a4608 AIL |
599 | - // 不透明度 |
600 | - _opacity = _model->GetModelOpacity(); | |
601 | - | |
602 | - // まばたき | |
603 | - if (!motionUpdated) | |
830d0ba4 AIL |
604 | - { |
605 | - if (_eyeBlink != NULL) | |
2b1f0c7c AIL |
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 | { | |
830d0ba4 AIL |
611 | - // メインモーションの更新がないとき |
612 | - _eyeBlink->UpdateParameters(_model, deltaTimeSeconds); // 目パチ | |
2b1f0c7c AIL |
613 | + // モーションの再生がない場合、待機モーションの中からランダムで再生する |
614 | + StartRandomMotion(MotionGroupIdle, PriorityIdle); | |
615 | } | |
830d0ba4 AIL |
616 | - } |
617 | - | |
618 | - if (_expressionManager != NULL) | |
2b1f0c7c | 619 | - { |
830d0ba4 AIL |
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の値を加える | |
2b1f0c7c AIL |
631 | + else |
632 | + { | |
633 | + _motionManager->UpdateMotion(_model, deltaTimeSeconds); // モーションを更新 | |
634 | + } | |
635 | + _model->SaveParameters(); // 状態を保存 | |
636 | ||
830d0ba4 AIL |
637 | - //ドラッグによる目の向きの調整 |
638 | - _model->AddParameterValue(_idParamEyeBallX, _dragX); // -1から1の値を加える | |
639 | - _model->AddParameterValue(_idParamEyeBallY, _dragY); | |
830d0ba4 AIL |
640 | |
641 | - // 呼吸など | |
642 | - if (_breath != NULL) | |
643 | - { | |
644 | - _breath->UpdateParameters(_model, deltaTimeSeconds); | |
2b1f0c7c AIL |
645 | + if (params.autoBlink && _eyeBlink) |
646 | + { | |
647 | + _eyeBlink->UpdateParameters(_model, deltaTimeSeconds); | |
648 | + } | |
649 | + else | |
650 | + { | |
8ff44985 | 651 | + _model->SetParameterValue(idMan->GetId(_("ParamEyeLOpen")), |
2b1f0c7c | 652 | + params.leftEyeOpenness); |
8ff44985 | 653 | + _model->SetParameterValue(idMan->GetId(_("ParamEyeROpen")), |
2b1f0c7c AIL |
654 | + params.rightEyeOpenness); |
655 | + } | |
8ff44985 | 656 | + _model->SetParameterValue(idMan->GetId(_("ParamMouthForm")), |
830d0ba4 | 657 | + params.mouthForm); |
8ff44985 | 658 | + _model->SetParameterValue(idMan->GetId(_("ParamMouthOpenY")), |
830d0ba4 | 659 | + params.mouthOpenness); |
8ff44985 | 660 | + _model->SetParameterValue(idMan->GetId(_("ParamEyeLSmile")), |
830d0ba4 | 661 | + params.leftEyeSmile); |
8ff44985 | 662 | + _model->SetParameterValue(idMan->GetId(_("ParamEyeRSmile")), |
830d0ba4 | 663 | + params.rightEyeSmile); |
8ff44985 | 664 | + _model->SetParameterValue(idMan->GetId(_("ParamAngleX")), |
830d0ba4 | 665 | + params.faceXAngle); |
8ff44985 | 666 | + _model->SetParameterValue(idMan->GetId(_("ParamAngleY")), |
830d0ba4 | 667 | + params.faceYAngle); |
8ff44985 | 668 | + _model->SetParameterValue(idMan->GetId(_("ParamAngleZ")), |
830d0ba4 | 669 | + params.faceZAngle); |
2b1f0c7c AIL |
670 | + if (params.autoBreath && _breath) |
671 | + { | |
672 | + // Note: _model->LoadParameters and SaveParameters is needed | |
673 | + // before - see above. | |
674 | + _breath->UpdateParameters(_model, deltaTimeSeconds); | |
675 | + } | |
830d0ba4 AIL |
676 | } |
677 | ||
678 | // 物理演算の設定 | |
525a4608 | 679 | @@ -386,22 +343,6 @@ void LAppModel::Update() |
830d0ba4 AIL |
680 | _physics->Evaluate(_model, deltaTimeSeconds); |
681 | } | |
682 | ||
683 | - // リップシンクの設定 | |
684 | - if (_lipSync) | |
685 | - { | |
261d3d0e AIL |
686 | - // リアルタイムでリップシンクを行う場合、システムから音量を取得して0〜1の範囲で値を入力します。 |
687 | - csmFloat32 value = 0.0f; | |
688 | - | |
689 | - // 状態更新/RMS値取得 | |
690 | - _wavFileHandler.Update(deltaTimeSeconds); | |
691 | - value = _wavFileHandler.GetRms(); | |
830d0ba4 AIL |
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 | { | |
525a4608 | 702 | @@ -464,7 +405,6 @@ CubismMotionQueueEntryHandle LAppModel:: |
261d3d0e AIL |
703 | { |
704 | csmString path = voice; | |
705 | path = _modelHomeDir + path; | |
706 | - _wavFileHandler.Start(path); | |
707 | } | |
708 | ||
709 | if (_debugMode) | |
525a4608 | 710 | @@ -616,3 +556,37 @@ Csm::Rendering::CubismOffscreenSurface_O |
830d0ba4 AIL |
711 | { |
712 | return _renderBuffer; | |
713 | } | |
714 | + | |
715 | +void LAppModel::SetFacialLandmarkDetector(FacialLandmarkDetector *detector) | |
716 | +{ | |
717 | + _detector = detector; | |
718 | +} | |
719 | + | |
8ff44985 AIL |
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 | + | |
830d0ba4 | 748 | diff -pruN --exclude build ./demo_clean/src/LAppModel.hpp ./demo_dev/src/LAppModel.hpp |
525a4608 AIL |
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 @@ | |
830d0ba4 AIL |
752 | #include <Type/csmRectF.hpp> |
753 | #include <Rendering/OpenGL/CubismOffscreenSurface_OpenGLES2.hpp> | |
754 | ||
525a4608 AIL |
755 | -#include "LAppWavFileHandler_Common.hpp" |
756 | #include "LAppModel_Common.hpp" | |
830d0ba4 AIL |
757 | +#include "facial_landmark_detector.h" |
758 | ||
759 | /** | |
760 | * @brief ユーザーが実際に使用するモデルの実装クラス<br> | |
525a4608 | 761 | @@ -25,8 +25,11 @@ class LAppModel : public LAppModel_Commo |
8ff44985 AIL |
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 デストラクタ | |
525a4608 | 774 | @@ -116,6 +119,13 @@ public: |
830d0ba4 | 775 | */ |
98cde37f | 776 | Csm::Rendering::CubismOffscreenSurface_OpenGLES2& GetRenderBuffer(); |
830d0ba4 AIL |
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行列を渡す。 | |
525a4608 | 788 | @@ -169,6 +179,17 @@ private: |
8ff44985 AIL |
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; ///< デルタ時間の積算値[秒] | |
525a4608 | 806 | @@ -185,7 +206,10 @@ private: |
261d3d0e | 807 | const Csm::CubismId* _idParamEyeBallX; ///< パラメータID: ParamEyeBallX |
830d0ba4 AIL |
808 | const Csm::CubismId* _idParamEyeBallY; ///< パラメータID: ParamEyeBallXY |
809 | ||
525a4608 | 810 | - LAppWavFileHandler_Common _wavFileHandler; ///< wavファイルハンドラ |
261d3d0e | 811 | - |
98cde37f | 812 | Csm::Rendering::CubismOffscreenSurface_OpenGLES2 _renderBuffer; ///< フレームバッファ以外の描画先 |
830d0ba4 AIL |
813 | + |
814 | + FacialLandmarkDetector *_detector; | |
815 | }; | |
98cde37f AIL |
816 | + |
817 | + | |
818 | + | |
830d0ba4 | 819 | diff -pruN --exclude build ./demo_clean/src/LAppTextureManager.cpp ./demo_dev/src/LAppTextureManager.cpp |
525a4608 AIL |
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 | |
830d0ba4 AIL |
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 | + | |
525a4608 | 861 | + _texturesInfo.PushBack(textureInfo); |
830d0ba4 AIL |
862 | + |
863 | + return textureInfo; | |
864 | +} | |
865 | + | |
866 | void LAppTextureManager::ReleaseTextures() | |
867 | { | |
525a4608 | 868 | for (Csm::csmUint32 i = 0; i < _texturesInfo.GetSize(); i++) |
830d0ba4 | 869 | diff -pruN --exclude build ./demo_clean/src/LAppTextureManager.hpp ./demo_dev/src/LAppTextureManager.hpp |
525a4608 AIL |
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: | |
830d0ba4 AIL |
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 | * | |
881 | diff -pruN --exclude build ./demo_clean/src/LAppView.cpp ./demo_dev/src/LAppView.cpp | |
525a4608 AIL |
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 | |
830d0ba4 AIL |
885 | void LAppView::Render() |
886 | { | |
887 | _back->Render(); | |
888 | - _gear->Render(); | |
889 | - _power->Render(); | |
890 | - | |
891 | ||
892 | LAppLive2DManager* Live2DManager = LAppLive2DManager::GetInstance(); | |
893 | ||
525a4608 | 894 | @@ -125,35 +122,17 @@ void LAppView::InitializeSprite() |
830d0ba4 AIL |
895 | glfwGetWindowSize(LAppDelegate::GetInstance()->GetWindow(), &width, &height); |
896 | ||
897 | LAppTextureManager* textureManager = LAppDelegate::GetInstance()->GetTextureManager(); | |
98cde37f | 898 | - const string resourcesPath = LAppDelegate::GetInstance()->GetExecuteAbsolutePath() + ResourcesPath; |
830d0ba4 AIL |
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; | |
525a4608 AIL |
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 | ||
830d0ba4 AIL |
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); | |
bc212fa6 | 921 | - _gear = new LAppSprite(x, y, fWidth, fHeight, gearTexture->id, programId); |
830d0ba4 AIL |
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); | |
bc212fa6 | 930 | - _power = new LAppSprite(x, y, fWidth, fHeight, powerTexture->id, programId); |
525a4608 | 931 | - |
830d0ba4 AIL |
932 | // 画面全体を覆うサイズ |
933 | x = width * 0.5f; | |
934 | y = height * 0.5f; | |
525a4608 AIL |
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); | |
830d0ba4 | 939 | - |
830d0ba4 AIL |
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 | - } | |
830d0ba4 | 951 | } |
830d0ba4 | 952 | } |
830d0ba4 | 953 | |
830d0ba4 | 954 | diff -pruN --exclude build ./demo_clean/src/main.cpp ./demo_dev/src/main.cpp |
525a4608 AIL |
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 @@ | |
830d0ba4 AIL |
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; | |
8ff44985 | 988 | + bool oldId; // If true, translate new (Cubism 3+) parameter IDs to old (Cubism 2.1) IDs |
830d0ba4 AIL |
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(); | |
261d3d0e | 1001 | + cmdArgs.scaleFactor = 4.5f; |
830d0ba4 | 1002 | + cmdArgs.translateX = 0.0f; |
261d3d0e | 1003 | + cmdArgs.translateY = -3.1f; |
830d0ba4 | 1004 | + cmdArgs.modelName = "Haru"; |
8ff44985 | 1005 | + cmdArgs.oldId = false; |
830d0ba4 AIL |
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 | + } | |
8ff44985 AIL |
1070 | + else if (arg == "--old-param-id" || arg == "-o") |
1071 | + { | |
1072 | + cmdArgs.oldId = (argv[i + 1][0] == '1'); | |
1073 | + } | |
830d0ba4 AIL |
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(); | |
830d0ba4 AIL |
1102 | + FacialLandmarkDetector detector(cmdArgs.cfgPath); |
1103 | + | |
1104 | + std::thread detectorThread(&FacialLandmarkDetector::mainLoop, | |
1105 | + &detector); | |
1106 | + | |
1107 | + LAppLive2DManager *manager = LAppLive2DManager::GetInstance(); | |
8ff44985 | 1108 | + manager->SetModel(cmdArgs.modelName, cmdArgs.oldId); |
830d0ba4 AIL |
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 | - |