Skip to content

Commit

Permalink
Merge pull request #30 from Live2D/develop
Browse files Browse the repository at this point in the history
Cubism 4 SDK for Native R5 beta4
  • Loading branch information
itoh-at-live2d-com authored Jul 7, 2022
2 parents 05da5dc + 95678a8 commit c0fc43a
Show file tree
Hide file tree
Showing 43 changed files with 19,387 additions and 49 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@ 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/).

## [4-r.5-beta.4] - 2022-07-07

### Added

* Add `Mao` model.

### Changed

* Disable ARC in Metal projects.


## [4-r.5-beta.3] - 2022-06-16

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


[4-r.5-beta.4]: https://github.com/Live2D/CubismNativeSamples/compare/4-r.5-beta.3...4-r.5-beta.4
[4-r.5-beta.3]: https://github.com/Live2D/CubismNativeSamples/compare/4-r.5-beta.2...4-r.5-beta.3
[4-r.5-beta.2]: https://github.com/Live2D/CubismNativeSamples/compare/4-r.5-beta.1...4-r.5-beta.2
[4-r.5-beta.1]: https://github.com/Live2D/CubismNativeSamples/compare/4-r.4...4-r.5-beta.1
Expand Down
15 changes: 15 additions & 0 deletions Core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,21 @@ 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/).


## 2022-07-07

### Added

* Add functions
* `csmGetParameterTypes`
* `csmGetDrawableParentPartIndices`

* Add type `csmMocVersion` and enum. This type is the return value of `csmGetMocVersion`, `csmGetLatestMocVersion`.

### Changed

* Upgrade Core version to 04.02.0002.


## 2022-06-02

### Changed
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ Demo
| CMake | 3.23.0 |
| Visual Studio 2013 | Update 5 |
| Visual Studio 2015 | Update 3 |
| Visual Studio 2017 | 15.9.45 |
| Visual Studio 2019 | 16.11.11 |
| Visual Studio 2017 | 15.9.49 |
| Visual Studio 2019 | 16.11.16 |
| XCode | 13.4.1 |

### Android
Expand Down Expand Up @@ -136,7 +136,7 @@ Demo
| プラットフォーム | バージョン |
| --- | --- |
| iOS / iPadOS | 15.5 |
| macOS | 12.4.1 |
| macOS | 12.4 |
| Windows 10 | 21H2 |
| Windows 11 | 21H2 |

Expand Down
3 changes: 2 additions & 1 deletion Samples/Cocos2d-x/Demo/Classes/LAppDefine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ namespace LAppDefine {
"Hiyori",
"Mark",
"Natori",
"Rice"
"Rice",
"Mao"
};
const csmInt32 ModelDirSize = sizeof(ModelDir) / sizeof(const csmChar*);

Expand Down
3 changes: 2 additions & 1 deletion Samples/D3D11/Demo/proj.d3d11.cmake/src/LAppDefine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ namespace LAppDefine {
"Hiyori",
"Mark",
"Natori",
"Rice"
"Rice",
"Mao"
};
const csmInt32 ModelDirSize = sizeof(ModelDir) / sizeof(const csmChar*);

Expand Down
3 changes: 2 additions & 1 deletion Samples/D3D9/Demo/proj.d3d9.cmake/src/LAppDefine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ namespace LAppDefine {
"Hiyori",
"Mark",
"Natori",
"Rice"
"Rice",
"Mao"
};
const csmInt32 ModelDirSize = sizeof(ModelDir) / sizeof(const csmChar*);

Expand Down
8 changes: 8 additions & 0 deletions Samples/Metal/Demo/proj.ios.cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,14 @@ elseif(PLATFORM STREQUAL "SIMULATOR64")
set_xcode_property(${APP_NAME} ARCHS "x86_64" "All")
endif()

# Disable ARC
set_target_properties(
${APP_NAME}
PROPERTIES
MACOSX_BUNDLE YES
XCODE_ATTRIBUTE_CLANG_ENABLE_OBJC_ARC NO
)

# You can change target that renderer draws by enabling following definition.
#
# * USE_RENDER_TARGET
Expand Down
3 changes: 2 additions & 1 deletion Samples/Metal/Demo/proj.ios.cmake/src/LAppDefine.mm
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@
"Hiyori",
"Mark",
"Natori",
"Rice"
"Rice",
"Mao"
};
const csmInt32 ModelDirSize = sizeof(ModelDir) / sizeof(const csmChar*);

