Hi guys, I am trying to find a better explanation and hopefully some examples on the use of Mesh Description and its methods in Blueprint. More specific, I am interested in the Compute Polygon Triangulation function and how it can be applied in practice. Unfortunately, I wasn’t able to find anything about that on the net and official documentation is rather barebone. Your advice will be much appreciated.
It uses the ear clipping algorithm. The source code has this comment:
// NOTE: This polygon triangulation code is partially based on the ear cutting algorithm described on
// page 497 of the book Real-time Collision Detection, published in 2005.
The book it talks about is this: https://amzn.to/362dCHj
(Which I think should be required reading for any 3D game programmer. It’s great!)
Note that there’s two implementations of essentially the same algorithm, one in FMeshDescription::ComputePolygonTriangulation()
and one in FGeomTools::TriangulatePoly()
.
Thanks for the recommendation, I’ll certainly check it out. I’ve already read some material on polygon triangulation from other sources as well. That’s why I looked into these functions in the first place.
I was actually hoping for a more practical explanation of how these implementations are supposed to be used in Blueprint. Looking at these functions, I am rather unsure about the way they are supposed to be linked/used:
More specifically, what is the Blueprint approach to defining the necessary vertices, edges, and the polygon itself? Am I supposed to add these to the returned arrays? And why aren’t these standard vectors? This looks different from the other functions for creating procedural meshes that I’ve used so far.
Yes, I am rather new to Blueprint and UE switching from several years in Unity and C#. Still trying to get used to this way of programming.
You’re supposed to first create a polygon group ID, which is a list of vertex indices. Check out FPolygonGroupID FMeshDescription::CreatePolygonGroup()
The exposed API is in MeshDescriptionBase.h
, but the implementation is in MeshDescription.h
. So, you’re supposed to create polygon groups, then create polygons using vertex index arrays, and then you can work on them. It looks to me as if the vertex indices are input reference arguments in the C++ code, yet the Blueprint exports them as outputs, which won’t work – this might be an untested workflow/function at the Blueprint level! (I’d expect the input arguments to be declared const in the C++ code.)
In general, the way this level of code is supposed to be used, is to drop down to C++. Blueprint is great for “when the player pulls the switch, start the elevator.” For lower-level data, you really want to use the C++ API. It’s quite simple to click the “File” menu and “Add C++ Class,” even if your project didn’t start out as a C++ project. Similarly, you don’t have to start the editor from Visual Studio; there’s a “build” button in the editor once it has a C++ class added. (But you still use Visual Studio, or Visual Studio Code, or Ryder, or vim, for actually editing the code.)
Alright, I see. I was wondering whether to use Blueprint or C++ code directly for this project, but it might be easier with code. Might have to rethink my approach. Thanks for taking the time to reply.
The question is not “either blueprint or C++,” the question is “which particular features to I leave to blueprint, and which particular features do I build in C++?”
In general, low-level, high-volume, data-specific features should be developed in C++, with properties exposed such that they can be configured/edited in blueprint, whereas high-level glue and game logic is totally fine to leave to blueprint most of the time. A successful game find the right balance to blend both.
Also, if this helps, feel free to tick the little up arrow icon
Alright, I’ve made significant advances in understanding the MeshDescrption and related classes. However, I am now facing a very annoying problem that I have no idea how to solve - maybe I lack enough understanding in the finer aspects of UE, but I have absolutely no idea why this error happens when I call the test Generate function I’ve created:
I invoke this from Blueprint, but the code is entirely in C++ and it compiles without any issues. The error is actually reproducible in different places in that function code, which are essentially different in nature (exception where the arrow points):
TArray<FVertexInstanceID> VertexInstanceIds;
VertexInstanceIds.SetNum( 12 );
// creating the vertices and other necessary stuff here in between...
-> MeshDescriptionBuilder.AppendTriangle( VertexInstanceIds[2], VertexInstanceIds[1], VertexInstanceIds[0], PolygonGroup );
and here:
FStaticMeshConstAttributes MeshDescriptionAttributes( MeshDescription );
-> TVertexAttributesConstRef<FVector3f> VertexPositions = MeshDescriptionAttributes.GetVertexPositions();
So, I am thinking it might be an issue with all these additional modules linking, however, I do have them all in the build.cs file. I’ve been trying to get this to work for a while now, but with no success. Any guidance or help will be much appreciated.
Edit: Of course, I debugged it. The objects and arrays are all looking fine and there are no null elements that could be causing this access violation. The Evaluation tool, however, has the same difficulties evaluating these expressions, but the inspection of the variables works without any problem (i.e. I can see the elements in the arrays and objects have these methods available at runtime).
Did you ever figure this issue out?
How would one fix the messed up blueprint node then? if those values are supposed to be inputs is it not as simple as changing the blueprint interface to show them as such?