How would I go about to weld/collapse/merge the two selected edges in the screenshot?
New to Unreal, trying out the Modeling Mode. Let’s say I like to build some simple 45°-edge-style geometry. Seems like a good use-case where rolling out Blender (etc.) would be overkill. However, I like the resulting geometry to be clean, so no degenerated zero-size triangles, etc.
I tried PolyEd → Edge Edits → Weld as well as Mesh Ops → Weld, which seem the obvious candidates. However, neither tools seem to have any effect at all. The latter doesn’t even merge anything with absurd tolerances like “100”. I pretty sure I’m doing some odd noob mistake Any ideas? Or does “Beta” mean this is really Beta and not yet usable?
So I found the function that does the welding in the code. It’s quite a bit to look through, and I don’t have the source version of UE-5 to breakpoint it so I might do that later. It does seem to work as a vertex merger though, so I think your intuition is correct.
This certainly is the most outstanding comment though
//
// construct edge equivalence sets. First we find all other edges with same
// midpoint, and then we form equivalence set for edge from subset that also
// has same endpoints
//
Try using TriEdits instead, there seems to be a collapse function for edge. I think weld is the combine edges with identical duplicate vertices into one.
Thanks. That does something. I managed to get what I wanted by some trial and error. Then reverted to try again, but then couldn’t repeat what I did I seems I don’t understand what I need to select to collapse the way I want. Apparently one needs to select multiple edges, not just those you want to collapse the vertices of. Possibly a chain of edges somehow?
(For anyone looking for the code section the comment was quoted from, that would be FMergeCoincidentMeshEdges::Apply() )
There was a lot of work done in 5 surround FDynamicMesh3 (Now has a wrapper class UDynamicMesh*) since 4. I think most of the intent was to standardize the mesh descriptions and editing workflow and less on the tools in the kit, so it may be that Epic just hasn’t gotten to this specific feature yet, although we would need them to weigh in.
It would be a bit of work but there is a way to register your own tool with the modeling editor dynamically. All of the tools now register themselves dynamically now it seems via UWeldMeshEdgesOperatorFactory::MakeNewOperator()
Hm, there is a CollapseEdge method on FDynamicMesh3, which seems supposed to do what I would expect when “collapsing an edge”. Will have a look tomorrow whether I can figure out how to call that.
/**
* Collapse the edge between the two vertices, if topologically possible.
* @param KeepVertID index of the vertex that should be kept
* @param RemoveVertID index of the vertex that should be removed
* @param EdgeParameterT vKeep is moved to Lerp(KeepPos, RemovePos, collapse_t)
* @param CollapseInfo returned information about new and modified mesh elements
* @return Ok on success, or enum value indicates why operation cannot be applied. Mesh remains unmodified on error.
*/
virtual EMeshResult CollapseEdge(int KeepVertID, int RemoveVertID, double EdgeParameterT,
FEdgeCollapseInfo& CollapseInfo);
virtual EMeshResult CollapseEdge(int KeepVertID, int RemoveVertID, FEdgeCollapseInfo& CollapseInfo)
{
return CollapseEdge(KeepVertID, RemoveVertID, 0, CollapseInfo);
}
I found a number of code leads, in case anyone would like to follow up on this. However, there seems no obvious easy way to add your own mesh ops, without modifying the engine itself. Certainly not something I should try in my first week of Unreal
UEditMeshPolygonsTool::ApplyWeldEdges()
This is called on PolyEd → Edge Edits → Weld
UEditMeshPolygonsTool::ApplyCollapseEdge()
Some dead code where somebody tried to implement collapsing of edges, with an interesting comment of “AAAHHH cannot do because of overlays”
This was probably supposed to call the above mentioned FDynamicMesh3::CollapseEdge.
UEditMeshPolygonsToolEdgeActions
The different tools when editing edges in PolyEd.
FModelingToolActionCommands
Registering of tools happens here.
FModelingToolsEditorModeModule::OnPostEngineInit()
Which again is tied to this module.
Another find, trying the TriEd mode. The collapse code in UEditMeshPolygonsTool::ApplyCollapseSingleEdge() there looks right when glancing at it, but it appears it somehow actually collapses a different edge than the one you selected. Maybe its a “random” neighbor vertex/edge ID that sometimes just doesn’t exist, which could explain why it sometimes does something and sometimes nothing at all.
Collapsing the selected edge in the screenshot actually collapses the one marked in purple:
This is a great question, thanks. One of the things to keep is that the current weld function only works on open boundaries. Other packages will collapse unneeded faces, which is a great option we will look into.
In this case if you removed the triangles that won’t be needed first with triEdit.
Ah, thx! That indeed does work in both PolyEd and TriEd. However, of course its a bit cumbersome having to delete the faces first. In TriEd mode you are likely having to flip at least one edge on the left or right side. In PolyEd you even have to insert edges on both sides to be able to delete the faces. In Unity ProBuilder as well as Blender this kind of thing happens automatically as it is clear which triangles need to be deleted during the weld.