Expand Down
32 changes: 25 additions & 7 deletions Samples/Metal/Demo/proj.ios.cmake/src/LAppLive2DManager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ + (LAppLive2DManager*)getInstance
{
@synchronized(self)
{
if(s_instance == nil)
if (s_instance == nil)
{
s_instance = [[LAppLive2DManager alloc] init];
}
Expand All @@ -44,8 +44,9 @@ + (LAppLive2DManager*)getInstance

+ (void)releaseInstance
{
if(s_instance != nil)
if (s_instance != nil)
{
[s_instance release];
s_instance = nil;
}
}
Expand All @@ -54,12 +55,14 @@ - (id)init
{
self = [super init];
if ( self ) {
_renderBuffer = nil;
_sprite = nil;
_viewMatrix = nil;
_sceneIndex = 0;

_viewMatrix = new Csm::CubismMatrix44();

_renderPassDescriptor = [MTLRenderPassDescriptor renderPassDescriptor];
_renderPassDescriptor = [[MTLRenderPassDescriptor alloc] init];
_renderPassDescriptor.colorAttachments[0].storeAction = MTLStoreActionStore;
_renderPassDescriptor.colorAttachments[0].clearColor = MTLClearColorMake(0.f, 0.f, 0.f, 0.f);
_renderPassDescriptor.depthAttachment.loadAction = MTLLoadActionClear;
Expand All @@ -79,7 +82,21 @@ - (void)dealloc
delete _renderBuffer;
_renderBuffer = NULL;
}

if (_renderPassDescriptor != nil)
{
[_renderPassDescriptor release];
_renderPassDescriptor = nil;
}

if (_sprite != nil)
{
[_sprite release];
_sprite = nil;
}

[self releaseAllModel];
[super dealloc];
}

- (void)releaseAllModel
Expand Down Expand Up @@ -119,7 +136,7 @@ - (void)onTap:(Csm::csmFloat32)x floatY:(Csm::csmFloat32)y;

for (Csm::csmUint32 i = 0; i < _models.GetSize(); i++)
{
if(_models[i]->HitTest(LAppDefine::HitAreaNameHead,x,y))
if (_models[i]->HitTest(LAppDefine::HitAreaNameHead,x,y))
{
if (LAppDefine::DebugLogEnable)
{
Expand Down Expand Up @@ -157,7 +174,7 @@ - (void)onUpdate:(id <MTLCommandBuffer>)commandBuffer currentDrawable:(id<CAMeta

if (_renderTarget != SelectTarget_None)
{
if(!_renderBuffer)
if (!_renderBuffer)
{
_renderBuffer = new Csm::Rendering::CubismOffscreenFrame_Metal;
_renderBuffer->SetMTLPixelFormat(MTLPixelFormatBGRA8Unorm);
Expand Down Expand Up @@ -224,7 +241,7 @@ - (void)onUpdate:(id <MTLCommandBuffer>)commandBuffer currentDrawable:(id<CAMeta

if (_renderTarget == SelectTarget_ViewFrameBuffer && _renderBuffer && _sprite)
{
MTLRenderPassDescriptor *renderPassDescriptor = [MTLRenderPassDescriptor renderPassDescriptor];
MTLRenderPassDescriptor *renderPassDescriptor = [[[MTLRenderPassDescriptor alloc] init] autorelease];
renderPassDescriptor.colorAttachments[0].texture = drawable.texture;
renderPassDescriptor.colorAttachments[0].loadAction = MTLLoadActionLoad;
renderPassDescriptor.colorAttachments[0].storeAction = MTLStoreActionStore;
Expand All @@ -243,7 +260,7 @@ - (void)onUpdate:(id <MTLCommandBuffer>)commandBuffer currentDrawable:(id<CAMeta
return;
}

MTLRenderPassDescriptor *renderPassDescriptor = [MTLRenderPassDescriptor renderPassDescriptor];
MTLRenderPassDescriptor *renderPassDescriptor = [[[MTLRenderPassDescriptor alloc] init] autorelease];
renderPassDescriptor.colorAttachments[0].texture = drawable.texture;
renderPassDescriptor.colorAttachments[0].loadAction = MTLLoadActionLoad;
renderPassDescriptor.colorAttachments[0].storeAction = MTLStoreActionStore;
Expand All @@ -255,6 +272,7 @@ - (void)onUpdate:(id <MTLCommandBuffer>)commandBuffer currentDrawable:(id<CAMeta
[depthSprite SetColor:1.0f g:1.0f b:1.0f a:0.25f + (float)i * 0.5f];
[depthSprite renderImmidiate:renderEncoder];
[renderEncoder endEncoding];
[depthSprite dealloc];
}
}
}
Expand Down
20 changes: 19 additions & 1 deletion Samples/Metal/Demo/proj.ios.cmake/src/LAppModel.mm
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,24 @@ void DeleteBuffer(csmByte* buffer, const csmChar* path = "")
const csmChar* group = _modelSetting->GetMotionGroupName(i);
ReleaseMotionGroup(group);
}

AppDelegate *delegate = (AppDelegate *) [[UIApplication sharedApplication] delegate];
LAppTextureManager *textureManager = [delegate getTextureManager];

for (csmInt32 modelTextureNumber = 0; modelTextureNumber < _modelSetting->GetTextureCount(); modelTextureNumber++)
{
// テクスチャ名が空文字だった場合は削除処理をスキップ
if (!strcmp(_modelSetting->GetTextureFileName(modelTextureNumber), ""))
{
continue;
}

//テクスチャ管理クラスからモデルテクスチャを削除する
csmString texturePath = _modelSetting->GetTextureFileName(modelTextureNumber);
texturePath = _modelHomeDir + texturePath;
[textureManager releaseTextureByName:texturePath.GetRawString()];
}

delete _modelSetting;
}

Expand Down Expand Up @@ -587,7 +605,7 @@ void DeleteBuffer(csmByte* buffer, const csmChar* path = "")
for (csmInt32 modelTextureNumber = 0; modelTextureNumber < _modelSetting->GetTextureCount(); modelTextureNumber++)
{
// テクスチャ名が空文字だった場合はロード・バインド処理をスキップ
if (strcmp(_modelSetting->GetTextureFileName(modelTextureNumber), "") == 0)
if (!strcmp(_modelSetting->GetTextureFileName(modelTextureNumber), ""))
{
continue;
}
Expand Down
51 changes: 43 additions & 8 deletions Samples/Metal/Demo/proj.ios.cmake/src/LAppSprite.mm
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ - (id)initWithMyVar:(float)x Y:(float)y Width:(float)width Height:(float)height
{
self = [super self];

if(self != nil)
if (self != nil)
{
_rect.left = (x - width * 0.5f);
_rect.right = (x + width * 0.5f);
Expand All @@ -46,6 +46,10 @@ - (id)initWithMyVar:(float)x Y:(float)y Width:(float)width Height:(float)height

_spriteColorR = _spriteColorG = _spriteColorB = _spriteColorA = 1.0f;

_pipelineState = nil;
_vertexBuffer = nil;
_fragmentBuffer = nil;

CubismRenderingInstanceSingleton_Metal *single = [CubismRenderingInstanceSingleton_Metal sharedManager];
id <MTLDevice> device = [single getMTLDevice];

Expand All @@ -57,6 +61,29 @@ - (id)initWithMyVar:(float)x Y:(float)y Width:(float)width Height:(float)height
return self;
}

- (void)dealloc
{
if (_pipelineState != nil)
{
[_pipelineState release];
_pipelineState = nil;
}

if (_vertexBuffer != nil)
{
[_vertexBuffer release];
_vertexBuffer = nil;
}

if (_fragmentBuffer != nil)
{
[_fragmentBuffer release];
_fragmentBuffer = nil;
}

[super dealloc];
}

- (void)renderImmidiate:(id<MTLRenderCommandEncoder>)renderEncoder
{
CubismRenderingInstanceSingleton_Metal *single = [CubismRenderingInstanceSingleton_Metal sharedManager];
Expand Down Expand Up @@ -183,32 +210,36 @@ - (void)SetMTLFunction:(id <MTLDevice>)device
{
MTLCompileOptions* compileOptions = [MTLCompileOptions new];
compileOptions.languageVersion = MTLLanguageVersion2_1;
NSError* compileError;
NSString* shader = [self GetMetalShader];
NSError* compileError;
id<MTLLibrary> shaderLib = [device newLibraryWithSource:shader options:compileOptions error:&compileError];
if(!shaderLib)
if (!shaderLib)
{
NSLog(@" ERROR: Couldnt create a Source shader library");
// assert here because if the shader libary isn't loading, nothing good will happen
return;
}
//頂点シェーダの取得
id <MTLFunction> vertexProgram = [shaderLib newFunctionWithName:@"vertexShader"];
if(!vertexProgram)
if (!vertexProgram)
{
NSLog(@">> ERROR: Couldn't load vertex function from default library");
return nil;
}

//フラグメントシェーダの取得
id <MTLFunction> fragmentProgram = [shaderLib newFunctionWithName:@"fragmentShader"];
if(!fragmentProgram)
if (!fragmentProgram)
{
NSLog(@" ERROR: Couldn't load fragment function from default library");
return nil;
}

[self SetMTLRenderPipelineDescriptor:device vertexProgram:vertexProgram fragmentProgram:fragmentProgram];
[compileOptions release];
[shaderLib release];
[vertexProgram release];
[fragmentProgram release];
}

- (void)SetMTLRenderPipelineDescriptor:(id <MTLDevice>)device vertexProgram:(id <MTLFunction>)vertexProgram fragmentProgram:(id <MTLFunction>)fragmentProgram
Expand All @@ -232,15 +263,19 @@ - (void)SetMTLRenderPipelineDescriptor:(id <MTLDevice>)device vertexProgram:(id
pipelineDescriptor.colorAttachments[0].destinationAlphaBlendFactor = MTLBlendFactorOneMinusSourceAlpha;

[self SetMTLRenderPipelineState:device pipelineDescriptor:pipelineDescriptor];
[pipelineDescriptor release];
}

- (void)SetMTLRenderPipelineState:(id <MTLDevice>)device pipelineDescriptor:(MTLRenderPipelineDescriptor*)pipelineDescriptor
{
NSError *error;
_pipelineState = [device newRenderPipelineStateWithDescriptor:pipelineDescriptor
error:&error];
if (_pipelineState == nil)
{
_pipelineState = [device newRenderPipelineStateWithDescriptor:pipelineDescriptor
error:&error];
}

if(!_pipelineState)
if (!_pipelineState)
{
NSLog(@"ERROR: Failed aquiring pipeline state: %@", error);
return nil;
Expand Down
Loading

0 comments on commit c0fc43a

Please sign in to comment.