我们从Python开源项目中,提取了以下1个代码示例,用于说明如何使用numpy.ushort()。
def setup_textures(gltf, uri_path): # TODO: support data URIs pil_images = {} for image_name, image in gltf.get('images', {}).items(): filename = os.path.join(uri_path, image['uri']) pil_image = Image.open(filename) pil_images[image_name] = pil_image _logger.debug('* loaded image "%s" (from %s)', image_name, filename) for texture_name, texture in gltf.get('textures', {}).items(): sampler = gltf['samplers'][texture['sampler']] texture_id = gl.glGenTextures(1) gl.glBindTexture(texture['target'], texture_id) sampler_id = gl.glGenSamplers(1) gl.glSamplerParameteri(sampler_id, gl.GL_TEXTURE_MIN_FILTER, sampler.get('minFilter', 9986)) gl.glSamplerParameteri(sampler_id, gl.GL_TEXTURE_MAG_FILTER, sampler.get('magFilter', 9729)) gl.glSamplerParameteri(sampler_id, gl.GL_TEXTURE_WRAP_S, sampler.get('wrapS', 10497)) gl.glSamplerParameteri(sampler_id, gl.GL_TEXTURE_WRAP_T, sampler.get('wrapT', 10497)) sampler['id'] = sampler_id gl.glPixelStorei(gl.GL_UNPACK_ALIGNMENT, 1) if texture['type'] != gl.GL_UNSIGNED_BYTE: raise Exception('TODO') gl.glTexImage2D(texture['target'], 0, texture['internalFormat'], pil_image.width, pil_image.height, 0, gl.GL_RGB, #texture['format'], # INVESTIGATE texture['type'], np.array(list(pil_image.getdata()), dtype=(np.ubyte if texture['type'] == gl.GL_UNSIGNED_BYTE else np.ushort))) gl.glGenerateMipmap(texture['target']) if gl.glGetError() != gl.GL_NO_ERROR: raise Exception('failed to create texture "%s"' % texture_name) texture['id'] = texture_id _logger.debug('* created texture "%s"', texture_name)