Skip to content

Commit 3ad80ca

Browse files
Update to Cubism 4 SDK for Native R7
1 parent f79a724 commit 3ad80ca

17 files changed

+492
-202
lines changed

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,21 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
66

77

8+
## [4-r.7] - 2023-05-25
9+
10+
### Added
11+
12+
* Add some function for checking consistency of MOC3.
13+
* Add the function of checking consistency on reviving a MOC3. (`CubismMoc::Create`)
14+
* Add the function of checking consistency from unrevived MOC3. (`CubismMoc::HasMocConsistencyFromUnrevivedMoc`)
15+
* Add some functions to change Multiply and Screen colors on a per part basis.
16+
17+
### Changed
18+
19+
* Change access specifier for `CubismExpressionMotion`.
20+
* Change to get opacity according to the current time of the motion.
21+
22+
823
## [4-r.6.2] - 2023-03-16
924

1025
### Fixed
@@ -261,6 +276,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
261276
* Fix invalid expressions of `CubismCdiJson`.
262277

263278

279+
[4-r.7]: https://github.com/Live2D/CubismNativeFramework/compare/4-r.6.2...4-r.7
264280
[4-r.6.2]: https://github.com/Live2D/CubismNativeFramework/compare/4-r.6.1...4-r.6.2
265281
[4-r.6.1]: https://github.com/Live2D/CubismNativeFramework/compare/4-r.6...4-r.6.1
266282
[4-r.6]: https://github.com/Live2D/CubismNativeFramework/compare/4-r.5.1...4-r.6

src/Model/CubismMoc.cpp

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,27 @@
1010

