Notifications
Clear all

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

here is modified version above (it’s hard to beat the performance) optimized for memory use

(
	fn BreakAndWeldAllUvwVerts obj =
	(
		converttomesh obj
		mesh = snapshotasmesh obj
		meshop.breakverts mesh #all
	
		setnumtverts obj mesh.numtverts
		buildtvfaces obj
	
		for v=1 to mesh.numtverts do settvert obj v (gettvert mesh v)
	
		verts = for v=1 to obj.numverts collect #()
		idx = deepcopy verts
		
		for j = 1 to mesh.numfaces do
		(
			f1 = getface obj j
			f2 = gettvface mesh j
			for i=1 to 3 do
			(
				p = gettvert mesh f2[i]
				if (k = finditem verts[f1[i]] p) == 0 then
				(
					append verts[f1[i]] p
					append idx[f1[i]] f2[i]
				)
				else f2[i] = idx[f1[i]][k]
			)
			settvface obj j f2
		)
	)
	
	gc light:on
	st = timestamp(); sh = heapfree
	BreakAndWeldAllUvwVerts $
	format "faces:% time:% ram:%
" $.numfaces (timestamp()-st) (sh-heapfree)	
)
5 Replies
(@polytools3d)
Joined: 11 months ago

Posts: 0

I get the same memory ussage and it is a little slow:

#40 – faces:99380 time:1091 ram:16968256L
#41 – faces:99380 time:1208 ram:16967544L

(@denist)
Joined: 11 months ago

Posts: 0

it was against your previous version…

i convert to mesh at the begging of the function to make the operation undoable. that causes a slight difference in performance…

(@polytools3d)
Joined: 11 months ago

Posts: 0

The delay in the notification system makes following the Thread confusing some times…

I think the 5-10% difference in speed is due to the loop, not that much the converttomesh.

for i=1 to 3 do
(@denist)
Joined: 11 months ago

Posts: 0

anyway i would prefer

for i=1 to <n> do...

that’s more clear and it can be used with editable poly algorithms as well

(@polytools3d)
Joined: 11 months ago

Posts: 0

You’re absolutely right, that is much clearer, easy to follow and flexible.

@PolyTools3D
we did the same optimization

@PolyTools3D
you are very good in algorithms… you beat me second time

You are very good in general Doctor (well… I think you already know that).

The sort of little challenge adds a different flavor to solving the problem, but to me the best of this kind of exercises is the learning process.

Just twice?

you might be surprised but i’m here for the same reason

at least twice…

we are in a little different positions. you are young and hungry, i’m old and bored.

btw… i’m 99% in the maya api programming now. but maxscripting is still my favorite brain practice routine!

I folow this thread from the beginning and must tell one thing. U guys tear apart this forum with incredible coding skills.
@Jorge as I said the other day on scriptspot KUNG-FU
@Denis I don’t belive you
You are here to force us to learn something useful and to accept any challenge.
Anyway beer for all

Soon they’ll get the result before executing
1sec instead of my 45min hahaha.
Very well done gentlemen.

Mmm

You should write a book before reaching the 100%.

A new approach. I am not sure if we will be able to squeeze this lemmon further.

faces:99380 time:1325 ram:43134792L
faces:99380 time:1111 ram:16968240L
faces:99380 time:577 ram:16968208L

(
 
 fn BreakAndWeldAllUvwVerts obj =
 (
 	mesh = snapshotasmesh obj
 	
 	setnumtverts obj (obj.numfaces*3)
 	buildtvfaces obj
 
 	verts = for j = 1 to obj.numverts collect #()
 	idx = deepcopy verts
 	
 	for j = 1 to obj.numfaces do
 	(
 		f1 = getface obj j
 		f2 = gettvface mesh j
 		
 		i3 = j*3
 		i2 = i3-1
 		i1 = i3-2
 		
 		v1 = gettvert mesh f2[1]
 		v2 = gettvert mesh f2[2]
 		v3 = gettvert mesh f2[3]
 		
 		k1 = finditem verts[f1[1]] v1
 		k2 = finditem verts[f1[2]] v2
 		k3 = finditem verts[f1[3]] v3
 
 		if k1 == 0 then
 		(
 			append verts[f1[1]] v1
 			append idx[f1[1]] i1
 		)
 		else i1 = idx[f1[1]][k1]
 
 		if k2 == 0 then
 		(
 			append verts[f1[2]] v2
 			append idx[f1[2]] i2
 		)
 		else i2 = idx[f1[2]][k2]
 
 		if k3 == 0 then
 		(
 			append verts[f1[3]] v3
 			append idx[f1[3]] i3
 		)
 		else i3 = idx[f1[3]][k3]
 		
 		settvert obj i1 v1
 		settvert obj i2 v2
 		settvert obj i3 v3
 		
 		settvface obj j [i1,i2,i3]
 	)
 
 )
 
 gc()
 st = timestamp(); sh = heapfree
 BreakAndWeldAllUvwVerts $
 format "faces:% time:% ram:%
" $.numfaces (timestamp()-st) (sh-heapfree)
 
 )
Page 4 / 6