Notifications
Clear all

[Closed] meshOp.breakVerts problems

I want to break some object’s vertices (usualy not all), but after that I need to know which verts was unified. So, breaking of vertice creating new vertices that I collecting into one group (array).

I wrote this script (you can copy and easy test it): 
function breakVertices object = 
    (
    	progressStart "Breaking into break groups..." -- show progress bar
    	local t = timeStamp()
    
    	local mesh = snapshotAsMesh object
    	local breakGroups = #()
    
    	local vCount, init_vCount = mesh.numverts
    	for i=1 to init_vCount do
    	(
    		vCount = mesh.numverts -- store vertices count before break
    		meshOp.breakVerts mesh #{i} -- break the vertice
    
    		-- disable data collecting start here
    		breakGroups[i] = #()
    		breakGroups[i][mesh.numverts-vCount+1] = i -- add base vertice as last one (it will init known size array)
    
    		for j=1 to (mesh.numverts-vCount) do -- collect new created vertices
    			breakGroups[i][j] = (vCount+j) --*/
    
    		progressUpdate (i*100.0/init_vCount) -- update progress bar
    		if( getProgressCancel() ) then exit -- progress bar cancel button pressed
    		
    		--gc() -- free memory
    	)
    	
    	print( "Breaking total time: " + ( (((timeStamp()-t)/1000.0)) as string ) )
    	progressEnd() 
    
    	return breakGroups
    )
    
    -- testing interface
    rollout VertNormals_roll "VertNormals" 
    (
    	button getBtn "Break into break groups"
    
    	on getBtn pressed do
    	(
    		undo off
    		(
    			disableSceneRedraw()
    
    			if(selection.count > 0) then
    			(
    				gc()
    				print( "Break groups: " + (breakVertices selection[1]) as string ) -- use the function
    			)
    			else
    				messageBox "No object selected!"
    
    			enableSceneRedraw()
    		)
    	)
    )
    
    -- create the rollout window and add the rollout
    if VertNormalsFloater != undefined do closerolloutfloater VertNormalsFloater
    	
    VertNormalsFloater = newRolloutFloater "BreakVertices Floater" 200 100
    addRollout VertNormals_roll VertNormalsFloater
    			
Works fine, but [b]meshOp.breakVerts[/b] throws "Unknown system exeption". It happens with more complicated objects, with mapping, materials etc, less with standard primitives.

Second problem is fact the breakVerts function seams to making hudge memory leaks. You can check it in windows process manager (disable data collecting code to see it is't the problem).

Maybe there is better way to break vertices?
6 Replies

your function causes huge memory leak. You are creating huge two-dimensional array which you really don’t need.
i modified your script and it works more or less for high-poly models:


function breakVertices object pb:undefined = 
(
	local mesh = snapshotAsMesh object

	local vCount, init_vCount = mesh.numverts
	local breakGroups = #()
	breakGroups.count = init_vCount  
	local breakVerts = meshop.breakVerts
	  
	for i=1 to init_vCount do
	(
		vCount = mesh.numverts -- store vertices count before break
		breakVerts mesh #{i} -- break the vertice
		
		breakGroups[i] = if vCount < mesh.numverts then #{(vCount+1)..mesh.numverts} else #{}
		if pb != undefined do pb.value = i*100./init_vCount
	)
	delete mesh
	breakGroups
)
  
-- testing interface
rollout VertNormals_roll "VertNormals" 
(
	button getBtn "Break into break groups"
	progressbar pb

	on getBtn pressed do undo off
	(
		if(selection.count > 0) then
		(
			print( "Break groups: " + (breakVertices selection[1] pb:pb) as string ) -- use the function
			gc light:on
		)
		else messageBox "No object selected!"
		pb.value = 0
	)
)

-- create the rollout window and add the rollout
if VertNormalsFloater != undefined do closerolloutfloater VertNormalsFloater

VertNormalsFloater = newRolloutFloater "BreakVertices Floater" 200 100
addRollout VertNormals_roll VertNormalsFloater

but probably there is better solution to do the same… just let me think a bit.

Yeah, this way is more memory and time saving, but it still makes unknown system exeption. Maxscripts marks meshOp.breakVerts as source of error. It happens also if you no collecting vertices.

Breaking single vert hunderts times is problematic. Before I had breaking all vertices at one time, and I was looking for vertices with similat position to cllect new vertices. That was terrible slow (more than 30 minutes peer 8000 verts).
Is it possible to get vertices in given area? Like region selelection, but for tri-mesh .

1 Reply
(@denist)
Joined: 1 year ago

Posts: 0

	fn breakVertices object = 
	(
		local mesh = snapshotasmesh object

		fdata = for f=1 to mesh.numfaces collect (getFace mesh f)

		vdata = #()
		vdata.count = mesh.numverts
		for v=1 to vdata.count do vdata[v] = #()
		meshop.breakVerts mesh mesh.verts
		pb.color = red
		for f=1 to mesh.numfaces do
		(
			vv = getFace mesh f
			for k=1 to 3 do append vdata[fdata[f][k]] vv[k]
		)
		delete mesh
		vdata
	)

works OK for 100,000 verts mesh, and it takes 12.4 sec on my machine

:surprised Amazing fast and no errors. Thanks so mutch. Why I didnt think before about checking face’s indices. Very clever.
And I did’t know that seting initial size of table is possible by calling .count =
Thanks again to you:beer:

1 Reply
(@denist)
Joined: 1 year ago

Posts: 0

by the way how do you want use it? what is the main idea?

I working on game meshes exprter. I need this to optimize count of vertices to export: