| 1 | diff -pruN --exclude build ./demo_clean/CMakeLists.txt ./demo_dev/CMakeLists.txt |
| 2 | --- ./demo_clean/CMakeLists.txt 2024-03-28 18:19:03.168248400 +0000 |
| 3 | +++ ./demo_dev/CMakeLists.txt 2024-03-28 18:23:33.549413300 +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-5-r.1) |
| 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 2024-03-28 18:19:03.998153300 +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 2024-03-28 18:19:03.868189000 +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 | +void CubismUserModelExtend::LoadAssets(const Csm::csmChar* fileName) |
| 138 | { |
| 139 | - return _currentModelDirectory + assetFileName; |
| 140 | -} |
| 141 | - |
| 142 | -void CubismUserModelExtend::SetAssetDirectory(const std::string& path) |
| 143 | -{ |
| 144 | - _currentModelDirectory = path; |
| 145 | -} |
| 146 | + csmSizeInt size; |
| 147 | + const csmString path = csmString(_currentModelDirectory.c_str()) + fileName; |
| 148 | |
| 149 | -void CubismUserModelExtend::LoadAsset(const std::string & fiileName, const std::function<void(Csm::csmByte*, Csm::csmSizeInt)>& afterLoadCallback) |
| 150 | -{ |
| 151 | - Csm::csmSizeInt bufferSize = 0; |
| 152 | - Csm::csmByte* buffer = nullptr; |
| 153 | - |
| 154 | - if (fiileName.empty()) |
| 155 | - { |
| 156 | - return; |
| 157 | - } |
| 158 | + csmByte* buffer = CreateBuffer(path.GetRawString(), &size); |
| 159 | + _modelJson = new CubismModelSettingJson(buffer, size); |
| 160 | + DeleteBuffer(buffer, path.GetRawString()); |
| 161 | |
| 162 | - // バッファの設定 |
| 163 | - buffer = LAppPal::LoadFileAsBytes(MakeAssetPath(fiileName).c_str(), &bufferSize); |
| 164 | - |
| 165 | - // コールバック関数の呼び出し |
| 166 | - afterLoadCallback(buffer, bufferSize); |
| 167 | - |
| 168 | - // バッファの解放 |
| 169 | - LAppPal::ReleaseBytes(buffer); |
| 170 | + // モデルの生成 |
| 171 | + SetupModel(); |
| 172 | } |
| 173 | |
| 174 | void CubismUserModelExtend::SetupModel() |
| 175 | @@ -109,44 +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 | + const csmInt32 count = _modelJson->GetExpressionCount(); |
| 205 | + for (csmInt32 i = 0; i < count; i++) |
| 206 | + { |
| 207 | + csmString name = _modelJson->GetExpressionName(i); |
| 208 | + csmString path = _modelJson->GetExpressionFileName(i); |
| 209 | + path = csmString(_currentModelDirectory.c_str()) + path; |
| 210 | |
| 211 | - if (motion) |
| 212 | + buffer = CreateBuffer(path.GetRawString(), &size); |
| 213 | + ACubismMotion* motion = LoadExpression(buffer, size, name.GetRawString()); |
| 214 | + |
| 215 | + if (_expressions[name]) |
| 216 | { |
| 217 | - if (_expressions[expressionName]) |
| 218 | - { |
| 219 | - ACubismMotion::Delete(_expressions[expressionName]); |
| 220 | - _expressions[expressionName] = nullptr; |
| 221 | - } |
| 222 | - _expressions[expressionName] = motion; |
| 223 | + ACubismMotion::Delete(_expressions[name]); |
| 224 | + _expressions[name] = nullptr; |
| 225 | } |
| 226 | - }); |
| 227 | + _expressions[name] = motion; |
| 228 | + |
| 229 | + DeleteBuffer(buffer, path.GetRawString()); |
| 230 | + } |
| 231 | } |
| 232 | |
| 233 | //ポーズデータの読み込み |
| 234 | - LoadAsset(_modelJson->GetPoseFileName(), [=](Csm::csmByte* buffer, Csm::csmSizeInt bufferSize) { |
| 235 | - LoadPose(buffer, bufferSize); |
| 236 | - }); |
| 237 | + if (strcmp(_modelJson->GetPoseFileName(), "")) |
| 238 | + { |
| 239 | + csmString path = _modelJson->GetPoseFileName(); |
| 240 | + path = csmString(_currentModelDirectory.c_str()) + path; |
| 241 | + |
| 242 | + buffer = CreateBuffer(path.GetRawString(), &size); |
| 243 | + LoadPose(buffer, size); |
| 244 | + DeleteBuffer(buffer, path.GetRawString()); |
| 245 | + } |
| 246 | |
| 247 | // 物理演算データの読み込み |
| 248 | - LoadAsset(_modelJson->GetPhysicsFileName(), [=](Csm::csmByte* buffer, Csm::csmSizeInt bufferSize) { |
| 249 | - LoadPhysics(buffer, bufferSize); |
| 250 | - }); |
| 251 | + if (strcmp(_modelJson->GetPhysicsFileName(), "")) |
| 252 | + { |
| 253 | + csmString path = _modelJson->GetPhysicsFileName(); |
| 254 | + path = csmString(_currentModelDirectory.c_str()) + path; |
| 255 | + |
| 256 | + buffer = CreateBuffer(path.GetRawString(), &size); |
| 257 | + LoadPhysics(buffer, size); |
| 258 | + DeleteBuffer(buffer, path.GetRawString()); |
| 259 | + } |
| 260 | |
| 261 | // モデルに付属するユーザーデータの読み込み |
| 262 | - LoadAsset(_modelJson->GetUserDataFile(), [=](Csm::csmByte* buffer, Csm::csmSizeInt bufferSize) { |
| 263 | - LoadUserData(buffer, bufferSize); |
| 264 | - }); |
| 265 | + if (strcmp(_modelJson->GetUserDataFile(), "")) |
| 266 | + { |
| 267 | + csmString path = _modelJson->GetUserDataFile(); |
| 268 | + path = csmString(_currentModelDirectory.c_str()) + path; |
| 269 | + buffer = CreateBuffer(path.GetRawString(), &size); |
| 270 | + LoadUserData(buffer, size); |
| 271 | + DeleteBuffer(buffer, path.GetRawString()); |
| 272 | + } |
| 273 | |
| 274 | // Layout |
| 275 | csmMap<csmString, csmFloat32> layout; |
| 276 | @@ -196,29 +210,26 @@ void CubismUserModelExtend::PreloadMotio |
| 277 | // モーションデータの読み込み |
| 278 | CubismMotion* tmpMotion = static_cast<CubismMotion*>(LoadMotion(buffer, size, name.GetRawString())); |
| 279 | |
| 280 | - if (tmpMotion) |
| 281 | + // フェードインの時間を取得 |
| 282 | + csmFloat32 fadeTime = _modelJson->GetMotionFadeInTimeValue(group, i); |
| 283 | + if (fadeTime >= 0.0f) |
| 284 | { |
| 285 | - // フェードインの時間を取得 |
| 286 | - csmFloat32 fadeTime = _modelJson->GetMotionFadeInTimeValue(group, i); |
| 287 | - if (fadeTime >= 0.0f) |
| 288 | - { |
| 289 | - tmpMotion->SetFadeInTime(fadeTime); |
| 290 | - } |
| 291 | + tmpMotion->SetFadeInTime(fadeTime); |
| 292 | + } |
| 293 | |
| 294 | - // フェードアウトの時間を取得 |
| 295 | - fadeTime = _modelJson->GetMotionFadeOutTimeValue(group, i); |
| 296 | - if (fadeTime >= 0.0f) |
| 297 | - { |
| 298 | - tmpMotion->SetFadeOutTime(fadeTime); |
| 299 | - } |
| 300 | + // フェードアウトの時間を取得 |
| 301 | + fadeTime = _modelJson->GetMotionFadeOutTimeValue(group, i); |
| 302 | + if (fadeTime >= 0.0f) |
| 303 | + { |
| 304 | + tmpMotion->SetFadeOutTime(fadeTime); |
| 305 | + } |
| 306 | |
| 307 | - if (_motions[name]) |
| 308 | - { |
| 309 | - // インスタンスを破棄 |
| 310 | - ACubismMotion::Delete(_motions[name]); |
| 311 | - } |
| 312 | - _motions[name] = tmpMotion; |
| 313 | + if (_motions[name]) |
| 314 | + { |
| 315 | + // インスタンスを破棄 |
| 316 | + ACubismMotion::Delete(_motions[name]); |
| 317 | } |
| 318 | + _motions[name] = tmpMotion; |
| 319 | |
| 320 | DeleteBuffer(buffer, path.GetRawString()); |
| 321 | } |
| 322 | @@ -292,24 +303,21 @@ Csm::CubismMotionQueueEntryHandle Cubism |
| 323 | // 一番先頭のモーションを読み込む |
| 324 | motion = static_cast<CubismMotion*>(LoadMotion(buffer, size, NULL, onFinishedMotionHandler)); |
| 325 | |
| 326 | - if (motion) |
| 327 | + csmFloat32 fadeTime = _modelJson->GetMotionFadeInTimeValue(group, no); |
| 328 | + if (fadeTime >= 0.0f) |
| 329 | { |
| 330 | - csmFloat32 fadeTime = _modelJson->GetMotionFadeInTimeValue(group, no); |
| 331 | - if (fadeTime >= 0.0f) |
| 332 | - { |
| 333 | - motion->SetFadeInTime(fadeTime); |
| 334 | - } |
| 335 | - |
| 336 | - fadeTime = _modelJson->GetMotionFadeOutTimeValue(group, no); |
| 337 | - if (fadeTime >= 0.0f) |
| 338 | - { |
| 339 | - motion->SetFadeOutTime(fadeTime); |
| 340 | - } |
| 341 | + motion->SetFadeInTime(fadeTime); |
| 342 | + } |
| 343 | |
| 344 | - // 終了時にメモリから削除 |
| 345 | - autoDelete = true; |
| 346 | + fadeTime = _modelJson->GetMotionFadeOutTimeValue(group, no); |
| 347 | + if (fadeTime >= 0.0f) |
| 348 | + { |
| 349 | + motion->SetFadeOutTime(fadeTime); |
| 350 | } |
| 351 | |
| 352 | + // 終了時にメモリから削除 |
| 353 | + autoDelete = true; |
| 354 | + |
| 355 | DeleteBuffer(buffer, path.GetRawString()); |
| 356 | } |
| 357 | else |
| 358 | @@ -355,16 +363,6 @@ void CubismUserModelExtend::ModelParamUp |
| 359 | _model->SaveParameters(); |
| 360 | //----------------------------------------------------------------- |
| 361 | |
| 362 | - // メインモーションの更新がないとき |
| 363 | - if (!motionUpdated) |
| 364 | - { |
| 365 | - if (_eyeBlink) |
| 366 | - { |
| 367 | - // まばたき |
| 368 | - _eyeBlink->UpdateParameters(_model, deltaTimeSeconds); |
| 369 | - } |
| 370 | - } |
| 371 | - |
| 372 | if (_expressionManager) |
| 373 | { |
| 374 | // 表情でパラメータ更新(相対変化) |
| 375 | @@ -387,12 +385,6 @@ void CubismUserModelExtend::ModelParamUp |
| 376 | _model->AddParameterValue(_idParamEyeBallX, _dragX); // -1から1の値を加える |
| 377 | _model->AddParameterValue(_idParamEyeBallY, _dragY); |
| 378 | |
| 379 | - // 呼吸など |
| 380 | - if (_breath) |
| 381 | - { |
| 382 | - _breath->UpdateParameters(_model, deltaTimeSeconds); |
| 383 | - } |
| 384 | - |
| 385 | // 物理演算の設定 |
| 386 | if (_physics) |
| 387 | { |
| 388 | diff -pruN --exclude build ./demo_clean/src/CubismUserModelExtend.hpp ./demo_dev/src/CubismUserModelExtend.hpp |
| 389 | --- ./demo_clean/src/CubismUserModelExtend.hpp 2024-03-28 18:19:03.926168700 +0000 |
| 390 | +++ ./demo_dev/src/CubismUserModelExtend.hpp 2023-03-05 23:22:10.986750400 +0000 |
| 391 | @@ -27,17 +27,13 @@ class CubismUserModelExtend : |
| 392 | { |
| 393 | public: |
| 394 | CubismUserModelExtend(const std::string modelDirectoryName, const std::string _currentModelDirectory); ///< コンストラクタ |
| 395 | - virtual ~CubismUserModelExtend(); ///< デストラクタ |
| 396 | + ~CubismUserModelExtend(); ///< デストラクタ |
| 397 | |
| 398 | /** |
| 399 | - * @brief model3.jsonからモデルを生成する |
| 400 | - * |
| 401 | - * model3.jsonの記述に従ってモデル生成、モーション、物理演算などのコンポーネント生成を行う |
| 402 | - * |
| 403 | - * @param[in] setting ICubismModelSettingのインスタンス |
| 404 | + * @brief model3.jsonが置かれたディレクトリとファイルパスからモデルを生成する |
| 405 | * |
| 406 | */ |
| 407 | - void SetupModel(); |
| 408 | + void LoadAssets(const Csm::csmChar* fileName); |
| 409 | |
| 410 | /** |
| 411 | * @brief モデルの更新 |
| 412 | @@ -48,35 +44,24 @@ public: |
| 413 | |
| 414 | private: |
| 415 | /** |
| 416 | - * @brief パスを作成 |
| 417 | + * @brief model3.jsonからモデルを生成する |
| 418 | * |
| 419 | - * アセットのパスを作成する |
| 420 | - */ |
| 421 | - std::string MakeAssetPath(const std::string & assetFileName); |
| 422 | - |
| 423 | - /** |
| 424 | - * @brief ディレクトリパスの設定 |
| 425 | + * model3.jsonの記述に従ってモデル生成、モーション、物理演算などのコンポーネント生成を行う |
| 426 | + * |
| 427 | + * @param[in] setting ICubismModelSettingのインスタンス |
| 428 | * |
| 429 | - * モデルのディレクトリパスを設定する |
| 430 | */ |
| 431 | - void SetAssetDirectory(const std::string & path); |
| 432 | + void SetupModel(); |
| 433 | |
| 434 | /** |
| 435 | - * @brief アセットのロードを行う |
| 436 | + * @brief 引数で指定したモーションの再生を開始する |
| 437 | * |
| 438 | - * 指定されたファイル名からアセットのロードを行う |
| 439 | + * @param[in] group モーショングループ名 |
| 440 | + * @param[in] no グループ内の番号 |
| 441 | + * @param[in] priority 優先度 |
| 442 | + * @param[in] onFinishedMotionHandler モーション再生終了時に呼び出されるコールバック関数。NULLの場合、呼び出されない。 |
| 443 | + * @return 開始したモーションの識別番号を返す。個別のモーションが終了したか否かを判定するIsFinished()の引数で使用する。開始できない時は「-1」 |
| 444 | */ |
| 445 | - void LoadAsset(const std::string & fiileName, const std::function<void(Csm::csmByte*, Csm::csmSizeInt)>& afterLoadCallback); |
| 446 | - |
| 447 | - /** |
| 448 | - * @brief 引数で指定したモーションの再生を開始する |
| 449 | - * |
| 450 | - * @param[in] group モーショングループ名 |
| 451 | - * @param[in] no グループ内の番号 |
| 452 | - * @param[in] priority 優先度 |
| 453 | - * @param[in] onFinishedMotionHandler モーション再生終了時に呼び出されるコールバック関数。NULLの場合、呼び出されない。 |
| 454 | - * @return 開始したモーションの識別番号を返す。個別のモーションが終了したか否かを判定するIsFinished()の引数で使用する。開始できない時は「-1」 |
| 455 | - */ |
| 456 | Csm::CubismMotionQueueEntryHandle StartMotion(const Csm::csmChar* group, Csm::csmInt32 no, Csm::csmInt32 priority, Csm::ACubismMotion::FinishedMotionCallback onFinishedMotionHandler = NULL); |
| 457 | |
| 458 | /** |
| 459 | diff -pruN --exclude build ./demo_clean/src/LAppAllocator.cpp ./demo_dev/src/LAppAllocator.cpp |
| 460 | --- ./demo_clean/src/LAppAllocator.cpp 2024-03-28 18:19:03.800631600 +0000 |
| 461 | +++ ./demo_dev/src/LAppAllocator.cpp 2023-03-05 23:22:10.847976000 +0000 |
| 462 | @@ -1,4 +1,4 @@ |
| 463 | -/** |
| 464 | +/** |
| 465 | * Copyright(c) Live2D Inc. All rights reserved. |
| 466 | * |
| 467 | * Use of this source code is governed by the Live2D Open Software license |
| 468 | @@ -9,7 +9,7 @@ |
| 469 | |
| 470 | using namespace Csm; |
| 471 | |
| 472 | -void* LAppAllocator::Allocate(const csmSizeType size) |
| 473 | +void* LAppAllocator::Allocate(const csmSizeType size) |
| 474 | { |
| 475 | return malloc(size); |
| 476 | } |
| 477 | diff -pruN --exclude build ./demo_clean/src/LAppAllocator.hpp ./demo_dev/src/LAppAllocator.hpp |
| 478 | --- ./demo_clean/src/LAppAllocator.hpp 2024-03-28 18:19:04.446046500 +0000 |
| 479 | +++ ./demo_dev/src/LAppAllocator.hpp 2023-03-05 23:22:10.953083600 +0000 |
| 480 | @@ -1,4 +1,4 @@ |
| 481 | -/** |
| 482 | +/** |
| 483 | * Copyright(c) Live2D Inc. All rights reserved. |
| 484 | * |
| 485 | * Use of this source code is governed by the Live2D Open Software license |
| 486 | diff -pruN --exclude build ./demo_clean/src/LAppDefine.cpp ./demo_dev/src/LAppDefine.cpp |
| 487 | --- ./demo_clean/src/LAppDefine.cpp 2024-03-28 18:19:04.269187200 +0000 |
| 488 | +++ ./demo_dev/src/LAppDefine.cpp 2023-03-05 23:22:10.995458800 +0000 |
| 489 | @@ -1,4 +1,4 @@ |
| 490 | -/** |
| 491 | +/** |
| 492 | * Copyright(c) Live2D Inc. All rights reserved. |
| 493 | * |
| 494 | * Use of this source code is governed by the Live2D Open Software license |
| 495 | @@ -20,7 +20,7 @@ namespace LAppDefine { |
| 496 | const csmFloat32 ViewLogicalLeft = -1.0f; |
| 497 | const csmFloat32 ViewLogicalRight = 1.0f; |
| 498 | const csmFloat32 ViewLogicalBottom = -1.0f; |
| 499 | - const csmFloat32 ViewLogicalTop = -1.0f; |
| 500 | + const csmFloat32 ViewLogicalTop = 1.0f; |
| 501 | |
| 502 | const csmFloat32 ViewLogicalMaxLeft = -2.0f; |
| 503 | const csmFloat32 ViewLogicalMaxRight = 2.0f; |
| 504 | @@ -38,6 +38,18 @@ namespace LAppDefine { |
| 505 | const csmChar* PowerImageName = "close.png"; |
| 506 | |
| 507 | // モデル定義------------------------------------------ |
| 508 | + // モデルを配置したディレクトリ名の配列 |
| 509 | + // ディレクトリ名とmodel3.jsonの名前を一致させておくこと |
| 510 | + const csmChar* ModelDir[] = { |
| 511 | + "Haru", |
| 512 | + "Hiyori", |
| 513 | + "Mark", |
| 514 | + "Natori", |
| 515 | + "Rice", |
| 516 | + "Mao" |
| 517 | + }; |
| 518 | + const csmInt32 ModelDirSize = sizeof(ModelDir) / sizeof(const csmChar*); |
| 519 | + |
| 520 | // 外部定義ファイル(json)と合わせる |
| 521 | const csmChar* MotionGroupIdle = "Idle"; // アイドリング |
| 522 | const csmChar* MotionGroupTapBody = "TapBody"; // 体をタップしたとき |
| 523 | @@ -52,9 +64,6 @@ namespace LAppDefine { |
| 524 | const csmInt32 PriorityNormal = 2; |
| 525 | const csmInt32 PriorityForce = 3; |
| 526 | |
| 527 | - // MOC3の整合性検証オプション |
| 528 | - const csmBool MocConsistencyValidationEnable = true; |
| 529 | - |
| 530 | // デバッグ用ログの表示オプション |
| 531 | const csmBool DebugLogEnable = true; |
| 532 | const csmBool DebugTouchLogEnable = false; |
| 533 | diff -pruN --exclude build ./demo_clean/src/LAppDefine.hpp ./demo_dev/src/LAppDefine.hpp |
| 534 | --- ./demo_clean/src/LAppDefine.hpp 2024-03-28 18:19:03.690794600 +0000 |
| 535 | +++ ./demo_dev/src/LAppDefine.hpp 2023-03-05 23:22:10.947784100 +0000 |
| 536 | @@ -1,9 +1,10 @@ |
| 537 | -/** |
| 538 | +/** |
| 539 | * Copyright(c) Live2D Inc. All rights reserved. |
| 540 | * |
| 541 | * Use of this source code is governed by the Live2D Open Software license |
| 542 | * that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html. |
| 543 | */ |
| 544 | + |
| 545 | #pragma once |
| 546 | |
| 547 | #include <CubismFramework.hpp> |
| 548 | @@ -36,6 +37,9 @@ namespace LAppDefine { |
| 549 | extern const csmChar* PowerImageName; ///< 終了ボタン画像ファイル |
| 550 | |
| 551 | // モデル定義-------------------------------------------- |
| 552 | + extern const csmChar* ModelDir[]; ///< モデルを配置したディレクトリ名の配列. ディレクトリ名とmodel3.jsonの名前を一致させておく. |
| 553 | + extern const csmInt32 ModelDirSize; ///< モデルディレクトリ配列のサイズ |
| 554 | + |
| 555 | // 外部定義ファイル(json)と合わせる |
| 556 | extern const csmChar* MotionGroupIdle; ///< アイドリング時に再生するモーションのリスト |
| 557 | extern const csmChar* MotionGroupTapBody; ///< 体をタップした時に再生するモーションのリスト |
| 558 | @@ -50,8 +54,6 @@ namespace LAppDefine { |
| 559 | extern const csmInt32 PriorityNormal; ///< モーションの優先度定数: 2 |
| 560 | extern const csmInt32 PriorityForce; ///< モーションの優先度定数: 3 |
| 561 | |
| 562 | - extern const csmBool MocConsistencyValidationEnable; ///< MOC3の整合性検証機能の有効・無効 |
| 563 | - |
| 564 | // デバッグ用ログの表示 |
| 565 | extern const csmBool DebugLogEnable; ///< デバッグ用ログ表示の有効・無効 |
| 566 | extern const csmBool DebugTouchLogEnable; ///< タッチ処理のデバッグ用ログ表示の有効・無効 |
| 567 | diff -pruN --exclude build ./demo_clean/src/LAppDelegate.cpp ./demo_dev/src/LAppDelegate.cpp |
| 568 | --- ./demo_clean/src/LAppDelegate.cpp 2024-03-28 18:19:03.753278100 +0000 |
| 569 | +++ ./demo_dev/src/LAppDelegate.cpp 2023-03-05 23:22:10.975780100 +0000 |
| 570 | @@ -1,4 +1,4 @@ |
| 571 | -/** |
| 572 | +/** |
| 573 | * Copyright(c) Live2D Inc. All rights reserved. |
| 574 | * |
| 575 | * Use of this source code is governed by the Live2D Open Software license |
| 576 | @@ -7,6 +7,7 @@ |
| 577 | |
| 578 | #include "LAppDelegate.hpp" |
| 579 | #include <iostream> |
| 580 | +#include <sstream> |
| 581 | #include <GL/glew.h> |
| 582 | #include <GLFW/glfw3.h> |
| 583 | #include "LAppView.hpp" |
| 584 | @@ -43,11 +44,12 @@ void LAppDelegate::ReleaseInstance() |
| 585 | s_instance = NULL; |
| 586 | } |
| 587 | |
| 588 | -bool LAppDelegate::Initialize() |
| 589 | +bool LAppDelegate::Initialize(int initWindowWidth, int initWindowHeight, |
| 590 | + const char *windowTitle) |
| 591 | { |
| 592 | if (DebugLogEnable) |
| 593 | { |
| 594 | - LAppPal::PrintLogLn("START"); |
| 595 | + LAppPal::PrintLog("START"); |
| 596 | } |
| 597 | |
| 598 | // GLFWの初期化 |
| 599 | @@ -55,18 +57,24 @@ bool LAppDelegate::Initialize() |
| 600 | { |
| 601 | if (DebugLogEnable) |
| 602 | { |
| 603 | - LAppPal::PrintLogLn("Can't initilize GLFW"); |
| 604 | + LAppPal::PrintLog("Can't initilize GLFW"); |
| 605 | } |
| 606 | return GL_FALSE; |
| 607 | } |
| 608 | |
| 609 | // Windowの生成_ |
| 610 | - _window = glfwCreateWindow(RenderTargetWidth, RenderTargetHeight, "SAMPLE", NULL, NULL); |
| 611 | + _window = glfwCreateWindow( |
| 612 | + initWindowWidth ? initWindowWidth : RenderTargetWidth, |
| 613 | + initWindowHeight ? initWindowHeight : RenderTargetHeight, |
| 614 | + windowTitle ? windowTitle : "SAMPLE", |
| 615 | + NULL, |
| 616 | + NULL); |
| 617 | + |
| 618 | if (_window == NULL) |
| 619 | { |
| 620 | if (DebugLogEnable) |
| 621 | { |
| 622 | - LAppPal::PrintLogLn("Can't create GLFW window."); |
| 623 | + LAppPal::PrintLog("Can't create GLFW window."); |
| 624 | } |
| 625 | glfwTerminate(); |
| 626 | return GL_FALSE; |
| 627 | @@ -79,7 +87,7 @@ bool LAppDelegate::Initialize() |
| 628 | if (glewInit() != GLEW_OK) { |
| 629 | if (DebugLogEnable) |
| 630 | { |
| 631 | - LAppPal::PrintLogLn("Can't initilize glew."); |
| 632 | + LAppPal::PrintLog("Can't initilize glew."); |
| 633 | } |
| 634 | glfwTerminate(); |
| 635 | return GL_FALSE; |
| 636 | @@ -93,10 +101,6 @@ bool LAppDelegate::Initialize() |
| 637 | glEnable(GL_BLEND); |
| 638 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
| 639 | |
| 640 | - //コールバック関数の登録 |
| 641 | - glfwSetMouseButtonCallback(_window, EventHandler::OnMouseCallBack); |
| 642 | - glfwSetCursorPosCallback(_window, EventHandler::OnMouseCallBack); |
| 643 | - |
| 644 | // ウィンドウサイズ記憶 |
| 645 | int width, height; |
| 646 | glfwGetWindowSize(LAppDelegate::GetInstance()->GetWindow(), &width, &height); |
| 647 | @@ -106,9 +110,15 @@ bool LAppDelegate::Initialize() |
| 648 | //AppViewの初期化 |
| 649 | _view->Initialize(); |
| 650 | |
| 651 | - // Cubism SDK の初期化 |
| 652 | + // Cubism3の初期化 |
| 653 | InitializeCubism(); |
| 654 | |
| 655 | + //load model |
| 656 | + LAppLive2DManager::GetInstance(); |
| 657 | + |
| 658 | + //load sprite |
| 659 | + _view->InitializeSprite(); |
| 660 | + |
| 661 | return GL_TRUE; |
| 662 | } |
| 663 | |
| 664 | @@ -125,7 +135,7 @@ void LAppDelegate::Release() |
| 665 | // リソースを解放 |
| 666 | LAppLive2DManager::ReleaseInstance(); |
| 667 | |
| 668 | - //Cubism SDK の解放 |
| 669 | + //Cubism3の解放 |
| 670 | CubismFramework::Dispose(); |
| 671 | } |
| 672 | |
| 673 | @@ -136,18 +146,13 @@ void LAppDelegate::Run() |
| 674 | { |
| 675 | int width, height; |
| 676 | glfwGetWindowSize(LAppDelegate::GetInstance()->GetWindow(), &width, &height); |
| 677 | - if( (_windowWidth!=width || _windowHeight!=height) && width>0 && height>0) |
| 678 | + if((_windowWidth!=width || _windowHeight!=height) && width>0 && height>0) |
| 679 | { |
| 680 | - //AppViewの初期化 |
| 681 | _view->Initialize(); |
| 682 | - // スプライトサイズを再設定 |
| 683 | _view->ResizeSprite(); |
| 684 | - // サイズを保存しておく |
| 685 | + |
| 686 | _windowWidth = width; |
| 687 | _windowHeight = height; |
| 688 | - |
| 689 | - // ビューポート変更 |
| 690 | - glViewport(0, 0, width, height); |
| 691 | } |
| 692 | |
| 693 | // 時間更新 |
| 694 | @@ -183,6 +188,7 @@ LAppDelegate::LAppDelegate(): |
| 695 | _windowWidth(0), |
| 696 | _windowHeight(0) |
| 697 | { |
| 698 | + _rootDirectory = ""; |
| 699 | _view = new LAppView(); |
| 700 | _textureManager = new LAppTextureManager(); |
| 701 | } |
| 702 | @@ -202,58 +208,10 @@ void LAppDelegate::InitializeCubism() |
| 703 | //Initialize cubism |
| 704 | CubismFramework::Initialize(); |
| 705 | |
| 706 | - //load model |
| 707 | - LAppLive2DManager::GetInstance(); |
| 708 | - |
| 709 | //default proj |
| 710 | CubismMatrix44 projection; |
| 711 | |
| 712 | LAppPal::UpdateTime(); |
| 713 | - |
| 714 | - _view->InitializeSprite(); |
| 715 | -} |
| 716 | - |
| 717 | -void LAppDelegate::OnMouseCallBack(GLFWwindow* window, int button, int action, int modify) |
| 718 | -{ |
| 719 | - if (_view == NULL) |
| 720 | - { |
| 721 | - return; |
| 722 | - } |
| 723 | - if (GLFW_MOUSE_BUTTON_LEFT != button) |
| 724 | - { |
| 725 | - return; |
| 726 | - } |
| 727 | - |
| 728 | - if (GLFW_PRESS == action) |
| 729 | - { |
| 730 | - _captured = true; |
| 731 | - _view->OnTouchesBegan(_mouseX, _mouseY); |
| 732 | - } |
| 733 | - else if (GLFW_RELEASE == action) |
| 734 | - { |
| 735 | - if (_captured) |
| 736 | - { |
| 737 | - _captured = false; |
| 738 | - _view->OnTouchesEnded(_mouseX, _mouseY); |
| 739 | - } |
| 740 | - } |
| 741 | -} |
| 742 | - |
| 743 | -void LAppDelegate::OnMouseCallBack(GLFWwindow* window, double x, double y) |
| 744 | -{ |
| 745 | - _mouseX = static_cast<float>(x); |
| 746 | - _mouseY = static_cast<float>(y); |
| 747 | - |
| 748 | - if (!_captured) |
| 749 | - { |
| 750 | - return; |
| 751 | - } |
| 752 | - if (_view == NULL) |
| 753 | - { |
| 754 | - return; |
| 755 | - } |
| 756 | - |
| 757 | - _view->OnTouchesMoved(_mouseX, _mouseY); |
| 758 | } |
| 759 | |
| 760 | GLuint LAppDelegate::CreateShader() |
| 761 | @@ -271,10 +229,6 @@ GLuint LAppDelegate::CreateShader() |
| 762 | "}"; |
| 763 | glShaderSource(vertexShaderId, 1, &vertexShader, NULL); |
| 764 | glCompileShader(vertexShaderId); |
| 765 | - if(!CheckShader(vertexShaderId)) |
| 766 | - { |
| 767 | - return 0; |
| 768 | - } |
| 769 | |
| 770 | //フラグメントシェーダのコンパイル |
| 771 | GLuint fragmentShaderId = glCreateShader(GL_FRAGMENT_SHADER); |
| 772 | @@ -288,10 +242,6 @@ GLuint LAppDelegate::CreateShader() |
| 773 | "}"; |
| 774 | glShaderSource(fragmentShaderId, 1, &fragmentShader, NULL); |
| 775 | glCompileShader(fragmentShaderId); |
| 776 | - if (!CheckShader(fragmentShaderId)) |
| 777 | - { |
| 778 | - return 0; |
| 779 | - } |
| 780 | |
| 781 | //プログラムオブジェクトの作成 |
| 782 | GLuint programId = glCreateProgram(); |
| 783 | @@ -306,25 +256,24 @@ GLuint LAppDelegate::CreateShader() |
| 784 | return programId; |
| 785 | } |
| 786 | |
| 787 | -bool LAppDelegate::CheckShader(GLuint shaderId) |
| 788 | +void LAppDelegate::SetRootDirectory(std::string rootDir) |
| 789 | { |
| 790 | - GLint status; |
| 791 | - GLint logLength; |
| 792 | - glGetShaderiv(shaderId, GL_INFO_LOG_LENGTH, &logLength); |
| 793 | - if (logLength > 0) |
| 794 | - { |
| 795 | - GLchar* log = reinterpret_cast<GLchar*>(CSM_MALLOC(logLength)); |
| 796 | - glGetShaderInfoLog(shaderId, logLength, &logLength, log); |
| 797 | - CubismLogError("Shader compile log: %s", log); |
| 798 | - CSM_FREE(log); |
| 799 | - } |
| 800 | + this->_rootDirectory = rootDir + "/"; |
| 801 | +} |
| 802 | + |
| 803 | +Csm::csmVector<string> LAppDelegate::Split(const std::string& baseString, char delimiter) |
| 804 | +{ |
| 805 | + Csm::csmVector<string> elems; |
| 806 | + stringstream ss(baseString); |
| 807 | + string item; |
| 808 | |
| 809 | - glGetShaderiv(shaderId, GL_COMPILE_STATUS, &status); |
| 810 | - if (status == GL_FALSE) |
| 811 | + while(getline(ss, item, delimiter)) |
| 812 | { |
| 813 | - glDeleteShader(shaderId); |
| 814 | - return false; |
| 815 | + if(!item.empty()) |
| 816 | + { |
| 817 | + elems.PushBack(item); |
| 818 | + } |
| 819 | } |
| 820 | |
| 821 | - return true; |
| 822 | + return elems; |
| 823 | } |
| 824 | diff -pruN --exclude build ./demo_clean/src/LAppDelegate.hpp ./demo_dev/src/LAppDelegate.hpp |
| 825 | --- ./demo_clean/src/LAppDelegate.hpp 2024-03-28 18:19:04.100879300 +0000 |
| 826 | +++ ./demo_dev/src/LAppDelegate.hpp 2023-03-05 23:22:10.789104800 +0000 |
| 827 | @@ -1,4 +1,4 @@ |
| 828 | -/** |
| 829 | +/** |
| 830 | * Copyright(c) Live2D Inc. All rights reserved. |
| 831 | * |
| 832 | * Use of this source code is governed by the Live2D Open Software license |
| 833 | @@ -7,8 +7,10 @@ |
| 834 | |
| 835 | #pragma once |
| 836 | |
| 837 | +#include <string> |
| 838 | #include <GL/glew.h> |
| 839 | #include <GLFW/glfw3.h> |
| 840 | +#include "Type/csmVector.hpp" |
| 841 | #include "LAppAllocator.hpp" |
| 842 | |
| 843 | class LAppView; |
| 844 | @@ -16,7 +18,7 @@ class LAppTextureManager; |
| 845 | |
| 846 | /** |
| 847 | * @brief アプリケーションクラス。 |
| 848 | -* Cubism SDK の管理を行う。 |
| 849 | +* Cubism3の管理を行う。 |
| 850 | */ |
| 851 | class LAppDelegate |
| 852 | { |
| 853 | @@ -38,7 +40,8 @@ public: |
| 854 | /** |
| 855 | * @brief APPに必要なものを初期化する。 |
| 856 | */ |
| 857 | - bool Initialize(); |
| 858 | + bool Initialize(int initWindowWidth = 0, int initWindowHeight = 0, |
| 859 | + const char *windowTitle = "SAMPLE"); |
| 860 | |
| 861 | /** |
| 862 | * @brief 解放する。 |
| 863 | @@ -51,25 +54,6 @@ public: |
| 864 | void Run(); |
| 865 | |
| 866 | /** |
| 867 | - * @brief OpenGL用 glfwSetMouseButtonCallback用関数。 |
| 868 | - * |
| 869 | - * @param[in] window コールバックを呼んだWindow情報 |
| 870 | - * @param[in] button ボタン種類 |
| 871 | - * @param[in] action 実行結果 |
| 872 | - * @param[in] modify |
| 873 | - */ |
| 874 | - void OnMouseCallBack(GLFWwindow* window, int button, int action, int modify); |
| 875 | - |
| 876 | - /** |
| 877 | - * @brief OpenGL用 glfwSetCursorPosCallback用関数。 |
| 878 | - * |
| 879 | - * @param[in] window コールバックを呼んだWindow情報 |
| 880 | - * @param[in] x x座標 |
| 881 | - * @param[in] y x座標 |
| 882 | - */ |
| 883 | - void OnMouseCallBack(GLFWwindow* window, double x, double y); |
| 884 | - |
| 885 | - /** |
| 886 | * @brief シェーダーを登録する。 |
| 887 | */ |
| 888 | GLuint CreateShader(); |
| 889 | @@ -94,6 +78,21 @@ public: |
| 890 | */ |
| 891 | void AppEnd() { _isEnd = true; } |
| 892 | |
| 893 | + /** |
| 894 | + * @brief ルートディレクトリを設定する。 |
| 895 | + * |
| 896 | + * @param[in] rootDir : The root directory to set to. |
| 897 | + */ |
| 898 | + void SetRootDirectory(std::string rootDir); |
| 899 | + |
| 900 | + /** |
| 901 | + * @brief ルートディレクトリを取得する。 |
| 902 | + */ |
| 903 | + std::string GetRootDirectory(){ return _rootDirectory;} |
| 904 | + |
| 905 | + /** |
| 906 | + * @brief テクスチャマネージャーを取得する。 |
| 907 | + */ |
| 908 | LAppTextureManager* GetTextureManager() { return _textureManager; } |
| 909 | |
| 910 | private: |
| 911 | @@ -108,17 +107,17 @@ private: |
| 912 | ~LAppDelegate(); |
| 913 | |
| 914 | /** |
| 915 | - * @brief Cubism SDK の初期化 |
| 916 | + * @brief Cubism3の初期化 |
| 917 | */ |
| 918 | void InitializeCubism(); |
| 919 | |
| 920 | /** |
| 921 | - * @brief CreateShader内部関数 エラーチェック |
| 922 | + * @brief 文字列を指定の文字で切り分ける |
| 923 | */ |
| 924 | - bool CheckShader(GLuint shaderId); |
| 925 | + Csm::csmVector<std::string> Split(const std::string& baseString, char delim); |
| 926 | |
| 927 | - LAppAllocator _cubismAllocator; ///< Cubism SDK Allocator |
| 928 | - Csm::CubismFramework::Option _cubismOption; ///< Cubism SDK Option |
| 929 | + LAppAllocator _cubismAllocator; ///< Cubism3 Allocator |
| 930 | + Csm::CubismFramework::Option _cubismOption; ///< Cubism3 Option |
| 931 | GLFWwindow* _window; ///< OpenGL ウィンドウ |
| 932 | LAppView* _view; ///< View情報 |
| 933 | bool _captured; ///< クリックしているか |
| 934 | @@ -126,28 +125,8 @@ private: |
| 935 | float _mouseY; ///< マウスY座標 |
| 936 | bool _isEnd; ///< APP終了しているか |
| 937 | LAppTextureManager* _textureManager; ///< テクスチャマネージャー |
| 938 | + std::string _rootDirectory; ///< ルートディレクトリ |
| 939 | |
| 940 | int _windowWidth; ///< Initialize関数で設定したウィンドウ幅 |
| 941 | int _windowHeight; ///< Initialize関数で設定したウィンドウ高さ |
| 942 | }; |
| 943 | - |
| 944 | -class EventHandler |
| 945 | -{ |
| 946 | -public: |
| 947 | - /** |
| 948 | - * @brief glfwSetMouseButtonCallback用コールバック関数。 |
| 949 | - */ |
| 950 | - static void OnMouseCallBack(GLFWwindow* window, int button, int action, int modify) |
| 951 | - { |
| 952 | - LAppDelegate::GetInstance()->OnMouseCallBack(window, button, action, modify); |
| 953 | - } |
| 954 | - |
| 955 | - /** |
| 956 | - * @brief glfwSetCursorPosCallback用コールバック関数。 |
| 957 | - */ |
| 958 | - static void OnMouseCallBack(GLFWwindow* window, double x, double y) |
| 959 | - { |
| 960 | - LAppDelegate::GetInstance()->OnMouseCallBack(window, x, y); |
| 961 | - } |
| 962 | - |
| 963 | -}; |
| 964 | diff -pruN --exclude build ./demo_clean/src/LAppLive2DManager.cpp ./demo_dev/src/LAppLive2DManager.cpp |
| 965 | --- ./demo_clean/src/LAppLive2DManager.cpp 2024-03-28 18:19:04.069617100 +0000 |
| 966 | +++ ./demo_dev/src/LAppLive2DManager.cpp 2023-03-05 23:22:10.967799000 +0000 |
| 967 | @@ -1,4 +1,4 @@ |
| 968 | -/** |
| 969 | +/** |
| 970 | * Copyright(c) Live2D Inc. All rights reserved. |
| 971 | * |
| 972 | * Use of this source code is governed by the Live2D Open Software license |
| 973 | @@ -6,9 +6,7 @@ |
| 974 | */ |
| 975 | |
| 976 | #include "LAppLive2DManager.hpp" |
| 977 | -#include <stdio.h> |
| 978 | -#include <stdlib.h> |
| 979 | -#include <io.h> |
| 980 | +#include <string> |
| 981 | #include <GL/glew.h> |
| 982 | #include <GLFW/glfw3.h> |
| 983 | #include <Rendering/CubismRenderer.hpp> |
| 984 | @@ -17,6 +15,7 @@ |
| 985 | #include "LAppDelegate.hpp" |
| 986 | #include "LAppModel.hpp" |
| 987 | #include "LAppView.hpp" |
| 988 | +#include "LAppSprite.hpp" |
| 989 | |
| 990 | using namespace Csm; |
| 991 | using namespace LAppDefine; |
| 992 | @@ -27,13 +26,7 @@ namespace { |
| 993 | |
| 994 | void FinishedMotion(ACubismMotion* self) |
| 995 | { |
| 996 | - LAppPal::PrintLogLn("Motion Finished: %x", self); |
| 997 | - } |
| 998 | - |
| 999 | - int CompareCsmString(const void* a, const void* b) |
| 1000 | - { |
| 1001 | - return strcmp(reinterpret_cast<const Csm::csmString*>(a)->GetRawString(), |
| 1002 | - reinterpret_cast<const Csm::csmString*>(b)->GetRawString()); |
| 1003 | + LAppPal::PrintLog("Motion Finished: %x", self); |
| 1004 | } |
| 1005 | } |
| 1006 | |
| 1007 | @@ -59,18 +52,16 @@ void LAppLive2DManager::ReleaseInstance( |
| 1008 | |
| 1009 | LAppLive2DManager::LAppLive2DManager() |
| 1010 | : _viewMatrix(NULL) |
| 1011 | - , _sceneIndex(0) |
| 1012 | + , _projScaleFactor(1.0f) |
| 1013 | + , _translateX(0.0f) |
| 1014 | + , _translateY(0.0f) |
| 1015 | { |
| 1016 | _viewMatrix = new CubismMatrix44(); |
| 1017 | - SetUpModel(); |
| 1018 | - |
| 1019 | - ChangeScene(_sceneIndex); |
| 1020 | } |
| 1021 | |
| 1022 | LAppLive2DManager::~LAppLive2DManager() |
| 1023 | { |
| 1024 | ReleaseAllModel(); |
| 1025 | - delete _viewMatrix; |
| 1026 | } |
| 1027 | |
| 1028 | void LAppLive2DManager::ReleaseAllModel() |
| 1029 | @@ -83,50 +74,6 @@ void LAppLive2DManager::ReleaseAllModel( |
| 1030 | _models.Clear(); |
| 1031 | } |
| 1032 | |
| 1033 | -void LAppLive2DManager::SetUpModel() |
| 1034 | -{ |
| 1035 | - // ResourcesPathの中にあるフォルダ名を全てクロールし、モデルが存在するフォルダを定義する。 |
| 1036 | - // フォルダはあるが同名の.model3.jsonが見つからなかった場合はリストに含めない。 |
| 1037 | - csmString crawlPath(ResourcesPath); |
| 1038 | - crawlPath += "*.*"; |
| 1039 | - |
| 1040 | - struct _finddata_t fdata; |
| 1041 | - intptr_t fh = _findfirst(crawlPath.GetRawString(), &fdata); |
| 1042 | - if (fh == -1) return; |
| 1043 | - |
| 1044 | - _modelDir.Clear(); |
| 1045 | - |
| 1046 | - while (_findnext(fh, &fdata) == 0) |
| 1047 | - { |
| 1048 | - if ((fdata.attrib & _A_SUBDIR) && strcmp(fdata.name, "..") != 0) |
| 1049 | - { |
| 1050 | - // フォルダと同名の.model3.jsonがあるか探索する |
| 1051 | - csmString model3jsonPath(ResourcesPath); |
| 1052 | - model3jsonPath += fdata.name; |
| 1053 | - model3jsonPath.Append(1, '/'); |
| 1054 | - model3jsonPath += fdata.name; |
| 1055 | - model3jsonPath += ".model3.json"; |
| 1056 | - |
| 1057 | - struct _finddata_t fdata2; |
| 1058 | - if (_findfirst(model3jsonPath.GetRawString(), &fdata2) != -1) |
| 1059 | - { |
| 1060 | - _modelDir.PushBack(csmString(fdata.name)); |
| 1061 | - } |
| 1062 | - } |
| 1063 | - } |
| 1064 | - qsort(_modelDir.GetPtr(), _modelDir.GetSize(), sizeof(csmString), CompareCsmString); |
| 1065 | -} |
| 1066 | - |
| 1067 | -csmVector<csmString> LAppLive2DManager::GetModelDir() const |
| 1068 | -{ |
| 1069 | - return _modelDir; |
| 1070 | -} |
| 1071 | - |
| 1072 | -csmInt32 LAppLive2DManager::GetModelDirSize() const |
| 1073 | -{ |
| 1074 | - return _modelDir.GetSize(); |
| 1075 | -} |
| 1076 | - |
| 1077 | LAppModel* LAppLive2DManager::GetModel(csmUint32 no) const |
| 1078 | { |
| 1079 | if (no < _models.GetSize()) |
| 1080 | @@ -151,27 +98,7 @@ void LAppLive2DManager::OnTap(csmFloat32 |
| 1081 | { |
| 1082 | if (DebugLogEnable) |
| 1083 | { |
| 1084 | - LAppPal::PrintLogLn("[APP]tap point: {x:%.2f y:%.2f}", x, y); |
| 1085 | - } |
| 1086 | - |
| 1087 | - for (csmUint32 i = 0; i < _models.GetSize(); i++) |
| 1088 | - { |
| 1089 | - if (_models[i]->HitTest(HitAreaNameHead, x, y)) |
| 1090 | - { |
| 1091 | - if (DebugLogEnable) |
| 1092 | - { |
| 1093 | - LAppPal::PrintLogLn("[APP]hit area: [%s]", HitAreaNameHead); |
| 1094 | - } |
| 1095 | - _models[i]->SetRandomExpression(); |
| 1096 | - } |
| 1097 | - else if (_models[i]->HitTest(HitAreaNameBody, x, y)) |
| 1098 | - { |
| 1099 | - if (DebugLogEnable) |
| 1100 | - { |
| 1101 | - LAppPal::PrintLogLn("[APP]hit area: [%s]", HitAreaNameBody); |
| 1102 | - } |
| 1103 | - _models[i]->StartRandomMotion(MotionGroupTapBody, PriorityNormal, FinishedMotion); |
| 1104 | - } |
| 1105 | + LAppPal::PrintLog("[APP]tap point: {x:%.2f y:%.2f}", x, y); |
| 1106 | } |
| 1107 | } |
| 1108 | |
| 1109 | @@ -180,15 +107,15 @@ void LAppLive2DManager::OnUpdate() const |
| 1110 | int width, height; |
| 1111 | glfwGetWindowSize(LAppDelegate::GetInstance()->GetWindow(), &width, &height); |
| 1112 | |
| 1113 | + CubismMatrix44 projection; |
| 1114 | csmUint32 modelCount = _models.GetSize(); |
| 1115 | for (csmUint32 i = 0; i < modelCount; ++i) |
| 1116 | { |
| 1117 | - CubismMatrix44 projection; |
| 1118 | LAppModel* model = GetModel(i); |
| 1119 | |
| 1120 | if (model->GetModel() == NULL) |
| 1121 | { |
| 1122 | - LAppPal::PrintLogLn("Failed to model->GetModel()."); |
| 1123 | + LAppPal::PrintLog("Failed to model->GetModel()."); |
| 1124 | continue; |
| 1125 | } |
| 1126 | |
| 1127 | @@ -196,12 +123,15 @@ void LAppLive2DManager::OnUpdate() const |
| 1128 | { |
| 1129 | // 横に長いモデルを縦長ウィンドウに表示する際モデルの横サイズでscaleを算出する |
| 1130 | model->GetModelMatrix()->SetWidth(2.0f); |
| 1131 | - projection.Scale(1.0f, static_cast<float>(width) / static_cast<float>(height)); |
| 1132 | + projection.Scale(_projScaleFactor, |
| 1133 | + _projScaleFactor * static_cast<float>(width) / static_cast<float>(height)); |
| 1134 | } |
| 1135 | else |
| 1136 | { |
| 1137 | - projection.Scale(static_cast<float>(height) / static_cast<float>(width), 1.0f); |
| 1138 | + projection.Scale(_projScaleFactor * static_cast<float>(height) / static_cast<float>(width), |
| 1139 | + _projScaleFactor); |
| 1140 | } |
| 1141 | + projection.Translate(_translateX, _translateY); |
| 1142 | |
| 1143 | // 必要があればここで乗算 |
| 1144 | if (_viewMatrix != NULL) |
| 1145 | @@ -209,45 +139,24 @@ void LAppLive2DManager::OnUpdate() const |
| 1146 | projection.MultiplyByMatrix(_viewMatrix); |
| 1147 | } |
| 1148 | |
| 1149 | - // モデル1体描画前コール |
| 1150 | LAppDelegate::GetInstance()->GetView()->PreModelDraw(*model); |
| 1151 | |
| 1152 | model->Update(); |
| 1153 | model->Draw(projection);///< 参照渡しなのでprojectionは変質する |
| 1154 | |
| 1155 | - // モデル1体描画後コール |
| 1156 | LAppDelegate::GetInstance()->GetView()->PostModelDraw(*model); |
| 1157 | } |
| 1158 | } |
| 1159 | |
| 1160 | -void LAppLive2DManager::NextScene() |
| 1161 | +void LAppLive2DManager::SetModel(std::string modelName, bool useOldParamId) |
| 1162 | { |
| 1163 | - csmInt32 no = (_sceneIndex + 1) % GetModelDirSize(); |
| 1164 | - ChangeScene(no); |
| 1165 | -} |
| 1166 | - |
| 1167 | -void LAppLive2DManager::ChangeScene(Csm::csmInt32 index) |
| 1168 | -{ |
| 1169 | - _sceneIndex = index; |
| 1170 | - if (DebugLogEnable) |
| 1171 | - { |
| 1172 | - LAppPal::PrintLogLn("[APP]model index: %d", _sceneIndex); |
| 1173 | - } |
| 1174 | - |
| 1175 | - // model3.jsonのパスを決定する. |
| 1176 | - // ディレクトリ名とmodel3.jsonの名前を一致していることが条件 |
| 1177 | - const csmString& model = _modelDir[index]; |
| 1178 | - |
| 1179 | - csmString modelPath(ResourcesPath); |
| 1180 | - modelPath += model; |
| 1181 | - modelPath.Append(1, '/'); |
| 1182 | - |
| 1183 | - csmString modelJsonName(model); |
| 1184 | + std::string modelPath = LAppDelegate::GetInstance()->GetRootDirectory() + ResourcesPath + modelName + "/"; |
| 1185 | + std::string modelJsonName = modelName; |
| 1186 | modelJsonName += ".model3.json"; |
| 1187 | |
| 1188 | ReleaseAllModel(); |
| 1189 | - _models.PushBack(new LAppModel()); |
| 1190 | - _models[0]->LoadAssets(modelPath.GetRawString(), modelJsonName.GetRawString()); |
| 1191 | + _models.PushBack(new LAppModel(useOldParamId)); |
| 1192 | + _models[0]->LoadAssets(modelPath.c_str(), modelJsonName.c_str()); |
| 1193 | |
| 1194 | /* |
| 1195 | * モデル半透明表示を行うサンプルを提示する。 |
| 1196 | @@ -268,16 +177,21 @@ void LAppLive2DManager::ChangeScene(Csm: |
| 1197 | |
| 1198 | #if defined(USE_RENDER_TARGET) || defined(USE_MODEL_RENDER_TARGET) |
| 1199 | // モデル個別にαを付けるサンプルとして、もう1体モデルを作成し、少し位置をずらす |
| 1200 | - _models.PushBack(new LAppModel()); |
| 1201 | - _models[1]->LoadAssets(modelPath.GetRawString(), modelJsonName.GetRawString()); |
| 1202 | + _models.PushBack(new LAppModel(useOldParamId)); |
| 1203 | + _models[1]->LoadAssets(modelPath.c_str(), modelJsonName.c_str()); |
| 1204 | _models[1]->GetModelMatrix()->TranslateX(0.2f); |
| 1205 | #endif |
| 1206 | |
| 1207 | + float clearColor[3] = { 1.0f, 1.0f, 1.0f }; |
| 1208 | + |
| 1209 | LAppDelegate::GetInstance()->GetView()->SwitchRenderingTarget(useRenderTarget); |
| 1210 | |
| 1211 | - // 別レンダリング先を選択した際の背景クリア色 |
| 1212 | - float clearColor[3] = { 1.0f, 1.0f, 1.0f }; |
| 1213 | - LAppDelegate::GetInstance()->GetView()->SetRenderTargetClearColor(clearColor[0], clearColor[1], clearColor[2]); |
| 1214 | + if(useRenderTarget) |
| 1215 | + { |
| 1216 | + LAppDelegate::GetInstance()->GetView()->SwitchRenderingTarget(useRenderTarget); |
| 1217 | + // 背景クリア色 |
| 1218 | + LAppDelegate::GetInstance()->GetView()->SetRenderTargetClearColor(clearColor[0], clearColor[1], clearColor[2]); |
| 1219 | + } |
| 1220 | } |
| 1221 | } |
| 1222 | |
| 1223 | @@ -292,3 +206,20 @@ void LAppLive2DManager::SetViewMatrix(Cu |
| 1224 | _viewMatrix->GetArray()[i] = m->GetArray()[i]; |
| 1225 | } |
| 1226 | } |
| 1227 | + |
| 1228 | +void LAppLive2DManager::SetFacialLandmarkDetector(FacialLandmarkDetector *detector) |
| 1229 | +{ |
| 1230 | + for (auto it = _models.Begin(); it != _models.End(); ++it) |
| 1231 | + { |
| 1232 | + (*it)->SetFacialLandmarkDetector(detector); |
| 1233 | + } |
| 1234 | +} |
| 1235 | + |
| 1236 | +void LAppLive2DManager::SetProjectionScaleTranslate(float scaleFactor, |
| 1237 | + float translateX, |
| 1238 | + float translateY) |
| 1239 | +{ |
| 1240 | + _projScaleFactor = scaleFactor; |
| 1241 | + _translateX = translateX; |
| 1242 | + _translateY = translateY; |
| 1243 | +} |
| 1244 | diff -pruN --exclude build ./demo_clean/src/LAppLive2DManager.hpp ./demo_dev/src/LAppLive2DManager.hpp |
| 1245 | --- ./demo_clean/src/LAppLive2DManager.hpp 2024-03-28 18:19:04.607350600 +0000 |
| 1246 | +++ ./demo_dev/src/LAppLive2DManager.hpp 2023-03-05 23:22:10.829032000 +0000 |
| 1247 | @@ -1,18 +1,20 @@ |
| 1248 | -/** |
| 1249 | +/** |
| 1250 | * Copyright(c) Live2D Inc. All rights reserved. |
| 1251 | * |
| 1252 | * Use of this source code is governed by the Live2D Open Software license |
| 1253 | * that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html. |
| 1254 | */ |
| 1255 | - |
| 1256 | #pragma once |
| 1257 | |
| 1258 | +#include <string> |
| 1259 | #include <CubismFramework.hpp> |
| 1260 | #include <Math/CubismMatrix44.hpp> |
| 1261 | #include <Type/csmVector.hpp> |
| 1262 | |
| 1263 | class LAppModel; |
| 1264 | |
| 1265 | +class FacialLandmarkDetector; |
| 1266 | + |
| 1267 | /** |
| 1268 | * @brief サンプルアプリケーションにおいてCubismModelを管理するクラス<br> |
| 1269 | * モデル生成と破棄、タップイベントの処理、モデル切り替えを行う。 |
| 1270 | @@ -37,24 +39,6 @@ public: |
| 1271 | static void ReleaseInstance(); |
| 1272 | |
| 1273 | /** |
| 1274 | - * @brief Resources フォルダにあるモデルフォルダ名をセットする |
| 1275 | - * |
| 1276 | - */ |
| 1277 | - void SetUpModel(); |
| 1278 | - |
| 1279 | - /** |
| 1280 | - * @brief Resources フォルダにあるモデルフォルダ名を取得する |
| 1281 | - * |
| 1282 | - */ |
| 1283 | - Csm::csmVector<Csm::csmString> GetModelDir() const; |
| 1284 | - |
| 1285 | - /** |
| 1286 | - * @brief Resources フォルダにあるモデルフォルダのサイズを取得する |
| 1287 | - * |
| 1288 | - */ |
| 1289 | - Csm::csmInt32 GetModelDirSize() const; |
| 1290 | - |
| 1291 | - /** |
| 1292 | * @brief 現在のシーンで保持しているモデルを返す |
| 1293 | * |
| 1294 | * @param[in] no モデルリストのインデックス値 |
| 1295 | @@ -91,16 +75,14 @@ public: |
| 1296 | void OnUpdate() const; |
| 1297 | |
| 1298 | /** |
| 1299 | - * @brief 次のシーンに切り替える<br> |
| 1300 | - * サンプルアプリケーションではモデルセットの切り替えを行う。 |
| 1301 | - */ |
| 1302 | - void NextScene(); |
| 1303 | - |
| 1304 | - /** |
| 1305 | - * @brief シーンを切り替える<br> |
| 1306 | - * サンプルアプリケーションではモデルセットの切り替えを行う。 |
| 1307 | - */ |
| 1308 | - void ChangeScene(Csm::csmInt32 index); |
| 1309 | + * @brief Set model data |
| 1310 | + * |
| 1311 | + * @param[in] modelName : Name of model, should be the same for both |
| 1312 | + * the directory and the model3.json file |
| 1313 | + * @param[in] useOldParamId : If true, translate new (Cubism 3+) |
| 1314 | + * parameter IDs to old (Cubism 2.1) ones |
| 1315 | + */ |
| 1316 | + void SetModel(std::string modelName, bool useOldParamId); |
| 1317 | |
| 1318 | /** |
| 1319 | * @brief モデル個数を得る |
| 1320 | @@ -113,6 +95,24 @@ public: |
| 1321 | */ |
| 1322 | void SetViewMatrix(Live2D::Cubism::Framework::CubismMatrix44* m); |
| 1323 | |
| 1324 | + /** |
| 1325 | + * @brief Set the pointer to the FacialLandmarkDetector instance |
| 1326 | + * |
| 1327 | + * @param[in] detector : Pointer to FacialLandmarkDetector instance |
| 1328 | + */ |
| 1329 | + void SetFacialLandmarkDetector(FacialLandmarkDetector *detector); |
| 1330 | + |
| 1331 | + /** |
| 1332 | + * @brief Set projection scale factor and translation parameters |
| 1333 | + * |
| 1334 | + * @param[in] scaleFactor : Scale factor applied in both X and Y directions |
| 1335 | + * @param[in] translateX : Translation in X direction |
| 1336 | + * @param[in] translateY : Translation in Y direction |
| 1337 | + */ |
| 1338 | + void SetProjectionScaleTranslate(float scaleFactor, |
| 1339 | + float translateX, |
| 1340 | + float translateY); |
| 1341 | + |
| 1342 | private: |
| 1343 | /** |
| 1344 | * @brief コンストラクタ |
| 1345 | @@ -124,9 +124,10 @@ private: |
| 1346 | */ |
| 1347 | virtual ~LAppLive2DManager(); |
| 1348 | |
| 1349 | - Csm::CubismMatrix44* _viewMatrix; ///< モデル描画に用いるView行列 |
| 1350 | - Csm::csmVector<LAppModel*> _models; ///< モデルインスタンスのコンテナ |
| 1351 | - Csm::csmInt32 _sceneIndex; ///< 表示するシーンのインデックス値 |
| 1352 | + Csm::CubismMatrix44* _viewMatrix; ///< モデル描画に用いるView行列 |
| 1353 | + Csm::csmVector<LAppModel*> _models; ///< モデルインスタンスのコンテナ |
| 1354 | |
| 1355 | - Csm::csmVector<Csm::csmString> _modelDir; ///< モデルディレクトリ名のコンテナ |
| 1356 | + float _projScaleFactor; |
| 1357 | + float _translateX; |
| 1358 | + float _translateY; |
| 1359 | }; |
| 1360 | diff -pruN --exclude build ./demo_clean/src/LAppModel.cpp ./demo_dev/src/LAppModel.cpp |
| 1361 | --- ./demo_clean/src/LAppModel.cpp 2024-03-28 18:19:04.524642700 +0000 |
| 1362 | +++ ./demo_dev/src/LAppModel.cpp 2024-03-28 18:26:32.604595000 +0000 |
| 1363 | @@ -1,4 +1,4 @@ |
| 1364 | -/** |
| 1365 | +/** |
| 1366 | * Copyright(c) Live2D Inc. All rights reserved. |
| 1367 | * |
| 1368 | * Use of this source code is governed by the Live2D Open Software license |
| 1369 | @@ -21,6 +21,8 @@ |
| 1370 | #include "LAppTextureManager.hpp" |
| 1371 | #include "LAppDelegate.hpp" |
| 1372 | |
| 1373 | +#include "facial_landmark_detector.h" |
| 1374 | + |
| 1375 | using namespace Live2D::Cubism::Framework; |
| 1376 | using namespace Live2D::Cubism::Framework::DefaultParameterId; |
| 1377 | using namespace LAppDefine; |
| 1378 | @@ -30,7 +32,7 @@ namespace { |
| 1379 | { |
| 1380 | if (DebugLogEnable) |
| 1381 | { |
| 1382 | - LAppPal::PrintLogLn("[APP]create buffer: %s ", path); |
| 1383 | + LAppPal::PrintLog("[APP]create buffer: %s ", path); |
| 1384 | } |
| 1385 | return LAppPal::LoadFileAsBytes(path, size); |
| 1386 | } |
| 1387 | @@ -39,33 +41,30 @@ namespace { |
| 1388 | { |
| 1389 | if (DebugLogEnable) |
| 1390 | { |
| 1391 | - LAppPal::PrintLogLn("[APP]delete buffer: %s", path); |
| 1392 | + LAppPal::PrintLog("[APP]delete buffer: %s", path); |
| 1393 | } |
| 1394 | LAppPal::ReleaseBytes(buffer); |
| 1395 | } |
| 1396 | } |
| 1397 | |
| 1398 | -LAppModel::LAppModel() |
| 1399 | +LAppModel::LAppModel(bool useOldParamId) |
| 1400 | : CubismUserModel() |
| 1401 | , _modelSetting(NULL) |
| 1402 | , _userTimeSeconds(0.0f) |
| 1403 | + , _detector(nullptr) |
| 1404 | + , _useOldParamId(useOldParamId) |
| 1405 | { |
| 1406 | - if (MocConsistencyValidationEnable) |
| 1407 | - { |
| 1408 | - _mocConsistency = true; |
| 1409 | - } |
| 1410 | - |
| 1411 | if (DebugLogEnable) |
| 1412 | { |
| 1413 | _debugMode = true; |
| 1414 | } |
| 1415 | |
| 1416 | - _idParamAngleX = CubismFramework::GetIdManager()->GetId(ParamAngleX); |
| 1417 | - _idParamAngleY = CubismFramework::GetIdManager()->GetId(ParamAngleY); |
| 1418 | - _idParamAngleZ = CubismFramework::GetIdManager()->GetId(ParamAngleZ); |
| 1419 | - _idParamBodyAngleX = CubismFramework::GetIdManager()->GetId(ParamBodyAngleX); |
| 1420 | - _idParamEyeBallX = CubismFramework::GetIdManager()->GetId(ParamEyeBallX); |
| 1421 | - _idParamEyeBallY = CubismFramework::GetIdManager()->GetId(ParamEyeBallY); |
| 1422 | + _idParamAngleX = CubismFramework::GetIdManager()->GetId(_(ParamAngleX)); |
| 1423 | + _idParamAngleY = CubismFramework::GetIdManager()->GetId(_(ParamAngleY)); |
| 1424 | + _idParamAngleZ = CubismFramework::GetIdManager()->GetId(_(ParamAngleZ)); |
| 1425 | + _idParamBodyAngleX = CubismFramework::GetIdManager()->GetId(_(ParamBodyAngleX)); |
| 1426 | + _idParamEyeBallX = CubismFramework::GetIdManager()->GetId(_(ParamEyeBallX)); |
| 1427 | + _idParamEyeBallY = CubismFramework::GetIdManager()->GetId(_(ParamEyeBallY)); |
| 1428 | } |
| 1429 | |
| 1430 | LAppModel::~LAppModel() |
| 1431 | @@ -89,7 +88,7 @@ void LAppModel::LoadAssets(const csmChar |
| 1432 | |
| 1433 | if (_debugMode) |
| 1434 | { |
| 1435 | - LAppPal::PrintLogLn("[APP]load model setting: %s", fileName); |
| 1436 | + LAppPal::PrintLog("[APP]load model setting: %s", fileName); |
| 1437 | } |
| 1438 | |
| 1439 | csmSizeInt size; |
| 1440 | @@ -101,17 +100,12 @@ void LAppModel::LoadAssets(const csmChar |
| 1441 | |
| 1442 | SetupModel(setting); |
| 1443 | |
| 1444 | - if (_model == NULL) |
| 1445 | - { |
| 1446 | - LAppPal::PrintLogLn("Failed to LoadAssets()."); |
| 1447 | - return; |
| 1448 | - } |
| 1449 | - |
| 1450 | CreateRenderer(); |
| 1451 | |
| 1452 | SetupTextures(); |
| 1453 | } |
| 1454 | |
| 1455 | + |
| 1456 | void LAppModel::SetupModel(ICubismModelSetting* setting) |
| 1457 | { |
| 1458 | _updating = true; |
| 1459 | @@ -130,41 +124,14 @@ void LAppModel::SetupModel(ICubismModelS |
| 1460 | |
| 1461 | if (_debugMode) |
| 1462 | { |
| 1463 | - LAppPal::PrintLogLn("[APP]create model: %s", setting->GetModelFileName()); |
| 1464 | + LAppPal::PrintLog("[APP]create model: %s", setting->GetModelFileName()); |
| 1465 | } |
| 1466 | |
| 1467 | buffer = CreateBuffer(path.GetRawString(), &size); |
| 1468 | - LoadModel(buffer, size, _mocConsistency); |
| 1469 | + LoadModel(buffer, size); |
| 1470 | DeleteBuffer(buffer, path.GetRawString()); |
| 1471 | } |
| 1472 | |
| 1473 | - //Expression |
| 1474 | - if (_modelSetting->GetExpressionCount() > 0) |
| 1475 | - { |
| 1476 | - const csmInt32 count = _modelSetting->GetExpressionCount(); |
| 1477 | - for (csmInt32 i = 0; i < count; i++) |
| 1478 | - { |
| 1479 | - csmString name = _modelSetting->GetExpressionName(i); |
| 1480 | - csmString path = _modelSetting->GetExpressionFileName(i); |
| 1481 | - path = _modelHomeDir + path; |
| 1482 | - |
| 1483 | - buffer = CreateBuffer(path.GetRawString(), &size); |
| 1484 | - ACubismMotion* motion = LoadExpression(buffer, size, name.GetRawString()); |
| 1485 | - |
| 1486 | - if (motion) |
| 1487 | - { |
| 1488 | - if (_expressions[name] != NULL) |
| 1489 | - { |
| 1490 | - ACubismMotion::Delete(_expressions[name]); |
| 1491 | - _expressions[name] = NULL; |
| 1492 | - } |
| 1493 | - _expressions[name] = motion; |
| 1494 | - } |
| 1495 | - |
| 1496 | - DeleteBuffer(buffer, path.GetRawString()); |
| 1497 | - } |
| 1498 | - } |
| 1499 | - |
| 1500 | //Physics |
| 1501 | if (strcmp(_modelSetting->GetPhysicsFileName(), "") != 0) |
| 1502 | { |
| 1503 | @@ -203,7 +170,7 @@ void LAppModel::SetupModel(ICubismModelS |
| 1504 | breathParameters.PushBack(CubismBreath::BreathParameterData(_idParamAngleY, 0.0f, 8.0f, 3.5345f, 0.5f)); |
| 1505 | breathParameters.PushBack(CubismBreath::BreathParameterData(_idParamAngleZ, 0.0f, 10.0f, 5.5345f, 0.5f)); |
| 1506 | breathParameters.PushBack(CubismBreath::BreathParameterData(_idParamBodyAngleX, 0.0f, 4.0f, 15.5345f, 0.5f)); |
| 1507 | - breathParameters.PushBack(CubismBreath::BreathParameterData(CubismFramework::GetIdManager()->GetId(ParamBreath), 0.5f, 0.5f, 3.2345f, 0.5f)); |
| 1508 | + breathParameters.PushBack(CubismBreath::BreathParameterData(CubismFramework::GetIdManager()->GetId(_(ParamBreath)), 0.5f, 0.5f, 3.2345f, 0.5f)); |
| 1509 | |
| 1510 | _breath->SetParameters(breathParameters); |
| 1511 | } |
| 1512 | @@ -227,21 +194,6 @@ void LAppModel::SetupModel(ICubismModelS |
| 1513 | } |
| 1514 | } |
| 1515 | |
| 1516 | - // LipSyncIds |
| 1517 | - { |
| 1518 | - csmInt32 lipSyncIdCount = _modelSetting->GetLipSyncParameterCount(); |
| 1519 | - for (csmInt32 i = 0; i < lipSyncIdCount; ++i) |
| 1520 | - { |
| 1521 | - _lipSyncIds.PushBack(_modelSetting->GetLipSyncParameterId(i)); |
| 1522 | - } |
| 1523 | - } |
| 1524 | - |
| 1525 | - if (_modelSetting == NULL || _modelMatrix == NULL) |
| 1526 | - { |
| 1527 | - LAppPal::PrintLogLn("Failed to SetupModel()."); |
| 1528 | - return; |
| 1529 | - } |
| 1530 | - |
| 1531 | //Layout |
| 1532 | csmMap<csmString, csmFloat32> layout; |
| 1533 | _modelSetting->GetLayoutMap(layout); |
| 1534 | @@ -274,7 +226,7 @@ void LAppModel::PreloadMotionGroup(const |
| 1535 | |
| 1536 | if (_debugMode) |
| 1537 | { |
| 1538 | - LAppPal::PrintLogLn("[APP]load motion: %s => [%s_%d] ", path.GetRawString(), group, i); |
| 1539 | + LAppPal::PrintLog("[APP]load motion: %s => [%s_%d] ", path.GetRawString(), group, i); |
| 1540 | } |
| 1541 | |
| 1542 | csmByte* buffer; |
| 1543 | @@ -282,27 +234,24 @@ void LAppModel::PreloadMotionGroup(const |
| 1544 | buffer = CreateBuffer(path.GetRawString(), &size); |
| 1545 | CubismMotion* tmpMotion = static_cast<CubismMotion*>(LoadMotion(buffer, size, name.GetRawString())); |
| 1546 | |
| 1547 | - if (tmpMotion) |
| 1548 | + csmFloat32 fadeTime = _modelSetting->GetMotionFadeInTimeValue(group, i); |
| 1549 | + if (fadeTime >= 0.0f) |
| 1550 | { |
| 1551 | - csmFloat32 fadeTime = _modelSetting->GetMotionFadeInTimeValue(group, i); |
| 1552 | - if (fadeTime >= 0.0f) |
| 1553 | - { |
| 1554 | - tmpMotion->SetFadeInTime(fadeTime); |
| 1555 | - } |
| 1556 | + tmpMotion->SetFadeInTime(fadeTime); |
| 1557 | + } |
| 1558 | |
| 1559 | - fadeTime = _modelSetting->GetMotionFadeOutTimeValue(group, i); |
| 1560 | - if (fadeTime >= 0.0f) |
| 1561 | - { |
| 1562 | - tmpMotion->SetFadeOutTime(fadeTime); |
| 1563 | - } |
| 1564 | - tmpMotion->SetEffectIds(_eyeBlinkIds, _lipSyncIds); |
| 1565 | + fadeTime = _modelSetting->GetMotionFadeOutTimeValue(group, i); |
| 1566 | + if (fadeTime >= 0.0f) |
| 1567 | + { |
| 1568 | + tmpMotion->SetFadeOutTime(fadeTime); |
| 1569 | + } |
| 1570 | + tmpMotion->SetEffectIds(_eyeBlinkIds, _lipSyncIds); |
| 1571 | |
| 1572 | - if (_motions[name] != NULL) |
| 1573 | - { |
| 1574 | - ACubismMotion::Delete(_motions[name]); |
| 1575 | - } |
| 1576 | - _motions[name] = tmpMotion; |
| 1577 | + if (_motions[name] != NULL) |
| 1578 | + { |
| 1579 | + ACubismMotion::Delete(_motions[name]); |
| 1580 | } |
| 1581 | + _motions[name] = tmpMotion; |
| 1582 | |
| 1583 | DeleteBuffer(buffer, path.GetRawString()); |
| 1584 | } |
| 1585 | @@ -357,62 +306,57 @@ void LAppModel::Update() |
| 1586 | const csmFloat32 deltaTimeSeconds = LAppPal::GetDeltaTime(); |
| 1587 | _userTimeSeconds += deltaTimeSeconds; |
| 1588 | |
| 1589 | - _dragManager->Update(deltaTimeSeconds); |
| 1590 | - _dragX = _dragManager->GetX(); |
| 1591 | - _dragY = _dragManager->GetY(); |
| 1592 | - |
| 1593 | - // モーションによるパラメータ更新の有無 |
| 1594 | - csmBool motionUpdated = false; |
| 1595 | - |
| 1596 | - //----------------------------------------------------------------- |
| 1597 | - _model->LoadParameters(); // 前回セーブされた状態をロード |
| 1598 | - if (_motionManager->IsFinished()) |
| 1599 | - { |
| 1600 | - // モーションの再生がない場合、待機モーションの中からランダムで再生する |
| 1601 | - StartRandomMotion(MotionGroupIdle, PriorityIdle); |
| 1602 | - } |
| 1603 | - else |
| 1604 | + if (_detector) |
| 1605 | { |
| 1606 | - motionUpdated = _motionManager->UpdateMotion(_model, deltaTimeSeconds); // モーションを更新 |
| 1607 | - } |
| 1608 | - _model->SaveParameters(); // 状態を保存 |
| 1609 | - //----------------------------------------------------------------- |
| 1610 | - |
| 1611 | - // 不透明度 |
| 1612 | - _opacity = _model->GetModelOpacity(); |
| 1613 | + auto idMan = CubismFramework::GetIdManager(); |
| 1614 | + auto params = _detector->getParams(); |
| 1615 | |
| 1616 | - // まばたき |
| 1617 | - if (!motionUpdated) |
| 1618 | - { |
| 1619 | - if (_eyeBlink != NULL) |
| 1620 | + // NOTE: Apparently, this LoadParameters/SaveParameters pair |
| 1621 | + // is needed for auto breath to work. |
| 1622 | + _model->LoadParameters(); // 前回セーブされた状態をロード |
| 1623 | + if (_motionManager->IsFinished() && params.randomMotion) |
| 1624 | { |
| 1625 | - // メインモーションの更新がないとき |
| 1626 | - _eyeBlink->UpdateParameters(_model, deltaTimeSeconds); // 目パチ |
| 1627 | + // モーションの再生がない場合、待機モーションの中からランダムで再生する |
| 1628 | + StartRandomMotion(MotionGroupIdle, PriorityIdle); |
| 1629 | } |
| 1630 | - } |
| 1631 | - |
| 1632 | - if (_expressionManager != NULL) |
| 1633 | - { |
| 1634 | - _expressionManager->UpdateMotion(_model, deltaTimeSeconds); // 表情でパラメータ更新(相対変化) |
| 1635 | - } |
| 1636 | - |
| 1637 | - //ドラッグによる変化 |
| 1638 | - //ドラッグによる顔の向きの調整 |
| 1639 | - _model->AddParameterValue(_idParamAngleX, _dragX * 30); // -30から30の値を加える |
| 1640 | - _model->AddParameterValue(_idParamAngleY, _dragY * 30); |
| 1641 | - _model->AddParameterValue(_idParamAngleZ, _dragX * _dragY * -30); |
| 1642 | - |
| 1643 | - //ドラッグによる体の向きの調整 |
| 1644 | - _model->AddParameterValue(_idParamBodyAngleX, _dragX * 10); // -10から10の値を加える |
| 1645 | + else |
| 1646 | + { |
| 1647 | + _motionManager->UpdateMotion(_model, deltaTimeSeconds); // モーションを更新 |
| 1648 | + } |
| 1649 | + _model->SaveParameters(); // 状態を保存 |
| 1650 | |
| 1651 | - //ドラッグによる目の向きの調整 |
| 1652 | - _model->AddParameterValue(_idParamEyeBallX, _dragX); // -1から1の値を加える |
| 1653 | - _model->AddParameterValue(_idParamEyeBallY, _dragY); |
| 1654 | |
| 1655 | - // 呼吸など |
| 1656 | - if (_breath != NULL) |
| 1657 | - { |
| 1658 | - _breath->UpdateParameters(_model, deltaTimeSeconds); |
| 1659 | + if (params.autoBlink && _eyeBlink) |
| 1660 | + { |
| 1661 | + _eyeBlink->UpdateParameters(_model, deltaTimeSeconds); |
| 1662 | + } |
| 1663 | + else |
| 1664 | + { |
| 1665 | + _model->SetParameterValue(idMan->GetId(_("ParamEyeLOpen")), |
| 1666 | + params.leftEyeOpenness); |
| 1667 | + _model->SetParameterValue(idMan->GetId(_("ParamEyeROpen")), |
| 1668 | + params.rightEyeOpenness); |
| 1669 | + } |
| 1670 | + _model->SetParameterValue(idMan->GetId(_("ParamMouthForm")), |
| 1671 | + params.mouthForm); |
| 1672 | + _model->SetParameterValue(idMan->GetId(_("ParamMouthOpenY")), |
| 1673 | + params.mouthOpenness); |
| 1674 | + _model->SetParameterValue(idMan->GetId(_("ParamEyeLSmile")), |
| 1675 | + params.leftEyeSmile); |
| 1676 | + _model->SetParameterValue(idMan->GetId(_("ParamEyeRSmile")), |
| 1677 | + params.rightEyeSmile); |
| 1678 | + _model->SetParameterValue(idMan->GetId(_("ParamAngleX")), |
| 1679 | + params.faceXAngle); |
| 1680 | + _model->SetParameterValue(idMan->GetId(_("ParamAngleY")), |
| 1681 | + params.faceYAngle); |
| 1682 | + _model->SetParameterValue(idMan->GetId(_("ParamAngleZ")), |
| 1683 | + params.faceZAngle); |
| 1684 | + if (params.autoBreath && _breath) |
| 1685 | + { |
| 1686 | + // Note: _model->LoadParameters and SaveParameters is needed |
| 1687 | + // before - see above. |
| 1688 | + _breath->UpdateParameters(_model, deltaTimeSeconds); |
| 1689 | + } |
| 1690 | } |
| 1691 | |
| 1692 | // 物理演算の設定 |
| 1693 | @@ -421,22 +365,6 @@ void LAppModel::Update() |
| 1694 | _physics->Evaluate(_model, deltaTimeSeconds); |
| 1695 | } |
| 1696 | |
| 1697 | - // リップシンクの設定 |
| 1698 | - if (_lipSync) |
| 1699 | - { |
| 1700 | - // リアルタイムでリップシンクを行う場合、システムから音量を取得して0〜1の範囲で値を入力します。 |
| 1701 | - csmFloat32 value = 0.0f; |
| 1702 | - |
| 1703 | - // 状態更新/RMS値取得 |
| 1704 | - _wavFileHandler.Update(deltaTimeSeconds); |
| 1705 | - value = _wavFileHandler.GetRms(); |
| 1706 | - |
| 1707 | - for (csmUint32 i = 0; i < _lipSyncIds.GetSize(); ++i) |
| 1708 | - { |
| 1709 | - _model->AddParameterValue(_lipSyncIds[i], value, 0.8f); |
| 1710 | - } |
| 1711 | - } |
| 1712 | - |
| 1713 | // ポーズの設定 |
| 1714 | if (_pose != NULL) |
| 1715 | { |
| 1716 | @@ -457,7 +385,7 @@ CubismMotionQueueEntryHandle LAppModel:: |
| 1717 | { |
| 1718 | if (_debugMode) |
| 1719 | { |
| 1720 | - LAppPal::PrintLogLn("[APP]can't start motion."); |
| 1721 | + LAppPal::PrintLog("[APP]can't start motion."); |
| 1722 | } |
| 1723 | return InvalidMotionQueueEntryHandleValue; |
| 1724 | } |
| 1725 | @@ -478,23 +406,19 @@ CubismMotionQueueEntryHandle LAppModel:: |
| 1726 | csmSizeInt size; |
| 1727 | buffer = CreateBuffer(path.GetRawString(), &size); |
| 1728 | motion = static_cast<CubismMotion*>(LoadMotion(buffer, size, NULL, onFinishedMotionHandler)); |
| 1729 | - |
| 1730 | - if (motion) |
| 1731 | + csmFloat32 fadeTime = _modelSetting->GetMotionFadeInTimeValue(group, no); |
| 1732 | + if (fadeTime >= 0.0f) |
| 1733 | { |
| 1734 | - csmFloat32 fadeTime = _modelSetting->GetMotionFadeInTimeValue(group, no); |
| 1735 | - if (fadeTime >= 0.0f) |
| 1736 | - { |
| 1737 | - motion->SetFadeInTime(fadeTime); |
| 1738 | - } |
| 1739 | + motion->SetFadeInTime(fadeTime); |
| 1740 | + } |
| 1741 | |
| 1742 | - fadeTime = _modelSetting->GetMotionFadeOutTimeValue(group, no); |
| 1743 | - if (fadeTime >= 0.0f) |
| 1744 | - { |
| 1745 | - motion->SetFadeOutTime(fadeTime); |
| 1746 | - } |
| 1747 | - motion->SetEffectIds(_eyeBlinkIds, _lipSyncIds); |
| 1748 | - autoDelete = true; // 終了時にメモリから削除 |
| 1749 | + fadeTime = _modelSetting->GetMotionFadeOutTimeValue(group, no); |
| 1750 | + if (fadeTime >= 0.0f) |
| 1751 | + { |
| 1752 | + motion->SetFadeOutTime(fadeTime); |
| 1753 | } |
| 1754 | + motion->SetEffectIds(_eyeBlinkIds, _lipSyncIds); |
| 1755 | + autoDelete = true; // 終了時にメモリから削除 |
| 1756 | |
| 1757 | DeleteBuffer(buffer, path.GetRawString()); |
| 1758 | } |
| 1759 | @@ -509,12 +433,11 @@ CubismMotionQueueEntryHandle LAppModel:: |
| 1760 | { |
| 1761 | csmString path = voice; |
| 1762 | path = _modelHomeDir + path; |
| 1763 | - _wavFileHandler.Start(path); |
| 1764 | } |
| 1765 | |
| 1766 | if (_debugMode) |
| 1767 | { |
| 1768 | - LAppPal::PrintLogLn("[APP]start motion: [%s_%d]", group, no); |
| 1769 | + LAppPal::PrintLog("[APP]start motion: [%s_%d]", group, no); |
| 1770 | } |
| 1771 | return _motionManager->StartMotionPriority(motion, autoDelete, priority); |
| 1772 | } |
| 1773 | @@ -579,7 +502,7 @@ void LAppModel::SetExpression(const csmC |
| 1774 | ACubismMotion* motion = _expressions[expressionID]; |
| 1775 | if (_debugMode) |
| 1776 | { |
| 1777 | - LAppPal::PrintLogLn("[APP]expression: [%s]", expressionID); |
| 1778 | + LAppPal::PrintLog("[APP]expression: [%s]", expressionID); |
| 1779 | } |
| 1780 | |
| 1781 | if (motion != NULL) |
| 1782 | @@ -588,7 +511,7 @@ void LAppModel::SetExpression(const csmC |
| 1783 | } |
| 1784 | else |
| 1785 | { |
| 1786 | - if (_debugMode) LAppPal::PrintLogLn("[APP]expression[%s] is null ", expressionID); |
| 1787 | + if (_debugMode) LAppPal::PrintLog("[APP]expression[%s] is null ", expressionID); |
| 1788 | } |
| 1789 | } |
| 1790 | |
| 1791 | @@ -662,29 +585,36 @@ Csm::Rendering::CubismOffscreenSurface_O |
| 1792 | return _renderBuffer; |
| 1793 | } |
| 1794 | |
| 1795 | -csmBool LAppModel::HasMocConsistencyFromFile(const csmChar* mocFileName) |
| 1796 | +void LAppModel::SetFacialLandmarkDetector(FacialLandmarkDetector *detector) |
| 1797 | { |
| 1798 | - CSM_ASSERT(strcmp(mocFileName, "")); |
| 1799 | - |
| 1800 | - csmByte* buffer; |
| 1801 | - csmSizeInt size; |
| 1802 | - |
| 1803 | - csmString path = mocFileName; |
| 1804 | - path = _modelHomeDir + path; |
| 1805 | - |
| 1806 | - buffer = CreateBuffer(path.GetRawString(), &size); |
| 1807 | + _detector = detector; |
| 1808 | +} |
| 1809 | |
| 1810 | - csmBool consistency = CubismMoc::HasMocConsistencyFromUnrevivedMoc(buffer, size); |
| 1811 | - if (!consistency) |
| 1812 | +Csm::csmString LAppModel::_(std::string s) |
| 1813 | +{ |
| 1814 | + std::string ans; |
| 1815 | + if (_useOldParamId) |
| 1816 | { |
| 1817 | - CubismLogInfo("Inconsistent MOC3."); |
| 1818 | + if (s == "ParamTere") |
| 1819 | + { |
| 1820 | + ans = "PARAM_CHEEK"; |
| 1821 | + } |
| 1822 | + else |
| 1823 | + { |
| 1824 | + for (size_t i = 0; i < s.size(); i++) |
| 1825 | + { |
| 1826 | + if (std::isupper(s[i]) && i != 0) |
| 1827 | + { |
| 1828 | + ans += '_'; |
| 1829 | + } |
| 1830 | + ans += std::toupper(s[i]); |
| 1831 | + } |
| 1832 | + } |
| 1833 | } |
| 1834 | else |
| 1835 | { |
| 1836 | - CubismLogInfo("Consistent MOC3."); |
| 1837 | + ans = s; |
| 1838 | } |
| 1839 | - |
| 1840 | - DeleteBuffer(buffer); |
| 1841 | - |
| 1842 | - return consistency; |
| 1843 | + return csmString(ans.c_str()); |
| 1844 | } |
| 1845 | + |
| 1846 | diff -pruN --exclude build ./demo_clean/src/LAppModel.hpp ./demo_dev/src/LAppModel.hpp |
| 1847 | --- ./demo_clean/src/LAppModel.hpp 2024-03-28 18:19:04.414826700 +0000 |
| 1848 | +++ ./demo_dev/src/LAppModel.hpp 2024-03-28 18:25:30.566916900 +0000 |
| 1849 | @@ -1,4 +1,4 @@ |
| 1850 | -/** |
| 1851 | +/** |
| 1852 | * Copyright(c) Live2D Inc. All rights reserved. |
| 1853 | * |
| 1854 | * Use of this source code is governed by the Live2D Open Software license |
| 1855 | @@ -13,7 +13,7 @@ |
| 1856 | #include <Type/csmRectF.hpp> |
| 1857 | #include <Rendering/OpenGL/CubismOffscreenSurface_OpenGLES2.hpp> |
| 1858 | |
| 1859 | -#include "LAppWavFileHandler.hpp" |
| 1860 | +#include "facial_landmark_detector.h" |
| 1861 | |
| 1862 | /** |
| 1863 | * @brief ユーザーが実際に使用するモデルの実装クラス<br> |
| 1864 | @@ -25,8 +25,11 @@ class LAppModel : public Csm::CubismUser |
| 1865 | public: |
| 1866 | /** |
| 1867 | * @brief コンストラクタ |
| 1868 | + * |
| 1869 | + * @param[in] useOldParamId : If true, translate new (Cubism 3+) |
| 1870 | + * parameter IDs to old (Cubism 2.1) ones |
| 1871 | */ |
| 1872 | - LAppModel(); |
| 1873 | + LAppModel(bool useOldParamId); |
| 1874 | |
| 1875 | /** |
| 1876 | * @brief デストラクタ |
| 1877 | @@ -115,12 +118,11 @@ public: |
| 1878 | Csm::Rendering::CubismOffscreenSurface_OpenGLES2& GetRenderBuffer(); |
| 1879 | |
| 1880 | /** |
| 1881 | - * @brief .moc3ファイルの整合性をチェックする |
| 1882 | + * @brief Set the pointer to the FacialLandmarkDetector instance |
| 1883 | * |
| 1884 | - * @param[in] mocName MOC3ファイル名 |
| 1885 | - * @return MOC3に整合性があれば'true'、そうでなければ'false'。 |
| 1886 | + * @param[in] detector : Pointer to FacialLandmarkDetector instance |
| 1887 | */ |
| 1888 | - Csm::csmBool HasMocConsistencyFromFile(const Csm::csmChar* mocFileName); |
| 1889 | + void SetFacialLandmarkDetector(FacialLandmarkDetector *detector); |
| 1890 | |
| 1891 | protected: |
| 1892 | /** |
| 1893 | @@ -175,6 +177,17 @@ private: |
| 1894 | */ |
| 1895 | void ReleaseExpressions(); |
| 1896 | |
| 1897 | + /** |
| 1898 | + * @brief Translate new (Cubism 3+) parameter IDs to old (Cubism 2.1) ones |
| 1899 | + * |
| 1900 | + * @param[in] s : New parameter ID |
| 1901 | + * |
| 1902 | + * @return Old parameter ID |
| 1903 | + */ |
| 1904 | + Csm::csmString _(std::string s); |
| 1905 | + |
| 1906 | + bool _useOldParamId; |
| 1907 | + |
| 1908 | Csm::ICubismModelSetting* _modelSetting; ///< モデルセッティング情報 |
| 1909 | Csm::csmString _modelHomeDir; ///< モデルセッティングが置かれたディレクトリ |
| 1910 | Csm::csmFloat32 _userTimeSeconds; ///< デルタ時間の積算値[秒] |
| 1911 | @@ -191,7 +204,10 @@ private: |
| 1912 | const Csm::CubismId* _idParamEyeBallX; ///< パラメータID: ParamEyeBallX |
| 1913 | const Csm::CubismId* _idParamEyeBallY; ///< パラメータID: ParamEyeBallXY |
| 1914 | |
| 1915 | - LAppWavFileHandler _wavFileHandler; ///< wavファイルハンドラ |
| 1916 | + Csm::Rendering::CubismOffscreenSurface_OpenGLES2 _renderBuffer; ///< フレームバッファ以外の描画先 |
| 1917 | |
| 1918 | - Csm::Rendering::CubismOffscreenSurface_OpenGLES2 _renderBuffer; ///< フレームバッファ以外の描画先 |
| 1919 | + FacialLandmarkDetector *_detector; |
| 1920 | }; |
| 1921 | + |
| 1922 | + |
| 1923 | + |
| 1924 | diff -pruN --exclude build ./demo_clean/src/LAppPal.cpp ./demo_dev/src/LAppPal.cpp |
| 1925 | --- ./demo_clean/src/LAppPal.cpp 2024-03-28 18:19:04.037915500 +0000 |
| 1926 | +++ ./demo_dev/src/LAppPal.cpp 2023-03-05 23:22:10.834981800 +0000 |
| 1927 | @@ -1,4 +1,4 @@ |
| 1928 | -/** |
| 1929 | +/** |
| 1930 | * Copyright(c) Live2D Inc. All rights reserved. |
| 1931 | * |
| 1932 | * Use of this source code is governed by the Live2D Open Software license |
| 1933 | @@ -6,7 +6,9 @@ |
| 1934 | */ |
| 1935 | |
| 1936 | #include "LAppPal.hpp" |
| 1937 | -#include <cstdio> |
| 1938 | +#include <stdexcept> |
| 1939 | +#include <stdio.h> |
| 1940 | +#include <stdlib.h> |
| 1941 | #include <stdarg.h> |
| 1942 | #include <sys/stat.h> |
| 1943 | #include <iostream> |
| 1944 | @@ -35,37 +37,18 @@ csmByte* LAppPal::LoadFileAsBytes(const |
| 1945 | if (stat(path, &statBuf) == 0) |
| 1946 | { |
| 1947 | size = statBuf.st_size; |
| 1948 | - |
| 1949 | - if (size == 0) |
| 1950 | - { |
| 1951 | - if (DebugLogEnable) |
| 1952 | - { |
| 1953 | - PrintLogLn("Stat succeeded but file size is zero. path:%s", path); |
| 1954 | - } |
| 1955 | - return NULL; |
| 1956 | - } |
| 1957 | - } |
| 1958 | - else |
| 1959 | - { |
| 1960 | - if (DebugLogEnable) |
| 1961 | - { |
| 1962 | - PrintLogLn("Stat failed. errno:%d path:%s", errno, path); |
| 1963 | - } |
| 1964 | - return NULL; |
| 1965 | + PrintLog(path); |
| 1966 | } |
| 1967 | |
| 1968 | std::fstream file; |
| 1969 | + char* buf = new char[size]; |
| 1970 | + |
| 1971 | file.open(path, std::ios::in | std::ios::binary); |
| 1972 | if (!file.is_open()) |
| 1973 | { |
| 1974 | - if (DebugLogEnable) |
| 1975 | - { |
| 1976 | - PrintLogLn("File open failed. path:%s", path); |
| 1977 | - } |
| 1978 | + throw std::runtime_error("Failed to open file " + filePath); |
| 1979 | return NULL; |
| 1980 | } |
| 1981 | - |
| 1982 | - char* buf = new char[size]; |
| 1983 | file.read(buf, size); |
| 1984 | file.close(); |
| 1985 | |
| 1986 | @@ -95,28 +78,8 @@ void LAppPal::PrintLog(const csmChar* fo |
| 1987 | va_list args; |
| 1988 | csmChar buf[256]; |
| 1989 | va_start(args, format); |
| 1990 | - vsnprintf_s(buf, sizeof(buf), format, args); // 標準出力でレンダリング |
| 1991 | -#ifdef CSM_DEBUG_MEMORY_LEAKING |
| 1992 | -// メモリリークチェック時は大量の標準出力がはしり重いのでprintfを利用する |
| 1993 | - std::printf(buf); |
| 1994 | -#else |
| 1995 | - std::cout << buf; |
| 1996 | -#endif |
| 1997 | - va_end(args); |
| 1998 | -} |
| 1999 | - |
| 2000 | -void LAppPal::PrintLogLn(const Csm::csmChar* format, ...) |
| 2001 | -{ |
| 2002 | - va_list args; |
| 2003 | - csmChar buf[256]; |
| 2004 | - va_start(args, format); |
| 2005 | - vsnprintf_s(buf, sizeof(buf), format, args); // 標準出力でレンダリング |
| 2006 | -#ifdef CSM_DEBUG_MEMORY_LEAKING |
| 2007 | - // メモリリークチェック時は大量の標準出力がはしり重いのでprintfを利用する |
| 2008 | - std::printf("%s\n", buf); |
| 2009 | -#else |
| 2010 | - std::cout << buf << std::endl; |
| 2011 | -#endif |
| 2012 | + vsnprintf(buf, sizeof(buf), format, args); // 標準出力でレンダリング |
| 2013 | + std::cerr << buf << std::endl; |
| 2014 | va_end(args); |
| 2015 | } |
| 2016 | |
| 2017 | @@ -124,8 +87,3 @@ void LAppPal::PrintMessage(const csmChar |
| 2018 | { |
| 2019 | PrintLog("%s", message); |
| 2020 | } |
| 2021 | - |
| 2022 | -void LAppPal::PrintMessageLn(const csmChar* message) |
| 2023 | -{ |
| 2024 | - PrintLogLn("%s", message); |
| 2025 | -} |
| 2026 | diff -pruN --exclude build ./demo_clean/src/LAppPal.hpp ./demo_dev/src/LAppPal.hpp |
| 2027 | --- ./demo_clean/src/LAppPal.hpp 2024-03-28 18:19:03.957378000 +0000 |
| 2028 | +++ ./demo_dev/src/LAppPal.hpp 2023-03-05 23:22:10.939820800 +0000 |
| 2029 | @@ -1,4 +1,4 @@ |
| 2030 | -/** |
| 2031 | +/** |
| 2032 | * Copyright(c) Live2D Inc. All rights reserved. |
| 2033 | * |
| 2034 | * Use of this source code is governed by the Live2D Open Software license |
| 2035 | @@ -8,6 +8,7 @@ |
| 2036 | #pragma once |
| 2037 | |
| 2038 | #include <CubismFramework.hpp> |
| 2039 | +#include <cstdlib> |
| 2040 | #include <string> |
| 2041 | |
| 2042 | /** |
| 2043 | @@ -62,17 +63,6 @@ public: |
| 2044 | static void PrintLog(const Csm::csmChar* format, ...); |
| 2045 | |
| 2046 | /** |
| 2047 | - * @brief ログを出力し最後に改行する |
| 2048 | - * |
| 2049 | - * ログを出力し最後に改行する |
| 2050 | - * |
| 2051 | - * @param[in] format 書式付文字列 |
| 2052 | - * @param[in] ... (可変長引数)文字列 |
| 2053 | - * |
| 2054 | - */ |
| 2055 | - static void PrintLogLn(const Csm::csmChar* format, ...); |
| 2056 | - |
| 2057 | - /** |
| 2058 | * @brief メッセージを出力する |
| 2059 | * |
| 2060 | * メッセージを出力する |
| 2061 | @@ -82,16 +72,6 @@ public: |
| 2062 | */ |
| 2063 | static void PrintMessage(const Csm::csmChar* message); |
| 2064 | |
| 2065 | - /** |
| 2066 | - * @brief メッセージを出力し最後に改行する |
| 2067 | - * |
| 2068 | - * メッセージを出力し最後に改行する |
| 2069 | - * |
| 2070 | - * @param[in] message 文字列 |
| 2071 | - * |
| 2072 | - */ |
| 2073 | - static void PrintMessageLn(const Csm::csmChar* message); |
| 2074 | - |
| 2075 | private: |
| 2076 | static double s_currentFrame; |
| 2077 | static double s_lastFrame; |
| 2078 | diff -pruN --exclude build ./demo_clean/src/LAppSprite.cpp ./demo_dev/src/LAppSprite.cpp |
| 2079 | --- ./demo_clean/src/LAppSprite.cpp 2024-03-28 18:19:04.304960000 +0000 |
| 2080 | +++ ./demo_dev/src/LAppSprite.cpp 2023-03-05 23:22:10.900085700 +0000 |
| 2081 | @@ -1,4 +1,4 @@ |
| 2082 | -/** |
| 2083 | +/** |
| 2084 | * Copyright(c) Live2D Inc. All rights reserved. |
| 2085 | * |
| 2086 | * Use of this source code is governed by the Live2D Open Software license |
| 2087 | @@ -6,6 +6,7 @@ |
| 2088 | */ |
| 2089 | |
| 2090 | #include "LAppSprite.hpp" |
| 2091 | +#include "LAppDelegate.hpp" |
| 2092 | |
| 2093 | LAppSprite::LAppSprite(float x, float y, float width, float height, GLuint textureId, GLuint programId) |
| 2094 | : _rect() |
| 2095 | @@ -34,10 +35,13 @@ LAppSprite::~LAppSprite() |
| 2096 | |
| 2097 | void LAppSprite::Render() const |
| 2098 | { |
| 2099 | + // 画面サイズを取得する |
| 2100 | + int maxWidth, maxHeight; |
| 2101 | + glfwGetWindowSize(LAppDelegate::GetInstance()->GetWindow(), &maxWidth, &maxHeight); |
| 2102 | |
| 2103 | - if (_maxWidth == 0 || _maxHeight == 0) |
| 2104 | + if(maxWidth==0 || maxHeight==0) |
| 2105 | { |
| 2106 | - return; // この際は描画できず |
| 2107 | + return; |
| 2108 | } |
| 2109 | |
| 2110 | const GLfloat uvVertex[] = |
| 2111 | @@ -58,10 +62,10 @@ void LAppSprite::Render() const |
| 2112 | // 頂点データ |
| 2113 | float positionVertex[] = |
| 2114 | { |
| 2115 | - (_rect.right - _maxWidth * 0.5f) / (_maxWidth * 0.5f), (_rect.up - _maxHeight * 0.5f) / (_maxHeight * 0.5f), |
| 2116 | - (_rect.left - _maxWidth * 0.5f) / (_maxWidth * 0.5f), (_rect.up - _maxHeight * 0.5f) / (_maxHeight * 0.5f), |
| 2117 | - (_rect.left - _maxWidth * 0.5f) / (_maxWidth * 0.5f), (_rect.down - _maxHeight * 0.5f) / (_maxHeight * 0.5f), |
| 2118 | - (_rect.right - _maxWidth * 0.5f) / (_maxWidth * 0.5f), (_rect.down - _maxHeight * 0.5f) / (_maxHeight * 0.5f) |
| 2119 | + (_rect.right - maxWidth * 0.5f) / (maxWidth * 0.5f), (_rect.up - maxHeight * 0.5f) / (maxHeight * 0.5f), |
| 2120 | + (_rect.left - maxWidth * 0.5f) / (maxWidth * 0.5f), (_rect.up - maxHeight * 0.5f) / (maxHeight * 0.5f), |
| 2121 | + (_rect.left - maxWidth * 0.5f) / (maxWidth * 0.5f), (_rect.down - maxHeight * 0.5f) / (maxHeight * 0.5f), |
| 2122 | + (_rect.right - maxWidth * 0.5f) / (maxWidth * 0.5f), (_rect.down - maxHeight * 0.5f) / (maxHeight * 0.5f) |
| 2123 | }; |
| 2124 | |
| 2125 | // attribute属性を登録 |
| 2126 | @@ -70,7 +74,6 @@ void LAppSprite::Render() const |
| 2127 | |
| 2128 | glUniform4f(_colorLocation, _spriteColor[0], _spriteColor[1], _spriteColor[2], _spriteColor[3]); |
| 2129 | |
| 2130 | - |
| 2131 | // モデルの描画 |
| 2132 | glBindTexture(GL_TEXTURE_2D, _textureId); |
| 2133 | glDrawArrays(GL_TRIANGLE_FAN, 0, 4); |
| 2134 | @@ -78,9 +81,13 @@ void LAppSprite::Render() const |
| 2135 | |
| 2136 | void LAppSprite::RenderImmidiate(GLuint textureId, const GLfloat uvVertex[8]) const |
| 2137 | { |
| 2138 | - if (_maxWidth == 0 || _maxHeight == 0) |
| 2139 | + // 画面サイズを取得する |
| 2140 | + int maxWidth, maxHeight; |
| 2141 | + glfwGetWindowSize(LAppDelegate::GetInstance()->GetWindow(), &maxWidth, &maxHeight); |
| 2142 | + |
| 2143 | + if(maxWidth==0 || maxHeight==0) |
| 2144 | { |
| 2145 | - return; // この際は描画できず |
| 2146 | + return; |
| 2147 | } |
| 2148 | |
| 2149 | // attribute属性を有効にする |
| 2150 | @@ -93,10 +100,10 @@ void LAppSprite::RenderImmidiate(GLuint |
| 2151 | // 頂点データ |
| 2152 | float positionVertex[] = |
| 2153 | { |
| 2154 | - (_rect.right - _maxWidth * 0.5f) / (_maxWidth * 0.5f), (_rect.up - _maxHeight * 0.5f) / (_maxHeight * 0.5f), |
| 2155 | - (_rect.left - _maxWidth * 0.5f) / (_maxWidth * 0.5f), (_rect.up - _maxHeight * 0.5f) / (_maxHeight * 0.5f), |
| 2156 | - (_rect.left - _maxWidth * 0.5f) / (_maxWidth * 0.5f), (_rect.down - _maxHeight * 0.5f) / (_maxHeight * 0.5f), |
| 2157 | - (_rect.right - _maxWidth * 0.5f) / (_maxWidth * 0.5f), (_rect.down - _maxHeight * 0.5f) / (_maxHeight * 0.5f) |
| 2158 | + (_rect.right - maxWidth * 0.5f) / (maxWidth * 0.5f), (_rect.up - maxHeight * 0.5f) / (maxHeight * 0.5f), |
| 2159 | + (_rect.left - maxWidth * 0.5f) / (maxWidth * 0.5f), (_rect.up - maxHeight * 0.5f) / (maxHeight * 0.5f), |
| 2160 | + (_rect.left - maxWidth * 0.5f) / (maxWidth * 0.5f), (_rect.down - maxHeight * 0.5f) / (maxHeight * 0.5f), |
| 2161 | + (_rect.right - maxWidth * 0.5f) / (maxWidth * 0.5f), (_rect.down - maxHeight * 0.5f) / (maxHeight * 0.5f) |
| 2162 | }; |
| 2163 | |
| 2164 | // attribute属性を登録 |
| 2165 | @@ -112,13 +119,16 @@ void LAppSprite::RenderImmidiate(GLuint |
| 2166 | |
| 2167 | bool LAppSprite::IsHit(float pointX, float pointY) const |
| 2168 | { |
| 2169 | - if (_maxWidth == 0 || _maxHeight == 0) |
| 2170 | + // 画面サイズを取得する |
| 2171 | + int maxWidth, maxHeight; |
| 2172 | + glfwGetWindowSize(LAppDelegate::GetInstance()->GetWindow(), &maxWidth, &maxHeight); |
| 2173 | + |
| 2174 | + if(maxWidth==0 || maxHeight==0) |
| 2175 | { |
| 2176 | - return false; // この際は描画できず |
| 2177 | + return false; |
| 2178 | } |
| 2179 | - |
| 2180 | //Y座標は変換する必要あり |
| 2181 | - float y = _maxHeight - pointY; |
| 2182 | + float y = maxHeight - pointY; |
| 2183 | |
| 2184 | return (pointX >= _rect.left && pointX <= _rect.right && y <= _rect.up && y >= _rect.down); |
| 2185 | } |
| 2186 | @@ -138,9 +148,3 @@ void LAppSprite::ResetRect(float x, floa |
| 2187 | _rect.up = (y + height * 0.5f); |
| 2188 | _rect.down = (y - height * 0.5f); |
| 2189 | } |
| 2190 | - |
| 2191 | -void LAppSprite::SetWindowSize(int width, int height) |
| 2192 | -{ |
| 2193 | - _maxWidth = width; |
| 2194 | - _maxHeight = height; |
| 2195 | -} |
| 2196 | diff -pruN --exclude build ./demo_clean/src/LAppSprite.hpp ./demo_dev/src/LAppSprite.hpp |
| 2197 | --- ./demo_clean/src/LAppSprite.hpp 2024-03-28 18:19:03.831886500 +0000 |
| 2198 | +++ ./demo_dev/src/LAppSprite.hpp 2023-03-05 23:22:10.876156000 +0000 |
| 2199 | @@ -1,4 +1,4 @@ |
| 2200 | -/** |
| 2201 | +/** |
| 2202 | * Copyright(c) Live2D Inc. All rights reserved. |
| 2203 | * |
| 2204 | * Use of this source code is governed by the Live2D Open Software license |
| 2205 | @@ -61,7 +61,7 @@ public: |
| 2206 | void Render() const; |
| 2207 | |
| 2208 | /** |
| 2209 | - * @brief テクスチャIDを指定して描画する |
| 2210 | + * @brief テクスチャを指定しての描画 |
| 2211 | * |
| 2212 | */ |
| 2213 | void RenderImmidiate(GLuint textureId, const GLfloat uvVertex[8]) const; |
| 2214 | @@ -94,24 +94,14 @@ public: |
| 2215 | */ |
| 2216 | void ResetRect(float x, float y, float width, float height); |
| 2217 | |
| 2218 | - /** |
| 2219 | - * @brief ウインドウサイズ設定 |
| 2220 | - * |
| 2221 | - * @param[in] width 横幅 |
| 2222 | - * @param[in] height 高さ |
| 2223 | - */ |
| 2224 | - void SetWindowSize(int width, int height); |
| 2225 | - |
| 2226 | private: |
| 2227 | - GLuint _textureId; ///< テクスチャID |
| 2228 | - Rect _rect; ///< 矩形 |
| 2229 | + GLuint _textureId; ///< テクスチャID |
| 2230 | + Rect _rect; ///< 矩形 |
| 2231 | int _positionLocation; ///< 位置アトリビュート |
| 2232 | int _uvLocation; ///< UVアトリビュート |
| 2233 | int _textureLocation; ///< テクスチャアトリビュート |
| 2234 | int _colorLocation; ///< カラーアトリビュート |
| 2235 | |
| 2236 | float _spriteColor[4]; ///< 表示カラー |
| 2237 | - int _maxWidth; ///< ウインドウ幅 |
| 2238 | - int _maxHeight; ///< ウインドウ高さ |
| 2239 | }; |
| 2240 | |
| 2241 | diff -pruN --exclude build ./demo_clean/src/LAppTextureManager.cpp ./demo_dev/src/LAppTextureManager.cpp |
| 2242 | --- ./demo_clean/src/LAppTextureManager.cpp 2024-03-28 18:19:04.226438800 +0000 |
| 2243 | +++ ./demo_dev/src/LAppTextureManager.cpp 2023-03-05 23:22:10.765166600 +0000 |
| 2244 | @@ -1,4 +1,4 @@ |
| 2245 | -/** |
| 2246 | +/** |
| 2247 | * Copyright(c) Live2D Inc. All rights reserved. |
| 2248 | * |
| 2249 | * Use of this source code is governed by the Live2D Open Software license |
| 2250 | @@ -10,7 +10,14 @@ |
| 2251 | #define STBI_NO_STDIO |
| 2252 | #define STBI_ONLY_PNG |
| 2253 | #define STB_IMAGE_IMPLEMENTATION |
| 2254 | +#if defined(__clang__) |
| 2255 | +#pragma clang diagnostic push |
| 2256 | +#pragma clang diagnostic ignored "-Wunused-function" |
| 2257 | +#endif |
| 2258 | #include "stb_image.h" |
| 2259 | +#if defined(__clang__) |
| 2260 | +#pragma clang diagnostic pop |
| 2261 | +#endif |
| 2262 | #include "LAppPal.hpp" |
| 2263 | |
| 2264 | LAppTextureManager::LAppTextureManager() |
| 2265 | @@ -89,6 +96,46 @@ LAppTextureManager::TextureInfo* LAppTex |
| 2266 | |
| 2267 | } |
| 2268 | |
| 2269 | +LAppTextureManager::TextureInfo* LAppTextureManager::CreateTextureFromColor( |
| 2270 | + uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha |
| 2271 | +) |
| 2272 | +{ |
| 2273 | + constexpr int width = 8, height = 8; |
| 2274 | + |
| 2275 | + uint8_t pixels[height][width][4]; |
| 2276 | + for (std::size_t h = 0; h < height; h++) |
| 2277 | + { |
| 2278 | + for (std::size_t w = 0; w < width; w++) |
| 2279 | + { |
| 2280 | + pixels[h][w][0] = red; |
| 2281 | + pixels[h][w][1] = green; |
| 2282 | + pixels[h][w][2] = blue; |
| 2283 | + pixels[h][w][3] = alpha; |
| 2284 | + } |
| 2285 | + } |
| 2286 | + |
| 2287 | + GLuint textureId; |
| 2288 | + glGenTextures(1, &textureId); |
| 2289 | + glBindTexture(GL_TEXTURE_2D, textureId); |
| 2290 | + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels); |
| 2291 | + |
| 2292 | + glGenerateMipmap(GL_TEXTURE_2D); |
| 2293 | + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); |
| 2294 | + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); |
| 2295 | + glBindTexture(GL_TEXTURE_2D, 0); |
| 2296 | + |
| 2297 | + |
| 2298 | + LAppTextureManager::TextureInfo* textureInfo = new LAppTextureManager::TextureInfo(); |
| 2299 | + textureInfo->fileName = ""; |
| 2300 | + textureInfo->width = width; |
| 2301 | + textureInfo->height = height; |
| 2302 | + textureInfo->id = textureId; |
| 2303 | + |
| 2304 | + _textures.PushBack(textureInfo); |
| 2305 | + |
| 2306 | + return textureInfo; |
| 2307 | +} |
| 2308 | + |
| 2309 | void LAppTextureManager::ReleaseTextures() |
| 2310 | { |
| 2311 | for (Csm::csmUint32 i = 0; i < _textures.GetSize(); i++) |
| 2312 | diff -pruN --exclude build ./demo_clean/src/LAppTextureManager.hpp ./demo_dev/src/LAppTextureManager.hpp |
| 2313 | --- ./demo_clean/src/LAppTextureManager.hpp 2024-03-28 18:19:04.351863200 +0000 |
| 2314 | +++ ./demo_dev/src/LAppTextureManager.hpp 2023-03-05 23:22:10.822016600 +0000 |
| 2315 | @@ -1,4 +1,4 @@ |
| 2316 | -/** |
| 2317 | +/** |
| 2318 | * Copyright(c) Live2D Inc. All rights reserved. |
| 2319 | * |
| 2320 | * Use of this source code is governed by the Live2D Open Software license |
| 2321 | @@ -72,6 +72,8 @@ public: |
| 2322 | */ |
| 2323 | TextureInfo* CreateTextureFromPngFile(std::string fileName); |
| 2324 | |
| 2325 | + TextureInfo *CreateTextureFromColor(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha = 255); |
| 2326 | + |
| 2327 | /** |
| 2328 | * @brief 画像の解放 |
| 2329 | * |
| 2330 | @@ -98,9 +100,9 @@ public: |
| 2331 | /** |
| 2332 | * @brief テクスチャIDからテクスチャ情報を得る |
| 2333 | * |
| 2334 | - * @param textureId[in] 取得したいテクスチャID |
| 2335 | - * @return テクスチャが存在していればTextureInfoが返る |
| 2336 | - */ |
| 2337 | + * @param[in] textureId 取得したいテクスチャID |
| 2338 | + * @return テクスチャが存在していればTextureInfoが返る |
| 2339 | + **/ |
| 2340 | TextureInfo* GetTextureInfoById(GLuint textureId) const; |
| 2341 | |
| 2342 | private: |
| 2343 | diff -pruN --exclude build ./demo_clean/src/LAppView.cpp ./demo_dev/src/LAppView.cpp |
| 2344 | --- ./demo_clean/src/LAppView.cpp 2024-03-28 18:19:03.722026200 +0000 |
| 2345 | +++ ./demo_dev/src/LAppView.cpp 2024-03-28 18:26:14.230329000 +0000 |
| 2346 | @@ -1,4 +1,4 @@ |
| 2347 | -/** |
| 2348 | +/** |
| 2349 | * Copyright(c) Live2D Inc. All rights reserved. |
| 2350 | * |
| 2351 | * Use of this source code is governed by the Live2D Open Software license |
| 2352 | @@ -13,18 +13,18 @@ |
| 2353 | #include "LAppLive2DManager.hpp" |
| 2354 | #include "LAppTextureManager.hpp" |
| 2355 | #include "LAppDefine.hpp" |
| 2356 | -#include "TouchManager.hpp" |
| 2357 | #include "LAppSprite.hpp" |
| 2358 | #include "LAppModel.hpp" |
| 2359 | |
| 2360 | +#include <Rendering/OpenGL/CubismOffscreenSurface_OpenGLES2.hpp> |
| 2361 | +#include <Rendering/OpenGL/CubismRenderer_OpenGLES2.hpp> |
| 2362 | + |
| 2363 | using namespace std; |
| 2364 | using namespace LAppDefine; |
| 2365 | |
| 2366 | LAppView::LAppView(): |
| 2367 | _programId(0), |
| 2368 | _back(NULL), |
| 2369 | - _gear(NULL), |
| 2370 | - _power(NULL), |
| 2371 | _renderSprite(NULL), |
| 2372 | _renderTarget(SelectTarget_None) |
| 2373 | { |
| 2374 | @@ -33,9 +33,6 @@ LAppView::LAppView(): |
| 2375 | _clearColor[2] = 1.0f; |
| 2376 | _clearColor[3] = 0.0f; |
| 2377 | |
| 2378 | - // タッチ関係のイベント管理 |
| 2379 | - _touchManager = new TouchManager(); |
| 2380 | - |
| 2381 | // デバイス座標からスクリーン座標に変換するための |
| 2382 | _deviceToScreen = new CubismMatrix44(); |
| 2383 | |
| 2384 | @@ -47,12 +44,10 @@ LAppView::~LAppView() |
| 2385 | { |
| 2386 | _renderBuffer.DestroyOffscreenSurface(); |
| 2387 | delete _renderSprite; |
| 2388 | + |
| 2389 | delete _viewMatrix; |
| 2390 | delete _deviceToScreen; |
| 2391 | - delete _touchManager; |
| 2392 | delete _back; |
| 2393 | - delete _gear; |
| 2394 | - delete _power; |
| 2395 | } |
| 2396 | |
| 2397 | void LAppView::Initialize() |
| 2398 | @@ -75,7 +70,7 @@ void LAppView::Initialize() |
| 2399 | _viewMatrix->SetScreenRect(left, right, bottom, top); // デバイスに対応する画面の範囲。 Xの左端, Xの右端, Yの下端, Yの上端 |
| 2400 | _viewMatrix->Scale(ViewScale, ViewScale); |
| 2401 | |
| 2402 | - _deviceToScreen->LoadIdentity(); // サイズが変わった際などリセット必須 |
| 2403 | + _deviceToScreen->LoadIdentity(); |
| 2404 | if (width > height) |
| 2405 | { |
| 2406 | float screenW = fabsf(right - left); |
| 2407 | @@ -103,16 +98,7 @@ void LAppView::Initialize() |
| 2408 | |
| 2409 | void LAppView::Render() |
| 2410 | { |
| 2411 | - // 画面サイズを取得する |
| 2412 | - int maxWidth, maxHeight; |
| 2413 | - glfwGetWindowSize(LAppDelegate::GetInstance()->GetWindow(), &maxWidth, &maxHeight); |
| 2414 | - _back->SetWindowSize(maxWidth, maxHeight); |
| 2415 | - _gear->SetWindowSize(maxWidth, maxHeight); |
| 2416 | - _power->SetWindowSize(maxWidth, maxHeight); |
| 2417 | - |
| 2418 | _back->Render(); |
| 2419 | - _gear->Render(); |
| 2420 | - _power->Render(); |
| 2421 | |
| 2422 | LAppLive2DManager* Live2DManager = LAppLive2DManager::GetInstance(); |
| 2423 | |
| 2424 | @@ -132,16 +118,15 @@ void LAppView::Render() |
| 2425 | 1.0f, 0.0f, |
| 2426 | }; |
| 2427 | |
| 2428 | - for (csmUint32 i = 0; i < Live2DManager->GetModelNum(); i++) |
| 2429 | + for(csmUint32 i=0; i<Live2DManager->GetModelNum(); i++) |
| 2430 | { |
| 2431 | - LAppModel* model = Live2DManager->GetModel(i); |
| 2432 | - float alpha = i < 1 ? 1.0f : model->GetOpacity(); // 片方のみ不透明度を取得できるようにする |
| 2433 | + float alpha = GetSpriteAlpha(i); // サンプルとしてαに適当な差をつける |
| 2434 | _renderSprite->SetColor(1.0f, 1.0f, 1.0f, alpha); |
| 2435 | |
| 2436 | + LAppModel *model = Live2DManager->GetModel(i); |
| 2437 | if (model) |
| 2438 | { |
| 2439 | - _renderSprite->SetWindowSize(maxWidth, maxHeight); |
| 2440 | - _renderSprite->RenderImmidiate( model->GetRenderBuffer().GetColorBuffer(), uvVertex); |
| 2441 | + _renderSprite->RenderImmidiate(model->GetRenderBuffer().GetColorBuffer(), uvVertex); |
| 2442 | } |
| 2443 | } |
| 2444 | } |
| 2445 | @@ -155,85 +140,22 @@ void LAppView::InitializeSprite() |
| 2446 | glfwGetWindowSize(LAppDelegate::GetInstance()->GetWindow(), &width, &height); |
| 2447 | |
| 2448 | LAppTextureManager* textureManager = LAppDelegate::GetInstance()->GetTextureManager(); |
| 2449 | - const string resourcesPath = ResourcesPath; |
| 2450 | |
| 2451 | - string imageName = BackImageName; |
| 2452 | - LAppTextureManager::TextureInfo* backgroundTexture = textureManager->CreateTextureFromPngFile(resourcesPath + imageName); |
| 2453 | + |
| 2454 | + LAppTextureManager::TextureInfo* backgroundTexture = |
| 2455 | + textureManager->CreateTextureFromColor(0, 255, 0); |
| 2456 | |
| 2457 | float x = width * 0.5f; |
| 2458 | float y = height * 0.5f; |
| 2459 | - float fWidth = static_cast<float>(backgroundTexture->width * 2.0f); |
| 2460 | - float fHeight = static_cast<float>(height * 0.95f); |
| 2461 | + float fWidth = static_cast<float>(width); |
| 2462 | + float fHeight = static_cast<float>(height); |
| 2463 | _back = new LAppSprite(x, y, fWidth, fHeight, backgroundTexture->id, _programId); |
| 2464 | |
| 2465 | - imageName = GearImageName; |
| 2466 | - LAppTextureManager::TextureInfo* gearTexture = textureManager->CreateTextureFromPngFile(resourcesPath + imageName); |
| 2467 | - |
| 2468 | - x = static_cast<float>(width - gearTexture->width * 0.5f); |
| 2469 | - y = static_cast<float>(height - gearTexture->height * 0.5f); |
| 2470 | - fWidth = static_cast<float>(gearTexture->width); |
| 2471 | - fHeight = static_cast<float>(gearTexture->height); |
| 2472 | - _gear = new LAppSprite(x, y, fWidth, fHeight, gearTexture->id, _programId); |
| 2473 | - |
| 2474 | - imageName = PowerImageName; |
| 2475 | - LAppTextureManager::TextureInfo* powerTexture = textureManager->CreateTextureFromPngFile(resourcesPath + imageName); |
| 2476 | - |
| 2477 | - x = static_cast<float>(width - powerTexture->width * 0.5f); |
| 2478 | - y = static_cast<float>(powerTexture->height * 0.5f); |
| 2479 | - fWidth = static_cast<float>(powerTexture->width); |
| 2480 | - fHeight = static_cast<float>(powerTexture->height); |
| 2481 | - _power = new LAppSprite(x, y, fWidth, fHeight, powerTexture->id, _programId); |
| 2482 | - |
| 2483 | // 画面全体を覆うサイズ |
| 2484 | x = width * 0.5f; |
| 2485 | y = height * 0.5f; |
| 2486 | _renderSprite = new LAppSprite(x, y, static_cast<float>(width), static_cast<float>(height), 0, _programId); |
| 2487 | -} |
| 2488 | - |
| 2489 | -void LAppView::OnTouchesBegan(float px, float py) const |
| 2490 | -{ |
| 2491 | - _touchManager->TouchesBegan(px, py); |
| 2492 | -} |
| 2493 | - |
| 2494 | -void LAppView::OnTouchesMoved(float px, float py) const |
| 2495 | -{ |
| 2496 | - float viewX = this->TransformViewX(_touchManager->GetX()); |
| 2497 | - float viewY = this->TransformViewY(_touchManager->GetY()); |
| 2498 | - |
| 2499 | - _touchManager->TouchesMoved(px, py); |
| 2500 | - |
| 2501 | - LAppLive2DManager* Live2DManager = LAppLive2DManager::GetInstance(); |
| 2502 | - Live2DManager->OnDrag(viewX, viewY); |
| 2503 | -} |
| 2504 | - |
| 2505 | -void LAppView::OnTouchesEnded(float px, float py) const |
| 2506 | -{ |
| 2507 | - // タッチ終了 |
| 2508 | - LAppLive2DManager* live2DManager = LAppLive2DManager::GetInstance(); |
| 2509 | - live2DManager->OnDrag(0.0f, 0.0f); |
| 2510 | - { |
| 2511 | - |
| 2512 | - // シングルタップ |
| 2513 | - float x = _deviceToScreen->TransformX(_touchManager->GetX()); // 論理座標変換した座標を取得。 |
| 2514 | - float y = _deviceToScreen->TransformY(_touchManager->GetY()); // 論理座標変換した座標を取得。 |
| 2515 | - if (DebugTouchLogEnable) |
| 2516 | - { |
| 2517 | - LAppPal::PrintLogLn("[APP]touchesEnded x:%.2f y:%.2f", x, y); |
| 2518 | - } |
| 2519 | - live2DManager->OnTap(x, y); |
| 2520 | |
| 2521 | - // 歯車にタップしたか |
| 2522 | - if (_gear->IsHit(px, py)) |
| 2523 | - { |
| 2524 | - live2DManager->NextScene(); |
| 2525 | - } |
| 2526 | - |
| 2527 | - // 電源ボタンにタップしたか |
| 2528 | - if (_power->IsHit(px, py)) |
| 2529 | - { |
| 2530 | - LAppDelegate::GetInstance()->AppEnd(); |
| 2531 | - } |
| 2532 | - } |
| 2533 | } |
| 2534 | |
| 2535 | float LAppView::TransformViewX(float deviceX) const |
| 2536 | @@ -258,7 +180,7 @@ float LAppView::TransformScreenY(float d |
| 2537 | return _deviceToScreen->TransformY(deviceY); |
| 2538 | } |
| 2539 | |
| 2540 | -void LAppView::PreModelDraw(LAppModel& refModel) |
| 2541 | +void LAppView::PreModelDraw(LAppModel &refModel) |
| 2542 | { |
| 2543 | // 別のレンダリングターゲットへ向けて描画する場合の使用するフレームバッファ |
| 2544 | Csm::Rendering::CubismOffscreenSurface_OpenGLES2* useTarget = NULL; |
| 2545 | @@ -271,12 +193,13 @@ void LAppView::PreModelDraw(LAppModel& r |
| 2546 | |
| 2547 | if (!useTarget->IsValid()) |
| 2548 | {// 描画ターゲット内部未作成の場合はここで作成 |
| 2549 | - int width, height; |
| 2550 | - glfwGetWindowSize(LAppDelegate::GetInstance()->GetWindow(), &width, &height); |
| 2551 | - if (width != 0 && height != 0) |
| 2552 | + int bufWidth, bufHeight; |
| 2553 | + glfwGetFramebufferSize(LAppDelegate::GetInstance()->GetWindow(), &bufWidth, &bufHeight); |
| 2554 | + |
| 2555 | + if(bufWidth!=0 && bufHeight!=0) |
| 2556 | { |
| 2557 | // モデル描画キャンバス |
| 2558 | - useTarget->CreateOffscreenSurface(static_cast<csmUint32>(width), static_cast<csmUint32>(height)); |
| 2559 | + useTarget->CreateOffscreenSurface(static_cast<csmUint32>(bufWidth), static_cast<csmUint32>(bufHeight)); |
| 2560 | } |
| 2561 | } |
| 2562 | |
| 2563 | @@ -286,7 +209,7 @@ void LAppView::PreModelDraw(LAppModel& r |
| 2564 | } |
| 2565 | } |
| 2566 | |
| 2567 | -void LAppView::PostModelDraw(LAppModel& refModel) |
| 2568 | +void LAppView::PostModelDraw(LAppModel &refModel) |
| 2569 | { |
| 2570 | // 別のレンダリングターゲットへ向けて描画する場合の使用するフレームバッファ |
| 2571 | Csm::Rendering::CubismOffscreenSurface_OpenGLES2* useTarget = NULL; |
| 2572 | @@ -312,12 +235,6 @@ void LAppView::PostModelDraw(LAppModel& |
| 2573 | }; |
| 2574 | |
| 2575 | _renderSprite->SetColor(1.0f, 1.0f, 1.0f, GetSpriteAlpha(0)); |
| 2576 | - |
| 2577 | - // 画面サイズを取得する |
| 2578 | - int maxWidth, maxHeight; |
| 2579 | - glfwGetWindowSize(LAppDelegate::GetInstance()->GetWindow(), &maxWidth, &maxHeight); |
| 2580 | - _renderSprite->SetWindowSize(maxWidth, maxHeight); |
| 2581 | - |
| 2582 | _renderSprite->RenderImmidiate(useTarget->GetColorBuffer(), uvVertex); |
| 2583 | } |
| 2584 | } |
| 2585 | @@ -382,32 +299,4 @@ void LAppView::ResizeSprite() |
| 2586 | _back->ResetRect(x, y, fWidth, fHeight); |
| 2587 | } |
| 2588 | } |
| 2589 | - |
| 2590 | - if (_power) |
| 2591 | - { |
| 2592 | - GLuint id = _power->GetTextureId(); |
| 2593 | - LAppTextureManager::TextureInfo* texInfo = textureManager->GetTextureInfoById(id); |
| 2594 | - if (texInfo) |
| 2595 | - { |
| 2596 | - x = static_cast<float>(width - texInfo->width * 0.5f); |
| 2597 | - y = static_cast<float>(texInfo->height * 0.5f); |
| 2598 | - fWidth = static_cast<float>(texInfo->width); |
| 2599 | - fHeight = static_cast<float>(texInfo->height); |
| 2600 | - _power->ResetRect(x, y, fWidth, fHeight); |
| 2601 | - } |
| 2602 | - } |
| 2603 | - |
| 2604 | - if (_gear) |
| 2605 | - { |
| 2606 | - GLuint id = _gear->GetTextureId(); |
| 2607 | - LAppTextureManager::TextureInfo* texInfo = textureManager->GetTextureInfoById(id); |
| 2608 | - if (texInfo) |
| 2609 | - { |
| 2610 | - x = static_cast<float>(width - texInfo->width * 0.5f); |
| 2611 | - y = static_cast<float>(height - texInfo->height * 0.5f); |
| 2612 | - fWidth = static_cast<float>(texInfo->width); |
| 2613 | - fHeight = static_cast<float>(texInfo->height); |
| 2614 | - _gear->ResetRect(x, y, fWidth, fHeight); |
| 2615 | - } |
| 2616 | - } |
| 2617 | } |
| 2618 | diff -pruN --exclude build ./demo_clean/src/LAppView.hpp ./demo_dev/src/LAppView.hpp |
| 2619 | --- ./demo_clean/src/LAppView.hpp 2024-03-28 18:19:03.659043800 +0000 |
| 2620 | +++ ./demo_dev/src/LAppView.hpp 2024-03-28 18:25:01.124283600 +0000 |
| 2621 | @@ -1,4 +1,4 @@ |
| 2622 | -/** |
| 2623 | +/** |
| 2624 | * Copyright(c) Live2D Inc. All rights reserved. |
| 2625 | * |
| 2626 | * Use of this source code is governed by the Live2D Open Software license |
| 2627 | @@ -14,7 +14,6 @@ |
| 2628 | #include "CubismFramework.hpp" |
| 2629 | #include <Rendering/OpenGL/CubismOffscreenSurface_OpenGLES2.hpp> |
| 2630 | |
| 2631 | -class TouchManager; |
| 2632 | class LAppSprite; |
| 2633 | class LAppModel; |
| 2634 | |
| 2635 | @@ -61,35 +60,11 @@ public: |
| 2636 | void InitializeSprite(); |
| 2637 | |
| 2638 | /** |
| 2639 | - * @brief スプライト系のサイズ再設定 |
| 2640 | - */ |
| 2641 | + * @brief スプライト系のサイズ再設定 |
| 2642 | + */ |
| 2643 | void ResizeSprite(); |
| 2644 | |
| 2645 | /** |
| 2646 | - * @brief タッチされたときに呼ばれる。 |
| 2647 | - * |
| 2648 | - * @param[in] pointX スクリーンX座標 |
| 2649 | - * @param[in] pointY スクリーンY座標 |
| 2650 | - */ |
| 2651 | - void OnTouchesBegan(float pointX, float pointY) const; |
| 2652 | - |
| 2653 | - /** |
| 2654 | - * @brief タッチしているときにポインタが動いたら呼ばれる。 |
| 2655 | - * |
| 2656 | - * @param[in] pointX スクリーンX座標 |
| 2657 | - * @param[in] pointY スクリーンY座標 |
| 2658 | - */ |
| 2659 | - void OnTouchesMoved(float pointX, float pointY) const; |
| 2660 | - |
| 2661 | - /** |
| 2662 | - * @brief タッチが終了したら呼ばれる。 |
| 2663 | - * |
| 2664 | - * @param[in] pointX スクリーンX座標 |
| 2665 | - * @param[in] pointY スクリーンY座標 |
| 2666 | - */ |
| 2667 | - void OnTouchesEnded(float pointX, float pointY) const; |
| 2668 | - |
| 2669 | - /** |
| 2670 | * @brief X座標をView座標に変換する。 |
| 2671 | * |
| 2672 | * @param[in] deviceX デバイスX座標 |
| 2673 | @@ -120,12 +95,12 @@ public: |
| 2674 | /** |
| 2675 | * @brief モデル1体を描画する直前にコールされる |
| 2676 | */ |
| 2677 | - void PreModelDraw(LAppModel& refModel); |
| 2678 | + void PreModelDraw(LAppModel &refModel); |
| 2679 | |
| 2680 | /** |
| 2681 | * @brief モデル1体を描画した直後にコールされる |
| 2682 | */ |
| 2683 | - void PostModelDraw(LAppModel& refModel); |
| 2684 | + void PostModelDraw(LAppModel &refModel); |
| 2685 | |
| 2686 | /** |
| 2687 | * @brief 別レンダリングターゲットにモデルを描画するサンプルで |
| 2688 | @@ -147,16 +122,13 @@ public: |
| 2689 | void SetRenderTargetClearColor(float r, float g, float b); |
| 2690 | |
| 2691 | private: |
| 2692 | - TouchManager* _touchManager; ///< タッチマネージャー |
| 2693 | Csm::CubismMatrix44* _deviceToScreen; ///< デバイスからスクリーンへの行列 |
| 2694 | Csm::CubismViewMatrix* _viewMatrix; ///< viewMatrix |
| 2695 | GLuint _programId; ///< シェーダID |
| 2696 | LAppSprite* _back; ///< 背景画像 |
| 2697 | - LAppSprite* _gear; ///< ギア画像 |
| 2698 | - LAppSprite* _power; ///< 電源画像 |
| 2699 | |
| 2700 | // レンダリング先を別ターゲットにする方式の場合に使用 |
| 2701 | - LAppSprite* _renderSprite; ///< モードによっては_renderBufferのテクスチャを描画 |
| 2702 | + LAppSprite* _renderSprite; ///< モードによっては_renderBufferのテクスチャを描画 |
| 2703 | Csm::Rendering::CubismOffscreenSurface_OpenGLES2 _renderBuffer; ///< モードによってはCubismモデル結果をこっちにレンダリング |
| 2704 | SelectTarget _renderTarget; ///< レンダリング先の選択肢 |
| 2705 | float _clearColor[4]; ///< レンダリングターゲットのクリアカラー |
| 2706 | diff -pruN --exclude build ./demo_clean/src/LAppWavFileHandler.cpp ./demo_dev/src/LAppWavFileHandler.cpp |
| 2707 | --- ./demo_clean/src/LAppWavFileHandler.cpp 2024-03-28 18:19:04.555847400 +0000 |
| 2708 | +++ ./demo_dev/src/LAppWavFileHandler.cpp 2023-03-05 23:22:10.921862800 +0000 |
| 2709 | @@ -11,8 +11,7 @@ |
| 2710 | #include "LAppPal.hpp" |
| 2711 | |
| 2712 | LAppWavFileHandler::LAppWavFileHandler() |
| 2713 | - : _rawData(NULL) |
| 2714 | - , _pcmData(NULL) |
| 2715 | + : _pcmData(NULL) |
| 2716 | , _userTimeSeconds(0.0f) |
| 2717 | , _lastRms(0.0f) |
| 2718 | , _sampleOffset(0) |
| 2719 | @@ -21,11 +20,6 @@ LAppWavFileHandler::LAppWavFileHandler() |
| 2720 | |
| 2721 | LAppWavFileHandler::~LAppWavFileHandler() |
| 2722 | { |
| 2723 | - if (_rawData != NULL) |
| 2724 | - { |
| 2725 | - CSM_FREE(_rawData); |
| 2726 | - } |
| 2727 | - |
| 2728 | if (_pcmData != NULL) |
| 2729 | { |
| 2730 | ReleasePcmData(); |
| 2731 | @@ -91,115 +85,11 @@ Csm::csmFloat32 LAppWavFileHandler::GetR |
| 2732 | return _lastRms; |
| 2733 | } |
| 2734 | |
| 2735 | -const LAppWavFileHandler::WavFileInfo& LAppWavFileHandler::GetWavFileInfo() const |
| 2736 | -{ |
| 2737 | - return _wavFileInfo; |
| 2738 | -} |
| 2739 | - |
| 2740 | -const Csm::csmByte* LAppWavFileHandler::GetRawData() const |
| 2741 | -{ |
| 2742 | - return _rawData; |
| 2743 | -} |
| 2744 | - |
| 2745 | -Csm::csmUint64 LAppWavFileHandler::GetRawDataSize() const |
| 2746 | -{ |
| 2747 | - return _rawDataSize; |
| 2748 | -} |
| 2749 | - |
| 2750 | -Csm::csmVector<Csm::csmFloat32> LAppWavFileHandler::GetPcmData() const |
| 2751 | -{ |
| 2752 | - Csm::csmVector<Csm::csmFloat32> buffer; |
| 2753 | - |
| 2754 | - for (Csm::csmUint32 sampleCount = 0; sampleCount < _wavFileInfo._samplesPerChannel; sampleCount++) |
| 2755 | - { |
| 2756 | - for (Csm::csmUint32 channelCount = 0; channelCount < _wavFileInfo._numberOfChannels; channelCount++) |
| 2757 | - { |
| 2758 | - buffer.PushBack(_pcmData[channelCount][sampleCount]); |
| 2759 | - } |
| 2760 | - } |
| 2761 | - |
| 2762 | - return buffer; |
| 2763 | -} |
| 2764 | - |
| 2765 | -void LAppWavFileHandler::GetPcmDataChannel(Csm::csmFloat32* dst, Csm::csmUint32 useChannel) const |
| 2766 | -{ |
| 2767 | - for (Csm::csmUint32 sampleCount = 0; sampleCount < _wavFileInfo._samplesPerChannel; sampleCount++) |
| 2768 | - { |
| 2769 | - dst[sampleCount] = _pcmData[useChannel][sampleCount]; |
| 2770 | - } |
| 2771 | -} |
| 2772 | - |
| 2773 | -Csm::csmFloat32 LAppWavFileHandler::NormalizePcmSample(Csm::csmUint32 bitsPerSample, Csm::csmByte* data, Csm::csmUint32 dataSize) |
| 2774 | -{ |
| 2775 | - Csm::csmInt32 pcm32; |
| 2776 | - |
| 2777 | - // 32ビット幅に拡張してから-1~1の範囲に丸める |
| 2778 | - switch (bitsPerSample) |
| 2779 | - { |
| 2780 | - case 8: |
| 2781 | - if (1 <= dataSize) |
| 2782 | - { |
| 2783 | - const Csm::csmUint8 ret = data[0]; |
| 2784 | - pcm32 = static_cast<Csm::csmInt32>(ret) - 128; |
| 2785 | - pcm32 <<= 24; |
| 2786 | - } |
| 2787 | - else |
| 2788 | - { |
| 2789 | - pcm32 = 0; |
| 2790 | - } |
| 2791 | - break; |
| 2792 | - case 16: |
| 2793 | - if (2 <= dataSize) |
| 2794 | - { |
| 2795 | - const Csm::csmUint16 ret = (data[1] << 8) | data[0]; |
| 2796 | - pcm32 = ret << 16; |
| 2797 | - } |
| 2798 | - else |
| 2799 | - { |
| 2800 | - pcm32 = 0; |
| 2801 | - } |
| 2802 | - break; |
| 2803 | - case 24: |
| 2804 | - if (3 <= dataSize) |
| 2805 | - { |
| 2806 | - const Csm::csmUint32 ret = (data[2] << 16) | (data[1] << 8) | data[0]; |
| 2807 | - pcm32 = ret << 8; |
| 2808 | - } |
| 2809 | - else |
| 2810 | - { |
| 2811 | - pcm32 = 0; |
| 2812 | - } |
| 2813 | - break; |
| 2814 | - case 32: |
| 2815 | - if (4 <= dataSize) |
| 2816 | - { |
| 2817 | - const Csm::csmUint32 ret = (data[3] << 24) | (data[2] << 16) | (data[1] << 8) | data[0]; |
| 2818 | - pcm32 = ret << 0; |
| 2819 | - } |
| 2820 | - else |
| 2821 | - { |
| 2822 | - pcm32 = 0; |
| 2823 | - } |
| 2824 | - break; |
| 2825 | - default: |
| 2826 | - // 対応していないビット幅 |
| 2827 | - pcm32 = 0; |
| 2828 | - break; |
| 2829 | - } |
| 2830 | - |
| 2831 | - return static_cast<Csm::csmFloat32>(pcm32) / INT32_MAX; |
| 2832 | -} |
| 2833 | - |
| 2834 | Csm::csmBool LAppWavFileHandler::LoadWavFile(const Csm::csmString& filePath) |
| 2835 | { |
| 2836 | Csm::csmBool ret; |
| 2837 | |
| 2838 | // 既にwavファイルロード済みならば領域開放 |
| 2839 | - if (_rawData != NULL) |
| 2840 | - { |
| 2841 | - CSM_FREE(_rawData); |
| 2842 | - _rawDataSize = 0; |
| 2843 | - } |
| 2844 | if (_pcmData != NULL) |
| 2845 | { |
| 2846 | ReleasePcmData(); |
| 2847 | @@ -251,10 +141,10 @@ Csm::csmBool LAppWavFileHandler::LoadWav |
| 2848 | _wavFileInfo._numberOfChannels = _byteReader.Get16LittleEndian(); |
| 2849 | // サンプリングレート |
| 2850 | _wavFileInfo._samplingRate = _byteReader.Get32LittleEndian(); |
| 2851 | - // 平均データ速度 |
| 2852 | - _wavFileInfo._avgBytesPerSec = _byteReader.Get32LittleEndian(); |
| 2853 | - // ブロックサイズ |
| 2854 | - _wavFileInfo._blockAlign = _byteReader.Get16LittleEndian(); |
| 2855 | + // データ速度[byte/sec](読み飛ばし) |
| 2856 | + _byteReader.Get32LittleEndian(); |
| 2857 | + // ブロックサイズ(読み飛ばし) |
| 2858 | + _byteReader.Get16LittleEndian(); |
| 2859 | // 量子化ビット数 |
| 2860 | _wavFileInfo._bitsPerSample = _byteReader.Get16LittleEndian(); |
| 2861 | // fmtチャンクの拡張部分の読み飛ばし |
| 2862 | @@ -280,25 +170,16 @@ Csm::csmBool LAppWavFileHandler::LoadWav |
| 2863 | _wavFileInfo._samplesPerChannel = (dataChunkSize * 8) / (_wavFileInfo._bitsPerSample * _wavFileInfo._numberOfChannels); |
| 2864 | } |
| 2865 | // 領域確保 |
| 2866 | - _rawDataSize = static_cast<Csm::csmUint64>(_wavFileInfo._blockAlign) * static_cast<Csm::csmUint64>(_wavFileInfo._samplesPerChannel); |
| 2867 | - _rawData = static_cast<Csm::csmByte*>(CSM_MALLOC(sizeof(Csm::csmByte) * _rawDataSize)); |
| 2868 | _pcmData = static_cast<Csm::csmFloat32**>(CSM_MALLOC(sizeof(Csm::csmFloat32*) * _wavFileInfo._numberOfChannels)); |
| 2869 | for (Csm::csmUint32 channelCount = 0; channelCount < _wavFileInfo._numberOfChannels; channelCount++) |
| 2870 | { |
| 2871 | _pcmData[channelCount] = static_cast<Csm::csmFloat32*>(CSM_MALLOC(sizeof(Csm::csmFloat32) * _wavFileInfo._samplesPerChannel)); |
| 2872 | } |
| 2873 | // 波形データ取得 |
| 2874 | - Csm::csmUint64 rawPos = 0; |
| 2875 | for (Csm::csmUint32 sampleCount = 0; sampleCount < _wavFileInfo._samplesPerChannel; sampleCount++) |
| 2876 | { |
| 2877 | for (Csm::csmUint32 channelCount = 0; channelCount < _wavFileInfo._numberOfChannels; channelCount++) |
| 2878 | { |
| 2879 | - // 正規化前 |
| 2880 | - for (Csm::csmUint32 byteCount = 0; byteCount < _wavFileInfo._bitsPerSample / 8; byteCount++) |
| 2881 | - { |
| 2882 | - _rawData[rawPos++] = _byteReader._fileByte[_byteReader._readOffset + byteCount]; |
| 2883 | - } |
| 2884 | - // 正規化後 |
| 2885 | _pcmData[channelCount][sampleCount] = GetPcmSample(); |
| 2886 | } |
| 2887 | } |
| 2888 | diff -pruN --exclude build ./demo_clean/src/LAppWavFileHandler.hpp ./demo_dev/src/LAppWavFileHandler.hpp |
| 2889 | --- ./demo_clean/src/LAppWavFileHandler.hpp 2024-03-28 18:19:04.132172700 +0000 |
| 2890 | +++ ./demo_dev/src/LAppWavFileHandler.hpp 2023-03-05 23:22:10.871136700 +0000 |
| 2891 | @@ -8,7 +8,7 @@ |
| 2892 | #pragma once |
| 2893 | |
| 2894 | #include <CubismFramework.hpp> |
| 2895 | -#include <Type/csmVector.hpp> |
| 2896 | +#include <Utils/CubismString.hpp> |
| 2897 | |
| 2898 | /** |
| 2899 | * @brief wavファイルハンドラ |
| 2900 | @@ -18,28 +18,6 @@ class LAppWavFileHandler |
| 2901 | { |
| 2902 | public: |
| 2903 | /** |
| 2904 | - * @brief 読み込んだwavfileの情報 |
| 2905 | - */ |
| 2906 | - struct WavFileInfo |
| 2907 | - { |
| 2908 | - /** |
| 2909 | - * @brief コンストラクタ |
| 2910 | - */ |
| 2911 | - WavFileInfo() : _fileName(""), _numberOfChannels(0), |
| 2912 | - _bitsPerSample(0), _samplingRate(0), _samplesPerChannel(0), |
| 2913 | - _avgBytesPerSec(0), _blockAlign(0) |
| 2914 | - { } |
| 2915 | - |
| 2916 | - Csm::csmString _fileName; ///< ファイル名 |
| 2917 | - Csm::csmUint32 _numberOfChannels; ///< チャンネル数 |
| 2918 | - Csm::csmUint32 _bitsPerSample; ///< サンプルあたりビット数 |
| 2919 | - Csm::csmUint32 _samplingRate; ///< サンプリングレート |
| 2920 | - Csm::csmUint32 _samplesPerChannel; ///< 1チャンネルあたり総サンプル数 |
| 2921 | - Csm::csmUint32 _avgBytesPerSec; ///< 平均データ速度 |
| 2922 | - Csm::csmUint32 _blockAlign; ///< ブロックサイズ |
| 2923 | - } _wavFileInfo; |
| 2924 | - |
| 2925 | - /** |
| 2926 | * @brief コンストラクタ |
| 2927 | */ |
| 2928 | LAppWavFileHandler(); |
| 2929 | @@ -72,53 +50,6 @@ public: |
| 2930 | */ |
| 2931 | Csm::csmFloat32 GetRms() const; |
| 2932 | |
| 2933 | - /** |
| 2934 | - * @brief ファイル情報を取得 |
| 2935 | - * |
| 2936 | - * @retval ファイル情報 |
| 2937 | - */ |
| 2938 | - const WavFileInfo& GetWavFileInfo() const; |
| 2939 | - |
| 2940 | - /** |
| 2941 | - * @brief 正規化前のデータを取得 |
| 2942 | - * |
| 2943 | - * @retval 正規化前のデータ |
| 2944 | - */ |
| 2945 | - const Csm::csmByte* GetRawData() const; |
| 2946 | - |
| 2947 | - /** |
| 2948 | - * @brief 正規化前のデータの大きさを取得 |
| 2949 | - * |
| 2950 | - * @retval 正規化前のデータの大きさ |
| 2951 | - */ |
| 2952 | - Csm::csmUint64 GetRawDataSize() const; |
| 2953 | - |
| 2954 | - /** |
| 2955 | - * @brief 正規化データを取得する |
| 2956 | - * |
| 2957 | - * @retval 正規化データ |
| 2958 | - */ |
| 2959 | - Csm::csmVector<Csm::csmFloat32> GetPcmData() const; |
| 2960 | - |
| 2961 | - /** |
| 2962 | - * @brief 引数で指定したチャンネルの正規化データを取得する |
| 2963 | - * |
| 2964 | - * @param[in] dst 格納先 |
| 2965 | - * @param[in] useChannel 使用するチャンネル |
| 2966 | - */ |
| 2967 | - void GetPcmDataChannel(Csm::csmFloat32* dst, Csm::csmUint32 useChannel) const; |
| 2968 | - |
| 2969 | - /** |
| 2970 | - * @brief -1~1の範囲の1サンプル取得 |
| 2971 | - * |
| 2972 | - * @param[in] bitsPerSample ビット深度 |
| 2973 | - * @param[in] data 正規化したいデータ |
| 2974 | - * @param[in] dataSize 正規化したいデータの大きさ |
| 2975 | - * |
| 2976 | - * @retval csmFloat32 正規化されたサンプル |
| 2977 | - */ |
| 2978 | - static Csm::csmFloat32 NormalizePcmSample(Csm::csmUint32 bitsPerSample, Csm::csmByte* data, Csm::csmUint32 dataSize); |
| 2979 | - |
| 2980 | private: |
| 2981 | /** |
| 2982 | * @brief wavファイルのロード |
| 2983 | @@ -141,6 +72,25 @@ private: |
| 2984 | Csm::csmFloat32 GetPcmSample(); |
| 2985 | |
| 2986 | /** |
| 2987 | + * @brief 読み込んだwavfileの情報 |
| 2988 | + */ |
| 2989 | + struct WavFileInfo |
| 2990 | + { |
| 2991 | + /** |
| 2992 | + * @brief コンストラクタ |
| 2993 | + */ |
| 2994 | + WavFileInfo() : _fileName(""), _numberOfChannels(0), |
| 2995 | + _bitsPerSample(0), _samplingRate(0), _samplesPerChannel(0) |
| 2996 | + { } |
| 2997 | + |
| 2998 | + Csm::csmString _fileName; ///< ファイル名 |
| 2999 | + Csm::csmUint32 _numberOfChannels; ///< チャンネル数 |
| 3000 | + Csm::csmUint32 _bitsPerSample; ///< サンプルあたりビット数 |
| 3001 | + Csm::csmUint32 _samplingRate; ///< サンプリングレート |
| 3002 | + Csm::csmUint32 _samplesPerChannel; ///< 1チャンネルあたり総サンプル数 |
| 3003 | + } _wavFileInfo; |
| 3004 | + |
| 3005 | + /** |
| 3006 | * @brief バイトリーダ |
| 3007 | */ |
| 3008 | struct ByteReader { |
| 3009 | @@ -225,8 +175,6 @@ private: |
| 3010 | Csm::csmUint32 _readOffset; ///< ファイル参照位置 |
| 3011 | } _byteReader; |
| 3012 | |
| 3013 | - Csm::csmByte* _rawData; ///< 正規化される前のバイト列 |
| 3014 | - Csm::csmUint64 _rawDataSize; ///< 正規化される前のバイト列の大きさ |
| 3015 | Csm::csmFloat32** _pcmData; ///< -1から1の範囲で表現された音声データ配列 |
| 3016 | Csm::csmUint32 _sampleOffset; ///< サンプル参照位置 |
| 3017 | Csm::csmFloat32 _lastRms; ///< 最後に計測したRMS値 |
| 3018 | diff -pruN --exclude build ./demo_clean/src/MouseActionManager.cpp ./demo_dev/src/MouseActionManager.cpp |
| 3019 | --- ./demo_clean/src/MouseActionManager.cpp 2024-03-28 18:19:04.195179800 +0000 |
| 3020 | +++ ./demo_dev/src/MouseActionManager.cpp 2023-03-05 23:22:10.841970900 +0000 |
| 3021 | @@ -1,9 +1,9 @@ |
| 3022 | -/** |
| 3023 | - * Copyright(c) Live2D Inc. All rights reserved. |
| 3024 | - * |
| 3025 | - * Use of this source code is governed by the Live2D Open Software license |
| 3026 | - * that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html. |
| 3027 | - */ |
| 3028 | +/** |
| 3029 | +* Copyright(c) Live2D Inc. All rights reserved. |
| 3030 | +* |
| 3031 | +* Use of this source code is governed by the Live2D Open Software license |
| 3032 | +* that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html. |
| 3033 | +*/ |
| 3034 | |
| 3035 | #include "MouseActionManager.hpp" |
| 3036 | |
| 3037 | @@ -13,7 +13,7 @@ namespace { |
| 3038 | |
| 3039 | MouseActionManager* MouseActionManager::GetInstance() |
| 3040 | { |
| 3041 | - if (instance == NULL) |
| 3042 | + if (!instance) |
| 3043 | { |
| 3044 | instance = new MouseActionManager(); |
| 3045 | } |
| 3046 | @@ -23,7 +23,7 @@ MouseActionManager* MouseActionManager:: |
| 3047 | |
| 3048 | void MouseActionManager::ReleaseInstance() |
| 3049 | { |
| 3050 | - if (instance != NULL) |
| 3051 | + if (instance) |
| 3052 | { |
| 3053 | delete instance; |
| 3054 | } |
| 3055 | @@ -99,18 +99,21 @@ void MouseActionManager::OnMouseCallBack |
| 3056 | return; |
| 3057 | } |
| 3058 | |
| 3059 | - if (GLFW_PRESS == action) |
| 3060 | + switch (action) |
| 3061 | { |
| 3062 | + case GLFW_PRESS: |
| 3063 | _captured = true; |
| 3064 | OnTouchesBegan(_mouseX, _mouseY); |
| 3065 | - } |
| 3066 | - else if (GLFW_RELEASE == action) |
| 3067 | - { |
| 3068 | + break; |
| 3069 | + case GLFW_RELEASE: |
| 3070 | if (_captured) |
| 3071 | { |
| 3072 | _captured = false; |
| 3073 | OnTouchesEnded(_mouseX, _mouseY); |
| 3074 | } |
| 3075 | + break; |
| 3076 | + default: |
| 3077 | + break; |
| 3078 | } |
| 3079 | } |
| 3080 | |
| 3081 | diff -pruN --exclude build ./demo_clean/src/MouseActionManager.hpp ./demo_dev/src/MouseActionManager.hpp |
| 3082 | --- ./demo_clean/src/MouseActionManager.hpp 2024-03-28 18:19:04.336247400 +0000 |
| 3083 | +++ ./demo_dev/src/MouseActionManager.hpp 2023-03-05 23:22:10.961094400 +0000 |
| 3084 | @@ -1,4 +1,4 @@ |
| 3085 | -/** |
| 3086 | +/** |
| 3087 | * Copyright(c) Live2D Inc. All rights reserved. |
| 3088 | * |
| 3089 | * Use of this source code is governed by the Live2D Open Software license |
| 3090 | diff -pruN --exclude build ./demo_clean/src/TouchManager.cpp ./demo_dev/src/TouchManager.cpp |
| 3091 | --- ./demo_clean/src/TouchManager.cpp 2024-03-28 18:19:04.493378700 +0000 |
| 3092 | +++ ./demo_dev/src/TouchManager.cpp 2023-03-05 23:22:10.861957900 +0000 |
| 3093 | @@ -1,4 +1,4 @@ |
| 3094 | -/** |
| 3095 | +/** |
| 3096 | * Copyright(c) Live2D Inc. All rights reserved. |
| 3097 | * |
| 3098 | * Use of this source code is governed by the Live2D Open Software license |
| 3099 | diff -pruN --exclude build ./demo_clean/src/TouchManager.hpp ./demo_dev/src/TouchManager.hpp |
| 3100 | --- ./demo_clean/src/TouchManager.hpp 2024-03-28 18:19:03.612203500 +0000 |
| 3101 | +++ ./demo_dev/src/TouchManager.hpp 2023-03-05 23:22:10.884102300 +0000 |
| 3102 | @@ -1,4 +1,4 @@ |
| 3103 | -/** |
| 3104 | +/** |
| 3105 | * Copyright(c) Live2D Inc. All rights reserved. |
| 3106 | * |
| 3107 | * Use of this source code is governed by the Live2D Open Software license |
| 3108 | diff -pruN --exclude build ./demo_clean/src/main.cpp ./demo_dev/src/main.cpp |
| 3109 | --- ./demo_clean/src/main.cpp 2024-03-28 18:19:03.894879200 +0000 |
| 3110 | +++ ./demo_dev/src/main.cpp 2023-03-05 23:22:10.772150300 +0000 |
| 3111 | @@ -1,22 +1,166 @@ |
| 3112 | -/** |
| 3113 | +/** |
| 3114 | * Copyright(c) Live2D Inc. All rights reserved. |
| 3115 | * |
| 3116 | * Use of this source code is governed by the Live2D Open Software license |
| 3117 | * that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html. |
| 3118 | */ |
| 3119 | |
| 3120 | +#include <thread> |
| 3121 | +#include <stdexcept> |
| 3122 | +#include <sstream> |
| 3123 | + |
| 3124 | +#ifdef __cpp_lib_filesystem |
| 3125 | +#include <filesystem> |
| 3126 | +namespace fs = std::filesystem; |
| 3127 | +#else |
| 3128 | +#include <experimental/filesystem> |
| 3129 | +namespace fs = std::experimental::filesystem; |
| 3130 | +#endif |
| 3131 | + |
| 3132 | + |
| 3133 | #include "LAppDelegate.hpp" |
| 3134 | +#include "LAppLive2DManager.hpp" |
| 3135 | +#include "facial_landmark_detector.h" |
| 3136 | |
| 3137 | -int main() |
| 3138 | +struct CmdArgs |
| 3139 | { |
| 3140 | - // create the application instance |
| 3141 | - if (LAppDelegate::GetInstance()->Initialize() == GL_FALSE) |
| 3142 | + int windowWidth; |
| 3143 | + int windowHeight; |
| 3144 | + std::string windowTitle; |
| 3145 | + std::string rootDir; |
| 3146 | + float scaleFactor; |
| 3147 | + float translateX; |
| 3148 | + float translateY; |
| 3149 | + std::string modelName; |
| 3150 | + bool oldId; // If true, translate new (Cubism 3+) parameter IDs to old (Cubism 2.1) IDs |
| 3151 | + std::string cfgPath; // Path to config file for FacialLandmarkDetector |
| 3152 | +}; |
| 3153 | + |
| 3154 | +CmdArgs parseArgv(int argc, char *argv[]) |
| 3155 | +{ |
| 3156 | + // I think the command-line args are simple enough to not justify using a library... |
| 3157 | + CmdArgs cmdArgs; |
| 3158 | + // Set default values |
| 3159 | + cmdArgs.windowWidth = 600; |
| 3160 | + cmdArgs.windowHeight = 600; |
| 3161 | + cmdArgs.windowTitle = "FacialLandmarksForCubism example"; |
| 3162 | + cmdArgs.rootDir = fs::current_path().string(); |
| 3163 | + cmdArgs.scaleFactor = 4.5f; |
| 3164 | + cmdArgs.translateX = 0.0f; |
| 3165 | + cmdArgs.translateY = -3.1f; |
| 3166 | + cmdArgs.modelName = "Haru"; |
| 3167 | + cmdArgs.oldId = false; |
| 3168 | + cmdArgs.cfgPath = ""; |
| 3169 | + |
| 3170 | + int i = 1; |
| 3171 | + while (i < argc) |
| 3172 | { |
| 3173 | - return 1; |
| 3174 | + std::string arg = argv[i]; |
| 3175 | + std::stringstream ss; |
| 3176 | + |
| 3177 | + if (arg == "--window-width" || arg == "-W") // capital W for consistency with height |
| 3178 | + { |
| 3179 | + ss << argv[i + 1]; |
| 3180 | + if (!(ss >> cmdArgs.windowWidth)) |
| 3181 | + { |
| 3182 | + throw std::runtime_error("Invalid argument for window width"); |
| 3183 | + } |
| 3184 | + } |
| 3185 | + else if (arg == "--window-height" || arg == "-H") // avoiding "-h", typically for help |
| 3186 | + { |
| 3187 | + ss << argv[i + 1]; |
| 3188 | + if (!(ss >> cmdArgs.windowHeight)) |
| 3189 | + { |
| 3190 | + throw std::runtime_error("Invalid argument for window height"); |
| 3191 | + } |
| 3192 | + } |
| 3193 | + else if (arg == "--window-title" || arg == "-t") |
| 3194 | + { |
| 3195 | + cmdArgs.windowTitle = argv[i + 1]; |
| 3196 | + } |
| 3197 | + else if (arg == "--root-dir" || arg == "-d") |
| 3198 | + { |
| 3199 | + cmdArgs.rootDir = argv[i + 1]; |
| 3200 | + } |
| 3201 | + else if (arg == "--scale-factor" || arg == "-f") |
| 3202 | + { |
| 3203 | + ss << argv[i + 1]; |
| 3204 | + if (!(ss >> cmdArgs.scaleFactor)) |
| 3205 | + { |
| 3206 | + throw std::runtime_error("Invalid argument for scale factor"); |
| 3207 | + } |
| 3208 | + } |
| 3209 | + else if (arg == "--translate-x" || arg == "-x") |
| 3210 | + { |
| 3211 | + ss << argv[i + 1]; |
| 3212 | + if (!(ss >> cmdArgs.translateX)) |
| 3213 | + { |
| 3214 | + throw std::runtime_error("Invalid argument for translate X"); |
| 3215 | + } |
| 3216 | + } |
| 3217 | + else if (arg == "--translate-y" || arg == "-y") |
| 3218 | + { |
| 3219 | + ss << argv[i + 1]; |
| 3220 | + if (!(ss >> cmdArgs.translateY)) |
| 3221 | + { |
| 3222 | + throw std::runtime_error("Invalid argument for translate Y"); |
| 3223 | + } |
| 3224 | + } |
| 3225 | + else if (arg == "--model" || arg == "-m") |
| 3226 | + { |
| 3227 | + cmdArgs.modelName = argv[i + 1]; |
| 3228 | + } |
| 3229 | + else if (arg == "--config" || arg == "-c") |
| 3230 | + { |
| 3231 | + cmdArgs.cfgPath = argv[i + 1]; |
| 3232 | + } |
| 3233 | + else if (arg == "--old-param-id" || arg == "-o") |
| 3234 | + { |
| 3235 | + cmdArgs.oldId = (argv[i + 1][0] == '1'); |
| 3236 | + } |
| 3237 | + else |
| 3238 | + { |
| 3239 | + throw std::runtime_error("Unrecognized argument: " + arg); |
| 3240 | + } |
| 3241 | + |
| 3242 | + i += 2; |
| 3243 | } |
| 3244 | |
| 3245 | - LAppDelegate::GetInstance()->Run(); |
| 3246 | + return cmdArgs; |
| 3247 | +} |
| 3248 | + |
| 3249 | +int main(int argc, char* argv[]) |
| 3250 | +{ |
| 3251 | + auto cmdArgs = parseArgv(argc, argv); |
| 3252 | + |
| 3253 | + LAppDelegate *delegate = LAppDelegate::GetInstance(); |
| 3254 | + |
| 3255 | + if (!delegate->Initialize(cmdArgs.windowWidth, |
| 3256 | + cmdArgs.windowHeight, |
| 3257 | + cmdArgs.windowTitle.c_str())) |
| 3258 | + { |
| 3259 | + throw std::runtime_error("Unable to initialize LAppDelegate"); |
| 3260 | + } |
| 3261 | + |
| 3262 | + delegate->SetRootDirectory(cmdArgs.rootDir); |
| 3263 | + |
| 3264 | + FacialLandmarkDetector detector(cmdArgs.cfgPath); |
| 3265 | + |
| 3266 | + std::thread detectorThread(&FacialLandmarkDetector::mainLoop, |
| 3267 | + &detector); |
| 3268 | + |
| 3269 | + LAppLive2DManager *manager = LAppLive2DManager::GetInstance(); |
| 3270 | + manager->SetModel(cmdArgs.modelName, cmdArgs.oldId); |
| 3271 | + |
| 3272 | + manager->SetProjectionScaleTranslate(cmdArgs.scaleFactor, |
| 3273 | + cmdArgs.translateX, |
| 3274 | + cmdArgs.translateY); |
| 3275 | + manager->SetFacialLandmarkDetector(&detector); |
| 3276 | + |
| 3277 | + delegate->Run(); |
| 3278 | + |
| 3279 | + detector.stop(); |
| 3280 | + detectorThread.join(); |
| 3281 | |
| 3282 | return 0; |
| 3283 | } |
| 3284 | - |
| 3285 | diff -pruN --exclude build ./demo_clean/src/mainMinimum.cpp ./demo_dev/src/mainMinimum.cpp |
| 3286 | --- ./demo_clean/src/mainMinimum.cpp 2024-03-28 18:19:04.383534500 +0000 |
| 3287 | +++ ./demo_dev/src/mainMinimum.cpp 2023-03-05 23:22:10.854990900 +0000 |
| 3288 | @@ -1,4 +1,4 @@ |
| 3289 | -/** |
| 3290 | +/** |
| 3291 | * Copyright(c) Live2D Inc. All rights reserved. |
| 3292 | * |
| 3293 | * Use of this source code is governed by the Live2D Open Software license |
| 3294 | @@ -7,7 +7,8 @@ |
| 3295 | |
| 3296 | #include <functional> |
| 3297 | |
| 3298 | -#include <stb_image.h> |
| 3299 | +#include <sstream> |
| 3300 | +#include <unistd.h> |
| 3301 | #include <GL/glew.h> |
| 3302 | #include <GLFW/glfw3.h> |
| 3303 | |
| 3304 | @@ -15,19 +16,15 @@ |
| 3305 | #include "LAppAllocator.hpp" |
| 3306 | #include "LAppTextureManager.hpp" |
| 3307 | #include "LAppPal.hpp" |
| 3308 | -#include "TouchManager.hpp" |
| 3309 | #include "CubismUserModelExtend.hpp" |
| 3310 | -#include "CubismSampleViewMatrix.hpp" |
| 3311 | #include "MouseActionManager.hpp" |
| 3312 | |
| 3313 | #include <CubismFramework.hpp> |
| 3314 | -#include <CubismDefaultParameterId.hpp> |
| 3315 | #include <CubismModelSettingJson.hpp> |
| 3316 | #include <Model/CubismUserModel.hpp> |
| 3317 | #include <Physics/CubismPhysics.hpp> |
| 3318 | #include <Rendering/OpenGL/CubismRenderer_OpenGLES2.hpp> |
| 3319 | #include <Utils/CubismString.hpp> |
| 3320 | -#include <Math/CubismViewMatrix.hpp> |
| 3321 | |
| 3322 | /** |
| 3323 | *@brief モデルデータのディレクトリ名 |
| 3324 | @@ -36,8 +33,6 @@ |
| 3325 | static const Csm::csmChar* _modelDirectoryName = "Hiyori"; |
| 3326 | |
| 3327 | static Csm::CubismUserModel* _userModel; ///< ユーザーが実際に使用するモデル |
| 3328 | -static Csm::CubismModelSettingJson* _modelJson; ///< モデルの設定情報 |
| 3329 | -static Csm::CubismModel* _model; ///< Mocデータから作成されるモデルデータ |
| 3330 | |
| 3331 | Csm::csmFloat32 _userTimeSeconds; ///< デルタ時間の積算値[秒] |
| 3332 | Csm::csmVector<Csm::CubismIdHandle> _eyeBlinkIds; ///< モデルに設定されたまばたき機能用パラメータID |
| 3333 | @@ -66,8 +61,8 @@ static LAppAllocator _cubismAllocator; / |
| 3334 | |
| 3335 | static LAppTextureManager* _textureManager; ///< テクスチャの管理 |
| 3336 | |
| 3337 | +static std::string _rootDirectory; ///< ルートディレクトリ |
| 3338 | static std::string _currentModelDirectory; ///< 現在のモデルのディレクトリ名 |
| 3339 | -const Csm::csmChar* _currentModelDirectoryChar; ///< 現在のモデルのディレクトリ名のconst csmCharポインタ型 |
| 3340 | |
| 3341 | static GLFWwindow* _window; ///< ウィンドウオブジェクト |
| 3342 | |
| 3343 | @@ -90,18 +85,71 @@ static void InitializeCubism() |
| 3344 | } |
| 3345 | |
| 3346 | /** |
| 3347 | +* @brief 文字列の分割 |
| 3348 | +* |
| 3349 | +* 指定された区切り文字で文字列を分割する |
| 3350 | +*/ |
| 3351 | +Csm::csmVector<std::string> Split(const std::string& baseString, char delimiter) |
| 3352 | +{ |
| 3353 | + Csm::csmVector < std::string > elems; |
| 3354 | + std::stringstream ss(baseString); |
| 3355 | + std::string item; |
| 3356 | + |
| 3357 | + while (getline(ss, item, delimiter)) |
| 3358 | + { |
| 3359 | + if (!item.empty()) |
| 3360 | + { |
| 3361 | + elems.PushBack(item); |
| 3362 | + } |
| 3363 | + } |
| 3364 | + |
| 3365 | + return elems; |
| 3366 | +} |
| 3367 | + |
| 3368 | +/** |
| 3369 | +* @brief ルートディレクトリの設定 |
| 3370 | +* |
| 3371 | +* Linuxのルートディレクトリを確認し、パスを取得する |
| 3372 | +*/ |
| 3373 | +void SetRootDirectory() |
| 3374 | +{ |
| 3375 | + const int maximumPathBufferSize = 1024; |
| 3376 | + char path[maximumPathBufferSize]; |
| 3377 | + ssize_t len = readlink("/proc/self/exe", path, maximumPathBufferSize - 1); |
| 3378 | + |
| 3379 | + if (len != -1) |
| 3380 | + { |
| 3381 | + path[len] = '\0'; |
| 3382 | + } |
| 3383 | + |
| 3384 | + std::string pathString(path); |
| 3385 | + |
| 3386 | + pathString = pathString.substr(0, pathString.rfind("Demo")); |
| 3387 | + Csm::csmVector<std::string> splitStrings = Split(pathString, '/'); |
| 3388 | + |
| 3389 | + _rootDirectory = ""; |
| 3390 | + |
| 3391 | + for (int i = 0; i < splitStrings.GetSize(); i++) |
| 3392 | + { |
| 3393 | + _rootDirectory += "/" + splitStrings[i]; |
| 3394 | + } |
| 3395 | + |
| 3396 | + _rootDirectory += "/"; |
| 3397 | +} |
| 3398 | + |
| 3399 | +/** |
| 3400 | * @brief システムの初期化 |
| 3401 | * |
| 3402 | * 基盤システムの初期化処理を行う |
| 3403 | */ |
| 3404 | static bool InitializeSystem() |
| 3405 | { |
| 3406 | - LAppPal::PrintLogLn("START"); |
| 3407 | + LAppPal::PrintLog("START"); |
| 3408 | |
| 3409 | // GLFWの初期化 |
| 3410 | if (glfwInit() == GL_FALSE) |
| 3411 | { |
| 3412 | - LAppPal::PrintLogLn("Can't initilize GLFW"); |
| 3413 | + LAppPal::PrintLog("Can't initilize GLFW"); |
| 3414 | |
| 3415 | return GL_FALSE; |
| 3416 | } |
| 3417 | @@ -110,7 +158,7 @@ static bool InitializeSystem() |
| 3418 | _window = glfwCreateWindow(LAppDefine::RenderTargetWidth, LAppDefine::RenderTargetHeight, "SIMPLE_SAMPLE", NULL, NULL); |
| 3419 | if (_window == NULL) |
| 3420 | { |
| 3421 | - LAppPal::PrintLogLn("Can't create GLFW window."); |
| 3422 | + LAppPal::PrintLog("Can't create GLFW window."); |
| 3423 | |
| 3424 | glfwTerminate(); |
| 3425 | return GL_FALSE; |
| 3426 | @@ -121,7 +169,7 @@ static bool InitializeSystem() |
| 3427 | glfwSwapInterval(1); |
| 3428 | |
| 3429 | if (glewInit() != GLEW_OK) { |
| 3430 | - LAppPal::PrintLogLn("Can't initilize glew."); |
| 3431 | + LAppPal::PrintLog("Can't initilize glew."); |
| 3432 | |
| 3433 | glfwTerminate(); |
| 3434 | return GL_FALSE; |
| 3435 | @@ -149,6 +197,8 @@ static bool InitializeSystem() |
| 3436 | // ドラッグ入力管理クラスの初期化 |
| 3437 | MouseActionManager::GetInstance()->Initialize(windowWidth, windowHeight); |
| 3438 | |
| 3439 | + SetRootDirectory(); |
| 3440 | + |
| 3441 | return GL_TRUE; |
| 3442 | } |
| 3443 | |
| 3444 | @@ -182,16 +232,6 @@ void Release() |
| 3445 | } |
| 3446 | |
| 3447 | /** |
| 3448 | -* @brief ディレクトリパスの設定 |
| 3449 | -* |
| 3450 | -* モデルのディレクトリパスを設定する |
| 3451 | -*/ |
| 3452 | -void SetAssetDirectory(const std::string& path) |
| 3453 | -{ |
| 3454 | - _currentModelDirectory = path; |
| 3455 | -} |
| 3456 | - |
| 3457 | -/** |
| 3458 | * @brief モデルの読み込み |
| 3459 | * |
| 3460 | * モデルデータの読み込み処理を行う |
| 3461 | @@ -201,13 +241,15 @@ void SetAssetDirectory(const std::string |
| 3462 | void LoadModel(const std::string modelDirectoryName) |
| 3463 | { |
| 3464 | // モデルのディレクトリを指定 |
| 3465 | - SetAssetDirectory(LAppDefine::ResourcesPath + modelDirectoryName + "/"); |
| 3466 | + _currentModelDirectory = _rootDirectory + LAppDefine::ResourcesPath + modelDirectoryName + "/"; |
| 3467 | |
| 3468 | // モデルデータの新規生成 |
| 3469 | _userModel = new CubismUserModelExtend(modelDirectoryName, _currentModelDirectory); |
| 3470 | |
| 3471 | // モデルデータの読み込み及び生成とセットアップを行う |
| 3472 | - static_cast<CubismUserModelExtend*>(_userModel)->SetupModel(); |
| 3473 | + std::string json = ".model3.json"; |
| 3474 | + std::string fileName = _modelDirectoryName + json; |
| 3475 | + static_cast<CubismUserModelExtend*>(_userModel)->LoadAssets(fileName.c_str()); |
| 3476 | |
| 3477 | // ユーザーモデルをMouseActionManagerへ渡す |
| 3478 | MouseActionManager::GetInstance()->SetUserModel(_userModel); |