Read custom data in UE4

I have recently started looking into ways to use Unreal Engine 4 for my visualizations and so far it looks quite promising. The data I usually work come from groundwater modeling simulations, therefore are not typical data one gets from modeling software such as Blender Houdini etc.

So the following is my way to get data from custom ascii files to UE4. For this guide I will assume that the data are organized as follows:

The first line is the number of nodes and the number of triangles. The procedure I’m following accepts only triangular data. so I have actually converted the quadrilaterals to triangles when I created the above file. Then Nnodes times is repeated the line that holds the x y coordinates. Note that in the file I provide 3 z coordinates. These correspond to ground surface, water table and bottom of the aquifer. in my case. Then I’m listing the ids of each of the Ntriangles of the mesh.

Inside UE4 I started from a C++ project and created an class named CustomMesh based on Actor class. The header file is the following

  • Header file

The most important line in the header file is the OnConstruction  virtual method which is called every time the asset is transformed. Apart from the virtual method I defined 3 exposed properties  InputFile, XYscale, Zscale. There is also a UProceduralMeshComponent that holds the actual data. This actually should not be exposed however I did it as I’m still experimenting with this. This header file will create a category DATA as shown below where the data can be updated inside the editor.

  • Implementation file
    • Constructor

In the constructor all I’m doing is to create the object and set it as root. Note also that I have included the Filehepler.h  which is used for reading the custom file.

    • OnConstruction

First we clear out and existing mesh in the object and initialize required variables.

Then I read the first line to get the number of vertices and number of triangles.

Next we read the vertices. Note that while reading the x y coordinates we identify the bounding box of the data so that we can translate the mesh into the center of the transform. Otherwise the mesh will be located somewhere far away of the gizmo icon.

Next we read the triangles. The triangles are stored as 1D vector.

Last we create the custom meshes. For each Z coordinate I create one mesh, which set to visible after the creation.

So far this is adequate to create the custom mesh. However created a blueprint class based on the Custom Mesh class which I dragged into my scene.

The above code does not read the UV coordinates. Soon I’ll add this info in the file and show some figures.

To be continued…

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.