Break and Weld UV's on 100k tris meshes

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Display Modes
  02 February 2014
Originally Posted by denisT: 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...
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
__________________
Jorge Rodríguez
PolyTools3D
 
  02 February 2014
Originally Posted by PolyTools3D: 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

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
 
  02 February 2014
Originally Posted by denisT: @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?
__________________
Jorge Rodríguez
PolyTools3D
 
  02 February 2014
Originally Posted by denisT: 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
You're absolutely right, that is much clearer, easy to follow and flexible.
__________________
Jorge Rodríguez
PolyTools3D
 
  02 February 2014
Originally Posted by PolyTools3D: Y but to me the best of this kind of exercises is the learning process.

you might be surprised but i'm here for the same reason
 
  02 February 2014
Originally Posted by PolyTools3D: Just twice?

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!
 
  02 February 2014
Originally Posted by denisT: you might be surprised but i'm here for the same reason

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
__________________
Looking in the right side. [bgaTools]

Last edited by gazybara : 02 February 2014 at 02:50 AM.
 
  02 February 2014
Soon they'll get the result before executing
1sec instead of my 45min hahaha.
Very well done gentlemen.
__________________

 
  02 February 2014
Originally Posted by denisT: we are in a little different positions. you are young and hungry, i'm old and bored.
Mmm…
Originally Posted by denisT: btw... i'm 99% in the maya api programming now. but maxscripting is still my favorite brain practice routine!
You should write a book before reaching the 100%.
__________________
Jorge Rodríguez
PolyTools3D

Last edited by PolyTools3D : 02 February 2014 at 10:02 PM.
 
  02 February 2014
Version 0.3 - A new approach

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:%\n" $.numfaces (timestamp()-st) (sh-heapfree)
 
 )
__________________
Jorge Rodríguez
PolyTools3D
 
  02 February 2014
And here is the compact version which has a little penalty in speed but looks clearer, as Denis suggested.
(
 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
 		f3 = [j*3,j*3-1,j*3-2]
 
 		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]] f3[i]
 			)
 			else f3[i] = idx[f1[i]][k]
 			
 			settvert obj f3[i] p
 		)
 		settvface obj j f3
 	)
 )
 gc()
 st = timestamp(); sh = heapfree
 BreakAndWeldAllUvwVerts $
 format "faces:% time:% ram:%\n" $.numfaces (timestamp()-st) (sh-heapfree)
 )
__________________
Jorge Rodríguez
PolyTools3D
 
  02 February 2014
Hey Jorge
You said that second for-loop causes slowdown
I don't know if mapped fn can helps here but still...
I mean about this concept. Maybe it can replace "for i = 1 to 3 do ()"

verts = #()
 idx = #()
 a = #(1,2,3)
 
 mapped fn test a &verts &idx =
 (
 	verts[a] = "v" + a as string
 	idx[a] = "i" + a as string
 )
 test a &verts &idx
__________________
Looking in the right side. [bgaTools]
 
  02 February 2014
Originally Posted by gazybara: Hey Jorge
You said that second for-loop causes slowdown
I don't know if mapped fn can helps here but still...
I mean about this concept. Maybe it can replace "for i = 1 to 3 do ()"
Thank you Branko for bringing this up. I’ve tried mapping the inner loop as well as the main loop and both options were slower and used more memory.

The “compact” version, is not a lot slower as is, but I was losing half of the optimization I did. So I went from 1000 down to 500 and then up to 750 (aprox.)

Anyway, for 100K mesh 250ms is nothing if you like the clearer code better.
__________________
Jorge Rodríguez
PolyTools3D
 
  02 February 2014
Originally Posted by PolyTools3D: Thank you Branko for bringing this up. I’ve tried mapping the inner loop as well as the main loop and both options were slower and used more memory.

The “compact” version, is not a lot slower as is, but I was losing half of the optimization I did. So I went from 1000 down to 500 and then up to 750 (aprox.)

Anyway, for 100K mesh 250ms is nothing if you like the clearer code better.

Great result you achive here. Then mapped fn have same performance issue as for-loop.
Good to know that. Also adding items like I did maybe is not good way. Append fn probably produce faster result.
__________________
Looking in the right side. [bgaTools]
 
  02 February 2014
Originally Posted by PolyTools3D: And here is the compact version which has a little penalty in speed but looks clearer, as Denis suggested.
(
      fn BreakAndWeldAllUvwVerts obj =
      (
      	mesh = snapshotasmesh obj
      	
      	setnumtverts obj (obj.numfaces*3)
      	buildtvfaces obj
      
      	verts = for j = 1 to obj.numverts collect #()
      	idx = deepcopy verts
	f3 = [0,0,0]
      	for j = 1 to obj.numfaces do
      	(
      		f1 = getface obj j
      		f2 = gettvface mesh j
    		n = j*3+1
      
      		for i = 1 to 3 do
      		(
    			f3[i] = n-i
      			p = gettvert mesh f2[i]
      			if (k = finditem verts[f1[i]] p) == 0 then
      			(
      				append verts[f1[i]] p
      				append idx[f1[i]] f3[i]
    				settvert obj f3[i] p
      			)
      			else f3[i] = idx[f1[i]][k]
      			
      			
      		)
      		settvface obj j f3
      	)
      )
      gc()
      st = timestamp(); sh = heapfree
      BreakAndWeldAllUvwVerts $
      format "faces:% time:% ram:%\n" $.numfaces (timestamp()-st) (sh-heapfree)
      )


see some suggestions in red... i don't have max right now to test it.

Last edited by denisT : 02 February 2014 at 03:04 AM.
 
Thread Closed share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright ©2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 04:03 PM.


Powered by vBulletin
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.