Improve mesh indexing.
This commit is contained in:
parent
c3e50b7d60
commit
2f3508ed3a
@ -192,22 +192,29 @@ class ObjArchive(Archive):
|
|||||||
if name:
|
if name:
|
||||||
assert mesh
|
assert mesh
|
||||||
objects[name] = mesh
|
objects[name] = mesh
|
||||||
vertices = set()
|
|
||||||
for mesh in objects.values():
|
vertices = []
|
||||||
vertices |= frozenset(chain.from_iterable(mesh))
|
|
||||||
vertices = tuple(vertices)
|
|
||||||
indices = []
|
indices = []
|
||||||
models = {}
|
models = {}
|
||||||
for name, mesh in sorted(objects.items()):
|
for name, mesh in sorted(objects.items()):
|
||||||
offset = len(indices)
|
offset = len(indices)
|
||||||
assert offset < 65536
|
assert offset < 65536
|
||||||
indices.extend(map(vertices.index, chain.from_iterable(mesh)))
|
mesh_vertices = []
|
||||||
count = len(indices) - offset
|
for vertex in chain.from_iterable(mesh):
|
||||||
|
if vertex not in mesh_vertices:
|
||||||
|
mesh_vertices.append(vertex)
|
||||||
|
base_vertex = len(vertices)
|
||||||
|
mesh_indices = list(map(lambda v: mesh_vertices.index(v) + base_vertex, chain.from_iterable(mesh)))
|
||||||
|
assert max(mesh_indices) < 65536
|
||||||
|
count = len(mesh_indices)
|
||||||
|
print(name, ": vertices =", count, "packed =", len(mesh_vertices))
|
||||||
assert count % 3 == 0
|
assert count % 3 == 0
|
||||||
count //= 3
|
count //= 3
|
||||||
assert count < 65536
|
assert count < 65536
|
||||||
print(name, ": offset =", offset, "triangles =", count)
|
vertices.extend(mesh_vertices)
|
||||||
|
indices.extend(mesh_indices)
|
||||||
models[name] = (offset, count)
|
models[name] = (offset, count)
|
||||||
|
|
||||||
name = str(objpath.stem)
|
name = str(objpath.stem)
|
||||||
assert name not in self.vertices_db.keys()
|
assert name not in self.vertices_db.keys()
|
||||||
#TODO: move to math
|
#TODO: move to math
|
||||||
|
Loading…
Reference in New Issue
Block a user