How to use Procedural Mesh Component in Blueprint?

I see Procedural Mesh Component in UE4.9 and I have studied this link:

but I dont know how to build triangle mesh like git example using Blueprint in UE4.9:

1 Like

In the wiki is mentioned, that this apporach no longer works in 4.8+. So I went and tried the Procedural Mesh Component in a Blueprint.

Basically you can add Procedural Mesh Component to an Actor and provide Vertices, Triangles and UVs to generate a mesh that is rendered at the actors location. I will briefly summarize what I did:

  • I wrote a custom Component that generates the Vertices (from a file).
  • I store all Vertices in a UStruct, that is accessible in Blueprints.
  • I wrote a Blueprint function that generates Triangles und UVs for my Vertices
  • I use the generated Vertices, Triangles and UVs as input for “Create Mesh Section”-Node
  • I apply a Material and Transformation to the generated mesh

I currently use 4.8.3 but this should work for 4.9, too.

(Edited to fix list formatting)

thanks, I’ll try it

That sounds exactly what I am trying to archive. Could you provide some more details about what you did (Code and Blueprint-Screenshots)?

That would be awsome!

I have the code at my university and will work on it again on thursday. I can send you some screenshots from my blueprints to show you how it looks.

That would be very appreciated. I`m sure it would help lots of people

I post this as an answer becaus the comment section is too small and won’t allow long comments…

Info: I’m on version 4.8.3

Here are some screenshots from my Blueprint setup. There is lots of other stuff there that is not so important and I will try to describe the basic setup:

In my setup, LeftEyeGeometry and RightEyeGeometry are both Procedural Mesh Components that both get a generated mesh. The mesh is generated in the function “Generate Geometry From Distortion”, the Procedural Mesh Components are updated with the function “Create Mesh Section

In my case I generate a mesh from an xml file that contains 2D data points. The function “Create Mesh Section” expects at least an array of vertices (the 3d data points that make up the mesh), an array of triangles (integer: the vertices that make up the faces of the mesh) and an array of UV-coordinates (2d vector: a 2D vector that maps a vertice into UV coordinates for texture mapping).

The function “Generate Geometry From Distortion” generates these three arrays. recommend reading some code about mesh generation, because my implementation is just a translation in blueprint code from existing implementations. Here is the link I used: [link text][3]

In the “Generate Vertices”-Comment I just map all vertices to coordinates from -1 to 1 (easyer to scale and my data points are not normalized) and map the X->Y and Y->Z (because I wanted my data points to be in the Y/Z plane).

Here I prepare some variables for the function. NumX is the horizontal vertice count, NumY the vertical count. Vertices is an array of vertices (upper-left to lower-right) in 2D coordinates.

(See picture in comment)
Generate UV-Coordinates for each vertice

(See picture in comment)
Compare this part with the implementation on [link text][3]!

Don’t forget to provide a Material for your Procedural Mesh Components!

You can start with a simple example and build a mesh with 4 vertices by hand. The Vertices, Triangle und UV arrays can be build by hand and you can get comfortable with the function “Create Mesh Section”. Note that you wont see a mesh if the triangles face the wrong direction.

I hope my explanation is not too reduced. If there are any questions, feel free to ask!

1 Like

I added the screenshots as an answer, because comments won’t allow long posts.

I tried to follow your steps…I just set values in “create mesh section”.

But unable to see any geometry.

Is there any pre-requirement for it ?

I found debugging a little tedious to say the least. There are some things to look out for:

  • The triangles can define the polygon in the wrong direction. That means the normals of the mesh face away from your initial position and you won’t see them at first.
  • There is no material assigned to the mesh. Enable wireframe mode and see if there is a mesh. You can also make the material double-sided
  • The mesh is to small (or to big). If you enter vertex coordinates between -1 and 1 then the mesh is in fact a maximum of 2 units in dimension. Try to zoom in (or out)

I started with a minimal example (I am away from my PC for the holidays so this is how I remember it):

  • vertices: [(-1,0,-1), (1,0,-1), (1,0,1)]
  • triangles: either [0,1,2] or [0,2,1]
  • uvs: either [(0,0), (1,0), (1,1)] or [(0,0), (1,1), (1,0)]

Triangles define which vertices make up one polygon and and which direction the normal of the polygon is facing. UVs are, if I recall correctly, in the same order as the triangles and are defined in coordinate space (0,0) to (1,1)

Hope this helps