export_uv_png: Use grayscale FBO for drawing. #104800

Open
YimingWu wants to merge 1 commits from ChengduLittleA/blender-addons:fix-uv-export into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.

View File

@ -16,7 +16,7 @@ except ImportError:
def export(filepath, face_data, colors, width, height, opacity): def export(filepath, face_data, colors, width, height, opacity):
offscreen = gpu.types.GPUOffScreen(width, height) offscreen = gpu.types.GPUOffScreen(width, height, format="R8")
offscreen.bind() offscreen.bind()
try: try:
@ -24,8 +24,8 @@ def export(filepath, face_data, colors, width, height, opacity):
fb.clear(color=(0.0, 0.0, 0.0, 0.0)) fb.clear(color=(0.0, 0.0, 0.0, 0.0))
draw_image(face_data, opacity) draw_image(face_data, opacity)
pixel_data = fb.read_color(0, 0, width, height, 4, 0, 'UBYTE') pixel_data = fb.read_color(0, 0, width, height, 1, 0, 'UBYTE')
pixel_data.dimensions = width * height * 4 pixel_data.dimensions = width * height * 1
save_pixels(filepath, pixel_data, width, height) save_pixels(filepath, pixel_data, width, height)
finally: finally:
offscreen.unbind() offscreen.unbind()
@ -97,7 +97,7 @@ def draw_lines(face_data):
shader = gpu.shader.from_builtin('POLYLINE_UNIFORM_COLOR') shader = gpu.shader.from_builtin('POLYLINE_UNIFORM_COLOR')
shader.uniform_float("viewportSize", gpu.state.viewport_get()[2:]) shader.uniform_float("viewportSize", gpu.state.viewport_get()[2:])
shader.uniform_float("lineWidth", 1.0) shader.uniform_float("lineWidth", 1.0)
shader.uniform_float("color", (0.0, 0.0, 0.0, 1.0)) shader.uniform_float("color", (1.0, 1.0, 1.0, 1.0))
batch = batch_for_shader(shader, 'LINES', {"pos": coords}) batch = batch_for_shader(shader, 'LINES', {"pos": coords})
batch.draw(shader) batch.draw(shader)
@ -105,15 +105,18 @@ def draw_lines(face_data):
def save_pixels(filepath, pixel_data, width, height): def save_pixels(filepath, pixel_data, width, height):
if oiio: if oiio:
spec = oiio.ImageSpec(width, height, 4, "uint8") spec = oiio.ImageSpec(width, height, 1, "uint8")
image = oiio.ImageOutput.create(filepath) image = oiio.ImageOutput.create(filepath)
image.open(filepath, spec) image.open(filepath, spec)
image.write_image(pixel_data) image.write_image(pixel_data)
image.close() image.close()
return return
image = bpy.data.images.new("temp", width, height, alpha=True) image = bpy.data.images.new("temp", width, height, alpha=False)
image.filepath = filepath image.filepath = filepath
image.pixels = [v / 255 for v in pixel_data] for i in range(0,width*height):
image.pixels[i * 3 + 0] = pixel_data[i]
image.pixels[i * 3 + 1] = pixel_data[i]
image.pixels[i * 3 + 2] = pixel_data[i]
image.save() image.save()
bpy.data.images.remove(image) bpy.data.images.remove(image)