Updated BP to code
This commit is contained in:
parent
b5050e0a79
commit
bb56f3f1ce
|
@ -18,6 +18,173 @@ AProceduralBuilding::AProceduralBuilding()
|
||||||
RootComponent = StaticMeshComponent;
|
RootComponent = StaticMeshComponent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UHierarchicalInstancedStaticMeshComponent* AProceduralBuilding::GetHISMComp(
|
||||||
|
const UStaticMesh* SM)
|
||||||
|
{
|
||||||
|
|
||||||
|
FString SMName = SM->GetName();
|
||||||
|
|
||||||
|
UHierarchicalInstancedStaticMeshComponent** HISMCompPtr = HISMComps.Find(SMName);
|
||||||
|
|
||||||
|
if(HISMCompPtr) return *HISMCompPtr;
|
||||||
|
|
||||||
|
UHierarchicalInstancedStaticMeshComponent* HISMComp = *HISMCompPtr;
|
||||||
|
|
||||||
|
// If it doesn't exist, create the component
|
||||||
|
HISMComp = NewObject<UHierarchicalInstancedStaticMeshComponent>(this,
|
||||||
|
FName(*FString::Printf(TEXT("HISMComp_%d"), HISMComps.Num())));
|
||||||
|
HISMComp->SetupAttachment(RootComponent);
|
||||||
|
HISMComp->RegisterComponent();
|
||||||
|
|
||||||
|
// Set the mesh that will be used
|
||||||
|
HISMComp->SetStaticMesh(const_cast<UStaticMesh*>(SM));
|
||||||
|
|
||||||
|
// Add to the map
|
||||||
|
HISMComps.Emplace(SMName, HISMComp);
|
||||||
|
|
||||||
|
return HISMComp;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AProceduralBuilding::ConvertOldBP_ToNativeCodeObject(AActor* BP_Building)
|
||||||
|
{
|
||||||
|
AProceduralBuilding* ProceduralBuilding = nullptr;
|
||||||
|
|
||||||
|
// Look for all the HISMComps
|
||||||
|
TArray<UHierarchicalInstancedStaticMeshComponent*> OtherHISMComps;
|
||||||
|
BP_Building->GetComponents<UHierarchicalInstancedStaticMeshComponent>(OtherHISMComps);
|
||||||
|
|
||||||
|
for(UHierarchicalInstancedStaticMeshComponent* OtherHISMComp : OtherHISMComps)
|
||||||
|
{
|
||||||
|
const UStaticMesh* SM = OtherHISMComp->GetStaticMesh();
|
||||||
|
|
||||||
|
// Create a new HISMComp and set the SM
|
||||||
|
UHierarchicalInstancedStaticMeshComponent* NewHISMComp = GetHISMComp(SM);
|
||||||
|
|
||||||
|
// Create the instances
|
||||||
|
const TArray<FInstancedStaticMeshInstanceData>& PerInstanceSMData = OtherHISMComp->PerInstanceSMData;
|
||||||
|
|
||||||
|
for(const FInstancedStaticMeshInstanceData& InstSMIData : PerInstanceSMData)
|
||||||
|
{
|
||||||
|
FTransform Transform = FTransform(InstSMIData.Transform);
|
||||||
|
|
||||||
|
NewHISMComp->AddInstance(Transform);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Look for all ChildActors -> Add new Child
|
||||||
|
TArray<UChildActorComponent*> OtherChildComps;
|
||||||
|
BP_Building->GetComponents<UChildActorComponent>(OtherChildComps);
|
||||||
|
|
||||||
|
for(const UChildActorComponent* OtherChildActor : OtherChildComps)
|
||||||
|
{
|
||||||
|
// Create a new ChildActorComponent
|
||||||
|
UChildActorComponent* ChildActorComp = NewObject<UChildActorComponent>(this,
|
||||||
|
FName(*FString::Printf(TEXT("ChildActorComp_%d"), ChildActorComps.Num() )));
|
||||||
|
ChildActorComp->SetupAttachment(RootComponent);
|
||||||
|
|
||||||
|
// Set the class that it will use
|
||||||
|
ChildActorComp->SetChildActorClass(OtherChildActor->GetChildActorClass());
|
||||||
|
ChildActorComp->SetRelativeTransform(OtherChildActor->GetRelativeTransform());
|
||||||
|
|
||||||
|
// Spawns the actor referenced by UChildActorComponent
|
||||||
|
ChildActorComp->RegisterComponent();
|
||||||
|
|
||||||
|
AActor* NewChildActor = ChildActorComp->GetChildActor();
|
||||||
|
|
||||||
|
#if WITH_EDITOR
|
||||||
|
// Add the child actor to a subfolder of the actor's name
|
||||||
|
NewChildActor->SetFolderPath(FName( *FString::Printf(TEXT("/Buildings/%s"), *GetName())));
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Look for all the SMComps
|
||||||
|
TArray<UStaticMeshComponent*> NewSMComps;
|
||||||
|
NewChildActor->GetComponents<UStaticMeshComponent>(NewSMComps);
|
||||||
|
|
||||||
|
// Make it invisible on the child actor to avoid duplication with the HISMComp
|
||||||
|
UStaticMeshComponent* PivotSMComp = NewSMComps[0];
|
||||||
|
PivotSMComp->SetVisibility(false, false);
|
||||||
|
|
||||||
|
ChildActorComps.Emplace(ChildActorComp);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void AProceduralBuilding::SetBaseParameters(
|
||||||
|
const TSet<int>& InDoorsIndexPosition,
|
||||||
|
const TArray<bool>& InUseWallMesh,
|
||||||
|
int InNumFloors,
|
||||||
|
int InLengthX,
|
||||||
|
int InLengthY,
|
||||||
|
bool InCorners,
|
||||||
|
bool InUseFullBlocks)
|
||||||
|
{
|
||||||
|
DoorsIndexPosition = InDoorsIndexPosition;
|
||||||
|
UseWallMesh = InUseWallMesh;
|
||||||
|
NumFloors = InNumFloors;
|
||||||
|
LengthX = InLengthX;
|
||||||
|
LengthY = InLengthY;
|
||||||
|
Corners = InCorners;
|
||||||
|
UseFullBlocks = InUseFullBlocks;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AProceduralBuilding::SetVisibilityParameters(
|
||||||
|
const TArray<bool>& InSideVisibility,
|
||||||
|
const TArray<bool>& InCornerVisibility,
|
||||||
|
bool InRoofVisibility)
|
||||||
|
{
|
||||||
|
SideVisibility = InSideVisibility;
|
||||||
|
CornerVisibility = InCornerVisibility;
|
||||||
|
RoofVisibility = InRoofVisibility;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AProceduralBuilding::SetBaseMeshes(
|
||||||
|
const TArray<UStaticMesh*>& InBaseMeshes,
|
||||||
|
const TArray<TSubclassOf<AActor>>& InBaseBPs,
|
||||||
|
const TArray<UStaticMesh*>& InCornerBaseMeshes,
|
||||||
|
const TArray<TSubclassOf<AActor>>& InCornerBaseBPs,
|
||||||
|
const TArray<UStaticMesh*>& InDoorMeshes,
|
||||||
|
const TArray<TSubclassOf<AActor>>& InDoorBPs)
|
||||||
|
{
|
||||||
|
BaseMeshes = InBaseMeshes;
|
||||||
|
BaseBPs = InBaseBPs;
|
||||||
|
CornerBaseMeshes = InCornerBaseMeshes;
|
||||||
|
CornerBaseBPs = InCornerBaseBPs;
|
||||||
|
DoorMeshes = InDoorMeshes;
|
||||||
|
DoorBPs = InDoorBPs;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AProceduralBuilding::SetBodyMeshes(
|
||||||
|
const TArray<UStaticMesh*>& InBodyMeshes,
|
||||||
|
const TArray<TSubclassOf<AActor>>& InBodyBPs,
|
||||||
|
const TArray<UStaticMesh*>& InCornerBodyMeshes,
|
||||||
|
const TArray<TSubclassOf<AActor>>& InCornerBodyBPs,
|
||||||
|
const TArray<UStaticMesh*>& InWallMeshes,
|
||||||
|
const TArray<TSubclassOf<AActor>>& InWallBPs)
|
||||||
|
{
|
||||||
|
BodyMeshes = InBodyMeshes;
|
||||||
|
BodyBPs = InBodyBPs;
|
||||||
|
CornerBodyMeshes = InCornerBodyMeshes;
|
||||||
|
CornerBodyBPs = InCornerBodyBPs;
|
||||||
|
WallMeshes = InWallMeshes;
|
||||||
|
WallBPs = InWallBPs;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AProceduralBuilding::SetTopMeshes(
|
||||||
|
const TArray<UStaticMesh*>& InTopMeshes,
|
||||||
|
const TArray<TSubclassOf<AActor>>& InTopBPs,
|
||||||
|
const TArray<UStaticMesh*>& InCornerTopMeshes,
|
||||||
|
const TArray<TSubclassOf<AActor>>& InCornerTopBPs,
|
||||||
|
const TArray<UStaticMesh*>& InRoofMeshes,
|
||||||
|
const TArray<TSubclassOf<AActor>>& InRoofBPs)
|
||||||
|
{
|
||||||
|
TopMeshes = InTopMeshes;
|
||||||
|
TopBPs = InTopBPs;
|
||||||
|
CornerTopMeshes = InCornerTopMeshes;
|
||||||
|
CornerTopBPs = InCornerTopBPs;
|
||||||
|
RoofMeshes = InRoofMeshes;
|
||||||
|
RoofBPs = InRoofBPs;
|
||||||
|
}
|
||||||
|
|
||||||
#if WITH_EDITOR
|
#if WITH_EDITOR
|
||||||
|
|
||||||
void AProceduralBuilding::EditorApplyTranslation(
|
void AProceduralBuilding::EditorApplyTranslation(
|
||||||
|
@ -28,9 +195,6 @@ void AProceduralBuilding::EditorApplyTranslation(
|
||||||
{
|
{
|
||||||
Super::EditorApplyTranslation(DeltaTranslation, bAltDown, bShiftDown, bCtrlDown);
|
Super::EditorApplyTranslation(DeltaTranslation, bAltDown, bShiftDown, bCtrlDown);
|
||||||
|
|
||||||
const FTransform& ParentTransform = GetTransform();
|
|
||||||
FTransform ChildTransform = ChildActorComps[0]->GetChildActor()->GetTransform();
|
|
||||||
|
|
||||||
for(UChildActorComponent* ChildActorComp : ChildActorComps)
|
for(UChildActorComponent* ChildActorComp : ChildActorComps)
|
||||||
{
|
{
|
||||||
AActor* ChildActor = ChildActorComp->GetChildActor();
|
AActor* ChildActor = ChildActorComp->GetChildActor();
|
||||||
|
@ -43,9 +207,6 @@ void AProceduralBuilding::EditorApplyRotation(const FRotator& DeltaRotation, boo
|
||||||
{
|
{
|
||||||
Super::EditorApplyRotation(DeltaRotation, bAltDown, bShiftDown, bCtrlDown);
|
Super::EditorApplyRotation(DeltaRotation, bAltDown, bShiftDown, bCtrlDown);
|
||||||
|
|
||||||
const FTransform& ParentTransform = GetTransform();
|
|
||||||
FTransform ChildTransform = ChildActorComps[0]->GetChildActor()->GetTransform();
|
|
||||||
|
|
||||||
FVector ParentLocation = GetActorLocation();
|
FVector ParentLocation = GetActorLocation();
|
||||||
for(UChildActorComponent* ChildActorComp : ChildActorComps)
|
for(UChildActorComponent* ChildActorComp : ChildActorComps)
|
||||||
{
|
{
|
||||||
|
@ -74,7 +235,6 @@ void AProceduralBuilding::EditorApplyScale(const FVector& DeltaScale, const FVec
|
||||||
FVector ChildActorScale = ChildActor->GetActorScale3D();
|
FVector ChildActorScale = ChildActor->GetActorScale3D();
|
||||||
// TODO: apply scale with rotation in mind
|
// TODO: apply scale with rotation in mind
|
||||||
// ChildActor->SetActorScale3D();
|
// ChildActor->SetActorScale3D();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -410,11 +570,7 @@ float AProceduralBuilding::AddChunck(
|
||||||
// Spawns the actor referenced by UChildActorComponent
|
// Spawns the actor referenced by UChildActorComponent
|
||||||
ChildActorComp->RegisterComponent();
|
ChildActorComp->RegisterComponent();
|
||||||
|
|
||||||
// Create and attach child actor to parent
|
|
||||||
AActor* ChildActor = ChildActorComp->GetChildActor();
|
AActor* ChildActor = ChildActorComp->GetChildActor();
|
||||||
FAttachmentTransformRules AttachmentTransformRules =
|
|
||||||
FAttachmentTransformRules(EAttachmentRule::SnapToTarget, true);
|
|
||||||
//ChildActor->AttachToComponent(RootComponent, AttachmentTransformRules);
|
|
||||||
|
|
||||||
#if WITH_EDITOR
|
#if WITH_EDITOR
|
||||||
// Add the child actor to a subfolder of the actor's name
|
// Add the child actor to a subfolder of the actor's name
|
||||||
|
@ -462,33 +618,6 @@ void AProceduralBuilding::AddMeshToBuilding(const UStaticMesh* SM)
|
||||||
HISMComp->AddInstance(CurrentTransform);
|
HISMComp->AddInstance(CurrentTransform);
|
||||||
}
|
}
|
||||||
|
|
||||||
UHierarchicalInstancedStaticMeshComponent* AProceduralBuilding::GetHISMComp(
|
|
||||||
const UStaticMesh* SM)
|
|
||||||
{
|
|
||||||
|
|
||||||
FString SMName = SM->GetName();
|
|
||||||
|
|
||||||
UHierarchicalInstancedStaticMeshComponent** HISMCompPtr = HISMComps.Find(SMName);
|
|
||||||
|
|
||||||
if(HISMCompPtr) return *HISMCompPtr;
|
|
||||||
|
|
||||||
UHierarchicalInstancedStaticMeshComponent* HISMComp = *HISMCompPtr;
|
|
||||||
|
|
||||||
// If it doesn't exist, create the component
|
|
||||||
HISMComp = NewObject<UHierarchicalInstancedStaticMeshComponent>(this,
|
|
||||||
FName(*FString::Printf(TEXT("HISMComp_%d"), HISMComps.Num())));
|
|
||||||
HISMComp->SetupAttachment(RootComponent);
|
|
||||||
HISMComp->RegisterComponent();
|
|
||||||
|
|
||||||
// Set the mesh that will be used
|
|
||||||
HISMComp->SetStaticMesh(const_cast<UStaticMesh*>(SM));
|
|
||||||
|
|
||||||
// Add to the map
|
|
||||||
HISMComps.Emplace(SMName, HISMComp);
|
|
||||||
|
|
||||||
return HISMComp;
|
|
||||||
}
|
|
||||||
|
|
||||||
FVector AProceduralBuilding::GetMeshSize(const UStaticMesh* SM)
|
FVector AProceduralBuilding::GetMeshSize(const UStaticMesh* SM)
|
||||||
{
|
{
|
||||||
FBox Box = SM->GetBoundingBox();
|
FBox Box = SM->GetBoundingBox();
|
||||||
|
|
|
@ -12,11 +12,6 @@
|
||||||
|
|
||||||
// TODO: support n-sides building
|
// TODO: support n-sides building
|
||||||
|
|
||||||
// TODO: option (button) to clear all the values
|
|
||||||
// TODO: option (button) to clear all the meshes
|
|
||||||
|
|
||||||
// TODO:
|
|
||||||
|
|
||||||
struct FloorMeshCollection
|
struct FloorMeshCollection
|
||||||
{
|
{
|
||||||
TArray<UStaticMesh*>* MainMeshes = nullptr;
|
TArray<UStaticMesh*>* MainMeshes = nullptr;
|
||||||
|
@ -37,6 +32,57 @@ public:
|
||||||
// Sets default values for this actor's properties
|
// Sets default values for this actor's properties
|
||||||
AProceduralBuilding();
|
AProceduralBuilding();
|
||||||
|
|
||||||
|
// Looks for the HISMComp on the HISMComps Map that uses the SelectedMesh and returns it.
|
||||||
|
// If doesn't exist its created
|
||||||
|
UFUNCTION(BlueprintCallable, Category="Procedural Building")
|
||||||
|
UHierarchicalInstancedStaticMeshComponent* GetHISMComp(const UStaticMesh* SM);
|
||||||
|
|
||||||
|
UFUNCTION(BlueprintCallable, CallInEditor, Category="Procedural Building")
|
||||||
|
void ConvertOldBP_ToNativeCodeObject(AActor* BP_Building);
|
||||||
|
|
||||||
|
UFUNCTION(BlueprintCallable, Category="Procedural Building|Conversion")
|
||||||
|
void SetBaseParameters(
|
||||||
|
const TSet<int>& InDoorsIndexPosition,
|
||||||
|
const TArray<bool>& InUseWallMesh,
|
||||||
|
int InNumFloors,
|
||||||
|
int InLengthX,
|
||||||
|
int InLengthY,
|
||||||
|
bool InCorners,
|
||||||
|
bool InUseFullBlocks);
|
||||||
|
|
||||||
|
UFUNCTION(BlueprintCallable, Category="Procedural Building|Conversion")
|
||||||
|
void SetVisibilityParameters(
|
||||||
|
const TArray<bool>& InSideVisibility,
|
||||||
|
const TArray<bool>& InCornerVisibility,
|
||||||
|
bool InRoofVisibility);
|
||||||
|
|
||||||
|
UFUNCTION(BlueprintCallable, Category="Procedural Building|Conversion")
|
||||||
|
void SetBaseMeshes(
|
||||||
|
const TArray<UStaticMesh*>& InBaseMeshes,
|
||||||
|
const TArray<TSubclassOf<AActor>>& InBaseBPs,
|
||||||
|
const TArray<UStaticMesh*>& InCornerBaseMeshes,
|
||||||
|
const TArray<TSubclassOf<AActor>>& InCornerBaseBPs,
|
||||||
|
const TArray<UStaticMesh*>& InDoorMeshes,
|
||||||
|
const TArray<TSubclassOf<AActor>>& InDoorBPs);
|
||||||
|
|
||||||
|
UFUNCTION(BlueprintCallable, Category="Procedural Building|Conversion")
|
||||||
|
void SetBodyMeshes(
|
||||||
|
const TArray<UStaticMesh*>& InBodyMeshes,
|
||||||
|
const TArray<TSubclassOf<AActor>>& InBodyBPs,
|
||||||
|
const TArray<UStaticMesh*>& InCornerBodyMeshes,
|
||||||
|
const TArray<TSubclassOf<AActor>>& InCornerBodyBPs,
|
||||||
|
const TArray<UStaticMesh*>& InWallMeshes,
|
||||||
|
const TArray<TSubclassOf<AActor>>& InWallBPs);
|
||||||
|
|
||||||
|
UFUNCTION(BlueprintCallable, Category="Procedural Building|Conversion")
|
||||||
|
void SetTopMeshes(
|
||||||
|
const TArray<UStaticMesh*>& InTopMeshes,
|
||||||
|
const TArray<TSubclassOf<AActor>>& InTopBPs,
|
||||||
|
const TArray<UStaticMesh*>& InCornerTopMeshes,
|
||||||
|
const TArray<TSubclassOf<AActor>>& InCornerTopBPs,
|
||||||
|
const TArray<UStaticMesh*>& InRoofMeshes,
|
||||||
|
const TArray<TSubclassOf<AActor>>& InRoofBPs);
|
||||||
|
|
||||||
#if WITH_EDITOR
|
#if WITH_EDITOR
|
||||||
/**
|
/**
|
||||||
* Called by ApplyDeltaToActor to perform an actor class-specific operation based on widget manipulation.
|
* Called by ApplyDeltaToActor to perform an actor class-specific operation based on widget manipulation.
|
||||||
|
@ -258,10 +304,6 @@ private:
|
||||||
// Add the Static Mesh on the transform location with the transform orientation
|
// Add the Static Mesh on the transform location with the transform orientation
|
||||||
void AddMeshToBuilding(const UStaticMesh* SM);
|
void AddMeshToBuilding(const UStaticMesh* SM);
|
||||||
|
|
||||||
// Looks for the HISMComp on the HISMComps Map that uses the SelectedMesh and returns it.
|
|
||||||
// If doesn't exist its created
|
|
||||||
UHierarchicalInstancedStaticMeshComponent* GetHISMComp(const UStaticMesh* SM);
|
|
||||||
|
|
||||||
// Calculate the Bounds for the Static Mesh
|
// Calculate the Bounds for the Static Mesh
|
||||||
FVector GetMeshSize(const UStaticMesh* SM);
|
FVector GetMeshSize(const UStaticMesh* SM);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue