Files
UnrealEngineUWP/Engine/Plugins/Experimental/MeshModelingToolset/Source/MeshModelingTools/Public/RemeshMeshTool.h
Ryan Schmidt 1a178fa774 ModelingTools: clean up old PDI-based mesh edge rendering in Weld, Generate Polygroups, Remesh, Simplify. Replace with usage of UMeshElementsVisualizer and/or UPreviewGeometry. Also clean up includes and port to UE::ToolTarget:: APIs.
UMeshElementsVisualizer::SetMeshAccessFunction() now takes a TFunction with a TFunctionRef argument, instead of with a FDynamicMesh3* argument. This allows the UMeshElementsVisualizer to access the target mesh via the ProcessMesh()-style call on a UPreviewMesh, UDynamicMesh, etc, rather than receiving direct pointer access. See UWeldMeshEdgesTool::Setup() for example usage.

Add UMeshOpPreviewWithBackgroundCompute::ProcessCurrentMesh(), which forwards to the embedded UPreviewMesh::ProcessMesh()  (which can be used with the above)

Add UE::ToolTarget::GetMeshDescriptionCopy() to ModelingToolTargetUtil, similar to existing DynamicMesh variant that will auto-compute tangents if necessary.

#rb none
#rnx
#jira none
#preflight 60c8def586ce760001d8de51
#fyi semion.piskarev

[CL 16679472 by Ryan Schmidt in ue5-main branch]
2021-06-15 17:05:25 -04:00

152 lines
5.0 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#include "MultiSelectionTool.h"
#include "InteractiveToolBuilder.h"
#include "MeshOpPreviewHelpers.h"
#include "CleaningOps/RemeshMeshOp.h"
#include "Properties/RemeshProperties.h"
#include "RemeshMeshTool.generated.h"
class UMeshStatisticsProperties;
class UMeshElementsVisualizer;
PREDECLARE_GEOMETRY(class FDynamicMesh3);
PREDECLARE_GEOMETRY(typedef TMeshAABBTree3<FDynamicMesh3> FDynamicMeshAABBTree3);
/**
*
*/
UCLASS()
class MESHMODELINGTOOLS_API URemeshMeshToolBuilder : public UInteractiveToolBuilder
{
GENERATED_BODY()
public:
/**
* Return true if we have one object selected. URemeshMeshTool is a UMultiSelectionTool, however we currently
* only ever apply it to a single mesh. (See comment at URemeshMeshTool definition below.)
*/
virtual bool CanBuildTool(const FToolBuilderState& SceneState) const override;
virtual UInteractiveTool* BuildTool(const FToolBuilderState& SceneState) const override;
protected:
virtual const FToolTargetTypeRequirements& GetTargetRequirements() const override;
};
/**
* Standard properties of the Remesh operation
*/
UCLASS()
class MESHMODELINGTOOLS_API URemeshMeshToolProperties : public URemeshProperties
{
GENERATED_BODY()
public:
URemeshMeshToolProperties();
/** Target triangle count */
UPROPERTY(EditAnywhere, Category = Remeshing, meta = (EditCondition = "bUseTargetEdgeLength == false"))
int TargetTriangleCount;
/** Smoothing type */
UPROPERTY(EditAnywhere, Category = Remeshing)
ERemeshSmoothingType SmoothingType;
/** If true, UVs and Normals are discarded */
UPROPERTY(EditAnywhere, Category = Remeshing)
bool bDiscardAttributes;
/** Display colors corresponding to the mesh's polygon groups */
UPROPERTY(EditAnywhere, Category = Display)
bool bShowGroupColors = false;
/** Remeshing type */
UPROPERTY(EditAnywhere, Category = Remeshing, AdvancedDisplay)
ERemeshType RemeshType;
/** Number of Remeshing passes */
UPROPERTY(EditAnywhere, Category = Remeshing, AdvancedDisplay, meta = (EditCondition = "RemeshType == ERemeshType::FullPass", UIMin = "0", UIMax = "50", ClampMin = "0", ClampMax = "1000"))
int RemeshIterations;
/** Maximum number of Remeshing passes, for Remeshers that have convergence criteria */
UPROPERTY(EditAnywhere, Category = Remeshing, AdvancedDisplay, meta = (EditCondition = "RemeshType != ERemeshType::FullPass", UIMin = "0", UIMax = "200", ClampMin = "0", ClampMax = "200"))
int MaxRemeshIterations;
/** For NormalFlowRemesher: extra iterations of normal flow with no remeshing */
UPROPERTY(EditAnywhere, Category = Remeshing, AdvancedDisplay, meta = (EditCondition = "RemeshType == ERemeshType::NormalFlow", UIMin = "0", UIMax = "200", ClampMin = "0", ClampMax = "200"))
int ExtraProjectionIterations;
/** If true, the target count is ignored and the target edge length is used directly */
UPROPERTY(EditAnywhere, Category = Remeshing, AdvancedDisplay)
bool bUseTargetEdgeLength;
/** Target edge length */
UPROPERTY(EditAnywhere, Category = Remeshing, AdvancedDisplay, meta = (NoSpinbox = "true", EditCondition = "bUseTargetEdgeLength == true"))
float TargetEdgeLength;
/** Enable projection back to input mesh */
UPROPERTY(EditAnywhere, Category = Remeshing, AdvancedDisplay)
bool bReproject;
};
/**
* Simple Mesh Remeshing Tool
*
* Note this is a subclass of UMultiSelectionTool, however we currently only ever apply it to one mesh at a time. The
* function URemeshMeshToolBuilder::CanBuildTool will return true only when a single mesh is selected, and the tool will
* only be applied to the first mesh in the selection list. The reason we inherit from UMultiSelectionTool is so
* that subclasses of this class can work with multiple meshes (see, for example, UProjectToTargetTool.)
*/
UCLASS()
class MESHMODELINGTOOLS_API URemeshMeshTool : public UMultiSelectionTool, public UE::Geometry::IDynamicMeshOperatorFactory
{
GENERATED_BODY()
public:
URemeshMeshTool(const FObjectInitializer&);
virtual void SetWorld(UWorld* World);
virtual void Setup() override;
virtual void Shutdown(EToolShutdownType ShutdownType) override;
virtual void OnTick(float DeltaTime) 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;
// IDynamicMeshOperatorFactory API
virtual TUniquePtr<UE::Geometry::FDynamicMeshOperator> MakeNewOperator() override;
UPROPERTY()
URemeshMeshToolProperties* BasicProperties;
UPROPERTY()
UMeshStatisticsProperties* MeshStatisticsProperties;
UPROPERTY()
UMeshOpPreviewWithBackgroundCompute* Preview;
UPROPERTY()
UMeshElementsVisualizer* MeshElementsDisplay;
protected:
UWorld* TargetWorld;
TSharedPtr<UE::Geometry::FDynamicMesh3, ESPMode::ThreadSafe> OriginalMesh;
TSharedPtr<UE::Geometry::FDynamicMeshAABBTree3, ESPMode::ThreadSafe> OriginalMeshSpatial;
double InitialMeshArea;
double CalculateTargetEdgeLength(int TargetTriCount);
void UpdateVisualization();
};