You've already forked UnrealEngineUWP
mirror of
https://github.com/izzy2lost/UnrealEngineUWP.git
synced 2026-03-26 18:15:20 -07:00
#rb none #rnx #jira none #preflight 60c52c5db9446100014da02d [CL 16653115 by Ryan Schmidt in ue5-main branch]
177 lines
4.3 KiB
C++
177 lines
4.3 KiB
C++
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
#pragma once
|
|
|
|
#include "CoreMinimal.h"
|
|
#include "UObject/NoExportTypes.h"
|
|
#include "MultiSelectionTool.h"
|
|
#include "InteractiveToolBuilder.h"
|
|
#include "MeshOpPreviewHelpers.h"
|
|
#include "ToolDataVisualizer.h"
|
|
#include "DynamicMesh/DynamicMesh3.h"
|
|
#include "BaseTools/SingleClickTool.h"
|
|
#include "Properties/MeshMaterialProperties.h"
|
|
#include "Properties/MeshUVChannelProperties.h"
|
|
#include "Drawing/UVLayoutPreview.h"
|
|
|
|
#include "UVLayoutTool.generated.h"
|
|
|
|
|
|
// predeclarations
|
|
struct FMeshDescription;
|
|
class UDynamicMeshComponent;
|
|
|
|
/**
|
|
*
|
|
*/
|
|
UCLASS()
|
|
class MESHMODELINGTOOLSEDITORONLY_API UUVLayoutToolBuilder : public UInteractiveToolBuilder
|
|
{
|
|
GENERATED_BODY()
|
|
|
|
public:
|
|
virtual bool CanBuildTool(const FToolBuilderState& SceneState) const override;
|
|
virtual UInteractiveTool* BuildTool(const FToolBuilderState& SceneState) const override;
|
|
|
|
protected:
|
|
virtual const FToolTargetTypeRequirements& GetTargetRequirements() const override;
|
|
};
|
|
|
|
|
|
|
|
UENUM()
|
|
enum class EUVLayoutType
|
|
{
|
|
Transform,
|
|
Stack,
|
|
Repack
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
* Standard properties
|
|
*/
|
|
UCLASS()
|
|
class MESHMODELINGTOOLSEDITORONLY_API UUVLayoutToolProperties : public UInteractiveToolPropertySet
|
|
{
|
|
GENERATED_BODY()
|
|
|
|
public:
|
|
UUVLayoutToolProperties();
|
|
|
|
/** Type of transformation to apply to input UV islands */
|
|
UPROPERTY(EditAnywhere, Category = UVLayout)
|
|
EUVLayoutType LayoutType = EUVLayoutType::Repack;
|
|
|
|
/** Expected resolution of output textures; controls spacing left between charts */
|
|
UPROPERTY(EditAnywhere, Category = UVLayout, meta = (UIMin = "64", UIMax = "2048", ClampMin = "2", ClampMax = "4096"))
|
|
int TextureResolution = 1024;
|
|
|
|
/** Apply this uniform scaling to the UVs after any layout recalculation */
|
|
UPROPERTY(EditAnywhere, Category = UVLayout, meta = (UIMin = "0.1", UIMax = "5.0", ClampMin = "0.0001", ClampMax = "10000") )
|
|
float UVScaleFactor = 1;
|
|
|
|
/** Apply this 2D translation to the UVs after any layout recalculation, and after scaling */
|
|
UPROPERTY(EditAnywhere, Category = UVLayout)
|
|
FVector2D UVTranslate = FVector2D(0,0);
|
|
|
|
/** Allow the packer to flip the orientation of UV islands if it save space. May cause problems for downstream operations, not recommended. */
|
|
UPROPERTY(EditAnywhere, Category = UVLayout, AdvancedDisplay)
|
|
bool bAllowFlips = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
* Factory with enough info to spawn the background-thread Operator to do a chunk of work for the tool
|
|
* stores a pointer to the tool and enough info to know which specific operator it should spawn
|
|
*/
|
|
UCLASS()
|
|
class MESHMODELINGTOOLSEDITORONLY_API UUVLayoutOperatorFactory : public UObject, public UE::Geometry::IDynamicMeshOperatorFactory
|
|
{
|
|
GENERATED_BODY()
|
|
|
|
public:
|
|
// IDynamicMeshOperatorFactory API
|
|
virtual TUniquePtr<UE::Geometry::FDynamicMeshOperator> MakeNewOperator() override;
|
|
|
|
UPROPERTY()
|
|
UUVLayoutTool *Tool;
|
|
|
|
int ComponentIndex;
|
|
|
|
};
|
|
|
|
/**
|
|
* Simple Mesh Normal Updating Tool
|
|
*/
|
|
UCLASS()
|
|
class MESHMODELINGTOOLSEDITORONLY_API UUVLayoutTool : public UMultiSelectionTool
|
|
{
|
|
GENERATED_BODY()
|
|
|
|
public:
|
|
|
|
friend UUVLayoutOperatorFactory;
|
|
|
|
UUVLayoutTool();
|
|
|
|
virtual void Setup() override;
|
|
virtual void Shutdown(EToolShutdownType ShutdownType) override;
|
|
|
|
virtual void SetWorld(UWorld* World, UInteractiveGizmoManager* GizmoManagerIn);
|
|
|
|
virtual void OnTick(float DeltaTime) override;
|
|
virtual void Render(IToolsContextRenderAPI* RenderAPI) override;
|
|
|
|
virtual bool HasCancel() const override { return true; }
|
|
virtual bool HasAccept() const override { return true; }
|
|
virtual bool CanAccept() const override;
|
|
|
|
virtual void OnPropertyModified(UObject* PropertySet, FProperty* Property) override;
|
|
|
|
|
|
public:
|
|
int32 GetSelectedUVChannel() const;
|
|
|
|
|
|
protected:
|
|
|
|
UPROPERTY()
|
|
UMeshUVChannelProperties* UVChannelProperties = nullptr;
|
|
|
|
UPROPERTY()
|
|
UUVLayoutToolProperties* BasicProperties = nullptr;
|
|
|
|
UPROPERTY()
|
|
UExistingMeshMaterialProperties* MaterialSettings = nullptr;
|
|
|
|
UPROPERTY()
|
|
TArray<UMeshOpPreviewWithBackgroundCompute*> Previews;
|
|
|
|
protected:
|
|
TArray<TSharedPtr<UE::Geometry::FDynamicMesh3, ESPMode::ThreadSafe>> OriginalDynamicMeshes;
|
|
|
|
UWorld* TargetWorld = nullptr;
|
|
|
|
FViewCameraState CameraState;
|
|
|
|
void UpdateNumPreviews();
|
|
|
|
void UpdateVisualization();
|
|
|
|
void OnPreviewMeshUpdated(UMeshOpPreviewWithBackgroundCompute* Compute);
|
|
|
|
void GenerateAsset(const TArray<FDynamicMeshOpResult>& Results);
|
|
|
|
|
|
protected:
|
|
UPROPERTY()
|
|
UUVLayoutPreview* UVLayoutView = nullptr;
|
|
};
|