Download

Programmatic creation of static mesh objects?

Hello all, I was wondering how easy it would be to create in C++ a custom static mesh in the editor. For e.g. being able to create custom geometry for floors / walls based on an external 2D tile map that was for all intents and purposes the same as an FBX that had been constructed outside the editor and imported. Creating the verts, indices, collision, UVs etc and getting a UStaticMesh out of it that could be placed in the level.

I found a struct called FRawMesh which seems to be a good starting point, but haven’t yet figured out how I would turn this into a fully functional static mesh asset. I wondered if anyone had any experience of doing this and could offer any tips.

Thanks!

Chris

Not sure if this is exactly what you are looking for, but here you go:

Code example on the wiki: https://wiki.unrealengine.com/Procedural_Mesh_Generation

Thread on the subject: https://forums.unrealengine.com/showthread.php?1552-Generate-Procedural-Mesh

Thanks! I found this but it appears to be a very custom thing that doesn’t create anything analogous with the static meshes, and doesn’t support precalc lighting and other stuff that comes with static meshes themselves.

I guess it comes down to me needing to replicate the entire FBX import process code with my own inputs somehow.

Thanks!

I think I’ve figured this out mostly. Will post code for anyone who wants to be able to do this too once it’s all working.

The process is to replicate the code in UFbxFactory that converts an Fbx SDK scene into an Unreal Static Mesh. By creating your own FbxScene object and feeding this in it will allow you to essentially create geometry at editor run-time and create static mesh content assets with whatever geometry as you desire. Which will then be indistinguishable from an FBX imported mesh. Though I’m not sure what a ‘reimport’ would do in this case.

Will report with results in a while.

Yes I’m actually interested. I wanted a feature to import meshes at runtime myself.

Well I found it impossible to actually get all the FBX stuff linking despite copying the FBX stuff in the Build.Target for some other modules that use it like Matinee, no matter what I do I get a bunch of linker errors with the FBX stuff. so I ended up replicating all the Fbx stuff inside my module. And that’s like pulling at an endless thread where I’m putting more and more stuff into my module and never getting to a point where it compiles. Gah.

Posted as a tut here: https://forums.unrealengine.com/showthread.php?2605-Tutorial-Generating-custom-static-meshes-at-Editor-run-time&p=15576#post15576

Hope the thread duplication is ok, but wanted to label it in a way that makes it easy to search for.

Any news about the FRawMesh struct?