Navigation
API > API/Plugins > API/Plugins/DynamicMesh
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
| Name | FTransferBoneWeights |
| Type | class |
| Header File | /Engine/Plugins/Runtime/GeometryProcessing/Source/DynamicMesh/Public/Operations/TransferBoneWeights.h |
| Include Path | #include "Operations/TransferBoneWeights.h" |
Syntax
class FTransferBoneWeights
Constructors
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
FTransferBoneWeights
(
const FDynamicMesh3* InSourceMesh, |
Assumes that the InSourceMesh has bone attributes, use bIgnoreBoneAttributes flag to ignore the bone attributes and skip re-indexing. | Operations/TransferBoneWeights.h |
Destructors
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
virtual ~FTransferBoneWeights() |
Operations/TransferBoneWeights.h |
Enums
Public
| Name | Remarks |
|---|---|
| ETransferBoneWeightsMethod |
Variables
Public
| Name | Type | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|---|
| bIgnoreBoneAttributes | bool | Completely ignore the source and target mesh bone attributes when transferring weights from one dynamic mesh to another. | Operations/TransferBoneWeights.h | |
| bUseIntrinsicLaplacian | bool | If true, will use the intrinsic Delaunay mesh to construct sparse Cotangent Laplacian matrix. | Operations/TransferBoneWeights.h | |
| bUseParallel | bool | Enable/disable multi-threading. | Operations/TransferBoneWeights.h | |
| ForceInpaint | TArray< float > | Optional mask where if ForceInpaint[VertexID] != 0 we want to force the weights for the vertex to be computed | Operations/TransferBoneWeights.h | |
| ForceInpaintWeightMapName | FName | Alternatively, if the mask is stored as a target mesh weight map attribute, specify its name. | Operations/TransferBoneWeights.h | |
| LayeredMeshSupport | bool | If true, when the closest point doesn't pass the normal threshold test, will try again with a flipped normal. | Operations/TransferBoneWeights.h | |
| MatchedVertices | TArray< bool > | Outputs MatchedVertices[VertexID] is set to true for a target mesh vertex ID with a match found, false otherwise. | Operations/TransferBoneWeights.h | |
| MaxNumInfluences | int32 | During the transfer, only use this number of influences per vertex. | Operations/TransferBoneWeights.h | |
| NormalThreshold | double | Maximum angle (in radians) difference between target and source point normals to be considred a match. | Operations/TransferBoneWeights.h | |
| NumSmoothingIterations | int32 | The number of optional post-processing smoothing iterations applied to the vertices without the match. | Operations/TransferBoneWeights.h | |
| Progress | FProgressCancel * | Optional Inputs Set this to be able to cancel the running operation. | Operations/TransferBoneWeights.h | |
| SearchRadius | double | Optional Inputs for ETransferBoneWeightsMethod::InpaintWeights method Radius for searching the closest point. | Operations/TransferBoneWeights.h | |
| SmoothingStrength | float | The strength of each post-processing smoothing iteration. | Operations/TransferBoneWeights.h | |
| TargetToWorld | FTransformSRT3d | Transform applied to the input target mesh or target point before transfer. | Operations/TransferBoneWeights.h | |
| TargetVerticesSubset | TArray< int32 > | Optional subset of target mesh vertices to transfer weights to. | Operations/TransferBoneWeights.h | |
| TransferMethod | ETransferBoneWeightsMethod | The transfer method to compute the bone weights. | Operations/TransferBoneWeights.h |
Functions
Public
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
virtual 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 | Operations/TransferBoneWeights.h | |
virtual bool TransferWeightsToPoint
(
UE::AnimationCore::FBoneWeights& OutWeights, |
Compute the bone weights for a given point using the ETransferBoneWeightsMethod::ClosestPointOnSurface algorithm. | Operations/TransferBoneWeights.h | |
bool TransferWeightsToPoint
(
TArray< BoneIndexType >& OutBones, |
Compute the bone weights for a given point using the ETransferBoneWeightsMethod::ClosestPointOnSurface algorithm. | Operations/TransferBoneWeights.h | |
virtual EOperationValidationResult Validate() |
Operations/TransferBoneWeights.h |
Protected
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
virtual bool Cancelled() |
Operations/TransferBoneWeights.h | ||
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. | Operations/TransferBoneWeights.h |