Upgrade to Cubism 5 Release R1.
[facial-landmarks-for-cubism.git] / example / demo_win.patch
CommitLineData
6d2cd78f 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:28:27.492813451 +0100
6d2cd78f
AL
4@@ -9,7 +9,7 @@ option(
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)
6d2cd78f
AL
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@@ -41,7 +41,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 11)
18+set(CMAKE_CXX_STANDARD 17)
19 set(CMAKE_CXX_STANDARD_REQUIRED ON)
20 set(CMAKE_CXX_EXTENSIONS OFF)
21
22@@ -113,6 +113,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@@ -122,12 +125,14 @@ target_link_libraries(${APP_NAME}
33 Framework
34 glfw
35 ${OPENGL_LIBRARIES}
36+ FacialLandmarksForCubism
37+ ws2_32
38 # Solve the MSVCRT confliction.
39 debug -NODEFAULTLIB:libcmtd.lib
40 optimized -NODEFAULTLIB:libcmt.lib
41 )
42 # Specify include directories.
43-target_include_directories(${APP_NAME} PRIVATE ${STB_PATH})
44+target_include_directories(${APP_NAME} PRIVATE ${STB_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/../../include)
45 # Build in multi-process.
46 target_compile_options(${APP_NAME} PRIVATE /MP)
47
48diff -pruN --exclude build ./demo_clean/src/CMakeLists.txt ./demo_dev/src/CMakeLists.txt
6fd3638f
AIL
49--- ./demo_clean/src/CMakeLists.txt 2023-05-18 09:58:50.000000000 +0100
50+++ ./demo_dev/src/CMakeLists.txt 2023-05-28 08:28:27.492813451 +0100
6d2cd78f
AL
51@@ -1,49 +1,22 @@
52-if (CSM_MINIMUM_DEMO)
53- target_sources(${APP_NAME}
54+target_sources(${APP_NAME}
55 PRIVATE
56 ${CMAKE_CURRENT_SOURCE_DIR}/LAppAllocator.cpp
57 ${CMAKE_CURRENT_SOURCE_DIR}/LAppAllocator.hpp
58 ${CMAKE_CURRENT_SOURCE_DIR}/LAppDefine.cpp
59 ${CMAKE_CURRENT_SOURCE_DIR}/LAppDefine.hpp
60+ ${CMAKE_CURRENT_SOURCE_DIR}/LAppDelegate.cpp
61+ ${CMAKE_CURRENT_SOURCE_DIR}/LAppDelegate.hpp
62+ ${CMAKE_CURRENT_SOURCE_DIR}/LAppLive2DManager.cpp
63+ ${CMAKE_CURRENT_SOURCE_DIR}/LAppLive2DManager.hpp
64+ ${CMAKE_CURRENT_SOURCE_DIR}/LAppModel.cpp
65+ ${CMAKE_CURRENT_SOURCE_DIR}/LAppModel.hpp
66 ${CMAKE_CURRENT_SOURCE_DIR}/LAppPal.cpp
67 ${CMAKE_CURRENT_SOURCE_DIR}/LAppPal.hpp
68+ ${CMAKE_CURRENT_SOURCE_DIR}/LAppSprite.cpp
69+ ${CMAKE_CURRENT_SOURCE_DIR}/LAppSprite.hpp
70 ${CMAKE_CURRENT_SOURCE_DIR}/LAppTextureManager.cpp
71 ${CMAKE_CURRENT_SOURCE_DIR}/LAppTextureManager.hpp
72- ${CMAKE_CURRENT_SOURCE_DIR}/mainMinimum.cpp
73- ${CMAKE_CURRENT_SOURCE_DIR}/TouchManager.cpp
74- ${CMAKE_CURRENT_SOURCE_DIR}/TouchManager.hpp
75- ${CMAKE_CURRENT_SOURCE_DIR}/CubismUserModelExtend.cpp
76- ${CMAKE_CURRENT_SOURCE_DIR}/CubismUserModelExtend.hpp
77- ${CMAKE_CURRENT_SOURCE_DIR}/CubismSampleViewMatrix.cpp
78- ${CMAKE_CURRENT_SOURCE_DIR}/CubismSampleViewMatrix.hpp
79- ${CMAKE_CURRENT_SOURCE_DIR}/MouseActionManager.cpp
80- ${CMAKE_CURRENT_SOURCE_DIR}/MouseActionManager.hpp
81- )
82-else ()
83- target_sources(${APP_NAME}
84- PRIVATE
85- ${CMAKE_CURRENT_SOURCE_DIR}/LAppAllocator.cpp
86- ${CMAKE_CURRENT_SOURCE_DIR}/LAppAllocator.hpp
87- ${CMAKE_CURRENT_SOURCE_DIR}/LAppDefine.cpp
88- ${CMAKE_CURRENT_SOURCE_DIR}/LAppDefine.hpp
89- ${CMAKE_CURRENT_SOURCE_DIR}/LAppDelegate.cpp
90- ${CMAKE_CURRENT_SOURCE_DIR}/LAppDelegate.hpp
91- ${CMAKE_CURRENT_SOURCE_DIR}/LAppWavFileHandler.cpp
92- ${CMAKE_CURRENT_SOURCE_DIR}/LAppWavFileHandler.hpp
93- ${CMAKE_CURRENT_SOURCE_DIR}/LAppLive2DManager.cpp
94- ${CMAKE_CURRENT_SOURCE_DIR}/LAppLive2DManager.hpp
95- ${CMAKE_CURRENT_SOURCE_DIR}/LAppModel.cpp
96- ${CMAKE_CURRENT_SOURCE_DIR}/LAppModel.hpp
97- ${CMAKE_CURRENT_SOURCE_DIR}/LAppPal.cpp
98- ${CMAKE_CURRENT_SOURCE_DIR}/LAppPal.hpp
99- ${CMAKE_CURRENT_SOURCE_DIR}/LAppSprite.cpp
100- ${CMAKE_CURRENT_SOURCE_DIR}/LAppSprite.hpp
101- ${CMAKE_CURRENT_SOURCE_DIR}/LAppTextureManager.cpp
102- ${CMAKE_CURRENT_SOURCE_DIR}/LAppTextureManager.hpp
103- ${CMAKE_CURRENT_SOURCE_DIR}/LAppView.cpp
104- ${CMAKE_CURRENT_SOURCE_DIR}/LAppView.hpp
105- ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp
106- ${CMAKE_CURRENT_SOURCE_DIR}/TouchManager.cpp
107- ${CMAKE_CURRENT_SOURCE_DIR}/TouchManager.hpp
108- )
109-endif ()
110+ ${CMAKE_CURRENT_SOURCE_DIR}/LAppView.cpp
111+ ${CMAKE_CURRENT_SOURCE_DIR}/LAppView.hpp
112+ ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp
113+)
114diff -pruN --exclude build ./demo_clean/src/CubismUserModelExtend.cpp ./demo_dev/src/CubismUserModelExtend.cpp
6fd3638f
AIL
115--- ./demo_clean/src/CubismUserModelExtend.cpp 2023-05-18 09:58:50.000000000 +0100
116+++ ./demo_dev/src/CubismUserModelExtend.cpp 2023-05-28 08:28:27.492813451 +0100
6d2cd78f
AL
117@@ -1,4 +1,4 @@
118-/**
119+/**
120 * Copyright(c) Live2D Inc. All rights reserved.
121 *
122 * Use of this source code is governed by the Live2D Open Software license
123@@ -23,7 +23,7 @@
124 #include "CubismUserModelExtend.hpp"
125
126 using namespace Live2D::Cubism::Framework;
127-using namespace Live2D::Cubism::Framework::DefaultParameterId;
128+using namespace DefaultParameterId;
129 using namespace LAppDefine;
130
131 namespace {
132@@ -74,34 +74,17 @@ CubismUserModelExtend::~CubismUserModelE
133 delete _textureManager;
134 }
135
136-std::string CubismUserModelExtend::MakeAssetPath(const std::string& assetFileName)
137-{
138- return _currentModelDirectory + assetFileName;
139-}
140-
141-void CubismUserModelExtend::SetAssetDirectory(const std::string& path)
142-{
143- _currentModelDirectory = path;
144-}
145-
146-void CubismUserModelExtend::LoadAsset(const std::string & fiileName, const std::function<void(Csm::csmByte*, Csm::csmSizeInt)>& afterLoadCallback)
147+void CubismUserModelExtend::LoadAssets(const Csm::csmChar* fileName)
148 {
149- Csm::csmSizeInt bufferSize = 0;
150- Csm::csmByte* buffer = nullptr;
151-
152- if (fiileName.empty())
153- {
154- return;
155- }
156-
157- // バッファの設定
158- buffer = LAppPal::LoadFileAsBytes(MakeAssetPath(fiileName).c_str(), &bufferSize);
159+ csmSizeInt size;
160+ const csmString path = csmString(_currentModelDirectory.c_str()) + fileName;
161
162- // コールバック関数の呼び出し
163- afterLoadCallback(buffer, bufferSize);
164+ csmByte* buffer = CreateBuffer(path.GetRawString(), &size);
165+ _modelJson = new CubismModelSettingJson(buffer, size);
166+ DeleteBuffer(buffer, path.GetRawString());
167
168- // バッファの解放
169- LAppPal::ReleaseBytes(buffer);
170+ // モデルの生成
171+ SetupModel();
172 }
173
174 void CubismUserModelExtend::SetupModel()
175@@ -109,40 +92,75 @@ void CubismUserModelExtend::SetupModel()
176 _updating = true;
177 _initialized = false;
178
179- // モデルの設定データをJsonファイルから読み込み
180- LoadAsset(_modelDirName + ".model3.json", [=](Csm::csmByte* buffer, Csm::csmSizeInt bufferSize) { _modelJson = new Csm::CubismModelSettingJson(buffer, bufferSize); });
181- // モデルの設定データからモデルデータを読み込み
182- LoadAsset(_modelJson->GetModelFileName(), [=](Csm::csmByte* buffer, Csm::csmSizeInt bufferSize) { LoadModel(buffer, bufferSize); });
183+ csmByte* buffer;
184+ csmSizeInt size;
185+
186+ //Cubism Model
187+ if (strcmp(_modelJson->GetModelFileName(), ""))
188+ {
189+ csmString path = _modelJson->GetModelFileName();
190+ path = csmString(_currentModelDirectory.c_str()) + path;
191+
192+ buffer = CreateBuffer(path.GetRawString(), &size);
193+ LoadModel(buffer, size);
194+ DeleteBuffer(buffer, path.GetRawString());
195+ }
196
197 // 表情データの読み込み
198- for (auto expressionIndex = 0; expressionIndex < _modelJson->GetExpressionCount(); ++expressionIndex)
199+ if (_modelJson->GetExpressionCount() > 0)
200 {
201- LoadAsset(_modelJson->GetExpressionFileName(expressionIndex), [=](Csm::csmByte* buffer, Csm::csmSizeInt bufferSize) {
202- auto expressionName = _modelJson->GetExpressionName(expressionIndex);
203- ACubismMotion* motion = LoadExpression(buffer, bufferSize, expressionName);
204- if (_expressions[expressionName])
205+ const csmInt32 count = _modelJson->GetExpressionCount();
206+ for (csmInt32 i = 0; i < count; i++)
207+ {
208+ csmString name = _modelJson->GetExpressionName(i);
209+ csmString path = _modelJson->GetExpressionFileName(i);
210+ path = csmString(_currentModelDirectory.c_str()) + path;
211+
212+ buffer = CreateBuffer(path.GetRawString(), &size);
213+ ACubismMotion* motion = LoadExpression(buffer, size, name.GetRawString());
214+
215+ if (_expressions[name])
216 {
217- ACubismMotion::Delete(_expressions[expressionName]);
218- _expressions[expressionName] = nullptr;
219+ ACubismMotion::Delete(_expressions[name]);
220+ _expressions[name] = nullptr;
221 }
222- _expressions[expressionName] = motion;
223- });
224+ _expressions[name] = motion;
225+
226+ DeleteBuffer(buffer, path.GetRawString());
227+ }
228 }
229
230 //ポーズデータの読み込み
231- LoadAsset(_modelJson->GetPoseFileName(), [=](Csm::csmByte* buffer, Csm::csmSizeInt bufferSize) {
232- LoadPose(buffer, bufferSize);
233- });
234+ if (strcmp(_modelJson->GetPoseFileName(), ""))
235+ {
236+ csmString path = _modelJson->GetPoseFileName();
237+ path = csmString(_currentModelDirectory.c_str()) + path;
238+
239+ buffer = CreateBuffer(path.GetRawString(), &size);
240+ LoadPose(buffer, size);
241+ DeleteBuffer(buffer, path.GetRawString());
242+ }
243
244 // 物理演算データの読み込み
245- LoadAsset(_modelJson->GetPhysicsFileName(), [=](Csm::csmByte* buffer, Csm::csmSizeInt bufferSize) {
246- LoadPhysics(buffer, bufferSize);
247- });
248+ if (strcmp(_modelJson->GetPhysicsFileName(), ""))
249+ {
250+ csmString path = _modelJson->GetPhysicsFileName();
251+ path = csmString(_currentModelDirectory.c_str()) + path;
252+
253+ buffer = CreateBuffer(path.GetRawString(), &size);
254+ LoadPhysics(buffer, size);
255+ DeleteBuffer(buffer, path.GetRawString());
256+ }
257
258 // モデルに付属するユーザーデータの読み込み
259- LoadAsset(_modelJson->GetUserDataFile(), [=](Csm::csmByte* buffer, Csm::csmSizeInt bufferSize) {
260- LoadUserData(buffer, bufferSize);
261- });
262+ if (strcmp(_modelJson->GetUserDataFile(), ""))
263+ {
264+ csmString path = _modelJson->GetUserDataFile();
265+ path = csmString(_currentModelDirectory.c_str()) + path;
266+ buffer = CreateBuffer(path.GetRawString(), &size);
267+ LoadUserData(buffer, size);
268+ DeleteBuffer(buffer, path.GetRawString());
269+ }
270
271 // Layout
272 csmMap<csmString, csmFloat32> layout;
273@@ -345,16 +363,6 @@ void CubismUserModelExtend::ModelParamUp
274 _model->SaveParameters();
275 //-----------------------------------------------------------------
276
277- // メインモーションの更新がないとき
278- if (!motionUpdated)
279- {
280- if (_eyeBlink)
281- {
282- // まばたき
283- _eyeBlink->UpdateParameters(_model, deltaTimeSeconds);
284- }
285- }
286-
287 if (_expressionManager)
288 {
289 // 表情でパラメータ更新(相対変化)
290@@ -377,12 +385,6 @@ void CubismUserModelExtend::ModelParamUp
291 _model->AddParameterValue(_idParamEyeBallX, _dragX); // -1から1の値を加える
292 _model->AddParameterValue(_idParamEyeBallY, _dragY);
293
294- // 呼吸など
295- if (_breath)
296- {
297- _breath->UpdateParameters(_model, deltaTimeSeconds);
298- }
299-
300 // 物理演算の設定
301 if (_physics)
302 {
303diff -pruN --exclude build ./demo_clean/src/CubismUserModelExtend.hpp ./demo_dev/src/CubismUserModelExtend.hpp
6fd3638f
AIL
304--- ./demo_clean/src/CubismUserModelExtend.hpp 2023-05-18 09:58:50.000000000 +0100
305+++ ./demo_dev/src/CubismUserModelExtend.hpp 2023-05-28 08:28:27.492813451 +0100
6d2cd78f
AL
306@@ -27,17 +27,13 @@ class CubismUserModelExtend :
307 {
308 public:
309 CubismUserModelExtend(const std::string modelDirectoryName, const std::string _currentModelDirectory); ///< コンストラクタ
310- virtual ~CubismUserModelExtend(); ///< デストラクタ
311+ ~CubismUserModelExtend(); ///< デストラクタ
312
313 /**
314- * @brief model3.jsonからモデルを生成する
315- *
316- * model3.jsonの記述に従ってモデル生成、モーション、物理演算などのコンポーネント生成を行う
317- *
318- * @param[in] setting ICubismModelSettingのインスタンス
319+ * @brief model3.jsonが置かれたディレクトリとファイルパスからモデルを生成する
320 *
321 */
322- void SetupModel();
323+ void LoadAssets(const Csm::csmChar* fileName);
324
325 /**
326 * @brief モデルの更新
327@@ -48,35 +44,24 @@ public:
328
329 private:
330 /**
331- * @brief パスを作成
332+ * @brief model3.jsonからモデルを生成する
333 *
334- * アセットのパスを作成する
335- */
336- std::string MakeAssetPath(const std::string & assetFileName);
337-
338- /**
339- * @brief ディレクトリパスの設定
340+ * model3.jsonの記述に従ってモデル生成、モーション、物理演算などのコンポーネント生成を行う
341+ *
342+ * @param[in] setting ICubismModelSettingのインスタンス
343 *
344- * モデルのディレクトリパスを設定する
345 */
346- void SetAssetDirectory(const std::string & path);
347+ void SetupModel();
348
349 /**
350- * @brief アセットのロードを行う
351+ * @brief 引数で指定したモーションの再生を開始する
352 *
353- * 指定されたファイル名からアセットのロードを行う
354+ * @param[in] group モーショングループ名
355+ * @param[in] no グループ内の番号
356+ * @param[in] priority 優先度
357+ * @param[in] onFinishedMotionHandler モーション再生終了時に呼び出されるコールバック関数。NULLの場合、呼び出されない。
358+ * @return 開始したモーションの識別番号を返す。個別のモーションが終了したか否かを判定するIsFinished()の引数で使用する。開始できない時は「-1」
359 */
360- void LoadAsset(const std::string & fiileName, const std::function<void(Csm::csmByte*, Csm::csmSizeInt)>& afterLoadCallback);
361-
362- /**
363- * @brief 引数で指定したモーションの再生を開始する
364- *
365- * @param[in] group モーショングループ名
366- * @param[in] no グループ内の番号
367- * @param[in] priority 優先度
368- * @param[in] onFinishedMotionHandler モーション再生終了時に呼び出されるコールバック関数。NULLの場合、呼び出されない。
369- * @return 開始したモーションの識別番号を返す。個別のモーションが終了したか否かを判定するIsFinished()の引数で使用する。開始できない時は「-1」
370- */
371 Csm::CubismMotionQueueEntryHandle StartMotion(const Csm::csmChar* group, Csm::csmInt32 no, Csm::csmInt32 priority, Csm::ACubismMotion::FinishedMotionCallback onFinishedMotionHandler = NULL);
372
373 /**
374diff -pruN --exclude build ./demo_clean/src/LAppAllocator.cpp ./demo_dev/src/LAppAllocator.cpp
6fd3638f
AIL
375--- ./demo_clean/src/LAppAllocator.cpp 2023-05-18 09:58:50.000000000 +0100
376+++ ./demo_dev/src/LAppAllocator.cpp 2023-05-28 08:28:27.492813451 +0100
6d2cd78f
AL
377@@ -1,4 +1,4 @@
378-/**
379+/**
380 * Copyright(c) Live2D Inc. All rights reserved.
381 *
382 * Use of this source code is governed by the Live2D Open Software license
383@@ -9,7 +9,7 @@
384
385 using namespace Csm;
386
387-void* LAppAllocator::Allocate(const csmSizeType size)
388+void* LAppAllocator::Allocate(const csmSizeType size)
389 {
390 return malloc(size);
391 }
392diff -pruN --exclude build ./demo_clean/src/LAppAllocator.hpp ./demo_dev/src/LAppAllocator.hpp
6fd3638f
AIL
393--- ./demo_clean/src/LAppAllocator.hpp 2023-05-18 09:58:50.000000000 +0100
394+++ ./demo_dev/src/LAppAllocator.hpp 2023-05-28 08:28:27.492813451 +0100
6d2cd78f
AL
395@@ -1,4 +1,4 @@
396-/**
397+/**
398 * Copyright(c) Live2D Inc. All rights reserved.
399 *
400 * Use of this source code is governed by the Live2D Open Software license
401diff -pruN --exclude build ./demo_clean/src/LAppDefine.cpp ./demo_dev/src/LAppDefine.cpp
6fd3638f
AIL
402--- ./demo_clean/src/LAppDefine.cpp 2023-05-18 09:58:50.000000000 +0100
403+++ ./demo_dev/src/LAppDefine.cpp 2023-05-28 08:28:27.496813523 +0100
6d2cd78f
AL
404@@ -1,4 +1,4 @@
405-/**
406+/**
407 * Copyright(c) Live2D Inc. All rights reserved.
408 *
409 * Use of this source code is governed by the Live2D Open Software license
410@@ -20,7 +20,7 @@ namespace LAppDefine {
411 const csmFloat32 ViewLogicalLeft = -1.0f;
412 const csmFloat32 ViewLogicalRight = 1.0f;
413 const csmFloat32 ViewLogicalBottom = -1.0f;
414- const csmFloat32 ViewLogicalTop = -1.0f;
415+ const csmFloat32 ViewLogicalTop = 1.0f;
416
417 const csmFloat32 ViewLogicalMaxLeft = -2.0f;
418 const csmFloat32 ViewLogicalMaxRight = 2.0f;
419diff -pruN --exclude build ./demo_clean/src/LAppDefine.hpp ./demo_dev/src/LAppDefine.hpp
6fd3638f
AIL
420--- ./demo_clean/src/LAppDefine.hpp 2023-05-18 09:58:50.000000000 +0100
421+++ ./demo_dev/src/LAppDefine.hpp 2023-05-28 08:28:27.496813523 +0100
6d2cd78f
AL
422@@ -1,9 +1,10 @@
423-/**
424+/**
425 * Copyright(c) Live2D Inc. All rights reserved.
426 *
427 * Use of this source code is governed by the Live2D Open Software license
428 * that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html.
429 */
430+
431 #pragma once
432
433 #include <CubismFramework.hpp>
434diff -pruN --exclude build ./demo_clean/src/LAppDelegate.cpp ./demo_dev/src/LAppDelegate.cpp
6fd3638f
AIL
435--- ./demo_clean/src/LAppDelegate.cpp 2023-05-18 09:58:50.000000000 +0100
436+++ ./demo_dev/src/LAppDelegate.cpp 2023-05-28 08:28:27.496813523 +0100
6d2cd78f
AL
437@@ -1,4 +1,4 @@
438-/**
439+/**
440 * Copyright(c) Live2D Inc. All rights reserved.
441 *
442 * Use of this source code is governed by the Live2D Open Software license
443@@ -7,6 +7,7 @@
444
445 #include "LAppDelegate.hpp"
446 #include <iostream>
447+#include <sstream>
448 #include <GL/glew.h>
449 #include <GLFW/glfw3.h>
450 #include "LAppView.hpp"
451@@ -43,7 +44,8 @@ void LAppDelegate::ReleaseInstance()
452 s_instance = NULL;
453 }
454
455-bool LAppDelegate::Initialize()
456+bool LAppDelegate::Initialize(int initWindowWidth, int initWindowHeight,
457+ const char *windowTitle)
458 {
459 if (DebugLogEnable)
460 {
461@@ -61,7 +63,13 @@ bool LAppDelegate::Initialize()
462 }
463
464 // Windowの生成_
465- _window = glfwCreateWindow(RenderTargetWidth, RenderTargetHeight, "SAMPLE", NULL, NULL);
466+ _window = glfwCreateWindow(
467+ initWindowWidth ? initWindowWidth : RenderTargetWidth,
468+ initWindowHeight ? initWindowHeight : RenderTargetHeight,
469+ windowTitle ? windowTitle : "SAMPLE",
470+ NULL,
471+ NULL);
472+
473 if (_window == NULL)
474 {
475 if (DebugLogEnable)
476@@ -93,10 +101,6 @@ bool LAppDelegate::Initialize()
477 glEnable(GL_BLEND);
478 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
479
480- //コールバック関数の登録
481- glfwSetMouseButtonCallback(_window, EventHandler::OnMouseCallBack);
482- glfwSetCursorPosCallback(_window, EventHandler::OnMouseCallBack);
483-
484 // ウィンドウサイズ記憶
485 int width, height;
486 glfwGetWindowSize(LAppDelegate::GetInstance()->GetWindow(), &width, &height);
487@@ -106,9 +110,15 @@ bool LAppDelegate::Initialize()
488 //AppViewの初期化
489 _view->Initialize();
490
491- // Cubism SDK の初期化
492+ // Cubism3の初期化
493 InitializeCubism();
494
495+ //load model
496+ LAppLive2DManager::GetInstance();
497+
498+ //load sprite
499+ _view->InitializeSprite();
500+
501 return GL_TRUE;
502 }
503
504@@ -125,7 +135,7 @@ void LAppDelegate::Release()
505 // リソースを解放
506 LAppLive2DManager::ReleaseInstance();
507
508- //Cubism SDK の解放
509+ //Cubism3の解放
510 CubismFramework::Dispose();
511 }
512
513@@ -136,18 +146,13 @@ void LAppDelegate::Run()
514 {
515 int width, height;
516 glfwGetWindowSize(LAppDelegate::GetInstance()->GetWindow(), &width, &height);
517- if( (_windowWidth!=width || _windowHeight!=height) && width>0 && height>0)
518+ if((_windowWidth!=width || _windowHeight!=height) && width>0 && height>0)
519 {
520- //AppViewの初期化
521 _view->Initialize();
522- // スプライトサイズを再設定
523 _view->ResizeSprite();
524- // サイズを保存しておく
525+
526 _windowWidth = width;
527 _windowHeight = height;
528-
529- // ビューポート変更
530- glViewport(0, 0, width, height);
531 }
532
533 // 時間更新
534@@ -183,6 +188,7 @@ LAppDelegate::LAppDelegate():
535 _windowWidth(0),
536 _windowHeight(0)
537 {
538+ _rootDirectory = "";
539 _view = new LAppView();
540 _textureManager = new LAppTextureManager();
541 }
542@@ -202,58 +208,10 @@ void LAppDelegate::InitializeCubism()
543 //Initialize cubism
544 CubismFramework::Initialize();
545
546- //load model
547- LAppLive2DManager::GetInstance();
548-
549 //default proj
550 CubismMatrix44 projection;
551
552 LAppPal::UpdateTime();
553-
554- _view->InitializeSprite();
555-}
556-
557-void LAppDelegate::OnMouseCallBack(GLFWwindow* window, int button, int action, int modify)
558-{
559- if (_view == NULL)
560- {
561- return;
562- }
563- if (GLFW_MOUSE_BUTTON_LEFT != button)
564- {
565- return;
566- }
567-
568- if (GLFW_PRESS == action)
569- {
570- _captured = true;
571- _view->OnTouchesBegan(_mouseX, _mouseY);
572- }
573- else if (GLFW_RELEASE == action)
574- {
575- if (_captured)
576- {
577- _captured = false;
578- _view->OnTouchesEnded(_mouseX, _mouseY);
579- }
580- }
581-}
582-
583-void LAppDelegate::OnMouseCallBack(GLFWwindow* window, double x, double y)
584-{
585- _mouseX = static_cast<float>(x);
586- _mouseY = static_cast<float>(y);
587-
588- if (!_captured)
589- {
590- return;
591- }
592- if (_view == NULL)
593- {
594- return;
595- }
596-
597- _view->OnTouchesMoved(_mouseX, _mouseY);
598 }
599
600 GLuint LAppDelegate::CreateShader()
601@@ -271,10 +229,6 @@ GLuint LAppDelegate::CreateShader()
602 "}";
603 glShaderSource(vertexShaderId, 1, &vertexShader, NULL);
604 glCompileShader(vertexShaderId);
605- if(!CheckShader(vertexShaderId))
606- {
607- return 0;
608- }
609
610 //フラグメントシェーダのコンパイル
611 GLuint fragmentShaderId = glCreateShader(GL_FRAGMENT_SHADER);
612@@ -288,10 +242,6 @@ GLuint LAppDelegate::CreateShader()
613 "}";
614 glShaderSource(fragmentShaderId, 1, &fragmentShader, NULL);
615 glCompileShader(fragmentShaderId);
616- if (!CheckShader(fragmentShaderId))
617- {
618- return 0;
619- }
620
621 //プログラムオブジェクトの作成
622 GLuint programId = glCreateProgram();
623@@ -306,25 +256,24 @@ GLuint LAppDelegate::CreateShader()
624 return programId;
625 }
626
627-bool LAppDelegate::CheckShader(GLuint shaderId)
628+void LAppDelegate::SetRootDirectory(std::string rootDir)
629 {
630- GLint status;
631- GLint logLength;
632- glGetShaderiv(shaderId, GL_INFO_LOG_LENGTH, &logLength);
633- if (logLength > 0)
634- {
635- GLchar* log = reinterpret_cast<GLchar*>(CSM_MALLOC(logLength));
636- glGetShaderInfoLog(shaderId, logLength, &logLength, log);
637- CubismLogError("Shader compile log: %s", log);
638- CSM_FREE(log);
639- }
640+ this->_rootDirectory = rootDir + "/";
641+}
642+
643+Csm::csmVector<string> LAppDelegate::Split(const std::string& baseString, char delimiter)
644+{
645+ Csm::csmVector<string> elems;
646+ stringstream ss(baseString);
647+ string item;
648
649- glGetShaderiv(shaderId, GL_COMPILE_STATUS, &status);
650- if (status == GL_FALSE)
651+ while(getline(ss, item, delimiter))
652 {
653- glDeleteShader(shaderId);
654- return false;
655+ if(!item.empty())
656+ {
657+ elems.PushBack(item);
658+ }
659 }
660
661- return true;
662+ return elems;
663 }
664diff -pruN --exclude build ./demo_clean/src/LAppDelegate.hpp ./demo_dev/src/LAppDelegate.hpp
6fd3638f
AIL
665--- ./demo_clean/src/LAppDelegate.hpp 2023-05-18 09:58:50.000000000 +0100
666+++ ./demo_dev/src/LAppDelegate.hpp 2023-05-28 08:28:27.496813523 +0100
6d2cd78f
AL
667@@ -1,4 +1,4 @@
668-/**
669+/**
670 * Copyright(c) Live2D Inc. All rights reserved.
671 *
672 * Use of this source code is governed by the Live2D Open Software license
673@@ -7,8 +7,10 @@
674
675 #pragma once
676
677+#include <string>
678 #include <GL/glew.h>
679 #include <GLFW/glfw3.h>
680+#include "Type/csmVector.hpp"
681 #include "LAppAllocator.hpp"
682
683 class LAppView;
684@@ -16,7 +18,7 @@ class LAppTextureManager;
685
686 /**
687 * @brief アプリケーションクラス。
688-* Cubism SDK の管理を行う。
689+* Cubism3の管理を行う。
690 */
691 class LAppDelegate
692 {
693@@ -38,7 +40,8 @@ public:
694 /**
695 * @brief APPに必要なものを初期化する。
696 */
697- bool Initialize();
698+ bool Initialize(int initWindowWidth = 0, int initWindowHeight = 0,
699+ const char *windowTitle = "SAMPLE");
700
701 /**
702 * @brief 解放する。
703@@ -51,25 +54,6 @@ public:
704 void Run();
705
706 /**
707- * @brief OpenGL用 glfwSetMouseButtonCallback用関数。
708- *
709- * @param[in] window コールバックを呼んだWindow情報
710- * @param[in] button ボタン種類
711- * @param[in] action 実行結果
712- * @param[in] modify
713- */
714- void OnMouseCallBack(GLFWwindow* window, int button, int action, int modify);
715-
716- /**
717- * @brief OpenGL用 glfwSetCursorPosCallback用関数。
718- *
719- * @param[in] window コールバックを呼んだWindow情報
720- * @param[in] x x座標
721- * @param[in] y x座標
722- */
723- void OnMouseCallBack(GLFWwindow* window, double x, double y);
724-
725- /**
726 * @brief シェーダーを登録する。
727 */
728 GLuint CreateShader();
729@@ -94,6 +78,21 @@ public:
730 */
731 void AppEnd() { _isEnd = true; }
732
733+ /**
734+ * @brief ルートディレクトリを設定する。
735+ *
736+ * @param[in] rootDir : The root directory to set to.
737+ */
738+ void SetRootDirectory(std::string rootDir);
739+
740+ /**
741+ * @brief ルートディレクトリを取得する。
742+ */
743+ std::string GetRootDirectory(){ return _rootDirectory;}
744+
745+ /**
746+ * @brief テクスチャマネージャーを取得する。
747+ */
748 LAppTextureManager* GetTextureManager() { return _textureManager; }
749
750 private:
751@@ -108,17 +107,17 @@ private:
752 ~LAppDelegate();
753
754 /**
755- * @brief Cubism SDK の初期化
756+ * @brief Cubism3の初期化
757 */
758 void InitializeCubism();
759
760 /**
761- * @brief CreateShader内部関数 エラーチェック
762+ * @brief 文字列を指定の文字で切り分ける
763 */
764- bool CheckShader(GLuint shaderId);
765+ Csm::csmVector<std::string> Split(const std::string& baseString, char delim);
766
767- LAppAllocator _cubismAllocator; ///< Cubism SDK Allocator
768- Csm::CubismFramework::Option _cubismOption; ///< Cubism SDK Option
769+ LAppAllocator _cubismAllocator; ///< Cubism3 Allocator
770+ Csm::CubismFramework::Option _cubismOption; ///< Cubism3 Option
771 GLFWwindow* _window; ///< OpenGL ウィンドウ
772 LAppView* _view; ///< View情報
773 bool _captured; ///< クリックしているか
774@@ -126,28 +125,8 @@ private:
775 float _mouseY; ///< マウスY座標
776 bool _isEnd; ///< APP終了しているか
777 LAppTextureManager* _textureManager; ///< テクスチャマネージャー
778+ std::string _rootDirectory; ///< ルートディレクトリ
779
780 int _windowWidth; ///< Initialize関数で設定したウィンドウ幅
781 int _windowHeight; ///< Initialize関数で設定したウィンドウ高さ
782 };
783-
784-class EventHandler
785-{
786-public:
787- /**
788- * @brief glfwSetMouseButtonCallback用コールバック関数。
789- */
790- static void OnMouseCallBack(GLFWwindow* window, int button, int action, int modify)
791- {
792- LAppDelegate::GetInstance()->OnMouseCallBack(window, button, action, modify);
793- }
794-
795- /**
796- * @brief glfwSetCursorPosCallback用コールバック関数。
797- */
798- static void OnMouseCallBack(GLFWwindow* window, double x, double y)
799- {
800- LAppDelegate::GetInstance()->OnMouseCallBack(window, x, y);
801- }
802-
803-};
804diff -pruN --exclude build ./demo_clean/src/LAppLive2DManager.cpp ./demo_dev/src/LAppLive2DManager.cpp
6fd3638f
AIL
805--- ./demo_clean/src/LAppLive2DManager.cpp 2023-05-18 09:58:50.000000000 +0100
806+++ ./demo_dev/src/LAppLive2DManager.cpp 2023-05-28 08:28:27.496813523 +0100
6d2cd78f
AL
807@@ -1,4 +1,4 @@
808-/**
809+/**
810 * Copyright(c) Live2D Inc. All rights reserved.
811 *
812 * Use of this source code is governed by the Live2D Open Software license
813@@ -15,6 +15,7 @@
814 #include "LAppDelegate.hpp"
815 #include "LAppModel.hpp"
816 #include "LAppView.hpp"
817+#include "LAppSprite.hpp"
818
819 using namespace Csm;
820 using namespace LAppDefine;
821@@ -51,11 +52,11 @@ void LAppLive2DManager::ReleaseInstance(
822
823 LAppLive2DManager::LAppLive2DManager()
824 : _viewMatrix(NULL)
825- , _sceneIndex(0)
826+ , _projScaleFactor(1.0f)
827+ , _translateX(0.0f)
828+ , _translateY(0.0f)
829 {
830 _viewMatrix = new CubismMatrix44();
831-
832- ChangeScene(_sceneIndex);
833 }
834
835 LAppLive2DManager::~LAppLive2DManager()
836@@ -99,26 +100,6 @@ void LAppLive2DManager::OnTap(csmFloat32
837 {
838 LAppPal::PrintLog("[APP]tap point: {x:%.2f y:%.2f}", x, y);
839 }
840-
841- for (csmUint32 i = 0; i < _models.GetSize(); i++)
842- {
843- if (_models[i]->HitTest(HitAreaNameHead, x, y))
844- {
845- if (DebugLogEnable)
846- {
847- LAppPal::PrintLog("[APP]hit area: [%s]", HitAreaNameHead);
848- }
849- _models[i]->SetRandomExpression();
850- }
851- else if (_models[i]->HitTest(HitAreaNameBody, x, y))
852- {
853- if (DebugLogEnable)
854- {
855- LAppPal::PrintLog("[APP]hit area: [%s]", HitAreaNameBody);
856- }
857- _models[i]->StartRandomMotion(MotionGroupTapBody, PriorityNormal, FinishedMotion);
858- }
859- }
860 }
861
862 void LAppLive2DManager::OnUpdate() const
863@@ -126,10 +107,10 @@ void LAppLive2DManager::OnUpdate() const
864 int width, height;
865 glfwGetWindowSize(LAppDelegate::GetInstance()->GetWindow(), &width, &height);
866
867+ CubismMatrix44 projection;
868 csmUint32 modelCount = _models.GetSize();
869 for (csmUint32 i = 0; i < modelCount; ++i)
870 {
871- CubismMatrix44 projection;
872 LAppModel* model = GetModel(i);
873
874 if (model->GetModel() == NULL)
875@@ -142,12 +123,15 @@ void LAppLive2DManager::OnUpdate() const
876 {
877 // 横に長いモデルを縦長ウィンドウに表示する際モデルの横サイズでscaleを算出する
878 model->GetModelMatrix()->SetWidth(2.0f);
879- projection.Scale(1.0f, static_cast<float>(width) / static_cast<float>(height));
880+ projection.Scale(_projScaleFactor,
881+ _projScaleFactor * static_cast<float>(width) / static_cast<float>(height));
882 }
883 else
884 {
885- projection.Scale(static_cast<float>(height) / static_cast<float>(width), 1.0f);
886+ projection.Scale(_projScaleFactor * static_cast<float>(height) / static_cast<float>(width),
887+ _projScaleFactor);
888 }
889+ projection.Translate(_translateX, _translateY);
890
891 // 必要があればここで乗算
892 if (_viewMatrix != NULL)
893@@ -155,41 +139,23 @@ void LAppLive2DManager::OnUpdate() const
894 projection.MultiplyByMatrix(_viewMatrix);
895 }
896
897- // モデル1体描画前コール
898 LAppDelegate::GetInstance()->GetView()->PreModelDraw(*model);
899
900 model->Update();
901 model->Draw(projection);///< 参照渡しなのでprojectionは変質する
902
903- // モデル1体描画後コール
904 LAppDelegate::GetInstance()->GetView()->PostModelDraw(*model);
905 }
906 }
907
908-void LAppLive2DManager::NextScene()
909-{
910- csmInt32 no = (_sceneIndex + 1) % ModelDirSize;
911- ChangeScene(no);
912-}
913-
914-void LAppLive2DManager::ChangeScene(Csm::csmInt32 index)
915+void LAppLive2DManager::SetModel(std::string modelName, bool useOldParamId)
916 {
917- _sceneIndex = index;
918- if (DebugLogEnable)
919- {
920- LAppPal::PrintLog("[APP]model index: %d", _sceneIndex);
921- }
922-
923- // ModelDir[]に保持したディレクトリ名から
924- // model3.jsonのパスを決定する.
925- // ディレクトリ名とmodel3.jsonの名前を一致させておくこと.
926- std::string model = ModelDir[index];
927- std::string modelPath = ResourcesPath + model + "/";
928- std::string modelJsonName = ModelDir[index];
929+ std::string modelPath = LAppDelegate::GetInstance()->GetRootDirectory() + ResourcesPath + modelName + "/";
930+ std::string modelJsonName = modelName;
931 modelJsonName += ".model3.json";
932
933 ReleaseAllModel();
934- _models.PushBack(new LAppModel());
935+ _models.PushBack(new LAppModel(useOldParamId));
936 _models[0]->LoadAssets(modelPath.c_str(), modelJsonName.c_str());
937
938 /*
939@@ -211,16 +177,21 @@ void LAppLive2DManager::ChangeScene(Csm:
940
941 #if defined(USE_RENDER_TARGET) || defined(USE_MODEL_RENDER_TARGET)
942 // モデル個別にαを付けるサンプルとして、もう1体モデルを作成し、少し位置をずらす
943- _models.PushBack(new LAppModel());
944+ _models.PushBack(new LAppModel(useOldParamId));
945 _models[1]->LoadAssets(modelPath.c_str(), modelJsonName.c_str());
946 _models[1]->GetModelMatrix()->TranslateX(0.2f);
947 #endif
948
949+ float clearColor[3] = { 1.0f, 1.0f, 1.0f };
950+
951 LAppDelegate::GetInstance()->GetView()->SwitchRenderingTarget(useRenderTarget);
952
953- // 別レンダリング先を選択した際の背景クリア色
954- float clearColor[3] = { 1.0f, 1.0f, 1.0f };
955- LAppDelegate::GetInstance()->GetView()->SetRenderTargetClearColor(clearColor[0], clearColor[1], clearColor[2]);
956+ if(useRenderTarget)
957+ {
958+ LAppDelegate::GetInstance()->GetView()->SwitchRenderingTarget(useRenderTarget);
959+ // 背景クリア色
960+ LAppDelegate::GetInstance()->GetView()->SetRenderTargetClearColor(clearColor[0], clearColor[1], clearColor[2]);
961+ }
962 }
963 }
964
965@@ -235,3 +206,20 @@ void LAppLive2DManager::SetViewMatrix(Cu
966 _viewMatrix->GetArray()[i] = m->GetArray()[i];
967 }
968 }
969+
970+void LAppLive2DManager::SetFacialLandmarkDetector(FacialLandmarkDetector *detector)
971+{
972+ for (auto it = _models.Begin(); it != _models.End(); ++it)
973+ {
974+ (*it)->SetFacialLandmarkDetector(detector);
975+ }
976+}
977+
978+void LAppLive2DManager::SetProjectionScaleTranslate(float scaleFactor,
979+ float translateX,
980+ float translateY)
981+{
982+ _projScaleFactor = scaleFactor;
983+ _translateX = translateX;
984+ _translateY = translateY;
985+}
986diff -pruN --exclude build ./demo_clean/src/LAppLive2DManager.hpp ./demo_dev/src/LAppLive2DManager.hpp
6fd3638f
AIL
987--- ./demo_clean/src/LAppLive2DManager.hpp 2023-05-18 09:58:50.000000000 +0100
988+++ ./demo_dev/src/LAppLive2DManager.hpp 2023-05-28 08:28:27.496813523 +0100
6d2cd78f
AL
989@@ -1,18 +1,20 @@
990-/**
991+/**
992 * Copyright(c) Live2D Inc. All rights reserved.
993 *
994 * Use of this source code is governed by the Live2D Open Software license
995 * that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html.
996 */
997-
998 #pragma once
999
1000+#include <string>
1001 #include <CubismFramework.hpp>
1002 #include <Math/CubismMatrix44.hpp>
1003 #include <Type/csmVector.hpp>
1004
1005 class LAppModel;
1006
1007+class FacialLandmarkDetector;
1008+
1009 /**
1010 * @brief サンプルアプリケーションにおいてCubismModelを管理するクラス<br>
1011 * モデル生成と破棄、タップイベントの処理、モデル切り替えを行う。
1012@@ -73,16 +75,14 @@ public:
1013 void OnUpdate() const;
1014
1015 /**
1016- * @brief 次のシーンに切り替える<br>
1017- * サンプルアプリケーションではモデルセットの切り替えを行う。
1018- */
1019- void NextScene();
1020-
1021- /**
1022- * @brief シーンを切り替える<br>
1023- * サンプルアプリケーションではモデルセットの切り替えを行う。
1024- */
1025- void ChangeScene(Csm::csmInt32 index);
1026+ * @brief Set model data
1027+ *
1028+ * @param[in] modelName : Name of model, should be the same for both
1029+ * the directory and the model3.json file
1030+ * @param[in] useOldParamId : If true, translate new (Cubism 3+)
1031+ * parameter IDs to old (Cubism 2.1) ones
1032+ */
1033+ void SetModel(std::string modelName, bool useOldParamId);
1034
1035 /**
1036 * @brief モデル個数を得る
1037@@ -95,6 +95,24 @@ public:
1038 */
1039 void SetViewMatrix(Live2D::Cubism::Framework::CubismMatrix44* m);
1040
1041+ /**
1042+ * @brief Set the pointer to the FacialLandmarkDetector instance
1043+ *
1044+ * @param[in] detector : Pointer to FacialLandmarkDetector instance
1045+ */
1046+ void SetFacialLandmarkDetector(FacialLandmarkDetector *detector);
1047+
1048+ /**
1049+ * @brief Set projection scale factor and translation parameters
1050+ *
1051+ * @param[in] scaleFactor : Scale factor applied in both X and Y directions
1052+ * @param[in] translateX : Translation in X direction
1053+ * @param[in] translateY : Translation in Y direction
1054+ */
1055+ void SetProjectionScaleTranslate(float scaleFactor,
1056+ float translateX,
1057+ float translateY);
1058+
1059 private:
1060 /**
1061 * @brief コンストラクタ
1062@@ -108,5 +126,8 @@ private:
1063
1064 Csm::CubismMatrix44* _viewMatrix; ///< モデル描画に用いるView行列
1065 Csm::csmVector<LAppModel*> _models; ///< モデルインスタンスのコンテナ
1066- Csm::csmInt32 _sceneIndex; ///< 表示するシーンのインデックス値
1067+
1068+ float _projScaleFactor;
1069+ float _translateX;
1070+ float _translateY;
1071 };
1072diff -pruN --exclude build ./demo_clean/src/LAppModel.cpp ./demo_dev/src/LAppModel.cpp
6fd3638f
AIL
1073--- ./demo_clean/src/LAppModel.cpp 2023-05-18 09:58:50.000000000 +0100
1074+++ ./demo_dev/src/LAppModel.cpp 2023-05-28 08:34:09.047010843 +0100
6d2cd78f
AL
1075@@ -1,4 +1,4 @@
1076-/**
1077+/**
1078 * Copyright(c) Live2D Inc. All rights reserved.
1079 *
1080 * Use of this source code is governed by the Live2D Open Software license
1081@@ -21,6 +21,8 @@
1082 #include "LAppTextureManager.hpp"
1083 #include "LAppDelegate.hpp"
1084
1085+#include "facial_landmark_detector.h"
1086+
1087 using namespace Live2D::Cubism::Framework;
1088 using namespace Live2D::Cubism::Framework::DefaultParameterId;
1089 using namespace LAppDefine;
6fd3638f 1090@@ -45,10 +47,12 @@ namespace {
6d2cd78f
AL
1091 }
1092 }
1093
1094-LAppModel::LAppModel()
1095+LAppModel::LAppModel(bool useOldParamId)
1096 : CubismUserModel()
1097 , _modelSetting(NULL)
1098 , _userTimeSeconds(0.0f)
1099+ , _detector(nullptr)
1100+ , _useOldParamId(useOldParamId)
1101 {
6fd3638f 1102 if (MocConsistencyValidationEnable)
6d2cd78f 1103 {
6fd3638f 1104@@ -60,12 +64,12 @@ LAppModel::LAppModel()
6d2cd78f
AL
1105 _debugMode = true;
1106 }
1107
1108- _idParamAngleX = CubismFramework::GetIdManager()->GetId(ParamAngleX);
1109- _idParamAngleY = CubismFramework::GetIdManager()->GetId(ParamAngleY);
1110- _idParamAngleZ = CubismFramework::GetIdManager()->GetId(ParamAngleZ);
1111- _idParamBodyAngleX = CubismFramework::GetIdManager()->GetId(ParamBodyAngleX);
1112- _idParamEyeBallX = CubismFramework::GetIdManager()->GetId(ParamEyeBallX);
1113- _idParamEyeBallY = CubismFramework::GetIdManager()->GetId(ParamEyeBallY);
1114+ _idParamAngleX = CubismFramework::GetIdManager()->GetId(_(ParamAngleX));
1115+ _idParamAngleY = CubismFramework::GetIdManager()->GetId(_(ParamAngleY));
1116+ _idParamAngleZ = CubismFramework::GetIdManager()->GetId(_(ParamAngleZ));
1117+ _idParamBodyAngleX = CubismFramework::GetIdManager()->GetId(_(ParamBodyAngleX));
1118+ _idParamEyeBallX = CubismFramework::GetIdManager()->GetId(_(ParamEyeBallX));
1119+ _idParamEyeBallY = CubismFramework::GetIdManager()->GetId(_(ParamEyeBallY));
1120 }
1121
1122 LAppModel::~LAppModel()
6fd3638f 1123@@ -101,12 +105,6 @@ void LAppModel::LoadAssets(const csmChar
6d2cd78f
AL
1124
1125 SetupModel(setting);
1126
1127- if (_model == NULL)
1128- {
1129- LAppPal::PrintLog("Failed to LoadAssets().");
1130- return;
1131- }
1132-
1133 CreateRenderer();
1134
1135 SetupTextures();
6fd3638f 1136@@ -138,30 +136,6 @@ void LAppModel::SetupModel(ICubismModelS
6d2cd78f
AL
1137 DeleteBuffer(buffer, path.GetRawString());
1138 }
1139
1140- //Expression
1141- if (_modelSetting->GetExpressionCount() > 0)
1142- {
1143- const csmInt32 count = _modelSetting->GetExpressionCount();
1144- for (csmInt32 i = 0; i < count; i++)
1145- {
1146- csmString name = _modelSetting->GetExpressionName(i);
1147- csmString path = _modelSetting->GetExpressionFileName(i);
1148- path = _modelHomeDir + path;
1149-
1150- buffer = CreateBuffer(path.GetRawString(), &size);
1151- ACubismMotion* motion = LoadExpression(buffer, size, name.GetRawString());
1152-
1153- if (_expressions[name] != NULL)
1154- {
1155- ACubismMotion::Delete(_expressions[name]);
1156- _expressions[name] = NULL;
1157- }
1158- _expressions[name] = motion;
1159-
1160- DeleteBuffer(buffer, path.GetRawString());
1161- }
1162- }
1163-
1164 //Physics
1165 if (strcmp(_modelSetting->GetPhysicsFileName(), "") != 0)
1166 {
6fd3638f 1167@@ -200,7 +174,7 @@ void LAppModel::SetupModel(ICubismModelS
6d2cd78f
AL
1168 breathParameters.PushBack(CubismBreath::BreathParameterData(_idParamAngleY, 0.0f, 8.0f, 3.5345f, 0.5f));
1169 breathParameters.PushBack(CubismBreath::BreathParameterData(_idParamAngleZ, 0.0f, 10.0f, 5.5345f, 0.5f));
1170 breathParameters.PushBack(CubismBreath::BreathParameterData(_idParamBodyAngleX, 0.0f, 4.0f, 15.5345f, 0.5f));
1171- breathParameters.PushBack(CubismBreath::BreathParameterData(CubismFramework::GetIdManager()->GetId(ParamBreath), 0.5f, 0.5f, 3.2345f, 0.5f));
1172+ breathParameters.PushBack(CubismBreath::BreathParameterData(CubismFramework::GetIdManager()->GetId(_(ParamBreath)), 0.5f, 0.5f, 3.2345f, 0.5f));
1173
1174 _breath->SetParameters(breathParameters);
1175 }
6fd3638f 1176@@ -224,21 +198,6 @@ void LAppModel::SetupModel(ICubismModelS
6d2cd78f
AL
1177 }
1178 }
1179
1180- // LipSyncIds
1181- {
1182- csmInt32 lipSyncIdCount = _modelSetting->GetLipSyncParameterCount();
1183- for (csmInt32 i = 0; i < lipSyncIdCount; ++i)
1184- {
1185- _lipSyncIds.PushBack(_modelSetting->GetLipSyncParameterId(i));
1186- }
1187- }
1188-
1189- if (_modelSetting == NULL || _modelMatrix == NULL)
1190- {
1191- LAppPal::PrintLog("Failed to SetupModel().");
1192- return;
1193- }
1194-
1195 //Layout
1196 csmMap<csmString, csmFloat32> layout;
1197 _modelSetting->GetLayoutMap(layout);
6fd3638f 1198@@ -351,62 +310,57 @@ void LAppModel::Update()
6d2cd78f
AL
1199 const csmFloat32 deltaTimeSeconds = LAppPal::GetDeltaTime();
1200 _userTimeSeconds += deltaTimeSeconds;
1201
1202- _dragManager->Update(deltaTimeSeconds);
1203- _dragX = _dragManager->GetX();
1204- _dragY = _dragManager->GetY();
1205-
1206- // モーションによるパラメータ更新の有無
1207- csmBool motionUpdated = false;
1208-
1209- //-----------------------------------------------------------------
1210- _model->LoadParameters(); // 前回セーブされた状態をロード
1211- if (_motionManager->IsFinished())
6fd3638f 1212- {
6d2cd78f
AL
1213- // モーションの再生がない場合、待機モーションの中からランダムで再生する
1214- StartRandomMotion(MotionGroupIdle, PriorityIdle);
1215- }
1216- else
6fd3638f
AIL
1217+ if (_detector)
1218 {
6d2cd78f
AL
1219- motionUpdated = _motionManager->UpdateMotion(_model, deltaTimeSeconds); // モーションを更新
1220- }
1221- _model->SaveParameters(); // 状態を保存
1222- //-----------------------------------------------------------------
1223+ auto idMan = CubismFramework::GetIdManager();
1224+ auto params = _detector->getParams();
1225
6fd3638f
AIL
1226- // 不透明度
1227- _opacity = _model->GetModelOpacity();
1228-
6d2cd78f
AL
1229- // まばたき
1230- if (!motionUpdated)
1231- {
1232- if (_eyeBlink != NULL)
1233+ // NOTE: Apparently, this LoadParameters/SaveParameters pair
1234+ // is needed for auto breath to work.
1235+ _model->LoadParameters(); // 前回セーブされた状態をロード
1236+ if (_motionManager->IsFinished() && params.randomMotion)
1237 {
1238- // メインモーションの更新がないとき
1239- _eyeBlink->UpdateParameters(_model, deltaTimeSeconds); // 目パチ
1240+ // モーションの再生がない場合、待機モーションの中からランダムで再生する
1241+ StartRandomMotion(MotionGroupIdle, PriorityIdle);
1242 }
1243- }
1244-
1245- if (_expressionManager != NULL)
1246- {
1247- _expressionManager->UpdateMotion(_model, deltaTimeSeconds); // 表情でパラメータ更新(相対変化)
1248- }
1249-
1250- //ドラッグによる変化
1251- //ドラッグによる顔の向きの調整
1252- _model->AddParameterValue(_idParamAngleX, _dragX * 30); // -30から30の値を加える
1253- _model->AddParameterValue(_idParamAngleY, _dragY * 30);
1254- _model->AddParameterValue(_idParamAngleZ, _dragX * _dragY * -30);
1255-
1256- //ドラッグによる体の向きの調整
1257- _model->AddParameterValue(_idParamBodyAngleX, _dragX * 10); // -10から10の値を加える
1258+ else
1259+ {
1260+ _motionManager->UpdateMotion(_model, deltaTimeSeconds); // モーションを更新
1261+ }
1262+ _model->SaveParameters(); // 状態を保存
1263
1264- //ドラッグによる目の向きの調整
1265- _model->AddParameterValue(_idParamEyeBallX, _dragX); // -1から1の値を加える
1266- _model->AddParameterValue(_idParamEyeBallY, _dragY);
1267
1268- // 呼吸など
1269- if (_breath != NULL)
1270- {
1271- _breath->UpdateParameters(_model, deltaTimeSeconds);
1272+ if (params.autoBlink && _eyeBlink)
1273+ {
1274+ _eyeBlink->UpdateParameters(_model, deltaTimeSeconds);
1275+ }
1276+ else
1277+ {
1278+ _model->SetParameterValue(idMan->GetId(_("ParamEyeLOpen")),
1279+ params.leftEyeOpenness);
1280+ _model->SetParameterValue(idMan->GetId(_("ParamEyeROpen")),
1281+ params.rightEyeOpenness);
1282+ }
1283+ _model->SetParameterValue(idMan->GetId(_("ParamMouthForm")),
1284+ params.mouthForm);
1285+ _model->SetParameterValue(idMan->GetId(_("ParamMouthOpenY")),
1286+ params.mouthOpenness);
1287+ _model->SetParameterValue(idMan->GetId(_("ParamEyeLSmile")),
1288+ params.leftEyeSmile);
1289+ _model->SetParameterValue(idMan->GetId(_("ParamEyeRSmile")),
1290+ params.rightEyeSmile);
1291+ _model->SetParameterValue(idMan->GetId(_("ParamAngleX")),
1292+ params.faceXAngle);
1293+ _model->SetParameterValue(idMan->GetId(_("ParamAngleY")),
1294+ params.faceYAngle);
1295+ _model->SetParameterValue(idMan->GetId(_("ParamAngleZ")),
1296+ params.faceZAngle);
1297+ if (params.autoBreath && _breath)
1298+ {
1299+ // Note: _model->LoadParameters and SaveParameters is needed
1300+ // before - see above.
1301+ _breath->UpdateParameters(_model, deltaTimeSeconds);
1302+ }
1303 }
1304
1305 // 物理演算の設定
6fd3638f 1306@@ -415,22 +369,6 @@ void LAppModel::Update()
6d2cd78f
AL
1307 _physics->Evaluate(_model, deltaTimeSeconds);
1308 }
1309
1310- // リップシンクの設定
1311- if (_lipSync)
1312- {
1313- // リアルタイムでリップシンクを行う場合、システムから音量を取得して0〜1の範囲で値を入力します。
1314- csmFloat32 value = 0.0f;
1315-
1316- // 状態更新/RMS値取得
1317- _wavFileHandler.Update(deltaTimeSeconds);
1318- value = _wavFileHandler.GetRms();
1319-
1320- for (csmUint32 i = 0; i < _lipSyncIds.GetSize(); ++i)
1321- {
1322- _model->AddParameterValue(_lipSyncIds[i], value, 0.8f);
1323- }
1324- }
1325-
1326 // ポーズの設定
1327 if (_pose != NULL)
1328 {
6fd3638f 1329@@ -499,7 +437,6 @@ CubismMotionQueueEntryHandle LAppModel::
6d2cd78f
AL
1330 {
1331 csmString path = voice;
1332 path = _modelHomeDir + path;
1333- _wavFileHandler.Start(path);
1334 }
1335
1336 if (_debugMode)
6fd3638f
AIL
1337@@ -678,3 +615,37 @@ csmBool LAppModel::HasMocConsistencyFrom
1338
1339 return consistency;
6d2cd78f
AL
1340 }
1341+
1342+void LAppModel::SetFacialLandmarkDetector(FacialLandmarkDetector *detector)
1343+{
1344+ _detector = detector;
1345+}
1346+
1347+Csm::csmString LAppModel::_(std::string s)
1348+{
1349+ std::string ans;
1350+ if (_useOldParamId)
1351+ {
1352+ if (s == "ParamTere")
1353+ {
1354+ ans = "PARAM_CHEEK";
1355+ }
1356+ else
1357+ {
1358+ for (size_t i = 0; i < s.size(); i++)
1359+ {
1360+ if (std::isupper(s[i]) && i != 0)
1361+ {
1362+ ans += '_';
1363+ }
1364+ ans += std::toupper(s[i]);
1365+ }
1366+ }
1367+ }
1368+ else
1369+ {
1370+ ans = s;
1371+ }
1372+ return csmString(ans.c_str());
1373+}
1374+
1375diff -pruN --exclude build ./demo_clean/src/LAppModel.hpp ./demo_dev/src/LAppModel.hpp
6fd3638f
AIL
1376--- ./demo_clean/src/LAppModel.hpp 2023-05-18 09:58:50.000000000 +0100
1377+++ ./demo_dev/src/LAppModel.hpp 2023-05-28 08:28:27.500813596 +0100
6d2cd78f
AL
1378@@ -1,4 +1,4 @@
1379-/**
1380+/**
1381 * Copyright(c) Live2D Inc. All rights reserved.
1382 *
1383 * Use of this source code is governed by the Live2D Open Software license
1384@@ -13,7 +13,7 @@
1385 #include <Type/csmRectF.hpp>
1386 #include <Rendering/OpenGL/CubismOffscreenSurface_OpenGLES2.hpp>
1387
1388-#include "LAppWavFileHandler.hpp"
1389+#include "facial_landmark_detector.h"
1390
1391 /**
1392 * @brief ユーザーが実際に使用するモデルの実装クラス<br>
1393@@ -25,8 +25,11 @@ class LAppModel : public Csm::CubismUser
1394 public:
1395 /**
1396 * @brief コンストラクタ
1397+ *
1398+ * @param[in] useOldParamId : If true, translate new (Cubism 3+)
1399+ * parameter IDs to old (Cubism 2.1) ones
1400 */
1401- LAppModel();
1402+ LAppModel(bool useOldParamId);
1403
1404 /**
1405 * @brief デストラクタ
6fd3638f 1406@@ -122,6 +125,13 @@ public:
6d2cd78f 1407 */
6fd3638f 1408 Csm::csmBool HasMocConsistencyFromFile(const Csm::csmChar* mocFileName);
6d2cd78f
AL
1409
1410+ /**
1411+ * @brief Set the pointer to the FacialLandmarkDetector instance
1412+ *
1413+ * @param[in] detector : Pointer to FacialLandmarkDetector instance
1414+ */
1415+ void SetFacialLandmarkDetector(FacialLandmarkDetector *detector);
1416+
1417 protected:
1418 /**
1419 * @brief モデルを描画する処理。モデルを描画する空間のView-Projection行列を渡す。
6fd3638f 1420@@ -175,6 +185,17 @@ private:
6d2cd78f
AL
1421 */
1422 void ReleaseExpressions();
1423
1424+ /**
1425+ * @brief Translate new (Cubism 3+) parameter IDs to old (Cubism 2.1) ones
1426+ *
1427+ * @param[in] s : New parameter ID
1428+ *
1429+ * @return Old parameter ID
1430+ */
1431+ Csm::csmString _(std::string s);
1432+
1433+ bool _useOldParamId;
1434+
1435 Csm::ICubismModelSetting* _modelSetting; ///< モデルセッティング情報
1436 Csm::csmString _modelHomeDir; ///< モデルセッティングが置かれたディレクトリ
1437 Csm::csmFloat32 _userTimeSeconds; ///< デルタ時間の積算値[秒]
6fd3638f 1438@@ -191,9 +212,9 @@ private:
6d2cd78f
AL
1439 const Csm::CubismId* _idParamEyeBallX; ///< パラメータID: ParamEyeBallX
1440 const Csm::CubismId* _idParamEyeBallY; ///< パラメータID: ParamEyeBallXY
1441
1442- LAppWavFileHandler _wavFileHandler; ///< wavファイルハンドラ
1443+ Csm::Rendering::CubismOffscreenFrame_OpenGLES2 _renderBuffer; ///< フレームバッファ以外の描画先
1444
1445- Csm::Rendering::CubismOffscreenFrame_OpenGLES2 _renderBuffer; ///< フレームバッファ以外の描画先
1446+ FacialLandmarkDetector *_detector;
1447 };
1448
1449
1450diff -pruN --exclude build ./demo_clean/src/LAppPal.cpp ./demo_dev/src/LAppPal.cpp
6fd3638f
AIL
1451--- ./demo_clean/src/LAppPal.cpp 2023-05-18 09:58:50.000000000 +0100
1452+++ ./demo_dev/src/LAppPal.cpp 2023-05-28 08:28:27.500813596 +0100
6d2cd78f
AL
1453@@ -1,4 +1,4 @@
1454-/**
1455+/**
1456 * Copyright(c) Live2D Inc. All rights reserved.
1457 *
1458 * Use of this source code is governed by the Live2D Open Software license
1459@@ -6,7 +6,9 @@
1460 */
1461
1462 #include "LAppPal.hpp"
1463-#include <cstdio>
1464+#include <stdexcept>
1465+#include <stdio.h>
1466+#include <stdlib.h>
1467 #include <stdarg.h>
1468 #include <sys/stat.h>
1469 #include <iostream>
1470@@ -35,6 +37,7 @@ csmByte* LAppPal::LoadFileAsBytes(const
1471 if (stat(path, &statBuf) == 0)
1472 {
1473 size = statBuf.st_size;
1474+ PrintLog(path);
1475 }
1476
1477 std::fstream file;
1478@@ -43,10 +46,7 @@ csmByte* LAppPal::LoadFileAsBytes(const
1479 file.open(path, std::ios::in | std::ios::binary);
1480 if (!file.is_open())
1481 {
1482- if (DebugLogEnable)
1483- {
1484- PrintLog("file open error");
1485- }
1486+ throw std::runtime_error("Failed to open file " + filePath);
1487 return NULL;
1488 }
1489 file.read(buf, size);
1490@@ -78,13 +78,8 @@ void LAppPal::PrintLog(const csmChar* fo
1491 va_list args;
1492 csmChar buf[256];
1493 va_start(args, format);
1494- vsnprintf_s(buf, sizeof(buf), format, args); // 標準出力でレンダリング
1495-#ifdef CSM_DEBUG_MEMORY_LEAKING
1496-// メモリリークチェック時は大量の標準出力がはしり重いのでprintfを利用する
1497- std::printf(buf);
1498-#else
1499+ vsnprintf(buf, sizeof(buf), format, args); // 標準出力でレンダリング
1500 std::cerr << buf << std::endl;
1501-#endif
1502 va_end(args);
1503 }
1504
1505diff -pruN --exclude build ./demo_clean/src/LAppPal.hpp ./demo_dev/src/LAppPal.hpp
6fd3638f
AIL
1506--- ./demo_clean/src/LAppPal.hpp 2023-05-18 09:58:50.000000000 +0100
1507+++ ./demo_dev/src/LAppPal.hpp 2023-05-28 08:28:27.500813596 +0100
6d2cd78f
AL
1508@@ -1,4 +1,4 @@
1509-/**
1510+/**
1511 * Copyright(c) Live2D Inc. All rights reserved.
1512 *
1513 * Use of this source code is governed by the Live2D Open Software license
1514@@ -8,6 +8,7 @@
1515 #pragma once
1516
1517 #include <CubismFramework.hpp>
1518+#include <cstdlib>
1519 #include <string>
1520
1521 /**
1522diff -pruN --exclude build ./demo_clean/src/LAppSprite.cpp ./demo_dev/src/LAppSprite.cpp
6fd3638f
AIL
1523--- ./demo_clean/src/LAppSprite.cpp 2023-05-18 09:58:50.000000000 +0100
1524+++ ./demo_dev/src/LAppSprite.cpp 2023-05-28 08:28:27.500813596 +0100
6d2cd78f
AL
1525@@ -1,4 +1,4 @@
1526-/**
1527+/**
1528 * Copyright(c) Live2D Inc. All rights reserved.
1529 *
1530 * Use of this source code is governed by the Live2D Open Software license
1531@@ -39,9 +39,9 @@ void LAppSprite::Render() const
1532 int maxWidth, maxHeight;
1533 glfwGetWindowSize(LAppDelegate::GetInstance()->GetWindow(), &maxWidth, &maxHeight);
1534
1535- if (maxWidth == 0 || maxHeight == 0)
1536+ if(maxWidth==0 || maxHeight==0)
1537 {
1538- return; // この際は描画できず
1539+ return;
1540 }
1541
1542 const GLfloat uvVertex[] =
1543@@ -74,7 +74,6 @@ void LAppSprite::Render() const
1544
1545 glUniform4f(_colorLocation, _spriteColor[0], _spriteColor[1], _spriteColor[2], _spriteColor[3]);
1546
1547-
1548 // モデルの描画
1549 glBindTexture(GL_TEXTURE_2D, _textureId);
1550 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
1551@@ -86,9 +85,9 @@ void LAppSprite::RenderImmidiate(GLuint
1552 int maxWidth, maxHeight;
1553 glfwGetWindowSize(LAppDelegate::GetInstance()->GetWindow(), &maxWidth, &maxHeight);
1554
1555- if (maxWidth == 0 || maxHeight == 0)
1556+ if(maxWidth==0 || maxHeight==0)
1557 {
1558- return; // この際は描画できず
1559+ return;
1560 }
1561
1562 // attribute属性を有効にする
1563@@ -124,11 +123,10 @@ bool LAppSprite::IsHit(float pointX, flo
1564 int maxWidth, maxHeight;
1565 glfwGetWindowSize(LAppDelegate::GetInstance()->GetWindow(), &maxWidth, &maxHeight);
1566
1567- if (maxWidth == 0 || maxHeight == 0)
1568+ if(maxWidth==0 || maxHeight==0)
1569 {
1570- return false; // この際は描画できず
1571+ return false;
1572 }
1573-
1574 //Y座標は変換する必要あり
1575 float y = maxHeight - pointY;
1576
1577diff -pruN --exclude build ./demo_clean/src/LAppSprite.hpp ./demo_dev/src/LAppSprite.hpp
6fd3638f
AIL
1578--- ./demo_clean/src/LAppSprite.hpp 2023-05-18 09:58:50.000000000 +0100
1579+++ ./demo_dev/src/LAppSprite.hpp 2023-05-28 08:28:27.500813596 +0100
6d2cd78f
AL
1580@@ -1,4 +1,4 @@
1581-/**
1582+/**
1583 * Copyright(c) Live2D Inc. All rights reserved.
1584 *
1585 * Use of this source code is governed by the Live2D Open Software license
1586@@ -61,7 +61,7 @@ public:
1587 void Render() const;
1588
1589 /**
1590- * @brief テクスチャIDを指定して描画する
1591+ * @brief テクスチャを指定しての描画
1592 *
1593 */
1594 void RenderImmidiate(GLuint textureId, const GLfloat uvVertex[8]) const;
1595@@ -95,8 +95,8 @@ public:
1596 void ResetRect(float x, float y, float width, float height);
1597
1598 private:
1599- GLuint _textureId; ///< テクスチャID
1600- Rect _rect; ///< 矩形
1601+ GLuint _textureId; ///< テクスチャID
1602+ Rect _rect; ///< 矩形
1603 int _positionLocation; ///< 位置アトリビュート
1604 int _uvLocation; ///< UVアトリビュート
1605 int _textureLocation; ///< テクスチャアトリビュート
1606diff -pruN --exclude build ./demo_clean/src/LAppTextureManager.cpp ./demo_dev/src/LAppTextureManager.cpp
6fd3638f
AIL
1607--- ./demo_clean/src/LAppTextureManager.cpp 2023-05-18 09:58:50.000000000 +0100
1608+++ ./demo_dev/src/LAppTextureManager.cpp 2023-05-28 08:28:27.500813596 +0100
6d2cd78f
AL
1609@@ -1,4 +1,4 @@
1610-/**
1611+/**
1612 * Copyright(c) Live2D Inc. All rights reserved.
1613 *
1614 * Use of this source code is governed by the Live2D Open Software license
1615@@ -10,7 +10,14 @@
1616 #define STBI_NO_STDIO
1617 #define STBI_ONLY_PNG
1618 #define STB_IMAGE_IMPLEMENTATION
1619+#if defined(__clang__)
1620+#pragma clang diagnostic push
1621+#pragma clang diagnostic ignored "-Wunused-function"
1622+#endif
1623 #include "stb_image.h"
1624+#if defined(__clang__)
1625+#pragma clang diagnostic pop
1626+#endif
1627 #include "LAppPal.hpp"
1628
1629 LAppTextureManager::LAppTextureManager()
1630@@ -89,6 +96,46 @@ LAppTextureManager::TextureInfo* LAppTex
1631
1632 }
1633
1634+LAppTextureManager::TextureInfo* LAppTextureManager::CreateTextureFromColor(
1635+ uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha
1636+)
1637+{
1638+ constexpr int width = 8, height = 8;
1639+
1640+ uint8_t pixels[height][width][4];
1641+ for (std::size_t h = 0; h < height; h++)
1642+ {
1643+ for (std::size_t w = 0; w < width; w++)
1644+ {
1645+ pixels[h][w][0] = red;
1646+ pixels[h][w][1] = green;
1647+ pixels[h][w][2] = blue;
1648+ pixels[h][w][3] = alpha;
1649+ }
1650+ }
1651+
1652+ GLuint textureId;
1653+ glGenTextures(1, &textureId);
1654+ glBindTexture(GL_TEXTURE_2D, textureId);
1655+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
1656+
1657+ glGenerateMipmap(GL_TEXTURE_2D);
1658+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
1659+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
1660+ glBindTexture(GL_TEXTURE_2D, 0);
1661+
1662+
1663+ LAppTextureManager::TextureInfo* textureInfo = new LAppTextureManager::TextureInfo();
1664+ textureInfo->fileName = "";
1665+ textureInfo->width = width;
1666+ textureInfo->height = height;
1667+ textureInfo->id = textureId;
1668+
1669+ _textures.PushBack(textureInfo);
1670+
1671+ return textureInfo;
1672+}
1673+
1674 void LAppTextureManager::ReleaseTextures()
1675 {
1676 for (Csm::csmUint32 i = 0; i < _textures.GetSize(); i++)
1677diff -pruN --exclude build ./demo_clean/src/LAppTextureManager.hpp ./demo_dev/src/LAppTextureManager.hpp
6fd3638f
AIL
1678--- ./demo_clean/src/LAppTextureManager.hpp 2023-05-18 09:58:50.000000000 +0100
1679+++ ./demo_dev/src/LAppTextureManager.hpp 2023-05-28 08:28:27.500813596 +0100
6d2cd78f
AL
1680@@ -1,4 +1,4 @@
1681-/**
1682+/**
1683 * Copyright(c) Live2D Inc. All rights reserved.
1684 *
1685 * Use of this source code is governed by the Live2D Open Software license
1686@@ -72,6 +72,8 @@ public:
1687 */
1688 TextureInfo* CreateTextureFromPngFile(std::string fileName);
1689
1690+ TextureInfo *CreateTextureFromColor(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha = 255);
1691+
1692 /**
1693 * @brief 画像の解放
1694 *
1695@@ -98,9 +100,9 @@ public:
1696 /**
1697 * @brief テクスチャIDからテクスチャ情報を得る
1698 *
1699- * @param textureId[in] 取得したいテクスチャID
1700- * @return テクスチャが存在していればTextureInfoが返る
1701- */
1702+ * @param[in] textureId 取得したいテクスチャID
1703+ * @return テクスチャが存在していればTextureInfoが返る
1704+ **/
1705 TextureInfo* GetTextureInfoById(GLuint textureId) const;
1706
1707 private:
1708diff -pruN --exclude build ./demo_clean/src/LAppView.cpp ./demo_dev/src/LAppView.cpp
6fd3638f
AIL
1709--- ./demo_clean/src/LAppView.cpp 2023-05-18 09:58:50.000000000 +0100
1710+++ ./demo_dev/src/LAppView.cpp 2023-05-28 08:28:27.500813596 +0100
6d2cd78f
AL
1711@@ -1,4 +1,4 @@
1712-/**
1713+/**
1714 * Copyright(c) Live2D Inc. All rights reserved.
1715 *
1716 * Use of this source code is governed by the Live2D Open Software license
1717@@ -13,18 +13,18 @@
1718 #include "LAppLive2DManager.hpp"
1719 #include "LAppTextureManager.hpp"
1720 #include "LAppDefine.hpp"
1721-#include "TouchManager.hpp"
1722 #include "LAppSprite.hpp"
1723 #include "LAppModel.hpp"
1724
1725+#include <Rendering/OpenGL/CubismOffscreenSurface_OpenGLES2.hpp>
1726+#include <Rendering/OpenGL/CubismRenderer_OpenGLES2.hpp>
1727+
1728 using namespace std;
1729 using namespace LAppDefine;
1730
1731 LAppView::LAppView():
1732 _programId(0),
1733 _back(NULL),
1734- _gear(NULL),
1735- _power(NULL),
1736 _renderSprite(NULL),
1737 _renderTarget(SelectTarget_None)
1738 {
1739@@ -33,9 +33,6 @@ LAppView::LAppView():
1740 _clearColor[2] = 1.0f;
1741 _clearColor[3] = 0.0f;
1742
1743- // タッチ関係のイベント管理
1744- _touchManager = new TouchManager();
1745-
1746 // デバイス座標からスクリーン座標に変換するための
1747 _deviceToScreen = new CubismMatrix44();
1748
1749@@ -47,12 +44,10 @@ LAppView::~LAppView()
1750 {
1751 _renderBuffer.DestroyOffscreenFrame();
1752 delete _renderSprite;
1753+
1754 delete _viewMatrix;
1755 delete _deviceToScreen;
1756- delete _touchManager;
1757 delete _back;
1758- delete _gear;
1759- delete _power;
1760 }
1761
1762 void LAppView::Initialize()
1763@@ -75,7 +70,7 @@ void LAppView::Initialize()
1764 _viewMatrix->SetScreenRect(left, right, bottom, top); // デバイスに対応する画面の範囲。 Xの左端, Xの右端, Yの下端, Yの上端
1765 _viewMatrix->Scale(ViewScale, ViewScale);
1766
1767- _deviceToScreen->LoadIdentity(); // サイズが変わった際などリセット必須
1768+ _deviceToScreen->LoadIdentity();
1769 if (width > height)
1770 {
1771 float screenW = fabsf(right - left);
1772@@ -104,8 +99,6 @@ void LAppView::Initialize()
1773 void LAppView::Render()
1774 {
1775 _back->Render();
1776- _gear->Render();
1777- _power->Render();
1778
1779 LAppLive2DManager* Live2DManager = LAppLive2DManager::GetInstance();
1780
1781@@ -125,7 +118,7 @@ void LAppView::Render()
1782 1.0f, 0.0f,
1783 };
1784
1785- for (csmUint32 i = 0; i < Live2DManager->GetModelNum(); i++)
1786+ for(csmUint32 i=0; i<Live2DManager->GetModelNum(); i++)
1787 {
6fd3638f
AIL
1788 LAppModel* model = Live2DManager->GetModel(i);
1789 float alpha = i < 1 ? 1.0f : model->GetOpacity(); // 片方のみ不透明度を取得できるようにする
6d2cd78f 1790@@ -133,7 +126,7 @@ void LAppView::Render()
6fd3638f 1791
6d2cd78f
AL
1792 if (model)
1793 {
1794- _renderSprite->RenderImmidiate( model->GetRenderBuffer().GetColorBuffer(), uvVertex);
1795+ _renderSprite->RenderImmidiate(model->GetRenderBuffer().GetColorBuffer(), uvVertex);
1796 }
1797 }
1798 }
1799@@ -147,85 +140,22 @@ void LAppView::InitializeSprite()
1800 glfwGetWindowSize(LAppDelegate::GetInstance()->GetWindow(), &width, &height);
1801
1802 LAppTextureManager* textureManager = LAppDelegate::GetInstance()->GetTextureManager();
1803- const string resourcesPath = ResourcesPath;
1804
1805- string imageName = BackImageName;
1806- LAppTextureManager::TextureInfo* backgroundTexture = textureManager->CreateTextureFromPngFile(resourcesPath + imageName);
1807+
1808+ LAppTextureManager::TextureInfo* backgroundTexture =
1809+ textureManager->CreateTextureFromColor(0, 255, 0);
1810
1811 float x = width * 0.5f;
1812 float y = height * 0.5f;
1813- float fWidth = static_cast<float>(backgroundTexture->width * 2.0f);
1814- float fHeight = static_cast<float>(height * 0.95f);
1815+ float fWidth = static_cast<float>(width);
1816+ float fHeight = static_cast<float>(height);
1817 _back = new LAppSprite(x, y, fWidth, fHeight, backgroundTexture->id, _programId);
1818
1819- imageName = GearImageName;
1820- LAppTextureManager::TextureInfo* gearTexture = textureManager->CreateTextureFromPngFile(resourcesPath + imageName);
1821-
1822- x = static_cast<float>(width - gearTexture->width * 0.5f);
1823- y = static_cast<float>(height - gearTexture->height * 0.5f);
1824- fWidth = static_cast<float>(gearTexture->width);
1825- fHeight = static_cast<float>(gearTexture->height);
1826- _gear = new LAppSprite(x, y, fWidth, fHeight, gearTexture->id, _programId);
1827-
1828- imageName = PowerImageName;
1829- LAppTextureManager::TextureInfo* powerTexture = textureManager->CreateTextureFromPngFile(resourcesPath + imageName);
1830-
1831- x = static_cast<float>(width - powerTexture->width * 0.5f);
1832- y = static_cast<float>(powerTexture->height * 0.5f);
1833- fWidth = static_cast<float>(powerTexture->width);
1834- fHeight = static_cast<float>(powerTexture->height);
1835- _power = new LAppSprite(x, y, fWidth, fHeight, powerTexture->id, _programId);
1836-
1837 // 画面全体を覆うサイズ
1838 x = width * 0.5f;
1839 y = height * 0.5f;
1840 _renderSprite = new LAppSprite(x, y, static_cast<float>(width), static_cast<float>(height), 0, _programId);
1841-}
1842-
1843-void LAppView::OnTouchesBegan(float px, float py) const
1844-{
1845- _touchManager->TouchesBegan(px, py);
1846-}
1847-
1848-void LAppView::OnTouchesMoved(float px, float py) const
1849-{
1850- float viewX = this->TransformViewX(_touchManager->GetX());
1851- float viewY = this->TransformViewY(_touchManager->GetY());
1852-
1853- _touchManager->TouchesMoved(px, py);
1854
1855- LAppLive2DManager* Live2DManager = LAppLive2DManager::GetInstance();
1856- Live2DManager->OnDrag(viewX, viewY);
1857-}
1858-
1859-void LAppView::OnTouchesEnded(float px, float py) const
1860-{
1861- // タッチ終了
1862- LAppLive2DManager* live2DManager = LAppLive2DManager::GetInstance();
1863- live2DManager->OnDrag(0.0f, 0.0f);
1864- {
1865-
1866- // シングルタップ
1867- float x = _deviceToScreen->TransformX(_touchManager->GetX()); // 論理座標変換した座標を取得。
1868- float y = _deviceToScreen->TransformY(_touchManager->GetY()); // 論理座標変換した座標を取得。
1869- if (DebugTouchLogEnable)
1870- {
1871- LAppPal::PrintLog("[APP]touchesEnded x:%.2f y:%.2f", x, y);
1872- }
1873- live2DManager->OnTap(x, y);
1874-
1875- // 歯車にタップしたか
1876- if (_gear->IsHit(px, py))
1877- {
1878- live2DManager->NextScene();
1879- }
1880-
1881- // 電源ボタンにタップしたか
1882- if (_power->IsHit(px, py))
1883- {
1884- LAppDelegate::GetInstance()->AppEnd();
1885- }
1886- }
1887 }
1888
1889 float LAppView::TransformViewX(float deviceX) const
1890@@ -250,7 +180,7 @@ float LAppView::TransformScreenY(float d
1891 return _deviceToScreen->TransformY(deviceY);
1892 }
1893
1894-void LAppView::PreModelDraw(LAppModel& refModel)
1895+void LAppView::PreModelDraw(LAppModel &refModel)
1896 {
1897 // 別のレンダリングターゲットへ向けて描画する場合の使用するフレームバッファ
1898 Csm::Rendering::CubismOffscreenFrame_OpenGLES2* useTarget = NULL;
1899@@ -263,12 +193,13 @@ void LAppView::PreModelDraw(LAppModel& r
1900
1901 if (!useTarget->IsValid())
1902 {// 描画ターゲット内部未作成の場合はここで作成
1903- int width, height;
1904- glfwGetWindowSize(LAppDelegate::GetInstance()->GetWindow(), &width, &height);
1905- if (width != 0 && height != 0)
1906+ int bufWidth, bufHeight;
1907+ glfwGetFramebufferSize(LAppDelegate::GetInstance()->GetWindow(), &bufWidth, &bufHeight);
1908+
1909+ if(bufWidth!=0 && bufHeight!=0)
1910 {
1911 // モデル描画キャンバス
1912- useTarget->CreateOffscreenFrame(static_cast<csmUint32>(width), static_cast<csmUint32>(height));
1913+ useTarget->CreateOffscreenFrame(static_cast<csmUint32>(bufWidth), static_cast<csmUint32>(bufHeight));
1914 }
1915 }
1916
1917@@ -278,7 +209,7 @@ void LAppView::PreModelDraw(LAppModel& r
1918 }
1919 }
1920
1921-void LAppView::PostModelDraw(LAppModel& refModel)
1922+void LAppView::PostModelDraw(LAppModel &refModel)
1923 {
1924 // 別のレンダリングターゲットへ向けて描画する場合の使用するフレームバッファ
1925 Csm::Rendering::CubismOffscreenFrame_OpenGLES2* useTarget = NULL;
1926@@ -368,32 +299,4 @@ void LAppView::ResizeSprite()
1927 _back->ResetRect(x, y, fWidth, fHeight);
1928 }
1929 }
1930-
1931- if (_power)
1932- {
1933- GLuint id = _power->GetTextureId();
1934- LAppTextureManager::TextureInfo* texInfo = textureManager->GetTextureInfoById(id);
1935- if (texInfo)
1936- {
1937- x = static_cast<float>(width - texInfo->width * 0.5f);
1938- y = static_cast<float>(texInfo->height * 0.5f);
1939- fWidth = static_cast<float>(texInfo->width);
1940- fHeight = static_cast<float>(texInfo->height);
1941- _power->ResetRect(x, y, fWidth, fHeight);
1942- }
1943- }
1944-
1945- if (_gear)
1946- {
1947- GLuint id = _gear->GetTextureId();
1948- LAppTextureManager::TextureInfo* texInfo = textureManager->GetTextureInfoById(id);
1949- if (texInfo)
1950- {
1951- x = static_cast<float>(width - texInfo->width * 0.5f);
1952- y = static_cast<float>(height - texInfo->height * 0.5f);
1953- fWidth = static_cast<float>(texInfo->width);
1954- fHeight = static_cast<float>(texInfo->height);
1955- _gear->ResetRect(x, y, fWidth, fHeight);
1956- }
1957- }
1958 }
1959diff -pruN --exclude build ./demo_clean/src/LAppView.hpp ./demo_dev/src/LAppView.hpp
6fd3638f
AIL
1960--- ./demo_clean/src/LAppView.hpp 2023-05-18 09:58:50.000000000 +0100
1961+++ ./demo_dev/src/LAppView.hpp 2023-05-28 08:28:27.500813596 +0100
6d2cd78f
AL
1962@@ -1,4 +1,4 @@
1963-/**
1964+/**
1965 * Copyright(c) Live2D Inc. All rights reserved.
1966 *
1967 * Use of this source code is governed by the Live2D Open Software license
1968@@ -14,7 +14,6 @@
1969 #include "CubismFramework.hpp"
1970 #include <Rendering/OpenGL/CubismOffscreenSurface_OpenGLES2.hpp>
1971
1972-class TouchManager;
1973 class LAppSprite;
1974 class LAppModel;
1975
1976@@ -61,35 +60,11 @@ public:
1977 void InitializeSprite();
1978
1979 /**
1980- * @brief スプライト系のサイズ再設定
1981- */
1982+ * @brief スプライト系のサイズ再設定
1983+ */
1984 void ResizeSprite();
1985
1986 /**
1987- * @brief タッチされたときに呼ばれる。
1988- *
1989- * @param[in] pointX スクリーンX座標
1990- * @param[in] pointY スクリーンY座標
1991- */
1992- void OnTouchesBegan(float pointX, float pointY) const;
1993-
1994- /**
1995- * @brief タッチしているときにポインタが動いたら呼ばれる。
1996- *
1997- * @param[in] pointX スクリーンX座標
1998- * @param[in] pointY スクリーンY座標
1999- */
2000- void OnTouchesMoved(float pointX, float pointY) const;
2001-
2002- /**
2003- * @brief タッチが終了したら呼ばれる。
2004- *
2005- * @param[in] pointX スクリーンX座標
2006- * @param[in] pointY スクリーンY座標
2007- */
2008- void OnTouchesEnded(float pointX, float pointY) const;
2009-
2010- /**
2011 * @brief X座標をView座標に変換する。
2012 *
2013 * @param[in] deviceX デバイスX座標
2014@@ -120,12 +95,12 @@ public:
2015 /**
2016 * @brief モデル1体を描画する直前にコールされる
2017 */
2018- void PreModelDraw(LAppModel& refModel);
2019+ void PreModelDraw(LAppModel &refModel);
2020
2021 /**
2022 * @brief モデル1体を描画した直後にコールされる
2023 */
2024- void PostModelDraw(LAppModel& refModel);
2025+ void PostModelDraw(LAppModel &refModel);
2026
2027 /**
2028 * @brief 別レンダリングターゲットにモデルを描画するサンプルで
2029@@ -147,16 +122,13 @@ public:
2030 void SetRenderTargetClearColor(float r, float g, float b);
2031
2032 private:
2033- TouchManager* _touchManager; ///< タッチマネージャー
2034 Csm::CubismMatrix44* _deviceToScreen; ///< デバイスからスクリーンへの行列
2035 Csm::CubismViewMatrix* _viewMatrix; ///< viewMatrix
2036 GLuint _programId; ///< シェーダID
2037 LAppSprite* _back; ///< 背景画像
2038- LAppSprite* _gear; ///< ギア画像
2039- LAppSprite* _power; ///< 電源画像
2040
2041 // レンダリング先を別ターゲットにする方式の場合に使用
2042- LAppSprite* _renderSprite; ///< モードによっては_renderBufferのテクスチャを描画
2043+ LAppSprite* _renderSprite; ///< モードによっては_renderBufferのテクスチャを描画
2044 Csm::Rendering::CubismOffscreenFrame_OpenGLES2 _renderBuffer; ///< モードによってはCubismモデル結果をこっちにレンダリング
2045 SelectTarget _renderTarget; ///< レンダリング先の選択肢
2046 float _clearColor[4]; ///< レンダリングターゲットのクリアカラー
2047diff -pruN --exclude build ./demo_clean/src/MouseActionManager.cpp ./demo_dev/src/MouseActionManager.cpp
6fd3638f
AIL
2048--- ./demo_clean/src/MouseActionManager.cpp 2023-05-18 09:58:50.000000000 +0100
2049+++ ./demo_dev/src/MouseActionManager.cpp 2023-05-28 08:28:27.500813596 +0100
6d2cd78f
AL
2050@@ -1,9 +1,9 @@
2051-/**
2052- * Copyright(c) Live2D Inc. All rights reserved.
2053- *
2054- * Use of this source code is governed by the Live2D Open Software license
2055- * that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html.
2056- */
2057+/**
2058+* Copyright(c) Live2D Inc. All rights reserved.
2059+*
2060+* Use of this source code is governed by the Live2D Open Software license
2061+* that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html.
2062+*/
2063
2064 #include "MouseActionManager.hpp"
2065
2066@@ -13,7 +13,7 @@ namespace {
2067
2068 MouseActionManager* MouseActionManager::GetInstance()
2069 {
2070- if (instance == NULL)
2071+ if (!instance)
2072 {
2073 instance = new MouseActionManager();
2074 }
2075@@ -23,7 +23,7 @@ MouseActionManager* MouseActionManager::
2076
2077 void MouseActionManager::ReleaseInstance()
2078 {
2079- if (instance != NULL)
2080+ if (instance)
2081 {
2082 delete instance;
2083 }
2084@@ -99,18 +99,21 @@ void MouseActionManager::OnMouseCallBack
2085 return;
2086 }
2087
2088- if (GLFW_PRESS == action)
2089+ switch (action)
2090 {
2091+ case GLFW_PRESS:
2092 _captured = true;
2093 OnTouchesBegan(_mouseX, _mouseY);
2094- }
2095- else if (GLFW_RELEASE == action)
2096- {
2097+ break;
2098+ case GLFW_RELEASE:
2099 if (_captured)
2100 {
2101 _captured = false;
2102 OnTouchesEnded(_mouseX, _mouseY);
2103 }
2104+ break;
2105+ default:
2106+ break;
2107 }
2108 }
2109
2110diff -pruN --exclude build ./demo_clean/src/MouseActionManager.hpp ./demo_dev/src/MouseActionManager.hpp
6fd3638f
AIL
2111--- ./demo_clean/src/MouseActionManager.hpp 2023-05-18 09:58:50.000000000 +0100
2112+++ ./demo_dev/src/MouseActionManager.hpp 2023-05-28 08:28:27.500813596 +0100
6d2cd78f
AL
2113@@ -1,4 +1,4 @@
2114-/**
2115+/**
2116 * Copyright(c) Live2D Inc. All rights reserved.
2117 *
2118 * Use of this source code is governed by the Live2D Open Software license
2119diff -pruN --exclude build ./demo_clean/src/TouchManager.cpp ./demo_dev/src/TouchManager.cpp
6fd3638f
AIL
2120--- ./demo_clean/src/TouchManager.cpp 2023-05-18 09:58:50.000000000 +0100
2121+++ ./demo_dev/src/TouchManager.cpp 2023-05-28 08:28:27.504813669 +0100
6d2cd78f
AL
2122@@ -1,4 +1,4 @@
2123-/**
2124+/**
2125 * Copyright(c) Live2D Inc. All rights reserved.
2126 *
2127 * Use of this source code is governed by the Live2D Open Software license
2128diff -pruN --exclude build ./demo_clean/src/TouchManager.hpp ./demo_dev/src/TouchManager.hpp
6fd3638f
AIL
2129--- ./demo_clean/src/TouchManager.hpp 2023-05-18 09:58:50.000000000 +0100
2130+++ ./demo_dev/src/TouchManager.hpp 2023-05-28 08:28:27.504813669 +0100
6d2cd78f
AL
2131@@ -1,4 +1,4 @@
2132-/**
2133+/**
2134 * Copyright(c) Live2D Inc. All rights reserved.
2135 *
2136 * Use of this source code is governed by the Live2D Open Software license
2137diff -pruN --exclude build ./demo_clean/src/main.cpp ./demo_dev/src/main.cpp
6fd3638f
AIL
2138--- ./demo_clean/src/main.cpp 2023-05-18 09:58:50.000000000 +0100
2139+++ ./demo_dev/src/main.cpp 2023-05-28 08:28:27.504813669 +0100
6d2cd78f
AL
2140@@ -1,22 +1,166 @@
2141-/**
2142+/**
2143 * Copyright(c) Live2D Inc. All rights reserved.
2144 *
2145 * Use of this source code is governed by the Live2D Open Software license
2146 * that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html.
2147 */
2148
2149+#include <thread>
2150+#include <stdexcept>
2151+#include <sstream>
2152+
2153+#ifdef __cpp_lib_filesystem
2154+#include <filesystem>
2155+namespace fs = std::filesystem;
2156+#else
2157+#include <experimental/filesystem>
2158+namespace fs = std::experimental::filesystem;
2159+#endif
2160+
2161+
2162 #include "LAppDelegate.hpp"
2163+#include "LAppLive2DManager.hpp"
2164+#include "facial_landmark_detector.h"
2165
2166-int main()
2167+struct CmdArgs
2168 {
2169- // create the application instance
2170- if (LAppDelegate::GetInstance()->Initialize() == GL_FALSE)
2171+ int windowWidth;
2172+ int windowHeight;
2173+ std::string windowTitle;
2174+ std::string rootDir;
2175+ float scaleFactor;
2176+ float translateX;
2177+ float translateY;
2178+ std::string modelName;
2179+ bool oldId; // If true, translate new (Cubism 3+) parameter IDs to old (Cubism 2.1) IDs
2180+ std::string cfgPath; // Path to config file for FacialLandmarkDetector
2181+};
2182+
2183+CmdArgs parseArgv(int argc, char *argv[])
2184+{
2185+ // I think the command-line args are simple enough to not justify using a library...
2186+ CmdArgs cmdArgs;
2187+ // Set default values
2188+ cmdArgs.windowWidth = 600;
2189+ cmdArgs.windowHeight = 600;
2190+ cmdArgs.windowTitle = "FacialLandmarksForCubism example";
2191+ cmdArgs.rootDir = fs::current_path().string();
2192+ cmdArgs.scaleFactor = 4.5f;
2193+ cmdArgs.translateX = 0.0f;
2194+ cmdArgs.translateY = -3.1f;
2195+ cmdArgs.modelName = "Haru";
2196+ cmdArgs.oldId = false;
2197+ cmdArgs.cfgPath = "";
2198+
2199+ int i = 1;
2200+ while (i < argc)
2201 {
2202- return 1;
2203+ std::string arg = argv[i];
2204+ std::stringstream ss;
2205+
2206+ if (arg == "--window-width" || arg == "-W") // capital W for consistency with height
2207+ {
2208+ ss << argv[i + 1];
2209+ if (!(ss >> cmdArgs.windowWidth))
2210+ {
2211+ throw std::runtime_error("Invalid argument for window width");
2212+ }
2213+ }
2214+ else if (arg == "--window-height" || arg == "-H") // avoiding "-h", typically for help
2215+ {
2216+ ss << argv[i + 1];
2217+ if (!(ss >> cmdArgs.windowHeight))
2218+ {
2219+ throw std::runtime_error("Invalid argument for window height");
2220+ }
2221+ }
2222+ else if (arg == "--window-title" || arg == "-t")
2223+ {
2224+ cmdArgs.windowTitle = argv[i + 1];
2225+ }
2226+ else if (arg == "--root-dir" || arg == "-d")
2227+ {
2228+ cmdArgs.rootDir = argv[i + 1];
2229+ }
2230+ else if (arg == "--scale-factor" || arg == "-f")
2231+ {
2232+ ss << argv[i + 1];
2233+ if (!(ss >> cmdArgs.scaleFactor))
2234+ {
2235+ throw std::runtime_error("Invalid argument for scale factor");
2236+ }
2237+ }
2238+ else if (arg == "--translate-x" || arg == "-x")
2239+ {
2240+ ss << argv[i + 1];
2241+ if (!(ss >> cmdArgs.translateX))
2242+ {
2243+ throw std::runtime_error("Invalid argument for translate X");
2244+ }
2245+ }
2246+ else if (arg == "--translate-y" || arg == "-y")
2247+ {
2248+ ss << argv[i + 1];
2249+ if (!(ss >> cmdArgs.translateY))
2250+ {
2251+ throw std::runtime_error("Invalid argument for translate Y");
2252+ }
2253+ }
2254+ else if (arg == "--model" || arg == "-m")
2255+ {
2256+ cmdArgs.modelName = argv[i + 1];
2257+ }
2258+ else if (arg == "--config" || arg == "-c")
2259+ {
2260+ cmdArgs.cfgPath = argv[i + 1];
2261+ }
2262+ else if (arg == "--old-param-id" || arg == "-o")
2263+ {
2264+ cmdArgs.oldId = (argv[i + 1][0] == '1');
2265+ }
2266+ else
2267+ {
2268+ throw std::runtime_error("Unrecognized argument: " + arg);
2269+ }
2270+
2271+ i += 2;
2272 }
2273
2274- LAppDelegate::GetInstance()->Run();
2275+ return cmdArgs;
2276+}
2277+
2278+int main(int argc, char* argv[])
2279+{
2280+ auto cmdArgs = parseArgv(argc, argv);
2281+
2282+ LAppDelegate *delegate = LAppDelegate::GetInstance();
2283+
2284+ if (!delegate->Initialize(cmdArgs.windowWidth,
2285+ cmdArgs.windowHeight,
2286+ cmdArgs.windowTitle.c_str()))
2287+ {
2288+ throw std::runtime_error("Unable to initialize LAppDelegate");
2289+ }
2290+
2291+ delegate->SetRootDirectory(cmdArgs.rootDir);
2292+
2293+ FacialLandmarkDetector detector(cmdArgs.cfgPath);
2294+
2295+ std::thread detectorThread(&FacialLandmarkDetector::mainLoop,
2296+ &detector);
2297+
2298+ LAppLive2DManager *manager = LAppLive2DManager::GetInstance();
2299+ manager->SetModel(cmdArgs.modelName, cmdArgs.oldId);
2300+
2301+ manager->SetProjectionScaleTranslate(cmdArgs.scaleFactor,
2302+ cmdArgs.translateX,
2303+ cmdArgs.translateY);
2304+ manager->SetFacialLandmarkDetector(&detector);
2305+
2306+ delegate->Run();
2307+
2308+ detector.stop();
2309+ detectorThread.join();
2310
2311 return 0;
2312 }
2313-
2314diff -pruN --exclude build ./demo_clean/src/mainMinimum.cpp ./demo_dev/src/mainMinimum.cpp
6fd3638f
AIL
2315--- ./demo_clean/src/mainMinimum.cpp 2023-05-18 09:58:50.000000000 +0100
2316+++ ./demo_dev/src/mainMinimum.cpp 2023-05-28 08:28:27.504813669 +0100
6d2cd78f
AL
2317@@ -1,4 +1,4 @@
2318-/**
2319+/**
2320 * Copyright(c) Live2D Inc. All rights reserved.
2321 *
2322 * Use of this source code is governed by the Live2D Open Software license
2323@@ -7,7 +7,8 @@
2324
2325 #include <functional>
2326
2327-#include <stb_image.h>
2328+#include <sstream>
2329+#include <unistd.h>
2330 #include <GL/glew.h>
2331 #include <GLFW/glfw3.h>
2332
2333@@ -15,19 +16,15 @@
2334 #include "LAppAllocator.hpp"
2335 #include "LAppTextureManager.hpp"
2336 #include "LAppPal.hpp"
2337-#include "TouchManager.hpp"
2338 #include "CubismUserModelExtend.hpp"
2339-#include "CubismSampleViewMatrix.hpp"
2340 #include "MouseActionManager.hpp"
2341
2342 #include <CubismFramework.hpp>
2343-#include <CubismDefaultParameterId.hpp>
2344 #include <CubismModelSettingJson.hpp>
2345 #include <Model/CubismUserModel.hpp>
2346 #include <Physics/CubismPhysics.hpp>
2347 #include <Rendering/OpenGL/CubismRenderer_OpenGLES2.hpp>
2348 #include <Utils/CubismString.hpp>
2349-#include <Math/CubismViewMatrix.hpp>
2350
2351 /**
2352 *@brief モデルデータのディレクトリ名
2353@@ -36,8 +33,6 @@
2354 static const Csm::csmChar* _modelDirectoryName = "Hiyori";
2355
2356 static Csm::CubismUserModel* _userModel; ///< ユーザーが実際に使用するモデル
2357-static Csm::CubismModelSettingJson* _modelJson; ///< モデルの設定情報
2358-static Csm::CubismModel* _model; ///< Mocデータから作成されるモデルデータ
2359
2360 Csm::csmFloat32 _userTimeSeconds; ///< デルタ時間の積算値[秒]
2361 Csm::csmVector<Csm::CubismIdHandle> _eyeBlinkIds; ///< モデルに設定されたまばたき機能用パラメータID
2362@@ -66,8 +61,8 @@ static LAppAllocator _cubismAllocator; /
2363
2364 static LAppTextureManager* _textureManager; ///< テクスチャの管理
2365
2366+static std::string _rootDirectory; ///< ルートディレクトリ
2367 static std::string _currentModelDirectory; ///< 現在のモデルのディレクトリ名
2368-const Csm::csmChar* _currentModelDirectoryChar; ///< 現在のモデルのディレクトリ名のconst csmCharポインタ型
2369
2370 static GLFWwindow* _window; ///< ウィンドウオブジェクト
2371
2372@@ -90,6 +85,59 @@ static void InitializeCubism()
2373 }
2374
2375 /**
2376+* @brief 文字列の分割
2377+*
2378+* 指定された区切り文字で文字列を分割する
2379+*/
2380+Csm::csmVector<std::string> Split(const std::string& baseString, char delimiter)
2381+{
2382+ Csm::csmVector < std::string > elems;
2383+ std::stringstream ss(baseString);
2384+ std::string item;
2385+
2386+ while (getline(ss, item, delimiter))
2387+ {
2388+ if (!item.empty())
2389+ {
2390+ elems.PushBack(item);
2391+ }
2392+ }
2393+
2394+ return elems;
2395+}
2396+
2397+/**
2398+* @brief ルートディレクトリの設定
2399+*
2400+* Linuxのルートディレクトリを確認し、パスを取得する
2401+*/
2402+void SetRootDirectory()
2403+{
2404+ const int maximumPathBufferSize = 1024;
2405+ char path[maximumPathBufferSize];
2406+ ssize_t len = readlink("/proc/self/exe", path, maximumPathBufferSize - 1);
2407+
2408+ if (len != -1)
2409+ {
2410+ path[len] = '\0';
2411+ }
2412+
2413+ std::string pathString(path);
2414+
2415+ pathString = pathString.substr(0, pathString.rfind("Demo"));
2416+ Csm::csmVector<std::string> splitStrings = Split(pathString, '/');
2417+
2418+ _rootDirectory = "";
2419+
2420+ for (int i = 0; i < splitStrings.GetSize(); i++)
2421+ {
2422+ _rootDirectory += "/" + splitStrings[i];
2423+ }
2424+
2425+ _rootDirectory += "/";
2426+}
2427+
2428+/**
2429 * @brief システムの初期化
2430 *
2431 * 基盤システムの初期化処理を行う
2432@@ -149,6 +197,8 @@ static bool InitializeSystem()
2433 // ドラッグ入力管理クラスの初期化
2434 MouseActionManager::GetInstance()->Initialize(windowWidth, windowHeight);
2435
2436+ SetRootDirectory();
2437+
2438 return GL_TRUE;
2439 }
2440
2441@@ -182,16 +232,6 @@ void Release()
2442 }
2443
2444 /**
2445-* @brief ディレクトリパスの設定
2446-*
2447-* モデルのディレクトリパスを設定する
2448-*/
2449-void SetAssetDirectory(const std::string& path)
2450-{
2451- _currentModelDirectory = path;
2452-}
2453-
2454-/**
2455 * @brief モデルの読み込み
2456 *
2457 * モデルデータの読み込み処理を行う
2458@@ -201,13 +241,15 @@ void SetAssetDirectory(const std::string
2459 void LoadModel(const std::string modelDirectoryName)
2460 {
2461 // モデルのディレクトリを指定
2462- SetAssetDirectory(LAppDefine::ResourcesPath + modelDirectoryName + "/");
2463+ _currentModelDirectory = _rootDirectory + LAppDefine::ResourcesPath + modelDirectoryName + "/";
2464
2465 // モデルデータの新規生成
2466 _userModel = new CubismUserModelExtend(modelDirectoryName, _currentModelDirectory);
2467
2468 // モデルデータの読み込み及び生成とセットアップを行う
2469- static_cast<CubismUserModelExtend*>(_userModel)->SetupModel();
2470+ std::string json = ".model3.json";
2471+ std::string fileName = _modelDirectoryName + json;
2472+ static_cast<CubismUserModelExtend*>(_userModel)->LoadAssets(fileName.c_str());
2473
2474 // ユーザーモデルをMouseActionManagerへ渡す
2475 MouseActionManager::GetInstance()->SetUserModel(_userModel);