Skip to content

Commit

Permalink
Merge pull request #43 from Live2D/develop
Browse files Browse the repository at this point in the history
Update to Cubism 5 SDK for Native R1 beta3
  • Loading branch information
itoh-at-live2d-com authored Oct 12, 2023
2 parents 57f0208 + 8edce19 commit 12dea6c
Show file tree
Hide file tree
Showing 20 changed files with 350 additions and 118 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).


## [5-r.1-beta.3] - 2023-10-12


### Added

* Add functions for MotionSyncPlugin to `LAppWavFileHandler`.

### Changed

* Change so that `LAppSprite` is not depend on `LAppDelegate`.


## [5-r.1-beta.2] - 2023-09-28

### Added
Expand Down Expand Up @@ -342,6 +354,7 @@ See [Core Changelog] for details.
* What was `Package.json` is currently being changed to`cubism-info.yml`.


[5-r.1-beta.3]: https://github.com/Live2D/CubismNativeSamples/compare/5-r.1-beta.2...5-r.1-beta.3
[5-r.1-beta.2]: https://github.com/Live2D/CubismNativeSamples/compare/5-r.1-beta.1...5-r.1-beta.2
[5-r.1-beta.1]: https://github.com/Live2D/CubismNativeSamples/compare/4-r.7...5-r.1-beta.1
[4-r.7]: https://github.com/Live2D/CubismNativeSamples/compare/4-r.6.2...4-r.7
Expand Down
2 changes: 1 addition & 1 deletion Framework
4 changes: 2 additions & 2 deletions README.ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,10 @@ Demo
| CMake | 3.27.1 |
| Visual Studio 2013 | Update 5 |
| Visual Studio 2015 | Update 3 |
| Visual Studio 2017 | 15.9.56 |
| Visual Studio 2017 | 15.9.57 |
| Visual Studio 2019 | 16.11.30 |
| Visual Studio 2022 | 17.7.4 |
| XCode | 14.3.1 |
| Xcode | 14.3.1 |

### Android

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,10 @@ Please refer to [CHANGELOG.md](CHANGELOG.md) for the changelog of this repositor
| CMake | 3.27.1 |
| Visual Studio 2013 | Update 5 |
| Visual Studio 2015 | Update 3 |
| Visual Studio 2017 | 15.9.56 |
| Visual Studio 2017 | 15.9.57 |
| Visual Studio 2019 | 16.11.30 |
| Visual Studio 2022 | 17.7.4 |
| XCode | 14.3.1 |
| Xcode | 14.3.1 |

### Android

Expand Down
4 changes: 2 additions & 2 deletions Samples/Cocos2d-x/README.ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Cocos2d-xで実装したアプリケーションのサンプル実装です。

| フレームワーク | バージョン |
| --- | --- |
| [XCode] | 12.4 |
| [Xcode] | 12.4 |
| [Cocos2d-x] | 4.0 (`95e5d868ce5958c0dadfc485bdda52f1bc404fe0`) |

その他の開発環境・動作確認環境はトップディレクトリにある [README.md](../../README.ja.md) を参照してください。
Expand Down Expand Up @@ -80,7 +80,7 @@ iOS 用の CMake プロジェクトです。

ビルド時に下記の手順を行なってください。

1. XCode`Project設定 - TARGETS - Demo - Packaging - Info.plist File` に記載されている `Info.plist` 内の `Executable file``$(EXECUTABLE_NAME)` または`Demo`(アプリ名)に書き換えてください
1. Xcode`Project設定 - TARGETS - Demo - Packaging - Info.plist File` に記載されている `Info.plist` 内の `Executable file``$(EXECUTABLE_NAME)` または`Demo`(アプリ名)に書き換えてください

NOTICE: Cubism Core は i386 アーキテクチャをサポートしていないため、**iPhone Simulator 向けのビルドは行えません。**

Expand Down
4 changes: 2 additions & 2 deletions Samples/Cocos2d-x/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ This is a sample implementation of an application implemented with Cocos2d-x.

| Framework | Version |
| --- | --- |
| [XCode] | 12.4 |
| [Xcode] | 12.4 |
| [Cocos2d-x] | 4.0 (`95e5d868ce5958c0dadfc485bdda52f1bc404fe0`) |

