1 diff -pruN --exclude build ./demo_clean/CMakeLists.txt ./demo_dev/CMakeLists.txt
2 --- ./demo_clean/CMakeLists.txt 2023-02-20 11:39:40.000000000 +0000
3 +++ ./demo_dev/CMakeLists.txt 2023-03-05 23:22:10.756801200 +0000
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.6.2)
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-02-20 11:39:40.000000000 +0000
50 +++ ./demo_dev/src/CMakeLists.txt 2023-03-05 23:22:10.976777100 +0000
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-02-20 11:39:40.000000000 +0000
116 +++ ./demo_dev/src/CubismUserModelExtend.cpp 2023-03-05 23:22:10.780128700 +0000
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-02-20 11:39:40.000000000 +0000
305 +++ ./demo_dev/src/CubismUserModelExtend.hpp 2023-03-05 23:22:10.986750400 +0000
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-02-20 11:39:40.000000000 +0000
376 +++ ./demo_dev/src/LAppAllocator.cpp 2023-03-05 23:22:10.847976000 +0000
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-02-20 11:39:40.000000000 +0000
394 +++ ./demo_dev/src/LAppAllocator.hpp 2023-03-05 23:22:10.953083600 +0000
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-02-20 11:39:40.000000000 +0000
403 +++ ./demo_dev/src/LAppDefine.cpp 2023-03-05 23:22:10.995458800 +0000
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-02-20 11:39:40.000000000 +0000
421 +++ ./demo_dev/src/LAppDefine.hpp 2023-03-05 23:22:10.947784100 +0000
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-02-20 11:39:40.000000000 +0000
436 +++ ./demo_dev/src/LAppDelegate.cpp 2023-03-05 23:22:10.975780100 +0000
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-02-20 11:39:40.000000000 +0000
666 +++ ./demo_dev/src/LAppDelegate.hpp 2023-03-05 23:22:10.789104800 +0000
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-02-20 11:39:40.000000000 +0000
806 +++ ./demo_dev/src/LAppLive2DManager.cpp 2023-03-05 23:22:10.967799000 +0000
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-02-20 11:39:40.000000000 +0000
988 +++ ./demo_dev/src/LAppLive2DManager.hpp 2023-03-05 23:22:10.829032000 +0000
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-02-20 11:39:40.000000000 +0000
1074 +++ ./demo_dev/src/LAppModel.cpp 2023-03-05 23:22:10.797100200 +0000
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,22 +47,24 @@ namespace {
1094 -LAppModel::LAppModel()
1095 +LAppModel::LAppModel(bool useOldParamId)
1097 , _modelSetting(NULL)
1098 , _userTimeSeconds(0.0f)
1099 + , _detector(nullptr)
1100 + , _useOldParamId(useOldParamId)
1107 - _idParamAngleX = CubismFramework::GetIdManager()->GetId(ParamAngleX);
1108 - _idParamAngleY = CubismFramework::GetIdManager()->GetId(ParamAngleY);
1109 - _idParamAngleZ = CubismFramework::GetIdManager()->GetId(ParamAngleZ);
1110 - _idParamBodyAngleX = CubismFramework::GetIdManager()->GetId(ParamBodyAngleX);
1111 - _idParamEyeBallX = CubismFramework::GetIdManager()->GetId(ParamEyeBallX);
1112 - _idParamEyeBallY = CubismFramework::GetIdManager()->GetId(ParamEyeBallY);
1113 + _idParamAngleX = CubismFramework::GetIdManager()->GetId(_(ParamAngleX));
1114 + _idParamAngleY = CubismFramework::GetIdManager()->GetId(_(ParamAngleY));
1115 + _idParamAngleZ = CubismFramework::GetIdManager()->GetId(_(ParamAngleZ));
1116 + _idParamBodyAngleX = CubismFramework::GetIdManager()->GetId(_(ParamBodyAngleX));
1117 + _idParamEyeBallX = CubismFramework::GetIdManager()->GetId(_(ParamEyeBallX));
1118 + _idParamEyeBallY = CubismFramework::GetIdManager()->GetId(_(ParamEyeBallY));
1121 LAppModel::~LAppModel()
1122 @@ -96,12 +100,6 @@ void LAppModel::LoadAssets(const csmChar
1124 SetupModel(setting);
1126 - if (_model == NULL)
1128 - LAppPal::PrintLog("Failed to LoadAssets().");
1135 @@ -134,30 +132,6 @@ void LAppModel::SetupModel(ICubismModelS
1136 DeleteBuffer(buffer, path.GetRawString());
1140 - if (_modelSetting->GetExpressionCount() > 0)
1142 - const csmInt32 count = _modelSetting->GetExpressionCount();
1143 - for (csmInt32 i = 0; i < count; i++)
1145 - csmString name = _modelSetting->GetExpressionName(i);
1146 - csmString path = _modelSetting->GetExpressionFileName(i);
1147 - path = _modelHomeDir + path;
1149 - buffer = CreateBuffer(path.GetRawString(), &size);
1150 - ACubismMotion* motion = LoadExpression(buffer, size, name.GetRawString());
1152 - if (_expressions[name] != NULL)
1154 - ACubismMotion::Delete(_expressions[name]);
1155 - _expressions[name] = NULL;
1157 - _expressions[name] = motion;
1159 - DeleteBuffer(buffer, path.GetRawString());
1164 if (strcmp(_modelSetting->GetPhysicsFileName(), "") != 0)
1166 @@ -196,7 +170,7 @@ void LAppModel::SetupModel(ICubismModelS
1167 breathParameters.PushBack(CubismBreath::BreathParameterData(_idParamAngleY, 0.0f, 8.0f, 3.5345f, 0.5f));
1168 breathParameters.PushBack(CubismBreath::BreathParameterData(_idParamAngleZ, 0.0f, 10.0f, 5.5345f, 0.5f));
1169 breathParameters.PushBack(CubismBreath::BreathParameterData(_idParamBodyAngleX, 0.0f, 4.0f, 15.5345f, 0.5f));
1170 - breathParameters.PushBack(CubismBreath::BreathParameterData(CubismFramework::GetIdManager()->GetId(ParamBreath), 0.5f, 0.5f, 3.2345f, 0.5f));
1171 + breathParameters.PushBack(CubismBreath::BreathParameterData(CubismFramework::GetIdManager()->GetId(_(ParamBreath)), 0.5f, 0.5f, 3.2345f, 0.5f));
1173 _breath->SetParameters(breathParameters);
1175 @@ -220,21 +194,6 @@ void LAppModel::SetupModel(ICubismModelS
1181 - csmInt32 lipSyncIdCount = _modelSetting->GetLipSyncParameterCount();
1182 - for (csmInt32 i = 0; i < lipSyncIdCount; ++i)
1184 - _lipSyncIds.PushBack(_modelSetting->GetLipSyncParameterId(i));
1188 - if (_modelSetting == NULL || _modelMatrix == NULL)
1190 - LAppPal::PrintLog("Failed to SetupModel().");
1195 csmMap<csmString, csmFloat32> layout;
1196 _modelSetting->GetLayoutMap(layout);
1197 @@ -347,59 +306,57 @@ void LAppModel::Update()
1198 const csmFloat32 deltaTimeSeconds = LAppPal::GetDeltaTime();
1199 _userTimeSeconds += deltaTimeSeconds;
1201 - _dragManager->Update(deltaTimeSeconds);
1202 - _dragX = _dragManager->GetX();
1203 - _dragY = _dragManager->GetY();
1205 - // モーションによるパラメータ更新の有無
1206 - csmBool motionUpdated = false;
1208 - //-----------------------------------------------------------------
1209 - _model->LoadParameters(); // 前回セーブされた状態をロード
1210 - if (_motionManager->IsFinished())
1213 - // モーションの再生がない場合、待機モーションの中からランダムで再生する
1214 - StartRandomMotion(MotionGroupIdle, PriorityIdle);
1218 - motionUpdated = _motionManager->UpdateMotion(_model, deltaTimeSeconds); // モーションを更新
1220 - _model->SaveParameters(); // 状態を保存
1221 - //-----------------------------------------------------------------
1222 + auto idMan = CubismFramework::GetIdManager();
1223 + auto params = _detector->getParams();
1226 - if (!motionUpdated)
1228 - if (_eyeBlink != NULL)
1229 + // NOTE: Apparently, this LoadParameters/SaveParameters pair
1230 + // is needed for auto breath to work.
1231 + _model->LoadParameters(); // 前回セーブされた状態をロード
1232 + if (_motionManager->IsFinished() && params.randomMotion)
1234 - // メインモーションの更新がないとき
1235 - _eyeBlink->UpdateParameters(_model, deltaTimeSeconds); // 目パチ
1236 + // モーションの再生がない場合、待機モーションの中からランダムで再生する
1237 + StartRandomMotion(MotionGroupIdle, PriorityIdle);
1241 - if (_expressionManager != NULL)
1243 - _expressionManager->UpdateMotion(_model, deltaTimeSeconds); // 表情でパラメータ更新(相対変化)
1248 - _model->AddParameterValue(_idParamAngleX, _dragX * 30); // -30から30の値を加える
1249 - _model->AddParameterValue(_idParamAngleY, _dragY * 30);
1250 - _model->AddParameterValue(_idParamAngleZ, _dragX * _dragY * -30);
1253 - _model->AddParameterValue(_idParamBodyAngleX, _dragX * 10); // -10から10の値を加える
1256 + _motionManager->UpdateMotion(_model, deltaTimeSeconds); // モーションを更新
1258 + _model->SaveParameters(); // 状態を保存
1261 - _model->AddParameterValue(_idParamEyeBallX, _dragX); // -1から1の値を加える
1262 - _model->AddParameterValue(_idParamEyeBallY, _dragY);
1265 - if (_breath != NULL)
1267 - _breath->UpdateParameters(_model, deltaTimeSeconds);
1268 + if (params.autoBlink && _eyeBlink)
1270 + _eyeBlink->UpdateParameters(_model, deltaTimeSeconds);
1274 + _model->SetParameterValue(idMan->GetId(_("ParamEyeLOpen")),
1275 + params.leftEyeOpenness);
1276 + _model->SetParameterValue(idMan->GetId(_("ParamEyeROpen")),
1277 + params.rightEyeOpenness);
1279 + _model->SetParameterValue(idMan->GetId(_("ParamMouthForm")),
1280 + params.mouthForm);
1281 + _model->SetParameterValue(idMan->GetId(_("ParamMouthOpenY")),
1282 + params.mouthOpenness);
1283 + _model->SetParameterValue(idMan->GetId(_("ParamEyeLSmile")),
1284 + params.leftEyeSmile);
1285 + _model->SetParameterValue(idMan->GetId(_("ParamEyeRSmile")),
1286 + params.rightEyeSmile);
1287 + _model->SetParameterValue(idMan->GetId(_("ParamAngleX")),
1288 + params.faceXAngle);
1289 + _model->SetParameterValue(idMan->GetId(_("ParamAngleY")),
1290 + params.faceYAngle);
1291 + _model->SetParameterValue(idMan->GetId(_("ParamAngleZ")),
1292 + params.faceZAngle);
1293 + if (params.autoBreath && _breath)
1295 + // Note: _model->LoadParameters and SaveParameters is needed
1296 + // before - see above.
1297 + _breath->UpdateParameters(_model, deltaTimeSeconds);
1302 @@ -408,22 +365,6 @@ void LAppModel::Update()
1303 _physics->Evaluate(_model, deltaTimeSeconds);
1309 - // リアルタイムでリップシンクを行う場合、システムから音量を取得して0〜1の範囲で値を入力します。
1310 - csmFloat32 value = 0.0f;
1313 - _wavFileHandler.Update(deltaTimeSeconds);
1314 - value = _wavFileHandler.GetRms();
1316 - for (csmUint32 i = 0; i < _lipSyncIds.GetSize(); ++i)
1318 - _model->AddParameterValue(_lipSyncIds[i], value, 0.8f);
1325 @@ -492,7 +433,6 @@ CubismMotionQueueEntryHandle LAppModel::
1327 csmString path = voice;
1328 path = _modelHomeDir + path;
1329 - _wavFileHandler.Start(path);
1333 @@ -644,3 +584,37 @@ Csm::Rendering::CubismOffscreenFrame_Ope
1335 return _renderBuffer;
1338 +void LAppModel::SetFacialLandmarkDetector(FacialLandmarkDetector *detector)
1340 + _detector = detector;
1343 +Csm::csmString LAppModel::_(std::string s)
1346 + if (_useOldParamId)
1348 + if (s == "ParamTere")
1350 + ans = "PARAM_CHEEK";
1354 + for (size_t i = 0; i < s.size(); i++)
1356 + if (std::isupper(s[i]) && i != 0)
1360 + ans += std::toupper(s[i]);
1368 + return csmString(ans.c_str());
1371 diff -pruN --exclude build ./demo_clean/src/LAppModel.hpp ./demo_dev/src/LAppModel.hpp
1372 --- ./demo_clean/src/LAppModel.hpp 2023-02-20 11:39:40.000000000 +0000
1373 +++ ./demo_dev/src/LAppModel.hpp 2023-03-05 23:22:10.907889300 +0000
1377 * Copyright(c) Live2D Inc. All rights reserved.
1379 * Use of this source code is governed by the Live2D Open Software license
1381 #include <Type/csmRectF.hpp>
1382 #include <Rendering/OpenGL/CubismOffscreenSurface_OpenGLES2.hpp>
1384 -#include "LAppWavFileHandler.hpp"
1385 +#include "facial_landmark_detector.h"
1388 * @brief ユーザーが実際に使用するモデルの実装クラス<br>
1389 @@ -25,8 +25,11 @@ class LAppModel : public Csm::CubismUser
1394 + * @param[in] useOldParamId : If true, translate new (Cubism 3+)
1395 + * parameter IDs to old (Cubism 2.1) ones
1398 + LAppModel(bool useOldParamId);
1402 @@ -114,6 +117,13 @@ public:
1404 Csm::Rendering::CubismOffscreenFrame_OpenGLES2& GetRenderBuffer();
1407 + * @brief Set the pointer to the FacialLandmarkDetector instance
1409 + * @param[in] detector : Pointer to FacialLandmarkDetector instance
1411 + void SetFacialLandmarkDetector(FacialLandmarkDetector *detector);
1415 * @brief モデルを描画する処理。モデルを描画する空間のView-Projection行列を渡す。
1416 @@ -167,6 +177,17 @@ private:
1418 void ReleaseExpressions();
1421 + * @brief Translate new (Cubism 3+) parameter IDs to old (Cubism 2.1) ones
1423 + * @param[in] s : New parameter ID
1425 + * @return Old parameter ID
1427 + Csm::csmString _(std::string s);
1429 + bool _useOldParamId;
1431 Csm::ICubismModelSetting* _modelSetting; ///< モデルセッティング情報
1432 Csm::csmString _modelHomeDir; ///< モデルセッティングが置かれたディレクトリ
1433 Csm::csmFloat32 _userTimeSeconds; ///< デルタ時間の積算値[秒]
1434 @@ -183,9 +204,9 @@ private:
1435 const Csm::CubismId* _idParamEyeBallX; ///< パラメータID: ParamEyeBallX
1436 const Csm::CubismId* _idParamEyeBallY; ///< パラメータID: ParamEyeBallXY
1438 - LAppWavFileHandler _wavFileHandler; ///< wavファイルハンドラ
1439 + Csm::Rendering::CubismOffscreenFrame_OpenGLES2 _renderBuffer; ///< フレームバッファ以外の描画先
1441 - Csm::Rendering::CubismOffscreenFrame_OpenGLES2 _renderBuffer; ///< フレームバッファ以外の描画先
1442 + FacialLandmarkDetector *_detector;
1446 diff -pruN --exclude build ./demo_clean/src/LAppPal.cpp ./demo_dev/src/LAppPal.cpp
1447 --- ./demo_clean/src/LAppPal.cpp 2023-02-20 11:39:40.000000000 +0000
1448 +++ ./demo_dev/src/LAppPal.cpp 2023-03-05 23:22:10.834981800 +0000
1452 * Copyright(c) Live2D Inc. All rights reserved.
1454 * Use of this source code is governed by the Live2D Open Software license
1458 #include "LAppPal.hpp"
1460 +#include <stdexcept>
1462 +#include <stdlib.h>
1464 #include <sys/stat.h>
1466 @@ -35,6 +37,7 @@ csmByte* LAppPal::LoadFileAsBytes(const
1467 if (stat(path, &statBuf) == 0)
1469 size = statBuf.st_size;
1474 @@ -43,10 +46,7 @@ csmByte* LAppPal::LoadFileAsBytes(const
1475 file.open(path, std::ios::in | std::ios::binary);
1476 if (!file.is_open())
1478 - if (DebugLogEnable)
1480 - PrintLog("file open error");
1482 + throw std::runtime_error("Failed to open file " + filePath);
1485 file.read(buf, size);
1486 @@ -78,13 +78,8 @@ void LAppPal::PrintLog(const csmChar* fo
1489 va_start(args, format);
1490 - vsnprintf_s(buf, sizeof(buf), format, args); // 標準出力でレンダリング
1491 -#ifdef CSM_DEBUG_MEMORY_LEAKING
1492 -// メモリリークチェック時は大量の標準出力がはしり重いのでprintfを利用する
1495 + vsnprintf(buf, sizeof(buf), format, args); // 標準出力でレンダリング
1496 std::cerr << buf << std::endl;
1501 diff -pruN --exclude build ./demo_clean/src/LAppPal.hpp ./demo_dev/src/LAppPal.hpp
1502 --- ./demo_clean/src/LAppPal.hpp 2023-02-20 11:39:40.000000000 +0000
1503 +++ ./demo_dev/src/LAppPal.hpp 2023-03-05 23:22:10.939820800 +0000
1507 * Copyright(c) Live2D Inc. All rights reserved.
1509 * Use of this source code is governed by the Live2D Open Software license
1513 #include <CubismFramework.hpp>
1518 diff -pruN --exclude build ./demo_clean/src/LAppSprite.cpp ./demo_dev/src/LAppSprite.cpp
1519 --- ./demo_clean/src/LAppSprite.cpp 2023-02-20 11:39:40.000000000 +0000
1520 +++ ./demo_dev/src/LAppSprite.cpp 2023-03-05 23:22:10.900085700 +0000
1524 * Copyright(c) Live2D Inc. All rights reserved.
1526 * Use of this source code is governed by the Live2D Open Software license
1527 @@ -39,9 +39,9 @@ void LAppSprite::Render() const
1528 int maxWidth, maxHeight;
1529 glfwGetWindowSize(LAppDelegate::GetInstance()->GetWindow(), &maxWidth, &maxHeight);
1531 - if (maxWidth == 0 || maxHeight == 0)
1532 + if(maxWidth==0 || maxHeight==0)
1534 - return; // この際は描画できず
1538 const GLfloat uvVertex[] =
1539 @@ -74,7 +74,6 @@ void LAppSprite::Render() const
1541 glUniform4f(_colorLocation, _spriteColor[0], _spriteColor[1], _spriteColor[2], _spriteColor[3]);
1545 glBindTexture(GL_TEXTURE_2D, _textureId);
1546 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
1547 @@ -86,9 +85,9 @@ void LAppSprite::RenderImmidiate(GLuint
1548 int maxWidth, maxHeight;
1549 glfwGetWindowSize(LAppDelegate::GetInstance()->GetWindow(), &maxWidth, &maxHeight);
1551 - if (maxWidth == 0 || maxHeight == 0)
1552 + if(maxWidth==0 || maxHeight==0)
1554 - return; // この際は描画できず
1558 // attribute属性を有効にする
1559 @@ -124,11 +123,10 @@ bool LAppSprite::IsHit(float pointX, flo
1560 int maxWidth, maxHeight;
1561 glfwGetWindowSize(LAppDelegate::GetInstance()->GetWindow(), &maxWidth, &maxHeight);
1563 - if (maxWidth == 0 || maxHeight == 0)
1564 + if(maxWidth==0 || maxHeight==0)
1566 - return false; // この際は描画できず
1571 float y = maxHeight - pointY;
1573 diff -pruN --exclude build ./demo_clean/src/LAppSprite.hpp ./demo_dev/src/LAppSprite.hpp
1574 --- ./demo_clean/src/LAppSprite.hpp 2023-02-20 11:39:40.000000000 +0000
1575 +++ ./demo_dev/src/LAppSprite.hpp 2023-03-05 23:22:10.876156000 +0000
1579 * Copyright(c) Live2D Inc. All rights reserved.
1581 * Use of this source code is governed by the Live2D Open Software license
1582 @@ -61,7 +61,7 @@ public:
1583 void Render() const;
1586 - * @brief テクスチャIDを指定して描画する
1587 + * @brief テクスチャを指定しての描画
1590 void RenderImmidiate(GLuint textureId, const GLfloat uvVertex[8]) const;
1591 @@ -95,8 +95,8 @@ public:
1592 void ResetRect(float x, float y, float width, float height);
1595 - GLuint _textureId; ///< テクスチャID
1596 - Rect _rect; ///< 矩形
1597 + GLuint _textureId; ///< テクスチャID
1598 + Rect _rect; ///< 矩形
1599 int _positionLocation; ///< 位置アトリビュート
1600 int _uvLocation; ///< UVアトリビュート
1601 int _textureLocation; ///< テクスチャアトリビュート
1602 diff -pruN --exclude build ./demo_clean/src/LAppTextureManager.cpp ./demo_dev/src/LAppTextureManager.cpp
1603 --- ./demo_clean/src/LAppTextureManager.cpp 2023-02-20 11:39:40.000000000 +0000
1604 +++ ./demo_dev/src/LAppTextureManager.cpp 2023-03-05 23:22:10.765166600 +0000
1608 * Copyright(c) Live2D Inc. All rights reserved.
1610 * Use of this source code is governed by the Live2D Open Software license
1612 #define STBI_NO_STDIO
1613 #define STBI_ONLY_PNG
1614 #define STB_IMAGE_IMPLEMENTATION
1615 +#if defined(__clang__)
1616 +#pragma clang diagnostic push
1617 +#pragma clang diagnostic ignored "-Wunused-function"
1619 #include "stb_image.h"
1620 +#if defined(__clang__)
1621 +#pragma clang diagnostic pop
1623 #include "LAppPal.hpp"
1625 LAppTextureManager::LAppTextureManager()
1626 @@ -89,6 +96,46 @@ LAppTextureManager::TextureInfo* LAppTex
1630 +LAppTextureManager::TextureInfo* LAppTextureManager::CreateTextureFromColor(
1631 + uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha
1634 + constexpr int width = 8, height = 8;
1636 + uint8_t pixels[height][width][4];
1637 + for (std::size_t h = 0; h < height; h++)
1639 + for (std::size_t w = 0; w < width; w++)
1641 + pixels[h][w][0] = red;
1642 + pixels[h][w][1] = green;
1643 + pixels[h][w][2] = blue;
1644 + pixels[h][w][3] = alpha;
1649 + glGenTextures(1, &textureId);
1650 + glBindTexture(GL_TEXTURE_2D, textureId);
1651 + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
1653 + glGenerateMipmap(GL_TEXTURE_2D);
1654 + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
1655 + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
1656 + glBindTexture(GL_TEXTURE_2D, 0);
1659 + LAppTextureManager::TextureInfo* textureInfo = new LAppTextureManager::TextureInfo();
1660 + textureInfo->fileName = "";
1661 + textureInfo->width = width;
1662 + textureInfo->height = height;
1663 + textureInfo->id = textureId;
1665 + _textures.PushBack(textureInfo);
1667 + return textureInfo;
1670 void LAppTextureManager::ReleaseTextures()
1672 for (Csm::csmUint32 i = 0; i < _textures.GetSize(); i++)
1673 diff -pruN --exclude build ./demo_clean/src/LAppTextureManager.hpp ./demo_dev/src/LAppTextureManager.hpp
1674 --- ./demo_clean/src/LAppTextureManager.hpp 2023-02-20 11:39:40.000000000 +0000
1675 +++ ./demo_dev/src/LAppTextureManager.hpp 2023-03-05 23:22:10.822016600 +0000
1679 * Copyright(c) Live2D Inc. All rights reserved.
1681 * Use of this source code is governed by the Live2D Open Software license
1682 @@ -72,6 +72,8 @@ public:
1684 TextureInfo* CreateTextureFromPngFile(std::string fileName);
1686 + TextureInfo *CreateTextureFromColor(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha = 255);
1691 @@ -98,9 +100,9 @@ public:
1693 * @brief テクスチャIDからテクスチャ情報を得る
1695 - * @param textureId[in] 取得したいテクスチャID
1696 - * @return テクスチャが存在していればTextureInfoが返る
1698 + * @param[in] textureId 取得したいテクスチャID
1699 + * @return テクスチャが存在していればTextureInfoが返る
1701 TextureInfo* GetTextureInfoById(GLuint textureId) const;
1704 diff -pruN --exclude build ./demo_clean/src/LAppView.cpp ./demo_dev/src/LAppView.cpp
1705 --- ./demo_clean/src/LAppView.cpp 2023-02-20 11:39:40.000000000 +0000
1706 +++ ./demo_dev/src/LAppView.cpp 2023-03-05 23:22:10.804064800 +0000
1710 * Copyright(c) Live2D Inc. All rights reserved.
1712 * Use of this source code is governed by the Live2D Open Software license
1714 #include "LAppLive2DManager.hpp"
1715 #include "LAppTextureManager.hpp"
1716 #include "LAppDefine.hpp"
1717 -#include "TouchManager.hpp"
1718 #include "LAppSprite.hpp"
1719 #include "LAppModel.hpp"
1721 +#include <Rendering/OpenGL/CubismOffscreenSurface_OpenGLES2.hpp>
1722 +#include <Rendering/OpenGL/CubismRenderer_OpenGLES2.hpp>
1724 using namespace std;
1725 using namespace LAppDefine;
1727 LAppView::LAppView():
1732 _renderSprite(NULL),
1733 _renderTarget(SelectTarget_None)
1735 @@ -33,9 +33,6 @@ LAppView::LAppView():
1736 _clearColor[2] = 1.0f;
1737 _clearColor[3] = 0.0f;
1740 - _touchManager = new TouchManager();
1742 // デバイス座標からスクリーン座標に変換するための
1743 _deviceToScreen = new CubismMatrix44();
1745 @@ -47,12 +44,10 @@ LAppView::~LAppView()
1747 _renderBuffer.DestroyOffscreenFrame();
1748 delete _renderSprite;
1751 delete _deviceToScreen;
1752 - delete _touchManager;
1758 void LAppView::Initialize()
1759 @@ -75,7 +70,7 @@ void LAppView::Initialize()
1760 _viewMatrix->SetScreenRect(left, right, bottom, top); // デバイスに対応する画面の範囲。 Xの左端, Xの右端, Yの下端, Yの上端
1761 _viewMatrix->Scale(ViewScale, ViewScale);
1763 - _deviceToScreen->LoadIdentity(); // サイズが変わった際などリセット必須
1764 + _deviceToScreen->LoadIdentity();
1767 float screenW = fabsf(right - left);
1768 @@ -104,8 +99,6 @@ void LAppView::Initialize()
1769 void LAppView::Render()
1775 LAppLive2DManager* Live2DManager = LAppLive2DManager::GetInstance();
1777 @@ -125,7 +118,7 @@ void LAppView::Render()
1781 - for (csmUint32 i = 0; i < Live2DManager->GetModelNum(); i++)
1782 + for(csmUint32 i=0; i<Live2DManager->GetModelNum(); i++)
1784 float alpha = GetSpriteAlpha(i); // サンプルとしてαに適当な差をつける
1785 _renderSprite->SetColor(1.0f, 1.0f, 1.0f, alpha);
1786 @@ -133,7 +126,7 @@ void LAppView::Render()
1787 LAppModel *model = Live2DManager->GetModel(i);
1790 - _renderSprite->RenderImmidiate( model->GetRenderBuffer().GetColorBuffer(), uvVertex);
1791 + _renderSprite->RenderImmidiate(model->GetRenderBuffer().GetColorBuffer(), uvVertex);
1795 @@ -147,85 +140,22 @@ void LAppView::InitializeSprite()
1796 glfwGetWindowSize(LAppDelegate::GetInstance()->GetWindow(), &width, &height);
1798 LAppTextureManager* textureManager = LAppDelegate::GetInstance()->GetTextureManager();
1799 - const string resourcesPath = ResourcesPath;
1801 - string imageName = BackImageName;
1802 - LAppTextureManager::TextureInfo* backgroundTexture = textureManager->CreateTextureFromPngFile(resourcesPath + imageName);
1804 + LAppTextureManager::TextureInfo* backgroundTexture =
1805 + textureManager->CreateTextureFromColor(0, 255, 0);
1807 float x = width * 0.5f;
1808 float y = height * 0.5f;
1809 - float fWidth = static_cast<float>(backgroundTexture->width * 2.0f);
1810 - float fHeight = static_cast<float>(height * 0.95f);
1811 + float fWidth = static_cast<float>(width);
1812 + float fHeight = static_cast<float>(height);
1813 _back = new LAppSprite(x, y, fWidth, fHeight, backgroundTexture->id, _programId);
1815 - imageName = GearImageName;
1816 - LAppTextureManager::TextureInfo* gearTexture = textureManager->CreateTextureFromPngFile(resourcesPath + imageName);
1818 - x = static_cast<float>(width - gearTexture->width * 0.5f);
1819 - y = static_cast<float>(height - gearTexture->height * 0.5f);
1820 - fWidth = static_cast<float>(gearTexture->width);
1821 - fHeight = static_cast<float>(gearTexture->height);
1822 - _gear = new LAppSprite(x, y, fWidth, fHeight, gearTexture->id, _programId);
1824 - imageName = PowerImageName;
1825 - LAppTextureManager::TextureInfo* powerTexture = textureManager->CreateTextureFromPngFile(resourcesPath + imageName);
1827 - x = static_cast<float>(width - powerTexture->width * 0.5f);
1828 - y = static_cast<float>(powerTexture->height * 0.5f);
1829 - fWidth = static_cast<float>(powerTexture->width);
1830 - fHeight = static_cast<float>(powerTexture->height);
1831 - _power = new LAppSprite(x, y, fWidth, fHeight, powerTexture->id, _programId);
1836 _renderSprite = new LAppSprite(x, y, static_cast<float>(width), static_cast<float>(height), 0, _programId);
1839 -void LAppView::OnTouchesBegan(float px, float py) const
1841 - _touchManager->TouchesBegan(px, py);
1844 -void LAppView::OnTouchesMoved(float px, float py) const
1846 - float viewX = this->TransformViewX(_touchManager->GetX());
1847 - float viewY = this->TransformViewY(_touchManager->GetY());
1849 - _touchManager->TouchesMoved(px, py);
1851 - LAppLive2DManager* Live2DManager = LAppLive2DManager::GetInstance();
1852 - Live2DManager->OnDrag(viewX, viewY);
1855 -void LAppView::OnTouchesEnded(float px, float py) const
1858 - LAppLive2DManager* live2DManager = LAppLive2DManager::GetInstance();
1859 - live2DManager->OnDrag(0.0f, 0.0f);
1863 - float x = _deviceToScreen->TransformX(_touchManager->GetX()); // 論理座標変換した座標を取得。
1864 - float y = _deviceToScreen->TransformY(_touchManager->GetY()); // 論理座標変換した座標を取得。
1865 - if (DebugTouchLogEnable)
1867 - LAppPal::PrintLog("[APP]touchesEnded x:%.2f y:%.2f", x, y);
1869 - live2DManager->OnTap(x, y);
1872 - if (_gear->IsHit(px, py))
1874 - live2DManager->NextScene();
1878 - if (_power->IsHit(px, py))
1880 - LAppDelegate::GetInstance()->AppEnd();
1885 float LAppView::TransformViewX(float deviceX) const
1886 @@ -250,7 +180,7 @@ float LAppView::TransformScreenY(float d
1887 return _deviceToScreen->TransformY(deviceY);
1890 -void LAppView::PreModelDraw(LAppModel& refModel)
1891 +void LAppView::PreModelDraw(LAppModel &refModel)
1893 // 別のレンダリングターゲットへ向けて描画する場合の使用するフレームバッファ
1894 Csm::Rendering::CubismOffscreenFrame_OpenGLES2* useTarget = NULL;
1895 @@ -263,12 +193,13 @@ void LAppView::PreModelDraw(LAppModel& r
1897 if (!useTarget->IsValid())
1898 {// 描画ターゲット内部未作成の場合はここで作成
1899 - int width, height;
1900 - glfwGetWindowSize(LAppDelegate::GetInstance()->GetWindow(), &width, &height);
1901 - if (width != 0 && height != 0)
1902 + int bufWidth, bufHeight;
1903 + glfwGetFramebufferSize(LAppDelegate::GetInstance()->GetWindow(), &bufWidth, &bufHeight);
1905 + if(bufWidth!=0 && bufHeight!=0)
1908 - useTarget->CreateOffscreenFrame(static_cast<csmUint32>(width), static_cast<csmUint32>(height));
1909 + useTarget->CreateOffscreenFrame(static_cast<csmUint32>(bufWidth), static_cast<csmUint32>(bufHeight));
1913 @@ -278,7 +209,7 @@ void LAppView::PreModelDraw(LAppModel& r
1917 -void LAppView::PostModelDraw(LAppModel& refModel)
1918 +void LAppView::PostModelDraw(LAppModel &refModel)
1920 // 別のレンダリングターゲットへ向けて描画する場合の使用するフレームバッファ
1921 Csm::Rendering::CubismOffscreenFrame_OpenGLES2* useTarget = NULL;
1922 @@ -368,32 +299,4 @@ void LAppView::ResizeSprite()
1923 _back->ResetRect(x, y, fWidth, fHeight);
1929 - GLuint id = _power->GetTextureId();
1930 - LAppTextureManager::TextureInfo* texInfo = textureManager->GetTextureInfoById(id);
1933 - x = static_cast<float>(width - texInfo->width * 0.5f);
1934 - y = static_cast<float>(texInfo->height * 0.5f);
1935 - fWidth = static_cast<float>(texInfo->width);
1936 - fHeight = static_cast<float>(texInfo->height);
1937 - _power->ResetRect(x, y, fWidth, fHeight);
1943 - GLuint id = _gear->GetTextureId();
1944 - LAppTextureManager::TextureInfo* texInfo = textureManager->GetTextureInfoById(id);
1947 - x = static_cast<float>(width - texInfo->width * 0.5f);
1948 - y = static_cast<float>(height - texInfo->height * 0.5f);
1949 - fWidth = static_cast<float>(texInfo->width);
1950 - fHeight = static_cast<float>(texInfo->height);
1951 - _gear->ResetRect(x, y, fWidth, fHeight);
1955 diff -pruN --exclude build ./demo_clean/src/LAppView.hpp ./demo_dev/src/LAppView.hpp
1956 --- ./demo_clean/src/LAppView.hpp 2023-02-20 11:39:40.000000000 +0000
1957 +++ ./demo_dev/src/LAppView.hpp 2023-03-05 23:22:10.892081200 +0000
1961 * Copyright(c) Live2D Inc. All rights reserved.
1963 * Use of this source code is governed by the Live2D Open Software license
1965 #include "CubismFramework.hpp"
1966 #include <Rendering/OpenGL/CubismOffscreenSurface_OpenGLES2.hpp>
1968 -class TouchManager;
1972 @@ -61,35 +60,11 @@ public:
1973 void InitializeSprite();
1976 - * @brief スプライト系のサイズ再設定
1978 + * @brief スプライト系のサイズ再設定
1980 void ResizeSprite();
1983 - * @brief タッチされたときに呼ばれる。
1985 - * @param[in] pointX スクリーンX座標
1986 - * @param[in] pointY スクリーンY座標
1988 - void OnTouchesBegan(float pointX, float pointY) const;
1991 - * @brief タッチしているときにポインタが動いたら呼ばれる。
1993 - * @param[in] pointX スクリーンX座標
1994 - * @param[in] pointY スクリーンY座標
1996 - void OnTouchesMoved(float pointX, float pointY) const;
1999 - * @brief タッチが終了したら呼ばれる。
2001 - * @param[in] pointX スクリーンX座標
2002 - * @param[in] pointY スクリーンY座標
2004 - void OnTouchesEnded(float pointX, float pointY) const;
2007 * @brief X座標をView座標に変換する。
2009 * @param[in] deviceX デバイスX座標
2010 @@ -120,12 +95,12 @@ public:
2012 * @brief モデル1体を描画する直前にコールされる
2014 - void PreModelDraw(LAppModel& refModel);
2015 + void PreModelDraw(LAppModel &refModel);
2018 * @brief モデル1体を描画した直後にコールされる
2020 - void PostModelDraw(LAppModel& refModel);
2021 + void PostModelDraw(LAppModel &refModel);
2024 * @brief 別レンダリングターゲットにモデルを描画するサンプルで
2025 @@ -147,16 +122,13 @@ public:
2026 void SetRenderTargetClearColor(float r, float g, float b);
2029 - TouchManager* _touchManager; ///< タッチマネージャー
2030 Csm::CubismMatrix44* _deviceToScreen; ///< デバイスからスクリーンへの行列
2031 Csm::CubismViewMatrix* _viewMatrix; ///< viewMatrix
2032 GLuint _programId; ///< シェーダID
2033 LAppSprite* _back; ///< 背景画像
2034 - LAppSprite* _gear; ///< ギア画像
2035 - LAppSprite* _power; ///< 電源画像
2037 // レンダリング先を別ターゲットにする方式の場合に使用
2038 - LAppSprite* _renderSprite; ///< モードによっては_renderBufferのテクスチャを描画
2039 + LAppSprite* _renderSprite; ///< モードによっては_renderBufferのテクスチャを描画
2040 Csm::Rendering::CubismOffscreenFrame_OpenGLES2 _renderBuffer; ///< モードによってはCubismモデル結果をこっちにレンダリング
2041 SelectTarget _renderTarget; ///< レンダリング先の選択肢
2042 float _clearColor[4]; ///< レンダリングターゲットのクリアカラー
2043 diff -pruN --exclude build ./demo_clean/src/MouseActionManager.cpp ./demo_dev/src/MouseActionManager.cpp
2044 --- ./demo_clean/src/MouseActionManager.cpp 2023-02-20 11:39:40.000000000 +0000
2045 +++ ./demo_dev/src/MouseActionManager.cpp 2023-03-05 23:22:10.841970900 +0000
2048 - * Copyright(c) Live2D Inc. All rights reserved.
2050 - * Use of this source code is governed by the Live2D Open Software license
2051 - * that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html.
2054 +* Copyright(c) Live2D Inc. All rights reserved.
2056 +* Use of this source code is governed by the Live2D Open Software license
2057 +* that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html.
2060 #include "MouseActionManager.hpp"
2062 @@ -13,7 +13,7 @@ namespace {
2064 MouseActionManager* MouseActionManager::GetInstance()
2066 - if (instance == NULL)
2069 instance = new MouseActionManager();
2071 @@ -23,7 +23,7 @@ MouseActionManager* MouseActionManager::
2073 void MouseActionManager::ReleaseInstance()
2075 - if (instance != NULL)
2080 @@ -99,18 +99,21 @@ void MouseActionManager::OnMouseCallBack
2084 - if (GLFW_PRESS == action)
2089 OnTouchesBegan(_mouseX, _mouseY);
2091 - else if (GLFW_RELEASE == action)
2094 + case GLFW_RELEASE:
2098 OnTouchesEnded(_mouseX, _mouseY);
2106 diff -pruN --exclude build ./demo_clean/src/MouseActionManager.hpp ./demo_dev/src/MouseActionManager.hpp
2107 --- ./demo_clean/src/MouseActionManager.hpp 2023-02-20 11:39:40.000000000 +0000
2108 +++ ./demo_dev/src/MouseActionManager.hpp 2023-03-05 23:22:10.961094400 +0000
2112 * Copyright(c) Live2D Inc. All rights reserved.
2114 * Use of this source code is governed by the Live2D Open Software license
2115 diff -pruN --exclude build ./demo_clean/src/TouchManager.cpp ./demo_dev/src/TouchManager.cpp
2116 --- ./demo_clean/src/TouchManager.cpp 2023-02-20 11:39:40.000000000 +0000
2117 +++ ./demo_dev/src/TouchManager.cpp 2023-03-05 23:22:10.861957900 +0000
2121 * Copyright(c) Live2D Inc. All rights reserved.
2123 * Use of this source code is governed by the Live2D Open Software license
2124 diff -pruN --exclude build ./demo_clean/src/TouchManager.hpp ./demo_dev/src/TouchManager.hpp
2125 --- ./demo_clean/src/TouchManager.hpp 2023-02-20 11:39:40.000000000 +0000
2126 +++ ./demo_dev/src/TouchManager.hpp 2023-03-05 23:22:10.884102300 +0000
2130 * Copyright(c) Live2D Inc. All rights reserved.
2132 * Use of this source code is governed by the Live2D Open Software license
2133 diff -pruN --exclude build ./demo_clean/src/main.cpp ./demo_dev/src/main.cpp
2134 --- ./demo_clean/src/main.cpp 2023-02-20 11:39:40.000000000 +0000
2135 +++ ./demo_dev/src/main.cpp 2023-03-05 23:22:10.772150300 +0000
2139 * Copyright(c) Live2D Inc. All rights reserved.
2141 * Use of this source code is governed by the Live2D Open Software license
2142 * that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html.
2146 +#include <stdexcept>
2149 +#ifdef __cpp_lib_filesystem
2150 +#include <filesystem>
2151 +namespace fs = std::filesystem;
2153 +#include <experimental/filesystem>
2154 +namespace fs = std::experimental::filesystem;
2158 #include "LAppDelegate.hpp"
2159 +#include "LAppLive2DManager.hpp"
2160 +#include "facial_landmark_detector.h"
2165 - // create the application instance
2166 - if (LAppDelegate::GetInstance()->Initialize() == GL_FALSE)
2169 + std::string windowTitle;
2170 + std::string rootDir;
2171 + float scaleFactor;
2174 + std::string modelName;
2175 + bool oldId; // If true, translate new (Cubism 3+) parameter IDs to old (Cubism 2.1) IDs
2176 + std::string cfgPath; // Path to config file for FacialLandmarkDetector
2179 +CmdArgs parseArgv(int argc, char *argv[])
2181 + // I think the command-line args are simple enough to not justify using a library...
2183 + // Set default values
2184 + cmdArgs.windowWidth = 600;
2185 + cmdArgs.windowHeight = 600;
2186 + cmdArgs.windowTitle = "FacialLandmarksForCubism example";
2187 + cmdArgs.rootDir = fs::current_path().string();
2188 + cmdArgs.scaleFactor = 4.5f;
2189 + cmdArgs.translateX = 0.0f;
2190 + cmdArgs.translateY = -3.1f;
2191 + cmdArgs.modelName = "Haru";
2192 + cmdArgs.oldId = false;
2193 + cmdArgs.cfgPath = "";
2199 + std::string arg = argv[i];
2200 + std::stringstream ss;
2202 + if (arg == "--window-width" || arg == "-W") // capital W for consistency with height
2204 + ss << argv[i + 1];
2205 + if (!(ss >> cmdArgs.windowWidth))
2207 + throw std::runtime_error("Invalid argument for window width");
2210 + else if (arg == "--window-height" || arg == "-H") // avoiding "-h", typically for help
2212 + ss << argv[i + 1];
2213 + if (!(ss >> cmdArgs.windowHeight))
2215 + throw std::runtime_error("Invalid argument for window height");
2218 + else if (arg == "--window-title" || arg == "-t")
2220 + cmdArgs.windowTitle = argv[i + 1];
2222 + else if (arg == "--root-dir" || arg == "-d")
2224 + cmdArgs.rootDir = argv[i + 1];
2226 + else if (arg == "--scale-factor" || arg == "-f")
2228 + ss << argv[i + 1];
2229 + if (!(ss >> cmdArgs.scaleFactor))
2231 + throw std::runtime_error("Invalid argument for scale factor");
2234 + else if (arg == "--translate-x" || arg == "-x")
2236 + ss << argv[i + 1];
2237 + if (!(ss >> cmdArgs.translateX))
2239 + throw std::runtime_error("Invalid argument for translate X");
2242 + else if (arg == "--translate-y" || arg == "-y")
2244 + ss << argv[i + 1];
2245 + if (!(ss >> cmdArgs.translateY))
2247 + throw std::runtime_error("Invalid argument for translate Y");
2250 + else if (arg == "--model" || arg == "-m")
2252 + cmdArgs.modelName = argv[i + 1];
2254 + else if (arg == "--config" || arg == "-c")
2256 + cmdArgs.cfgPath = argv[i + 1];
2258 + else if (arg == "--old-param-id" || arg == "-o")
2260 + cmdArgs.oldId = (argv[i + 1][0] == '1');
2264 + throw std::runtime_error("Unrecognized argument: " + arg);
2270 - LAppDelegate::GetInstance()->Run();
2274 +int main(int argc, char* argv[])
2276 + auto cmdArgs = parseArgv(argc, argv);
2278 + LAppDelegate *delegate = LAppDelegate::GetInstance();
2280 + if (!delegate->Initialize(cmdArgs.windowWidth,
2281 + cmdArgs.windowHeight,
2282 + cmdArgs.windowTitle.c_str()))
2284 + throw std::runtime_error("Unable to initialize LAppDelegate");
2287 + delegate->SetRootDirectory(cmdArgs.rootDir);
2289 + FacialLandmarkDetector detector(cmdArgs.cfgPath);
2291 + std::thread detectorThread(&FacialLandmarkDetector::mainLoop,
2294 + LAppLive2DManager *manager = LAppLive2DManager::GetInstance();
2295 + manager->SetModel(cmdArgs.modelName, cmdArgs.oldId);
2297 + manager->SetProjectionScaleTranslate(cmdArgs.scaleFactor,
2298 + cmdArgs.translateX,
2299 + cmdArgs.translateY);
2300 + manager->SetFacialLandmarkDetector(&detector);
2305 + detectorThread.join();
2310 diff -pruN --exclude build ./demo_clean/src/mainMinimum.cpp ./demo_dev/src/mainMinimum.cpp
2311 --- ./demo_clean/src/mainMinimum.cpp 2023-02-20 11:39:40.000000000 +0000
2312 +++ ./demo_dev/src/mainMinimum.cpp 2023-03-05 23:22:10.854990900 +0000
2316 * Copyright(c) Live2D Inc. All rights reserved.
2318 * Use of this source code is governed by the Live2D Open Software license
2321 #include <functional>
2323 -#include <stb_image.h>
2325 +#include <unistd.h>
2326 #include <GL/glew.h>
2327 #include <GLFW/glfw3.h>
2330 #include "LAppAllocator.hpp"
2331 #include "LAppTextureManager.hpp"
2332 #include "LAppPal.hpp"
2333 -#include "TouchManager.hpp"
2334 #include "CubismUserModelExtend.hpp"
2335 -#include "CubismSampleViewMatrix.hpp"
2336 #include "MouseActionManager.hpp"
2338 #include <CubismFramework.hpp>
2339 -#include <CubismDefaultParameterId.hpp>
2340 #include <CubismModelSettingJson.hpp>
2341 #include <Model/CubismUserModel.hpp>
2342 #include <Physics/CubismPhysics.hpp>
2343 #include <Rendering/OpenGL/CubismRenderer_OpenGLES2.hpp>
2344 #include <Utils/CubismString.hpp>
2345 -#include <Math/CubismViewMatrix.hpp>
2348 *@brief モデルデータのディレクトリ名
2350 static const Csm::csmChar* _modelDirectoryName = "Hiyori";
2352 static Csm::CubismUserModel* _userModel; ///< ユーザーが実際に使用するモデル
2353 -static Csm::CubismModelSettingJson* _modelJson; ///< モデルの設定情報
2354 -static Csm::CubismModel* _model; ///< Mocデータから作成されるモデルデータ
2356 Csm::csmFloat32 _userTimeSeconds; ///< デルタ時間の積算値[秒]
2357 Csm::csmVector<Csm::CubismIdHandle> _eyeBlinkIds; ///< モデルに設定されたまばたき機能用パラメータID
2358 @@ -66,8 +61,8 @@ static LAppAllocator _cubismAllocator; /
2360 static LAppTextureManager* _textureManager; ///< テクスチャの管理
2362 +static std::string _rootDirectory; ///< ルートディレクトリ
2363 static std::string _currentModelDirectory; ///< 現在のモデルのディレクトリ名
2364 -const Csm::csmChar* _currentModelDirectoryChar; ///< 現在のモデルのディレクトリ名のconst csmCharポインタ型
2366 static GLFWwindow* _window; ///< ウィンドウオブジェクト
2368 @@ -90,6 +85,59 @@ static void InitializeCubism()
2374 +* 指定された区切り文字で文字列を分割する
2376 +Csm::csmVector<std::string> Split(const std::string& baseString, char delimiter)
2378 + Csm::csmVector < std::string > elems;
2379 + std::stringstream ss(baseString);
2382 + while (getline(ss, item, delimiter))
2384 + if (!item.empty())
2386 + elems.PushBack(item);
2394 +* @brief ルートディレクトリの設定
2396 +* Linuxのルートディレクトリを確認し、パスを取得する
2398 +void SetRootDirectory()
2400 + const int maximumPathBufferSize = 1024;
2401 + char path[maximumPathBufferSize];
2402 + ssize_t len = readlink("/proc/self/exe", path, maximumPathBufferSize - 1);
2409 + std::string pathString(path);
2411 + pathString = pathString.substr(0, pathString.rfind("Demo"));
2412 + Csm::csmVector<std::string> splitStrings = Split(pathString, '/');
2414 + _rootDirectory = "";
2416 + for (int i = 0; i < splitStrings.GetSize(); i++)
2418 + _rootDirectory += "/" + splitStrings[i];
2421 + _rootDirectory += "/";
2428 @@ -149,6 +197,8 @@ static bool InitializeSystem()
2430 MouseActionManager::GetInstance()->Initialize(windowWidth, windowHeight);
2432 + SetRootDirectory();
2437 @@ -182,16 +232,6 @@ void Release()
2441 -* @brief ディレクトリパスの設定
2443 -* モデルのディレクトリパスを設定する
2445 -void SetAssetDirectory(const std::string& path)
2447 - _currentModelDirectory = path;
2454 @@ -201,13 +241,15 @@ void SetAssetDirectory(const std::string
2455 void LoadModel(const std::string modelDirectoryName)
2458 - SetAssetDirectory(LAppDefine::ResourcesPath + modelDirectoryName + "/");
2459 + _currentModelDirectory = _rootDirectory + LAppDefine::ResourcesPath + modelDirectoryName + "/";
2462 _userModel = new CubismUserModelExtend(modelDirectoryName, _currentModelDirectory);
2464 // モデルデータの読み込み及び生成とセットアップを行う
2465 - static_cast<CubismUserModelExtend*>(_userModel)->SetupModel();
2466 + std::string json = ".model3.json";
2467 + std::string fileName = _modelDirectoryName + json;
2468 + static_cast<CubismUserModelExtend*>(_userModel)->LoadAssets(fileName.c_str());
2470 // ユーザーモデルをMouseActionManagerへ渡す
2471 MouseActionManager::GetInstance()->SetUserModel(_userModel);