Navigation
API > API/Plugins > API/Plugins/DynamicMesh > API/Plugins/DynamicMesh/Operations
References
| Module | DynamicMesh |
| Header | /Engine/Plugins/Runtime/GeometryProcessing/Source/DynamicMesh/Public/Operations/TransferBoneWeights.h |
| Include | #include "Operations/TransferBoneWeights.h" |
Syntax
class FTransferBoneWeights
Remarks
Transfer bone weights from one mesh (source) to another (target). Uses the dynamic mesh bone attributes to reindex the bone indices of the transferred weights from the source to the target skeletons. If both meshes have identical bone name attributes, then reindexing is skipped.
During the reindexing, if a weighted bone in the source skeleton is not present in the target skeleton, then the weight is not transferred (skipped), and an error is printed to the console. For best results, the target skeleton should be a superset of all the bones that are indexed by the transferred weights.
Example usage:
FDynamicMesh SourceMesh = ...; // Mesh we transferring weights from. Must have bone attributes. FDynamicMesh TargetMesh = ...; // Mesh we are transferring weights to.
FTransferBoneWeights TransferBoneWeights(&SourceMesh, FSkeletalMeshAttributes::DefaultSkinWeightProfileName);
// Optionally, transform the target mesh. This is useful when you want to align the two meshes in world space. TransferBoneWeights.TargetToWorld = ...;
// When transferring weights from a dynamic mesh with bone attributes to a dynamic mesh without bone attributes, // first copy over the bone attributes from the source to the target. if (!TargetMesh.HasAttributes() || !TargetMesh.Attributes()->HasBones()) { TargetMesh.EnableAttributes(); TargetMesh.Attributes()->CopyBoneAttributes(*SourceMesh.Attributes()); }
// Set the transfer method. TransferBoneWeights.TransferMethod = ETransferBoneWeightsMethod::...;
// if ETransferBoneWeightsMethod::ClosestPointOnSurface is used and you simply want to copy weights over from the // closest points then set the radius and normal threshold to -1 (default). TransferBoneWeights.SearchRadius = -1 TransferBoneWeights.NormalThreshold = -1
// if ETransferBoneWeightsMethod::InpaintWeights is used then additionally set the radius and normal parameters TransferBoneWeights.SearchRadius = ... // Good estimate is to use a small value (0.05) of the bounding box radius TransferBoneWeights.NormalThreshold = ... // 30 degrees (0.52 rad) works well in practice
if (TransferBoneWeights.Validate() == EOperationValidationResult::Ok) { TransferBoneWeights.TransferWeightsToMesh(TargetMesh, FSkeletalMeshAttributes::DefaultSkinWeightProfileName); }
// Alternatively if you don't want to use FDynamicMesh3 to represent your target mesh you can transfer weights to // to each point separately by calling if (TransferBoneWeights.Validate() == EOperationValidationResult::Ok) { for each Point: FBoneWeights Weights; TransferBoneWeights.TransferWeightsToPoint(Weights, Point); }
// After the transfer you can check which target mesh vertices had the weight transferred directly from the source mesh // via the FTransferBoneWeights:MatchedVertices array
Variables
| Type | Name | Description | |
|---|---|---|---|
| bool | bIgnoreBoneAttributes | Completely ignore the source and target mesh bone attributes when transferring weights from one dynamic mesh to another. | |
| bool | bUseIntrinsicLaplacian | If true, will use the intrinsic Delaunay mesh to construct sparse Cotangent Laplacian matrix. | |
| bool | bUseParallel | Enable/disable multi-threading. | |
| TArray< float > | ForceInpaint | Optional mask where if ForceInpaint[VertexID] != 0 we want to force the weights for the vertex to be computed automatically. | |
| FName | ForceInpaintWeightMapName | Alternatively, if the mask is stored as a target mesh weight map attribute, specify its name. | |
| TUniquePtr< FDynamicMeshAABBTree3 > | InternalSourceBVH | If the caller doesn't pass BVH for the source mesh then we compute one. | |
| TUniquePtr< FMeshNormals > | InternalSourceMeshNormals | If the source mesh doesn't have per-vertex normals then compute them | |
| bool | LayeredMeshSupport | If true, when the closest point doesn't pass the normal threshold test, will try again with a flipped normal. | |
| TArray< bool > | MatchedVertices | OutputsMatchedVertices[VertexID] is set to true for a target mesh vertex ID with a match found, false otherwise. | |
| double | NormalThreshold | Maximum angle (in radians) difference between target and source point normals to be considred a match. | |
| int32 | NumSmoothingIterations | The number of optional post-processing smoothing iterations applied to the vertices without the match. | |
| FProgressCancel * | Progress | Optional InputsSet this to be able to cancel the running operation. | |
| double | SearchRadius | Optional Inputs for ETransferBoneWeightsMethod::InpaintWeights methodRadius for searching the closest point. | |
| float | SmoothingStrength | The strength of each post-processing smoothing iteration. | |
| const FDynamicMeshAABBTree3 * | SourceBVH | The caller can optionally specify the source mesh BVH in case this operator is run on multiple target meshes while the source mesh remains the same. | |
| const FDynamicMesh3 * | SourceMesh | Source mesh we are transfering weights from. | |
| FName | SourceProfileName | The name of the source mesh skinning profile name. | |
| FTransformSRT3d | TargetToWorld | Transform applied to the input target mesh or target point before transfer. | |
| ETransferBoneWeightsMethod | TransferMethod | The transfer method to compute the bone weights. |
Constructors
| Type | Name | Description | |
|---|---|---|---|
FTransferBoneWeights
(
const FDynamicMesh3* InSourceMesh, |
Assumes that the InSourceMesh has bone attributes, use bIgnoreBoneAttributes flag to ignore the bone attributes and skip re-indexing. |
Destructors
| Type | Name | Description | |
|---|---|---|---|
Functions
| Type | Name | Description | |
|---|---|---|---|
| bool | Cancelled () |
||
| bool | FindClosestPointOnSourceSurface
(
const FVector3d& InPoint, |
Find the closest point on the surface of the source mesh and return the ID of the triangle containing it and its barycentric coordinates. | |
| bool | TransferWeightsToMesh
(
FDynamicMesh3& InOutTargetMesh, |
Transfer the bone weights from the source mesh to the given target mesh and store the result in the skin weight attribute with the given profile name. | |
| bool | TransferWeightsToPoint
(
UE::AnimationCore::FBoneWeights& OutWeights, |
Compute the bone weights for a given point using the ETransferBoneWeightsMethod::ClosestPointOnSurface algorithm. | |
| bool | TransferWeightsToPoint
(
TArray< BoneIndexType >& OutBones, |
Compute the bone weights for a given point using the ETransferBoneWeightsMethod::ClosestPointOnSurface algorithm. | |
| EOperationValidationResult | Validate () |
Enums
| Type | Name | Description | |
|---|---|---|---|
| ETransferBoneWeightsMethod |