Skip to content

Commit 6c710c6

Browse files
Update to Cubism 4 SDK for Native R5 beta4
1 parent 68e00b7 commit 6c710c6

11 files changed

+156
-21
lines changed

CHANGELOG.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,24 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
66

7+
## [4-r.5-beta.4] - 2022-07-07
8+
9+
### Added
10+
11+
* Add a function to get the latest .moc3 Version and the .moc3 Version of the loaded model.
12+
* Add a function to get the type of parameters of the model.
13+
* Add a function to get the parent part of the model's Drawable.
14+
15+
### Changed
16+
17+
* Disable ARC in Metal renderer.
18+
19+
### Fixed
20+
21+
* Fix dangling pointer in `GetRenderPassDescriptor` function for Metal.
22+
23+
24+
725
## [4-r.5-beta.3] - 2022-06-16
826

927
### Fixed
@@ -173,6 +191,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
173191
* Fix invalid expressions of `CubismCdiJson`.
174192

175193

194+
[4-r.5-beta.4]: https://github.com/Live2D/CubismNativeFramework/compare/4-r.5-beta.3...4-r.5-beta.4
176195
[4-r.5-beta.3]: https://github.com/Live2D/CubismNativeFramework/compare/4-r.5-beta.2...4-r.5-beta.3
177196
[4-r.5-beta.2]: https://github.com/Live2D/CubismNativeFramework/compare/4-r.5-beta.1...4-r.5-beta.2
178197
[4-r.5-beta.1]: https://github.com/Live2D/CubismNativeFramework/compare/4-r.4...4-r.5-beta.1

src/Model/CubismMoc.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@ CubismMoc* CubismMoc::Create(const csmByte* mocBytes, csmSizeInt size)
1818
memcpy(alignedBuffer, mocBytes, size);
1919

2020
Core::csmMoc* moc = Core::csmReviveMocInPlace(alignedBuffer, size);
21+
const Core::csmMocVersion version = Core::csmGetMocVersion(alignedBuffer, size);
2122

2223
if (moc)
2324
{
2425
cubismMoc = CSM_NEW CubismMoc(moc);
26+
cubismMoc->_mocVersion = version;
2527
}
2628

2729
return cubismMoc;
@@ -35,6 +37,7 @@ void CubismMoc::Delete(CubismMoc* moc)
3537
CubismMoc::CubismMoc(Core::csmMoc* moc)
3638
: _moc(moc)
3739
, _modelCount(0)
40+
, _mocVersion(0)
3841
{ }
3942

4043
CubismMoc::~CubismMoc()
@@ -69,4 +72,14 @@ void CubismMoc::DeleteModel(CubismModel* model)
6972
--_modelCount;
7073
}
7174

75+
Core::csmMocVersion CubismMoc::GetLatestMocVersion()
76+
{
77+
return Core::csmGetLatestMocVersion();
78+
}
79+
80+
Core::csmMocVersion CubismMoc::GetMocVersion()
81+
{
82+
return _mocVersion;
83+
}
84+
7285
}}}

src/Model/CubismMoc.hpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,24 @@ class CubismMoc
5757
*/
5858
void DeleteModel(CubismModel* model);
5959

