def unpack_array(stream,attribute_format,size):
if attribute_format.attribute == gx.VA_POS:
component_type = gx.ComponentType(attribute_format.component_type)
component_count = gx.PositionComponentCount(attribute_format.component_count)
array_type = Array
elif attribute_format.attribute == gx.VA_NRM:
component_type = gx.ComponentType(attribute_format.component_type)
component_count = gx.NormalComponentCount(attribute_format.component_count)
array_type = Array
elif attribute_format.attribute in gx.VA_CLR:
component_type = gx.ColorComponentType(attribute_format.component_type)
component_count = gx.ColorComponentCount(attribute_format.component_count)
array_type = ColorArray
elif attribute_format.attribute in gx.VA_TEX:
component_type = gx.ComponentType(attribute_format.component_type)
component_count = gx.TexCoordComponentCount(attribute_format.component_count)
array_type = Array
else:
raise FormatError('invalid vertex attribute')
element_type = array_type.create_element_type(component_type,component_count)
element_count = size//element_type.itemsize
array = numpy.fromfile(stream,element_type,element_count).view(array_type)
array.attribute = attribute_format.attribute
array.component_type = component_type
array.component_count = component_count
array.scale_exponent = attribute_format.scale_exponent
return array
评论列表
文章目录