Skip to content

Commit

Permalink
Merge pull request #1 from Live2D/develop
Browse files Browse the repository at this point in the history
Update to Cubism 5 SDK for Unreal Engine R1 alpha2
  • Loading branch information
itoh-at-live2d-com authored Sep 26, 2024
2 parents 08f65f9 + 040f842 commit 19d42e6
Show file tree
Hide file tree
Showing 54 changed files with 513 additions and 347 deletions.
15 changes: 15 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,17 @@
# Core directory files
/Source/ThirdParty/Live2DCubismCore/**/*.a
/Source/ThirdParty/Live2DCubismCore/**/*.bundle
/Source/ThirdParty/Live2DCubismCore/**/*.dll
/Source/ThirdParty/Live2DCubismCore/**/*.dylib
/Source/ThirdParty/Live2DCubismCore/**/*.lib
/Source/ThirdParty/Live2DCubismCore/**/*.so

# Other files
/build/
.vs/
.vscode/
.idea/
*.iml
.DS_Store
Binaries
Intermediate
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,27 @@ 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-alpha.2] - 2024-09-26

### Added

* Add support for Unreal Engine 5.1 and 5.4.

### Changed

* Align component addition order with execution order.

### Fixed

* Fix the calculation of CubismMotionComponent.
* Fix incorrect pose transition behavior.


## [5-r.1-alpha.1] - 2024-09-05

### Added

* New released!


