def read_vertex(self, vrtf, uvscales): vertex = Vertex() start = self.stream.tell() end = start + vrtf.stride for declaration in vrtf.declarations: u = declaration.usage value = self.read_element(declaration, uvscales[declaration.usage_index]) if u == VertexFormat.USAGE.POSITION: vertex.position = value elif u == VertexFormat.USAGE.NORMAL: vertex.normal = value elif u == VertexFormat.USAGE.UV: if vertex.uv == None: vertex.uv = [] vertex.uv.append(value) elif u == VertexFormat.USAGE.BLEND_INDEX: vertex.blend_indices = value elif u == VertexFormat.USAGE.BLEND_WEIGHT: vertex.blend_weights = value elif u == VertexFormat.USAGE.COLOR: vertex.colour = value elif u == VertexFormat.USAGE.TANGENT: vertex.tangent = value else: raise Exception("Unknown usage %s", declaration.usage) actual = self.stream.tell() return vertex
def read_rcol(self, stream, rcol): s = StreamReader(stream) self.read_tag(stream) self.version = s.u32() tgi = TGIList() tgi.begin_read(stream) self.shader = s.u32() if self.shader: end_material = s.u32() + stream.tell() self.material = MaterialBlock() self.material.read(stream, tgi) assert stream.tell() == end_material self.merge_group = s.u32() self.sort_order = s.u32() cVertices = s.u32() self.vertex_format.read(stream) for vertex_index in range(cVertices): vertex = Vertex() for declaration in self.vertex_format.declarations: if declaration.usage == self.VertexFormat.Declaration.USAGE.POSITION: vertex.position = [s.f32(), s.f32(), s.f32()] elif declaration.usage == self.VertexFormat.Declaration.USAGE.NORMAL: vertex.normal = [s.f32(), s.f32(), s.f32()] elif declaration.usage == self.VertexFormat.Declaration.USAGE.UV: uv = [s.f32(), s.f32()] if vertex.uv == None: vertex.uv = [] vertex.uv.append(uv) elif declaration.usage == self.VertexFormat.Declaration.USAGE.BLEND_INDEX: vertex.blend_indices = [s.i8(), s.i8(), s.i8(), s.i8()] elif declaration.usage == self.VertexFormat.Declaration.USAGE.BLEND_WEIGHT: vertex.blend_weights = [s.f32(), s.f32(), s.f32(), s.f32()] elif declaration.usage == self.VertexFormat.Declaration.USAGE.TANGENT: vertex.tangent = [s.f32(), s.f32(), s.f32()] elif declaration.usage == self.VertexFormat.Declaration.USAGE.COLOUR: vertex.colour = [s.u8(), s.u8(), s.u8(), s.u8()] elif declaration.usage == self.VertexFormat.Declaration.USAGE.ID: vertex.id = s.u32() self.vertices.append(vertex) assert s.u32() == 1 bytes_per_index = s.u8() assert bytes_per_index == 2 self.indices = [[s.u16() for i in range(3)] for i in range(int(s.u32() / 3))] self.skin_controller = tgi.get_resource(s.u32()) self.bones = [s.u32() for i in range(s.u32())] tgi.end_read(stream)
def read_vertex(self, vrtf, uvscales): vertex = Vertex() start = self.stream.tell() end = start + vrtf.stride for declaration in vrtf.declarations: u = declaration.usage value = self.read_element(declaration,uvscales[declaration.usage_index]) if u == VertexFormat.USAGE.POSITION: vertex.position = value elif u == VertexFormat.USAGE.NORMAL: vertex.normal = value elif u == VertexFormat.USAGE.UV: if vertex.uv == None: vertex.uv = [] vertex.uv.append(value) elif u == VertexFormat.USAGE.BLEND_INDEX: vertex.blend_indices = value elif u == VertexFormat.USAGE.BLEND_WEIGHT: vertex.blend_weights = value elif u == VertexFormat.USAGE.COLOR: vertex.colour = value elif u == VertexFormat.USAGE.TANGENT: vertex.tangent = value else: raise Exception("Unknown usage %s", declaration.usage) actual = self.stream.tell() return vertex