For other development environments and operation environments, see [README.md](../../README.md) in the top directory.
Expand Down Expand Up @@ -78,7 +78,7 @@ Running the script in the `script` directory will generate a CMake deliverable i

Follow the steps below when building.

1. Rewrite the `Executable file` in `Info.plist` stated in XCode's `Project Settings - TARGETS - Demo - Packaging - Info.plist File` to `$(EXECUTABLE_NAME)` or `Demo` (app name).
1. Rewrite the `Executable file` in `Info.plist` stated in Xcode's `Project Settings - TARGETS - Demo - Packaging - Info.plist File` to `$(EXECUTABLE_NAME)` or `Demo` (app name).

NOTICE: Cubism Core does not support the i386 architecture, so **it is not possible to build for iPhone Simulator.**

Expand Down
8 changes: 4 additions & 4 deletions Samples/Metal/README.ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ iOS もしくは Mac Catalyst用の CMake プロジェクトです。

Appleシリコン搭載のMacでのiOS Simulator用ビルド時は下記の手順を行ってください。

1. XCode`Project設定 - TARGETS - Demo` および `Framework``Build Settings - Architectures - Architectures` の記載を実行環境に合わせて変更してください。
1. Xcode`Project設定 - TARGETS - Demo` および `Framework``Build Settings - Architectures - Architectures` の記載を実行環境に合わせて変更してください。


Mac Catalyst用ビルド時は下記の手順を行なってください。

1. XCode`Project設定 - TARGETS - Demo - General - Supported Destinations``+` を押下し、`Mac > Mac Catalyst` を選択し、モーダルビューの`Enable`を押下してください。
2. XCode`Project設定 - TARGETS - Demo` および `Framework``Build Settings - Architectures - Architectures` の記載を実行環境に合わせて変更してください。
3. XCode`Project設定 - TARGETS - Demo` および `Framework``Build Settings - Architectures - Base SDK``iOS` に変更してください。
1. Xcode`Project設定 - TARGETS - Demo - General - Supported Destinations``+` を押下し、`Mac > Mac Catalyst` を選択し、モーダルビューの`Enable`を押下してください。
2. Xcode`Project設定 - TARGETS - Demo` および `Framework``Build Settings - Architectures - Architectures` の記載を実行環境に合わせて変更してください。
3. Xcode`Project設定 - TARGETS - Demo` および `Framework``Build Settings - Architectures - Base SDK``iOS` に変更してください。
もしくはApple公式Tutorialsを参考ください。
[turning-on-mac-catalyst]:https://developer.apple.com/tutorials/mac-catalyst/turning-on-mac-catalyst

Expand Down
8 changes: 4 additions & 4 deletions Samples/Metal/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ You can choose between iOS, iOS Simulator, or Mac Catalyst when running the scri

Follow the steps below when building for iOS Simulator on a Mac with Apple silicon.

1. Change the description of XCode's `Project Settings - TARGETS - Demo` and `Framework`'s `Build Settings - Architectures - Architectures` according to the execution environment.
1. Change the description of Xcode's `Project Settings - TARGETS - Demo` and `Framework`'s `Build Settings - Architectures - Architectures` according to the execution environment.


Follow the steps below when building for Mac Catalyst.

1. In XCode, under `Project Settings - TARGETS - Demo - General - Supported Destinations`, press `+`, select `Mac > Mac Catalyst` and press `Enable` in the modal view.
2. Change the description of XCode's `Project Settings - TARGETS - Demo` and `Framework`'s `Build Settings - Architectures - Architectures` according to the execution environment.
3. Change XCode's `Project Settings - TARGETS - Demo` and `Framework`'s `Build Settings - Architectures - Base SDK` to `iOS`, or refer to the Apple official tutorials.
1. In Xcode, under `Project Settings - TARGETS - Demo - General - Supported Destinations`, press `+`, select `Mac > Mac Catalyst` and press `Enable` in the modal view.
2. Change the description of Xcode's `Project Settings - TARGETS - Demo` and `Framework`'s `Build Settings - Architectures - Architectures` according to the execution environment.
3. Change Xcode's `Project Settings - TARGETS - Demo` and `Framework`'s `Build Settings - Architectures - Base SDK` to `iOS`, or refer to the Apple official tutorials.
[turning-on-mac-catalyst]: https://developer.apple.com/tutorials/mac-catalyst/turning-on-mac-catalyst


