Download

Procedural Mesh in c++

Hi guys, im working on a project where I really need to import data from an obj file at runtime. Unfortunately it doesn’t look like there is a function for that in unreal API so I would have to write my own parser and construct a mesh at runtime. I found the Procedural Mesh node in Blueprint API. (https://docs.unrealengine.com/latest/INT/BlueprintAPI/Components/ProceduralMesh/CreateMeshSection/index.html)

This looks pretty much like the stuff im looking for, except I am new to unreal engine in general, and have no experience with Blueprint at all. I am very comfortable with C++ so I would like to know if the same thing can be done in C++.

I would also REALLY appreciate if you guys know about a function or a 3rd party tool or even a tutorial that can save me all this trouble and allow importing of a 3D Model at runtime.

Cheers.

I currently use RMC Plugin in my project in combination with Assimp and they work incredibly well together with minimal ‘glue’ code to get assimp -> RMC to work; all you really need to do is initialize an assimp object, iterate over the vertices and face normals, push them into your RMC object. Then convert and apply assimp transformation to UE4, which I found has been the hardest thing because it requires some fiddling as assimp uses a different cartesian plane rule to UE4 so you will have to convert between the two.

It’s worth noting a few things about importing 3D models at runtime:

  • If your game isn’t required to run on low end machines and don’t mind sacrificing significant FPS then it’s definitely worth your time to look into VXGI (NVidia’s implementation of runtime voxel based global illumination) if you want your scenes to look remotely good.
  • If your game is required to run on low end machines at a respectable framerate and want it to look good, have a look into light baking. If you’re making a map editor (like I am) this won’t be an issue as you can simply allow the user to build their lighting in your editor before saving. This is something I am looking into with great detail and I think I have found a good solution.
  • Texture will likely require atlasing. There are 3rd party C++ standalone libraries that auto atlas textures for in an efficient way but this is still something you will have to think about if you want a good performance increase.
  • Don’t forget about collisions; your 3D models may be made by the players themselves, you will have to figure out a way the player can specify its collision. In my case I am simply going to allow the user to add primitives and prepend “col_” to each object name which is then recognised as a collision hull for the RMC object.

Importing 3D models isn’t as trivial as simply pushing verts into the renderer and hoping things work out. It’s a lot of work to be able to get it to look good, let alone run at a decent framerate.

Edit: I have yet to work on texture importing but that’s relatively trivial and involves importing the image file with something like ResIL and shoving the resource into a texture node of precompiled UE4 material then applying that material instance to the object after the assimp -> RMC.

I would provide examples to all this but they’re really messy right now and are more geared towards importing entire objects as entire maps, not actual objects.

Edit edit: It’s probably also worth rewording your thread title to “Importing 3D models at runtime” for future developers looking for the same thing. It took me about 2 weeks to get this right and there doesn’t seem to be any sort of resources on this. So hopefully I saved someone at least a week of development :slight_smile: