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