1111
namespace Live2D { namespace Cubism { namespace Framework {
1212

13-
CubismMoc* CubismMoc::Create(const csmByte* mocBytes, csmSizeInt size)
13+
CubismMoc* CubismMoc::Create(const csmByte* mocBytes, csmSizeInt size, csmBool shouldCheckMocConsistency)
1414
{
1515
CubismMoc* cubismMoc = NULL;
1616

1717
void* alignedBuffer = CSM_MALLOC_ALLIGNED(size, Core::csmAlignofMoc);
1818
memcpy(alignedBuffer, mocBytes, size);
1919

20+
if (shouldCheckMocConsistency)
21+
{
22+
// .moc3の整合性を確認
23+
csmBool consistency = HasMocConsistency(alignedBuffer, size);
24+
if (!consistency)
25+
{
26+
CSM_FREE_ALLIGNED(alignedBuffer);
27+
28+
// 整合性が確認できなければ処理しない
29+
CubismLogError("Inconsistent MOC3.");
30+
return cubismMoc;
31+
}
32+
}
33+
2034
Core::csmMoc* moc = Core::csmReviveMocInPlace(alignedBuffer, size);
2135
const Core::csmMocVersion version = Core::csmGetMocVersion(alignedBuffer, size);
2236

@@ -84,8 +98,20 @@ Core::csmMocVersion CubismMoc::GetMocVersion()
8498

8599
csmBool CubismMoc::HasMocConsistency(void* address, const csmUint32 size)
86100
{
87-
csmInt32 consistencyFlags = Core::csmHasMocConsistency(address, size);
88-
return consistencyFlags != 0 ? true : false;
101+
csmInt32 isConsistent = Core::csmHasMocConsistency(address, size);
102+
return isConsistent != 0 ? true : false;
103+
}
104+
105+
csmBool CubismMoc::HasMocConsistencyFromUnrevivedMoc(const csmByte* mocBytes, csmSizeInt size)
106+
{
107+
void* alignedBuffer = CSM_MALLOC_ALLIGNED(size, Core::csmAlignofMoc);
108+
memcpy(alignedBuffer, mocBytes, size);
109+
110+
csmBool consistency = CubismMoc::HasMocConsistency(alignedBuffer, size);
111+
112+
CSM_FREE_ALLIGNED(alignedBuffer);
113+
114+
return consistency;
89115
}
90116

91117
}}}

src/Model/CubismMoc.hpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ class CubismMoc
2929
*
3030
* @param[in] mocBytes Mocファイルのバッファ
3131
* @param[in] size バッファのサイズ
32+
* @param[in] shouldCheckMocConsistency MOCの整合性チェックフラグ(初期値 : false)
3233
*/
33-
static CubismMoc* Create(const csmByte* mocBytes, csmSizeInt size);
34+
static CubismMoc* Create(const csmByte* mocBytes, csmSizeInt size, csmBool shouldCheckMocConsistency = false);
3435

3536
/**
3637
* @brief Mocデータを削除
@@ -85,6 +86,16 @@ class CubismMoc
8586
*/
8687
static csmBool HasMocConsistency(void* address, const csmUint32 size);
8788

89+
/**
90+
* @brief Checks consistency of a moc.
91+
*
92+
* @param mocBytes Mocファイルのバッファ
93+
* @param size バッファのサイズ
94+
*
95+
* @return 'true' if Moc is valid; 'false' otherwise.
96+
*/
97+
static csmBool HasMocConsistencyFromUnrevivedMoc(const csmByte* mocBytes, csmSizeInt size);
98+
8899
private:
89100
/**
90101
* @brief コンストラクタ

src/Model/CubismModel.cpp

Lines changed: 167 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ CubismModel::CubismModel(Core::csmModel* model)
2626
, _isOverwrittenModelMultiplyColors(false)
2727
, _isOverwrittenModelScreenColors(false)
2828
, _isOverwrittenCullings(false)
29+
, _modelOpacity(1.0f)
2930
{ }
3031

3132
CubismModel::~CubismModel()
@@ -378,15 +379,19 @@ void CubismModel::Initialize()
378379
}
379380
}
380381

382+
const csmInt32 partCount = Core::csmGetPartCount(_model);
381383
{
382384
const csmChar** partIds = Core::csmGetPartIds(_model);
383-
const csmInt32 partCount = Core::csmGetPartCount(_model);
384385

385386
_partIds.PrepareCapacity(partCount);
386387
for (csmInt32 i = 0; i < partCount; ++i)
387388
{
388389
_partIds.PushBack(CubismFramework::GetIdManager()->GetId(partIds[i]));
389390
}
391+
392+
_userPartMultiplyColors.PrepareCapacity(partCount);
393+
_userPartScreenColors.PrepareCapacity(partCount);
394+
_partChildDrawables.Resize(partCount);
390395
}
391396

392397
{
@@ -398,38 +403,69 @@ void CubismModel::Initialize()
398403
_userScreenColors.PrepareCapacity(drawableCount);
399404
_userCullings.PrepareCapacity(drawableCount);
400405

406+
// カリング設定
407+
DrawableCullingData userCulling;
408+
userCulling.IsOverwritten = false;
409+
userCulling.IsCulling = 0;
410+
401411
// 乗算色
402412
Rendering::CubismRenderer::CubismTextureColor multiplyColor;
403413
multiplyColor.R = 1.0f;
404414
multiplyColor.G = 1.0f;
405415
multiplyColor.B = 1.0f;
406416
multiplyColor.A = 1.0f;
407-
DrawableColorData userMultiplyColor;
408-
userMultiplyColor.IsOverwritten = false;
409-
userMultiplyColor.Color = multiplyColor;
410417

411418
// スクリーン色
412419
Rendering::CubismRenderer::CubismTextureColor screenColor;
413420
screenColor.R = 0.0f;
414421
screenColor.G = 0.0f;
415422
screenColor.B = 0.0f;
416423
screenColor.A = 1.0f;
417-
DrawableColorData userScreenColor;
418-
userScreenColor.IsOverwritten = false;
419-
userScreenColor.Color = screenColor;
420-
421-
// カリング設定
422-
DrawableCullingData userCulling;
423-
userCulling.IsOverwritten = false;
424-
userCulling.IsCulling = 0;
425424

425+
// Parts
426+
{
427+
// 乗算色
428+
PartColorData userMultiplyColor;
429+
userMultiplyColor.IsOverwritten = false;
430+
userMultiplyColor.Color = multiplyColor;
431+
432+
// スクリーン色
433+
PartColorData userScreenColor;
434+
userScreenColor.IsOverwritten = false;
435+
userScreenColor.Color = screenColor;
436+
437+
for (csmInt32 i = 0; i < partCount; ++i)
438+
{
439+
_userPartMultiplyColors.PushBack(userMultiplyColor);
440+
_userPartScreenColors.PushBack(userScreenColor);
441+
}
442+
}
426443

427-
for (csmInt32 i = 0; i < drawableCount; ++i)
444+
// Drawables
428445
{
429-
_drawableIds.PushBack(CubismFramework::GetIdManager()->GetId(drawableIds[i]));
430-
_userMultiplyColors.PushBack(userMultiplyColor);
431-
_userScreenColors.PushBack(userScreenColor);
432-
_userCullings.PushBack(userCulling);
446+
// 乗算色
447+
DrawableColorData userMultiplyColor;
448+
userMultiplyColor.IsOverwritten = false;
449+
userMultiplyColor.Color = multiplyColor;
450+
451+
// スクリーン色
452+
DrawableColorData userScreenColor;
453+
userScreenColor.IsOverwritten = false;
454+
userScreenColor.Color = screenColor;
455+
456+
for (csmInt32 i = 0; i < drawableCount; ++i)
457+
{
458+
_drawableIds.PushBack(CubismFramework::GetIdManager()->GetId(drawableIds[i]));
459+
_userMultiplyColors.PushBack(userMultiplyColor);
460+
_userScreenColors.PushBack(userScreenColor);
461+
_userCullings.PushBack(userCulling);
462+
463+
csmInt32 parentIndex = Core::csmGetDrawableParentPartIndices(_model)[i];
464+
if (parentIndex >= 0)
465+
{
466+
_partChildDrawables[parentIndex].PushBack(i);
467+
}
468+
}
433469
}
434470
}
435471
}
@@ -440,6 +476,12 @@ CubismIdHandle CubismModel::GetDrawableId(csmInt32 drawableIndex) const
440476
return CubismFramework::GetIdManager()->GetId(parameterIds[drawableIndex]);
441477
}
442478

479+
CubismIdHandle CubismModel::GetPartId(csmUint32 partIndex)
480+
{
481+
const csmChar** partIds = Core::csmGetPartIds(_model);
482+
return CubismFramework::GetIdManager()->GetId(partIds[partIndex]);
483+
}
484+
443485
csmInt32 CubismModel::GetPartCount() const
444486
{
445487
const csmInt32 partCount = Core::csmGetPartCount(_model);
@@ -675,6 +717,60 @@ void CubismModel::SetScreenColor(csmInt32 drawableIndex, csmFloat32 r, csmFloat3
675717
_userScreenColors[drawableIndex].Color.A = a;
676718
}
677719

720+
Rendering::CubismRenderer::CubismTextureColor CubismModel::GetPartMultiplyColor(csmInt32 partIndex) const
721+
{
722+
return _userPartMultiplyColors[partIndex].Color;
723+
}
724+
725+
Rendering::CubismRenderer::CubismTextureColor CubismModel::GetPartScreenColor(csmInt32 partIndex) const
726+
{
727+
return _userPartScreenColors[partIndex].Color;
728+
}
729+
730+
void CubismModel::SetPartMultiplyColor(csmInt32 partIndex, const Rendering::CubismRenderer::CubismTextureColor& color)
731+
{
732+
SetPartMultiplyColor(partIndex, color.R, color.G, color.B, color.A);
733+
}
734+
735+
void CubismModel::SetPartColor(
736+
csmUint32 partIndex,
737+
csmFloat32 r, csmFloat32 g, csmFloat32 b, csmFloat32 a,
738+
csmVector<PartColorData>& partColors,
739+
csmVector <DrawableColorData>& drawableColors)
740+
{
741+
partColors[partIndex].Color.R = r;
742+
partColors[partIndex].Color.G = g;
743+
partColors[partIndex].Color.B = b;
744+
partColors[partIndex].Color.A = a;
745+
746+
if (partColors[partIndex].IsOverwritten)
747+
{
748+
for (csmUint32 i = 0; i < _partChildDrawables[partIndex].GetSize(); i++)
749+
{
750+
csmUint32 drawableIndex = _partChildDrawables[partIndex][i];
751+
drawableColors[drawableIndex].Color.R = r;
752+
drawableColors[drawableIndex].Color.G = g;
753+
drawableColors[drawableIndex].Color.B = b;
754+
drawableColors[drawableIndex].Color.A = a;
755+
}
756+
}
757+
}
758+
759+
void CubismModel::SetPartMultiplyColor(csmInt32 partIndex, csmFloat32 r, csmFloat32 g, csmFloat32 b, csmFloat32 a)
760+
{
761+
SetPartColor(partIndex, r, g, b, a, _userPartMultiplyColors, _userMultiplyColors);
762+
}
763+
764+
void CubismModel::SetPartScreenColor(csmInt32 partIndex, const Rendering::CubismRenderer::CubismTextureColor& color)
765+
{
766+
SetPartScreenColor(partIndex, color.R, color.G, color.B, color.A);
767+
}
768+
769+
void CubismModel::SetPartScreenColor(csmInt32 partIndex, csmFloat32 r, csmFloat32 g, csmFloat32 b, csmFloat32 a)
770+
{
771+
SetPartColor(partIndex, r, g, b, a, _userPartScreenColors, _userScreenColors);
772+
}
773+
678774
csmBool CubismModel::GetOverwriteFlagForModelMultiplyColors() const
679775
{
680776
return _isOverwrittenModelMultiplyColors;
@@ -715,6 +811,50 @@ void CubismModel::SetOverwriteFlagForDrawableScreenColors(csmUint32 drawableInde
715811
_userScreenColors[drawableIndex].IsOverwritten = value;
716812
}
717813

814+
csmBool CubismModel::GetOverwriteColorForPartMultiplyColors(csmInt32 partIndex) const
815+
{
816+
return _userPartMultiplyColors[partIndex].IsOverwritten;
817+
}
818+
819+
csmBool CubismModel::GetOverwriteColorForPartScreenColors(csmInt32 partIndex) const
820+
{
821+
return _userPartScreenColors[partIndex].IsOverwritten;
822+
}
823+
824+
void CubismModel::SetOverwriteColorForPartColors(
825+
csmUint32 partIndex,
826+
csmBool value,
827+
csmVector<PartColorData>& partColors,
828+
csmVector <DrawableColorData>& drawableColors)
829+
{
830+
partColors[partIndex].IsOverwritten = value;
831+
832+
for (csmUint32 i = 0; i < _partChildDrawables[partIndex].GetSize(); i++)
833+
{
834+
csmUint32 drawableIndex = _partChildDrawables[partIndex][i];
835+
drawableColors[drawableIndex].IsOverwritten = value;
836+
if (value)
837+
{
838+
drawableColors[drawableIndex].Color.R = partColors[partIndex].Color.R;
839+
drawableColors[drawableIndex].Color.G = partColors[partIndex].Color.G;
840+
drawableColors[drawableIndex].Color.B = partColors[partIndex].Color.B;
841+
drawableColors[drawableIndex].Color.A = partColors[partIndex].Color.A;
842+
}
843+
}
844+
}
845+
846+
void CubismModel::SetOverwriteColorForPartMultiplyColors(csmUint32 partIndex, csmBool value)
847+
{
848+
_userPartMultiplyColors[partIndex].IsOverwritten = value;
849+
SetOverwriteColorForPartColors(partIndex, value, _userPartMultiplyColors, _userMultiplyColors);
850+
}
851+
852+
void CubismModel::SetOverwriteColorForPartScreenColors(csmUint32 partIndex, csmBool value)
853+
{
854+
_userPartScreenColors[partIndex].IsOverwritten = value;
855+
SetOverwriteColorForPartColors(partIndex, value, _userPartScreenColors, _userScreenColors);
856+
}
857+
718858
csmInt32 CubismModel::GetDrawableCulling(csmInt32 drawableIndex) const
719859
{
720860
if (GetOverwriteFlagForModelCullings() || GetOverwriteFlagForDrawableCullings(drawableIndex))
@@ -751,6 +891,16 @@ void CubismModel::SetOverwriteFlagForDrawableCullings(csmUint32 drawableIndex, c
751891
_userCullings[drawableIndex].IsOverwritten = value;
752892
}
753893

894+
csmFloat32 CubismModel::GetModelOpacity()
895+
{
896+
return _modelOpacity;
897+
}
898+
899+
void CubismModel::SetModelOpacity(csmFloat32 value)
900+
{
901+
_modelOpacity = value;
902+
}
903+
754904
Core::csmModel* CubismModel::GetModel() const
755905
{
756906
return _model;

0 commit comments

Comments
 (0)