Morph Mesh to Static Mesh

I originally posted this question in answer hub but since it’s kinda open ended I thought it might be better to post it here. I’m currently working on a procedural and custom mesh generation plugin that will allow you to use procedurally generated meshes as assets and edit them in an editor as well as the game. I’ve got a lot of plans for it and I’ll probably post a more detailed WIP thread once I have something more substantial.

Anyway I’d like to have an option to convert a morph mesh (as I’ve called my asset type :)) to a static mesh for reasons that should be obvious. I’ve already got a conversion for the other way around. I’ve been digging around in the code and I can see a couple ways to convert back to a static mesh.

One would be just to export an FBX and then import it again. I like this option because it also means that you can then edit a generated mesh in some program if need be plus most other assets have this option. The problem I’m having is that all the FBX exporters are methods of FFbxExporter, you need to access this class’s private data to make an exporter. Doing this would make my plugin not stand alone, I don’t want it to rely on modified engine code.

The other option is just to make a static mesh asset directly by filling in the RawMesh or StaticMeshLOD data structure. I still need to look into this option a bit to see what would be the best way to do this. The meshes could then still be exported from the static mesh asset. The problem with this way is I’m not sure if there’s any asset factory for a static mesh asset apart from the Fbx one.

Does anyone have any suggestions on what way might be best?

Hey .
I did this on a basic level in that editor plugin I was working on (a while back now, I haven’t had chance to do any more work on that side of things lately). I had a routine that took my cell/portal geometry, triangulated the walls and floors and then stuck it into a static mesh asset. I don’t remember if the code I sent you had this in, or if I implemented it just after. I can send you it again if you like, though you may be better off just looking at the engine code I based it on - it was the routines used to implement the ‘Convert level BSP to static mesh’ functionality. You should be able to find it easily enough, maybe you already have.

What’s the issue you mention regarding the asset factory?

Hey Kamrann,

Thanks for the tip. I’ve been able to basically work it out since I made that first post by tracing the FBX import pipeline. At the moment I’m filling in a FRawMesh struct and then calling StaticMesh->Build() but I’m getting over quadruple the vertices come out after build in some cases and I’m still missing some other data.

I’ll check out the BSP code, not sure why I didn’t think of that! I’ll let you know if I want to have another look at your code later.

I think the factory thing isn’t actually an issue. I was just assuming I’d have to use an existing factory to make a new static mesh asset but it turns out it’s not a problem to make a second one of your own. Exporting to FBX without engine modification seems like a no go though.

Edit: I found the code you mentioned and it was pretty much how I was doing it already but I was missing a couple things. I’m still getting the vertices duplicating but I think the problem there is with something else.

Edit 2: I fixed the vertices duplication problem by adjusting SrcModel->BuildSettings before calling build. It was re-calculating normals and tangents and I guess floating point errors were making them slightly different causing the vertices to duplicate