From 4217b51939447561f83d1a1ad5feec279ded526c Mon Sep 17 00:00:00 2001 From: CloudyCanvas Date: Sat, 15 Mar 2025 16:40:24 -0500 Subject: [PATCH] Fixed Blueprint Summary: Made many changes to the code that enables it in Blueprint without causing crashes. Detail: Made a lot of changes that may or may not correspond to the coding style preference. So just take it or leave it. I made it so the model component can be added to an actor through the component add. Additionally, I made it flexible to work with any actor type than the model actor. I also removed some of the components ability to be added through the component add menu. Mainly because I made them be created through the model component instead when you set the corresponding files. Setting the files will create the baseline for the model. You can then also add the other components through the drop down if needed. Made it so they should not crash even if the model component has not been added yet. --- .../EyeBlink/CubismEyeBlinkComponent.cpp | 24 +++- .../CubismHarmonicMotionComponent.cpp | 24 +++- .../LipSync/CubismLipSyncComponent.cpp | 24 +++- .../Effects/LookAt/CubismLookAtComponent.cpp | 24 +++- .../Raycast/CubismRaycastComponent.cpp | 24 +++- .../Expression/CubismExpressionComponent.cpp | 25 +++- .../Private/Model/CubismDrawableComponent.cpp | 24 +++- .../Private/Model/CubismModelComponent.cpp | 124 +++++++++++++++++- .../Model/CubismParameterComponent.cpp | 24 +++- .../Model/CubismParameterStoreComponent.cpp | 40 +++++- .../Private/Model/CubismPartComponent.cpp | 24 +++- .../Private/Motion/CubismMotionComponent.cpp | 24 +++- .../Physics/CubismPhysicsComponent.cpp | 24 +++- .../Private/Pose/CubismPoseComponent.cpp | 24 +++- .../Rendering/CubismMaskTextureComponent.cpp | 49 +++++-- .../Rendering/CubismRendererComponent.cpp | 102 +++++++++----- .../EyeBlink/CubismEyeBlinkComponent.h | 1 + .../CubismHarmonicMotionComponent.h | 2 + .../Effects/LipSync/CubismLipSyncComponent.h | 2 + .../Effects/LookAt/CubismLookAtComponent.h | 2 + .../Effects/Raycast/CubismRaycastComponent.h | 2 + .../Expression/CubismExpressionComponent.h | 4 +- .../Public/Model/CubismDrawableComponent.h | 4 + .../Public/Model/CubismModelComponent.h | 49 ++++++- .../Public/Model/CubismParameterComponent.h | 3 + .../Model/CubismParameterStoreComponent.h | 2 + .../Public/Model/CubismPartComponent.h | 2 + .../Public/Motion/CubismMotionComponent.h | 4 +- .../Public/Physics/CubismPhysicsComponent.h | 4 +- .../Public/Pose/CubismPoseComponent.h | 4 +- .../Rendering/CubismMaskTextureComponent.h | 9 +- .../Rendering/CubismRendererComponent.h | 9 +- 32 files changed, 600 insertions(+), 107 deletions(-) diff --git a/Source/Live2DCubismFramework/Private/Effects/EyeBlink/CubismEyeBlinkComponent.cpp b/Source/Live2DCubismFramework/Private/Effects/EyeBlink/CubismEyeBlinkComponent.cpp index 42f6f10..e65817b 100644 --- a/Source/Live2DCubismFramework/Private/Effects/EyeBlink/CubismEyeBlinkComponent.cpp +++ b/Source/Live2DCubismFramework/Private/Effects/EyeBlink/CubismEyeBlinkComponent.cpp @@ -52,14 +52,27 @@ void UCubismEyeBlinkComponent::Setup(UCubismModelComponent* InModel) Model->AddTickPrerequisiteComponent(this); // model ticks after parameters are updated by components } +TObjectPtr UCubismEyeBlinkComponent::GetModel() +{ + if (TObjectPtr ModelComp = Cast(GetOwner()->FindComponentByClass())) + { + return ModelComp; + } + + return nullptr; +} + // UObject interface void UCubismEyeBlinkComponent::PostLoad() { Super::PostLoad(); - const ACubismModel* Owner = Cast(GetOwner()); + const TObjectPtr ModelComp = GetModel(); - Setup(Owner->Model); + if (ModelComp) + { + Setup(ModelComp); + } } #if WITH_EDITOR @@ -118,9 +131,12 @@ void UCubismEyeBlinkComponent::OnComponentCreated() { Super::OnComponentCreated(); - const ACubismModel* Owner = Cast(GetOwner()); + const TObjectPtr ModelComp = GetModel(); - Setup(Owner->Model); + if (ModelComp) + { + Setup(ModelComp); + } } void UCubismEyeBlinkComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) diff --git a/Source/Live2DCubismFramework/Private/Effects/HarmonicMotion/CubismHarmonicMotionComponent.cpp b/Source/Live2DCubismFramework/Private/Effects/HarmonicMotion/CubismHarmonicMotionComponent.cpp index 1cbe9a7..7903044 100644 --- a/Source/Live2DCubismFramework/Private/Effects/HarmonicMotion/CubismHarmonicMotionComponent.cpp +++ b/Source/Live2DCubismFramework/Private/Effects/HarmonicMotion/CubismHarmonicMotionComponent.cpp @@ -41,14 +41,27 @@ void UCubismHarmonicMotionComponent::Setup(UCubismModelComponent* InModel) Model->AddTickPrerequisiteComponent(this); // model ticks after parameters are updated by components } +TObjectPtr UCubismHarmonicMotionComponent::GetModel() +{ + if (TObjectPtr ModelComp = Cast(GetOwner()->FindComponentByClass())) + { + return ModelComp; + } + + return nullptr; +} + // UObject interface void UCubismHarmonicMotionComponent::PostLoad() { Super::PostLoad(); - const ACubismModel* Owner = Cast(GetOwner()); + const TObjectPtr ModelComp = GetModel(); - Setup(Owner->Model); + if (ModelComp) + { + Setup(ModelComp); + } } // End of UObject interface @@ -57,9 +70,12 @@ void UCubismHarmonicMotionComponent::OnComponentCreated() { Super::OnComponentCreated(); - const ACubismModel* Owner = Cast(GetOwner()); + const TObjectPtr ModelComp = GetModel(); - Setup(Owner->Model); + if (ModelComp) + { + Setup(ModelComp); + } } void UCubismHarmonicMotionComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) diff --git a/Source/Live2DCubismFramework/Private/Effects/LipSync/CubismLipSyncComponent.cpp b/Source/Live2DCubismFramework/Private/Effects/LipSync/CubismLipSyncComponent.cpp index 4309d6e..4875fb2 100644 --- a/Source/Live2DCubismFramework/Private/Effects/LipSync/CubismLipSyncComponent.cpp +++ b/Source/Live2DCubismFramework/Private/Effects/LipSync/CubismLipSyncComponent.cpp @@ -119,14 +119,27 @@ TObjectPtr UCubismLipSyncComponent::CreateAudioComponent() return NewAudio; } +TObjectPtr UCubismLipSyncComponent::GetModel() +{ + if (TObjectPtr ModelComp = Cast(GetOwner()->FindComponentByClass())) + { + return ModelComp; + } + + return nullptr; +} + // UObject interface void UCubismLipSyncComponent::PostLoad() { Super::PostLoad(); - const ACubismModel* Owner = Cast(GetOwner()); + const TObjectPtr ModelComp = GetModel(); - Setup(Owner->Model); + if (ModelComp) + { + Setup(ModelComp); + } } #if WITH_EDITOR @@ -199,9 +212,12 @@ void UCubismLipSyncComponent::OnComponentCreated() { Super::OnComponentCreated(); - const ACubismModel* Owner = Cast(GetOwner()); + const TObjectPtr ModelComp = GetModel(); - Setup(Owner->Model); + if (ModelComp) + { + Setup(ModelComp); + } } void UCubismLipSyncComponent::OnComponentDestroyed(bool bDestroyingHierarchy) diff --git a/Source/Live2DCubismFramework/Private/Effects/LookAt/CubismLookAtComponent.cpp b/Source/Live2DCubismFramework/Private/Effects/LookAt/CubismLookAtComponent.cpp index 95b5366..1d6e832 100644 --- a/Source/Live2DCubismFramework/Private/Effects/LookAt/CubismLookAtComponent.cpp +++ b/Source/Live2DCubismFramework/Private/Effects/LookAt/CubismLookAtComponent.cpp @@ -44,14 +44,27 @@ void UCubismLookAtComponent::Setup(UCubismModelComponent* InModel) Model->AddTickPrerequisiteComponent(this); // model ticks after parameters are updated by components } +TObjectPtr UCubismLookAtComponent::GetModel() +{ + if (TObjectPtr ModelComp = Cast(GetOwner()->FindComponentByClass())) + { + return ModelComp; + } + + return nullptr; +} + // UObject interface void UCubismLookAtComponent::PostLoad() { Super::PostLoad(); - const ACubismModel* Owner = Cast(GetOwner()); + const TObjectPtr ModelComp = GetModel(); - Setup(Owner->Model); + if (ModelComp) + { + Setup(ModelComp); + } } // End of UObject interface @@ -60,9 +73,12 @@ void UCubismLookAtComponent::OnComponentCreated() { Super::OnComponentCreated(); - const ACubismModel* Owner = Cast(GetOwner()); + const TObjectPtr ModelComp = GetModel(); - Setup(Owner->Model); + if (ModelComp) + { + Setup(ModelComp); + } } void UCubismLookAtComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) diff --git a/Source/Live2DCubismFramework/Private/Effects/Raycast/CubismRaycastComponent.cpp b/Source/Live2DCubismFramework/Private/Effects/Raycast/CubismRaycastComponent.cpp index 37ccefa..b54e632 100644 --- a/Source/Live2DCubismFramework/Private/Effects/Raycast/CubismRaycastComponent.cpp +++ b/Source/Live2DCubismFramework/Private/Effects/Raycast/CubismRaycastComponent.cpp @@ -224,14 +224,27 @@ bool UCubismRaycastComponent::RayIntersectTriangle return true; } +TObjectPtr UCubismRaycastComponent::GetModel() +{ + if (TObjectPtr ModelComp = Cast(GetOwner()->FindComponentByClass())) + { + return ModelComp; + } + + return nullptr; +} + // UObject interface void UCubismRaycastComponent::PostLoad() { Super::PostLoad(); - const ACubismModel* Owner = Cast(GetOwner()); + const TObjectPtr ModelComp = GetModel(); - Setup(Owner->Model); + if (ModelComp) + { + Setup(ModelComp); + } } // End of UObject interface @@ -240,8 +253,11 @@ void UCubismRaycastComponent::OnComponentCreated() { Super::OnComponentCreated(); - const ACubismModel* Owner = Cast(GetOwner()); + const TObjectPtr ModelComp = GetModel(); - Setup(Owner->Model); + if (ModelComp) + { + Setup(ModelComp); + } } // End of UActorComponent interface diff --git a/Source/Live2DCubismFramework/Private/Expression/CubismExpressionComponent.cpp b/Source/Live2DCubismFramework/Private/Expression/CubismExpressionComponent.cpp index d5cdb25..ea3c5b1 100644 --- a/Source/Live2DCubismFramework/Private/Expression/CubismExpressionComponent.cpp +++ b/Source/Live2DCubismFramework/Private/Expression/CubismExpressionComponent.cpp @@ -82,14 +82,28 @@ void UCubismExpressionComponent::StopAllExpressions(const bool bForce) } } +TObjectPtr UCubismExpressionComponent::GetModel() +{ + if (TObjectPtr ModelComp = Cast(GetOwner()->FindComponentByClass())) + { + return ModelComp; + } + + return nullptr; +} + + // UObject interface void UCubismExpressionComponent::PostLoad() { Super::PostLoad(); - const ACubismModel* Owner = Cast(GetOwner()); + const TObjectPtr ModelComp = GetModel(); - Setup(Owner->Model); + if (ModelComp) + { + Setup(ModelComp); + } } #if WITH_EDITOR @@ -119,9 +133,12 @@ void UCubismExpressionComponent::OnComponentCreated() { Super::OnComponentCreated(); - const ACubismModel* Owner = Cast(GetOwner()); + const TObjectPtr ModelComp = GetModel(); - Setup(Owner->Model); + if (ModelComp) + { + Setup(ModelComp); + } } void UCubismExpressionComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) diff --git a/Source/Live2DCubismFramework/Private/Model/CubismDrawableComponent.cpp b/Source/Live2DCubismFramework/Private/Model/CubismDrawableComponent.cpp index aef0781..2904039 100644 --- a/Source/Live2DCubismFramework/Private/Model/CubismDrawableComponent.cpp +++ b/Source/Live2DCubismFramework/Private/Model/CubismDrawableComponent.cpp @@ -187,14 +187,27 @@ int32 UCubismDrawableComponent::GetDrawableMaskCount() const return Model->GetDrawableMaskCount(Index); } +TObjectPtr UCubismDrawableComponent::GetModel() +{ + if (TObjectPtr ModelComp = Cast(GetOwner()->FindComponentByClass())) + { + return ModelComp; + } + + return nullptr; +} + // UObject interface void UCubismDrawableComponent::PostLoad() { Super::PostLoad(); - const ACubismModel* Owner = Cast(GetOwner()); + const TObjectPtr ModelComp = GetModel(); - Setup(Owner->Model); + if (ModelComp) + { + Setup(ModelComp); + } } #if WITH_EDITOR @@ -269,9 +282,12 @@ void UCubismDrawableComponent::OnComponentCreated() { Super::OnComponentCreated(); - const ACubismModel* Owner = Cast(GetOwner()); + const TObjectPtr ModelComp = GetModel(); - Setup(Owner->Model); + if (ModelComp) + { + Setup(ModelComp); + } } void UCubismDrawableComponent::SendRenderDynamicData_Concurrent() diff --git a/Source/Live2DCubismFramework/Private/Model/CubismModelComponent.cpp b/Source/Live2DCubismFramework/Private/Model/CubismModelComponent.cpp index 17be99e..c16d3a3 100644 --- a/Source/Live2DCubismFramework/Private/Model/CubismModelComponent.cpp +++ b/Source/Live2DCubismFramework/Private/Model/CubismModelComponent.cpp @@ -13,6 +13,12 @@ #include "Model/CubismParameterComponent.h" #include "Model/CubismPartComponent.h" #include "UserData/CubismUserData3Json.h" +#include "Model/CubismParameterStoreComponent.h" +#include "Rendering/CubismRendererComponent.h" +#include "Pose/CubismPoseComponent.h" +#include "Motion/CubismMotionComponent.h" +#include "Expression/CubismExpressionComponent.h" +#include "Physics/CubismPhysicsComponent.h" #include "CubismLog.h" @@ -29,6 +35,12 @@ UCubismModelComponent::~UCubismModelComponent() void UCubismModelComponent::Setup() { + + if (!Moc) + { + return; + } + check(Moc); Moc->SetupModel(this); @@ -564,10 +576,21 @@ void UCubismModelComponent::OnComponentCreated() { Super::OnComponentCreated(); + if (!Moc) + { + return; + } + check(Moc); Moc->SetupModel(this); + //Need to ensure that the model is cleaned up before it can be created + if (NonNativeParameterIds.Num() > 0) + { + ComponentCleanup(); + } + { const int32 DrawableCount = csmGetDrawableCount(RawModel); Drawables.Reserve(DrawableCount); @@ -626,12 +649,97 @@ void UCubismModelComponent::OnComponentCreated() Parts.Add(Part); } } + + Setup(); + ComponentSetup(); } -void UCubismModelComponent::OnComponentDestroyed(bool bDestroyingHierarchy) +void UCubismModelComponent::ComponentSetup() +{ + //Setting up the Store Component + if (!ParameterStore) + { + ParameterStore = NewObject(this, UCubismParameterStoreComponent::StaticClass()); + ParameterStore->RegisterComponent(); + } + + + //Setting up the renderer Component + if (!Renderer) + { + Renderer = NewObject(this, UCubismRendererComponent::StaticClass()); + Renderer->RegisterComponent(); + } + + + //Setting up the pose component + if (!Pose) + { + Pose = NewObject(this, UCubismPoseComponent::StaticClass()); + if (PoseJson) + { + Pose->Json = PoseJson; + } + Pose->RegisterComponent(); + } + + + //Setting up the motion component + if (!Motion) + { + Motion = NewObject(this, UCubismMotionComponent::StaticClass()); + + if (MotionJsons.Num() > 0) + { + Motion->Jsons = MotionJsons; + } + + Motion->RegisterComponent(); + + if (MotionJsons.Num() > 0) + { + if (MotionJsons[0]) + { + Motion->PlayMotion(0, 0.0f, ECubismMotionPriority::Idle); + } + } + } + + //Setting up the expression component + if (!Expression) + { + Expression = NewObject(this, UCubismExpressionComponent::StaticClass()); + + if (ExpressionJsons.Num() > 0) + { + Expression->Jsons = ExpressionJsons; + } + + Expression->RegisterComponent(); + } + + //Setting up the physics component + if (!Physics) + { + Physics = NewObject(this, UCubismPhysicsComponent::StaticClass()); + + if (PhysicsJson) + { + Physics->Json = PhysicsJson; + } + + Physics->RegisterComponent(); + } +} + +void UCubismModelComponent::ComponentCleanup() { for (const TObjectPtr& Drawable : Drawables) { + if (!Drawable) + { + continue; + } Drawable->DetachFromComponent(FDetachmentTransformRules::KeepRelativeTransform); GetOwner()->RemoveInstanceComponent(Drawable); Drawable->DestroyComponent(); @@ -639,11 +747,19 @@ void UCubismModelComponent::OnComponentDestroyed(bool bDestroyingHierarchy) for (const TObjectPtr& Parameter : Parameters) { + if (!Parameter) + { + continue; + } Parameter->DestroyComponent(); } for (const TObjectPtr& Part : Parts) { + if (!Part) + { + continue; + } Part->DestroyComponent(); } @@ -654,6 +770,12 @@ void UCubismModelComponent::OnComponentDestroyed(bool bDestroyingHierarchy) DrawableIndices.Empty(); ParameterIndices.Empty(); PartIndices.Empty(); + NonNativeParameterIds.Empty(); +} + +void UCubismModelComponent::OnComponentDestroyed(bool bDestroyingHierarchy) +{ + ComponentCleanup(); Moc->DeleteModel(this); diff --git a/Source/Live2DCubismFramework/Private/Model/CubismParameterComponent.cpp b/Source/Live2DCubismFramework/Private/Model/CubismParameterComponent.cpp index f603187..15dcc10 100644 --- a/Source/Live2DCubismFramework/Private/Model/CubismParameterComponent.cpp +++ b/Source/Live2DCubismFramework/Private/Model/CubismParameterComponent.cpp @@ -98,14 +98,27 @@ void UCubismParameterComponent::MultiplyParameterValue(float TargetValue, const Model->SetParameterValue(Index, CurrentValue); } +TObjectPtr UCubismParameterComponent::GetModel() +{ + if (TObjectPtr ModelComp = Cast(GetOwner()->FindComponentByClass())) + { + return ModelComp; + } + + return nullptr; +} + // UObject interface void UCubismParameterComponent::PostLoad() { Super::PostLoad(); - const ACubismModel* Owner = Cast(GetOwner()); + const TObjectPtr ModelComp = GetModel(); - Setup(Owner->Model); + if (ModelComp) + { + Setup(ModelComp); + } } #if WITH_EDITOR @@ -133,8 +146,11 @@ void UCubismParameterComponent::OnComponentCreated() { Super::OnComponentCreated(); - const ACubismModel* Owner = Cast(GetOwner()); + const TObjectPtr ModelComp = GetModel(); - Setup(Owner->Model); + if (ModelComp) + { + Setup(ModelComp); + } } // End of UActorComponent interface diff --git a/Source/Live2DCubismFramework/Private/Model/CubismParameterStoreComponent.cpp b/Source/Live2DCubismFramework/Private/Model/CubismParameterStoreComponent.cpp index 209cc43..d9b8c68 100644 --- a/Source/Live2DCubismFramework/Private/Model/CubismParameterStoreComponent.cpp +++ b/Source/Live2DCubismFramework/Private/Model/CubismParameterStoreComponent.cpp @@ -85,6 +85,10 @@ void UCubismParameterStoreComponent::LoadParameters() { for (const TObjectPtr& Parameter : Model->Parameters) { + if (!Parameter) + { + continue; + } if (ParameterValues.Contains(Parameter->Index)) { Parameter->SetParameterValue(ParameterValues[Parameter->Index]); @@ -97,6 +101,10 @@ void UCubismParameterStoreComponent::LoadParameters() for (const TObjectPtr& Part : Model->Parts) { + if (!Part) + { + continue; + } if (PartOpacities.Contains(Part->Index)) { Part->SetPartOpacity(PartOpacities[Part->Index]); @@ -108,14 +116,27 @@ void UCubismParameterStoreComponent::LoadParameters() } } +TObjectPtr UCubismParameterStoreComponent::GetModel() +{ + if (TObjectPtr ModelComp = Cast(GetOwner()->FindComponentByClass())) + { + return ModelComp; + } + + return nullptr; +} + // UObject interface void UCubismParameterStoreComponent::PostLoad() { Super::PostLoad(); - const ACubismModel* Owner = Cast(GetOwner()); + const TObjectPtr ModelComp = GetModel(); - Setup(Owner->Model); + if (ModelComp) + { + Setup(ModelComp); + } } // End of UObject interface @@ -124,18 +145,25 @@ void UCubismParameterStoreComponent::OnComponentCreated() { Super::OnComponentCreated(); - const ACubismModel* Owner = Cast(GetOwner()); + const TObjectPtr ModelComp = GetModel(); - Setup(Owner->Model); + if (ModelComp) + { + Setup(ModelComp); + } } void UCubismParameterStoreComponent::OnComponentDestroyed(bool bDestroyingHierarchy) { - if (Model->ParameterStore == this) + if (Model) { - Model->ParameterStore = nullptr; + if (Model->ParameterStore == this) + { + Model->ParameterStore = nullptr; + } } + Super::OnComponentDestroyed(bDestroyingHierarchy); } diff --git a/Source/Live2DCubismFramework/Private/Model/CubismPartComponent.cpp b/Source/Live2DCubismFramework/Private/Model/CubismPartComponent.cpp index d91e0e8..0495978 100644 --- a/Source/Live2DCubismFramework/Private/Model/CubismPartComponent.cpp +++ b/Source/Live2DCubismFramework/Private/Model/CubismPartComponent.cpp @@ -51,14 +51,27 @@ void UCubismPartComponent::SetPartOpacity(float TargetOpacity) Model->SetPartOpacity(Index, Opacity); } +TObjectPtr UCubismPartComponent::GetModel() +{ + if (TObjectPtr ModelComp = Cast(GetOwner()->FindComponentByClass())) + { + return ModelComp; + } + + return nullptr; +} + // UObject interface void UCubismPartComponent::PostLoad() { Super::PostLoad(); - const ACubismModel* Owner = Cast(GetOwner()); + const TObjectPtr ModelComp = GetModel(); - Setup(Owner->Model); + if (ModelComp) + { + Setup(ModelComp); + } } #if WITH_EDITOR @@ -86,8 +99,11 @@ void UCubismPartComponent::OnComponentCreated() { Super::OnComponentCreated(); - const ACubismModel* Owner = Cast(GetOwner()); + const TObjectPtr ModelComp = GetModel(); - Setup(Owner->Model); + if (ModelComp) + { + Setup(ModelComp); + } } // End of UActorComponent interface diff --git a/Source/Live2DCubismFramework/Private/Motion/CubismMotionComponent.cpp b/Source/Live2DCubismFramework/Private/Motion/CubismMotionComponent.cpp index da7396f..3ba8bb5 100644 --- a/Source/Live2DCubismFramework/Private/Motion/CubismMotionComponent.cpp +++ b/Source/Live2DCubismFramework/Private/Motion/CubismMotionComponent.cpp @@ -115,14 +115,27 @@ void UCubismMotionComponent::StopAllMotions(const bool bForce) } } +TObjectPtr UCubismMotionComponent::GetModel() +{ + if (TObjectPtr ModelComp = Cast(GetOwner()->FindComponentByClass())) + { + return ModelComp; + } + + return nullptr; +} + // UObject interface void UCubismMotionComponent::PostLoad() { Super::PostLoad(); - const ACubismModel* Owner = Cast(GetOwner()); + const TObjectPtr ModelComp = GetModel(); - Setup(Owner->Model); + if (ModelComp) + { + Setup(ModelComp); + } } #if WITH_EDITOR @@ -145,9 +158,12 @@ void UCubismMotionComponent::OnComponentCreated() { Super::OnComponentCreated(); - const ACubismModel* Owner = Cast(GetOwner()); + const TObjectPtr ModelComp = GetModel(); - Setup(Owner->Model); + if (ModelComp) + { + Setup(ModelComp); + } } void UCubismMotionComponent::OnComponentDestroyed(bool bDestroyingHierarchy) diff --git a/Source/Live2DCubismFramework/Private/Physics/CubismPhysicsComponent.cpp b/Source/Live2DCubismFramework/Private/Physics/CubismPhysicsComponent.cpp index 3593288..2258224 100644 --- a/Source/Live2DCubismFramework/Private/Physics/CubismPhysicsComponent.cpp +++ b/Source/Live2DCubismFramework/Private/Physics/CubismPhysicsComponent.cpp @@ -298,14 +298,27 @@ void UCubismPhysicsComponent::UpdateParticlesForStabilization( } } +TObjectPtr UCubismPhysicsComponent::GetModel() +{ + if (TObjectPtr ModelComp = Cast(GetOwner()->FindComponentByClass())) + { + return ModelComp; + } + + return nullptr; +} + // UObject interface void UCubismPhysicsComponent::PostLoad() { Super::PostLoad(); - const ACubismModel* Owner = Cast(GetOwner()); + const TObjectPtr ModelComp = GetModel(); - Setup(Owner->Model); + if (ModelComp) + { + Setup(ModelComp); + } } #if WITH_EDITOR @@ -328,9 +341,12 @@ void UCubismPhysicsComponent::OnComponentCreated() { Super::OnComponentCreated(); - const ACubismModel* Owner = Cast(GetOwner()); + const TObjectPtr ModelComp = GetModel(); - Setup(Owner->Model); + if (ModelComp) + { + Setup(ModelComp); + } } void UCubismPhysicsComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) diff --git a/Source/Live2DCubismFramework/Private/Pose/CubismPoseComponent.cpp b/Source/Live2DCubismFramework/Private/Pose/CubismPoseComponent.cpp index 1d49640..a3938bb 100644 --- a/Source/Live2DCubismFramework/Private/Pose/CubismPoseComponent.cpp +++ b/Source/Live2DCubismFramework/Private/Pose/CubismPoseComponent.cpp @@ -91,14 +91,27 @@ void UCubismPoseComponent::Setup(UCubismModelComponent* InModel) AddTickPrerequisiteComponent(Model->Motion); // must be updated at first because motions overwrite parameters } +TObjectPtr UCubismPoseComponent::GetModel() +{ + if (TObjectPtr ModelComp = Cast(GetOwner()->FindComponentByClass())) + { + return ModelComp; + } + + return nullptr; +} + // UObject interface void UCubismPoseComponent::PostLoad() { Super::PostLoad(); - ACubismModel* Owner = Cast(GetOwner()); + const TObjectPtr ModelComp = GetModel(); - Setup(Owner->Model); + if (ModelComp) + { + Setup(ModelComp); + } } #if WITH_EDITOR @@ -121,9 +134,12 @@ void UCubismPoseComponent::OnComponentCreated() { Super::OnComponentCreated(); - ACubismModel* Owner = Cast(GetOwner()); + const TObjectPtr ModelComp = GetModel(); - Setup(Owner->Model); + if (ModelComp) + { + Setup(ModelComp); + } } void UCubismPoseComponent::DoFade(float DeltaTime) diff --git a/Source/Live2DCubismFramework/Private/Rendering/CubismMaskTextureComponent.cpp b/Source/Live2DCubismFramework/Private/Rendering/CubismMaskTextureComponent.cpp index 5035143..c96d60c 100644 --- a/Source/Live2DCubismFramework/Private/Rendering/CubismMaskTextureComponent.cpp +++ b/Source/Live2DCubismFramework/Private/Rendering/CubismMaskTextureComponent.cpp @@ -22,7 +22,7 @@ UCubismMaskTextureComponent::UCubismMaskTextureComponent() bTickInEditor = true; } -void UCubismMaskTextureComponent::AddModel(ACubismModel* Model) +void UCubismMaskTextureComponent::AddModel(AActor* Model) { Models.AddUnique(Model); @@ -37,7 +37,7 @@ void UCubismMaskTextureComponent::AddModel(ACubismModel* Model) bDirty = true; } -void UCubismMaskTextureComponent::RemoveModel(ACubismModel* Model) +void UCubismMaskTextureComponent::RemoveModel(AActor* Model) { Models.Remove(Model); @@ -55,11 +55,18 @@ void UCubismMaskTextureComponent::RemoveModel(ACubismModel* Model) void UCubismMaskTextureComponent::ResolveMaskLayout() { NumMasks = 0; - for (const TObjectPtr& ModelActor : Models) + for (const TObjectPtr& ModelActor : Models) { + const TObjectPtr ModelComp = GetModel(ModelActor); + + if (!ModelComp) + { + continue; + } + if (IsValid(ModelActor)) { - NumMasks += ModelActor->Model->Renderer->NumMasks; + NumMasks += ModelComp->Renderer->NumMasks; } } @@ -74,14 +81,20 @@ void UCubismMaskTextureComponent::ResolveMaskLayout() AllocateRenderTargets(RenderTargetCount); int32 Index = 0; - for (const TObjectPtr& ModelActor : Models) + for (const TObjectPtr& ModelActor : Models) { if (!IsValid(ModelActor)) { continue; } + const TObjectPtr ModelComp = GetModel(ModelActor); - for (const TSharedPtr& Junction : ModelActor->Model->Renderer->Junctions) + if (!ModelComp) + { + continue; + } + + for (const TSharedPtr& Junction : ModelComp->Renderer->Junctions) { if (Junction->MaskDrawables.Num() == 0) { @@ -122,7 +135,7 @@ void UCubismMaskTextureComponent::ResolveMaskLayout() 2.0f * Column + 1.0f, 2.0f * Row + 1.0f, 0.5f / Resolution, - 100.0f / ModelActor->Model->GetPixelsPerUnit() + 100.0f / ModelComp->GetPixelsPerUnit() ); if (Channel%4 == 0) @@ -175,6 +188,16 @@ void UCubismMaskTextureComponent::AllocateRenderTargets(const int32 RequiredRTs) } } +TObjectPtr UCubismMaskTextureComponent::GetModel(AActor* Model) +{ + if (TObjectPtr ModelComp = Cast(Model->FindComponentByClass())) + { + return ModelComp; + } + + return nullptr; +} + // UObject interface #if WITH_EDITOR void UCubismMaskTextureComponent::PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent) @@ -243,16 +266,22 @@ void UCubismMaskTextureComponent::TickComponent(float DeltaTime, ELevelTick Tick TArray MaskDrawInfos; - for (const TObjectPtr& ModelActor : Models) + for (const TObjectPtr& ModelActor : Models) { if (!IsValid(ModelActor)) { continue; } + const TObjectPtr ModelComp = GetModel(ModelActor); + + if (!ModelComp) + { + continue; + } - const TArray>& Textures = ModelActor->Model->Textures; + const TArray>& Textures = ModelComp->Textures; - for (const TSharedPtr& Junction : ModelActor->Model->Renderer->Junctions) + for (const TSharedPtr& Junction : ModelComp->Renderer->Junctions) { // If the render target does not match, skip drawing the mask. if (Junction->RenderTarget != RenderTarget) diff --git a/Source/Live2DCubismFramework/Private/Rendering/CubismRendererComponent.cpp b/Source/Live2DCubismFramework/Private/Rendering/CubismRendererComponent.cpp index 4627020..a5765cf 100644 --- a/Source/Live2DCubismFramework/Private/Rendering/CubismRendererComponent.cpp +++ b/Source/Live2DCubismFramework/Private/Rendering/CubismRendererComponent.cpp @@ -26,6 +26,13 @@ UCubismRendererComponent::UCubismRendererComponent() bTickInEditor = true; } +void UCubismRendererComponent::BeginPlay() +{ + Super::BeginPlay(); + + SpawnMaskTexture(); +} + void UCubismRendererComponent::Setup(UCubismModelComponent* InModel) { check(InModel); @@ -94,10 +101,10 @@ void UCubismRendererComponent::Setup(UCubismModelComponent* InModel) if (MaskTexture) { MaskTexture->MaskTextureComponent->ResolveMaskLayout(); + AddTickPrerequisiteComponent(MaskTexture->MaskTextureComponent); // must render after mask texture updated } AddTickPrerequisiteComponent(Model); // must render after model updated - AddTickPrerequisiteComponent(MaskTexture->MaskTextureComponent); // must render after mask texture updated } void UCubismRendererComponent::ApplyRenderOrder() @@ -140,14 +147,60 @@ void UCubismRendererComponent::ApplyRenderOrder() } } +void UCubismRendererComponent::SpawnMaskTexture() +{ + AActor* Owner = GetOwner(); + + if (MaskTexture == nullptr) + { + TArray FoundActors; + UGameplayStatics::GetAllActorsOfClass(Owner->GetWorld(), ACubismMaskTexture::StaticClass(), FoundActors); + if (FoundActors.Num() == 0) + { + MaskTexture = Owner->GetWorld()->SpawnActor(); + } + else + { + MaskTexture = (ACubismMaskTexture*)FoundActors[0]; + } + } + else + { + MaskTexture->MaskTextureComponent->RemoveModel(Owner); + } + //Should check in case it's spawned in blueprint and the mask texture won't be placed in the blueprint scene + if (MaskTexture) + { +#if WITH_EDITOR + MaskTexture->SetActorLabel(TEXT("CubismMaskTexture")); + MaskTexture->SetFlags(RF_Transactional); +#endif + MaskTexture->MaskTextureComponent->AddModel(Owner); + } +} + + +TObjectPtr UCubismRendererComponent::GetModel() +{ + if (TObjectPtr ModelComp = Cast(GetOwner()->FindComponentByClass())) + { + return ModelComp; + } + + return nullptr; +} + // UObject interface void UCubismRendererComponent::PostLoad() { Super::PostLoad(); - const ACubismModel* Owner = Cast(GetOwner()); + const TObjectPtr ModelComp = GetModel(); - Setup(Owner->Model); + if (ModelComp) + { + Setup(ModelComp); + } } #if WITH_EDITOR @@ -161,7 +214,7 @@ void UCubismRendererComponent::PostEditChangeProperty(FPropertyChangedEvent& Pro { if (MaskTexture) { - ACubismModel* Owner = Cast(GetOwner()); + AActor* Owner = GetOwner(); MaskTexture->MaskTextureComponent->AddModel(Owner); } @@ -184,49 +237,36 @@ void UCubismRendererComponent::OnComponentCreated() { Super::OnComponentCreated(); - ACubismModel* Owner = Cast(GetOwner()); - - if (MaskTexture == nullptr) + if (GetWorld()->WorldType != EWorldType::EditorPreview) { - TArray FoundActors; - UGameplayStatics::GetAllActorsOfClass(Owner->GetWorld(), ACubismMaskTexture::StaticClass(), FoundActors); - if (FoundActors.Num() == 0) - { - MaskTexture = Owner->GetWorld()->SpawnActor(); - #if WITH_EDITOR - MaskTexture->SetActorLabel(TEXT("CubismMaskTexture")); - MaskTexture->SetFlags(RF_Transactional); - #endif - } - else - { - MaskTexture = (ACubismMaskTexture*) FoundActors[0]; - } - } - else - { - MaskTexture->MaskTextureComponent->RemoveModel(Owner); + SpawnMaskTexture(); } - MaskTexture->MaskTextureComponent->AddModel(Owner); + const TObjectPtr ModelComp = GetModel(); - Setup(Owner->Model); + if (ModelComp) + { + Setup(ModelComp); + } } void UCubismRendererComponent::OnComponentDestroyed(bool bDestroyingHierarchy) { if (MaskTexture) { - ACubismModel* Owner = Cast(GetOwner()); + AActor* Owner = GetOwner(); MaskTexture->MaskTextureComponent->RemoveModel(Owner); } - - if (Model->Renderer == this) + if (Model) { - Model->Renderer = nullptr; + if (Model->Renderer == this) + { + Model->Renderer = nullptr; + } } + Super::OnComponentDestroyed(bDestroyingHierarchy); } diff --git a/Source/Live2DCubismFramework/Public/Effects/EyeBlink/CubismEyeBlinkComponent.h b/Source/Live2DCubismFramework/Public/Effects/EyeBlink/CubismEyeBlinkComponent.h index e367314..9b95286 100644 --- a/Source/Live2DCubismFramework/Public/Effects/EyeBlink/CubismEyeBlinkComponent.h +++ b/Source/Live2DCubismFramework/Public/Effects/EyeBlink/CubismEyeBlinkComponent.h @@ -117,6 +117,7 @@ class LIVE2DCUBISMFRAMEWORK_API UCubismEyeBlinkComponent : public UActorComponen */ UCubismEyeBlinkComponent(); + TObjectPtr GetModel(); /** * The model component that the component depends on. */ diff --git a/Source/Live2DCubismFramework/Public/Effects/HarmonicMotion/CubismHarmonicMotionComponent.h b/Source/Live2DCubismFramework/Public/Effects/HarmonicMotion/CubismHarmonicMotionComponent.h index 18236f2..158decf 100644 --- a/Source/Live2DCubismFramework/Public/Effects/HarmonicMotion/CubismHarmonicMotionComponent.h +++ b/Source/Live2DCubismFramework/Public/Effects/HarmonicMotion/CubismHarmonicMotionComponent.h @@ -43,6 +43,8 @@ class LIVE2DCUBISMFRAMEWORK_API UCubismHarmonicMotionComponent : public UActorCo */ UCubismHarmonicMotionComponent(); + TObjectPtr GetModel(); + /** * The model component that the component depends on. */ diff --git a/Source/Live2DCubismFramework/Public/Effects/LipSync/CubismLipSyncComponent.h b/Source/Live2DCubismFramework/Public/Effects/LipSync/CubismLipSyncComponent.h index b4c52c4..a14940c 100644 --- a/Source/Live2DCubismFramework/Public/Effects/LipSync/CubismLipSyncComponent.h +++ b/Source/Live2DCubismFramework/Public/Effects/LipSync/CubismLipSyncComponent.h @@ -109,6 +109,8 @@ class LIVE2DCUBISMFRAMEWORK_API UCubismLipSyncComponent : public UActorComponent */ UCubismLipSyncComponent(); + TObjectPtr GetModel(); + /** * The model component that the component depends on. */ diff --git a/Source/Live2DCubismFramework/Public/Effects/LookAt/CubismLookAtComponent.h b/Source/Live2DCubismFramework/Public/Effects/LookAt/CubismLookAtComponent.h index 6d37d32..f44f107 100644 --- a/Source/Live2DCubismFramework/Public/Effects/LookAt/CubismLookAtComponent.h +++ b/Source/Live2DCubismFramework/Public/Effects/LookAt/CubismLookAtComponent.h @@ -55,6 +55,8 @@ class LIVE2DCUBISMFRAMEWORK_API UCubismLookAtComponent : public UActorComponent */ UCubismLookAtComponent(); + TObjectPtr GetModel(); + /** * The model component that the component depends on. */ diff --git a/Source/Live2DCubismFramework/Public/Effects/Raycast/CubismRaycastComponent.h b/Source/Live2DCubismFramework/Public/Effects/Raycast/CubismRaycastComponent.h index b2c009f..8726e4b 100644 --- a/Source/Live2DCubismFramework/Public/Effects/Raycast/CubismRaycastComponent.h +++ b/Source/Live2DCubismFramework/Public/Effects/Raycast/CubismRaycastComponent.h @@ -96,6 +96,8 @@ class LIVE2DCUBISMFRAMEWORK_API UCubismRaycastComponent : public UActorComponent */ UCubismRaycastComponent(); + TObjectPtr GetModel(); + /** * The model component that the component depends on. */ diff --git a/Source/Live2DCubismFramework/Public/Expression/CubismExpressionComponent.h b/Source/Live2DCubismFramework/Public/Expression/CubismExpressionComponent.h index 459ef8e..211d5c5 100644 --- a/Source/Live2DCubismFramework/Public/Expression/CubismExpressionComponent.h +++ b/Source/Live2DCubismFramework/Public/Expression/CubismExpressionComponent.h @@ -54,7 +54,7 @@ struct LIVE2DCUBISMFRAMEWORK_API FCubismExpressionParameterValue /** * A component to apply the expression motion to the specified parameters of the Cubism model. */ -UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) ) +UCLASS(Blueprintable) class LIVE2DCUBISMFRAMEWORK_API UCubismExpressionComponent : public UActorComponent { GENERATED_BODY() @@ -108,6 +108,8 @@ class LIVE2DCUBISMFRAMEWORK_API UCubismExpressionComponent : public UActorCompon */ UCubismExpressionComponent(); + TObjectPtr GetModel(); + /** * The model component that the component depends on. */ diff --git a/Source/Live2DCubismFramework/Public/Model/CubismDrawableComponent.h b/Source/Live2DCubismFramework/Public/Model/CubismDrawableComponent.h index 77e5c81..590cca3 100644 --- a/Source/Live2DCubismFramework/Public/Model/CubismDrawableComponent.h +++ b/Source/Live2DCubismFramework/Public/Model/CubismDrawableComponent.h @@ -202,6 +202,8 @@ class LIVE2DCUBISMFRAMEWORK_API UCubismDrawableComponent : public UMeshComponent */ UCubismDrawableComponent(); + TObjectPtr GetModel(); + /** * The model component that the component depends on. */ @@ -261,6 +263,8 @@ class LIVE2DCUBISMFRAMEWORK_API UCubismDrawableComponent : public UMeshComponent #endif // End of UObject interface + + // UActorComponent interface virtual void OnComponentCreated() override; diff --git a/Source/Live2DCubismFramework/Public/Model/CubismModelComponent.h b/Source/Live2DCubismFramework/Public/Model/CubismModelComponent.h index f244d06..e1e8c85 100644 --- a/Source/Live2DCubismFramework/Public/Model/CubismModelComponent.h +++ b/Source/Live2DCubismFramework/Public/Model/CubismModelComponent.h @@ -28,6 +28,10 @@ class UCubismEyeBlinkComponent; class UCubismHarmonicMotionComponent; class UCubismLipSyncComponent; class UCubismLookAtComponent; +class UCubismPose3Json; +class UCubismMotion3Json; +class UCubismExp3Json; +class UCubismPhysics3Json; /** * An enumeration for the blend mode of a drawable. @@ -64,18 +68,31 @@ enum class ECubismParameterType : uint8 /** * A component to control a Live2D Cubism model. */ -UCLASS(Blueprintable) +UCLASS(Blueprintable, meta = (BlueprintSpawnableComponent)) class LIVE2DCUBISMFRAMEWORK_API UCubismModelComponent : public USceneComponent { GENERATED_BODY() public: + /** * The moc asset that contains the model information. */ - UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Live2D Cubism") + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Live2D Cubism") TObjectPtr Moc; + /** + * The pose asset that contains the pose information. + */ + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Live2D Cubism") + TObjectPtr PoseJson; + + /** +* The pose asset that contains the motion information. +*/ + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Live2D Cubism") + TArray> MotionJsons; + /** * The list of drawable components that consist of the model. */ @@ -172,6 +189,18 @@ class LIVE2DCUBISMFRAMEWORK_API UCubismModelComponent : public USceneComponent UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Live2D Cubism") TObjectPtr UserDataJson; + /** +* The json assets that contain the expression information. +*/ + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Live2D Cubism") + TArray> ExpressionJsons; + + /** +* The json assets that contain the physics information. +*/ + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Live2D Cubism") + TObjectPtr PhysicsJson; + /** * The opacity of the model. */ @@ -357,7 +386,7 @@ class LIVE2DCUBISMFRAMEWORK_API UCubismModelComponent : public USceneComponent UFUNCTION(BlueprintCallable, Category = "Live2D Cubism") UCubismPartComponent* GetPart(const FString PartId); -private: +public: /** * @brief The constructor of the component. */ @@ -540,6 +569,7 @@ class LIVE2DCUBISMFRAMEWORK_API UCubismModelComponent : public USceneComponent */ int32 GetDrawableParentPartIndex(const int32 DrawableIndex) const; + public: /** * The map from the ID of a drawable to its index. */ @@ -612,12 +642,15 @@ class LIVE2DCUBISMFRAMEWORK_API UCubismModelComponent : public USceneComponent */ void AddParameter(const FString ParameterId); + public: /** * The map from the ID of a parameter to its index. */ UPROPERTY() TMap ParameterIndices; + private: + /** * The list of the IDs of the parameters that are not in the original model. */ @@ -661,12 +694,16 @@ class LIVE2DCUBISMFRAMEWORK_API UCubismModelComponent : public USceneComponent */ void AddPart(const FString PartId); + public: + /** * The map from the ID of a part to its index. */ UPROPERTY() TMap PartIndices; + private: + /** * The list of the IDs of the parts that are not in the original model. */ @@ -682,6 +719,8 @@ class LIVE2DCUBISMFRAMEWORK_API UCubismModelComponent : public USceneComponent private: friend class UCubismMoc3; + public: + /** * The raw model data. */ @@ -700,6 +739,10 @@ class LIVE2DCUBISMFRAMEWORK_API UCubismModelComponent : public USceneComponent virtual void OnComponentCreated() override; virtual void OnComponentDestroyed(bool bDestroyingHierarchy) override; + void ComponentCleanup(); + + void ComponentSetup(); + virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override; // End of UActorComponent interface }; diff --git a/Source/Live2DCubismFramework/Public/Model/CubismParameterComponent.h b/Source/Live2DCubismFramework/Public/Model/CubismParameterComponent.h index 2acdff2..d18413c 100644 --- a/Source/Live2DCubismFramework/Public/Model/CubismParameterComponent.h +++ b/Source/Live2DCubismFramework/Public/Model/CubismParameterComponent.h @@ -101,6 +101,9 @@ class LIVE2DCUBISMFRAMEWORK_API UCubismParameterComponent : public UActorCompone */ UCubismParameterComponent(); + + TObjectPtr GetModel(); + /** * The model component that the component depends on. */ diff --git a/Source/Live2DCubismFramework/Public/Model/CubismParameterStoreComponent.h b/Source/Live2DCubismFramework/Public/Model/CubismParameterStoreComponent.h index 2883e65..5d8a8a9 100644 --- a/Source/Live2DCubismFramework/Public/Model/CubismParameterStoreComponent.h +++ b/Source/Live2DCubismFramework/Public/Model/CubismParameterStoreComponent.h @@ -61,6 +61,8 @@ class LIVE2DCUBISMFRAMEWORK_API UCubismParameterStoreComponent : public UActorCo */ UCubismParameterStoreComponent(); + TObjectPtr GetModel(); + /** * The model component that the component depends on. */ diff --git a/Source/Live2DCubismFramework/Public/Model/CubismPartComponent.h b/Source/Live2DCubismFramework/Public/Model/CubismPartComponent.h index 79470b8..e24ce84 100644 --- a/Source/Live2DCubismFramework/Public/Model/CubismPartComponent.h +++ b/Source/Live2DCubismFramework/Public/Model/CubismPartComponent.h @@ -86,6 +86,8 @@ class LIVE2DCUBISMFRAMEWORK_API UCubismPartComponent : public UActorComponent */ UCubismPartComponent(); + TObjectPtr GetModel(); + /** * The model component that the component depends on. */ diff --git a/Source/Live2DCubismFramework/Public/Motion/CubismMotionComponent.h b/Source/Live2DCubismFramework/Public/Motion/CubismMotionComponent.h index f1eb948..5b23999 100644 --- a/Source/Live2DCubismFramework/Public/Motion/CubismMotionComponent.h +++ b/Source/Live2DCubismFramework/Public/Motion/CubismMotionComponent.h @@ -32,7 +32,7 @@ enum class ECubismMotionPriority : uint8 /** * A component to apply the motion to the specified parameters of the Cubism model. */ -UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) ) +UCLASS(Blueprintable) class LIVE2DCUBISMFRAMEWORK_API UCubismMotionComponent : public UActorComponent { GENERATED_BODY() @@ -122,6 +122,8 @@ class LIVE2DCUBISMFRAMEWORK_API UCubismMotionComponent : public UActorComponent */ UCubismMotionComponent(); + TObjectPtr GetModel(); + /** * The model component that the component depends on. */ diff --git a/Source/Live2DCubismFramework/Public/Physics/CubismPhysicsComponent.h b/Source/Live2DCubismFramework/Public/Physics/CubismPhysicsComponent.h index e1cd42c..1230d6d 100644 --- a/Source/Live2DCubismFramework/Public/Physics/CubismPhysicsComponent.h +++ b/Source/Live2DCubismFramework/Public/Physics/CubismPhysicsComponent.h @@ -17,7 +17,7 @@ class UCubismModelComponent; /** * A component to apply the physics to the specified parameters of the Cubism model. */ -UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) ) +UCLASS(Blueprintable) class LIVE2DCUBISMFRAMEWORK_API UCubismPhysicsComponent : public UActorComponent { GENERATED_BODY() @@ -68,6 +68,8 @@ class LIVE2DCUBISMFRAMEWORK_API UCubismPhysicsComponent : public UActorComponent */ UCubismPhysicsComponent(); + TObjectPtr GetModel(); + /** * @brief The model component that the component depends on. */ diff --git a/Source/Live2DCubismFramework/Public/Pose/CubismPoseComponent.h b/Source/Live2DCubismFramework/Public/Pose/CubismPoseComponent.h index 3ffe043..64b4a50 100644 --- a/Source/Live2DCubismFramework/Public/Pose/CubismPoseComponent.h +++ b/Source/Live2DCubismFramework/Public/Pose/CubismPoseComponent.h @@ -50,7 +50,7 @@ struct FCubismPosePartGroupParameter /** * A component to apply the pose to the specified parameters of the Cubism model. */ -UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) ) +UCLASS(Blueprintable) class LIVE2DCUBISMFRAMEWORK_API UCubismPoseComponent : public UActorComponent { GENERATED_BODY() @@ -83,6 +83,8 @@ class LIVE2DCUBISMFRAMEWORK_API UCubismPoseComponent : public UActorComponent */ UCubismPoseComponent(); + TObjectPtr GetModel(); + /** * @brief Perform the fade operation on the part. * diff --git a/Source/Live2DCubismFramework/Public/Rendering/CubismMaskTextureComponent.h b/Source/Live2DCubismFramework/Public/Rendering/CubismMaskTextureComponent.h index c02e22c..7e4fa29 100644 --- a/Source/Live2DCubismFramework/Public/Rendering/CubismMaskTextureComponent.h +++ b/Source/Live2DCubismFramework/Public/Rendering/CubismMaskTextureComponent.h @@ -9,6 +9,7 @@ #pragma once #include "Model/CubismModelActor.h" +#include "Model/CubismModelComponent.h" #include "Rendering/CubismShaders.h" #include "CubismMaskTextureComponent.generated.h" @@ -62,7 +63,7 @@ class LIVE2DCUBISMFRAMEWORK_API UCubismMaskTextureComponent : public UActorCompo * The list of ACubismModel instances whose masks are managed by the component. */ UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Live2D Cubism") - TArray> Models; + TArray> Models; /** * The list of render targets where the assigned masks are drawn. @@ -75,14 +76,14 @@ class LIVE2DCUBISMFRAMEWORK_API UCubismMaskTextureComponent : public UActorCompo * @param Model The model to add. */ UFUNCTION(BlueprintCallable, Category = "Live2D Cubism") - void AddModel(ACubismModel* Model); + void AddModel(AActor* Model); /** * @brief The function to remove a model from the component. * @param Model The model to remove. */ UFUNCTION(BlueprintCallable, Category = "Live2D Cubism") - void RemoveModel(ACubismModel* Model); + void RemoveModel(AActor* Model); /** * ResolveMaskLayout @@ -98,6 +99,8 @@ class LIVE2DCUBISMFRAMEWORK_API UCubismMaskTextureComponent : public UActorCompo */ UCubismMaskTextureComponent(); + TObjectPtr GetModel(AActor* Model); + /** * @brief The function to calculate the optimal level of detail under the current settings. * @return The optimal level of detail. diff --git a/Source/Live2DCubismFramework/Public/Rendering/CubismRendererComponent.h b/Source/Live2DCubismFramework/Public/Rendering/CubismRendererComponent.h index 602b5d8..a619eb4 100644 --- a/Source/Live2DCubismFramework/Public/Rendering/CubismRendererComponent.h +++ b/Source/Live2DCubismFramework/Public/Rendering/CubismRendererComponent.h @@ -28,7 +28,7 @@ enum class ECubismRendererSortingOrder : uint8 /** * A component to render Live2D Cubism models. */ -UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) ) +UCLASS(Blueprintable) class LIVE2DCUBISMFRAMEWORK_API UCubismRendererComponent : public UActorComponent { GENERATED_BODY() @@ -96,12 +96,19 @@ class LIVE2DCUBISMFRAMEWORK_API UCubismRendererComponent : public UActorComponen */ UCubismRendererComponent(); + void SpawnMaskTexture(); + + TObjectPtr GetModel(); + /** * The model component that the component depends on. */ TObjectPtr Model; public: + + virtual void BeginPlay() override; + // UObject interface virtual void PostLoad() override;