Skip to content

Commit 9f31abd

Browse files
Update to Cubism 4 SDK for Native R5 beta1
1 parent be0f978 commit 9f31abd

24 files changed

+799
-64
lines changed

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,18 @@ 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.1] - 2022-05-19
8+
9+
### Added
10+
11+
* Add processing related to multiply colors and screen colors added in Cubism 4.2.
12+
* Add a function to reset the physics states.
13+
14+
### Fixed
15+
16+
* Fix GetTextureDirectory() to return the directory name of the 0th texture path.
17+
18+
719
## [4-r.4] - 2021-12-09
820

921
### Added
@@ -141,6 +153,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
141153
* Fix invalid expressions of `CubismCdiJson`.
142154

143155

156+
[4-r.5-beta.1]: https://github.com/Live2D/CubismNativeFramework/compare/4-r.4...4-r.5-beta.1
157+
[4-r.4]: https://github.com/Live2D/CubismNativeFramework/compare/4-r.4-beta.1...4-r.4
144158
[4-r.4-beta.1]: https://github.com/Live2D/CubismNativeFramework/compare/4-r.3...4-r.4-beta.1
145159
[4-r.3]: https://github.com/Live2D/CubismNativeFramework/compare/4-r.3-beta.1...4-r.3
146160
[4-r.3-beta.1]: https://github.com/Live2D/CubismNativeFramework/compare/4-r.2...4-r.3-beta.1

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,4 @@ JSON パーサーやログ出力などのユーティリティ機能を提供し
7979
ユーザー同士でCubism SDKの活用方法の提案や質問をしたい場合は、是非コミュニティをご活用ください。
8080

8181
- [Live2D 公式コミュニティ](https://creatorsforum.live2d.com/)
82-
- [Live2D community(English)](http://community.live2d.com/)
82+
- [Live2D community(English)](https://community.live2d.com/)

src/CubismModelSettingJson.cpp

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,43 @@ csmInt32 CubismModelSettingJson::GetTextureCount()
223223

224224
const csmChar* CubismModelSettingJson::GetTextureDirectory()
225225
{
226-
return (*_jsonValue[FrequentNode_Textures]).GetRawString();
226+
if (!IsExistTextureFiles())
227+
{
228+
return "";
229+
}
230+
231+
csmVector<csmString> splitPathBuffer;
232+
csmVector<csmChar> charBuffer;
233+
const csmChar* rawString = (*_jsonValue[FrequentNode_Textures])[0].GetRawString();
234+
csmInt32 rawStringSize = (*_jsonValue[FrequentNode_Textures])[0].GetString().GetLength();
235+
for (csmInt32 i = 0; i < rawStringSize; i++)
236+
{
237+
// /を含んでいる場合splitする
238+
if (rawString[i] == '/')
239+
{
240+
csmString str = csmString(charBuffer.GetPtr());
241+
splitPathBuffer.PushBack(str);
242+
charBuffer.Clear();
243+
}
244+
// 一文字ずつVector配列に格納する
245+
else
246+
{
247+
charBuffer.PushBack(static_cast<csmChar>(rawString[i] & 0xFF));
248+
}
249+
}
250+
251+
csmInt32 arrayLength = splitPathBuffer.GetSize();
252+
csmString textureDirectoryStr = csmString();
253+
for(csmInt32 i = 0; i < arrayLength; i++)
254+
{
255+
textureDirectoryStr = textureDirectoryStr + splitPathBuffer[i];
256+
if(i < arrayLength - 1)
257+
{
258+
textureDirectoryStr = textureDirectoryStr + "/";
259+
}
260+
}
261+
262+
return textureDirectoryStr.GetRawString();
227263
}
228264

229265
const csmChar* CubismModelSettingJson::GetTextureFileName(csmInt32 index)

src/Model/CubismModel.cpp

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ CubismModel::CubismModel(Core::csmModel* model)
2323
, _parameterMaximumValues(NULL)
2424
, _parameterMinimumValues(NULL)
2525
, _partOpacities(NULL)
26+
, _isOverwrittenModelMultiplyColors(false)
27+
, _isOverwrittenModelScreenColors(false)
2628
{ }
2729

2830
CubismModel::~CubismModel()
@@ -386,9 +388,34 @@ void CubismModel::Initialize()
386388
const csmInt32 drawableCount = Core::csmGetDrawableCount(_model);
387389

388390
_drawableIds.PrepareCapacity(drawableCount);
391+
_userMultiplyColors.PrepareCapacity(drawableCount);
392+
_userScreenColors.PrepareCapacity(drawableCount);
393+
394+
// 乗算色
395+
Rendering::CubismRenderer::CubismTextureColor multiplyColor;
396+
multiplyColor.R = 1.0f;
397+
multiplyColor.G = 1.0f;
398+
multiplyColor.B = 1.0f;
399+
multiplyColor.A = 1.0f;
400+
DrawableColorData userMultiplyColor;
401+
userMultiplyColor.IsOverwritten = false;
402+
userMultiplyColor.Color = multiplyColor;
403+
404+
// スクリーン色
405+
Rendering::CubismRenderer::CubismTextureColor screenColor;
406+
screenColor.R = 0.0f;
407+
screenColor.G = 0.0f;
408+
screenColor.B = 0.0f;
409+
screenColor.A = 1.0f;
410+
DrawableColorData userScreenColor;
411+
userScreenColor.IsOverwritten = false;
412+
userScreenColor.Color = screenColor;
413+
389414
for (csmInt32 i = 0; i < drawableCount; ++i)
390415
{
391416
_drawableIds.PushBack(CubismFramework::GetIdManager()->GetId(drawableIds[i]));
417+
_userMultiplyColors.PushBack(userMultiplyColor);
418+
_userScreenColors.PushBack(userScreenColor);
392419
}
393420
}
394421
}
@@ -459,6 +486,18 @@ csmFloat32 CubismModel::GetDrawableOpacity(csmInt32 drawableIndex) const
459486
return opacities[drawableIndex];
460487
}
461488

