Read SHDW chunks

This commit is contained in:
William Herald Snyder 2023-01-06 21:30:16 -05:00
parent f451be4d18
commit 63f9e43e17
2 changed files with 37 additions and 0 deletions

View File

@ -39,6 +39,20 @@ class VertexWeight:
weight: float = 1.0
bone: int = 0
@dataclass
class ShadowGeometry:
""" Class representing 'SHDW' chunks. """
# Perhaps I could just use the positions list in the segment
# class, but I don't know if SHDW info can coexist with
# a normal geometry segment...
positions: List[Vector] = field(default_factory=list)
# The second two entries may not be necessary...
edges: List[Tuple[int,int,int,int]] = field(default_factory=list)
@dataclass
class GeometrySegment:
""" Class representing a 'SEGM' section in a .msh file. """
@ -56,6 +70,7 @@ class GeometrySegment:
triangles: List[List[int]] = field(default_factory=list)
triangle_strips: List[List[int]] = None
shadow_geometry: ShadowGeometry = None
@dataclass
class CollisionPrimitive:

View File

@ -388,6 +388,28 @@ def _read_segm(segm: Reader, materials_list: List[Material]) -> GeometrySegment:
#if segm.read_u16 != 0:
# segm.skip_bytes(-2)
elif next_header == "SHDW":
shadow_geometry = ShadowGeometry()
with segm.read_child() as shdw:
#print("Found shadow chunk")
num_positions = shdw.read_u32()
#print(f" Num verts in shadow mesh: {num_positions}")
shadow_geometry.positions = [shdw.read_vec() for _ in range(num_positions)]
num_edges = shdw.read_u32()
#print(f" Num edges in shadow mesh: {num_edges}")
edges = []
for i in range(num_edges):
edges.append(tuple(shdw.read_u16(4)))
#print(" " + str(edges[-1]))
shadow_geometry.edges = edges
geometry_seg.shadow_geometry = shadow_geometry
elif next_header == "WGHT":
with segm.read_child() as wght: