Yes, done that in blueprints already. Was only testing if it would make the performance better doing the same via c++. Got it working now. Here’s the code:
void UDisplaceMesh::Displace(UDynamicMesh* DynamicMesh, UTexture2D* DisplacementMap, float TessellationScale, float DisplacementMagnitude)
{
if (!DynamicMesh || !DisplacementMap)
{
UE_LOG(LogTemp, Warning, TEXT("Invalid mesh or texture input."));
return;
}
// Tessellate the mesh
FGeometryScriptPNTessellateOptions Options;
UGeometryScriptLibrary_MeshSubdivideFunctions::ApplyPNTessellation(DynamicMesh, Options, TessellationScale);
// Apply displacement from texture
FGeometryScriptMeshSelection Selection;
FGeometryScriptDisplaceFromTextureOptions Options1;
Options1.Magnitude = DisplacementMagnitude;
UGeometryScriptLibrary_MeshDeformFunctions::ApplyDisplaceFromTextureMap(DynamicMesh, DisplacementMap, Selection, Options1, 0);
// Recompute Normals
FGeometryScriptCalculateNormalsOptions CalculateOptions;
UGeometryScriptLibrary_MeshNormalsFunctions::RecomputeNormals(DynamicMesh, CalculateOptions);
}