Expand Down
43 changes: 18 additions & 25 deletions Samples/OpenGL/Demo/proj.mac.cmake/src/LAppSprite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/

#include "LAppSprite.hpp"
#include "LAppDelegate.hpp"

LAppSprite::LAppSprite(float x, float y, float width, float height, GLuint textureId, GLuint programId)
: _rect()
Expand Down Expand Up @@ -35,11 +34,7 @@ LAppSprite::~LAppSprite()

void LAppSprite::Render() const
{
// 画面サイズを取得する
int maxWidth, maxHeight;
glfwGetWindowSize(LAppDelegate::GetInstance()->GetWindow(), &maxWidth, &maxHeight);

if(maxWidth==0 || maxHeight==0)
if (_maxWidth == 0 || _maxHeight == 0)
{
return;
}
Expand All @@ -62,10 +57,10 @@ void LAppSprite::Render() const
// 頂点データ
float positionVertex[] =
{
(_rect.right - maxWidth * 0.5f) / (maxWidth * 0.5f), (_rect.up - maxHeight * 0.5f) / (maxHeight * 0.5f),
(_rect.left - maxWidth * 0.5f) / (maxWidth * 0.5f), (_rect.up - maxHeight * 0.5f) / (maxHeight * 0.5f),
(_rect.left - maxWidth * 0.5f) / (maxWidth * 0.5f), (_rect.down - maxHeight * 0.5f) / (maxHeight * 0.5f),
(_rect.right - maxWidth * 0.5f) / (maxWidth * 0.5f), (_rect.down - maxHeight * 0.5f) / (maxHeight * 0.5f)
(_rect.right - _maxWidth * 0.5f) / (_maxWidth * 0.5f), (_rect.up - _maxHeight * 0.5f) / (_maxHeight * 0.5f),
(_rect.left - _maxWidth * 0.5f) / (_maxWidth * 0.5f), (_rect.up - _maxHeight * 0.5f) / (_maxHeight * 0.5f),
(_rect.left - _maxWidth * 0.5f) / (_maxWidth * 0.5f), (_rect.down - _maxHeight * 0.5f) / (_maxHeight * 0.5f),
(_rect.right - _maxWidth * 0.5f) / (_maxWidth * 0.5f), (_rect.down - _maxHeight * 0.5f) / (_maxHeight * 0.5f)
};

// attribute属性を登録
Expand All @@ -81,11 +76,7 @@ void LAppSprite::Render() const

void LAppSprite::RenderImmidiate(GLuint textureId, const GLfloat uvVertex[8]) const
{
// 画面サイズを取得する
int maxWidth, maxHeight;
glfwGetWindowSize(LAppDelegate::GetInstance()->GetWindow(), &maxWidth, &maxHeight);

if(maxWidth==0 || maxHeight==0)
if (_maxWidth == 0 || _maxHeight == 0)
{
return;
}
Expand All @@ -100,10 +91,10 @@ void LAppSprite::RenderImmidiate(GLuint textureId, const GLfloat uvVertex[8]) co
// 頂点データ
float positionVertex[] =
{
(_rect.right - maxWidth * 0.5f) / (maxWidth * 0.5f), (_rect.up - maxHeight * 0.5f) / (maxHeight * 0.5f),
(_rect.left - maxWidth * 0.5f) / (maxWidth * 0.5f), (_rect.up - maxHeight * 0.5f) / (maxHeight * 0.5f),
(_rect.left - maxWidth * 0.5f) / (maxWidth * 0.5f), (_rect.down - maxHeight * 0.5f) / (maxHeight * 0.5f),
(_rect.right - maxWidth * 0.5f) / (maxWidth * 0.5f), (_rect.down - maxHeight * 0.5f) / (maxHeight * 0.5f)
(_rect.right - _maxWidth * 0.5f) / (_maxWidth * 0.5f), (_rect.up - _maxHeight * 0.5f) / (_maxHeight * 0.5f),
(_rect.left - _maxWidth * 0.5f) / (_maxWidth * 0.5f), (_rect.up - _maxHeight * 0.5f) / (_maxHeight * 0.5f),
(_rect.left - _maxWidth * 0.5f) / (_maxWidth * 0.5f), (_rect.down - _maxHeight * 0.5f) / (_maxHeight * 0.5f),
(_rect.right - _maxWidth * 0.5f) / (_maxWidth * 0.5f), (_rect.down - _maxHeight * 0.5f) / (_maxHeight * 0.5f)
};

// attribute属性を登録
Expand All @@ -119,16 +110,12 @@ void LAppSprite::RenderImmidiate(GLuint textureId, const GLfloat uvVertex[8]) co

bool LAppSprite::IsHit(float pointX, float pointY) const
{
// 画面サイズを取得する
int maxWidth, maxHeight;
glfwGetWindowSize(LAppDelegate::GetInstance()->GetWindow(), &maxWidth, &maxHeight);

if(maxWidth==0 || maxHeight==0)
if (_maxWidth == 0 || _maxHeight == 0)
{
return false;
}
//Y座標は変換する必要あり
float y = maxHeight - pointY;
float y = _maxHeight - pointY;

return (pointX >= _rect.left && pointX <= _rect.right && y <= _rect.up && y >= _rect.down);
}
Expand All @@ -148,3 +135,9 @@ void LAppSprite::ResetRect(float x, float y, float width, float height)
_rect.up = (y + height * 0.5f);
_rect.down = (y - height * 0.5f);
}

void LAppSprite::SetWindowSize(int width, int height)
{
_maxWidth = width;
_maxHeight = height;
}
10 changes: 10 additions & 0 deletions Samples/OpenGL/Demo/proj.mac.cmake/src/LAppSprite.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,14 @@ class LAppSprite
*/
void ResetRect(float x, float y, float width, float height);

/**
* @brief ウインドウサイズ設定
*
* @param[in] width 横幅
* @param[in] height 高さ
*/
void SetWindowSize(int width, int height);

private:
GLuint _textureId; ///< テクスチャID
Rect _rect; ///< 矩形
Expand All @@ -103,5 +111,7 @@ class LAppSprite
int _colorLocation; ///< カラーアトリビュート

float _spriteColor[4]; ///< 表示カラー
int _maxWidth; ///< ウインドウ幅
int _maxHeight; ///< ウインドウ高さ
};

