On 23/11/2016 at 03:27, xxxxxxxx wrote:
Is there a way for getting each group of ngon?
Here my first attempt who is working 90% time but that mean the obj need to be inserted into the document and is not optimized at all on huge mesh.
def deconnexion(obj) :
doc = c4d.documents.GetActiveDocument()
settings = c4d.BaseContainer()
settings[c4d.MDATA_DISCONNECT_PRESERVEGROUPS] = False
test = c4d.utils.SendModelingCommand(command = c4d.MCOMMAND_DISCONNECT,
list = [obj],
mode = c4d.MODELINGCOMMANDMODE_POLYGONSELECTION,
bc = settings,
doc = doc)
def get_ngnon(obj) :
save_before = obj.GetClone()
mode = doc.GetMode()
doc.SetMode(c4d.Mpolygons)
deconnexion(obj)
selection = obj.GetPolygonS()
selection.DeselectAll()
buffer_all_ngons = []
poly_to_check = range(0,obj.GetPolygonCount())
for polygon_index in xrange(obj.GetPolygonCount()) :
selection.DeselectAll()
#Si notre l'index est dans le poly to check
if polygon_index in poly_to_check:
#On select notre poly
selection.Select(polygon_index)
# On selectionne les élements connecté
c4d.CallCommand(12557)
#Si il y a plus de 1 poly c'est que c'est un ngno
if selection.GetCount() >= 2:
count = op.GetPolygonCount()
buffer = []
for i in xrange(count) :
if selection.IsSelected(i) :
if i in poly_to_check: poly_to_check.remove(i)
buffer.append(i)
buffer_all_ngons.append(buffer)
doc.SetMode(mode)
save_before.CopyTo(obj,0)
return buffer_all_ngons
Here is another attempt here you can see my scene http://img4.hostingpics.net/pics/432338ngon.jpg
poly id 0 = quad
all other are ngon
In this attempt I only try to have all ngons.
But finaly I would like to have the same output as my first attempt.
def get_ngon_v2(obj) :
edge_ngon = list(set(obj.GetNgonEdgesCompact()))
all_ngons = []
nbr = c4d.utils.Neighbor()
nbr.Init(obj)
for i in xrange(op.GetPolygonCount()) :
pli = nbr.GetPolyInfo(i)["edge"]
for edge in pli:
if edge in edge_ngon:
all_ngons.append(i)
return list(set(all_ngons))
Thanks in advance