You've already forked UnrealEngineUWP
mirror of
https://github.com/izzy2lost/UnrealEngineUWP.git
synced 2026-03-26 18:15:20 -07:00
* Changed the API of the actor factory's CreateActor/SpawnActor in order to take a FActorSpawnParameters in parameter, so as to expose UWorld::SpawnActor's own option to the factory user. * The level pointer is still part of the function prototypes in order to make it explicit to the user that he needs to pass in a valid ULevel (rather than relying on FActorSpawnParameters's OverrideLevel, which is easy to miss). In the case where OverrideLevel is indeed passed within FActorSpawnParameters, the functions validate that the pointer is the same as the level param * Also, removed automatic creation of water mesh actor on map load : this is not playing well with world partition because it will keep on creating new actors if the level containing the water mesh actor is not loaded #rb marc.audy, kevin.ortegren #jira none #tests editor + full build preflight [CL 16219600 by jonathan bard in ue5-main branch]
226 lines
7.3 KiB
C++
226 lines
7.3 KiB
C++
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
#include "CoreMinimal.h"
|
|
#include "InputCoreTypes.h"
|
|
#include "Materials/MaterialInterface.h"
|
|
#include "AI/NavigationSystemBase.h"
|
|
#include "Materials/MaterialInstanceDynamic.h"
|
|
#include "UnrealWidgetFwd.h"
|
|
#include "EditorModeManager.h"
|
|
#include "EditorViewportClient.h"
|
|
#include "LandscapeToolInterface.h"
|
|
#include "LandscapeProxy.h"
|
|
#include "LandscapeEdMode.h"
|
|
#include "Containers/ArrayView.h"
|
|
#include "LandscapeEditorObject.h"
|
|
#include "ScopedTransaction.h"
|
|
#include "LandscapeEdit.h"
|
|
#include "LandscapeDataAccess.h"
|
|
#include "LandscapeRender.h"
|
|
#include "LandscapeHeightfieldCollisionComponent.h"
|
|
#include "LandscapeEdModeTools.h"
|
|
#include "LandscapeBlueprintBrushBase.h"
|
|
#include "LandscapeInfo.h"
|
|
#include "Landscape.h"
|
|
#include "ActorFactories/ActorFactory.h"
|
|
//#include "LandscapeDataAccess.h"
|
|
|
|
#define LOCTEXT_NAMESPACE "Landscape"
|
|
|
|
template<class ToolTarget>
|
|
class FLandscapeToolBlueprintBrush : public FLandscapeTool
|
|
{
|
|
protected:
|
|
FEdModeLandscape* EdMode;
|
|
|
|
public:
|
|
FLandscapeToolBlueprintBrush(FEdModeLandscape* InEdMode)
|
|
: EdMode(InEdMode)
|
|
{
|
|
}
|
|
|
|
virtual bool UsesTransformWidget() const { return true; }
|
|
virtual bool OverrideWidgetLocation() const { return false; }
|
|
virtual bool OverrideWidgetRotation() const { return false; }
|
|
|
|
virtual void AddReferencedObjects(FReferenceCollector& Collector) override
|
|
{
|
|
}
|
|
|
|
virtual const TCHAR* GetToolName() override { return TEXT("BlueprintBrush"); }
|
|
virtual FText GetDisplayName() override { return FText(); };
|
|
virtual FText GetDisplayMessage() override { return FText(); };
|
|
|
|
virtual void SetEditRenderType() override { GLandscapeEditRenderMode = ELandscapeEditRenderMode::None | (GLandscapeEditRenderMode & ELandscapeEditRenderMode::BitMaskForMask); }
|
|
virtual bool SupportsMask() override { return false; }
|
|
|
|
virtual ELandscapeToolTargetTypeMask::Type GetSupportedTargetTypes() override
|
|
{
|
|
return ELandscapeToolTargetTypeMask::FromType(ToolTarget::TargetType);
|
|
}
|
|
|
|
virtual void EnterTool() override
|
|
{
|
|
}
|
|
|
|
virtual void ExitTool() override
|
|
{
|
|
GEditor->SelectNone(true, true);
|
|
}
|
|
|
|
virtual void Tick(FEditorViewportClient* ViewportClient, float DeltaTime)
|
|
{
|
|
}
|
|
|
|
virtual bool BeginTool(FEditorViewportClient* ViewportClient, const FLandscapeToolTarget& Target, const FVector& InHitLocation) override
|
|
{
|
|
UClass* BrushClassPtr = EdMode->UISettings->BlueprintBrush.Get();
|
|
if (BrushClassPtr == nullptr)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
ALandscapeBlueprintBrushBase* DefaultObject = Cast<ALandscapeBlueprintBrushBase>(BrushClassPtr->GetDefaultObject(false));
|
|
|
|
if (DefaultObject == nullptr)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
// Only allow placing brushes that would affect our target type
|
|
if ((DefaultObject->IsAffectingHeightmap() && Target.TargetType == ELandscapeToolTargetType::Heightmap) || (DefaultObject->IsAffectingWeightmap() && Target.TargetType == ELandscapeToolTargetType::Weightmap))
|
|
{
|
|
ULandscapeInfo* Info = EdMode->CurrentToolTarget.LandscapeInfo.Get();
|
|
check(Info);
|
|
|
|
FVector SpawnLocation = Info->GetLandscapeProxy()->LandscapeActorToWorld().TransformPosition(InHitLocation);
|
|
|
|
FString BrushActorString = FString::Format(TEXT("{0}_{1}"), { Info->LandscapeActor.Get()->GetActorLabel(), BrushClassPtr->GetName() });
|
|
FName BrushActorName = MakeUniqueObjectName(Info->LandscapeActor.Get()->GetLevel(), BrushClassPtr, FName(BrushActorString));
|
|
|
|
FActorSpawnParameters SpawnInfo;
|
|
SpawnInfo.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
|
|
SpawnInfo.bNoFail = true;
|
|
SpawnInfo.OverrideLevel = Info->LandscapeActor.Get()->GetLevel(); // always spawn in the same level as the one containing the ALandscape
|
|
SpawnInfo.Name = BrushActorName;
|
|
|
|
FScopedTransaction Transaction(LOCTEXT("LandscapeEdModeBlueprintToolSpawn", "Create landscape brush"));
|
|
|
|
// Use the class factory if there's one :
|
|
UActorFactory* BrushActorFactory = GEditor->FindActorFactoryForActorClass(BrushClassPtr);
|
|
|
|
UWorld* ActorWorld = ViewportClient->GetWorld();
|
|
ALandscapeBlueprintBrushBase* Brush = (BrushActorFactory != nullptr)
|
|
? CastChecked<ALandscapeBlueprintBrushBase>(BrushActorFactory->CreateActor(ActorWorld, SpawnInfo.OverrideLevel, FTransform(SpawnLocation), SpawnInfo))
|
|
: ActorWorld->SpawnActor<ALandscapeBlueprintBrushBase>(BrushClassPtr, SpawnLocation, FRotator(0.0f), SpawnInfo);
|
|
EdMode->UISettings->BlueprintBrush = nullptr;
|
|
|
|
Brush->SetActorLabel(BrushActorString);
|
|
|
|
GEditor->SelectNone(true, true);
|
|
GEditor->SelectActor(Brush, true, true);
|
|
|
|
EdMode->RefreshDetailPanel();
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
virtual void EndTool(FEditorViewportClient* ViewportClient) override
|
|
{
|
|
}
|
|
|
|
virtual bool MouseMove(FEditorViewportClient* ViewportClient, FViewport* Viewport, int32 x, int32 y) override
|
|
{
|
|
return false;
|
|
}
|
|
|
|
virtual bool InputKey(FEditorViewportClient* InViewportClient, FViewport* InViewport, FKey InKey, EInputEvent InEvent) override
|
|
{
|
|
if (InKey == EKeys::Enter && InEvent == IE_Pressed)
|
|
{
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
virtual bool InputDelta(FEditorViewportClient* InViewportClient, FViewport* InViewport, FVector& InDrag, FRotator& InRot, FVector& InScale) override
|
|
{
|
|
return false;
|
|
}
|
|
|
|
virtual void Render(const FSceneView* View, FViewport* Viewport, FPrimitiveDrawInterface* PDI) override
|
|
{
|
|
// The editor can try to render the tool before the UpdateLandscapeEditorData command runs and the landscape editor realizes that the landscape has been hidden/deleted
|
|
const ULandscapeInfo* const LandscapeInfo = EdMode->CurrentToolTarget.LandscapeInfo.Get();
|
|
const ALandscapeProxy* const LandscapeProxy = LandscapeInfo->GetLandscapeProxy();
|
|
if (LandscapeProxy)
|
|
{
|
|
const FTransform LandscapeToWorld = LandscapeProxy->LandscapeActorToWorld();
|
|
|
|
int32 MinX, MinY, MaxX, MaxY;
|
|
if (LandscapeInfo->GetLandscapeExtent(MinX, MinY, MaxX, MaxY))
|
|
{
|
|
// TODO if required
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
protected:
|
|
/* float GetLocalZAtPoint(const ULandscapeInfo* LandscapeInfo, int32 x, int32 y) const
|
|
{
|
|
// try to find Z location
|
|
TSet<ULandscapeComponent*> Components;
|
|
LandscapeInfo->GetComponentsInRegion(x, y, x, y, Components);
|
|
for (ULandscapeComponent* Component : Components)
|
|
{
|
|
FLandscapeComponentDataInterface DataInterface(Component);
|
|
return LandscapeDataAccess::GetLocalHeight(DataInterface.GetHeight(x - Component->SectionBaseX, y - Component->SectionBaseY));
|
|
}
|
|
return 0.0f;
|
|
}
|
|
*/
|
|
|
|
public:
|
|
};
|
|
/*
|
|
void FEdModeLandscape::ApplyMirrorTool()
|
|
{
|
|
if (CurrentTool->GetToolName() == FName("Mirror"))
|
|
{
|
|
FLandscapeToolMirror* MirrorTool = (FLandscapeToolMirror*)CurrentTool;
|
|
MirrorTool->ApplyMirror();
|
|
GEditor->RedrawLevelEditingViewports();
|
|
}
|
|
}
|
|
|
|
void FEdModeLandscape::CenterMirrorTool()
|
|
{
|
|
if (CurrentTool->GetToolName() == FName("Mirror"))
|
|
{
|
|
FLandscapeToolMirror* MirrorTool = (FLandscapeToolMirror*)CurrentTool;
|
|
MirrorTool->CenterMirrorPoint();
|
|
GEditor->RedrawLevelEditingViewports();
|
|
}
|
|
}
|
|
*/
|
|
|
|
|
|
|
|
//
|
|
// Toolset initialization
|
|
//
|
|
void FEdModeLandscape::InitializeTool_BlueprintBrush()
|
|
{
|
|
auto Sculpt_Tool_BlueprintBrush = MakeUnique<FLandscapeToolBlueprintBrush<FHeightmapToolTarget>>(this);
|
|
Sculpt_Tool_BlueprintBrush->ValidBrushes.Add("BrushSet_Dummy");
|
|
LandscapeTools.Add(MoveTemp(Sculpt_Tool_BlueprintBrush));
|
|
|
|
auto Paint_Tool_BlueprintBrush = MakeUnique<FLandscapeToolBlueprintBrush<FWeightmapToolTarget>>(this);
|
|
Paint_Tool_BlueprintBrush->ValidBrushes.Add("BrushSet_Dummy");
|
|
LandscapeTools.Add(MoveTemp(Paint_Tool_BlueprintBrush));
|
|
}
|
|
|
|
#undef LOCTEXT_NAMESPACE
|