7 changes: 7 additions & 0 deletions Samples/OpenGL/Demo/proj.mac.cmake/src/LAppView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,13 @@ void LAppView::Initialize()

void LAppView::Render()
{
// 画面サイズを取得する
int maxWidth, maxHeight;
glfwGetWindowSize(LAppDelegate::GetInstance()->GetWindow(), &maxWidth, &maxHeight);
_back->SetWindowSize(maxWidth, maxHeight);
_gear->SetWindowSize(maxWidth, maxHeight);
_power->SetWindowSize(maxWidth, maxHeight);

_back->Render();
_gear->Render();
_power->Render();
Expand Down
68 changes: 63 additions & 5 deletions Samples/OpenGL/Demo/proj.mac.cmake/src/LAppWavFileHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
#include "LAppPal.hpp"

LAppWavFileHandler::LAppWavFileHandler()
: _pcmData(NULL)
: _rawData(NULL)
, _pcmData(NULL)
, _userTimeSeconds(0.0f)
, _lastRms(0.0f)
, _sampleOffset(0)
Expand All @@ -20,6 +21,11 @@ LAppWavFileHandler::LAppWavFileHandler()

LAppWavFileHandler::~LAppWavFileHandler()
{
if (_rawData != NULL)
{
CSM_FREE(_rawData);
}

if (_pcmData != NULL)
{
ReleasePcmData();
Expand Down Expand Up @@ -85,11 +91,54 @@ Csm::csmFloat32 LAppWavFileHandler::GetRms() const
return _lastRms;
}

const LAppWavFileHandler::WavFileInfo& LAppWavFileHandler::GetWavFileInfo() const
{
return _wavFileInfo;
}

Csm::csmByte* LAppWavFileHandler::GetRawData() const
{
return _rawData;
}

Csm::csmUint64 LAppWavFileHandler::GetRawDataSize() const
{
return _rawDataSize;
}

Csm::csmVector<Csm::csmFloat32> LAppWavFileHandler::GetPcmData() const
{
Csm::csmVector<Csm::csmFloat32> buffer;

for (Csm::csmUint32 sampleCount = 0; sampleCount < _wavFileInfo._samplesPerChannel; sampleCount++)
{
for (Csm::csmUint32 channelCount = 0; channelCount < _wavFileInfo._numberOfChannels; channelCount++)
{
buffer.PushBack(_pcmData[channelCount][sampleCount]);
}
}

return buffer;
}

void LAppWavFileHandler::GetPcmDataChannel(Csm::csmFloat32* dst, Csm::csmUint32 useChannel) const
{
for (Csm::csmUint32 sampleCount = 0; sampleCount < _wavFileInfo._samplesPerChannel; sampleCount++)
{
dst[sampleCount] = _pcmData[useChannel][sampleCount];
}
}

Csm::csmBool LAppWavFileHandler::LoadWavFile(const Csm::csmString& filePath)
{
Csm::csmBool ret;

// 既にwavファイルロード済みならば領域開放
if (_rawData != NULL)
{
CSM_FREE(_rawData);
_rawDataSize = 0;
}
if (_pcmData != NULL)
{
ReleasePcmData();
Expand Down Expand Up @@ -141,10 +190,10 @@ Csm::csmBool LAppWavFileHandler::LoadWavFile(const Csm::csmString& filePath)
_wavFileInfo._numberOfChannels = _byteReader.Get16LittleEndian();
// サンプリングレート
_wavFileInfo._samplingRate = _byteReader.Get32LittleEndian();
// データ速度[byte/sec](読み飛ばし)
_byteReader.Get32LittleEndian();
// ブロックサイズ(読み飛ばし)
_byteReader.Get16LittleEndian();
// 平均データ速度
_wavFileInfo._avgBytesPerSec = _byteReader.Get32LittleEndian();
// ブロックサイズ
_wavFileInfo._blockAlign = _byteReader.Get16LittleEndian();
// 量子化ビット数
_wavFileInfo._bitsPerSample = _byteReader.Get16LittleEndian();
// fmtチャンクの拡張部分の読み飛ばし
Expand All @@ -170,16 +219,25 @@ Csm::csmBool LAppWavFileHandler::LoadWavFile(const Csm::csmString& filePath)
_wavFileInfo._samplesPerChannel = (dataChunkSize * 8) / (_wavFileInfo._bitsPerSample * _wavFileInfo._numberOfChannels);
}
// 領域確保
_rawDataSize = static_cast<Csm::csmUint64>(_wavFileInfo._blockAlign) * static_cast<Csm::csmUint64>(_wavFileInfo._samplesPerChannel);
_rawData = static_cast<Csm::csmByte*>(CSM_MALLOC(sizeof(Csm::csmByte) * _rawDataSize));
_pcmData = static_cast<Csm::csmFloat32**>(CSM_MALLOC(sizeof(Csm::csmFloat32*) * _wavFileInfo._numberOfChannels));
for (Csm::csmUint32 channelCount = 0; channelCount < _wavFileInfo._numberOfChannels; channelCount++)
{
_pcmData[channelCount] = static_cast<Csm::csmFloat32*>(CSM_MALLOC(sizeof(Csm::csmFloat32) * _wavFileInfo._samplesPerChannel));
}
// 波形データ取得
Csm::csmUint64 rawPos = 0;
for (Csm::csmUint32 sampleCount = 0; sampleCount < _wavFileInfo._samplesPerChannel; sampleCount++)
{
for (Csm::csmUint32 channelCount = 0; channelCount < _wavFileInfo._numberOfChannels; channelCount++)
{
// 正規化前
for (Csm::csmUint32 byteCount = 0; byteCount < _wavFileInfo._bitsPerSample / 8; byteCount++)
{
_rawData[rawPos++] = _byteReader._fileByte[_byteReader._readOffset + byteCount];
}
// 正規化後
_pcmData[channelCount][sampleCount] = GetPcmSample();
}
}
Expand Down
Loading

0 comments on commit 12dea6c

Please sign in to comment.