Skip to content

Instantly share code, notes, and snippets.

@jaforsgren
Created March 28, 2019 14:35
Show Gist options
  • Save jaforsgren/f8bdcdcd113d9c562f94321558af953d to your computer and use it in GitHub Desktop.
Save jaforsgren/f8bdcdcd113d9c562f94321558af953d to your computer and use it in GitHub Desktop.
split primitive islands into separate primitives
old_primitive = { 'material': '2.mat', 'verts': [1, 4, 7, 7, 8, 9, 9, 0, 0]}
tris = [old_primitive['verts'][i:i+3] for i in range(0, len(old_primitive['verts']), 3)]
new_primitives = {}
primitive_id = 0
new_element = {'triangles':[]}
for i, tri in enumerate(tris):
prev = [item for sublist in tris[:i] for item in sublist]
if any(v in prev for v in tri):
new_primitives[primitive_id] = new_element
new_element['triangles'].append(tri)
else:
primitive_id +=1
new_element['triangles'] = [tri]
new_primitives[primitive_id] = new_element
print(new_primitives)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment