UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
DynamicMeshSculptLayers.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "Containers/Array.h"
10
11
12namespace UE::Geometry
13{
14
15
18
19
20// Manages a dynamic mesh attribute set's sculpt layer data
22{
23public:
24
25 inline int32 NumLayers() const
26 {
27 return Layers.Num();
28 }
29
30 inline bool IsEnabled() const
31 {
32 return !Layers.IsEmpty();
33 }
34
35 inline int32 GetActiveLayer() const
36 {
37 return ActiveLayer;
38 }
39
40 // Attempt to set the active sculpt layer to the requested index. Will clamp to a valid layer range. Note: If the requested layer has zero weight, will attempt to use a layer with non-zero weight instead.
41 // @return The actual current active layer (may be different from the requested layer!)
43
44 // Remove the given sculpt layer, discarding its contribution to the shape.
45 // Note: Shifts all sculpt layers above this index downward, which may invalidate externally-held sculpt layer indices. May also change the active layer.
47
48 // Merge the contribution of a range of layers.
49 // Note: Shifts all sculpt layers above this range downward, which may invalidate externally-held sculpt layer indices. May also change the active layer.
50 // @param StartIndex Index of the first layer to merge
51 // @param EndIndex Index of the last layer to merge
52 // @param bUseWeights Whether to merge layers based on their current weight strength. Requires StartIndex have non-zero weight. If false, the mesh vertices may move after merge.
53 GEOMETRYCORE_API bool MergeSculptLayers(int32 StartIndex, int32 EndIndex, bool bUseWeights);
54
55 // Set new sculpt layer weights
57
58 // moves the layer at the first provided index to the location given by the second provided index
59 GEOMETRYCORE_API bool MoveLayer(const int32 InitLayerIndex, const int32 TargetIndex);
60
61 // Directly access the sculpt layer data
63 {
64 return Layers.IsValidIndex(LayerIndex) ? &Layers[LayerIndex] : nullptr;
65 }
66
67 // Directly access the sculpt layer data
68 // Note: Must explicitly call "RebuildMesh" for modifications to be applied to the mesh vertex positions
70 {
71 return Layers.IsValidIndex(LayerIndex) ? &Layers[LayerIndex] : nullptr;
72 }
73
74 // Get the current sculpt layer weights
76 {
77 return TConstArrayView<double>(LayerWeights);
78 }
79
80 // Rebuild mesh from sculpt layer offsets + weights, ignoring current mesh positions
82 {
83 UpdateMeshFromLayers();
84 }
85
86 // Update the active layer's sculpt offsets so that the sum of sculpt layers w/ current weights gives the current mesh vertex positions.
87 // Will fail if the active layer has zero weight, or if there are no sculpt layers.
88 // @return true on success
90
91 // Copy across sculpt layer data via a vertex mapping, for all layers that exist on both this and the other layers
93
94private:
95
96 // Sculpt layers are stored as vertex position offsets from the previous layer, with layer zero storing initial positions
98 // Weights per sculpt layer
99 TArray<double> LayerWeights;
100 // Indicates which layer is currently being edited (and is therefore reflected in the mesh vertices, rather than the layer data)
101 int32 ActiveLayer = -1;
102
104
105
106 // Internal helpers used by FDynamicMeshAttributeSet to manage layers
107
110 GEOMETRYCORE_API void EnableMatching(FDynamicMeshAttributeSet* AttributeSet, const FDynamicMeshSculptLayers& ToMatch, bool bClearExisting, bool bDiscardExtraAttributes);
113 GEOMETRYCORE_API bool CheckValidity(const FDynamicMeshAttributeSet* AttributeSet, bool bAllowNonmanifold, EValidityCheckFailMode FailMode) const;
114 GEOMETRYCORE_API bool UpdateMeshFromLayers();
115 GEOMETRYCORE_API bool ValidateActiveLayer();
116
117 inline bool HasValidLayers() const
118 {
119 return Layers.Num() == LayerWeights.Num() && Layers.IsValidIndex(ActiveLayer);
120 }
121};
122
123
124} // namespace UE::Geometry
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
Definition Array.h:670
UE_REWRITE SizeType Num() const
Definition Array.h:1144
Definition IndirectArray.h:20
UE_FORCEINLINE_HINT int32 Num() const
Definition IndirectArray.h:94
UE_FORCEINLINE_HINT bool IsValidIndex(int32 Index) const
Definition IndirectArray.h:408
Definition CompactMaps.h:20
Definition DynamicMeshAttributeSet.h:84
Definition DynamicMeshSculptLayers.h:22
bool IsEnabled() const
Definition DynamicMeshSculptLayers.h:30
GEOMETRYCORE_API bool MergeSculptLayers(int32 StartIndex, int32 EndIndex, bool bUseWeights)
Definition DynamicMeshSculptLayers.cpp:54
int32 NumLayers() const
Definition DynamicMeshSculptLayers.h:25
GEOMETRYCORE_API void CopyThroughMapping(const FDynamicMeshSculptLayers &Other, const FMeshIndexMappings &Mapping)
Definition DynamicMeshSculptLayers.cpp:204
GEOMETRYCORE_API void UpdateLayerWeights(TConstArrayView< double > InLayerWeights)
Definition DynamicMeshSculptLayers.cpp:94
GEOMETRYCORE_API bool UpdateLayersFromMesh()
Definition DynamicMeshSculptLayers.cpp:242
void RebuildMesh()
Definition DynamicMeshSculptLayers.h:81
GEOMETRYCORE_API bool DiscardSculptLayer(int32 LayerIndex)
Definition DynamicMeshSculptLayers.cpp:18
FDynamicMeshSculptLayerAttribute * GetLayer(int32 LayerIndex)
Definition DynamicMeshSculptLayers.h:69
TConstArrayView< double > GetLayerWeights() const
Definition DynamicMeshSculptLayers.h:75
GEOMETRYCORE_API int32 SetActiveLayer(int32 LayerIndex)
Definition DynamicMeshSculptLayers.cpp:10
int32 GetActiveLayer() const
Definition DynamicMeshSculptLayers.h:35
const FDynamicMeshSculptLayerAttribute * GetLayer(int32 LayerIndex) const
Definition DynamicMeshSculptLayers.h:62
GEOMETRYCORE_API bool MoveLayer(const int32 InitLayerIndex, const int32 TargetIndex)
Definition DynamicMeshSculptLayers.cpp:32
Definition DynamicVertexAttribute.h:49
Definition ParametricSurfaceData.h:18
TDynamicMeshVertexAttribute< double, 3 > FDynamicMeshSculptLayerAttribute
Definition DynamicMeshSculptLayers.h:17
EValidityCheckFailMode
Definition GeometryTypes.h:72
Definition MeshIndexMappings.h:22