1 diff -pruN --exclude build ./demo_clean/CMakeLists.txt ./demo_dev/CMakeLists.txt
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
4 @@ -9,7 +9,7 @@ option(
8 -set(SDK_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../..)
9 +set(SDK_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../CubismSdkForNative-4-r.7)
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)
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)
22 @@ -113,6 +113,9 @@ target_link_libraries(Framework Live2DCu
23 # Find opengl libraries.
24 find_package(OpenGL REQUIRED)
26 +# Add FacialLandmarksForCubism
27 +add_subdirectory(../.. FacialLandmarksForCubism_build)
29 # Make executable app.
30 add_executable(${APP_NAME})
32 @@ -122,12 +125,14 @@ target_link_libraries(${APP_NAME}
36 + FacialLandmarksForCubism
38 # Solve the MSVCRT confliction.
39 debug -NODEFAULTLIB:libcmtd.lib
40 optimized -NODEFAULTLIB:libcmt.lib
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)
48 diff -pruN --exclude build ./demo_clean/src/CMakeLists.txt ./demo_dev/src/CMakeLists.txt
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
52 -if (CSM_MINIMUM_DEMO)
53 - target_sources(${APP_NAME}
54 +target_sources(${APP_NAME}
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
83 - target_sources(${APP_NAME}
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
110 + ${CMAKE_CURRENT_SOURCE_DIR}/LAppView.cpp
111 + ${CMAKE_CURRENT_SOURCE_DIR}/LAppView.hpp
112 + ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp
114 diff -pruN --exclude build ./demo_clean/src/CubismUserModelExtend.cpp ./demo_dev/src/CubismUserModelExtend.cpp
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
120 * Copyright(c) Live2D Inc. All rights reserved.
122 * Use of this source code is governed by the Live2D Open Software license
124 #include "CubismUserModelExtend.hpp"
126 using namespace Live2D::Cubism::Framework;
127 -using namespace Live2D::Cubism::Framework::DefaultParameterId;
128 +using namespace DefaultParameterId;
129 using namespace LAppDefine;
132 @@ -74,34 +74,17 @@ CubismUserModelExtend::~CubismUserModelE
133 delete _textureManager;
136 -std::string CubismUserModelExtend::MakeAssetPath(const std::string& assetFileName)
138 - return _currentModelDirectory + assetFileName;
141 -void CubismUserModelExtend::SetAssetDirectory(const std::string& path)
143 - _currentModelDirectory = path;
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)
149 - Csm::csmSizeInt bufferSize = 0;
150 - Csm::csmByte* buffer = nullptr;
152 - if (fiileName.empty())
158 - buffer = LAppPal::LoadFileAsBytes(MakeAssetPath(fiileName).c_str(), &bufferSize);
160 + const csmString path = csmString(_currentModelDirectory.c_str()) + fileName;
163 - afterLoadCallback(buffer, bufferSize);
164 + csmByte* buffer = CreateBuffer(path.GetRawString(), &size);
165 + _modelJson = new CubismModelSettingJson(buffer, size);
166 + DeleteBuffer(buffer, path.GetRawString());
169 - LAppPal::ReleaseBytes(buffer);
174 void CubismUserModelExtend::SetupModel()
175 @@ -109,40 +92,75 @@ void CubismUserModelExtend::SetupModel()
177 _initialized = false;
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); });
187 + if (strcmp(_modelJson->GetModelFileName(), ""))
189 + csmString path = _modelJson->GetModelFileName();
190 + path = csmString(_currentModelDirectory.c_str()) + path;
192 + buffer = CreateBuffer(path.GetRawString(), &size);
193 + LoadModel(buffer, size);
194 + DeleteBuffer(buffer, path.GetRawString());
198 - for (auto expressionIndex = 0; expressionIndex < _modelJson->GetExpressionCount(); ++expressionIndex)
199 + if (_modelJson->GetExpressionCount() > 0)
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++)
208 + csmString name = _modelJson->GetExpressionName(i);
209 + csmString path = _modelJson->GetExpressionFileName(i);
210 + path = csmString(_currentModelDirectory.c_str()) + path;
212 + buffer = CreateBuffer(path.GetRawString(), &size);
213 + ACubismMotion* motion = LoadExpression(buffer, size, name.GetRawString());
215 + if (_expressions[name])
217 - ACubismMotion::Delete(_expressions[expressionName]);
218 - _expressions[expressionName] = nullptr;
219 + ACubismMotion::Delete(_expressions[name]);
220 + _expressions[name] = nullptr;
222 - _expressions[expressionName] = motion;
224 + _expressions[name] = motion;
226 + DeleteBuffer(buffer, path.GetRawString());
231 - LoadAsset(_modelJson->GetPoseFileName(), [=](Csm::csmByte* buffer, Csm::csmSizeInt bufferSize) {
232 - LoadPose(buffer, bufferSize);
234 + if (strcmp(_modelJson->GetPoseFileName(), ""))
236 + csmString path = _modelJson->GetPoseFileName();
237 + path = csmString(_currentModelDirectory.c_str()) + path;
239 + buffer = CreateBuffer(path.GetRawString(), &size);
240 + LoadPose(buffer, size);
241 + DeleteBuffer(buffer, path.GetRawString());
245 - LoadAsset(_modelJson->GetPhysicsFileName(), [=](Csm::csmByte* buffer, Csm::csmSizeInt bufferSize) {
246 - LoadPhysics(buffer, bufferSize);
248 + if (strcmp(_modelJson->GetPhysicsFileName(), ""))
250 + csmString path = _modelJson->GetPhysicsFileName();
251 + path = csmString(_currentModelDirectory.c_str()) + path;
253 + buffer = CreateBuffer(path.GetRawString(), &size);
254 + LoadPhysics(buffer, size);
255 + DeleteBuffer(buffer, path.GetRawString());
258 // モデルに付属するユーザーデータの読み込み
259 - LoadAsset(_modelJson->GetUserDataFile(), [=](Csm::csmByte* buffer, Csm::csmSizeInt bufferSize) {
260 - LoadUserData(buffer, bufferSize);
262 + if (strcmp(_modelJson->GetUserDataFile(), ""))
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());
272 csmMap<csmString, csmFloat32> layout;
273 @@ -345,16 +363,6 @@ void CubismUserModelExtend::ModelParamUp
274 _model->SaveParameters();
275 //-----------------------------------------------------------------
277 - // メインモーションの更新がないとき
278 - if (!motionUpdated)
283 - _eyeBlink->UpdateParameters(_model, deltaTimeSeconds);
287 if (_expressionManager)
290 @@ -377,12 +385,6 @@ void CubismUserModelExtend::ModelParamUp
291 _model->AddParameterValue(_idParamEyeBallX, _dragX); // -1から1の値を加える
292 _model->AddParameterValue(_idParamEyeBallY, _dragY);
297 - _breath->UpdateParameters(_model, deltaTimeSeconds);
303 diff -pruN --exclude build ./demo_clean/src/CubismUserModelExtend.hpp ./demo_dev/src/CubismUserModelExtend.hpp
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
306 @@ -27,17 +27,13 @@ class CubismUserModelExtend :
309 CubismUserModelExtend(const std::string modelDirectoryName, const std::string _currentModelDirectory); ///< コンストラクタ
310 - virtual ~CubismUserModelExtend(); ///< デストラクタ
311 + ~CubismUserModelExtend(); ///< デストラクタ
314 - * @brief model3.jsonからモデルを生成する
316 - * model3.jsonの記述に従ってモデル生成、モーション、物理演算などのコンポーネント生成を行う
318 - * @param[in] setting ICubismModelSettingのインスタンス
319 + * @brief model3.jsonが置かれたディレクトリとファイルパスからモデルを生成する
323 + void LoadAssets(const Csm::csmChar* fileName);
327 @@ -48,35 +44,24 @@ public:
332 + * @brief model3.jsonからモデルを生成する
336 - std::string MakeAssetPath(const std::string & assetFileName);
339 - * @brief ディレクトリパスの設定
340 + * model3.jsonの記述に従ってモデル生成、モーション、物理演算などのコンポーネント生成を行う
342 + * @param[in] setting ICubismModelSettingのインスタンス
344 - * モデルのディレクトリパスを設定する
346 - void SetAssetDirectory(const std::string & path);
350 - * @brief アセットのロードを行う
351 + * @brief 引数で指定したモーションの再生を開始する
353 - * 指定されたファイル名からアセットのロードを行う
354 + * @param[in] group モーショングループ名
355 + * @param[in] no グループ内の番号
356 + * @param[in] priority 優先度
357 + * @param[in] onFinishedMotionHandler モーション再生終了時に呼び出されるコールバック関数。NULLの場合、呼び出されない。
358 + * @return 開始したモーションの識別番号を返す。個別のモーションが終了したか否かを判定するIsFinished()の引数で使用する。開始できない時は「-1」
360 - void LoadAsset(const std::string & fiileName, const std::function<void(Csm::csmByte*, Csm::csmSizeInt)>& afterLoadCallback);
363 - * @brief 引数で指定したモーションの再生を開始する
365 - * @param[in] group モーショングループ名
366 - * @param[in] no グループ内の番号
367 - * @param[in] priority 優先度
368 - * @param[in] onFinishedMotionHandler モーション再生終了時に呼び出されるコールバック関数。NULLの場合、呼び出されない。
369 - * @return 開始したモーションの識別番号を返す。個別のモーションが終了したか否かを判定するIsFinished()の引数で使用する。開始できない時は「-1」
371 Csm::CubismMotionQueueEntryHandle StartMotion(const Csm::csmChar* group, Csm::csmInt32 no, Csm::csmInt32 priority, Csm::ACubismMotion::FinishedMotionCallback onFinishedMotionHandler = NULL);
374 diff -pruN --exclude build ./demo_clean/src/LAppAllocator.cpp ./demo_dev/src/LAppAllocator.cpp
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
380 * Copyright(c) Live2D Inc. All rights reserved.
382 * Use of this source code is governed by the Live2D Open Software license
387 -void* LAppAllocator::Allocate(const csmSizeType size)
388 +void* LAppAllocator::Allocate(const csmSizeType size)
392 diff -pruN --exclude build ./demo_clean/src/LAppAllocator.hpp ./demo_dev/src/LAppAllocator.hpp
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
398 * Copyright(c) Live2D Inc. All rights reserved.
400 * Use of this source code is governed by the Live2D Open Software license
401 diff -pruN --exclude build ./demo_clean/src/LAppDefine.cpp ./demo_dev/src/LAppDefine.cpp
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
407 * Copyright(c) Live2D Inc. All rights reserved.
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;
417 const csmFloat32 ViewLogicalMaxLeft = -2.0f;
418 const csmFloat32 ViewLogicalMaxRight = 2.0f;
419 diff -pruN --exclude build ./demo_clean/src/LAppDefine.hpp ./demo_dev/src/LAppDefine.hpp
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
425 * Copyright(c) Live2D Inc. All rights reserved.
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.
433 #include <CubismFramework.hpp>
434 diff -pruN --exclude build ./demo_clean/src/LAppDelegate.cpp ./demo_dev/src/LAppDelegate.cpp
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
440 * Copyright(c) Live2D Inc. All rights reserved.
442 * Use of this source code is governed by the Live2D Open Software license
445 #include "LAppDelegate.hpp"
449 #include <GLFW/glfw3.h>
450 #include "LAppView.hpp"
451 @@ -43,7 +44,8 @@ void LAppDelegate::ReleaseInstance()
455 -bool LAppDelegate::Initialize()
456 +bool LAppDelegate::Initialize(int initWindowWidth, int initWindowHeight,
457 + const char *windowTitle)
461 @@ -61,7 +63,13 @@ bool LAppDelegate::Initialize()
465 - _window = glfwCreateWindow(RenderTargetWidth, RenderTargetHeight, "SAMPLE", NULL, NULL);
466 + _window = glfwCreateWindow(
467 + initWindowWidth ? initWindowWidth : RenderTargetWidth,
468 + initWindowHeight ? initWindowHeight : RenderTargetHeight,
469 + windowTitle ? windowTitle : "SAMPLE",
476 @@ -93,10 +101,6 @@ bool LAppDelegate::Initialize()
478 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
481 - glfwSetMouseButtonCallback(_window, EventHandler::OnMouseCallBack);
482 - glfwSetCursorPosCallback(_window, EventHandler::OnMouseCallBack);
486 glfwGetWindowSize(LAppDelegate::GetInstance()->GetWindow(), &width, &height);
487 @@ -106,9 +110,15 @@ bool LAppDelegate::Initialize()
496 + LAppLive2DManager::GetInstance();
499 + _view->InitializeSprite();
504 @@ -125,7 +135,7 @@ void LAppDelegate::Release()
506 LAppLive2DManager::ReleaseInstance();
510 CubismFramework::Dispose();
513 @@ -136,18 +146,13 @@ void LAppDelegate::Run()
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)
523 _view->ResizeSprite();
526 _windowWidth = width;
527 _windowHeight = height;
530 - glViewport(0, 0, width, height);
534 @@ -183,6 +188,7 @@ LAppDelegate::LAppDelegate():
538 + _rootDirectory = "";
539 _view = new LAppView();
540 _textureManager = new LAppTextureManager();
542 @@ -202,58 +208,10 @@ void LAppDelegate::InitializeCubism()
544 CubismFramework::Initialize();
547 - LAppLive2DManager::GetInstance();
550 CubismMatrix44 projection;
552 LAppPal::UpdateTime();
554 - _view->InitializeSprite();
557 -void LAppDelegate::OnMouseCallBack(GLFWwindow* window, int button, int action, int modify)
563 - if (GLFW_MOUSE_BUTTON_LEFT != button)
568 - if (GLFW_PRESS == action)
571 - _view->OnTouchesBegan(_mouseX, _mouseY);
573 - else if (GLFW_RELEASE == action)
578 - _view->OnTouchesEnded(_mouseX, _mouseY);
583 -void LAppDelegate::OnMouseCallBack(GLFWwindow* window, double x, double y)
585 - _mouseX = static_cast<float>(x);
586 - _mouseY = static_cast<float>(y);
597 - _view->OnTouchesMoved(_mouseX, _mouseY);
600 GLuint LAppDelegate::CreateShader()
601 @@ -271,10 +229,6 @@ GLuint LAppDelegate::CreateShader()
603 glShaderSource(vertexShaderId, 1, &vertexShader, NULL);
604 glCompileShader(vertexShaderId);
605 - if(!CheckShader(vertexShaderId))
611 GLuint fragmentShaderId = glCreateShader(GL_FRAGMENT_SHADER);
612 @@ -288,10 +242,6 @@ GLuint LAppDelegate::CreateShader()
614 glShaderSource(fragmentShaderId, 1, &fragmentShader, NULL);
615 glCompileShader(fragmentShaderId);
616 - if (!CheckShader(fragmentShaderId))
622 GLuint programId = glCreateProgram();
623 @@ -306,25 +256,24 @@ GLuint LAppDelegate::CreateShader()
627 -bool LAppDelegate::CheckShader(GLuint shaderId)
628 +void LAppDelegate::SetRootDirectory(std::string rootDir)
632 - glGetShaderiv(shaderId, GL_INFO_LOG_LENGTH, &logLength);
635 - GLchar* log = reinterpret_cast<GLchar*>(CSM_MALLOC(logLength));
636 - glGetShaderInfoLog(shaderId, logLength, &logLength, log);
637 - CubismLogError("Shader compile log: %s", log);
640 + this->_rootDirectory = rootDir + "/";
643 +Csm::csmVector<string> LAppDelegate::Split(const std::string& baseString, char delimiter)
645 + Csm::csmVector<string> elems;
646 + stringstream ss(baseString);
649 - glGetShaderiv(shaderId, GL_COMPILE_STATUS, &status);
650 - if (status == GL_FALSE)
651 + while(getline(ss, item, delimiter))
653 - glDeleteShader(shaderId);
657 + elems.PushBack(item);
664 diff -pruN --exclude build ./demo_clean/src/LAppDelegate.hpp ./demo_dev/src/LAppDelegate.hpp
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
670 * Copyright(c) Live2D Inc. All rights reserved.
672 * Use of this source code is governed by the Live2D Open Software license
679 #include <GLFW/glfw3.h>
680 +#include "Type/csmVector.hpp"
681 #include "LAppAllocator.hpp"
684 @@ -16,7 +18,7 @@ class LAppTextureManager;
687 * @brief アプリケーションクラス。
688 -* Cubism SDK の管理を行う。
693 @@ -38,7 +40,8 @@ public:
695 * @brief APPに必要なものを初期化する。
698 + bool Initialize(int initWindowWidth = 0, int initWindowHeight = 0,
699 + const char *windowTitle = "SAMPLE");
703 @@ -51,25 +54,6 @@ public:
707 - * @brief OpenGL用 glfwSetMouseButtonCallback用関数。
709 - * @param[in] window コールバックを呼んだWindow情報
710 - * @param[in] button ボタン種類
711 - * @param[in] action 実行結果
712 - * @param[in] modify
714 - void OnMouseCallBack(GLFWwindow* window, int button, int action, int modify);
717 - * @brief OpenGL用 glfwSetCursorPosCallback用関数。
719 - * @param[in] window コールバックを呼んだWindow情報
723 - void OnMouseCallBack(GLFWwindow* window, double x, double y);
728 GLuint CreateShader();
729 @@ -94,6 +78,21 @@ public:
731 void AppEnd() { _isEnd = true; }
734 + * @brief ルートディレクトリを設定する。
736 + * @param[in] rootDir : The root directory to set to.
738 + void SetRootDirectory(std::string rootDir);
741 + * @brief ルートディレクトリを取得する。
743 + std::string GetRootDirectory(){ return _rootDirectory;}
746 + * @brief テクスチャマネージャーを取得する。
748 LAppTextureManager* GetTextureManager() { return _textureManager; }
751 @@ -108,17 +107,17 @@ private:
755 - * @brief Cubism SDK の初期化
756 + * @brief Cubism3の初期化
758 void InitializeCubism();
761 - * @brief CreateShader内部関数 エラーチェック
762 + * @brief 文字列を指定の文字で切り分ける
764 - bool CheckShader(GLuint shaderId);
765 + Csm::csmVector<std::string> Split(const std::string& baseString, char delim);
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; ///< ルートディレクトリ
780 int _windowWidth; ///< Initialize関数で設定したウィンドウ幅
781 int _windowHeight; ///< Initialize関数で設定したウィンドウ高さ
788 - * @brief glfwSetMouseButtonCallback用コールバック関数。
790 - static void OnMouseCallBack(GLFWwindow* window, int button, int action, int modify)
792 - LAppDelegate::GetInstance()->OnMouseCallBack(window, button, action, modify);
796 - * @brief glfwSetCursorPosCallback用コールバック関数。
798 - static void OnMouseCallBack(GLFWwindow* window, double x, double y)
800 - LAppDelegate::GetInstance()->OnMouseCallBack(window, x, y);
804 diff -pruN --exclude build ./demo_clean/src/LAppLive2DManager.cpp ./demo_dev/src/LAppLive2DManager.cpp
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
810 * Copyright(c) Live2D Inc. All rights reserved.
812 * Use of this source code is governed by the Live2D Open Software license
814 #include "LAppDelegate.hpp"
815 #include "LAppModel.hpp"
816 #include "LAppView.hpp"
817 +#include "LAppSprite.hpp"
820 using namespace LAppDefine;
821 @@ -51,11 +52,11 @@ void LAppLive2DManager::ReleaseInstance(
823 LAppLive2DManager::LAppLive2DManager()
826 + , _projScaleFactor(1.0f)
827 + , _translateX(0.0f)
828 + , _translateY(0.0f)
830 _viewMatrix = new CubismMatrix44();
832 - ChangeScene(_sceneIndex);
835 LAppLive2DManager::~LAppLive2DManager()
836 @@ -99,26 +100,6 @@ void LAppLive2DManager::OnTap(csmFloat32
838 LAppPal::PrintLog("[APP]tap point: {x:%.2f y:%.2f}", x, y);
841 - for (csmUint32 i = 0; i < _models.GetSize(); i++)
843 - if (_models[i]->HitTest(HitAreaNameHead, x, y))
845 - if (DebugLogEnable)
847 - LAppPal::PrintLog("[APP]hit area: [%s]", HitAreaNameHead);
849 - _models[i]->SetRandomExpression();
851 - else if (_models[i]->HitTest(HitAreaNameBody, x, y))
853 - if (DebugLogEnable)
855 - LAppPal::PrintLog("[APP]hit area: [%s]", HitAreaNameBody);
857 - _models[i]->StartRandomMotion(MotionGroupTapBody, PriorityNormal, FinishedMotion);
862 void LAppLive2DManager::OnUpdate() const
863 @@ -126,10 +107,10 @@ void LAppLive2DManager::OnUpdate() const
865 glfwGetWindowSize(LAppDelegate::GetInstance()->GetWindow(), &width, &height);
867 + CubismMatrix44 projection;
868 csmUint32 modelCount = _models.GetSize();
869 for (csmUint32 i = 0; i < modelCount; ++i)
871 - CubismMatrix44 projection;
872 LAppModel* model = GetModel(i);
874 if (model->GetModel() == NULL)
875 @@ -142,12 +123,15 @@ void LAppLive2DManager::OnUpdate() const
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));
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),
889 + projection.Translate(_translateX, _translateY);
892 if (_viewMatrix != NULL)
893 @@ -155,41 +139,23 @@ void LAppLive2DManager::OnUpdate() const
894 projection.MultiplyByMatrix(_viewMatrix);
898 LAppDelegate::GetInstance()->GetView()->PreModelDraw(*model);
901 model->Draw(projection);///< 参照渡しなのでprojectionは変質する
904 LAppDelegate::GetInstance()->GetView()->PostModelDraw(*model);
908 -void LAppLive2DManager::NextScene()
910 - csmInt32 no = (_sceneIndex + 1) % ModelDirSize;
914 -void LAppLive2DManager::ChangeScene(Csm::csmInt32 index)
915 +void LAppLive2DManager::SetModel(std::string modelName, bool useOldParamId)
917 - _sceneIndex = index;
918 - if (DebugLogEnable)
920 - LAppPal::PrintLog("[APP]model index: %d", _sceneIndex);
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";
934 - _models.PushBack(new LAppModel());
935 + _models.PushBack(new LAppModel(useOldParamId));
936 _models[0]->LoadAssets(modelPath.c_str(), modelJsonName.c_str());
939 @@ -211,16 +177,21 @@ void LAppLive2DManager::ChangeScene(Csm:
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);
949 + float clearColor[3] = { 1.0f, 1.0f, 1.0f };
951 LAppDelegate::GetInstance()->GetView()->SwitchRenderingTarget(useRenderTarget);
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)
958 + LAppDelegate::GetInstance()->GetView()->SwitchRenderingTarget(useRenderTarget);
960 + LAppDelegate::GetInstance()->GetView()->SetRenderTargetClearColor(clearColor[0], clearColor[1], clearColor[2]);
965 @@ -235,3 +206,20 @@ void LAppLive2DManager::SetViewMatrix(Cu
966 _viewMatrix->GetArray()[i] = m->GetArray()[i];
970 +void LAppLive2DManager::SetFacialLandmarkDetector(FacialLandmarkDetector *detector)
972 + for (auto it = _models.Begin(); it != _models.End(); ++it)
974 + (*it)->SetFacialLandmarkDetector(detector);
978 +void LAppLive2DManager::SetProjectionScaleTranslate(float scaleFactor,
982 + _projScaleFactor = scaleFactor;
983 + _translateX = translateX;
984 + _translateY = translateY;
986 diff -pruN --exclude build ./demo_clean/src/LAppLive2DManager.hpp ./demo_dev/src/LAppLive2DManager.hpp
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
992 * Copyright(c) Live2D Inc. All rights reserved.
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.
1001 #include <CubismFramework.hpp>
1002 #include <Math/CubismMatrix44.hpp>
1003 #include <Type/csmVector.hpp>
1007 +class FacialLandmarkDetector;
1010 * @brief サンプルアプリケーションにおいてCubismModelを管理するクラス<br>
1011 * モデル生成と破棄、タップイベントの処理、モデル切り替えを行う。
1012 @@ -73,16 +75,14 @@ public:
1013 void OnUpdate() const;
1016 - * @brief 次のシーンに切り替える<br>
1017 - * サンプルアプリケーションではモデルセットの切り替えを行う。
1022 - * @brief シーンを切り替える<br>
1023 - * サンプルアプリケーションではモデルセットの切り替えを行う。
1025 - void ChangeScene(Csm::csmInt32 index);
1026 + * @brief Set model data
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
1033 + void SetModel(std::string modelName, bool useOldParamId);
1037 @@ -95,6 +95,24 @@ public:
1039 void SetViewMatrix(Live2D::Cubism::Framework::CubismMatrix44* m);
1042 + * @brief Set the pointer to the FacialLandmarkDetector instance
1044 + * @param[in] detector : Pointer to FacialLandmarkDetector instance
1046 + void SetFacialLandmarkDetector(FacialLandmarkDetector *detector);
1049 + * @brief Set projection scale factor and translation parameters
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
1055 + void SetProjectionScaleTranslate(float scaleFactor,
1057 + float translateY);
1062 @@ -108,5 +126,8 @@ private:
1064 Csm::CubismMatrix44* _viewMatrix; ///< モデル描画に用いるView行列
1065 Csm::csmVector<LAppModel*> _models; ///< モデルインスタンスのコンテナ
1066 - Csm::csmInt32 _sceneIndex; ///< 表示するシーンのインデックス値
1068 + float _projScaleFactor;
1069 + float _translateX;
1070 + float _translateY;
1072 diff -pruN --exclude build ./demo_clean/src/LAppModel.cpp ./demo_dev/src/LAppModel.cpp
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
1078 * Copyright(c) Live2D Inc. All rights reserved.
1080 * Use of this source code is governed by the Live2D Open Software license
1082 #include "LAppTextureManager.hpp"
1083 #include "LAppDelegate.hpp"
1085 +#include "facial_landmark_detector.h"
1087 using namespace Live2D::Cubism::Framework;
1088 using namespace Live2D::Cubism::Framework::DefaultParameterId;
1089 using namespace LAppDefine;
1090 @@ -45,10 +47,12 @@ namespace {
1094 -LAppModel::LAppModel()
1095 +LAppModel::LAppModel(bool useOldParamId)
1097 , _modelSetting(NULL)
1098 , _userTimeSeconds(0.0f)
1099 + , _detector(nullptr)
1100 + , _useOldParamId(useOldParamId)
1102 if (MocConsistencyValidationEnable)
1104 @@ -60,12 +64,12 @@ LAppModel::LAppModel()
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));
1122 LAppModel::~LAppModel()
1123 @@ -101,12 +105,6 @@ void LAppModel::LoadAssets(const csmChar
1125 SetupModel(setting);
1127 - if (_model == NULL)
1129 - LAppPal::PrintLog("Failed to LoadAssets().");
1136 @@ -138,30 +136,6 @@ void LAppModel::SetupModel(ICubismModelS
1137 DeleteBuffer(buffer, path.GetRawString());
1141 - if (_modelSetting->GetExpressionCount() > 0)
1143 - const csmInt32 count = _modelSetting->GetExpressionCount();
1144 - for (csmInt32 i = 0; i < count; i++)
1146 - csmString name = _modelSetting->GetExpressionName(i);
1147 - csmString path = _modelSetting->GetExpressionFileName(i);
1148 - path = _modelHomeDir + path;
1150 - buffer = CreateBuffer(path.GetRawString(), &size);
1151 - ACubismMotion* motion = LoadExpression(buffer, size, name.GetRawString());
1153 - if (_expressions[name] != NULL)
1155 - ACubismMotion::Delete(_expressions[name]);
1156 - _expressions[name] = NULL;
1158 - _expressions[name] = motion;
1160 - DeleteBuffer(buffer, path.GetRawString());
1165 if (strcmp(_modelSetting->GetPhysicsFileName(), "") != 0)
1167 @@ -200,7 +174,7 @@ void LAppModel::SetupModel(ICubismModelS
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));
1174 _breath->SetParameters(breathParameters);
1176 @@ -224,21 +198,6 @@ void LAppModel::SetupModel(ICubismModelS
1182 - csmInt32 lipSyncIdCount = _modelSetting->GetLipSyncParameterCount();
1183 - for (csmInt32 i = 0; i < lipSyncIdCount; ++i)
1185 - _lipSyncIds.PushBack(_modelSetting->GetLipSyncParameterId(i));
1189 - if (_modelSetting == NULL || _modelMatrix == NULL)
1191 - LAppPal::PrintLog("Failed to SetupModel().");
1196 csmMap<csmString, csmFloat32> layout;
1197 _modelSetting->GetLayoutMap(layout);
1198 @@ -351,62 +310,57 @@ void LAppModel::Update()
1199 const csmFloat32 deltaTimeSeconds = LAppPal::GetDeltaTime();
1200 _userTimeSeconds += deltaTimeSeconds;
1202 - _dragManager->Update(deltaTimeSeconds);
1203 - _dragX = _dragManager->GetX();
1204 - _dragY = _dragManager->GetY();
1206 - // モーションによるパラメータ更新の有無
1207 - csmBool motionUpdated = false;
1209 - //-----------------------------------------------------------------
1210 - _model->LoadParameters(); // 前回セーブされた状態をロード
1211 - if (_motionManager->IsFinished())
1213 - // モーションの再生がない場合、待機モーションの中からランダムで再生する
1214 - StartRandomMotion(MotionGroupIdle, PriorityIdle);
1219 - motionUpdated = _motionManager->UpdateMotion(_model, deltaTimeSeconds); // モーションを更新
1221 - _model->SaveParameters(); // 状態を保存
1222 - //-----------------------------------------------------------------
1223 + auto idMan = CubismFramework::GetIdManager();
1224 + auto params = _detector->getParams();
1227 - _opacity = _model->GetModelOpacity();
1230 - if (!motionUpdated)
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)
1238 - // メインモーションの更新がないとき
1239 - _eyeBlink->UpdateParameters(_model, deltaTimeSeconds); // 目パチ
1240 + // モーションの再生がない場合、待機モーションの中からランダムで再生する
1241 + StartRandomMotion(MotionGroupIdle, PriorityIdle);
1245 - if (_expressionManager != NULL)
1247 - _expressionManager->UpdateMotion(_model, deltaTimeSeconds); // 表情でパラメータ更新(相対変化)
1252 - _model->AddParameterValue(_idParamAngleX, _dragX * 30); // -30から30の値を加える
1253 - _model->AddParameterValue(_idParamAngleY, _dragY * 30);
1254 - _model->AddParameterValue(_idParamAngleZ, _dragX * _dragY * -30);
1257 - _model->AddParameterValue(_idParamBodyAngleX, _dragX * 10); // -10から10の値を加える
1260 + _motionManager->UpdateMotion(_model, deltaTimeSeconds); // モーションを更新
1262 + _model->SaveParameters(); // 状態を保存
1265 - _model->AddParameterValue(_idParamEyeBallX, _dragX); // -1から1の値を加える
1266 - _model->AddParameterValue(_idParamEyeBallY, _dragY);
1269 - if (_breath != NULL)
1271 - _breath->UpdateParameters(_model, deltaTimeSeconds);
1272 + if (params.autoBlink && _eyeBlink)
1274 + _eyeBlink->UpdateParameters(_model, deltaTimeSeconds);
1278 + _model->SetParameterValue(idMan->GetId(_("ParamEyeLOpen")),
1279 + params.leftEyeOpenness);
1280 + _model->SetParameterValue(idMan->GetId(_("ParamEyeROpen")),
1281 + params.rightEyeOpenness);
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)
1299 + // Note: _model->LoadParameters and SaveParameters is needed
1300 + // before - see above.
1301 + _breath->UpdateParameters(_model, deltaTimeSeconds);
1306 @@ -415,22 +369,6 @@ void LAppModel::Update()
1307 _physics->Evaluate(_model, deltaTimeSeconds);
1313 - // リアルタイムでリップシンクを行う場合、システムから音量を取得して0〜1の範囲で値を入力します。
1314 - csmFloat32 value = 0.0f;
1317 - _wavFileHandler.Update(deltaTimeSeconds);
1318 - value = _wavFileHandler.GetRms();
1320 - for (csmUint32 i = 0; i < _lipSyncIds.GetSize(); ++i)
1322 - _model->AddParameterValue(_lipSyncIds[i], value, 0.8f);
1329 @@ -499,7 +437,6 @@ CubismMotionQueueEntryHandle LAppModel::
1331 csmString path = voice;
1332 path = _modelHomeDir + path;
1333 - _wavFileHandler.Start(path);
1337 @@ -678,3 +615,37 @@ csmBool LAppModel::HasMocConsistencyFrom
1342 +void LAppModel::SetFacialLandmarkDetector(FacialLandmarkDetector *detector)
1344 + _detector = detector;
1347 +Csm::csmString LAppModel::_(std::string s)
1350 + if (_useOldParamId)
1352 + if (s == "ParamTere")
1354 + ans = "PARAM_CHEEK";
1358 + for (size_t i = 0; i < s.size(); i++)
1360 + if (std::isupper(s[i]) && i != 0)
1364 + ans += std::toupper(s[i]);
1372 + return csmString(ans.c_str());
1375 diff -pruN --exclude build ./demo_clean/src/LAppModel.hpp ./demo_dev/src/LAppModel.hpp
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
1381 * Copyright(c) Live2D Inc. All rights reserved.
1383 * Use of this source code is governed by the Live2D Open Software license
1385 #include <Type/csmRectF.hpp>
1386 #include <Rendering/OpenGL/CubismOffscreenSurface_OpenGLES2.hpp>
1388 -#include "LAppWavFileHandler.hpp"
1389 +#include "facial_landmark_detector.h"
1392 * @brief ユーザーが実際に使用するモデルの実装クラス<br>
1393 @@ -25,8 +25,11 @@ class LAppModel : public Csm::CubismUser
1398 + * @param[in] useOldParamId : If true, translate new (Cubism 3+)
1399 + * parameter IDs to old (Cubism 2.1) ones
1402 + LAppModel(bool useOldParamId);
1406 @@ -122,6 +125,13 @@ public:
1408 Csm::csmBool HasMocConsistencyFromFile(const Csm::csmChar* mocFileName);
1411 + * @brief Set the pointer to the FacialLandmarkDetector instance
1413 + * @param[in] detector : Pointer to FacialLandmarkDetector instance
1415 + void SetFacialLandmarkDetector(FacialLandmarkDetector *detector);
1419 * @brief モデルを描画する処理。モデルを描画する空間のView-Projection行列を渡す。
1420 @@ -175,6 +185,17 @@ private:
1422 void ReleaseExpressions();
1425 + * @brief Translate new (Cubism 3+) parameter IDs to old (Cubism 2.1) ones
1427 + * @param[in] s : New parameter ID
1429 + * @return Old parameter ID
1431 + Csm::csmString _(std::string s);
1433 + bool _useOldParamId;
1435 Csm::ICubismModelSetting* _modelSetting; ///< モデルセッティング情報
1436 Csm::csmString _modelHomeDir; ///< モデルセッティングが置かれたディレクトリ
1437 Csm::csmFloat32 _userTimeSeconds; ///< デルタ時間の積算値[秒]
1438 @@ -191,9 +212,9 @@ private:
1439 const Csm::CubismId* _idParamEyeBallX; ///< パラメータID: ParamEyeBallX
1440 const Csm::CubismId* _idParamEyeBallY; ///< パラメータID: ParamEyeBallXY
1442 - LAppWavFileHandler _wavFileHandler; ///< wavファイルハンドラ
1443 + Csm::Rendering::CubismOffscreenFrame_OpenGLES2 _renderBuffer; ///< フレームバッファ以外の描画先
1445 - Csm::Rendering::CubismOffscreenFrame_OpenGLES2 _renderBuffer; ///< フレームバッファ以外の描画先
1446 + FacialLandmarkDetector *_detector;
1450 diff -pruN --exclude build ./demo_clean/src/LAppPal.cpp ./demo_dev/src/LAppPal.cpp
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
1456 * Copyright(c) Live2D Inc. All rights reserved.
1458 * Use of this source code is governed by the Live2D Open Software license
1462 #include "LAppPal.hpp"
1464 +#include <stdexcept>
1466 +#include <stdlib.h>
1468 #include <sys/stat.h>
1470 @@ -35,6 +37,7 @@ csmByte* LAppPal::LoadFileAsBytes(const
1471 if (stat(path, &statBuf) == 0)
1473 size = statBuf.st_size;
1478 @@ -43,10 +46,7 @@ csmByte* LAppPal::LoadFileAsBytes(const
1479 file.open(path, std::ios::in | std::ios::binary);
1480 if (!file.is_open())
1482 - if (DebugLogEnable)
1484 - PrintLog("file open error");
1486 + throw std::runtime_error("Failed to open file " + filePath);
1489 file.read(buf, size);
1490 @@ -78,13 +78,8 @@ void LAppPal::PrintLog(const csmChar* fo
1493 va_start(args, format);
1494 - vsnprintf_s(buf, sizeof(buf), format, args); // 標準出力でレンダリング
1495 -#ifdef CSM_DEBUG_MEMORY_LEAKING
1496 -// メモリリークチェック時は大量の標準出力がはしり重いのでprintfを利用する
1499 + vsnprintf(buf, sizeof(buf), format, args); // 標準出力でレンダリング
1500 std::cerr << buf << std::endl;
1505 diff -pruN --exclude build ./demo_clean/src/LAppPal.hpp ./demo_dev/src/LAppPal.hpp
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
1511 * Copyright(c) Live2D Inc. All rights reserved.
1513 * Use of this source code is governed by the Live2D Open Software license
1517 #include <CubismFramework.hpp>
1522 diff -pruN --exclude build ./demo_clean/src/LAppSprite.cpp ./demo_dev/src/LAppSprite.cpp
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
1528 * Copyright(c) Live2D Inc. All rights reserved.
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);
1535 - if (maxWidth == 0 || maxHeight == 0)
1536 + if(maxWidth==0 || maxHeight==0)
1538 - return; // この際は描画できず
1542 const GLfloat uvVertex[] =
1543 @@ -74,7 +74,6 @@ void LAppSprite::Render() const
1545 glUniform4f(_colorLocation, _spriteColor[0], _spriteColor[1], _spriteColor[2], _spriteColor[3]);
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);
1555 - if (maxWidth == 0 || maxHeight == 0)
1556 + if(maxWidth==0 || maxHeight==0)
1558 - return; // この際は描画できず
1562 // attribute属性を有効にする
1563 @@ -124,11 +123,10 @@ bool LAppSprite::IsHit(float pointX, flo
1564 int maxWidth, maxHeight;
1565 glfwGetWindowSize(LAppDelegate::GetInstance()->GetWindow(), &maxWidth, &maxHeight);
1567 - if (maxWidth == 0 || maxHeight == 0)
1568 + if(maxWidth==0 || maxHeight==0)
1570 - return false; // この際は描画できず
1575 float y = maxHeight - pointY;
1577 diff -pruN --exclude build ./demo_clean/src/LAppSprite.hpp ./demo_dev/src/LAppSprite.hpp
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
1583 * Copyright(c) Live2D Inc. All rights reserved.
1585 * Use of this source code is governed by the Live2D Open Software license
1586 @@ -61,7 +61,7 @@ public:
1587 void Render() const;
1590 - * @brief テクスチャIDを指定して描画する
1591 + * @brief テクスチャを指定しての描画
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);
1599 - GLuint _textureId; ///< テクスチャID
1600 - Rect _rect; ///< 矩形
1601 + GLuint _textureId; ///< テクスチャID
1602 + Rect _rect; ///< 矩形
1603 int _positionLocation; ///< 位置アトリビュート
1604 int _uvLocation; ///< UVアトリビュート
1605 int _textureLocation; ///< テクスチャアトリビュート
1606 diff -pruN --exclude build ./demo_clean/src/LAppTextureManager.cpp ./demo_dev/src/LAppTextureManager.cpp
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
1612 * Copyright(c) Live2D Inc. All rights reserved.
1614 * Use of this source code is governed by the Live2D Open Software license
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"
1623 #include "stb_image.h"
1624 +#if defined(__clang__)
1625 +#pragma clang diagnostic pop
1627 #include "LAppPal.hpp"
1629 LAppTextureManager::LAppTextureManager()
1630 @@ -89,6 +96,46 @@ LAppTextureManager::TextureInfo* LAppTex
1634 +LAppTextureManager::TextureInfo* LAppTextureManager::CreateTextureFromColor(
1635 + uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha
1638 + constexpr int width = 8, height = 8;
1640 + uint8_t pixels[height][width][4];
1641 + for (std::size_t h = 0; h < height; h++)
1643 + for (std::size_t w = 0; w < width; w++)
1645 + pixels[h][w][0] = red;
1646 + pixels[h][w][1] = green;
1647 + pixels[h][w][2] = blue;
1648 + pixels[h][w][3] = alpha;
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);
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);
1663 + LAppTextureManager::TextureInfo* textureInfo = new LAppTextureManager::TextureInfo();
1664 + textureInfo->fileName = "";
1665 + textureInfo->width = width;
1666 + textureInfo->height = height;
1667 + textureInfo->id = textureId;
1669 + _textures.PushBack(textureInfo);
1671 + return textureInfo;
1674 void LAppTextureManager::ReleaseTextures()
1676 for (Csm::csmUint32 i = 0; i < _textures.GetSize(); i++)
1677 diff -pruN --exclude build ./demo_clean/src/LAppTextureManager.hpp ./demo_dev/src/LAppTextureManager.hpp
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
1683 * Copyright(c) Live2D Inc. All rights reserved.
1685 * Use of this source code is governed by the Live2D Open Software license
1686 @@ -72,6 +72,8 @@ public:
1688 TextureInfo* CreateTextureFromPngFile(std::string fileName);
1690 + TextureInfo *CreateTextureFromColor(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha = 255);
1695 @@ -98,9 +100,9 @@ public:
1697 * @brief テクスチャIDからテクスチャ情報を得る
1699 - * @param textureId[in] 取得したいテクスチャID
1700 - * @return テクスチャが存在していればTextureInfoが返る
1702 + * @param[in] textureId 取得したいテクスチャID
1703 + * @return テクスチャが存在していればTextureInfoが返る
1705 TextureInfo* GetTextureInfoById(GLuint textureId) const;
1708 diff -pruN --exclude build ./demo_clean/src/LAppView.cpp ./demo_dev/src/LAppView.cpp
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
1714 * Copyright(c) Live2D Inc. All rights reserved.
1716 * Use of this source code is governed by the Live2D Open Software license
1718 #include "LAppLive2DManager.hpp"
1719 #include "LAppTextureManager.hpp"
1720 #include "LAppDefine.hpp"
1721 -#include "TouchManager.hpp"
1722 #include "LAppSprite.hpp"
1723 #include "LAppModel.hpp"
1725 +#include <Rendering/OpenGL/CubismOffscreenSurface_OpenGLES2.hpp>
1726 +#include <Rendering/OpenGL/CubismRenderer_OpenGLES2.hpp>
1728 using namespace std;
1729 using namespace LAppDefine;
1731 LAppView::LAppView():
1736 _renderSprite(NULL),
1737 _renderTarget(SelectTarget_None)
1739 @@ -33,9 +33,6 @@ LAppView::LAppView():
1740 _clearColor[2] = 1.0f;
1741 _clearColor[3] = 0.0f;
1744 - _touchManager = new TouchManager();
1746 // デバイス座標からスクリーン座標に変換するための
1747 _deviceToScreen = new CubismMatrix44();
1749 @@ -47,12 +44,10 @@ LAppView::~LAppView()
1751 _renderBuffer.DestroyOffscreenFrame();
1752 delete _renderSprite;
1755 delete _deviceToScreen;
1756 - delete _touchManager;
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);
1767 - _deviceToScreen->LoadIdentity(); // サイズが変わった際などリセット必須
1768 + _deviceToScreen->LoadIdentity();
1771 float screenW = fabsf(right - left);
1772 @@ -104,8 +99,6 @@ void LAppView::Initialize()
1773 void LAppView::Render()
1779 LAppLive2DManager* Live2DManager = LAppLive2DManager::GetInstance();
1781 @@ -125,7 +118,7 @@ void LAppView::Render()
1785 - for (csmUint32 i = 0; i < Live2DManager->GetModelNum(); i++)
1786 + for(csmUint32 i=0; i<Live2DManager->GetModelNum(); i++)
1788 LAppModel* model = Live2DManager->GetModel(i);
1789 float alpha = i < 1 ? 1.0f : model->GetOpacity(); // 片方のみ不透明度を取得できるようにする
1790 @@ -133,7 +126,7 @@ void LAppView::Render()
1794 - _renderSprite->RenderImmidiate( model->GetRenderBuffer().GetColorBuffer(), uvVertex);
1795 + _renderSprite->RenderImmidiate(model->GetRenderBuffer().GetColorBuffer(), uvVertex);
1799 @@ -147,85 +140,22 @@ void LAppView::InitializeSprite()
1800 glfwGetWindowSize(LAppDelegate::GetInstance()->GetWindow(), &width, &height);
1802 LAppTextureManager* textureManager = LAppDelegate::GetInstance()->GetTextureManager();
1803 - const string resourcesPath = ResourcesPath;
1805 - string imageName = BackImageName;
1806 - LAppTextureManager::TextureInfo* backgroundTexture = textureManager->CreateTextureFromPngFile(resourcesPath + imageName);
1808 + LAppTextureManager::TextureInfo* backgroundTexture =
1809 + textureManager->CreateTextureFromColor(0, 255, 0);
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);
1819 - imageName = GearImageName;
1820 - LAppTextureManager::TextureInfo* gearTexture = textureManager->CreateTextureFromPngFile(resourcesPath + imageName);
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);
1828 - imageName = PowerImageName;
1829 - LAppTextureManager::TextureInfo* powerTexture = textureManager->CreateTextureFromPngFile(resourcesPath + imageName);
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);
1840 _renderSprite = new LAppSprite(x, y, static_cast<float>(width), static_cast<float>(height), 0, _programId);
1843 -void LAppView::OnTouchesBegan(float px, float py) const
1845 - _touchManager->TouchesBegan(px, py);
1848 -void LAppView::OnTouchesMoved(float px, float py) const
1850 - float viewX = this->TransformViewX(_touchManager->GetX());
1851 - float viewY = this->TransformViewY(_touchManager->GetY());
1853 - _touchManager->TouchesMoved(px, py);
1855 - LAppLive2DManager* Live2DManager = LAppLive2DManager::GetInstance();
1856 - Live2DManager->OnDrag(viewX, viewY);
1859 -void LAppView::OnTouchesEnded(float px, float py) const
1862 - LAppLive2DManager* live2DManager = LAppLive2DManager::GetInstance();
1863 - live2DManager->OnDrag(0.0f, 0.0f);
1867 - float x = _deviceToScreen->TransformX(_touchManager->GetX()); // 論理座標変換した座標を取得。
1868 - float y = _deviceToScreen->TransformY(_touchManager->GetY()); // 論理座標変換した座標を取得。
1869 - if (DebugTouchLogEnable)
1871 - LAppPal::PrintLog("[APP]touchesEnded x:%.2f y:%.2f", x, y);
1873 - live2DManager->OnTap(x, y);
1876 - if (_gear->IsHit(px, py))
1878 - live2DManager->NextScene();
1882 - if (_power->IsHit(px, py))
1884 - LAppDelegate::GetInstance()->AppEnd();
1889 float LAppView::TransformViewX(float deviceX) const
1890 @@ -250,7 +180,7 @@ float LAppView::TransformScreenY(float d
1891 return _deviceToScreen->TransformY(deviceY);
1894 -void LAppView::PreModelDraw(LAppModel& refModel)
1895 +void LAppView::PreModelDraw(LAppModel &refModel)
1897 // 別のレンダリングターゲットへ向けて描画する場合の使用するフレームバッファ
1898 Csm::Rendering::CubismOffscreenFrame_OpenGLES2* useTarget = NULL;
1899 @@ -263,12 +193,13 @@ void LAppView::PreModelDraw(LAppModel& r
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);
1909 + if(bufWidth!=0 && bufHeight!=0)
1912 - useTarget->CreateOffscreenFrame(static_cast<csmUint32>(width), static_cast<csmUint32>(height));
1913 + useTarget->CreateOffscreenFrame(static_cast<csmUint32>(bufWidth), static_cast<csmUint32>(bufHeight));
1917 @@ -278,7 +209,7 @@ void LAppView::PreModelDraw(LAppModel& r
1921 -void LAppView::PostModelDraw(LAppModel& refModel)
1922 +void LAppView::PostModelDraw(LAppModel &refModel)
1924 // 別のレンダリングターゲットへ向けて描画する場合の使用するフレームバッファ
1925 Csm::Rendering::CubismOffscreenFrame_OpenGLES2* useTarget = NULL;
1926 @@ -368,32 +299,4 @@ void LAppView::ResizeSprite()
1927 _back->ResetRect(x, y, fWidth, fHeight);
1933 - GLuint id = _power->GetTextureId();
1934 - LAppTextureManager::TextureInfo* texInfo = textureManager->GetTextureInfoById(id);
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);
1947 - GLuint id = _gear->GetTextureId();
1948 - LAppTextureManager::TextureInfo* texInfo = textureManager->GetTextureInfoById(id);
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);
1959 diff -pruN --exclude build ./demo_clean/src/LAppView.hpp ./demo_dev/src/LAppView.hpp
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
1965 * Copyright(c) Live2D Inc. All rights reserved.
1967 * Use of this source code is governed by the Live2D Open Software license
1969 #include "CubismFramework.hpp"
1970 #include <Rendering/OpenGL/CubismOffscreenSurface_OpenGLES2.hpp>
1972 -class TouchManager;
1976 @@ -61,35 +60,11 @@ public:
1977 void InitializeSprite();
1980 - * @brief スプライト系のサイズ再設定
1982 + * @brief スプライト系のサイズ再設定
1984 void ResizeSprite();
1987 - * @brief タッチされたときに呼ばれる。
1989 - * @param[in] pointX スクリーンX座標
1990 - * @param[in] pointY スクリーンY座標
1992 - void OnTouchesBegan(float pointX, float pointY) const;
1995 - * @brief タッチしているときにポインタが動いたら呼ばれる。
1997 - * @param[in] pointX スクリーンX座標
1998 - * @param[in] pointY スクリーンY座標
2000 - void OnTouchesMoved(float pointX, float pointY) const;
2003 - * @brief タッチが終了したら呼ばれる。
2005 - * @param[in] pointX スクリーンX座標
2006 - * @param[in] pointY スクリーンY座標
2008 - void OnTouchesEnded(float pointX, float pointY) const;
2011 * @brief X座標をView座標に変換する。
2013 * @param[in] deviceX デバイスX座標
2014 @@ -120,12 +95,12 @@ public:
2016 * @brief モデル1体を描画する直前にコールされる
2018 - void PreModelDraw(LAppModel& refModel);
2019 + void PreModelDraw(LAppModel &refModel);
2022 * @brief モデル1体を描画した直後にコールされる
2024 - void PostModelDraw(LAppModel& refModel);
2025 + void PostModelDraw(LAppModel &refModel);
2028 * @brief 別レンダリングターゲットにモデルを描画するサンプルで
2029 @@ -147,16 +122,13 @@ public:
2030 void SetRenderTargetClearColor(float r, float g, float b);
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; ///< 電源画像
2041 // レンダリング先を別ターゲットにする方式の場合に使用
2042 - LAppSprite* _renderSprite; ///< モードによっては_renderBufferのテクスチャを描画
2043 + LAppSprite* _renderSprite; ///< モードによっては_renderBufferのテクスチャを描画
2044 Csm::Rendering::CubismOffscreenFrame_OpenGLES2 _renderBuffer; ///< モードによってはCubismモデル結果をこっちにレンダリング
2045 SelectTarget _renderTarget; ///< レンダリング先の選択肢
2046 float _clearColor[4]; ///< レンダリングターゲットのクリアカラー
2047 diff -pruN --exclude build ./demo_clean/src/MouseActionManager.cpp ./demo_dev/src/MouseActionManager.cpp
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
2052 - * Copyright(c) Live2D Inc. All rights reserved.
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.
2058 +* Copyright(c) Live2D Inc. All rights reserved.
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.
2064 #include "MouseActionManager.hpp"
2066 @@ -13,7 +13,7 @@ namespace {
2068 MouseActionManager* MouseActionManager::GetInstance()
2070 - if (instance == NULL)
2073 instance = new MouseActionManager();
2075 @@ -23,7 +23,7 @@ MouseActionManager* MouseActionManager::
2077 void MouseActionManager::ReleaseInstance()
2079 - if (instance != NULL)
2084 @@ -99,18 +99,21 @@ void MouseActionManager::OnMouseCallBack
2088 - if (GLFW_PRESS == action)
2093 OnTouchesBegan(_mouseX, _mouseY);
2095 - else if (GLFW_RELEASE == action)
2098 + case GLFW_RELEASE:
2102 OnTouchesEnded(_mouseX, _mouseY);
2110 diff -pruN --exclude build ./demo_clean/src/MouseActionManager.hpp ./demo_dev/src/MouseActionManager.hpp
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
2116 * Copyright(c) Live2D Inc. All rights reserved.
2118 * Use of this source code is governed by the Live2D Open Software license
2119 diff -pruN --exclude build ./demo_clean/src/TouchManager.cpp ./demo_dev/src/TouchManager.cpp
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
2125 * Copyright(c) Live2D Inc. All rights reserved.
2127 * Use of this source code is governed by the Live2D Open Software license
2128 diff -pruN --exclude build ./demo_clean/src/TouchManager.hpp ./demo_dev/src/TouchManager.hpp
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
2134 * Copyright(c) Live2D Inc. All rights reserved.
2136 * Use of this source code is governed by the Live2D Open Software license
2137 diff -pruN --exclude build ./demo_clean/src/main.cpp ./demo_dev/src/main.cpp
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
2143 * Copyright(c) Live2D Inc. All rights reserved.
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.
2150 +#include <stdexcept>
2153 +#ifdef __cpp_lib_filesystem
2154 +#include <filesystem>
2155 +namespace fs = std::filesystem;
2157 +#include <experimental/filesystem>
2158 +namespace fs = std::experimental::filesystem;
2162 #include "LAppDelegate.hpp"
2163 +#include "LAppLive2DManager.hpp"
2164 +#include "facial_landmark_detector.h"
2169 - // create the application instance
2170 - if (LAppDelegate::GetInstance()->Initialize() == GL_FALSE)
2173 + std::string windowTitle;
2174 + std::string rootDir;
2175 + float scaleFactor;
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
2183 +CmdArgs parseArgv(int argc, char *argv[])
2185 + // I think the command-line args are simple enough to not justify using a library...
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 = "";
2203 + std::string arg = argv[i];
2204 + std::stringstream ss;
2206 + if (arg == "--window-width" || arg == "-W") // capital W for consistency with height
2208 + ss << argv[i + 1];
2209 + if (!(ss >> cmdArgs.windowWidth))
2211 + throw std::runtime_error("Invalid argument for window width");
2214 + else if (arg == "--window-height" || arg == "-H") // avoiding "-h", typically for help
2216 + ss << argv[i + 1];
2217 + if (!(ss >> cmdArgs.windowHeight))
2219 + throw std::runtime_error("Invalid argument for window height");
2222 + else if (arg == "--window-title" || arg == "-t")
2224 + cmdArgs.windowTitle = argv[i + 1];
2226 + else if (arg == "--root-dir" || arg == "-d")
2228 + cmdArgs.rootDir = argv[i + 1];
2230 + else if (arg == "--scale-factor" || arg == "-f")
2232 + ss << argv[i + 1];
2233 + if (!(ss >> cmdArgs.scaleFactor))
2235 + throw std::runtime_error("Invalid argument for scale factor");
2238 + else if (arg == "--translate-x" || arg == "-x")
2240 + ss << argv[i + 1];
2241 + if (!(ss >> cmdArgs.translateX))
2243 + throw std::runtime_error("Invalid argument for translate X");
2246 + else if (arg == "--translate-y" || arg == "-y")
2248 + ss << argv[i + 1];
2249 + if (!(ss >> cmdArgs.translateY))
2251 + throw std::runtime_error("Invalid argument for translate Y");
2254 + else if (arg == "--model" || arg == "-m")
2256 + cmdArgs.modelName = argv[i + 1];
2258 + else if (arg == "--config" || arg == "-c")
2260 + cmdArgs.cfgPath = argv[i + 1];
2262 + else if (arg == "--old-param-id" || arg == "-o")
2264 + cmdArgs.oldId = (argv[i + 1][0] == '1');
2268 + throw std::runtime_error("Unrecognized argument: " + arg);
2274 - LAppDelegate::GetInstance()->Run();
2278 +int main(int argc, char* argv[])
2280 + auto cmdArgs = parseArgv(argc, argv);
2282 + LAppDelegate *delegate = LAppDelegate::GetInstance();
2284 + if (!delegate->Initialize(cmdArgs.windowWidth,
2285 + cmdArgs.windowHeight,
2286 + cmdArgs.windowTitle.c_str()))
2288 + throw std::runtime_error("Unable to initialize LAppDelegate");
2291 + delegate->SetRootDirectory(cmdArgs.rootDir);
2293 + FacialLandmarkDetector detector(cmdArgs.cfgPath);
2295 + std::thread detectorThread(&FacialLandmarkDetector::mainLoop,
2298 + LAppLive2DManager *manager = LAppLive2DManager::GetInstance();
2299 + manager->SetModel(cmdArgs.modelName, cmdArgs.oldId);
2301 + manager->SetProjectionScaleTranslate(cmdArgs.scaleFactor,
2302 + cmdArgs.translateX,
2303 + cmdArgs.translateY);
2304 + manager->SetFacialLandmarkDetector(&detector);
2309 + detectorThread.join();
2314 diff -pruN --exclude build ./demo_clean/src/mainMinimum.cpp ./demo_dev/src/mainMinimum.cpp
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
2320 * Copyright(c) Live2D Inc. All rights reserved.
2322 * Use of this source code is governed by the Live2D Open Software license
2325 #include <functional>
2327 -#include <stb_image.h>
2329 +#include <unistd.h>
2330 #include <GL/glew.h>
2331 #include <GLFW/glfw3.h>
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"
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>
2352 *@brief モデルデータのディレクトリ名
2354 static const Csm::csmChar* _modelDirectoryName = "Hiyori";
2356 static Csm::CubismUserModel* _userModel; ///< ユーザーが実際に使用するモデル
2357 -static Csm::CubismModelSettingJson* _modelJson; ///< モデルの設定情報
2358 -static Csm::CubismModel* _model; ///< Mocデータから作成されるモデルデータ
2360 Csm::csmFloat32 _userTimeSeconds; ///< デルタ時間の積算値[秒]
2361 Csm::csmVector<Csm::CubismIdHandle> _eyeBlinkIds; ///< モデルに設定されたまばたき機能用パラメータID
2362 @@ -66,8 +61,8 @@ static LAppAllocator _cubismAllocator; /
2364 static LAppTextureManager* _textureManager; ///< テクスチャの管理
2366 +static std::string _rootDirectory; ///< ルートディレクトリ
2367 static std::string _currentModelDirectory; ///< 現在のモデルのディレクトリ名
2368 -const Csm::csmChar* _currentModelDirectoryChar; ///< 現在のモデルのディレクトリ名のconst csmCharポインタ型
2370 static GLFWwindow* _window; ///< ウィンドウオブジェクト
2372 @@ -90,6 +85,59 @@ static void InitializeCubism()
2378 +* 指定された区切り文字で文字列を分割する
2380 +Csm::csmVector<std::string> Split(const std::string& baseString, char delimiter)
2382 + Csm::csmVector < std::string > elems;
2383 + std::stringstream ss(baseString);
2386 + while (getline(ss, item, delimiter))
2388 + if (!item.empty())
2390 + elems.PushBack(item);
2398 +* @brief ルートディレクトリの設定
2400 +* Linuxのルートディレクトリを確認し、パスを取得する
2402 +void SetRootDirectory()
2404 + const int maximumPathBufferSize = 1024;
2405 + char path[maximumPathBufferSize];
2406 + ssize_t len = readlink("/proc/self/exe", path, maximumPathBufferSize - 1);
2413 + std::string pathString(path);
2415 + pathString = pathString.substr(0, pathString.rfind("Demo"));
2416 + Csm::csmVector<std::string> splitStrings = Split(pathString, '/');
2418 + _rootDirectory = "";
2420 + for (int i = 0; i < splitStrings.GetSize(); i++)
2422 + _rootDirectory += "/" + splitStrings[i];
2425 + _rootDirectory += "/";
2432 @@ -149,6 +197,8 @@ static bool InitializeSystem()
2434 MouseActionManager::GetInstance()->Initialize(windowWidth, windowHeight);
2436 + SetRootDirectory();
2441 @@ -182,16 +232,6 @@ void Release()
2445 -* @brief ディレクトリパスの設定
2447 -* モデルのディレクトリパスを設定する
2449 -void SetAssetDirectory(const std::string& path)
2451 - _currentModelDirectory = path;
2458 @@ -201,13 +241,15 @@ void SetAssetDirectory(const std::string
2459 void LoadModel(const std::string modelDirectoryName)
2462 - SetAssetDirectory(LAppDefine::ResourcesPath + modelDirectoryName + "/");
2463 + _currentModelDirectory = _rootDirectory + LAppDefine::ResourcesPath + modelDirectoryName + "/";
2466 _userModel = new CubismUserModelExtend(modelDirectoryName, _currentModelDirectory);
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());
2474 // ユーザーモデルをMouseActionManagerへ渡す
2475 MouseActionManager::GetInstance()->SetUserModel(_userModel);