Read SHDW chunks
This commit is contained in:
		@@ -39,6 +39,20 @@ class VertexWeight:
 | 
				
			|||||||
    weight: float = 1.0
 | 
					    weight: float = 1.0
 | 
				
			||||||
    bone: int = 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
 | 
					@dataclass
 | 
				
			||||||
class GeometrySegment:
 | 
					class GeometrySegment:
 | 
				
			||||||
    """ Class representing a 'SEGM' section in a .msh file. """
 | 
					    """ Class representing a 'SEGM' section in a .msh file. """
 | 
				
			||||||
@@ -56,6 +70,7 @@ class GeometrySegment:
 | 
				
			|||||||
    triangles: List[List[int]] = field(default_factory=list)
 | 
					    triangles: List[List[int]] = field(default_factory=list)
 | 
				
			||||||
    triangle_strips: List[List[int]] = None
 | 
					    triangle_strips: List[List[int]] = None
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    shadow_geometry: ShadowGeometry = None
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@dataclass
 | 
					@dataclass
 | 
				
			||||||
class CollisionPrimitive:
 | 
					class CollisionPrimitive:
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -388,6 +388,28 @@ def _read_segm(segm: Reader, materials_list: List[Material]) -> GeometrySegment:
 | 
				
			|||||||
            #if segm.read_u16 != 0: 
 | 
					            #if segm.read_u16 != 0: 
 | 
				
			||||||
            #    segm.skip_bytes(-2)
 | 
					            #    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":
 | 
					        elif next_header == "WGHT":
 | 
				
			||||||
            with segm.read_child() as wght:
 | 
					            with segm.read_child() as wght:
 | 
				
			||||||
                
 | 
					                
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user