Commit | Line | Data |
---|---|---|
830d0ba4 | 1 | diff -pruN --exclude build ./demo_clean/CMakeLists.txt ./demo_dev/CMakeLists.txt |
76316970 AIL |
2 | --- ./demo_clean/CMakeLists.txt 2021-02-17 01:23:17.000000000 +0000 |
3 | +++ ./demo_dev/CMakeLists.txt 2021-04-28 12:32:48.468744883 +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}/../../../..) | |
76316970 | 9 | +set(SDK_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../CubismSdkForNative-4-r.2) |
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) | |
13 | @@ -32,7 +32,7 @@ set(GLFW_INSTALL OFF CACHE BOOL "" FORCE | |
14 | set(BUILD_UTILS OFF CACHE BOOL "" FORCE) | |
15 | ||
16 | # Specify version of compiler. | |
17 | -set(CMAKE_CXX_STANDARD 14) | |
18 | +set(CMAKE_CXX_STANDARD 17) | |
19 | set(CMAKE_CXX_STANDARD_REQUIRED ON) | |
20 | set(CMAKE_CXX_EXTENSIONS OFF) | |
21 | ||
33ad240c | 22 | @@ -64,6 +64,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}) | |
33 | # Add source files. | |
33ad240c | 34 | @@ -73,9 +78,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 |
76316970 AIL |
57 | --- ./demo_clean/scripts/make_gcc 2021-02-17 01:23:17.000000000 +0000 |
58 | +++ ./demo_dev/scripts/make_gcc 2021-04-28 12:18:50.948333190 +0100 | |
126d8fa4 | 59 | @@ -10,4 +10,4 @@ BUILD_PATH=$SCRIPT_PATH/../build/make_gc |
830d0ba4 AIL |
60 | cmake -S "$CMAKE_PATH" \ |
61 | -B "$BUILD_PATH" \ | |
126d8fa4 | 62 | -D CMAKE_BUILD_TYPE=Release |
830d0ba4 | 63 | -cd "$BUILD_PATH" && make |
830d0ba4 AIL |
64 | +cd "$BUILD_PATH" && make -j4 |
65 | diff -pruN --exclude build ./demo_clean/src/CMakeLists.txt ./demo_dev/src/CMakeLists.txt | |
76316970 AIL |
66 | --- ./demo_clean/src/CMakeLists.txt 2021-02-17 01:23:17.000000000 +0000 |
67 | +++ ./demo_dev/src/CMakeLists.txt 2021-04-28 12:21:56.795134807 +0100 | |
68 | @@ -6,8 +6,6 @@ target_sources(${APP_NAME} | |
69 | ${CMAKE_CURRENT_SOURCE_DIR}/LAppDefine.hpp | |
70 | ${CMAKE_CURRENT_SOURCE_DIR}/LAppDelegate.cpp | |
71 | ${CMAKE_CURRENT_SOURCE_DIR}/LAppDelegate.hpp | |
72 | - ${CMAKE_CURRENT_SOURCE_DIR}/LAppWavFileHandler.cpp | |
73 | - ${CMAKE_CURRENT_SOURCE_DIR}/LAppWavFileHandler.hpp | |
74 | ${CMAKE_CURRENT_SOURCE_DIR}/LAppLive2DManager.cpp | |
75 | ${CMAKE_CURRENT_SOURCE_DIR}/LAppLive2DManager.hpp | |
76 | ${CMAKE_CURRENT_SOURCE_DIR}/LAppModel.cpp | |
77 | @@ -21,6 +19,4 @@ target_sources(${APP_NAME} | |
830d0ba4 AIL |
78 | ${CMAKE_CURRENT_SOURCE_DIR}/LAppView.cpp |
79 | ${CMAKE_CURRENT_SOURCE_DIR}/LAppView.hpp | |
80 | ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp | |
81 | - ${CMAKE_CURRENT_SOURCE_DIR}/TouchManager.cpp | |
82 | - ${CMAKE_CURRENT_SOURCE_DIR}/TouchManager.hpp | |
83 | ) | |
eba2eb3a | 84 | diff -pruN --exclude build ./demo_clean/src/LAppDefine.cpp ./demo_dev/src/LAppDefine.cpp |
76316970 AIL |
85 | --- ./demo_clean/src/LAppDefine.cpp 2021-02-17 01:23:17.000000000 +0000 |
86 | +++ ./demo_dev/src/LAppDefine.cpp 2021-04-28 12:18:50.948333190 +0100 | |
87 | @@ -64,11 +64,11 @@ namespace LAppDefine { | |
eba2eb3a AIL |
88 | const csmInt32 PriorityForce = 3; |
89 | ||
90 | // デバッグ用ログの表示オプション | |
91 | - const csmBool DebugLogEnable = true; | |
92 | + const csmBool DebugLogEnable = false; | |
93 | const csmBool DebugTouchLogEnable = false; | |
94 | ||
95 | // Frameworkから出力するログのレベル設定 | |
96 | - const CubismFramework::Option::LogLevel CubismLoggingLevel = CubismFramework::Option::LogLevel_Verbose; | |
97 | + const CubismFramework::Option::LogLevel CubismLoggingLevel = CubismFramework::Option::LogLevel_Warning; | |
98 | ||
99 | // デフォルトのレンダーターゲットサイズ | |
100 | const csmInt32 RenderTargetWidth = 1900; | |
830d0ba4 | 101 | diff -pruN --exclude build ./demo_clean/src/LAppDelegate.cpp ./demo_dev/src/LAppDelegate.cpp |
76316970 AIL |
102 | --- ./demo_clean/src/LAppDelegate.cpp 2021-02-17 01:23:17.000000000 +0000 |
103 | +++ ./demo_dev/src/LAppDelegate.cpp 2021-04-28 12:18:50.948333190 +0100 | |
830d0ba4 AIL |
104 | @@ -45,7 +45,8 @@ void LAppDelegate::ReleaseInstance() |
105 | s_instance = NULL; | |
106 | } | |
107 | ||
108 | -bool LAppDelegate::Initialize() | |
109 | +bool LAppDelegate::Initialize(int initWindowWidth, int initWindowHeight, | |
110 | + const char *windowTitle) | |
111 | { | |
112 | if (DebugLogEnable) | |
113 | { | |
114 | @@ -63,7 +64,13 @@ bool LAppDelegate::Initialize() | |
115 | } | |
116 | ||
117 | // Windowの生成_ | |
118 | - _window = glfwCreateWindow(RenderTargetWidth, RenderTargetHeight, "SAMPLE", NULL, NULL); | |
119 | + _window = glfwCreateWindow( | |
120 | + initWindowWidth ? initWindowWidth : RenderTargetWidth, | |
121 | + initWindowHeight ? initWindowHeight : RenderTargetHeight, | |
122 | + windowTitle ? windowTitle : "SAMPLE", | |
123 | + NULL, | |
124 | + NULL); | |
125 | + | |
126 | if (_window == NULL) | |
127 | { | |
128 | if (DebugLogEnable) | |
129 | @@ -95,10 +102,6 @@ bool LAppDelegate::Initialize() | |
130 | glEnable(GL_BLEND); | |
131 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); | |
132 | ||
133 | - //コールバック関数の登録 | |
134 | - glfwSetMouseButtonCallback(_window, EventHandler::OnMouseCallBack); | |
135 | - glfwSetCursorPosCallback(_window, EventHandler::OnMouseCallBack); | |
136 | - | |
137 | // ウィンドウサイズ記憶 | |
138 | int width, height; | |
139 | glfwGetWindowSize(LAppDelegate::GetInstance()->GetWindow(), &width, &height); | |
140 | @@ -111,8 +114,6 @@ bool LAppDelegate::Initialize() | |
141 | // Cubism3の初期化 | |
142 | InitializeCubism(); | |
143 | ||
144 | - SetRootDirectory(); | |
145 | - | |
146 | //load model | |
147 | LAppLive2DManager::GetInstance(); | |
148 | ||
149 | @@ -214,49 +215,6 @@ void LAppDelegate::InitializeCubism() | |
150 | LAppPal::UpdateTime(); | |
151 | } | |
152 | ||
153 | -void LAppDelegate::OnMouseCallBack(GLFWwindow* window, int button, int action, int modify) | |
154 | -{ | |
155 | - if (_view == NULL) | |
156 | - { | |
157 | - return; | |
158 | - } | |
159 | - if (GLFW_MOUSE_BUTTON_LEFT != button) | |
160 | - { | |
161 | - return; | |
162 | - } | |
163 | - | |
164 | - if (GLFW_PRESS == action) | |
165 | - { | |
166 | - _captured = true; | |
167 | - _view->OnTouchesBegan(_mouseX, _mouseY); | |
168 | - } | |
169 | - else if (GLFW_RELEASE == action) | |
170 | - { | |
171 | - if (_captured) | |
172 | - { | |
173 | - _captured = false; | |
174 | - _view->OnTouchesEnded(_mouseX, _mouseY); | |
175 | - } | |
176 | - } | |
177 | -} | |
178 | - | |
179 | -void LAppDelegate::OnMouseCallBack(GLFWwindow* window, double x, double y) | |
180 | -{ | |
181 | - _mouseX = static_cast<float>(x); | |
182 | - _mouseY = static_cast<float>(y); | |
183 | - | |
184 | - if (!_captured) | |
185 | - { | |
186 | - return; | |
187 | - } | |
188 | - if (_view == NULL) | |
189 | - { | |
190 | - return; | |
191 | - } | |
192 | - | |
193 | - _view->OnTouchesMoved(_mouseX, _mouseY); | |
194 | -} | |
195 | - | |
196 | GLuint LAppDelegate::CreateShader() | |
197 | { | |
198 | //バーテックスシェーダのコンパイル | |
199 | @@ -299,29 +257,9 @@ GLuint LAppDelegate::CreateShader() | |
200 | return programId; | |
201 | } | |
202 | ||
203 | -void LAppDelegate::SetRootDirectory() | |
204 | +void LAppDelegate::SetRootDirectory(std::string rootDir) | |
205 | { | |
206 | - char path[1024]; | |
207 | - ssize_t len = readlink("/proc/self/exe", path, 1024 - 1); | |
208 | - | |
209 | - if (len != -1) | |
210 | - { | |
211 | - path[len] = '\0'; | |
212 | - } | |
213 | - | |
214 | - std::string pathString(path); | |
215 | - | |
216 | - pathString = pathString.substr(0, pathString.rfind("Demo")); | |
217 | - Csm::csmVector<string> splitStrings = this->Split(pathString, '/'); | |
218 | - | |
219 | - this->_rootDirectory = ""; | |
220 | - | |
221 | - for(int i = 0; i < splitStrings.GetSize(); i++) | |
222 | - { | |
223 | - this->_rootDirectory = this->_rootDirectory + "/" +splitStrings[i]; | |
224 | - } | |
225 | - | |
226 | - this->_rootDirectory += "/"; | |
227 | + this->_rootDirectory = rootDir + "/"; | |
228 | } | |
229 | ||
230 | Csm::csmVector<string> LAppDelegate::Split(const std::string& baseString, char delimiter) | |
231 | diff -pruN --exclude build ./demo_clean/src/LAppDelegate.hpp ./demo_dev/src/LAppDelegate.hpp | |
76316970 AIL |
232 | --- ./demo_clean/src/LAppDelegate.hpp 2021-02-17 01:23:17.000000000 +0000 |
233 | +++ ./demo_dev/src/LAppDelegate.hpp 2021-04-28 12:18:50.948333190 +0100 | |
830d0ba4 AIL |
234 | @@ -40,7 +40,8 @@ public: |
235 | /** | |
236 | * @brief APPに必要なものを初期化する。 | |
237 | */ | |
238 | - bool Initialize(); | |
239 | + bool Initialize(int initWindowWidth = 0, int initWindowHeight = 0, | |
240 | + const char *windowTitle = "SAMPLE"); | |
241 | ||
242 | /** | |
243 | * @brief 解放する。 | |
244 | @@ -53,25 +54,6 @@ public: | |
245 | void Run(); | |
246 | ||
247 | /** | |
248 | - * @brief OpenGL用 glfwSetMouseButtonCallback用関数。 | |
249 | - * | |
250 | - * @param[in] window コールバックを呼んだWindow情報 | |
251 | - * @param[in] button ボタン種類 | |
252 | - * @param[in] action 実行結果 | |
253 | - * @param[in] modify | |
254 | - */ | |
255 | - void OnMouseCallBack(GLFWwindow* window, int button, int action, int modify); | |
256 | - | |
257 | - /** | |
258 | - * @brief OpenGL用 glfwSetCursorPosCallback用関数。 | |
259 | - * | |
260 | - * @param[in] window コールバックを呼んだWindow情報 | |
261 | - * @param[in] x x座標 | |
262 | - * @param[in] y x座標 | |
263 | - */ | |
264 | - void OnMouseCallBack(GLFWwindow* window, double x, double y); | |
265 | - | |
266 | - /** | |
267 | * @brief シェーダーを登録する。 | |
268 | */ | |
269 | GLuint CreateShader(); | |
270 | @@ -98,8 +80,10 @@ public: | |
271 | ||
272 | /** | |
273 | * @brief ルートディレクトリを設定する。 | |
274 | + * | |
275 | + * @param[in] rootDir : The root directory to set to. | |
276 | */ | |
277 | - void SetRootDirectory(); | |
278 | + void SetRootDirectory(std::string rootDir); | |
279 | ||
280 | /** | |
281 | * @brief ルートディレクトリを取得する。 | |
282 | @@ -146,24 +130,3 @@ private: | |
283 | int _windowWidth; ///< Initialize関数で設定したウィンドウ幅 | |
284 | int _windowHeight; ///< Initialize関数で設定したウィンドウ高さ | |
285 | }; | |
286 | - | |
287 | -class EventHandler | |
288 | -{ | |
289 | -public: | |
290 | - /** | |
291 | - * @brief glfwSetMouseButtonCallback用コールバック関数。 | |
292 | - */ | |
293 | - static void OnMouseCallBack(GLFWwindow* window, int button, int action, int modify) | |
294 | - { | |
295 | - LAppDelegate::GetInstance()->OnMouseCallBack(window, button, action, modify); | |
296 | - } | |
297 | - | |
298 | - /** | |
299 | - * @brief glfwSetCursorPosCallback用コールバック関数。 | |
300 | - */ | |
301 | - static void OnMouseCallBack(GLFWwindow* window, double x, double y) | |
302 | - { | |
303 | - LAppDelegate::GetInstance()->OnMouseCallBack(window, x, y); | |
304 | - } | |
305 | - | |
306 | -}; | |
307 | diff -pruN --exclude build ./demo_clean/src/LAppLive2DManager.cpp ./demo_dev/src/LAppLive2DManager.cpp | |
76316970 AIL |
308 | --- ./demo_clean/src/LAppLive2DManager.cpp 2021-02-17 01:23:17.000000000 +0000 |
309 | +++ ./demo_dev/src/LAppLive2DManager.cpp 2021-04-28 12:24:45.405646016 +0100 | |
310 | @@ -52,11 +52,11 @@ void LAppLive2DManager::ReleaseInstance( | |
830d0ba4 AIL |
311 | |
312 | LAppLive2DManager::LAppLive2DManager() | |
313 | : _viewMatrix(NULL) | |
314 | - , _sceneIndex(0) | |
315 | + , _projScaleFactor(1.0f) | |
316 | + , _translateX(0.0f) | |
317 | + , _translateY(0.0f) | |
318 | { | |
76316970 AIL |
319 | _viewMatrix = new CubismMatrix44(); |
320 | - | |
830d0ba4 AIL |
321 | - ChangeScene(_sceneIndex); |
322 | } | |
323 | ||
324 | LAppLive2DManager::~LAppLive2DManager() | |
76316970 | 325 | @@ -100,26 +100,6 @@ void LAppLive2DManager::OnTap(csmFloat32 |
830d0ba4 AIL |
326 | { |
327 | LAppPal::PrintLog("[APP]tap point: {x:%.2f y:%.2f}", x, y); | |
328 | } | |
329 | - | |
330 | - for (csmUint32 i = 0; i < _models.GetSize(); i++) | |
331 | - { | |
332 | - if (_models[i]->HitTest(HitAreaNameHead, x, y)) | |
333 | - { | |
334 | - if (DebugLogEnable) | |
335 | - { | |
336 | - LAppPal::PrintLog("[APP]hit area: [%s]", HitAreaNameHead); | |
337 | - } | |
338 | - _models[i]->SetRandomExpression(); | |
339 | - } | |
340 | - else if (_models[i]->HitTest(HitAreaNameBody, x, y)) | |
341 | - { | |
342 | - if (DebugLogEnable) | |
343 | - { | |
344 | - LAppPal::PrintLog("[APP]hit area: [%s]", HitAreaNameBody); | |
345 | - } | |
346 | - _models[i]->StartRandomMotion(MotionGroupTapBody, PriorityNormal, FinishedMotion); | |
347 | - } | |
348 | - } | |
349 | } | |
350 | ||
351 | void LAppLive2DManager::OnUpdate() const | |
76316970 AIL |
352 | @@ -136,12 +116,15 @@ void LAppLive2DManager::OnUpdate() const |
353 | { | |
354 | // 横に長いモデルを縦長ウィンドウに表示する際モデルの横サイズでscaleを算出する | |
355 | model->GetModelMatrix()->SetWidth(2.0f); | |
356 | - projection.Scale(1.0f, static_cast<float>(width) / static_cast<float>(height)); | |
357 | + projection.Scale(_projScaleFactor, | |
358 | + _projScaleFactor * static_cast<float>(width) / static_cast<float>(height)); | |
359 | } | |
360 | else | |
361 | { | |
362 | - projection.Scale(static_cast<float>(height) / static_cast<float>(width), 1.0f); | |
363 | + projection.Scale(_projScaleFactor * static_cast<float>(height) / static_cast<float>(width), | |
364 | + _projScaleFactor); | |
365 | } | |
366 | + projection.Translate(_translateX, _translateY); | |
830d0ba4 | 367 | |
76316970 AIL |
368 | // 必要があればここで乗算 |
369 | if (_viewMatrix != NULL) | |
370 | @@ -158,30 +141,14 @@ void LAppLive2DManager::OnUpdate() const | |
830d0ba4 AIL |
371 | } |
372 | } | |
373 | ||
374 | -void LAppLive2DManager::NextScene() | |
375 | -{ | |
376 | - csmInt32 no = (_sceneIndex + 1) % ModelDirSize; | |
377 | - ChangeScene(no); | |
378 | -} | |
379 | - | |
380 | -void LAppLive2DManager::ChangeScene(Csm::csmInt32 index) | |
2c3e79c6 | 381 | +void LAppLive2DManager::SetModel(std::string modelName, bool useOldParamId) |
830d0ba4 AIL |
382 | { |
383 | - _sceneIndex = index; | |
384 | - if (DebugLogEnable) | |
385 | - { | |
386 | - LAppPal::PrintLog("[APP]model index: %d", _sceneIndex); | |
387 | - } | |
388 | - | |
389 | - // ModelDir[]に保持したディレクトリ名から | |
390 | - // model3.jsonのパスを決定する. | |
391 | - // ディレクトリ名とmodel3.jsonの名前を一致させておくこと. | |
392 | - std::string model = ModelDir[index]; | |
393 | - std::string modelPath = LAppDelegate::GetInstance()->GetRootDirectory() + ResourcesPath + model + "/"; | |
394 | - std::string modelJsonName = ModelDir[index]; | |
395 | + std::string modelPath = LAppDelegate::GetInstance()->GetRootDirectory() + ResourcesPath + modelName + "/"; | |
396 | + std::string modelJsonName = modelName; | |
397 | modelJsonName += ".model3.json"; | |
398 | ||
399 | ReleaseAllModel(); | |
2c3e79c6 AIL |
400 | - _models.PushBack(new LAppModel()); |
401 | + _models.PushBack(new LAppModel(useOldParamId)); | |
402 | _models[0]->LoadAssets(modelPath.c_str(), modelJsonName.c_str()); | |
403 | ||
404 | /* | |
76316970 | 405 | @@ -203,7 +170,7 @@ void LAppLive2DManager::ChangeScene(Csm: |
2c3e79c6 AIL |
406 | |
407 | #if defined(USE_RENDER_TARGET) || defined(USE_MODEL_RENDER_TARGET) | |
408 | // モデル個別にαを付けるサンプルとして、もう1体モデルを作成し、少し位置をずらす | |
409 | - _models.PushBack(new LAppModel()); | |
410 | + _models.PushBack(new LAppModel(useOldParamId)); | |
411 | _models[1]->LoadAssets(modelPath.c_str(), modelJsonName.c_str()); | |
412 | _models[1]->GetModelMatrix()->TranslateX(0.2f); | |
413 | #endif | |
76316970 AIL |
414 | @@ -232,3 +199,20 @@ void LAppLive2DManager::SetViewMatrix(Cu |
415 | _viewMatrix->GetArray()[i] = m->GetArray()[i]; | |
416 | } | |
830d0ba4 AIL |
417 | } |
418 | + | |
126d8fa4 | 419 | +void LAppLive2DManager::SetTracker(MouseCursorTracker *tracker) |
830d0ba4 AIL |
420 | +{ |
421 | + for (auto it = _models.Begin(); it != _models.End(); ++it) | |
422 | + { | |
126d8fa4 | 423 | + (*it)->SetTracker(tracker); |
830d0ba4 AIL |
424 | + } |
425 | +} | |
426 | + | |
427 | +void LAppLive2DManager::SetProjectionScaleTranslate(float scaleFactor, | |
428 | + float translateX, | |
429 | + float translateY) | |
430 | +{ | |
431 | + _projScaleFactor = scaleFactor; | |
432 | + _translateX = translateX; | |
433 | + _translateY = translateY; | |
434 | +} | |
435 | diff -pruN --exclude build ./demo_clean/src/LAppLive2DManager.hpp ./demo_dev/src/LAppLive2DManager.hpp | |
76316970 AIL |
436 | --- ./demo_clean/src/LAppLive2DManager.hpp 2021-02-17 01:23:17.000000000 +0000 |
437 | +++ ./demo_dev/src/LAppLive2DManager.hpp 2021-04-28 12:18:50.948333190 +0100 | |
830d0ba4 AIL |
438 | @@ -6,12 +6,15 @@ |
439 | */ | |
440 | #pragma once | |
441 | ||
442 | +#include <string> | |
443 | #include <CubismFramework.hpp> | |
444 | #include <Math/CubismMatrix44.hpp> | |
445 | #include <Type/csmVector.hpp> | |
446 | ||
447 | class LAppModel; | |
448 | ||
126d8fa4 | 449 | +class MouseCursorTracker; |
830d0ba4 AIL |
450 | + |
451 | /** | |
452 | * @brief サンプルアプリケーションにおいてCubismModelを管理するクラス<br> | |
453 | * モデル生成と破棄、タップイベントの処理、モデル切り替えを行う。 | |
2c3e79c6 | 454 | @@ -72,16 +75,14 @@ public: |
830d0ba4 AIL |
455 | void OnUpdate() const; |
456 | ||
457 | /** | |
458 | - * @brief 次のシーンに切り替える<br> | |
459 | - * サンプルアプリケーションではモデルセットの切り替えを行う。 | |
460 | - */ | |
461 | - void NextScene(); | |
462 | - | |
463 | - /** | |
464 | - * @brief シーンを切り替える<br> | |
465 | - * サンプルアプリケーションではモデルセットの切り替えを行う。 | |
466 | - */ | |
467 | - void ChangeScene(Csm::csmInt32 index); | |
468 | + * @brief Set model data | |
469 | + * | |
470 | + * @param[in] modelName : Name of model, should be the same for both | |
471 | + * the directory and the model3.json file | |
2c3e79c6 AIL |
472 | + * @param[in] useOldParamId : If true, translate new (Cubism 3+) |
473 | + * parameter IDs to old (Cubism 2.1) ones | |
830d0ba4 | 474 | + */ |
2c3e79c6 | 475 | + void SetModel(std::string modelName, bool useOldParamId); |
830d0ba4 AIL |
476 | |
477 | /** | |
478 | * @brief モデル個数を得る | |
76316970 | 479 | @@ -94,6 +95,24 @@ public: |
830d0ba4 | 480 | */ |
76316970 | 481 | void SetViewMatrix(Live2D::Cubism::Framework::CubismMatrix44* m); |
830d0ba4 AIL |
482 | |
483 | + /** | |
126d8fa4 | 484 | + * @brief Set the pointer to the MouseCursorTracker instance |
830d0ba4 | 485 | + * |
126d8fa4 | 486 | + * @param[in] tracker : Pointer to MouseCursorTracker instance |
830d0ba4 | 487 | + */ |
126d8fa4 | 488 | + void SetTracker(MouseCursorTracker *tracker); |
830d0ba4 AIL |
489 | + |
490 | + /** | |
491 | + * @brief Set projection scale factor and translation parameters | |
492 | + * | |
493 | + * @param[in] scaleFactor : Scale factor applied in both X and Y directions | |
494 | + * @param[in] translateX : Translation in X direction | |
495 | + * @param[in] translateY : Translation in Y direction | |
496 | + */ | |
497 | + void SetProjectionScaleTranslate(float scaleFactor, | |
498 | + float translateX, | |
499 | + float translateY); | |
500 | + | |
501 | private: | |
502 | /** | |
503 | * @brief コンストラクタ | |
76316970 | 504 | @@ -107,5 +126,8 @@ private: |
830d0ba4 AIL |
505 | |
506 | Csm::CubismMatrix44* _viewMatrix; ///< モデル描画に用いるView行列 | |
507 | Csm::csmVector<LAppModel*> _models; ///< モデルインスタンスのコンテナ | |
508 | - Csm::csmInt32 _sceneIndex; ///< 表示するシーンのインデックス値 | |
509 | + | |
510 | + float _projScaleFactor; | |
511 | + float _translateX; | |
512 | + float _translateY; | |
513 | }; | |
514 | diff -pruN --exclude build ./demo_clean/src/LAppModel.cpp ./demo_dev/src/LAppModel.cpp | |
76316970 AIL |
515 | --- ./demo_clean/src/LAppModel.cpp 2021-02-17 01:23:17.000000000 +0000 |
516 | +++ ./demo_dev/src/LAppModel.cpp 2021-04-28 12:26:56.699586813 +0100 | |
eba2eb3a | 517 | @@ -21,6 +21,10 @@ |
830d0ba4 AIL |
518 | #include "LAppTextureManager.hpp" |
519 | #include "LAppDelegate.hpp" | |
520 | ||
126d8fa4 | 521 | +#include "mouse_cursor_tracker.h" |
830d0ba4 | 522 | + |
eba2eb3a AIL |
523 | +#include <iostream> |
524 | + | |
830d0ba4 AIL |
525 | using namespace Live2D::Cubism::Framework; |
526 | using namespace Live2D::Cubism::Framework::DefaultParameterId; | |
527 | using namespace LAppDefine; | |
2c3e79c6 AIL |
528 | @@ -45,22 +49,24 @@ namespace { |
529 | } | |
530 | } | |
531 | ||
532 | -LAppModel::LAppModel() | |
533 | +LAppModel::LAppModel(bool useOldParamId) | |
126d8fa4 AIL |
534 | : CubismUserModel() |
535 | , _modelSetting(NULL) | |
536 | , _userTimeSeconds(0.0f) | |
537 | + , _tracker(nullptr) | |
2c3e79c6 | 538 | + , _useOldParamId(useOldParamId) |
126d8fa4 AIL |
539 | { |
540 | if (DebugLogEnable) | |
541 | { | |
2c3e79c6 AIL |
542 | _debugMode = true; |
543 | } | |
544 | ||
545 | - _idParamAngleX = CubismFramework::GetIdManager()->GetId(ParamAngleX); | |
546 | - _idParamAngleY = CubismFramework::GetIdManager()->GetId(ParamAngleY); | |
547 | - _idParamAngleZ = CubismFramework::GetIdManager()->GetId(ParamAngleZ); | |
548 | - _idParamBodyAngleX = CubismFramework::GetIdManager()->GetId(ParamBodyAngleX); | |
549 | - _idParamEyeBallX = CubismFramework::GetIdManager()->GetId(ParamEyeBallX); | |
550 | - _idParamEyeBallY = CubismFramework::GetIdManager()->GetId(ParamEyeBallY); | |
551 | + _idParamAngleX = CubismFramework::GetIdManager()->GetId(_(ParamAngleX)); | |
552 | + _idParamAngleY = CubismFramework::GetIdManager()->GetId(_(ParamAngleY)); | |
553 | + _idParamAngleZ = CubismFramework::GetIdManager()->GetId(_(ParamAngleZ)); | |
554 | + _idParamBodyAngleX = CubismFramework::GetIdManager()->GetId(_(ParamBodyAngleX)); | |
555 | + _idParamEyeBallX = CubismFramework::GetIdManager()->GetId(_(ParamEyeBallX)); | |
556 | + _idParamEyeBallY = CubismFramework::GetIdManager()->GetId(_(ParamEyeBallY)); | |
557 | } | |
558 | ||
559 | LAppModel::~LAppModel() | |
560 | @@ -190,7 +196,7 @@ void LAppModel::SetupModel(ICubismModelS | |
561 | breathParameters.PushBack(CubismBreath::BreathParameterData(_idParamAngleY, 0.0f, 8.0f, 3.5345f, 0.5f)); | |
562 | breathParameters.PushBack(CubismBreath::BreathParameterData(_idParamAngleZ, 0.0f, 10.0f, 5.5345f, 0.5f)); | |
563 | breathParameters.PushBack(CubismBreath::BreathParameterData(_idParamBodyAngleX, 0.0f, 4.0f, 15.5345f, 0.5f)); | |
564 | - breathParameters.PushBack(CubismBreath::BreathParameterData(CubismFramework::GetIdManager()->GetId(ParamBreath), 0.5f, 0.5f, 3.2345f, 0.5f)); | |
565 | + breathParameters.PushBack(CubismBreath::BreathParameterData(CubismFramework::GetIdManager()->GetId(_(ParamBreath)), 0.5f, 0.5f, 3.2345f, 0.5f)); | |
566 | ||
567 | _breath->SetParameters(breathParameters); | |
568 | } | |
76316970 | 569 | @@ -335,83 +341,118 @@ void LAppModel::Update() |
830d0ba4 AIL |
570 | const csmFloat32 deltaTimeSeconds = LAppPal::GetDeltaTime(); |
571 | _userTimeSeconds += deltaTimeSeconds; | |
572 | ||
573 | - _dragManager->Update(deltaTimeSeconds); | |
574 | - _dragX = _dragManager->GetX(); | |
575 | - _dragY = _dragManager->GetY(); | |
576 | - | |
577 | - // モーションによるパラメータ更新の有無 | |
578 | - csmBool motionUpdated = false; | |
579 | - | |
580 | - //----------------------------------------------------------------- | |
581 | - _model->LoadParameters(); // 前回セーブされた状態をロード | |
582 | - if (_motionManager->IsFinished()) | |
eba2eb3a | 583 | - { |
830d0ba4 AIL |
584 | - // モーションの再生がない場合、待機モーションの中からランダムで再生する |
585 | - StartRandomMotion(MotionGroupIdle, PriorityIdle); | |
586 | - } | |
587 | - else | |
eba2eb3a AIL |
588 | + if (_tracker) |
589 | { | |
830d0ba4 AIL |
590 | - motionUpdated = _motionManager->UpdateMotion(_model, deltaTimeSeconds); // モーションを更新 |
591 | - } | |
592 | - _model->SaveParameters(); // 状態を保存 | |
593 | - //----------------------------------------------------------------- | |
2b1f0c7c | 594 | + auto idMan = CubismFramework::GetIdManager(); |
126d8fa4 | 595 | + auto params = _tracker->getParams(); |
2b1f0c7c | 596 | |
830d0ba4 AIL |
597 | - // まばたき |
598 | - if (!motionUpdated) | |
599 | - { | |
600 | - if (_eyeBlink != NULL) | |
2b1f0c7c | 601 | + _model->LoadParameters(); // 前回セーブされた状態をロード |
eba2eb3a AIL |
602 | + |
603 | + int paramsMotionPriority = static_cast<int>(params.motionPriority); | |
604 | + | |
605 | + if (paramsMotionPriority != PriorityNone) | |
2b1f0c7c | 606 | { |
830d0ba4 AIL |
607 | - // メインモーションの更新がないとき |
608 | - _eyeBlink->UpdateParameters(_model, deltaTimeSeconds); // 目パチ | |
eba2eb3a AIL |
609 | + StartMotion(params.motionGroup.c_str(), params.motionNumber, |
610 | + paramsMotionPriority); | |
611 | + } | |
612 | + else if (params.randomIdleMotion && _motionManager->IsFinished()) | |
613 | + { | |
2b1f0c7c AIL |
614 | + // モーションの再生がない場合、待機モーションの中からランダムで再生する |
615 | + StartRandomMotion(MotionGroupIdle, PriorityIdle); | |
616 | } | |
830d0ba4 | 617 | - } |
126d8fa4 | 618 | |
830d0ba4 | 619 | - if (_expressionManager != NULL) |
2b1f0c7c | 620 | - { |
830d0ba4 AIL |
621 | - _expressionManager->UpdateMotion(_model, deltaTimeSeconds); // 表情でパラメータ更新(相対変化) |
622 | - } | |
eba2eb3a AIL |
623 | + // FIXME pose does not return to normal after motion |
624 | + // if we don't have randomIdleMotion set | |
625 | + else | |
626 | + { | |
627 | + _motionManager->UpdateMotion(_model, deltaTimeSeconds); // モーションを更新 | |
628 | + } | |
629 | + _model->SaveParameters(); // 状態を保存 | |
126d8fa4 | 630 | |
830d0ba4 AIL |
631 | - //ドラッグによる変化 |
632 | - //ドラッグによる顔の向きの調整 | |
633 | - _model->AddParameterValue(_idParamAngleX, _dragX * 30); // -30から30の値を加える | |
634 | - _model->AddParameterValue(_idParamAngleY, _dragY * 30); | |
635 | - _model->AddParameterValue(_idParamAngleZ, _dragX * _dragY * -30); | |
eba2eb3a | 636 | + if (params.expression != "") |
126d8fa4 | 637 | + { |
eba2eb3a | 638 | + SetExpression(params.expression.c_str()); |
126d8fa4 | 639 | + } |
eba2eb3a | 640 | + if (_expressionManager != NULL) |
2b1f0c7c | 641 | + { |
eba2eb3a | 642 | + _expressionManager->UpdateMotion(_model, deltaTimeSeconds); // 表情でパラメータ更新(相対変化) |
2b1f0c7c | 643 | + } |
126d8fa4 AIL |
644 | |
645 | - //ドラッグによる体の向きの調整 | |
646 | - _model->AddParameterValue(_idParamBodyAngleX, _dragX * 10); // -10から10の値を加える | |
eba2eb3a AIL |
647 | + bool autoBlink = params.autoBlink && _eyeBlink; |
648 | + auto eyeLOpenIt = params.live2d.find("ParamEyeLOpen"); | |
649 | + auto eyeROpenIt = params.live2d.find("ParamEyeROpen"); | |
2b1f0c7c | 650 | |
830d0ba4 AIL |
651 | - //ドラッグによる目の向きの調整 |
652 | - _model->AddParameterValue(_idParamEyeBallX, _dragX); // -1から1の値を加える | |
653 | - _model->AddParameterValue(_idParamEyeBallY, _dragY); | |
eba2eb3a | 654 | + if (autoBlink) |
126d8fa4 | 655 | + { |
eba2eb3a AIL |
656 | + // Handle blink first |
657 | + _eyeBlink->UpdateParameters(_model, deltaTimeSeconds); | |
658 | + } | |
830d0ba4 AIL |
659 | |
660 | - // 呼吸など | |
661 | - if (_breath != NULL) | |
662 | - { | |
663 | - _breath->UpdateParameters(_model, deltaTimeSeconds); | |
76316970 | 664 | - } |
eba2eb3a AIL |
665 | + if (eyeLOpenIt != params.live2d.end()) |
666 | + { | |
667 | + // If value specified, override blinking | |
2c3e79c6 | 668 | + _model->SetParameterValue(idMan->GetId(_("ParamEyeLOpen")), |
eba2eb3a AIL |
669 | + eyeLOpenIt->second); |
670 | + } | |
671 | + else if (!autoBlink) | |
672 | + { | |
673 | + // If no value specified and no auto blink, set to 1 | |
2c3e79c6 | 674 | + _model->SetParameterValue(idMan->GetId(_("ParamEyeLOpen")), 1); |
76316970 AIL |
675 | |
676 | - // 物理演算の設定 | |
677 | - if (_physics != NULL) | |
678 | - { | |
679 | - _physics->Evaluate(_model, deltaTimeSeconds); | |
680 | - } | |
eba2eb3a | 681 | + } |
76316970 AIL |
682 | |
683 | - // リップシンクの設定 | |
684 | - if (_lipSync) | |
685 | - { | |
686 | - // リアルタイムでリップシンクを行う場合、システムから音量を取得して0〜1の範囲で値を入力します。 | |
687 | - csmFloat32 value = 0.0f; | |
eba2eb3a AIL |
688 | + if (eyeROpenIt != params.live2d.end()) |
689 | + { | |
2c3e79c6 | 690 | + _model->SetParameterValue(idMan->GetId(_("ParamEyeROpen")), |
eba2eb3a AIL |
691 | + eyeROpenIt->second); |
692 | + } | |
693 | + else if (!autoBlink) | |
694 | + { | |
2c3e79c6 | 695 | + _model->SetParameterValue(idMan->GetId(_("ParamEyeROpen")), 1); |
eba2eb3a | 696 | + } |
76316970 AIL |
697 | |
698 | - // 状態更新/RMS値取得 | |
699 | - _wavFileHandler.Update(deltaTimeSeconds); | |
700 | - value = _wavFileHandler.GetRms(); | |
701 | ||
702 | - for (csmUint32 i = 0; i < _lipSyncIds.GetSize(); ++i) | |
eba2eb3a | 703 | + if (params.useLipSync && _lipSync) |
76316970 AIL |
704 | { |
705 | - _model->AddParameterValue(_lipSyncIds[i], value, 0.8f); | |
eba2eb3a AIL |
706 | + csmFloat32 value = params.lipSyncParam; // 0 to 1 |
707 | + | |
126d8fa4 AIL |
708 | + for (csmUint32 i = 0; i < _lipSyncIds.GetSize(); ++i) |
709 | + { | |
710 | + _model->AddParameterValue(_lipSyncIds[i], value, 0.8f); | |
711 | + } | |
2b1f0c7c AIL |
712 | + } |
713 | + else | |
714 | + { | |
2c3e79c6 | 715 | + _model->SetParameterValue(idMan->GetId(_("ParamMouthOpenY")), |
eba2eb3a AIL |
716 | + params.live2d["ParamMouthOpenY"]); |
717 | + } | |
718 | + | |
719 | + for (auto const &entry : params.live2d) | |
720 | + { | |
721 | + std::string key = entry.first; | |
722 | + double val = entry.second; | |
723 | + | |
724 | + if (key != "ParamEyeLOpen" && key != "ParamEyeROpen" && | |
725 | + key != "ParamMouthOpenY") | |
726 | + { | |
2c3e79c6 | 727 | + _model->SetParameterValue(idMan->GetId(_(key)), val); |
eba2eb3a | 728 | + } |
2b1f0c7c | 729 | + } |
126d8fa4 | 730 | + |
2b1f0c7c AIL |
731 | + if (params.autoBreath && _breath) |
732 | + { | |
733 | + // Note: _model->LoadParameters and SaveParameters is needed | |
734 | + // before - see above. | |
735 | + _breath->UpdateParameters(_model, deltaTimeSeconds); | |
76316970 | 736 | } |
830d0ba4 AIL |
737 | } |
738 | ||
76316970 AIL |
739 | + // 物理演算の設定 |
740 | + if (_physics != NULL) | |
741 | + { | |
742 | + _physics->Evaluate(_model, deltaTimeSeconds); | |
743 | + } | |
744 | + | |
830d0ba4 AIL |
745 | // ポーズの設定 |
746 | if (_pose != NULL) | |
747 | { | |
76316970 AIL |
748 | @@ -480,7 +521,6 @@ CubismMotionQueueEntryHandle LAppModel:: |
749 | { | |
750 | csmString path = voice; | |
751 | path = _modelHomeDir + path; | |
752 | - _wavFileHandler.Start(path); | |
753 | } | |
754 | ||
755 | if (_debugMode) | |
756 | @@ -632,3 +672,42 @@ Csm::Rendering::CubismOffscreenFrame_Ope | |
830d0ba4 AIL |
757 | { |
758 | return _renderBuffer; | |
759 | } | |
760 | + | |
126d8fa4 | 761 | +void LAppModel::SetTracker(MouseCursorTracker *tracker) |
830d0ba4 | 762 | +{ |
126d8fa4 | 763 | + _tracker = tracker; |
830d0ba4 AIL |
764 | +} |
765 | + | |
eba2eb3a AIL |
766 | +Csm::ICubismModelSetting* LAppModel::GetModelSetting(void) const |
767 | +{ | |
768 | + return _modelSetting; | |
769 | +} | |
770 | + | |
2c3e79c6 AIL |
771 | +Csm::csmString LAppModel::_(std::string s) |
772 | +{ | |
773 | + std::string ans; | |
774 | + if (_useOldParamId) | |
775 | + { | |
776 | + if (s == "ParamTere") | |
777 | + { | |
778 | + ans = "PARAM_CHEEK"; | |
779 | + } | |
780 | + else | |
781 | + { | |
782 | + for (size_t i = 0; i < s.size(); i++) | |
783 | + { | |
784 | + if (std::isupper(s[i]) && i != 0) | |
785 | + { | |
786 | + ans += '_'; | |
787 | + } | |
788 | + ans += std::toupper(s[i]); | |
789 | + } | |
790 | + } | |
791 | + } | |
792 | + else | |
793 | + { | |
794 | + ans = s; | |
795 | + } | |
796 | + return csmString(ans.c_str()); | |
797 | +} | |
798 | + | |
830d0ba4 | 799 | diff -pruN --exclude build ./demo_clean/src/LAppModel.hpp ./demo_dev/src/LAppModel.hpp |
76316970 AIL |
800 | --- ./demo_clean/src/LAppModel.hpp 2021-02-17 01:23:17.000000000 +0000 |
801 | +++ ./demo_dev/src/LAppModel.hpp 2021-04-28 12:27:55.836457680 +0100 | |
802 | @@ -13,7 +13,7 @@ | |
830d0ba4 AIL |
803 | #include <Type/csmRectF.hpp> |
804 | #include <Rendering/OpenGL/CubismOffscreenSurface_OpenGLES2.hpp> | |
805 | ||
76316970 | 806 | -#include "LAppWavFileHandler.hpp" |
126d8fa4 | 807 | +#include "mouse_cursor_tracker.h" |
830d0ba4 AIL |
808 | |
809 | /** | |
810 | * @brief ユーザーが実際に使用するモデルの実装クラス<br> | |
76316970 | 811 | @@ -25,8 +25,11 @@ class LAppModel : public Csm::CubismUser |
2c3e79c6 AIL |
812 | public: |
813 | /** | |
814 | * @brief コンストラクタ | |
815 | + * | |
816 | + * @param[in] useOldParamId : If true, translate new (Cubism 3+) | |
817 | + * parameter IDs to old (Cubism 2.1) ones | |
818 | */ | |
819 | - LAppModel(); | |
820 | + LAppModel(bool useOldParamId); | |
821 | ||
822 | /** | |
823 | * @brief デストラクタ | |
76316970 | 824 | @@ -114,6 +117,15 @@ public: |
830d0ba4 AIL |
825 | */ |
826 | Csm::Rendering::CubismOffscreenFrame_OpenGLES2& GetRenderBuffer(); | |
827 | ||
828 | + /** | |
126d8fa4 | 829 | + * @brief Set the pointer to the MouseCursorTracker instance |
830d0ba4 | 830 | + * |
126d8fa4 | 831 | + * @param[in] tracker : Pointer to MouseCursorTracker instance |
830d0ba4 | 832 | + */ |
126d8fa4 | 833 | + void SetTracker(MouseCursorTracker *tracker); |
830d0ba4 | 834 | + |
eba2eb3a AIL |
835 | + Csm::ICubismModelSetting* GetModelSetting(void) const; |
836 | + | |
830d0ba4 AIL |
837 | protected: |
838 | /** | |
839 | * @brief モデルを描画する処理。モデルを描画する空間のView-Projection行列を渡す。 | |
76316970 | 840 | @@ -167,6 +179,17 @@ private: |
2c3e79c6 AIL |
841 | */ |
842 | void ReleaseExpressions(); | |
843 | ||
844 | + /** | |
845 | + * @brief Translate new (Cubism 3+) parameter IDs to old (Cubism 2.1) ones | |
846 | + * | |
847 | + * @param[in] s : New parameter ID | |
848 | + * | |
849 | + * @return Old parameter ID | |
850 | + */ | |
851 | + Csm::csmString _(std::string s); | |
852 | + | |
853 | + bool _useOldParamId; | |
854 | + | |
855 | Csm::ICubismModelSetting* _modelSetting; ///< モデルセッティング情報 | |
856 | Csm::csmString _modelHomeDir; ///< モデルセッティングが置かれたディレクトリ | |
857 | Csm::csmFloat32 _userTimeSeconds; ///< デルタ時間の積算値[秒] | |
76316970 AIL |
858 | @@ -183,9 +206,9 @@ private: |
859 | const Csm::CubismId* _idParamEyeBallX; ///< パラメータID: ParamEyeBallX | |
830d0ba4 AIL |
860 | const Csm::CubismId* _idParamEyeBallY; ///< パラメータID: ParamEyeBallXY |
861 | ||
76316970 AIL |
862 | - LAppWavFileHandler _wavFileHandler; ///< wavファイルハンドラ |
863 | - | |
830d0ba4 AIL |
864 | Csm::Rendering::CubismOffscreenFrame_OpenGLES2 _renderBuffer; ///< フレームバッファ以外の描画先 |
865 | + | |
126d8fa4 | 866 | + MouseCursorTracker *_tracker; |
830d0ba4 AIL |
867 | }; |
868 | ||
869 | ||
870 | diff -pruN --exclude build ./demo_clean/src/LAppPal.cpp ./demo_dev/src/LAppPal.cpp | |
76316970 AIL |
871 | --- ./demo_clean/src/LAppPal.cpp 2021-02-17 01:23:17.000000000 +0000 |
872 | +++ ./demo_dev/src/LAppPal.cpp 2021-04-28 12:18:50.952333251 +0100 | |
830d0ba4 AIL |
873 | @@ -6,6 +6,7 @@ |
874 | */ | |
875 | ||
876 | #include "LAppPal.hpp" | |
877 | +#include <stdexcept> | |
878 | #include <stdio.h> | |
879 | #include <stdlib.h> | |
880 | #include <stdarg.h> | |
eba2eb3a AIL |
881 | @@ -36,7 +37,6 @@ csmByte* LAppPal::LoadFileAsBytes(const |
882 | if (stat(path, &statBuf) == 0) | |
883 | { | |
884 | size = statBuf.st_size; | |
885 | - PrintLog(path); | |
886 | } | |
887 | ||
888 | std::fstream file; | |
889 | @@ -45,10 +45,7 @@ csmByte* LAppPal::LoadFileAsBytes(const | |
830d0ba4 AIL |
890 | file.open(path, std::ios::in | std::ios::binary); |
891 | if (!file.is_open()) | |
892 | { | |
893 | - if (DebugLogEnable) | |
894 | - { | |
895 | - PrintLog("file open error"); | |
896 | - } | |
897 | + throw std::runtime_error("Failed to open file " + filePath); | |
898 | return NULL; | |
899 | } | |
900 | file.read(buf, size); | |
901 | diff -pruN --exclude build ./demo_clean/src/LAppTextureManager.cpp ./demo_dev/src/LAppTextureManager.cpp | |
76316970 AIL |
902 | --- ./demo_clean/src/LAppTextureManager.cpp 2021-02-17 01:23:17.000000000 +0000 |
903 | +++ ./demo_dev/src/LAppTextureManager.cpp 2021-04-28 12:18:50.952333251 +0100 | |
830d0ba4 AIL |
904 | @@ -96,6 +96,46 @@ LAppTextureManager::TextureInfo* LAppTex |
905 | ||
906 | } | |
907 | ||
908 | +LAppTextureManager::TextureInfo* LAppTextureManager::CreateTextureFromColor( | |
909 | + uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha | |
910 | +) | |
911 | +{ | |
912 | + int width = 8, height = 8; | |
913 | + | |
914 | + uint8_t pixels[height][width][4]; | |
915 | + for (std::size_t h = 0; h < height; h++) | |
916 | + { | |
917 | + for (std::size_t w = 0; w < width; w++) | |
918 | + { | |
919 | + pixels[h][w][0] = red; | |
920 | + pixels[h][w][1] = green; | |
921 | + pixels[h][w][2] = blue; | |
922 | + pixels[h][w][3] = alpha; | |
923 | + } | |
924 | + } | |
925 | + | |
926 | + GLuint textureId; | |
927 | + glGenTextures(1, &textureId); | |
928 | + glBindTexture(GL_TEXTURE_2D, textureId); | |
929 | + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels); | |
930 | + | |
931 | + glGenerateMipmap(GL_TEXTURE_2D); | |
932 | + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); | |
933 | + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); | |
934 | + glBindTexture(GL_TEXTURE_2D, 0); | |
935 | + | |
936 | + | |
937 | + LAppTextureManager::TextureInfo* textureInfo = new LAppTextureManager::TextureInfo(); | |
938 | + textureInfo->fileName = ""; | |
939 | + textureInfo->width = width; | |
940 | + textureInfo->height = height; | |
941 | + textureInfo->id = textureId; | |
942 | + | |
943 | + _textures.PushBack(textureInfo); | |
944 | + | |
945 | + return textureInfo; | |
946 | +} | |
947 | + | |
948 | void LAppTextureManager::ReleaseTextures() | |
949 | { | |
950 | for (Csm::csmUint32 i = 0; i < _textures.GetSize(); i++) | |
951 | diff -pruN --exclude build ./demo_clean/src/LAppTextureManager.hpp ./demo_dev/src/LAppTextureManager.hpp | |
76316970 AIL |
952 | --- ./demo_clean/src/LAppTextureManager.hpp 2021-02-17 01:23:17.000000000 +0000 |
953 | +++ ./demo_dev/src/LAppTextureManager.hpp 2021-04-28 12:18:50.952333251 +0100 | |
830d0ba4 AIL |
954 | @@ -72,6 +72,8 @@ public: |
955 | */ | |
956 | TextureInfo* CreateTextureFromPngFile(std::string fileName); | |
957 | ||
958 | + TextureInfo *CreateTextureFromColor(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha = 255); | |
959 | + | |
960 | /** | |
961 | * @brief 画像の解放 | |
962 | * | |
963 | diff -pruN --exclude build ./demo_clean/src/LAppView.cpp ./demo_dev/src/LAppView.cpp | |
76316970 AIL |
964 | --- ./demo_clean/src/LAppView.cpp 2021-02-17 01:23:17.000000000 +0000 |
965 | +++ ./demo_dev/src/LAppView.cpp 2021-04-28 12:18:50.952333251 +0100 | |
830d0ba4 AIL |
966 | @@ -13,7 +13,6 @@ |
967 | #include "LAppLive2DManager.hpp" | |
968 | #include "LAppTextureManager.hpp" | |
969 | #include "LAppDefine.hpp" | |
970 | -#include "TouchManager.hpp" | |
971 | #include "LAppSprite.hpp" | |
972 | #include "LAppModel.hpp" | |
973 | ||
974 | @@ -26,8 +25,6 @@ using namespace LAppDefine; | |
975 | LAppView::LAppView(): | |
976 | _programId(0), | |
977 | _back(NULL), | |
978 | - _gear(NULL), | |
979 | - _power(NULL), | |
980 | _renderSprite(NULL), | |
981 | _renderTarget(SelectTarget_None) | |
982 | { | |
983 | @@ -35,8 +32,6 @@ LAppView::LAppView(): | |
984 | _clearColor[1] = 1.0f; | |
985 | _clearColor[2] = 1.0f; | |
986 | _clearColor[3] = 0.0f; | |
987 | - // タッチ関係のイベント管理 | |
988 | - _touchManager = new TouchManager(); | |
989 | ||
990 | // デバイス座標からスクリーン座標に変換するための | |
991 | _deviceToScreen = new CubismMatrix44(); | |
992 | @@ -52,10 +47,7 @@ LAppView::~LAppView() | |
993 | ||
994 | delete _viewMatrix; | |
995 | delete _deviceToScreen; | |
996 | - delete _touchManager; | |
997 | delete _back; | |
998 | - delete _gear; | |
999 | - delete _power; | |
1000 | } | |
1001 | ||
1002 | void LAppView::Initialize() | |
76316970 | 1003 | @@ -107,9 +99,6 @@ void LAppView::Initialize() |
830d0ba4 AIL |
1004 | void LAppView::Render() |
1005 | { | |
1006 | _back->Render(); | |
1007 | - _gear->Render(); | |
1008 | - _power->Render(); | |
1009 | - | |
1010 | ||
1011 | LAppLive2DManager* Live2DManager = LAppLive2DManager::GetInstance(); | |
1012 | ||
76316970 | 1013 | @@ -151,35 +140,17 @@ void LAppView::InitializeSprite() |
830d0ba4 AIL |
1014 | glfwGetWindowSize(LAppDelegate::GetInstance()->GetWindow(), &width, &height); |
1015 | ||
1016 | LAppTextureManager* textureManager = LAppDelegate::GetInstance()->GetTextureManager(); | |
1017 | - const string resourcesPath = LAppDelegate::GetInstance()->GetRootDirectory() + ResourcesPath; | |
1018 | ||
1019 | - string imageName = BackImageName; | |
1020 | - LAppTextureManager::TextureInfo* backgroundTexture = textureManager->CreateTextureFromPngFile(resourcesPath + imageName); | |
1021 | + | |
1022 | + LAppTextureManager::TextureInfo* backgroundTexture = | |
1023 | + textureManager->CreateTextureFromColor(0, 255, 0); | |
1024 | ||
1025 | float x = width * 0.5f; | |
1026 | float y = height * 0.5f; | |
1027 | - float fWidth = static_cast<float>(backgroundTexture->width * 2.0f); | |
1028 | - float fHeight = static_cast<float>(height) * 0.95f; | |
1029 | + float fWidth = static_cast<float>(width); | |
1030 | + float fHeight = static_cast<float>(height); | |
1031 | _back = new LAppSprite(x, y, fWidth, fHeight, backgroundTexture->id, _programId); | |
1032 | ||
1033 | - imageName = GearImageName; | |
1034 | - LAppTextureManager::TextureInfo* gearTexture = textureManager->CreateTextureFromPngFile(resourcesPath + imageName); | |
1035 | - | |
1036 | - x = static_cast<float>(width - gearTexture->width * 0.5f); | |
1037 | - y = static_cast<float>(height - gearTexture->height * 0.5f); | |
1038 | - fWidth = static_cast<float>(gearTexture->width); | |
1039 | - fHeight = static_cast<float>(gearTexture->height); | |
1040 | - _gear = new LAppSprite(x, y, fWidth, fHeight, gearTexture->id, _programId); | |
1041 | - | |
1042 | - imageName = PowerImageName; | |
1043 | - LAppTextureManager::TextureInfo* powerTexture = textureManager->CreateTextureFromPngFile(resourcesPath + imageName); | |
1044 | - | |
1045 | - x = static_cast<float>(width - powerTexture->width * 0.5f); | |
1046 | - y = static_cast<float>(powerTexture->height * 0.5f); | |
1047 | - fWidth = static_cast<float>(powerTexture->width); | |
1048 | - fHeight = static_cast<float>(powerTexture->height); | |
1049 | - _power = new LAppSprite(x, y, fWidth, fHeight, powerTexture->id, _programId); | |
1050 | - | |
1051 | // 画面全体を覆うサイズ | |
1052 | x = width * 0.5f; | |
1053 | y = height * 0.5f; | |
76316970 | 1054 | @@ -187,52 +158,6 @@ void LAppView::InitializeSprite() |
830d0ba4 AIL |
1055 | |
1056 | } | |
1057 | ||
1058 | -void LAppView::OnTouchesBegan(float px, float py) const | |
1059 | -{ | |
1060 | - _touchManager->TouchesBegan(px, py); | |
1061 | -} | |
1062 | - | |
1063 | -void LAppView::OnTouchesMoved(float px, float py) const | |
1064 | -{ | |
1065 | - float viewX = this->TransformViewX(_touchManager->GetX()); | |
1066 | - float viewY = this->TransformViewY(_touchManager->GetY()); | |
1067 | - | |
1068 | - _touchManager->TouchesMoved(px, py); | |
1069 | - | |
1070 | - LAppLive2DManager* Live2DManager = LAppLive2DManager::GetInstance(); | |
1071 | - Live2DManager->OnDrag(viewX, viewY); | |
1072 | -} | |
1073 | - | |
1074 | -void LAppView::OnTouchesEnded(float px, float py) const | |
1075 | -{ | |
1076 | - // タッチ終了 | |
1077 | - LAppLive2DManager* live2DManager = LAppLive2DManager::GetInstance(); | |
1078 | - live2DManager->OnDrag(0.0f, 0.0f); | |
1079 | - { | |
1080 | - | |
1081 | - // シングルタップ | |
1082 | - float x = _deviceToScreen->TransformX(_touchManager->GetX()); // 論理座標変換した座標を取得。 | |
1083 | - float y = _deviceToScreen->TransformY(_touchManager->GetY()); // 論理座標変換した座標を取得。 | |
1084 | - if (DebugTouchLogEnable) | |
1085 | - { | |
1086 | - LAppPal::PrintLog("[APP]touchesEnded x:%.2f y:%.2f", x, y); | |
1087 | - } | |
1088 | - live2DManager->OnTap(x, y); | |
1089 | - | |
1090 | - // 歯車にタップしたか | |
1091 | - if (_gear->IsHit(px, py)) | |
1092 | - { | |
1093 | - live2DManager->NextScene(); | |
1094 | - } | |
1095 | - | |
1096 | - // 電源ボタンにタップしたか | |
1097 | - if (_power->IsHit(px, py)) | |
1098 | - { | |
1099 | - LAppDelegate::GetInstance()->AppEnd(); | |
1100 | - } | |
1101 | - } | |
1102 | -} | |
1103 | - | |
1104 | float LAppView::TransformViewX(float deviceX) const | |
1105 | { | |
1106 | float screenX = _deviceToScreen->TransformX(deviceX); // 論理座標変換した座標を取得。 | |
76316970 | 1107 | @@ -374,32 +299,4 @@ void LAppView::ResizeSprite() |
830d0ba4 AIL |
1108 | _back->ResetRect(x, y, fWidth, fHeight); |
1109 | } | |
1110 | } | |
1111 | - | |
1112 | - if (_power) | |
1113 | - { | |
1114 | - GLuint id = _power->GetTextureId(); | |
1115 | - LAppTextureManager::TextureInfo* texInfo = textureManager->GetTextureInfoById(id); | |
1116 | - if (texInfo) | |
1117 | - { | |
1118 | - x = static_cast<float>(width - texInfo->width * 0.5f); | |
1119 | - y = static_cast<float>(texInfo->height * 0.5f); | |
1120 | - fWidth = static_cast<float>(texInfo->width); | |
1121 | - fHeight = static_cast<float>(texInfo->height); | |
1122 | - _power->ResetRect(x, y, fWidth, fHeight); | |
1123 | - } | |
1124 | - } | |
1125 | - | |
1126 | - if (_gear) | |
1127 | - { | |
1128 | - GLuint id = _gear->GetTextureId(); | |
1129 | - LAppTextureManager::TextureInfo* texInfo = textureManager->GetTextureInfoById(id); | |
1130 | - if (texInfo) | |
1131 | - { | |
1132 | - x = static_cast<float>(width - texInfo->width * 0.5f); | |
1133 | - y = static_cast<float>(height - texInfo->height * 0.5f); | |
1134 | - fWidth = static_cast<float>(texInfo->width); | |
1135 | - fHeight = static_cast<float>(texInfo->height); | |
1136 | - _gear->ResetRect(x, y, fWidth, fHeight); | |
1137 | - } | |
1138 | - } | |
1139 | } | |
1140 | diff -pruN --exclude build ./demo_clean/src/LAppView.hpp ./demo_dev/src/LAppView.hpp | |
76316970 AIL |
1141 | --- ./demo_clean/src/LAppView.hpp 2021-02-17 01:23:17.000000000 +0000 |
1142 | +++ ./demo_dev/src/LAppView.hpp 2021-04-28 12:18:50.952333251 +0100 | |
830d0ba4 AIL |
1143 | @@ -14,7 +14,6 @@ |
1144 | #include "CubismFramework.hpp" | |
1145 | #include <Rendering/OpenGL/CubismOffscreenSurface_OpenGLES2.hpp> | |
1146 | ||
1147 | -class TouchManager; | |
1148 | class LAppSprite; | |
1149 | class LAppModel; | |
1150 | ||
1151 | @@ -66,30 +65,6 @@ public: | |
1152 | void ResizeSprite(); | |
1153 | ||
1154 | /** | |
1155 | - * @brief タッチされたときに呼ばれる。 | |
1156 | - * | |
1157 | - * @param[in] pointX スクリーンX座標 | |
1158 | - * @param[in] pointY スクリーンY座標 | |
1159 | - */ | |
1160 | - void OnTouchesBegan(float pointX, float pointY) const; | |
1161 | - | |
1162 | - /** | |
1163 | - * @brief タッチしているときにポインタが動いたら呼ばれる。 | |
1164 | - * | |
1165 | - * @param[in] pointX スクリーンX座標 | |
1166 | - * @param[in] pointY スクリーンY座標 | |
1167 | - */ | |
1168 | - void OnTouchesMoved(float pointX, float pointY) const; | |
1169 | - | |
1170 | - /** | |
1171 | - * @brief タッチが終了したら呼ばれる。 | |
1172 | - * | |
1173 | - * @param[in] pointX スクリーンX座標 | |
1174 | - * @param[in] pointY スクリーンY座標 | |
1175 | - */ | |
1176 | - void OnTouchesEnded(float pointX, float pointY) const; | |
1177 | - | |
1178 | - /** | |
1179 | * @brief X座標をView座標に変換する。 | |
1180 | * | |
1181 | * @param[in] deviceX デバイスX座標 | |
1182 | @@ -147,13 +122,10 @@ public: | |
1183 | void SetRenderTargetClearColor(float r, float g, float b); | |
1184 | ||
1185 | private: | |
1186 | - TouchManager* _touchManager; ///< タッチマネージャー | |
1187 | Csm::CubismMatrix44* _deviceToScreen; ///< デバイスからスクリーンへの行列 | |
1188 | Csm::CubismViewMatrix* _viewMatrix; ///< viewMatrix | |
1189 | GLuint _programId; ///< シェーダID | |
1190 | LAppSprite* _back; ///< 背景画像 | |
1191 | - LAppSprite* _gear; ///< ギア画像 | |
1192 | - LAppSprite* _power; ///< 電源画像 | |
1193 | ||
1194 | // レンダリング先を別ターゲットにする方式の場合に使用 | |
1195 | LAppSprite* _renderSprite; ///< モードによっては_renderBufferのテクスチャを描画 | |
1196 | diff -pruN --exclude build ./demo_clean/src/main.cpp ./demo_dev/src/main.cpp | |
76316970 AIL |
1197 | --- ./demo_clean/src/main.cpp 2021-02-17 01:23:17.000000000 +0000 |
1198 | +++ ./demo_dev/src/main.cpp 2021-04-28 12:28:55.845339613 +0100 | |
2c3e79c6 | 1199 | @@ -5,18 +5,188 @@ |
830d0ba4 AIL |
1200 | * that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html. |
1201 | */ | |
1202 | ||
1203 | +#include <thread> | |
1204 | +#include <stdexcept> | |
1205 | +#include <sstream> | |
eba2eb3a AIL |
1206 | +#include <vector> |
1207 | +#include <utility> | |
1208 | +#include <string> | |
830d0ba4 AIL |
1209 | + |
1210 | +#ifdef __cpp_lib_filesystem | |
1211 | +#include <filesystem> | |
1212 | +namespace fs = std::filesystem; | |
1213 | +#else | |
1214 | +#include <experimental/filesystem> | |
1215 | +namespace fs = std::experimental::filesystem; | |
1216 | +#endif | |
1217 | + | |
eba2eb3a | 1218 | +#include "ICubismModelSetting.hpp" |
830d0ba4 AIL |
1219 | #include "LAppDelegate.hpp" |
1220 | +#include "LAppLive2DManager.hpp" | |
eba2eb3a | 1221 | +#include "LAppModel.hpp" |
126d8fa4 | 1222 | +#include "mouse_cursor_tracker.h" |
830d0ba4 AIL |
1223 | + |
1224 | +struct CmdArgs | |
1225 | +{ | |
1226 | + int windowWidth; | |
1227 | + int windowHeight; | |
1228 | + std::string windowTitle; | |
1229 | + std::string rootDir; | |
1230 | + float scaleFactor; | |
1231 | + float translateX; | |
1232 | + float translateY; | |
1233 | + std::string modelName; | |
2c3e79c6 | 1234 | + bool oldId; // If true, translate new (Cubism 3+) parameter IDs to old (Cubism 2.1) IDs |
126d8fa4 | 1235 | + std::string cfgPath; // Path to config file for MouseCursorTracker |
830d0ba4 AIL |
1236 | +}; |
1237 | + | |
1238 | +CmdArgs parseArgv(int argc, char *argv[]) | |
1239 | +{ | |
1240 | + // I think the command-line args are simple enough to not justify using a library... | |
1241 | + CmdArgs cmdArgs; | |
1242 | + // Set default values | |
1243 | + cmdArgs.windowWidth = 600; | |
1244 | + cmdArgs.windowHeight = 600; | |
126d8fa4 | 1245 | + cmdArgs.windowTitle = "MouseTrackerForCubism example"; |
830d0ba4 | 1246 | + cmdArgs.rootDir = fs::current_path(); |
76316970 | 1247 | + cmdArgs.scaleFactor = 4.5f; |
830d0ba4 | 1248 | + cmdArgs.translateX = 0.0f; |
76316970 | 1249 | + cmdArgs.translateY = -3.1f; |
830d0ba4 | 1250 | + cmdArgs.modelName = "Haru"; |
2c3e79c6 | 1251 | + cmdArgs.oldId = false; |
830d0ba4 AIL |
1252 | + cmdArgs.cfgPath = ""; |
1253 | + | |
1254 | + int i = 1; | |
1255 | + while (i < argc) | |
1256 | + { | |
1257 | + std::string arg = argv[i]; | |
1258 | + std::stringstream ss; | |
1259 | + | |
1260 | + if (arg == "--window-width" || arg == "-W") // capital W for consistency with height | |
1261 | + { | |
1262 | + ss << argv[i + 1]; | |
1263 | + if (!(ss >> cmdArgs.windowWidth)) | |
1264 | + { | |
1265 | + throw std::runtime_error("Invalid argument for window width"); | |
1266 | + } | |
1267 | + } | |
1268 | + else if (arg == "--window-height" || arg == "-H") // avoiding "-h", typically for help | |
1269 | + { | |
1270 | + ss << argv[i + 1]; | |
1271 | + if (!(ss >> cmdArgs.windowHeight)) | |
1272 | + { | |
1273 | + throw std::runtime_error("Invalid argument for window height"); | |
1274 | + } | |
1275 | + } | |
1276 | + else if (arg == "--window-title" || arg == "-t") | |
1277 | + { | |
1278 | + cmdArgs.windowTitle = argv[i + 1]; | |
1279 | + } | |
1280 | + else if (arg == "--root-dir" || arg == "-d") | |
1281 | + { | |
1282 | + cmdArgs.rootDir = argv[i + 1]; | |
1283 | + } | |
1284 | + else if (arg == "--scale-factor" || arg == "-f") | |
1285 | + { | |
1286 | + ss << argv[i + 1]; | |
1287 | + if (!(ss >> cmdArgs.scaleFactor)) | |
1288 | + { | |
1289 | + throw std::runtime_error("Invalid argument for scale factor"); | |
1290 | + } | |
1291 | + } | |
1292 | + else if (arg == "--translate-x" || arg == "-x") | |
1293 | + { | |
1294 | + ss << argv[i + 1]; | |
1295 | + if (!(ss >> cmdArgs.translateX)) | |
1296 | + { | |
1297 | + throw std::runtime_error("Invalid argument for translate X"); | |
1298 | + } | |
1299 | + } | |
1300 | + else if (arg == "--translate-y" || arg == "-y") | |
1301 | + { | |
1302 | + ss << argv[i + 1]; | |
1303 | + if (!(ss >> cmdArgs.translateY)) | |
1304 | + { | |
1305 | + throw std::runtime_error("Invalid argument for translate Y"); | |
1306 | + } | |
1307 | + } | |
1308 | + else if (arg == "--model" || arg == "-m") | |
1309 | + { | |
1310 | + cmdArgs.modelName = argv[i + 1]; | |
1311 | + } | |
1312 | + else if (arg == "--config" || arg == "-c") | |
1313 | + { | |
1314 | + cmdArgs.cfgPath = argv[i + 1]; | |
1315 | + } | |
2c3e79c6 AIL |
1316 | + else if (arg == "--old-param-id" || arg == "-o") |
1317 | + { | |
1318 | + cmdArgs.oldId = (argv[i + 1][0] == '1'); | |
1319 | + } | |
830d0ba4 AIL |
1320 | + else |
1321 | + { | |
1322 | + throw std::runtime_error("Unrecognized argument: " + arg); | |
1323 | + } | |
1324 | + | |
1325 | + i += 2; | |
1326 | + } | |
1327 | + | |
1328 | + return cmdArgs; | |
1329 | +} | |
1330 | ||
1331 | int main(int argc, char* argv[]) | |
1332 | { | |
1333 | - // create the application instance | |
1334 | - if (LAppDelegate::GetInstance()->Initialize() == GL_FALSE) | |
1335 | + auto cmdArgs = parseArgv(argc, argv); | |
1336 | + | |
1337 | + LAppDelegate *delegate = LAppDelegate::GetInstance(); | |
1338 | + | |
1339 | + if (!delegate->Initialize(cmdArgs.windowWidth, | |
1340 | + cmdArgs.windowHeight, | |
1341 | + cmdArgs.windowTitle.c_str())) | |
1342 | { | |
1343 | - return 1; | |
1344 | + throw std::runtime_error("Unable to initialize LAppDelegate"); | |
1345 | } | |
1346 | ||
1347 | - LAppDelegate::GetInstance()->Run(); | |
1348 | + delegate->SetRootDirectory(cmdArgs.rootDir); | |
1349 | + | |
830d0ba4 | 1350 | + LAppLive2DManager *manager = LAppLive2DManager::GetInstance(); |
2c3e79c6 | 1351 | + manager->SetModel(cmdArgs.modelName, cmdArgs.oldId); |
830d0ba4 AIL |
1352 | + |
1353 | + manager->SetProjectionScaleTranslate(cmdArgs.scaleFactor, | |
1354 | + cmdArgs.translateX, | |
1355 | + cmdArgs.translateY); | |
eba2eb3a AIL |
1356 | + |
1357 | + LAppModel *model = manager->GetModel(0); | |
1358 | + if (!model) throw std::runtime_error("model is null"); | |
1359 | + | |
1360 | + Live2D::Cubism::Framework::ICubismModelSetting *modelSetting = model->GetModelSetting(); | |
1361 | + if (!modelSetting) throw std::runtime_error("modelSetting is null"); | |
1362 | + | |
1363 | + std::vector<std::pair<std::string, int> > motions; | |
1364 | + int motionGroupCount = modelSetting->GetMotionGroupCount(); | |
1365 | + for (int i = 0; i < motionGroupCount; i++) | |
1366 | + { | |
1367 | + const char *motionGroup = modelSetting->GetMotionGroupName(i); | |
1368 | + int motionCount = modelSetting->GetMotionCount(motionGroup); | |
1369 | + motions.push_back(std::make_pair(std::string(motionGroup), motionCount)); | |
1370 | + } | |
1371 | + | |
1372 | + std::vector<std::string> expressions; | |
1373 | + int expCount = modelSetting->GetExpressionCount(); | |
1374 | + for (int i = 0; i < expCount; i++) | |
1375 | + { | |
1376 | + const char *expName = modelSetting->GetExpressionName(i); | |
1377 | + expressions.push_back(std::string(expName)); | |
1378 | + } | |
1379 | + | |
1380 | + MouseCursorTracker tracker(cmdArgs.cfgPath, motions, expressions); | |
1381 | + | |
1382 | + std::thread trackerThread(&MouseCursorTracker::mainLoop, &tracker); | |
126d8fa4 | 1383 | + manager->SetTracker(&tracker); |
830d0ba4 AIL |
1384 | + |
1385 | + delegate->Run(); | |
1386 | + | |
126d8fa4 AIL |
1387 | + tracker.stop(); |
1388 | + trackerThread.join(); | |
830d0ba4 AIL |
1389 | |
1390 | return 0; | |
1391 | } | |
1392 | - |