I am working in UE5 and would like to get the vertex normals of a static mesh using the C++ API. I can successfully access the vertex buffer, and then get the PositionVertexBuffer and the StaticMeshVertexBuffer (link to docs). This yields the vertex positions and the vertex tangents. However, there seems to be no way to access the vertex normals. I believe I must be overlooking something because the vertex normals are so fundamental, but I have scoured the docs with no luck.
One idea is to use Blender to override the vertex tangents to store the vertex normals, and then import into Unreal. Then, fetching the vertex tangents in Unreal through the C++ API would actually provide the vertex normals. This seems very hacky though.
Can someone advise me on the best approach to get the vertex normals of a static mesh in Unreal C++?
Replies
Just a guess because I've not poked around in the C++ but you might have better luck sending the mesh through either the procedural mesh or dynamic mesh paths since they offer opportunity to bugger around with mesh data.
I can't quite work out what you're trying to do though
Thanks, I haven't explored the procedural mesh or dynamic mesh utilities but will take a look.
To clarify my question, I would like to use the vertex normals in combination with barycentric coordinates to do normal interpolation. The application is that this will allow me to smoothly orient an Unreal Pawn to match the the surface of a low poly static mesh. The image below will hopefully convey this, along with the source link.
https://www.scratchapixel.com/lessons/3d-basic-rendering/introduction-to-shading/shading-normals
IIRC a trace against a mesh can return the surface normal at whatever point you hit - wouldn't that "just work"? (assuming it takes the interpolated normals into account)
as poopipe said, you can do a LineTrace, but you might need to do more than one trace around your character, to get a better average normal. If you just shoot one LineTrace from pawn's origin, you'd be potentially dealing with an abrupt change in your pawn's vertical orientation as it moves around