[5-r.1-alpha.2]: https://github.com/Live2D/CubismUnrealEngineComponents/compare/5-r.1-alpha.1...5-r.1-alpha.2
Binary file modified Content/Materials/CustomUnlitAdditive.uasset
Binary file not shown.
Binary file modified Content/Materials/CustomUnlitAdditiveMasked.uasset
Binary file not shown.
Binary file modified Content/Materials/CustomUnlitAdditiveMaskedInverted.uasset
Binary file not shown.
Binary file modified Content/Materials/CustomUnlitMultiplicative.uasset
Binary file not shown.
Binary file modified Content/Materials/CustomUnlitMultiplicativeMasked.uasset
Binary file not shown.
Binary file modified Content/Materials/CustomUnlitMultiplicativeMaskedInverted.uasset
Binary file not shown.
Binary file modified Content/Materials/CustomUnlitNormal.uasset
Binary file not shown.
Binary file modified Content/Materials/CustomUnlitNormalMasked.uasset
Binary file not shown.
Binary file modified Content/Materials/CustomUnlitNormalMaskedInverted.uasset
Binary file not shown.
Binary file modified Content/Samples/LookAt/LookAtTest.umap
Binary file not shown.
Binary file modified Content/Samples/Models/Mao/Mao.uasset
Binary file not shown.
Binary file modified Content/Samples/Models/Mao/Mao/texture_00.uasset
Binary file not shown.
Binary file modified Content/Samples/Models/Mao/Mao_cdi3.uasset
Binary file not shown.
Binary file modified Content/Samples/Models/Mao/Mao_model3.uasset
Binary file not shown.
Binary file modified Content/Samples/Models/Mao/Mao_physics3.uasset
Binary file not shown.
Binary file modified Content/Samples/Models/Mao/Mao_pose3.uasset
Binary file not shown.
Binary file modified Content/Samples/Models/Mao/expressions/exp_01_exp3.uasset
Binary file not shown.
Binary file modified Content/Samples/Models/Mao/expressions/exp_02_exp3.uasset
Binary file not shown.
Binary file modified Content/Samples/Models/Mao/expressions/exp_03_exp3.uasset
Binary file not shown.
Binary file modified Content/Samples/Models/Mao/expressions/exp_04_exp3.uasset
Binary file not shown.
Binary file modified Content/Samples/Models/Mao/expressions/exp_05_exp3.uasset
Binary file not shown.
Binary file modified Content/Samples/Models/Mao/expressions/exp_06_exp3.uasset
Binary file not shown.
Binary file modified Content/Samples/Models/Mao/expressions/exp_07_exp3.uasset
Binary file not shown.
Binary file modified Content/Samples/Models/Mao/expressions/exp_08_exp3.uasset
Binary file not shown.
Binary file modified Content/Samples/Models/Mao/motions/mtn_01_motion3.uasset
Binary file not shown.
Binary file modified Content/Samples/Models/Mao/motions/mtn_02_motion3.uasset
Binary file not shown.
Binary file modified Content/Samples/Models/Mao/motions/mtn_03_motion3.uasset
Binary file not shown.
Binary file modified Content/Samples/Models/Mao/motions/mtn_04_motion3.uasset
Binary file not shown.
Binary file modified Content/Samples/Models/Mao/motions/sample_01_motion3.uasset
Binary file not shown.
Binary file modified Content/Samples/Models/Mao/motions/special_01_motion3.uasset
Binary file not shown.
Binary file modified Content/Samples/Models/Mao/motions/special_02_motion3.uasset
Binary file not shown.
Binary file modified Content/Samples/Models/Mao/motions/special_03_motion3.uasset
Binary file not shown.
Binary file modified Content/Samples/Raycast/RaycastTest.umap
Binary file not shown.
66 changes: 33 additions & 33 deletions Live2DCubismSDK.uplugin
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
{
"FileVersion": 3,
"Version": 1,
"VersionName": "5-r.1-alpha.1",
"FriendlyName": "Live2DCubismSDK",
"Description": "Live2D Cubism SDK for Unreal Engine Components",
"Category": "Other",
"CreatedBy": "Live2D Inc,",
"CreatedByURL": "https://www.live2d.com/",
"DocsURL": "https://docs.live2d.com/cubism-sdk-manual/top/",
"MarketplaceURL": "",
"SupportURL": "",
"CanContainContent": true,
"IsBetaVersion": true,
"IsExperimentalVersion": true,
"Installed": false,
"Modules": [
{
"Name": "Live2DCubismFramework",
"Type": "Runtime",
"LoadingPhase": "PostConfigInit"
},
{
"Name": "Live2DCubismFrameworkEditor",
"Type": "Editor",
"LoadingPhase": "Default"
},
{
"Name": "Live2DCubismFrameworkImporter",
"Type": "Editor",
"LoadingPhase": "Default"
}
]
{
"FileVersion": 3,
"Version": 1,
"VersionName": "5-r.1-alpha.2",
"FriendlyName": "Live2DCubismSDK",
"Description": "Live2D Cubism SDK for Unreal Engine Components",
"Category": "Other",
"CreatedBy": "Live2D Inc,",
"CreatedByURL": "https://www.live2d.com/",
"DocsURL": "https://docs.live2d.com/cubism-sdk-manual/top/",
"MarketplaceURL": "",
"SupportURL": "",
"CanContainContent": true,
"IsBetaVersion": true,
"IsExperimentalVersion": true,
"Installed": false,
"Modules": [
{
"Name": "Live2DCubismFramework",
"Type": "Runtime",
"LoadingPhase": "PostConfigInit"
},
{
"Name": "Live2DCubismFrameworkEditor",
"Type": "Editor",
"LoadingPhase": "Default"
},
{
"Name": "Live2DCubismFrameworkImporter",
"Type": "Editor",
"LoadingPhase": "Default"
}
]
}
7 changes: 5 additions & 2 deletions README.ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,14 @@ Cubismファイルをuassetファイルに変換する機能は `./Source/Live2D

| Unreal Engine | バージョン |
| --- | --- |
| Unreal Editor | 5.3.2 |
| Unreal Editor 5.4 | 5.4.4 |
| Unreal Editor 5.3 | 5.3.2 |
| Unreal Editor 5.2 | 5.2.1 |
| Unreal Editor 5.1 | 5.1.1 |

| ライブラリ / ツール | バージョン |
| --- | --- |
| Visual Studio 2022 | 17.9.3 |
| Visual Studio 2022 | 17.11.4 |
| Windows SDK | 10.0.22621.0 |

## テスト済みの環境
Expand Down
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,14 @@ Resources like shaders and other assets are located in `./Content/Materials`.

| Unreal Engine | Version |
| --- | --- |
| Unreal Editor | 5.3.2 |
| Unreal Editor 5.4 | 5.4.4 |
| Unreal Editor 5.3 | 5.3.2 |
| Unreal Editor 5.2 | 5.2.1 |
| Unreal Editor 5.1 | 5.1.1 |

| Library / Tool | Version |
| --- | --- |
| Visual Studio 2022 | 17.9.3 |
| Visual Studio 2022 | 17.11.4 |
| Windows SDK | 10.0.22621.0 |

## Tested environment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,8 @@
#include "Model/CubismModelActor.h"
#include "Model/CubismModelComponent.h"
#include "Model/CubismParameterComponent.h"
#include "Kismet/GameplayStatics.h"

const float FrameRate = 30.0f;
const float Epsilon = 0.01f;

UCubismLookAtComponent::UCubismLookAtComponent()
: FaceTargetX(0.0f)
, FaceTargetY(0.0f)
, FaceX(0.0f)
, FaceY(0.0f)
, FaceVX(0.0f)
, FaceVY(0.0f)
, LastTimeSeconds(0.0f)
, UserTimeSeconds(0.0f)
{
PrimaryComponentTick.bCanEverTick = true;
PrimaryComponentTick.TickGroup = TG_DuringPhysics;
Expand Down Expand Up @@ -93,50 +81,50 @@ void UCubismLookAtComponent::TickComponent(float DeltaTime, ELevelTick TickType,

switch (Parameter.Axis)
{
case ECubismLookAtAxis::X:
{
Parameter.Value = Parameter.Factor * LastPosition.X;
break;
}
case ECubismLookAtAxis::Y:
{
Parameter.Value = Parameter.Factor * LastPosition.Y;
break;
}
case ECubismLookAtAxis::Z:
{
Parameter.Value = Parameter.Factor * LastPosition.Z;
break;
}
default:
{
ensure(false);
break;
}
case ECubismLookAtAxis::X:
{
Parameter.Value = Parameter.Factor * LastPosition.X;
break;
}
case ECubismLookAtAxis::Y:
{
Parameter.Value = Parameter.Factor * LastPosition.Y;
break;
}
case ECubismLookAtAxis::Z:
{
Parameter.Value = Parameter.Factor * LastPosition.Z;
break;
}
default:
{
ensure(false);
break;
}
}

switch(Parameter.BlendMode)
switch (Parameter.BlendMode)
{
case ECubismParameterBlendMode::Overwrite:
{
Destination->SetParameterValue(Parameter.Value);
break;
}
case ECubismParameterBlendMode::Additive:
{
Destination->AddParameterValue(Parameter.Value);
break;
}
case ECubismParameterBlendMode::Multiplicative:
{
Destination->MultiplyParameterValue(Parameter.Value);
break;
}
default:
{
case ECubismParameterBlendMode::Overwrite:
{
Destination->SetParameterValue(Parameter.Value);
break;
}
case ECubismParameterBlendMode::Additive:
{
Destination->AddParameterValue(Parameter.Value);
break;
}
case ECubismParameterBlendMode::Multiplicative:
{
Destination->MultiplyParameterValue(Parameter.Value);
break;
}
default:
{
ensure(false);
break;
}
ensure(false);
break;
}
}
}
}
Expand All @@ -146,90 +134,27 @@ FVector UCubismLookAtComponent::SmoothDamp(const FVector CurrentValue, const flo
{
// global(world) coordinates to local(object) coordinates
const FTransform Transform = Model->GetRelativeTransform();
FVector TargetValue = Transform.InverseTransformPosition(Target ? Target->GetActorLocation() : Transform.GetLocation());

APlayerController* PlayerController = GetWorld()->GetFirstPlayerController();
if (!PlayerController)
{
return CurrentValue;
}

FVector2D ScreenPosition;
PlayerController->ProjectWorldLocationToScreen((Target->GetActorLocation() - Transform.GetLocation()), ScreenPosition, false);
const float Scale = 100.0f / Model->GetPixelsPerUnit();
TargetValue = FVector(-TargetValue.Y, TargetValue.Z, TargetValue.X) * Scale;

FVector2D Resolution = GEngine->GameViewport->Viewport->GetSizeXY();
const float Omega = 2.0f / Smoothing;
const float x = Omega * DeltaTime;
const float Invexp = 1.0f / (1.0f + x + 0.48f * x * x + 0.235f * x * x * x);

FaceTargetX = (float)(ScreenPosition.X / Resolution.X) * 2.0f - 1.0f;
FaceTargetY = (float)(ScreenPosition.Y / Resolution.Y) * 2.0f - 1.0f;
const FVector Damp = CurrentValue - TargetValue;

UserTimeSeconds += DeltaTime;
const FVector Tmp = (CurrentVelocity + Omega * Damp) * DeltaTime;
CurrentVelocity = (CurrentVelocity - Omega * Tmp) * Invexp;

const float FaceParamMaxV = 40.0f / 10.0f;
const float MaxV = FaceParamMaxV * 1.0f / FrameRate;
FVector NewDamp = (Damp + Tmp) * Invexp;


if (LastTimeSeconds == 0.0f)
if (FVector::DotProduct(Damp, NewDamp) < 0.0f)
{
LastTimeSeconds = UserTimeSeconds;
return CurrentValue;
NewDamp = FVector::ZeroVector;
CurrentVelocity = FVector::ZeroVector;
}


const float DeltaTimeWeight = (UserTimeSeconds - LastTimeSeconds) * FrameRate;
LastTimeSeconds = UserTimeSeconds;

const float TimeToMaxSpeed = 0.15f;
const float FrameToMaxSpeed = TimeToMaxSpeed * FrameRate; // sec * frame/sec
const float MaxA = DeltaTimeWeight * MaxV / FrameToMaxSpeed;


const float DX = FaceTargetX - FaceX;
const float DY = FaceTargetY - FaceY;


if (FMath::Abs(DX) <= Epsilon && FMath::Abs(DY) <= Epsilon)
{
return CurrentValue;
}

const float D = FMath::Sqrt((DX * DX) + (DY * DY));


const float VX = MaxV * DX / D;
const float VY = MaxV * DY / D;


float AX = VX - FaceVX;
float AY = VY - FaceVY;

const float A = FMath::Sqrt((AX * AX) + (AY * AY));


if (A < -MaxA || A > MaxA)
{
AX *= MaxA / A;
AY *= MaxA / A;
}

FaceVX += AX;
FaceVY += AY;

{

const float MaxVelocity = 0.5f * (FMath::Sqrt((MaxA * MaxA) + 16.0f * MaxA * D - 8.0f * MaxA * D) - MaxA);
const float CurVelocity = FMath::Sqrt((FaceVX * FaceVX) + (FaceVY * FaceVY));

if (CurVelocity > MaxVelocity)
{
FaceVX *= MaxVelocity / CurVelocity;
FaceVY *= MaxVelocity / CurVelocity;
}
}

FaceX += FaceVX;
FaceY += FaceVY;

FVector Ret = FVector(-FaceX, -FaceY, 0);


return Ret;
return NewDamp + TargetValue;
}
Loading

0 comments on commit 19d42e6

Please sign in to comment.