def split_normal(self, image: bpy.types.Image): roughness_name = self.new_texture_name_with_suffix( image.name, 'roughness', 'tga') if image.get('normalmap_converted', None): return image, bpy.data.images.get(roughness_name, None) if bpy.app.version > (2, 83, 0): buffer = np.zeros(image.size[0] * image.size[1] * 4, np.float32) image.pixels.foreach_get(buffer) else: buffer = np.array(image.pixels[:]) mask = buffer[2::4] roughness_rgb = np.dstack((mask, mask, mask, np.ones_like(mask))) roughness_texture = Source2ShaderBase.make_texture( roughness_name, image.size, roughness_rgb, True) buffer[1::4] = np.subtract(1, buffer[1::4]) buffer[2::4] = 1.0 if bpy.app.version > (2, 83, 0): image.pixels.foreach_set(buffer.tolist()) else: image.pixels[:] = buffer.tolist() image.pack() image['normalmap_converted'] = True return image, roughness_texture
def convert_normalmap(image: bpy.types.Image): if image.get('normalmap_converted', None): return image if bpy.app.version > (2, 83, 0): buffer = np.zeros(image.size[0] * image.size[1] * 4, np.float32) image.pixels.foreach_get(buffer) else: buffer = np.array(image.pixels[:]) buffer[1::4] = np.subtract(1, buffer[1::4]) if bpy.app.version > (2, 83, 0): image.pixels.foreach_set(buffer.tolist()) else: image.pixels[:] = buffer.tolist() image.pack() image['normalmap_converted'] = True return image
def convert_ssbump(image: bpy.types.Image): if image.get('ssbump_converted', None): return image if bpy.app.version > (2, 83, 0): buffer = np.zeros(image.size[0] * image.size[1] * 4, np.float32) image.pixels.foreach_get(buffer) else: buffer = np.array(image.pixels[:]) buffer[0::4] *= 0.5 buffer[0::4] += 0.33 buffer[1::4] *= 0.5 buffer[1::4] += 0.33 buffer[2::4] *= 0.2 buffer[2::4] += 0.8 if bpy.app.version > (2, 83, 0): image.pixels.foreach_set(buffer.tolist()) else: image.pixels[:] = buffer.tolist() image.pack() image['ssbump_converted'] = True return image