Notifications
Clear all

[Closed] redraw element

 em3

Hello! I am trying to iterate through each element, get that elements faces, get the verts, then redraw that mesh based on the faces/verts. If I run this code on my entire mesh, it redraws perfectly.


for foo in selection where classof foo == editable_mesh do(
 if not isKindOf foo Editable_mesh do convertToMesh foo
 theface = for f = 1 to foo.numfaces collect getFace foo f
 vertarr = for a = 1 to foo.numverts collect getVert foo a
 (
 	themesh = mesh vertices:vertarr faces:theface
 	meshop.autoEdge themesh #{1..(themesh.Edges.count)} 24 type:#SetClear
 	faces = #{1..themesh.numfaces}
 	meshop.unifyNormals themesh faces
 	for i = 1 to 2 do meshop.flipNormals themesh faces
 	--meshop.autoSmooth themesh faces 0.0
 	--update themesh
 	CenterPivot themesh
 	ResetXForm themesh
 	newobj = converttopoly themesh
 	newobj.selectedfaces = #{1..newobj.numfaces}
 	newobj.setSmoothingGroups 0 -1 1
	local sm = newobj.autoSmooth()
 	--select newobj
 )
 )

when I try to redraw by element, it completes but is completely warped and wrong.


fn redrawGoodMesh vertarr facearr=
 (
 	themesh = mesh vertices:vertarr faces:facearr
 	meshop.autoEdge themesh #{1..(themesh.Edges.count)} 24 type:#SetClear
 	faces = #{1..themesh.numfaces}
 	meshop.unifyNormals themesh faces
 	for i = 1 to 2 do meshop.flipNormals themesh faces
 	--meshop.autoSmooth themesh faces 0.0
 	--update themesh
 	CenterPivot themesh
 	ResetXForm themesh
 	newobj = converttopoly themesh
 	newobj.selectedfaces = #{1..newobj.numfaces}
 	newobj.setSmoothingGroups 0 -1 1
	local sm = newobj.autoSmooth()
 	--select newobj
 )
 
fn delfacefromarr dFarr pFArr =
	(
		for f = 1 to dFarr do 
		(
			for pf = 1 to pFarr.count do
				(
					case of
					(
					(dFarr[f] == pFarr[pf]):deleteitem pFarr pf
					)
				)
		)
	)
				
vertarr = #()
--for foo in selection where classof foo == editable_mesh do(
	
meshfaceArr = for f = 1 to foo.numfaces collect getFace foo f
	
tfaces=(meshop.getElementsUsingFace foo 1) as array
elefaces = for t = 1 to tfaces.count collect getface foo tfaces[t]
 
for v = 1 to elefaces.count do
(
	for vp = 1 to 3 do append vertarr (getvert foo elefaces[v][vp])

)

--df = (elefaces[1][1])-1

--for i = 1 to elefaces.count do for d = 1 to 3 do elefaces[i][d]-=df
	
redrawGoodMesh vertarr elefaces

I am not sure where I am getting off track. My gut is telling me it’s at tfaces but can’t figure out why. Thanks!

6 Replies

is it anything different than detach elements?

 em3

This is in order to avoid detachelements. The redraw only takes a second where detachelements takes minutes.

1 Reply
 em3
(@em3)
Joined: 11 months ago

Posts: 0

Thanks Denis! I was doing it the way wrong way. This gets me there


fn createNewMesh obj faces= 
(
newMesh = meshop.detachFaces obj faces delete:true asMesh:true
update obj --update the mesh
emesh = Editable_mesh() --create an empty Editable_mesh
emesh.mesh = newMesh --assign the detached faces to the new mesh
update emesh --update the mesh
centerpivot emesh
)

while foo.numfaces>1 do 
(	
tfaces=(meshop.getElementsUsingFace foo 1)
createNewMesh foo tfaces
)


  fn detachElements node:selection[1] name: deleteTarget:on = if iskindof node Editable_Mesh do
(	
	objs = #()
	if name == unsupplied do name = node.name 
	while node.numfaces > 0 do
	(
		obj = Editable_Mesh name:(uniquename name) transform:node.objecttransform
		obj.mesh = meshop.detachFaces node (meshop.getElementsUsingFace node 1) delete:on asMesh:on
		append objs obj
	)
	if deleteTarget do delete node
	centerpivot objs
	objs
)
detachElements()
  

in red is a key thing…

centerpivot is a mapped function. so we can do it at once.
also you have to decide what to do with new object transforms…

1 Reply
 em3
(@em3)
Joined: 11 months ago

Posts: 0

The updates do slow everything down for sure, in fact it consumes every bit of memory I have. Your routine above works pretty slick without locking the machine up. Thanks dude!

you don’t need all these mesh updates. it slows the process down