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