def to_u8_rgba(image): if not hasattr(image, 'n') or image.m != 1: raise Exception( 'the input image needs to be a Vector field (matrix with 1 column)' ) if len(image.shape) != 2: raise Exception( "the shape of the image must be of the form (width,height)") if image.dtype == u8 and image.n == 4: # already in the desired format return image if image not in image_field_cache: staging_img = Vector.field(4, u8, image.shape) image_field_cache[image] = staging_img else: staging_img = image_field_cache[image] if image.dtype == u8: copy_image_u8_to_u8(image, staging_img, image.n) elif image.dtype == f32: copy_image_f32_to_u8(image, staging_img, image.n) else: raise Exception("dtype of input image must either be u8 or f32") return staging_img
def get_normals_field(vertices): if vertices not in normals_field_cache: N = vertices.shape[0] normals = Vector.field(3, f32, shape=(N, )) normal_weights = field(f32, shape=(N, )) normals_field_cache[vertices] = (normals, normal_weights) return (normals, normal_weights) return normals_field_cache[vertices]
def get_vbo_field(vertices): if vertices not in vbo_field_cache: N = vertices.shape[0] pos = 3 normal = 3 tex_coord = 2 color = 4 vertex_stride = pos + normal + tex_coord + color vbo = Vector.field(vertex_stride, f32, shape=(N, )) vbo_field_cache[vertices] = vbo return vbo return vbo_field_cache[vertices]