You've already forked UnrealEngineUWP
mirror of
https://github.com/izzy2lost/UnrealEngineUWP.git
synced 2026-03-26 18:15:20 -07:00
Reduce surface area of MeshDescriptionProvider/Committer, replace with UE::ToolTarget:: calls where possible. Add new UE::ToolTarget::CommitMeshDescriptionUpdateViaDynamicMesh() function. This is being used for now to avoid potential regressions as UE::ToolTarget::CommitDynamicMeshUpdate will preferentially use DynamicMeshCommitter, and I am not certain it is functionally equivalent in all cases. Add new UE::ToolTarget::CommitDynamicMeshNormalsUpdate(), similar to existing UV version Add new Move-variant of UE::ToolTarget::CommitMeshDescriptionUpdate(), uses new Move-variant of IMeshDescriptionCommitter::CommitMeshDescription. Make existing IMeshDescriptionCommitter::CommitMeshDescription callback interface protected, to prevent usage of this function at public API level (will be removed in future). Tool updates should not change, just using cleaner APIs. EditNormalsTool now uses CommitDynamicMeshNormalsUpdate(), which does go via DynamicMeshCommitter preferentially, where it previously went via MeshDescriptionCommitter. In light testing the results appear equivalent. AttributeEditorTool now operates on MeshDescription copies in various update functions. These are not performance-critical. #rb rinat.abdrashitov #rnx #preflight 61ae45998358693a22c28d1b #ROBOMERGE-AUTHOR: ryan.schmidt #ROBOMERGE-SOURCE: CL 18384350 in //UE5/Release-5.0/... via CL 18384361 #ROBOMERGE-BOT: STARSHIP (Release-Engine-Staging -> Release-Engine-Test) (v896-18170469) [CL 18384373 by ryan schmidt in ue5-release-engine-test branch]
172 lines
4.2 KiB
C++
172 lines
4.2 KiB
C++
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
#pragma once
|
|
|
|
#include "DynamicMeshBrushTool.h"
|
|
#include "BaseTools/MeshSurfacePointMeshEditingTool.h"
|
|
#include "Changes/ValueWatcher.h"
|
|
#include "MeshDescription.h"
|
|
#include "DynamicMesh/DynamicVerticesOctree3.h"
|
|
#include "BoneContainer.h"
|
|
#include "Interfaces/Interface_BoneReferenceSkeletonProvider.h"
|
|
#include "Misc/Optional.h"
|
|
#include "Containers/Map.h"
|
|
#include "TargetInterfaces/MeshDescriptionCommitter.h"
|
|
|
|
#include "SkinWeightsPaintTool.generated.h"
|
|
|
|
|
|
struct FMeshDescription;
|
|
class USkinWeightsPaintTool;
|
|
class IMeshDescriptionCommitter;
|
|
|
|
|
|
|
|
class MESHMODELINGTOOLSEXP_API FMeshSkinWeightsChange : public FToolCommandChange
|
|
{
|
|
public:
|
|
FMeshSkinWeightsChange(const FName& InBoneName) :
|
|
FToolCommandChange(),
|
|
BoneName(InBoneName)
|
|
{ }
|
|
|
|
virtual FString ToString() const override
|
|
{
|
|
return FString(TEXT("Paint Skin Weights"));
|
|
}
|
|
|
|
void Apply(UObject* Object) override;
|
|
|
|
void Revert(UObject* Object) override;
|
|
|
|
void UpdateValues(const TArray<int32>& Indices, const TArray<float>& OldValues, const TArray<float>& NewValues);
|
|
|
|
private:
|
|
FName BoneName;
|
|
TMap<int32, float> OldWeights;
|
|
TMap<int32, float> NewWeights;
|
|
};
|
|
|
|
|
|
/**
|
|
*
|
|
*/
|
|
UCLASS()
|
|
class MESHMODELINGTOOLSEXP_API USkinWeightsPaintToolBuilder : public UMeshSurfacePointMeshEditingToolBuilder
|
|
{
|
|
GENERATED_BODY()
|
|
|
|
public:
|
|
UMeshSurfacePointTool* CreateNewTool(const FToolBuilderState& SceneState) const override;
|
|
};
|
|
|
|
|
|
UCLASS()
|
|
class MESHMODELINGTOOLSEXP_API USkinWeightsPaintToolProperties :
|
|
public UInteractiveToolPropertySet,
|
|
public IBoneReferenceSkeletonProvider
|
|
{
|
|
GENERATED_BODY()
|
|
public:
|
|
UPROPERTY(VisibleAnywhere, Category = Skeleton)
|
|
FBoneReference CurrentBone;
|
|
|
|
// IBoneReferenceSkeletonProvider
|
|
USkeleton* GetSkeleton(bool& bInvalidSkeletonIsError, const IPropertyHandle* PropertyHandle) override;
|
|
|
|
TObjectPtr<USkeletalMesh> SkeletalMesh;
|
|
};
|
|
|
|
|
|
/**
|
|
*
|
|
*/
|
|
UCLASS()
|
|
class MESHMODELINGTOOLSEXP_API USkinWeightsPaintTool : public UDynamicMeshBrushTool
|
|
{
|
|
GENERATED_BODY()
|
|
|
|
public:
|
|
void RegisterActions(FInteractiveToolActionSet& ActionSet) override;
|
|
|
|
void Setup() override;
|
|
void Render(IToolsContextRenderAPI* RenderAPI) override;
|
|
|
|
bool HasCancel() const override { return true; }
|
|
bool HasAccept() const override { return true; }
|
|
bool CanAccept() const override { return true; }
|
|
|
|
// UBaseBrushTool overrides
|
|
bool HitTest(const FRay& Ray, FHitResult& OutHit) override;
|
|
void OnBeginDrag(const FRay& Ray) override;
|
|
void OnUpdateDrag(const FRay& Ray) override;
|
|
void OnEndDrag(const FRay& Ray) override;
|
|
bool OnUpdateHover(const FInputDeviceRay& DevicePos) override;
|
|
|
|
protected:
|
|
|
|
virtual void ApplyStamp(const FBrushStampData& Stamp);
|
|
|
|
void OnShutdown(EToolShutdownType ShutdownType) override;
|
|
void OnTick(float DeltaTime) override;
|
|
|
|
double CalculateBrushFalloff(double Distance) const;
|
|
void CalculateVertexROI(const FBrushStampData& Stamp, TArray<int>& VertexROI);
|
|
|
|
UPROPERTY()
|
|
TObjectPtr<USkinWeightsPaintToolProperties> ToolProps;
|
|
|
|
TValueWatcher<FBoneReference> CurrentBoneWatcher;
|
|
|
|
bool bInRemoveStroke = false;
|
|
bool bInSmoothStroke = false;
|
|
FBrushStampData StartStamp;
|
|
FBrushStampData LastStamp;
|
|
bool bStampPending;
|
|
|
|
TUniquePtr<FMeshDescription> EditedMesh;
|
|
|
|
FBoneContainer BoneContainer;
|
|
|
|
UE::Geometry::TDynamicVerticesOctree3<FDynamicMesh3> VerticesOctree;
|
|
TArray<int> PreviewBrushROI;
|
|
|
|
using BoneInfluenceMapType = TMap<FName, TArray<float>>;
|
|
BoneInfluenceMapType SkinWeightsMap;
|
|
FName CurrentBone = NAME_None;
|
|
TOptional<FName> PendingCurrentBone;
|
|
|
|
|
|
bool bVisibleWeightsValid = false;
|
|
|
|
static FVector4f WeightToColor(float Value);
|
|
|
|
void InitializeSkinWeights();
|
|
void UpdateBoneVisualization();
|
|
void UpdateCurrentBone(const FName &BoneName);
|
|
|
|
struct FBonePositionInfo
|
|
{
|
|
FName BoneName;
|
|
int32 ParentBoneIndex;
|
|
FVector Position;
|
|
float Radius;
|
|
TMap<FName, int32> ChildBones;
|
|
};
|
|
TArray<FBonePositionInfo> BonePositionInfos;
|
|
float MaxDrawRadius = 0.0f;
|
|
|
|
void UpdateBonePositionInfos(float MinRadius);
|
|
void RenderBonePositions(FPrimitiveDrawInterface *PDI);
|
|
|
|
TUniquePtr<FMeshSkinWeightsChange> ActiveChange;
|
|
|
|
void BeginChange();
|
|
TUniquePtr<FMeshSkinWeightsChange> EndChange();
|
|
|
|
friend class FMeshSkinWeightsChange;
|
|
void ExternalUpdateValues(const FName &BoneName, const TMap<int32, float>& IndexValues);
|
|
|
|
void UpdateEditedSkinWeightsMesh();
|
|
};
|