489+
Core::csmVector4 CubismModel::GetDrawableMultiplyColor(csmInt32 drawableIndex) const
490+
{
491+
const Core::csmVector4* multiplyColors = Core::csmGetDrawableMultiplyColors(_model);
492+
return multiplyColors[drawableIndex];
493+
}
494+
495+
Core::csmVector4 CubismModel::GetDrawableScreenColor(csmInt32 drawableIndex) const
496+
{
497+
const Core::csmVector4* screenColors = Core::csmGetDrawableScreenColors(_model);
498+
return screenColors[drawableIndex];
499+
}
500+
462501
csmInt32 CubismModel::GetDrawableCulling(csmInt32 drawableIndex) const
463502
{
464503
const Core::csmFlags* constantFlags = Core::csmGetDrawableConstantFlags(_model);
@@ -501,6 +540,11 @@ csmBool CubismModel::GetDrawableDynamicFlagVertexPositionsDidChange(csmInt32 dra
501540
return IsBitSet(dynamicFlags[drawableIndex], Core::csmVertexPositionsDidChange) != 0 ? true : false;
502541
}
503542

543+
csmBool CubismModel::GetDrawableDynamicFlagBlendColorDidChange(csmInt32 drawableIndex) const
544+
{
545+
const Core::csmFlags* dynamicFlags = Core::csmGetDrawableDynamicFlags(_model);
546+
return IsBitSet(dynamicFlags[drawableIndex], Core::csmBlendColorDidChange) != 0 ? true : false;
547+
}
504548

505549
Rendering::CubismRenderer::CubismBlendMode CubismModel::GetDrawableBlendMode(csmInt32 drawableIndex) const
506550
{
@@ -564,6 +608,95 @@ void CubismModel::SaveParameters()
564608
}
565609
}
566610

