Commit | Line | Data |
---|---|---|
830d0ba4 | 1 | diff -pruN --exclude build ./demo_clean/CMakeLists.txt ./demo_dev/CMakeLists.txt |
ee3fcae5 AIL |
2 | --- ./demo_clean/CMakeLists.txt 2025-05-30 00:59:58.252401066 +0100 |
3 | +++ ./demo_dev/CMakeLists.txt 2025-05-30 01:05:35.538986524 +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}/../../../..) | |
ee3fcae5 | 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) | |
ee3fcae5 | 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 | ||
ee3fcae5 | 22 | @@ -67,6 +67,11 @@ target_link_libraries(Framework Live2DCu |
830d0ba4 AIL |
23 | # Find opengl libraries. |
24 | find_package(OpenGL REQUIRED) | |
25 | ||
126d8fa4 | 26 | +# Add MouseTrackerForCubism |
33ad240c AIL |
27 | +find_package(PkgConfig) |
28 | +pkg_check_modules(GTKMM gtkmm-3.0) | |
126d8fa4 | 29 | +add_subdirectory(../.. MouseTrackerForCubism_build) |
830d0ba4 AIL |
30 | + |
31 | # Make executable app. | |
32 | add_executable(${APP_NAME}) | |
ee3fcae5 AIL |
33 | # Add common source files. |
34 | @@ -79,9 +84,20 @@ target_link_libraries(${APP_NAME} | |
830d0ba4 AIL |
35 | Framework |
36 | glfw | |
37 | ${OPENGL_LIBRARIES} | |
126d8fa4 | 38 | + MouseTrackerForCubism |
830d0ba4 AIL |
39 | + stdc++fs |
40 | ) | |
41 | # Specify include directories. | |
42 | -target_include_directories(${APP_NAME} PRIVATE ${STB_PATH}) | |
33ad240c AIL |
43 | +target_include_directories(${APP_NAME} PRIVATE ${STB_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/../../include ${GTKMM_INCLUDE_DIRS}) |
44 | + | |
45 | +# Copy GUI to build directory | |
46 | +add_custom_command( | |
47 | + TARGET ${APP_NAME} | |
48 | + POST_BUILD | |
49 | + COMMAND | |
50 | + ${CMAKE_COMMAND} -E | |
51 | + copy ${CMAKE_CURRENT_SOURCE_DIR}/../../src/gui.glade $<TARGET_FILE_DIR:${APP_NAME}>/gui.glade | |
52 | +) | |
830d0ba4 AIL |
53 | |
54 | # Copy resource directory to build directory. | |
55 | add_custom_command( | |
830d0ba4 | 56 | diff -pruN --exclude build ./demo_clean/scripts/make_gcc ./demo_dev/scripts/make_gcc |
ee3fcae5 | 57 | --- ./demo_clean/scripts/make_gcc 2025-05-30 00:59:58.252401066 +0100 |
2772c864 | 58 | +++ ./demo_dev/scripts/make_gcc 2023-05-28 09:11:29.467788463 +0100 |
1ed58df4 | 59 | @@ -5,42 +5,9 @@ set -ue |
cd5de0f5 AIL |
60 | SCRIPT_PATH=$(cd $(dirname $0) && pwd) |
61 | CMAKE_PATH=$SCRIPT_PATH/.. | |
62 | BUILD_PATH=$SCRIPT_PATH/../build/make_gcc | |
63 | -MINIMUM_DEMO="OFF" | |
64 | -DATA="" | |
65 | - | |
66 | -if [ "$#" -ne 0 ]; then | |
67 | - DATA="$1" | |
68 | -fi | |
69 | - | |
70 | -while : | |
71 | -do | |
72 | - | |
73 | - if [ -z "$DATA" ]; then | |
74 | - echo "Choose which format you would like to create the demo." | |
75 | - echo "Full version : 1" | |
76 | - echo "Minimum version : 2" | |
77 | - read -p "Your Choice : " DATA | |
78 | - fi | |
79 | - | |
80 | - case "$DATA" in | |
81 | - "1" ) | |
82 | - echo "Making Full Demo" | |
83 | - MINIMUM_DEMO="OFF" | |
84 | - break ;; | |
85 | - "2" ) | |
86 | - echo "Making Minimum Demo" | |
87 | - MINIMUM_DEMO="ON" | |
88 | - break ;; | |
89 | - * ) | |
90 | - echo "You need to enter a valid number." | |
91 | - DATA="" ;; | |
92 | - esac | |
93 | -done | |
94 | ||
95 | # Run CMake. | |
830d0ba4 AIL |
96 | cmake -S "$CMAKE_PATH" \ |
97 | -B "$BUILD_PATH" \ | |
cd5de0f5 | 98 | - -D CMAKE_BUILD_TYPE=Release \ |
1ed58df4 AIL |
99 | - -D CSM_MINIMUM_DEMO=$MINIMUM_DEMO \ |
100 | - -D GLFW_BUILD_WAYLAND=OFF | |
830d0ba4 | 101 | -cd "$BUILD_PATH" && make |
cd5de0f5 | 102 | + -D CMAKE_BUILD_TYPE=Release |
830d0ba4 | 103 | +cd "$BUILD_PATH" && make -j4 |
eba2eb3a | 104 | diff -pruN --exclude build ./demo_clean/src/LAppDefine.cpp ./demo_dev/src/LAppDefine.cpp |
ee3fcae5 AIL |
105 | --- ./demo_clean/src/LAppDefine.cpp 2025-05-30 00:59:58.252401066 +0100 |
106 | +++ ./demo_dev/src/LAppDefine.cpp 2025-05-30 01:07:49.665920483 +0100 | |
107 | @@ -60,11 +60,11 @@ namespace LAppDefine { | |
eba2eb3a AIL |
108 | const csmInt32 PriorityForce = 3; |
109 | ||
110 | // デバッグ用ログの表示オプション | |
111 | - const csmBool DebugLogEnable = true; | |
112 | + const csmBool DebugLogEnable = false; | |
113 | const csmBool DebugTouchLogEnable = false; | |
114 | ||
115 | // Frameworkから出力するログのレベル設定 | |
116 | - const CubismFramework::Option::LogLevel CubismLoggingLevel = CubismFramework::Option::LogLevel_Verbose; | |
117 | + const CubismFramework::Option::LogLevel CubismLoggingLevel = CubismFramework::Option::LogLevel_Warning; | |
118 | ||
119 | // デフォルトのレンダーターゲットサイズ | |
120 | const csmInt32 RenderTargetWidth = 1900; | |
830d0ba4 | 121 | diff -pruN --exclude build ./demo_clean/src/LAppDelegate.cpp ./demo_dev/src/LAppDelegate.cpp |
ee3fcae5 AIL |
122 | --- ./demo_clean/src/LAppDelegate.cpp 2025-05-30 00:59:58.252401066 +0100 |
123 | +++ ./demo_dev/src/LAppDelegate.cpp 2025-05-30 01:09:31.843395630 +0100 | |
124 | @@ -46,7 +46,8 @@ void LAppDelegate::ReleaseInstance() | |
830d0ba4 AIL |
125 | s_instance = NULL; |
126 | } | |
127 | ||
128 | -bool LAppDelegate::Initialize() | |
129 | +bool LAppDelegate::Initialize(int initWindowWidth, int initWindowHeight, | |
130 | + const char *windowTitle) | |
131 | { | |
132 | if (DebugLogEnable) | |
133 | { | |
ee3fcae5 | 134 | @@ -64,7 +65,13 @@ bool LAppDelegate::Initialize() |
830d0ba4 AIL |
135 | } |
136 | ||
137 | // Windowの生成_ | |
138 | - _window = glfwCreateWindow(RenderTargetWidth, RenderTargetHeight, "SAMPLE", NULL, NULL); | |
139 | + _window = glfwCreateWindow( | |
140 | + initWindowWidth ? initWindowWidth : RenderTargetWidth, | |
141 | + initWindowHeight ? initWindowHeight : RenderTargetHeight, | |
142 | + windowTitle ? windowTitle : "SAMPLE", | |
143 | + NULL, | |
144 | + NULL); | |
145 | + | |
146 | if (_window == NULL) | |
147 | { | |
148 | if (DebugLogEnable) | |
ee3fcae5 | 149 | @@ -96,10 +103,6 @@ bool LAppDelegate::Initialize() |
830d0ba4 | 150 | glEnable(GL_BLEND); |
ee3fcae5 | 151 | glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); |
830d0ba4 AIL |
152 | |
153 | - //コールバック関数の登録 | |
154 | - glfwSetMouseButtonCallback(_window, EventHandler::OnMouseCallBack); | |
155 | - glfwSetCursorPosCallback(_window, EventHandler::OnMouseCallBack); | |
156 | - | |
157 | // ウィンドウサイズ記憶 | |
158 | int width, height; | |
159 | glfwGetWindowSize(LAppDelegate::GetInstance()->GetWindow(), &width, &height); | |
830d0ba4 | 160 | diff -pruN --exclude build ./demo_clean/src/LAppDelegate.hpp ./demo_dev/src/LAppDelegate.hpp |
ee3fcae5 AIL |
161 | --- ./demo_clean/src/LAppDelegate.hpp 2025-05-30 00:59:58.252401066 +0100 |
162 | +++ ./demo_dev/src/LAppDelegate.hpp 2025-05-30 01:10:00.192935412 +0100 | |
830d0ba4 AIL |
163 | @@ -40,7 +40,8 @@ public: |
164 | /** | |
165 | * @brief APPに必要なものを初期化する。 | |
166 | */ | |
167 | - bool Initialize(); | |
168 | + bool Initialize(int initWindowWidth = 0, int initWindowHeight = 0, | |
169 | + const char *windowTitle = "SAMPLE"); | |
170 | ||
171 | /** | |
172 | * @brief 解放する。 | |
830d0ba4 | 173 | diff -pruN --exclude build ./demo_clean/src/LAppLive2DManager.cpp ./demo_dev/src/LAppLive2DManager.cpp |
ee3fcae5 AIL |
174 | --- ./demo_clean/src/LAppLive2DManager.cpp 2025-05-30 00:59:58.252401066 +0100 |
175 | +++ ./demo_dev/src/LAppLive2DManager.cpp 2025-05-30 01:12:18.865322293 +0100 | |
1ed58df4 AIL |
176 | @@ -6,13 +6,7 @@ |
177 | */ | |
178 | ||
179 | #include "LAppLive2DManager.hpp" | |
180 | -#include <stdio.h> | |
181 | -#include <stdlib.h> | |
182 | -#include <string.h> | |
183 | -#include <dirent.h> | |
184 | -#include <unistd.h> | |
185 | -#include <libgen.h> | |
186 | -#include <limits.h> | |
187 | +#include <string> | |
188 | #include <GL/glew.h> | |
189 | #include <GLFW/glfw3.h> | |
190 | #include <Rendering/CubismRenderer.hpp> | |
ee3fcae5 | 191 | @@ -68,12 +62,11 @@ void LAppLive2DManager::ReleaseInstance( |
830d0ba4 AIL |
192 | |
193 | LAppLive2DManager::LAppLive2DManager() | |
194 | : _viewMatrix(NULL) | |
195 | - , _sceneIndex(0) | |
196 | + , _projScaleFactor(1.0f) | |
197 | + , _translateX(0.0f) | |
198 | + , _translateY(0.0f) | |
199 | { | |
76316970 | 200 | _viewMatrix = new CubismMatrix44(); |
1ed58df4 | 201 | - SetUpModel(); |
76316970 | 202 | - |
830d0ba4 AIL |
203 | - ChangeScene(_sceneIndex); |
204 | } | |
205 | ||
206 | LAppLive2DManager::~LAppLive2DManager() | |
ee3fcae5 | 207 | @@ -92,60 +85,6 @@ void LAppLive2DManager::ReleaseAllModel( |
1ed58df4 AIL |
208 | _models.Clear(); |
209 | } | |
210 | ||
211 | -void LAppLive2DManager::SetUpModel() | |
212 | -{ | |
213 | - // ResourcesPathの中にあるフォルダ名を全てクロールし、モデルが存在するフォルダを定義する。 | |
214 | - // フォルダはあるが同名の.model3.jsonが見つからなかった場合はリストに含めない。 | |
215 | - struct dirent *dirent; | |
216 | - csmString crawlPath(LAppDelegate::GetInstance()->GetExecuteAbsolutePath().c_str()); | |
217 | - crawlPath += ResourcesPath; | |
218 | - | |
219 | - DIR *pDir = opendir(crawlPath.GetRawString()); | |
220 | - if (pDir == NULL) return; | |
221 | - | |
222 | - _modelDir.Clear(); | |
223 | - | |
224 | - while ((dirent = readdir(pDir)) != NULL) | |
225 | - { | |
226 | - if ((dirent->d_type & DT_DIR) && strcmp(dirent->d_name, "..") != 0) | |
227 | - { | |
228 | - // フォルダと同名の.model3.jsonがあるか探索する | |
229 | - struct dirent *dirent2; | |
230 | - | |
231 | - csmString modelName(dirent->d_name); | |
232 | - | |
233 | - csmString modelPath(crawlPath); | |
234 | - modelPath += modelName; | |
235 | - modelPath.Append(1, '/'); | |
236 | - | |
237 | - csmString model3jsonName(modelName); | |
238 | - model3jsonName += ".model3.json"; | |
239 | - | |
240 | - DIR *pDir2 = opendir(modelPath.GetRawString()); | |
241 | - while ((dirent2 = readdir(pDir2)) != NULL) | |
242 | - { | |
243 | - if (strcmp(dirent2->d_name, model3jsonName.GetRawString()) == 0) | |
244 | - { | |
245 | - _modelDir.PushBack(csmString(dirent->d_name)); | |
246 | - } | |
247 | - } | |
248 | - closedir(pDir2); | |
249 | - } | |
250 | - } | |
251 | - closedir(pDir); | |
252 | - qsort(_modelDir.GetPtr(), _modelDir.GetSize(), sizeof(csmString), CompareCsmString); | |
253 | -} | |
254 | - | |
255 | -csmVector<csmString> LAppLive2DManager::GetModelDir() const | |
256 | -{ | |
257 | - return _modelDir; | |
258 | -} | |
259 | - | |
260 | -csmInt32 LAppLive2DManager::GetModelDirSize() const | |
261 | -{ | |
262 | - return _modelDir.GetSize(); | |
263 | -} | |
264 | - | |
265 | LAppModel* LAppLive2DManager::GetModel(csmUint32 no) const | |
266 | { | |
267 | if (no < _models.GetSize()) | |
ee3fcae5 | 268 | @@ -172,26 +111,6 @@ void LAppLive2DManager::OnTap(csmFloat32 |
830d0ba4 | 269 | { |
ee3fcae5 AIL |
270 | LAppPal::PrintLogLn("[APP]tap point: {x:%.2f y:%.2f}", x, y); |
271 | } | |
830d0ba4 AIL |
272 | - |
273 | - for (csmUint32 i = 0; i < _models.GetSize(); i++) | |
274 | - { | |
275 | - if (_models[i]->HitTest(HitAreaNameHead, x, y)) | |
276 | - { | |
277 | - if (DebugLogEnable) | |
278 | - { | |
1ed58df4 | 279 | - LAppPal::PrintLogLn("[APP]hit area: [%s]", HitAreaNameHead); |
830d0ba4 AIL |
280 | - } |
281 | - _models[i]->SetRandomExpression(); | |
282 | - } | |
283 | - else if (_models[i]->HitTest(HitAreaNameBody, x, y)) | |
284 | - { | |
285 | - if (DebugLogEnable) | |
286 | - { | |
1ed58df4 | 287 | - LAppPal::PrintLogLn("[APP]hit area: [%s]", HitAreaNameBody); |
830d0ba4 | 288 | - } |
a30911c5 | 289 | - _models[i]->StartRandomMotion(MotionGroupTapBody, PriorityNormal, FinishedMotion, BeganMotion); |
830d0ba4 | 290 | - } |
ee3fcae5 | 291 | - } |
830d0ba4 AIL |
292 | } |
293 | ||
ee3fcae5 AIL |
294 | void LAppLive2DManager::OnUpdate() const |
295 | @@ -215,12 +134,15 @@ void LAppLive2DManager::OnUpdate() const | |
76316970 AIL |
296 | { |
297 | // 横に長いモデルを縦長ウィンドウに表示する際モデルの横サイズでscaleを算出する | |
298 | model->GetModelMatrix()->SetWidth(2.0f); | |
299 | - projection.Scale(1.0f, static_cast<float>(width) / static_cast<float>(height)); | |
300 | + projection.Scale(_projScaleFactor, | |
301 | + _projScaleFactor * static_cast<float>(width) / static_cast<float>(height)); | |
302 | } | |
303 | else | |
304 | { | |
305 | - projection.Scale(static_cast<float>(height) / static_cast<float>(width), 1.0f); | |
306 | + projection.Scale(_projScaleFactor * static_cast<float>(height) / static_cast<float>(width), | |
307 | + _projScaleFactor); | |
308 | } | |
309 | + projection.Translate(_translateX, _translateY); | |
830d0ba4 | 310 | |
76316970 AIL |
311 | // 必要があればここで乗算 |
312 | if (_viewMatrix != NULL) | |
ee3fcae5 | 313 | @@ -237,37 +159,15 @@ void LAppLive2DManager::OnUpdate() const |
830d0ba4 AIL |
314 | } |
315 | } | |
316 | ||
317 | -void LAppLive2DManager::NextScene() | |
ee3fcae5 AIL |
318 | +void LAppLive2DManager::SetModel(std::string modelName, bool useOldParamId) |
319 | { | |
1ed58df4 | 320 | - csmInt32 no = (_sceneIndex + 1) % GetModelDirSize(); |
830d0ba4 AIL |
321 | - ChangeScene(no); |
322 | -} | |
323 | - | |
324 | -void LAppLive2DManager::ChangeScene(Csm::csmInt32 index) | |
ee3fcae5 | 325 | -{ |
830d0ba4 AIL |
326 | - _sceneIndex = index; |
327 | - if (DebugLogEnable) | |
328 | - { | |
1ed58df4 | 329 | - LAppPal::PrintLogLn("[APP]model index: %d", _sceneIndex); |
830d0ba4 AIL |
330 | - } |
331 | - | |
332 | - // ModelDir[]に保持したディレクトリ名から | |
333 | - // model3.jsonのパスを決定する. | |
334 | - // ディレクトリ名とmodel3.jsonの名前を一致させておくこと. | |
1ed58df4 AIL |
335 | - const csmString& model = _modelDir[index]; |
336 | - LAppPal::PrintLogLn("[APP]_modelDir: %s", model.GetRawString()); | |
337 | - | |
338 | - csmString modelPath(LAppDelegate::GetInstance()->GetExecuteAbsolutePath().c_str()); | |
339 | - modelPath += ResourcesPath; | |
340 | - modelPath += model; | |
341 | - modelPath.Append(1, '/'); | |
342 | - | |
343 | - csmString modelJsonName(model); | |
ee3fcae5 | 344 | + std::string modelPath = LAppDelegate::GetInstance()->GetExecuteAbsolutePath() + ResourcesPath + modelName + "/"; |
830d0ba4 AIL |
345 | + std::string modelJsonName = modelName; |
346 | modelJsonName += ".model3.json"; | |
347 | ||
348 | ReleaseAllModel(); | |
2c3e79c6 | 349 | - _models.PushBack(new LAppModel()); |
1ed58df4 | 350 | - _models[0]->LoadAssets(modelPath.GetRawString(), modelJsonName.GetRawString()); |
2c3e79c6 | 351 | + _models.PushBack(new LAppModel(useOldParamId)); |
1ed58df4 | 352 | + _models[0]->LoadAssets(modelPath.c_str(), modelJsonName.c_str()); |
2c3e79c6 AIL |
353 | |
354 | /* | |
1ed58df4 | 355 | * モデル半透明表示を行うサンプルを提示する。 |
ee3fcae5 | 356 | @@ -288,8 +188,8 @@ void LAppLive2DManager::ChangeScene(Csm: |
2c3e79c6 AIL |
357 | |
358 | #if defined(USE_RENDER_TARGET) || defined(USE_MODEL_RENDER_TARGET) | |
359 | // モデル個別にαを付けるサンプルとして、もう1体モデルを作成し、少し位置をずらす | |
360 | - _models.PushBack(new LAppModel()); | |
1ed58df4 | 361 | - _models[1]->LoadAssets(modelPath.GetRawString(), modelJsonName.GetRawString()); |
2c3e79c6 | 362 | + _models.PushBack(new LAppModel(useOldParamId)); |
1ed58df4 | 363 | + _models[1]->LoadAssets(modelPath.c_str(), modelJsonName.c_str()); |
2c3e79c6 AIL |
364 | _models[1]->GetModelMatrix()->TranslateX(0.2f); |
365 | #endif | |
1ed58df4 | 366 | |
ee3fcae5 | 367 | @@ -317,3 +217,20 @@ void LAppLive2DManager::SetViewMatrix(Cu |
76316970 AIL |
368 | _viewMatrix->GetArray()[i] = m->GetArray()[i]; |
369 | } | |
830d0ba4 AIL |
370 | } |
371 | + | |
126d8fa4 | 372 | +void LAppLive2DManager::SetTracker(MouseCursorTracker *tracker) |
830d0ba4 AIL |
373 | +{ |
374 | + for (auto it = _models.Begin(); it != _models.End(); ++it) | |
375 | + { | |
126d8fa4 | 376 | + (*it)->SetTracker(tracker); |
830d0ba4 AIL |
377 | + } |
378 | +} | |
379 | + | |
380 | +void LAppLive2DManager::SetProjectionScaleTranslate(float scaleFactor, | |
381 | + float translateX, | |
382 | + float translateY) | |
383 | +{ | |
384 | + _projScaleFactor = scaleFactor; | |
385 | + _translateX = translateX; | |
386 | + _translateY = translateY; | |
387 | +} | |
388 | diff -pruN --exclude build ./demo_clean/src/LAppLive2DManager.hpp ./demo_dev/src/LAppLive2DManager.hpp | |
ee3fcae5 AIL |
389 | --- ./demo_clean/src/LAppLive2DManager.hpp 2025-05-30 00:59:58.256401196 +0100 |
390 | +++ ./demo_dev/src/LAppLive2DManager.hpp 2025-05-30 01:12:54.056756547 +0100 | |
830d0ba4 AIL |
391 | @@ -6,12 +6,15 @@ |
392 | */ | |
393 | #pragma once | |
394 | ||
395 | +#include <string> | |
396 | #include <CubismFramework.hpp> | |
397 | #include <Math/CubismMatrix44.hpp> | |
398 | #include <Type/csmVector.hpp> | |
399 | ||
400 | class LAppModel; | |
401 | ||
126d8fa4 | 402 | +class MouseCursorTracker; |
830d0ba4 AIL |
403 | + |
404 | /** | |
405 | * @brief サンプルアプリケーションにおいてCubismModelを管理するクラス<br> | |
406 | * モデル生成と破棄、タップイベントの処理、モデル切り替えを行う。 | |
1ed58df4 AIL |
407 | @@ -36,24 +39,6 @@ public: |
408 | static void ReleaseInstance(); | |
409 | ||
410 | /** | |
411 | - * @brief Resources フォルダにあるモデルフォルダ名をセットする | |
412 | - * | |
413 | - */ | |
414 | - void SetUpModel(); | |
415 | - | |
416 | - /** | |
417 | - * @brief Resources フォルダにあるモデルフォルダ名を取得する | |
418 | - * | |
419 | - */ | |
420 | - Csm::csmVector<Csm::csmString> GetModelDir() const; | |
421 | - | |
422 | - /** | |
423 | - * @brief Resources フォルダにあるモデルフォルダのサイズを取得する | |
424 | - * | |
425 | - */ | |
426 | - Csm::csmInt32 GetModelDirSize() const; | |
427 | - | |
428 | - /** | |
429 | * @brief 現在のシーンで保持しているモデルを返す | |
430 | * | |
431 | * @param[in] no モデルリストのインデックス値 | |
432 | @@ -90,16 +75,14 @@ public: | |
830d0ba4 AIL |
433 | void OnUpdate() const; |
434 | ||
435 | /** | |
436 | - * @brief 次のシーンに切り替える<br> | |
437 | - * サンプルアプリケーションではモデルセットの切り替えを行う。 | |
438 | - */ | |
439 | - void NextScene(); | |
440 | - | |
441 | - /** | |
442 | - * @brief シーンを切り替える<br> | |
443 | - * サンプルアプリケーションではモデルセットの切り替えを行う。 | |
444 | - */ | |
445 | - void ChangeScene(Csm::csmInt32 index); | |
446 | + * @brief Set model data | |
447 | + * | |
448 | + * @param[in] modelName : Name of model, should be the same for both | |
449 | + * the directory and the model3.json file | |
2c3e79c6 AIL |
450 | + * @param[in] useOldParamId : If true, translate new (Cubism 3+) |
451 | + * parameter IDs to old (Cubism 2.1) ones | |
830d0ba4 | 452 | + */ |
2c3e79c6 | 453 | + void SetModel(std::string modelName, bool useOldParamId); |
830d0ba4 AIL |
454 | |
455 | /** | |
456 | * @brief モデル個数を得る | |
1ed58df4 | 457 | @@ -112,6 +95,24 @@ public: |
830d0ba4 | 458 | */ |
76316970 | 459 | void SetViewMatrix(Live2D::Cubism::Framework::CubismMatrix44* m); |
830d0ba4 AIL |
460 | |
461 | + /** | |
126d8fa4 | 462 | + * @brief Set the pointer to the MouseCursorTracker instance |
830d0ba4 | 463 | + * |
126d8fa4 | 464 | + * @param[in] tracker : Pointer to MouseCursorTracker instance |
830d0ba4 | 465 | + */ |
126d8fa4 | 466 | + void SetTracker(MouseCursorTracker *tracker); |
830d0ba4 AIL |
467 | + |
468 | + /** | |
469 | + * @brief Set projection scale factor and translation parameters | |
470 | + * | |
471 | + * @param[in] scaleFactor : Scale factor applied in both X and Y directions | |
472 | + * @param[in] translateX : Translation in X direction | |
473 | + * @param[in] translateY : Translation in Y direction | |
474 | + */ | |
475 | + void SetProjectionScaleTranslate(float scaleFactor, | |
476 | + float translateX, | |
477 | + float translateY); | |
478 | + | |
479 | private: | |
480 | /** | |
481 | * @brief コンストラクタ | |
ee3fcae5 | 482 | @@ -125,7 +126,8 @@ private: |
830d0ba4 | 483 | |
ee3fcae5 AIL |
484 | Csm::CubismMatrix44* _viewMatrix; ///< モデル描画に用いるView行列 |
485 | Csm::csmVector<LAppModel*> _models; ///< モデルインスタンスのコンテナ | |
1ed58df4 | 486 | - Csm::csmInt32 _sceneIndex; ///< 表示するシーンのインデックス値 |
1ed58df4 AIL |
487 | |
488 | - Csm::csmVector<Csm::csmString> _modelDir; ///< モデルディレクトリ名のコンテナ | |
830d0ba4 AIL |
489 | + float _projScaleFactor; |
490 | + float _translateX; | |
491 | + float _translateY; | |
492 | }; | |
493 | diff -pruN --exclude build ./demo_clean/src/LAppModel.cpp ./demo_dev/src/LAppModel.cpp | |
ee3fcae5 AIL |
494 | --- ./demo_clean/src/LAppModel.cpp 2025-05-30 00:59:58.256401196 +0100 |
495 | +++ ./demo_dev/src/LAppModel.cpp 2025-05-30 01:17:12.780545257 +0100 | |
496 | @@ -21,26 +21,32 @@ | |
830d0ba4 AIL |
497 | #include "LAppTextureManager.hpp" |
498 | #include "LAppDelegate.hpp" | |
499 | ||
126d8fa4 | 500 | +#include "mouse_cursor_tracker.h" |
830d0ba4 | 501 | + |
eba2eb3a AIL |
502 | +#include <iostream> |
503 | + | |
830d0ba4 AIL |
504 | using namespace Live2D::Cubism::Framework; |
505 | using namespace Live2D::Cubism::Framework::DefaultParameterId; | |
506 | using namespace LAppDefine; | |
2c3e79c6 AIL |
507 | |
508 | -LAppModel::LAppModel() | |
509 | +LAppModel::LAppModel(bool useOldParamId) | |
ee3fcae5 | 510 | : LAppModel_Common() |
126d8fa4 AIL |
511 | , _modelSetting(NULL) |
512 | , _userTimeSeconds(0.0f) | |
513 | + , _tracker(nullptr) | |
2c3e79c6 | 514 | + , _useOldParamId(useOldParamId) |
126d8fa4 AIL |
515 | { |
516 | if (DebugLogEnable) | |
517 | { | |
2c3e79c6 AIL |
518 | _debugMode = true; |
519 | } | |
520 | ||
521 | - _idParamAngleX = CubismFramework::GetIdManager()->GetId(ParamAngleX); | |
522 | - _idParamAngleY = CubismFramework::GetIdManager()->GetId(ParamAngleY); | |
523 | - _idParamAngleZ = CubismFramework::GetIdManager()->GetId(ParamAngleZ); | |
524 | - _idParamBodyAngleX = CubismFramework::GetIdManager()->GetId(ParamBodyAngleX); | |
525 | - _idParamEyeBallX = CubismFramework::GetIdManager()->GetId(ParamEyeBallX); | |
526 | - _idParamEyeBallY = CubismFramework::GetIdManager()->GetId(ParamEyeBallY); | |
527 | + _idParamAngleX = CubismFramework::GetIdManager()->GetId(_(ParamAngleX)); | |
528 | + _idParamAngleY = CubismFramework::GetIdManager()->GetId(_(ParamAngleY)); | |
529 | + _idParamAngleZ = CubismFramework::GetIdManager()->GetId(_(ParamAngleZ)); | |
530 | + _idParamBodyAngleX = CubismFramework::GetIdManager()->GetId(_(ParamBodyAngleX)); | |
531 | + _idParamEyeBallX = CubismFramework::GetIdManager()->GetId(_(ParamEyeBallX)); | |
532 | + _idParamEyeBallY = CubismFramework::GetIdManager()->GetId(_(ParamEyeBallY)); | |
533 | } | |
534 | ||
535 | LAppModel::~LAppModel() | |
ee3fcae5 | 536 | @@ -179,7 +185,7 @@ void LAppModel::SetupModel(ICubismModelS |
2c3e79c6 AIL |
537 | breathParameters.PushBack(CubismBreath::BreathParameterData(_idParamAngleY, 0.0f, 8.0f, 3.5345f, 0.5f)); |
538 | breathParameters.PushBack(CubismBreath::BreathParameterData(_idParamAngleZ, 0.0f, 10.0f, 5.5345f, 0.5f)); | |
539 | breathParameters.PushBack(CubismBreath::BreathParameterData(_idParamBodyAngleX, 0.0f, 4.0f, 15.5345f, 0.5f)); | |
540 | - breathParameters.PushBack(CubismBreath::BreathParameterData(CubismFramework::GetIdManager()->GetId(ParamBreath), 0.5f, 0.5f, 3.2345f, 0.5f)); | |
541 | + breathParameters.PushBack(CubismBreath::BreathParameterData(CubismFramework::GetIdManager()->GetId(_(ParamBreath)), 0.5f, 0.5f, 3.2345f, 0.5f)); | |
542 | ||
543 | _breath->SetParameters(breathParameters); | |
544 | } | |
ee3fcae5 | 545 | @@ -322,86 +328,117 @@ void LAppModel::Update() |
830d0ba4 AIL |
546 | const csmFloat32 deltaTimeSeconds = LAppPal::GetDeltaTime(); |
547 | _userTimeSeconds += deltaTimeSeconds; | |
548 | ||
549 | - _dragManager->Update(deltaTimeSeconds); | |
550 | - _dragX = _dragManager->GetX(); | |
551 | - _dragY = _dragManager->GetY(); | |
552 | - | |
553 | - // モーションによるパラメータ更新の有無 | |
554 | - csmBool motionUpdated = false; | |
555 | - | |
556 | - //----------------------------------------------------------------- | |
557 | - _model->LoadParameters(); // 前回セーブされた状態をロード | |
558 | - if (_motionManager->IsFinished()) | |
1ed58df4 | 559 | - { |
830d0ba4 AIL |
560 | - // モーションの再生がない場合、待機モーションの中からランダムで再生する |
561 | - StartRandomMotion(MotionGroupIdle, PriorityIdle); | |
562 | - } | |
563 | - else | |
1ed58df4 AIL |
564 | + if (_tracker) |
565 | { | |
830d0ba4 AIL |
566 | - motionUpdated = _motionManager->UpdateMotion(_model, deltaTimeSeconds); // モーションを更新 |
567 | - } | |
568 | - _model->SaveParameters(); // 状態を保存 | |
569 | - //----------------------------------------------------------------- | |
2b1f0c7c | 570 | + auto idMan = CubismFramework::GetIdManager(); |
126d8fa4 | 571 | + auto params = _tracker->getParams(); |
2b1f0c7c | 572 | |
2772c864 AIL |
573 | - // 不透明度 |
574 | - _opacity = _model->GetModelOpacity(); | |
575 | + _model->LoadParameters(); // 前回セーブされた状態をロード | |
576 | ||
830d0ba4 AIL |
577 | - // まばたき |
578 | - if (!motionUpdated) | |
579 | - { | |
580 | - if (_eyeBlink != NULL) | |
eba2eb3a AIL |
581 | + int paramsMotionPriority = static_cast<int>(params.motionPriority); |
582 | + | |
583 | + if (paramsMotionPriority != PriorityNone) | |
2b1f0c7c | 584 | { |
830d0ba4 AIL |
585 | - // メインモーションの更新がないとき |
586 | - _eyeBlink->UpdateParameters(_model, deltaTimeSeconds); // 目パチ | |
eba2eb3a AIL |
587 | + StartMotion(params.motionGroup.c_str(), params.motionNumber, |
588 | + paramsMotionPriority); | |
2772c864 AIL |
589 | } |
590 | - } | |
eba2eb3a AIL |
591 | + else if (params.randomIdleMotion && _motionManager->IsFinished()) |
592 | + { | |
2b1f0c7c AIL |
593 | + // モーションの再生がない場合、待機モーションの中からランダムで再生する |
594 | + StartRandomMotion(MotionGroupIdle, PriorityIdle); | |
2772c864 | 595 | + } |
eba2eb3a AIL |
596 | + // FIXME pose does not return to normal after motion |
597 | + // if we don't have randomIdleMotion set | |
598 | + else | |
599 | + { | |
600 | + _motionManager->UpdateMotion(_model, deltaTimeSeconds); // モーションを更新 | |
601 | + } | |
602 | + _model->SaveParameters(); // 状態を保存 | |
126d8fa4 | 603 | |
2772c864 AIL |
604 | - if (_expressionManager != NULL) |
605 | - { | |
606 | - _expressionManager->UpdateMotion(_model, deltaTimeSeconds); // 表情でパラメータ更新(相対変化) | |
607 | - } | |
eba2eb3a | 608 | + if (params.expression != "") |
126d8fa4 | 609 | + { |
eba2eb3a | 610 | + SetExpression(params.expression.c_str()); |
126d8fa4 | 611 | + } |
eba2eb3a | 612 | + if (_expressionManager != NULL) |
2b1f0c7c | 613 | + { |
eba2eb3a | 614 | + _expressionManager->UpdateMotion(_model, deltaTimeSeconds); // 表情でパラメータ更新(相対変化) |
2b1f0c7c | 615 | + } |
126d8fa4 | 616 | |
2772c864 AIL |
617 | - //ドラッグによる変化 |
618 | - //ドラッグによる顔の向きの調整 | |
619 | - _model->AddParameterValue(_idParamAngleX, _dragX * 30); // -30から30の値を加える | |
620 | - _model->AddParameterValue(_idParamAngleY, _dragY * 30); | |
621 | - _model->AddParameterValue(_idParamAngleZ, _dragX * _dragY * -30); | |
eba2eb3a AIL |
622 | + bool autoBlink = params.autoBlink && _eyeBlink; |
623 | + auto eyeLOpenIt = params.live2d.find("ParamEyeLOpen"); | |
624 | + auto eyeROpenIt = params.live2d.find("ParamEyeROpen"); | |
2b1f0c7c | 625 | |
2772c864 AIL |
626 | - //ドラッグによる体の向きの調整 |
627 | - _model->AddParameterValue(_idParamBodyAngleX, _dragX * 10); // -10から10の値を加える | |
eba2eb3a | 628 | + if (autoBlink) |
126d8fa4 | 629 | + { |
eba2eb3a AIL |
630 | + // Handle blink first |
631 | + _eyeBlink->UpdateParameters(_model, deltaTimeSeconds); | |
632 | + } | |
830d0ba4 | 633 | |
2772c864 AIL |
634 | - //ドラッグによる目の向きの調整 |
635 | - _model->AddParameterValue(_idParamEyeBallX, _dragX); // -1から1の値を加える | |
636 | - _model->AddParameterValue(_idParamEyeBallY, _dragY); | |
eba2eb3a AIL |
637 | + if (eyeLOpenIt != params.live2d.end()) |
638 | + { | |
639 | + // If value specified, override blinking | |
2c3e79c6 | 640 | + _model->SetParameterValue(idMan->GetId(_("ParamEyeLOpen")), |
eba2eb3a AIL |
641 | + eyeLOpenIt->second); |
642 | + } | |
643 | + else if (!autoBlink) | |
644 | + { | |
645 | + // If no value specified and no auto blink, set to 1 | |
2c3e79c6 | 646 | + _model->SetParameterValue(idMan->GetId(_("ParamEyeLOpen")), 1); |
76316970 | 647 | |
2772c864 AIL |
648 | - // 呼吸など |
649 | - if (_breath != NULL) | |
76316970 | 650 | - { |
2772c864 | 651 | - _breath->UpdateParameters(_model, deltaTimeSeconds); |
76316970 | 652 | - } |
eba2eb3a | 653 | + } |
76316970 | 654 | |
2772c864 AIL |
655 | - // 物理演算の設定 |
656 | - if (_physics != NULL) | |
76316970 | 657 | - { |
2772c864 AIL |
658 | - _physics->Evaluate(_model, deltaTimeSeconds); |
659 | - } | |
eba2eb3a AIL |
660 | + if (eyeROpenIt != params.live2d.end()) |
661 | + { | |
2c3e79c6 | 662 | + _model->SetParameterValue(idMan->GetId(_("ParamEyeROpen")), |
eba2eb3a AIL |
663 | + eyeROpenIt->second); |
664 | + } | |
665 | + else if (!autoBlink) | |
666 | + { | |
2c3e79c6 | 667 | + _model->SetParameterValue(idMan->GetId(_("ParamEyeROpen")), 1); |
eba2eb3a | 668 | + } |
2772c864 AIL |
669 | |
670 | - // リップシンクの設定 | |
671 | - if (_lipSync) | |
672 | - { | |
673 | - // リアルタイムでリップシンクを行う場合、システムから音量を取得して0〜1の範囲で値を入力します。 | |
674 | - csmFloat32 value = 0.0f; | |
675 | ||
676 | - // 状態更新/RMS値取得 | |
677 | - _wavFileHandler.Update(deltaTimeSeconds); | |
678 | - value = _wavFileHandler.GetRms(); | |
eba2eb3a | 679 | + if (params.useLipSync && _lipSync) |
5c2628e8 | 680 | + { |
eba2eb3a | 681 | + csmFloat32 value = params.lipSyncParam; // 0 to 1 |
a30911c5 AIL |
682 | |
683 | - for (csmUint32 i = 0; i < _lipSyncIds.GetSize(); ++i) | |
126d8fa4 AIL |
684 | + for (csmUint32 i = 0; i < _lipSyncIds.GetSize(); ++i) |
685 | + { | |
686 | + _model->AddParameterValue(_lipSyncIds[i], value, 0.8f); | |
687 | + } | |
2b1f0c7c AIL |
688 | + } |
689 | + else | |
ee3fcae5 | 690 | + { |
2c3e79c6 | 691 | + _model->SetParameterValue(idMan->GetId(_("ParamMouthOpenY")), |
eba2eb3a | 692 | + params.live2d["ParamMouthOpenY"]); |
ee3fcae5 | 693 | + } |
a30911c5 | 694 | + |
eba2eb3a | 695 | + for (auto const &entry : params.live2d) |
a30911c5 | 696 | + { |
eba2eb3a AIL |
697 | + std::string key = entry.first; |
698 | + double val = entry.second; | |
2772c864 | 699 | + |
eba2eb3a AIL |
700 | + if (key != "ParamEyeLOpen" && key != "ParamEyeROpen" && |
701 | + key != "ParamMouthOpenY") | |
702 | + { | |
2c3e79c6 | 703 | + _model->SetParameterValue(idMan->GetId(_(key)), val); |
eba2eb3a | 704 | + } |
2b1f0c7c | 705 | + } |
1ed58df4 | 706 | + |
2b1f0c7c | 707 | + if (params.autoBreath && _breath) |
ee3fcae5 AIL |
708 | { |
709 | - _model->AddParameterValue(_lipSyncIds[i], value, 0.8f); | |
2b1f0c7c AIL |
710 | + // Note: _model->LoadParameters and SaveParameters is needed |
711 | + // before - see above. | |
712 | + _breath->UpdateParameters(_model, deltaTimeSeconds); | |
ee3fcae5 AIL |
713 | } |
714 | } | |
715 | ||
76316970 AIL |
716 | + // 物理演算の設定 |
717 | + if (_physics != NULL) | |
718 | + { | |
719 | + _physics->Evaluate(_model, deltaTimeSeconds); | |
ee3fcae5 AIL |
720 | + } |
721 | + | |
722 | // ポーズの設定 | |
723 | if (_pose != NULL) | |
a30911c5 | 724 | { |
ee3fcae5 | 725 | @@ -464,7 +501,6 @@ CubismMotionQueueEntryHandle LAppModel:: |
76316970 AIL |
726 | { |
727 | csmString path = voice; | |
728 | path = _modelHomeDir + path; | |
729 | - _wavFileHandler.Start(path); | |
730 | } | |
731 | ||
732 | if (_debugMode) | |
ee3fcae5 | 733 | @@ -616,3 +652,42 @@ Csm::Rendering::CubismOffscreenSurface_O |
830d0ba4 AIL |
734 | { |
735 | return _renderBuffer; | |
736 | } | |
737 | + | |
126d8fa4 | 738 | +void LAppModel::SetTracker(MouseCursorTracker *tracker) |
830d0ba4 | 739 | +{ |
126d8fa4 | 740 | + _tracker = tracker; |
830d0ba4 AIL |
741 | +} |
742 | + | |
eba2eb3a AIL |
743 | +Csm::ICubismModelSetting* LAppModel::GetModelSetting(void) const |
744 | +{ | |
745 | + return _modelSetting; | |
746 | +} | |
747 | + | |
2c3e79c6 AIL |
748 | +Csm::csmString LAppModel::_(std::string s) |
749 | +{ | |
750 | + std::string ans; | |
751 | + if (_useOldParamId) | |
752 | + { | |
753 | + if (s == "ParamTere") | |
754 | + { | |
755 | + ans = "PARAM_CHEEK"; | |
756 | + } | |
757 | + else | |
758 | + { | |
759 | + for (size_t i = 0; i < s.size(); i++) | |
760 | + { | |
761 | + if (std::isupper(s[i]) && i != 0) | |
762 | + { | |
763 | + ans += '_'; | |
764 | + } | |
765 | + ans += std::toupper(s[i]); | |
766 | + } | |
767 | + } | |
768 | + } | |
769 | + else | |
770 | + { | |
771 | + ans = s; | |
772 | + } | |
773 | + return csmString(ans.c_str()); | |
774 | +} | |
775 | + | |
830d0ba4 | 776 | diff -pruN --exclude build ./demo_clean/src/LAppModel.hpp ./demo_dev/src/LAppModel.hpp |
ee3fcae5 AIL |
777 | --- ./demo_clean/src/LAppModel.hpp 2025-05-30 00:59:58.252401066 +0100 |
778 | +++ ./demo_dev/src/LAppModel.hpp 2025-05-30 01:15:06.963872011 +0100 | |
779 | @@ -12,8 +12,8 @@ | |
830d0ba4 AIL |
780 | #include <Type/csmRectF.hpp> |
781 | #include <Rendering/OpenGL/CubismOffscreenSurface_OpenGLES2.hpp> | |
782 | ||
ee3fcae5 AIL |
783 | -#include "LAppWavFileHandler_Common.hpp" |
784 | #include "LAppModel_Common.hpp" | |
126d8fa4 | 785 | +#include "mouse_cursor_tracker.h" |
830d0ba4 AIL |
786 | |
787 | /** | |
788 | * @brief ユーザーが実際に使用するモデルの実装クラス<br> | |
ee3fcae5 | 789 | @@ -25,8 +25,11 @@ class LAppModel : public LAppModel_Commo |
2c3e79c6 AIL |
790 | public: |
791 | /** | |
792 | * @brief コンストラクタ | |
793 | + * | |
794 | + * @param[in] useOldParamId : If true, translate new (Cubism 3+) | |
795 | + * parameter IDs to old (Cubism 2.1) ones | |
796 | */ | |
797 | - LAppModel(); | |
798 | + LAppModel(bool useOldParamId); | |
799 | ||
800 | /** | |
801 | * @brief デストラクタ | |
ee3fcae5 | 802 | @@ -116,6 +119,15 @@ public: |
830d0ba4 | 803 | */ |
1ed58df4 | 804 | Csm::Rendering::CubismOffscreenSurface_OpenGLES2& GetRenderBuffer(); |
830d0ba4 AIL |
805 | |
806 | + /** | |
126d8fa4 | 807 | + * @brief Set the pointer to the MouseCursorTracker instance |
830d0ba4 | 808 | + * |
126d8fa4 | 809 | + * @param[in] tracker : Pointer to MouseCursorTracker instance |
830d0ba4 | 810 | + */ |
126d8fa4 | 811 | + void SetTracker(MouseCursorTracker *tracker); |
830d0ba4 | 812 | + |
eba2eb3a AIL |
813 | + Csm::ICubismModelSetting* GetModelSetting(void) const; |
814 | + | |
830d0ba4 AIL |
815 | protected: |
816 | /** | |
817 | * @brief モデルを描画する処理。モデルを描画する空間のView-Projection行列を渡す。 | |
ee3fcae5 | 818 | @@ -169,6 +181,17 @@ private: |
2c3e79c6 AIL |
819 | */ |
820 | void ReleaseExpressions(); | |
821 | ||
822 | + /** | |
823 | + * @brief Translate new (Cubism 3+) parameter IDs to old (Cubism 2.1) ones | |
824 | + * | |
825 | + * @param[in] s : New parameter ID | |
826 | + * | |
827 | + * @return Old parameter ID | |
828 | + */ | |
829 | + Csm::csmString _(std::string s); | |
830 | + | |
831 | + bool _useOldParamId; | |
832 | + | |
833 | Csm::ICubismModelSetting* _modelSetting; ///< モデルセッティング情報 | |
834 | Csm::csmString _modelHomeDir; ///< モデルセッティングが置かれたディレクトリ | |
835 | Csm::csmFloat32 _userTimeSeconds; ///< デルタ時間の積算値[秒] | |
ee3fcae5 | 836 | @@ -185,7 +208,7 @@ private: |
76316970 | 837 | const Csm::CubismId* _idParamEyeBallX; ///< パラメータID: ParamEyeBallX |
830d0ba4 AIL |
838 | const Csm::CubismId* _idParamEyeBallY; ///< パラメータID: ParamEyeBallXY |
839 | ||
ee3fcae5 | 840 | - LAppWavFileHandler_Common _wavFileHandler; ///< wavファイルハンドラ |
76316970 | 841 | - |
1ed58df4 | 842 | Csm::Rendering::CubismOffscreenSurface_OpenGLES2 _renderBuffer; ///< フレームバッファ以外の描画先 |
830d0ba4 | 843 | + |
126d8fa4 | 844 | + MouseCursorTracker *_tracker; |
830d0ba4 | 845 | }; |
830d0ba4 | 846 | diff -pruN --exclude build ./demo_clean/src/LAppTextureManager.cpp ./demo_dev/src/LAppTextureManager.cpp |
ee3fcae5 AIL |
847 | --- ./demo_clean/src/LAppTextureManager.cpp 2025-05-30 00:59:58.252401066 +0100 |
848 | +++ ./demo_dev/src/LAppTextureManager.cpp 2025-05-30 01:18:50.733874528 +0100 | |
849 | @@ -96,6 +96,46 @@ LAppTextureManager::TextureInfo* LAppTex | |
830d0ba4 AIL |
850 | |
851 | } | |
852 | ||
853 | +LAppTextureManager::TextureInfo* LAppTextureManager::CreateTextureFromColor( | |
854 | + uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha | |
855 | +) | |
856 | +{ | |
857 | + int width = 8, height = 8; | |
858 | + | |
859 | + uint8_t pixels[height][width][4]; | |
860 | + for (std::size_t h = 0; h < height; h++) | |
861 | + { | |
862 | + for (std::size_t w = 0; w < width; w++) | |
863 | + { | |
864 | + pixels[h][w][0] = red; | |
865 | + pixels[h][w][1] = green; | |
866 | + pixels[h][w][2] = blue; | |
867 | + pixels[h][w][3] = alpha; | |
868 | + } | |
869 | + } | |
870 | + | |
871 | + GLuint textureId; | |
872 | + glGenTextures(1, &textureId); | |
873 | + glBindTexture(GL_TEXTURE_2D, textureId); | |
874 | + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels); | |
875 | + | |
876 | + glGenerateMipmap(GL_TEXTURE_2D); | |
877 | + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); | |
878 | + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); | |
879 | + glBindTexture(GL_TEXTURE_2D, 0); | |
880 | + | |
881 | + | |
882 | + LAppTextureManager::TextureInfo* textureInfo = new LAppTextureManager::TextureInfo(); | |
883 | + textureInfo->fileName = ""; | |
884 | + textureInfo->width = width; | |
885 | + textureInfo->height = height; | |
886 | + textureInfo->id = textureId; | |
887 | + | |
ee3fcae5 | 888 | + _texturesInfo.PushBack(textureInfo); |
830d0ba4 AIL |
889 | + |
890 | + return textureInfo; | |
891 | +} | |
892 | + | |
893 | void LAppTextureManager::ReleaseTextures() | |
894 | { | |
ee3fcae5 | 895 | for (Csm::csmUint32 i = 0; i < _texturesInfo.GetSize(); i++) |
830d0ba4 | 896 | diff -pruN --exclude build ./demo_clean/src/LAppTextureManager.hpp ./demo_dev/src/LAppTextureManager.hpp |
ee3fcae5 AIL |
897 | --- ./demo_clean/src/LAppTextureManager.hpp 2025-05-30 00:59:58.252401066 +0100 |
898 | +++ ./demo_dev/src/LAppTextureManager.hpp 2025-05-30 01:19:14.566288429 +0100 | |
899 | @@ -41,6 +41,8 @@ public: | |
830d0ba4 AIL |
900 | */ |
901 | TextureInfo* CreateTextureFromPngFile(std::string fileName); | |
902 | ||
903 | + TextureInfo *CreateTextureFromColor(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha = 255); | |
904 | + | |
905 | /** | |
906 | * @brief 画像の解放 | |
907 | * | |
908 | diff -pruN --exclude build ./demo_clean/src/LAppView.cpp ./demo_dev/src/LAppView.cpp | |
ee3fcae5 AIL |
909 | --- ./demo_clean/src/LAppView.cpp 2025-05-30 00:59:58.252401066 +0100 |
910 | +++ ./demo_dev/src/LAppView.cpp 2025-05-30 01:24:23.734104120 +0100 | |
911 | @@ -81,9 +81,6 @@ void LAppView::Initialize(int width, int | |
830d0ba4 AIL |
912 | void LAppView::Render() |
913 | { | |
914 | _back->Render(); | |
915 | - _gear->Render(); | |
916 | - _power->Render(); | |
917 | - | |
918 | ||
919 | LAppLive2DManager* Live2DManager = LAppLive2DManager::GetInstance(); | |
920 | ||
ee3fcae5 | 921 | @@ -125,35 +122,17 @@ void LAppView::InitializeSprite() |
830d0ba4 AIL |
922 | glfwGetWindowSize(LAppDelegate::GetInstance()->GetWindow(), &width, &height); |
923 | ||
924 | LAppTextureManager* textureManager = LAppDelegate::GetInstance()->GetTextureManager(); | |
1ed58df4 | 925 | - const string resourcesPath = LAppDelegate::GetInstance()->GetExecuteAbsolutePath() + ResourcesPath; |
830d0ba4 AIL |
926 | |
927 | - string imageName = BackImageName; | |
928 | - LAppTextureManager::TextureInfo* backgroundTexture = textureManager->CreateTextureFromPngFile(resourcesPath + imageName); | |
929 | + | |
930 | + LAppTextureManager::TextureInfo* backgroundTexture = | |
931 | + textureManager->CreateTextureFromColor(0, 255, 0); | |
932 | ||
933 | float x = width * 0.5f; | |
934 | float y = height * 0.5f; | |
935 | - float fWidth = static_cast<float>(backgroundTexture->width * 2.0f); | |
936 | - float fHeight = static_cast<float>(height) * 0.95f; | |
ee3fcae5 AIL |
937 | + float fWidth = static_cast<float>(width); |
938 | + float fHeight = static_cast<float>(height); | |
939 | _back = new LAppSprite(x, y, fWidth, fHeight, backgroundTexture->id, programId); | |
940 | ||
830d0ba4 AIL |
941 | - imageName = GearImageName; |
942 | - LAppTextureManager::TextureInfo* gearTexture = textureManager->CreateTextureFromPngFile(resourcesPath + imageName); | |
943 | - | |
944 | - x = static_cast<float>(width - gearTexture->width * 0.5f); | |
945 | - y = static_cast<float>(height - gearTexture->height * 0.5f); | |
946 | - fWidth = static_cast<float>(gearTexture->width); | |
947 | - fHeight = static_cast<float>(gearTexture->height); | |
a30911c5 | 948 | - _gear = new LAppSprite(x, y, fWidth, fHeight, gearTexture->id, programId); |
830d0ba4 AIL |
949 | - |
950 | - imageName = PowerImageName; | |
951 | - LAppTextureManager::TextureInfo* powerTexture = textureManager->CreateTextureFromPngFile(resourcesPath + imageName); | |
952 | - | |
953 | - x = static_cast<float>(width - powerTexture->width * 0.5f); | |
954 | - y = static_cast<float>(powerTexture->height * 0.5f); | |
955 | - fWidth = static_cast<float>(powerTexture->width); | |
956 | - fHeight = static_cast<float>(powerTexture->height); | |
a30911c5 | 957 | - _power = new LAppSprite(x, y, fWidth, fHeight, powerTexture->id, programId); |
ee3fcae5 | 958 | - |
830d0ba4 AIL |
959 | // 画面全体を覆うサイズ |
960 | x = width * 0.5f; | |
961 | y = height * 0.5f; | |
ee3fcae5 AIL |
962 | @@ -192,18 +171,6 @@ void LAppView::OnTouchesEnded(float px, |
963 | LAppPal::PrintLogLn("[APP]touchesEnded x:%.2f y:%.2f", x, y); | |
964 | } | |
965 | live2DManager->OnTap(x, y); | |
830d0ba4 | 966 | - |
830d0ba4 AIL |
967 | - // 歯車にタップしたか |
968 | - if (_gear->IsHit(px, py)) | |
969 | - { | |
970 | - live2DManager->NextScene(); | |
971 | - } | |
972 | - | |
973 | - // 電源ボタンにタップしたか | |
974 | - if (_power->IsHit(px, py)) | |
975 | - { | |
976 | - LAppDelegate::GetInstance()->AppEnd(); | |
977 | - } | |
ee3fcae5 | 978 | } |
a30911c5 AIL |
979 | } |
980 | ||
ee3fcae5 | 981 | @@ -329,32 +296,4 @@ void LAppView::ResizeSprite() |
830d0ba4 AIL |
982 | _back->ResetRect(x, y, fWidth, fHeight); |
983 | } | |
984 | } | |
985 | - | |
986 | - if (_power) | |
987 | - { | |
988 | - GLuint id = _power->GetTextureId(); | |
989 | - LAppTextureManager::TextureInfo* texInfo = textureManager->GetTextureInfoById(id); | |
990 | - if (texInfo) | |
991 | - { | |
992 | - x = static_cast<float>(width - texInfo->width * 0.5f); | |
993 | - y = static_cast<float>(texInfo->height * 0.5f); | |
994 | - fWidth = static_cast<float>(texInfo->width); | |
995 | - fHeight = static_cast<float>(texInfo->height); | |
996 | - _power->ResetRect(x, y, fWidth, fHeight); | |
997 | - } | |
998 | - } | |
999 | - | |
1000 | - if (_gear) | |
1001 | - { | |
1002 | - GLuint id = _gear->GetTextureId(); | |
1003 | - LAppTextureManager::TextureInfo* texInfo = textureManager->GetTextureInfoById(id); | |
1004 | - if (texInfo) | |
1005 | - { | |
1006 | - x = static_cast<float>(width - texInfo->width * 0.5f); | |
1007 | - y = static_cast<float>(height - texInfo->height * 0.5f); | |
1008 | - fWidth = static_cast<float>(texInfo->width); | |
1009 | - fHeight = static_cast<float>(texInfo->height); | |
1010 | - _gear->ResetRect(x, y, fWidth, fHeight); | |
1011 | - } | |
1012 | - } | |
1013 | } | |
830d0ba4 | 1014 | diff -pruN --exclude build ./demo_clean/src/main.cpp ./demo_dev/src/main.cpp |
ee3fcae5 AIL |
1015 | --- ./demo_clean/src/main.cpp 2025-05-30 00:59:58.252401066 +0100 |
1016 | +++ ./demo_dev/src/main.cpp 2025-05-30 01:19:44.722858078 +0100 | |
1017 | @@ -5,18 +5,186 @@ | |
830d0ba4 AIL |
1018 | * that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html. |
1019 | */ | |
1020 | ||
1021 | +#include <thread> | |
1022 | +#include <stdexcept> | |
1023 | +#include <sstream> | |
eba2eb3a AIL |
1024 | +#include <vector> |
1025 | +#include <utility> | |
1026 | +#include <string> | |
830d0ba4 AIL |
1027 | + |
1028 | +#ifdef __cpp_lib_filesystem | |
1029 | +#include <filesystem> | |
1030 | +namespace fs = std::filesystem; | |
1031 | +#else | |
1032 | +#include <experimental/filesystem> | |
1033 | +namespace fs = std::experimental::filesystem; | |
1034 | +#endif | |
1035 | + | |
eba2eb3a | 1036 | +#include "ICubismModelSetting.hpp" |
830d0ba4 AIL |
1037 | #include "LAppDelegate.hpp" |
1038 | +#include "LAppLive2DManager.hpp" | |
eba2eb3a | 1039 | +#include "LAppModel.hpp" |
126d8fa4 | 1040 | +#include "mouse_cursor_tracker.h" |
830d0ba4 AIL |
1041 | + |
1042 | +struct CmdArgs | |
1043 | +{ | |
1044 | + int windowWidth; | |
1045 | + int windowHeight; | |
1046 | + std::string windowTitle; | |
1047 | + std::string rootDir; | |
1048 | + float scaleFactor; | |
1049 | + float translateX; | |
1050 | + float translateY; | |
1051 | + std::string modelName; | |
2c3e79c6 | 1052 | + bool oldId; // If true, translate new (Cubism 3+) parameter IDs to old (Cubism 2.1) IDs |
126d8fa4 | 1053 | + std::string cfgPath; // Path to config file for MouseCursorTracker |
830d0ba4 AIL |
1054 | +}; |
1055 | + | |
1056 | +CmdArgs parseArgv(int argc, char *argv[]) | |
1057 | +{ | |
1058 | + // I think the command-line args are simple enough to not justify using a library... | |
1059 | + CmdArgs cmdArgs; | |
1060 | + // Set default values | |
1061 | + cmdArgs.windowWidth = 600; | |
1062 | + cmdArgs.windowHeight = 600; | |
126d8fa4 | 1063 | + cmdArgs.windowTitle = "MouseTrackerForCubism example"; |
830d0ba4 | 1064 | + cmdArgs.rootDir = fs::current_path(); |
76316970 | 1065 | + cmdArgs.scaleFactor = 4.5f; |
830d0ba4 | 1066 | + cmdArgs.translateX = 0.0f; |
76316970 | 1067 | + cmdArgs.translateY = -3.1f; |
830d0ba4 | 1068 | + cmdArgs.modelName = "Haru"; |
2c3e79c6 | 1069 | + cmdArgs.oldId = false; |
830d0ba4 AIL |
1070 | + cmdArgs.cfgPath = ""; |
1071 | + | |
1072 | + int i = 1; | |
1073 | + while (i < argc) | |
1074 | + { | |
1075 | + std::string arg = argv[i]; | |
1076 | + std::stringstream ss; | |
1077 | + | |
1078 | + if (arg == "--window-width" || arg == "-W") // capital W for consistency with height | |
1079 | + { | |
1080 | + ss << argv[i + 1]; | |
1081 | + if (!(ss >> cmdArgs.windowWidth)) | |
1082 | + { | |
1083 | + throw std::runtime_error("Invalid argument for window width"); | |
1084 | + } | |
1085 | + } | |
1086 | + else if (arg == "--window-height" || arg == "-H") // avoiding "-h", typically for help | |
1087 | + { | |
1088 | + ss << argv[i + 1]; | |
1089 | + if (!(ss >> cmdArgs.windowHeight)) | |
1090 | + { | |
1091 | + throw std::runtime_error("Invalid argument for window height"); | |
1092 | + } | |
1093 | + } | |
1094 | + else if (arg == "--window-title" || arg == "-t") | |
1095 | + { | |
1096 | + cmdArgs.windowTitle = argv[i + 1]; | |
1097 | + } | |
1098 | + else if (arg == "--root-dir" || arg == "-d") | |
1099 | + { | |
1100 | + cmdArgs.rootDir = argv[i + 1]; | |
1101 | + } | |
1102 | + else if (arg == "--scale-factor" || arg == "-f") | |
1103 | + { | |
1104 | + ss << argv[i + 1]; | |
1105 | + if (!(ss >> cmdArgs.scaleFactor)) | |
1106 | + { | |
1107 | + throw std::runtime_error("Invalid argument for scale factor"); | |
1108 | + } | |
1109 | + } | |
1110 | + else if (arg == "--translate-x" || arg == "-x") | |
1111 | + { | |
1112 | + ss << argv[i + 1]; | |
1113 | + if (!(ss >> cmdArgs.translateX)) | |
1114 | + { | |
1115 | + throw std::runtime_error("Invalid argument for translate X"); | |
1116 | + } | |
1117 | + } | |
1118 | + else if (arg == "--translate-y" || arg == "-y") | |
1119 | + { | |
1120 | + ss << argv[i + 1]; | |
1121 | + if (!(ss >> cmdArgs.translateY)) | |
1122 | + { | |
1123 | + throw std::runtime_error("Invalid argument for translate Y"); | |
1124 | + } | |
1125 | + } | |
1126 | + else if (arg == "--model" || arg == "-m") | |
1127 | + { | |
1128 | + cmdArgs.modelName = argv[i + 1]; | |
1129 | + } | |
1130 | + else if (arg == "--config" || arg == "-c") | |
1131 | + { | |
1132 | + cmdArgs.cfgPath = argv[i + 1]; | |
1133 | + } | |
2c3e79c6 AIL |
1134 | + else if (arg == "--old-param-id" || arg == "-o") |
1135 | + { | |
1136 | + cmdArgs.oldId = (argv[i + 1][0] == '1'); | |
1137 | + } | |
830d0ba4 AIL |
1138 | + else |
1139 | + { | |
1140 | + throw std::runtime_error("Unrecognized argument: " + arg); | |
1141 | + } | |
1142 | + | |
1143 | + i += 2; | |
1144 | + } | |
1145 | + | |
1146 | + return cmdArgs; | |
1147 | +} | |
1148 | ||
1149 | int main(int argc, char* argv[]) | |
1150 | { | |
1151 | - // create the application instance | |
1152 | - if (LAppDelegate::GetInstance()->Initialize() == GL_FALSE) | |
1153 | + auto cmdArgs = parseArgv(argc, argv); | |
1154 | + | |
1155 | + LAppDelegate *delegate = LAppDelegate::GetInstance(); | |
1156 | + | |
1157 | + if (!delegate->Initialize(cmdArgs.windowWidth, | |
1158 | + cmdArgs.windowHeight, | |
1159 | + cmdArgs.windowTitle.c_str())) | |
1160 | { | |
1161 | - return 1; | |
1162 | + throw std::runtime_error("Unable to initialize LAppDelegate"); | |
1163 | } | |
1164 | ||
1165 | - LAppDelegate::GetInstance()->Run(); | |
830d0ba4 | 1166 | + LAppLive2DManager *manager = LAppLive2DManager::GetInstance(); |
2c3e79c6 | 1167 | + manager->SetModel(cmdArgs.modelName, cmdArgs.oldId); |
830d0ba4 AIL |
1168 | + |
1169 | + manager->SetProjectionScaleTranslate(cmdArgs.scaleFactor, | |
1170 | + cmdArgs.translateX, | |
1171 | + cmdArgs.translateY); | |
eba2eb3a AIL |
1172 | + |
1173 | + LAppModel *model = manager->GetModel(0); | |
1174 | + if (!model) throw std::runtime_error("model is null"); | |
1175 | + | |
1176 | + Live2D::Cubism::Framework::ICubismModelSetting *modelSetting = model->GetModelSetting(); | |
1177 | + if (!modelSetting) throw std::runtime_error("modelSetting is null"); | |
1178 | + | |
1179 | + std::vector<std::pair<std::string, int> > motions; | |
1180 | + int motionGroupCount = modelSetting->GetMotionGroupCount(); | |
1181 | + for (int i = 0; i < motionGroupCount; i++) | |
1182 | + { | |
1183 | + const char *motionGroup = modelSetting->GetMotionGroupName(i); | |
1184 | + int motionCount = modelSetting->GetMotionCount(motionGroup); | |
1185 | + motions.push_back(std::make_pair(std::string(motionGroup), motionCount)); | |
1186 | + } | |
1187 | + | |
1188 | + std::vector<std::string> expressions; | |
1189 | + int expCount = modelSetting->GetExpressionCount(); | |
1190 | + for (int i = 0; i < expCount; i++) | |
1191 | + { | |
1192 | + const char *expName = modelSetting->GetExpressionName(i); | |
1193 | + expressions.push_back(std::string(expName)); | |
1194 | + } | |
1195 | + | |
1196 | + MouseCursorTracker tracker(cmdArgs.cfgPath, motions, expressions); | |
1197 | + | |
1198 | + std::thread trackerThread(&MouseCursorTracker::mainLoop, &tracker); | |
126d8fa4 | 1199 | + manager->SetTracker(&tracker); |
830d0ba4 AIL |
1200 | + |
1201 | + delegate->Run(); | |
1202 | + | |
126d8fa4 AIL |
1203 | + tracker.stop(); |
1204 | + trackerThread.join(); | |
830d0ba4 AIL |
1205 | |
1206 | return 0; | |
1207 | } | |
1208 | - |