60+
/**
61+
* @brief 最新の.moc3 Versionを取得
62+
*
63+
* 最新の.moc3 Versionを取得する。
64+
*
65+
* @return 最新の.moc3 Version
66+
*/
67+
static Core::csmMocVersion GetLatestMocVersion();
68+
69+
/**
70+
* @brief 読み込んだモデルの.moc3 Versionを取得
71+
*
72+
* 読み込んだモデルの.moc3 Versionを取得する。
73+
*
74+
* @return 読み込んだモデルの.moc3 Version
75+
*/
76+
Core::csmMocVersion GetMocVersion();
77+
6078
private:
6179
/**
6280
* @brief コンストラクタ
@@ -74,6 +92,7 @@ class CubismMoc
7492

7593
Core::csmMoc* _moc; ///< Mocデータ
7694
csmInt32 _modelCount; ///< Mocデータから作られたモデルの個数
95+
csmUint32 _mocVersion; ///< 読み込んだモデルの.moc3 Version
7796
};
7897

7998
}}}

src/Model/CubismModel.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,11 @@ csmInt32 CubismModel::GetParameterCount() const
135135
return Core::csmGetParameterCount(_model);
136136
}
137137

138+
Core::csmParameterType CubismModel::GetParameterType(csmUint32 parameterIndex) const
139+
{
140+
return Core::csmGetParameterTypes(_model)[parameterIndex];
141+
}
142+
138143
csmFloat32 CubismModel::GetParameterDefaultValue(csmUint32 parameterIndex) const
139144
{
140145
return Core::csmGetParameterDefaultValues(_model)[parameterIndex];
@@ -503,6 +508,11 @@ Core::csmVector4 CubismModel::GetDrawableScreenColor(csmInt32 drawableIndex) con
503508
return screenColors[drawableIndex];
504509
}
505510

511+
csmInt32 CubismModel::GetDrawableParentPartIndex(csmUint32 parameterIndex) const
512+
{
513+
return Core::csmGetPartParentPartIndices(_model)[parameterIndex];
514+
}
515+
506516
csmInt32 CubismModel::GetDrawableCulling(csmInt32 drawableIndex) const
507517
{
508518
const Core::csmFlags* constantFlags = Core::csmGetDrawableConstantFlags(_model);

src/Model/CubismModel.hpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class CubismModel
2828
public:
2929

3030
/**
31-
* @brief テクスチャの色をRGBAで扱うための構造体
31+
* @brief テクスチャの色をRGBAで扱うための構造体
3232
*/
3333
struct DrawableColorData
3434
{
@@ -186,6 +186,16 @@ class CubismModel
186186
*/
187187
csmInt32 GetParameterCount() const;
188188

189+
/**
190+
* @brief パラメータの種類の取得
191+
*
192+
* パラメータの種類を取得する。
193+
*
194+
* @return Core::csmParameterType_Normal -> 通常のパラメータ
195+
* Core::csmParameterType_BlendShape -> ブレンドシェイプパラメータ
196+
*/
197+
Core::csmParameterType GetParameterType(csmUint32 parameterIndex) const;
198+
189199
/**
190200
* @brief パラメータの最大値の取得
191201
*
@@ -453,6 +463,15 @@ class CubismModel
453463
*/
454464
Core::csmVector4 GetDrawableScreenColor(csmInt32 drawableIndex) const;
455465

466+
/**
467+
* @brief Drawableの親パーツのインデックスの取得
468+
*
469+
* Drawableの親パーツのインデックスを取得する。
470+
*
471+
* @return drawableの親パーツのインデックス
472+
*/
473+
csmInt32 GetDrawableParentPartIndex(csmUint32 parameterIndex) const;
474+
456475
/**
457476
* @brief Drawableのカリング情報の取得
458477
*

src/Motion/CubismMotionManager.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class CubismMotionManager : public CubismMotionQueueManager
6868
* 優先度を設定してモーションを開始する。
6969
*
7070
* @param[in] motion モーション
71-
* @param[in] autoDelete 再生が狩猟したモーションのインスタンスを削除するならtrue
71+
* @param[in] autoDelete 再生が終了したモーションのインスタンスを削除するならtrue
7272
* @param[in] priority 優先度
7373
* @return 開始したモーションの識別番号を返す。個別のモーションが終了したか否かを判定するIsFinished()の引数で使用する。開始できない時は「-1」
7474
*/

src/Rendering/Metal/CMakeLists.txt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ target_sources(${LIB_NAME}
1111
${CMAKE_CURRENT_SOURCE_DIR}/MetalShaderTypes.h
1212
)
1313

14-
set_source_files_properties(
15-
CubismRenderingInstanceSingleton_Metal.m
16-
TARGET_DIRECTORY ${LIB_NAME}
17-
PROPERTIES COMPILE_FLAGS "-fno-objc-arc"
14+
# Disable ARC
15+
set_target_properties(
16+
${LIB_NAME}
17+
PROPERTIES
18+
MACOSX_BUNDLE YES
19+
XCODE_ATTRIBUTE_CLANG_ENABLE_OBJC_ARC NO
1820
)

src/Rendering/Metal/CubismCommandBuffer_Metal.mm

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,26 @@
1414
namespace Framework {
1515
namespace Rendering {
1616
CubismCommandBuffer_Metal::DrawCommandBuffer::DrawCommand::DrawCommand()
17+
: _mtlCommandBuffer(NULL)
18+
, _pipelineState(NULL)
19+
, _renderPassDescriptor(NULL)
1720
{
1821
}
1922

2023
CubismCommandBuffer_Metal::DrawCommandBuffer::DrawCommand::~DrawCommand()
2124
{
25+
if (_mtlCommandBuffer != NULL)
26+
{
27+
_mtlCommandBuffer = NULL;
28+
}
29+
if (_pipelineState != NULL)
30+
{
31+
_pipelineState = NULL;
32+
}
33+
if (_renderPassDescriptor != NULL)
34+
{
35+
_renderPassDescriptor = NULL;
36+
}
2237
}
2338

2439
id <MTLCommandBuffer> CubismCommandBuffer_Metal::DrawCommandBuffer::DrawCommand::GetMTLCommandBuffer()
@@ -45,11 +60,26 @@
4560
: _vbStride(0)
4661
, _vbCount(0)
4762
, _ibCount(0)
63+
, _vertices(NULL)
64+
, _uvs(NULL)
65+
, _indices(NULL)
4866
{
4967
}
5068

5169
CubismCommandBuffer_Metal::DrawCommandBuffer::~DrawCommandBuffer()
5270
{
71+
if (_vertices != NULL)
72+
{
73+
[_vertices release];
74+
}
75+
if (_uvs != NULL)
76+
{
77+
[_uvs release];
78+
}
79+
if (_indices != NULL)
80+
{
81+
[_indices release];
82+
}
5383
}
5484

5585
void CubismCommandBuffer_Metal::DrawCommandBuffer::CreateVertexBuffer(id<MTLDevice> device, csmSizeInt stride, csmSizeInt count)

src/Rendering/Metal/CubismOffscreenSurface_Metal.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ class CubismOffscreenFrame_Metal
7777

7878
private:
7979
id <MTLTexture> _colorBuffer; ///レンダーテクスチャ
80-
csmBool _isInheritedRenderTexture;
8180
MTLRenderPassDescriptor *_renderPassDescriptor;
8281
csmUint32 _bufferWidth; ///< Create時に指定された幅
8382
csmUint32 _bufferHeight; ///< Create時に指定された高さ

src/Rendering/Metal/CubismOffscreenSurface_Metal.mm

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
CubismOffscreenFrame_Metal::CubismOffscreenFrame_Metal()
1515
: _colorBuffer(NULL)
1616
, _renderPassDescriptor(NULL)
17-
, _isInheritedRenderTexture(false)
1817
, _bufferWidth(0)
1918
, _bufferHeight(0)
2019
, _pixelFormat(MTLPixelFormatRGBA8Unorm)
@@ -32,11 +31,11 @@
3231

3332
do
3433
{
35-
if (colorBuffer == nil)
34+
if (colorBuffer == NULL)
3635
{
3736
csmBool initResult = false;
3837

39-
_renderPassDescriptor = [MTLRenderPassDescriptor renderPassDescriptor];
38+
_renderPassDescriptor = [[MTLRenderPassDescriptor alloc] init];
4039
_renderPassDescriptor.colorAttachments[0].loadAction = MTLLoadActionClear;
4140
_renderPassDescriptor.colorAttachments[0].storeAction = MTLStoreActionStore;
4241
_renderPassDescriptor.colorAttachments[0].clearColor = MTLClearColorMake(_clearColorR, _clearColorG, _clearColorB, _clearColorA);
@@ -47,10 +46,9 @@
4746

4847
_renderPassDescriptor.renderTargetWidth = displayBufferWidth;
4948
_renderPassDescriptor.renderTargetHeight = displayBufferHeight;
50-
_isInheritedRenderTexture = false;
5149

5250
// Set up a texture for rendering to and sampling from
53-
MTLTextureDescriptor *texDescriptor = [[MTLTextureDescriptor alloc] init];
51+
MTLTextureDescriptor *texDescriptor = [[[MTLTextureDescriptor alloc] init] autorelease];
5452
texDescriptor.textureType = MTLTextureType2D;
5553
texDescriptor.width = displayBufferWidth;
5654
texDescriptor.height = displayBufferHeight;
@@ -65,7 +63,6 @@
6563
else
6664
{
6765
_colorBuffer = colorBuffer;
68-
_isInheritedRenderTexture = true;
6966
}
7067

7168
if (_colorBuffer)
@@ -94,10 +91,17 @@
9491

9592
void CubismOffscreenFrame_Metal::DestroyOffscreenFrame()
9693
{
97-
if (!_isInheritedRenderTexture)
94+
if (_colorBuffer != NULL)
9895
{
96+
[_colorBuffer release];
9997
_colorBuffer = NULL;
10098
}
99+
100+
if (_renderPassDescriptor != NULL)
101+
{
102+
[_renderPassDescriptor release];
103+
_renderPassDescriptor = NULL;
104+
}
101105
}
102106

103107
id <MTLTexture> CubismOffscreenFrame_Metal::GetColorBuffer() const

0 commit comments

Comments
 (0)