611+
Rendering::CubismRenderer::CubismTextureColor CubismModel::GetMultiplyColor(csmInt32 drawableIndex) const
612+
{
613+
if (GetOverwriteFlagForModelMultiplyColors() || GetOverwriteFlagForDrawableMultiplyColors(drawableIndex))
614+
{
615+
return _userMultiplyColors[drawableIndex].Color;
616+
}
617+
618+
const Core::csmVector4 color = GetDrawableMultiplyColor(drawableIndex);
619+
620+
return Rendering::CubismRenderer::CubismTextureColor(color.X, color.Y, color.Z, color.W);
621+
}
622+
623+
Rendering::CubismRenderer::CubismTextureColor CubismModel::GetScreenColor(csmInt32 drawableIndex) const
624+
{
625+
if (GetOverwriteFlagForModelScreenColors() || GetOverwriteFlagForDrawableScreenColors(drawableIndex))
626+
{
627+
return _userScreenColors[drawableIndex].Color;
628+
}
629+
630+
const Core::csmVector4 color = GetDrawableScreenColor(drawableIndex);
631+
return Rendering::CubismRenderer::CubismTextureColor(color.X, color.Y, color.Z, color.W);
632+
}
633+
634+
void CubismModel::SetMultiplyColor(csmInt32 drawableIndex, const Rendering::CubismRenderer::CubismTextureColor& color)
635+
{
636+
SetMultiplyColor(drawableIndex, color.R, color.G, color.B, color.A);
637+
}
638+
639+
void CubismModel::SetMultiplyColor(csmInt32 drawableIndex, csmFloat32 r, csmFloat32 g, csmFloat32 b, csmFloat32 a)
640+
{
641+
_userMultiplyColors[drawableIndex].Color.R = r;
642+
_userMultiplyColors[drawableIndex].Color.G = g;
643+
_userMultiplyColors[drawableIndex].Color.B = b;
644+
_userMultiplyColors[drawableIndex].Color.A = a;
645+
}
646+
647+
void CubismModel::SetScreenColor(csmInt32 drawableIndex, const Rendering::CubismRenderer::CubismTextureColor& color)
648+
{
649+
SetScreenColor(drawableIndex, color.R, color.G, color.B, color.A);
650+
}
651+
652+
void CubismModel::SetScreenColor(csmInt32 drawableIndex, csmFloat32 r, csmFloat32 g, csmFloat32 b, csmFloat32 a)
653+
{
654+
_userScreenColors[drawableIndex].Color.R = r;
655+
_userScreenColors[drawableIndex].Color.G = g;
656+
_userScreenColors[drawableIndex].Color.B = b;
657+
_userScreenColors[drawableIndex].Color.A = a;
658+
}
659+
660+
csmBool CubismModel::GetOverwriteFlagForModelMultiplyColors() const
661+
{
662+
return _isOverwrittenModelMultiplyColors;
663+
}
664+
665+
csmBool CubismModel::GetOverwriteFlagForModelScreenColors() const
666+
{
667+
return _isOverwrittenModelScreenColors;
668+
}
669+
670+
void CubismModel::SetOverwriteFlagForModelMultiplyColors(csmBool value)
671+
{
672+
_isOverwrittenModelMultiplyColors = value;
673+
}
674+
675+
void CubismModel::SetOverwriteFlagForModelScreenColors(csmBool value)
676+
{
677+
_isOverwrittenModelScreenColors = value;
678+
}
679+
680+
csmBool CubismModel::GetOverwriteFlagForDrawableMultiplyColors(csmInt32 drawableIndex) const
681+
{
682+
return _userMultiplyColors[drawableIndex].IsOverwritten;
683+
}
684+
685+
csmBool CubismModel::GetOverwriteFlagForDrawableScreenColors(csmInt32 drawableIndex) const
686+
{
687+
return _userScreenColors[drawableIndex].IsOverwritten;
688+
}
689+
690+
void CubismModel::SetOverwriteFlagForDrawableMultiplyColors(csmUint32 drawableIndex, csmBool value)
691+
{
692+
_userMultiplyColors[drawableIndex].IsOverwritten = value;
693+
}
694+
695+
void CubismModel::SetOverwriteFlagForDrawableScreenColors(csmUint32 drawableIndex, csmBool value)
696+
{
697+
_userScreenColors[drawableIndex].IsOverwritten = value;
698+
}
699+
567700
Core::csmModel* CubismModel::GetModel() const
568701
{
569702
return _model;

0 commit comments

Comments
 (0)