From 63f9e43e176010377f3ec3a8c67b38747b4015bd Mon Sep 17 00:00:00 2001 From: William Herald Snyder Date: Fri, 6 Jan 2023 21:30:16 -0500 Subject: [PATCH] Read SHDW chunks --- addons/io_scene_swbf_msh/msh_model.py | 15 +++++++++++++++ addons/io_scene_swbf_msh/msh_scene_read.py | 22 ++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/addons/io_scene_swbf_msh/msh_model.py b/addons/io_scene_swbf_msh/msh_model.py index 3c6daf0..f83fb0b 100644 --- a/addons/io_scene_swbf_msh/msh_model.py +++ b/addons/io_scene_swbf_msh/msh_model.py @@ -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: diff --git a/addons/io_scene_swbf_msh/msh_scene_read.py b/addons/io_scene_swbf_msh/msh_scene_read.py index d4f9802..964eae0 100644 --- a/addons/io_scene_swbf_msh/msh_scene_read.py +++ b/addons/io_scene_swbf_msh/msh_scene_read.py @@ -387,7 +387,29 @@ def _read_segm(segm: Reader, materials_list: List[Material]) -> GeometrySegment: # TODO: Dont know if/how to handle trailing 0 bug yet: https://schlechtwetterfront.github.io/ze_filetypes/msh.html#STRP #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: