Bump engine submodules and rework vertices data for the new mesh struct.
This commit is contained in:
parent
f487a4fcb7
commit
efdbbb5815
2
engine
2
engine
@ -1 +1 @@
|
|||||||
Subproject commit a5adfacdfd6dbb52bd5d1438eef90a370976531e
|
Subproject commit b46b4bddba6c609307ca198438c60d617e20c752
|
@ -19,8 +19,10 @@ from engine import (
|
|||||||
buffer, INSTANCE_FLAG_SPAWNED, BATCH_MAX_SIZE, param_type, params_format,
|
buffer, INSTANCE_FLAG_SPAWNED, BATCH_MAX_SIZE, param_type, params_format,
|
||||||
create_batch, fill_batch, draw_batch, destroy_batch)
|
create_batch, fill_batch, draw_batch, destroy_batch)
|
||||||
|
|
||||||
_flags_p = POINTER(c_ubyte)
|
_flags_t = c_ubyte
|
||||||
_mesh_p = POINTER(c_ushort)
|
_flags_p = POINTER(_flags_t)
|
||||||
|
_mesh_t = c_ushort
|
||||||
|
_mesh_p = POINTER(_mesh_t)
|
||||||
|
|
||||||
class Batch:
|
class Batch:
|
||||||
__slots__ = ('_batch', 'vertices', 'max_size', 'size',
|
__slots__ = ('_batch', 'vertices', 'max_size', 'size',
|
||||||
@ -36,9 +38,9 @@ class Batch:
|
|||||||
self.vertices = vertices
|
self.vertices = vertices
|
||||||
self.max_size = max_size
|
self.max_size = max_size
|
||||||
self.size = 0
|
self.size = 0
|
||||||
self.flags = buffer(c_ubyte, max_size)
|
self.flags = buffer(_flags_t, max_size)
|
||||||
self._flags = _flags_p(self.flags)
|
self._flags = _flags_p(self.flags)
|
||||||
self.mesh = buffer(c_ushort, max_size)
|
self.mesh = buffer(_mesh_t, max_size)
|
||||||
self._meshes = _mesh_p(self.mesh)
|
self._meshes = _mesh_p(self.mesh)
|
||||||
if nparams:
|
if nparams:
|
||||||
self.param = tuple(map(lambda f: buffer(param_type(f), max_size), params_decls.values()))
|
self.param = tuple(map(lambda f: buffer(param_type(f), max_size), params_decls.values()))
|
||||||
|
@ -195,7 +195,7 @@ class ObjArchive(Archive):
|
|||||||
|
|
||||||
vertices = []
|
vertices = []
|
||||||
indices = []
|
indices = []
|
||||||
models = {}
|
meshes = {}
|
||||||
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
|
||||||
@ -213,7 +213,7 @@ class ObjArchive(Archive):
|
|||||||
assert count < 65536
|
assert count < 65536
|
||||||
vertices.extend(mesh_vertices)
|
vertices.extend(mesh_vertices)
|
||||||
indices.extend(mesh_indices)
|
indices.extend(mesh_indices)
|
||||||
models[name] = (offset, count)
|
meshes[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()
|
||||||
@ -226,9 +226,6 @@ class ObjArchive(Archive):
|
|||||||
n = (pack_10(_nz) << 20) | (pack_10(_ny) << 10) | pack_10(_nx)
|
n = (pack_10(_nz) << 20) | (pack_10(_ny) << 10) | pack_10(_nx)
|
||||||
t = ((_tl & 1023) << 20) | (pack_u10(_t) << 10) | pack_u10(_s)
|
t = ((_tl & 1023) << 20) | (pack_u10(_t) << 10) | pack_u10(_s)
|
||||||
return struct.pack('fffII', _px, _py, _pz, n, t)
|
return struct.pack('fffII', _px, _py, _pz, n, t)
|
||||||
meshes = {}
|
|
||||||
for mesh_name, (offset, count) in sorted(models.items()):
|
|
||||||
meshes[mesh_name] = offset | (count << 16)
|
|
||||||
self.vertices_db[name] = VerticesData(name,
|
self.vertices_db[name] = VerticesData(name,
|
||||||
array('B', b''.join(starmap(pack_vertex, vertices))),
|
array('B', b''.join(starmap(pack_vertex, vertices))),
|
||||||
array('H', indices),
|
array('H', indices),
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
# You should have received a copy of the GNU Affero General Public License
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
from itertools import chain
|
||||||
import struct
|
import struct
|
||||||
from array import array
|
from array import array
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
@ -147,7 +148,7 @@ class VerticesData:
|
|||||||
self.name = name
|
self.name = name
|
||||||
self.vertices = vertices
|
self.vertices = vertices
|
||||||
self.indices = indices
|
self.indices = indices
|
||||||
self.meshes = array('I', meshes.values())
|
self.meshes = meshes.values()
|
||||||
self.meshes_db = dict(zip(meshes.keys(), range(len(meshes))))
|
self.meshes_db = dict(zip(meshes.keys(), range(len(meshes))))
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
@ -155,7 +156,7 @@ class VerticesData:
|
|||||||
yield len(self.vertices) // VERTEX_SIZE
|
yield len(self.vertices) // VERTEX_SIZE
|
||||||
yield self.vertices
|
yield self.vertices
|
||||||
yield self.indices
|
yield self.indices
|
||||||
yield self.meshes
|
yield array('I', chain.from_iterable(self.meshes))
|
||||||
|
|
||||||
def get_mesh(self, name):
|
def get_mesh(self, name):
|
||||||
return self.meshes_db[name]
|
return self.meshes_db[name]
|
||||||
@ -167,19 +168,20 @@ class VerticesData:
|
|||||||
nvertices, nindices, nmeshes = _read_struct(file, 'III')
|
nvertices, nindices, nmeshes = _read_struct(file, 'III')
|
||||||
vertices = _read_array(file, 'B', nvertices * VERTEX_SIZE)
|
vertices = _read_array(file, 'B', nvertices * VERTEX_SIZE)
|
||||||
indices = _read_array(file, 'H', nindices)
|
indices = _read_array(file, 'H', nindices)
|
||||||
meshes = _read_array(file, 'I', nmeshes)
|
|
||||||
names = [_read_string(file) for _ in range(nmeshes)]
|
names = [_read_string(file) for _ in range(nmeshes)]
|
||||||
|
meshes = [_read_struct(file, 'II') for _ in range(nmeshes)]
|
||||||
return cls(name, vertices, indices, dict(zip(names, meshes)))
|
return cls(name, vertices, indices, dict(zip(names, meshes)))
|
||||||
|
|
||||||
def to_archive(self, file):
|
def to_archive(self, file):
|
||||||
_write_magic(file, b'VERT')
|
_write_magic(file, b'VERT')
|
||||||
_write_string(file, self.name)
|
_write_string(file, self.name)
|
||||||
_write_struct(file, 'III', len(self.vertices) // VERTEX_SIZE, len(self.indices), len(self.meshes))
|
_write_struct(file, 'III', len(self.vertices) // VERTEX_SIZE, len(self.indices), len(self.meshes_db))
|
||||||
_write_array(file, self.vertices)
|
_write_array(file, self.vertices)
|
||||||
_write_array(file, self.indices)
|
_write_array(file, self.indices)
|
||||||
_write_array(file, self.meshes)
|
|
||||||
for name in self.meshes_db.keys():
|
for name in self.meshes_db.keys():
|
||||||
_write_string(file, name)
|
_write_string(file, name)
|
||||||
|
for mesh in self.meshes:
|
||||||
|
_write_struct(file, 'II', *mesh)
|
||||||
|
|
||||||
class Archive:
|
class Archive:
|
||||||
__slots__ = 'textures_db', 'vertices_db'
|
__slots__ = 'textures_db', 'vertices_db'
|
||||||
|
Loading…
Reference in New Issue
Block a user