On 27/04/2017 at 10:37, xxxxxxxx wrote:
Thanks for the heads up. I've put together a probably horribly inefficient algorithm that I think retrieves all n-gons and non-n-gons.
def GetAllNgons(obj) :
"""Returns a list of ngons & polygons. Its all n-gons as they first appear based on poly_id then edge order.
Followed by all non-ngon polys in their poly order.
Output will looks something like:
[[0, 2, 3], [4, 6], [1], [5]]
"""
neighbor = c4d.utils.Neighbor()
neighbor.Init(obj)
polys = obj.GetAllPolygons()
poly_count = len(polys)
ngon_count = obj.GetNgonCount()
ngon_edges_compact = obj.GetNgonEdgesCompact() # N-gon info for each polygon
non_ngons = []
ngon_polys = []
ngons = None
edges = []
# Get NGon Polygons
for poly_id in xrange(poly_count) :
edge_value = ngon_edges_compact[poly_id] # Bitmask w/ slots for each edge in a quad
# No need to calculate n-gons if there aren't any
if not edge_value:
non_ngons.append([poly_id]) # Store it as a one item list to match format of ngons
continue
poly = polys[poly_id]
poly_info = neighbor.GetPolyInfo(poly_id)
for side in xrange(4) :
# Skip the fourth "edge" of triangles.
if side==2 and (poly.c == poly.d) :
continue
edge = None
if side == 0:
edge = (poly.a, poly.b)
elif side == 1:
edge = (poly.b, poly.c)
elif side == 2:
edge = (poly.c, poly.d)
elif side == 3:
edge = (poly.d, poly.a)
# N-Gon Edge
if not (edge_value & (1 << side) == 0) :
if poly_id not in ngon_polys:
ngon_polys.append(poly_id)
# Get the neighborning hidden ngon poly, should be safe to assume there will always be one.
adjacent_poly = neighbor.GetNeighbor(edge[0], edge[1], poly_id)
if ngons is None:
ngon = [poly_id, adjacent_poly]
ngons = [ngon]
else:
# Add this polygon to an existing set if one exists
present = False
print "ngons: ", ngons
for i, poly_set in enumerate(ngons) :
print "poly_set: ", poly_set
if adjacent_poly in poly_set:
ngons[i] = ngons[i][:] + [poly_id]
present = True
if not present:
ngons.append([poly_id, adjacent_poly])
for i, poly_set in enumerate(ngons) :
ngons[i] = list(set(ngons[i]))
ngons = ngons + non_ngons
return ngons