Notifications
Clear all

[Closed] Break vertex by vertex color

(
	   fn BreakVerticesByColorAndAlpha node =
	   (
		   mesh = copy node.mesh
		 
		 getmapface = meshop.getmapface
		 getmapvert = meshop.getmapvert
   
		   vertscolors = #()
		 vertsalphas = #()
		   colorsarray = #()
		   vertsbyface = #()
		   flagedverts = #{}
		   
		   for j = 1 to mesh.numfaces do
		   (
			   faceg = getface mesh j
			   facec = getvcface mesh j
			 facea = getmapface mesh -2 j
			   
			   for i = 1 to 3 do
			   (
				   vcolor = getvertcolor mesh facec[i]
				 valpha = getmapvert mesh -2 facea[i]
				   
				   if vertscolors[faceg[i]] == undefined then
				   (
					   vertscolors[faceg[i]] = vcolor
					 vertsalphas[faceg[i]] = valpha
				   )else(
					   if vertscolors[faceg[i]] != vcolor do flagedverts[faceg[i]] = true
					 if vertscolors[faceg[i]] == vcolor and vertsalphas[faceg[i]] != valpha do flagedverts[faceg[i]] = true
				   )
			   )
		   )
   
		   setvertselection mesh flagedverts
		   meshop.breakverts mesh flagedverts
   
		   flagedverts = getvertselection mesh
		   sharedfaces = meshop.getfacesusingvert mesh flagedverts
 
		   for j in sharedfaces do
		   (
			   faceg = getface mesh j
			   facec = getvcface mesh j
			   facea = getmapface mesh -2 j
			 
			   for i = 1 to 3 where flagedverts[faceg[i]] do
			   (
				   vcolor = getvertcolor mesh facec[i]
				 valpha = getmapvert mesh -2 facea[i]
				 
				 vrgba = vcolor + valpha
				 found = finditem colorsarray vrgba
				 
				   if found == 0 then
				   (
					 append colorsarray vrgba
					   append vertsbyface #([j,i])
				   )else(
					 append vertsbyface[found] [j,i]
				   )
			   )
		   )
 
		   for j in vertsbyface do
		   (
			   weldverts = #{}
			   for i in j do
			   (
				   face = getface mesh i[1]
				   weldverts[face[i[2]]] = true
			   )
			   meshop.weldvertsbythreshold mesh weldverts 0.0001
		   )
		   
		   node.mesh = mesh
		   
	   )
	   
	   gc()
	   st = timestamp(); sh = heapfree
	   BreakVerticesByColorAndAlpha $
	   format "time:% ram:% 
" (timestamp()-st) (sh-heapfree)
)

Thanks a lot

Page 2 / 2