Notifications
Clear all

[Closed] Break and Weld UV's on 100k tris meshes

Hello !

So i have those many CAD objects imported as meshes in max.
I’d like to use uv’s generated by the CAD software as they are pretty good already but they also have some issues.

First, a lot of map vertices are welded together even if the vertices on the mesh aren’t spatially at the same place.
I’ve found a way to fix this by breaking all uv vertices and reweld them.
But this action takes forever on a huge mesh (50k vertices,100k tris). Canceled after 20min just for breaking.
Do you think there would be a smarter way to do this via maxscript ?
I was thinking that, for instance, there’s no need for the weld to look into a treshold as vertex are directly on top of each others.
Thanks for any hints.

74 Replies

a small sample file may help

Ok. I took a small part ot the mesh and duplicated to match the 100k
https://dl.dropboxusercontent.com/u/13762052/polycount/cad_unwrap_test.obj
You can see that this duplicated part has only one uv element which is a total non sense. I don’t even get how max authorize this.
Anyway, as i said, the workaround i’ve found is to break all points and weld them. Not really an issue for a small mesh. I guess i could split big meshes in small parts, taking care to not destroy the edited normals.

what do you use to break and weld back map vertices? unwrap_uvw?
using just pure mxs it shouldn’t take more than ~2-3 secs for 50K verts mesh

Yeah,this what i do, considering there’s an unwrap on the object


obj = selection[1]
myUV = obj.modifiers[1] 
myUV.unwrap6.selectVerticesByNode #{1..obj.numverts} obj
myUV.breakSelected() 
myUV.setWeldThreshold 0.0001
myUV.weldSelected() 

It obviously doesn’t take 3 sec D:

1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

honestly i don’t believe that this can fix the mapping.

fn FakeDetach msh elementFaces = ( meshop.detachFaces msh elementFaces )	

fn ForAllElements msh theFunction =
(
	faces = msh.faces as bitarray;
	while not faces.isEmpty do
	(	
		elemfaces = meshop.getElementsUsingFace msh #((faces as array)[1]); -- this is what slows us down and also requires the gc() call or else we'll run out of memory
		theFunction msh elemfaces;
		faces = faces - elemfaces;
		gc();
	)
)	

ForAllElements $ FakeDetach

this will do what you want takes about 4mins on the sample file

though the quickest way to get the result is to use explode in the mesh edit geometry panel, set the angle to 180 and use to elements.

Ok sorry, the sample file isn’t representative. Each object is watertight, made of 1 element. I cant parse elements to detach them.
I’ve reuploaded the obj. It’s a small part, only 2,5k point, but same principle, with “corrupted” uvs.

The following code should break all UVW vertices. Welding them is a different thing and I am unsure of how would you accomplish that.

Looks like the source mapping, in the model you uploaded, is highly corrupted and there are many UVW vertices placed on the exact same positions, so welding all of them at once with a threshold will weld vertices that probably belong to different UVW shells.

The code can be easily adapted to work with Editable Poly and with different mapping channels.
(
    
    fn BreakAllUvwVerts obj =
    (
        if obj.modifiers.count == 0 and classof obj == editable_mesh do
        (
            m = snapshotasmesh obj
            meshop.breakVerts m #{1..m.numverts}
            
            numtverts = getnumtverts m
            
            setnumtverts obj numtverts
            buildtvfaces obj
    
            for j = 1 to numtverts do settvert obj j (gettvert m j)
            for j = 1 to m.numfaces do settvface obj j (gettvface m j)
            )
    )
    
    st = timestamp(); sh = heapfree
    BreakAllUvwVerts $
    format "time:% ram:%
" (timestamp()-st) (sh-heapfree)
    
    )

Well it does, I did the sequence several times on different imports and it always worked. The “re-weld” doesn’t weld points that aren’t physically at the same place, fixing the 1st issue.
Then I have to re run a break on open edges to actually separate all elements.
Then i run a script to fix the texel ratio, then a bit of manual stitching
I needed it to be faster as i have hundreds of objects. In the end it’s still faster than redoing the unwrap manually from scratch.

   Thanks Polytools, i've already seen you using that snapshot voodoo magic. Tbh i'm not sure to get what it does, but it's fast. Do you think that welding wouldnt work as the unwrap weld ? I just need it to not weld points that arent at the same physical place.
Page 1 / 6