diff --git a/io_mesh_uv_layout/export_uv_png.py b/io_mesh_uv_layout/export_uv_png.py index 784337be4..212b2bab1 100644 --- a/io_mesh_uv_layout/export_uv_png.py +++ b/io_mesh_uv_layout/export_uv_png.py @@ -16,7 +16,7 @@ except ImportError: 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() 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)) draw_image(face_data, opacity) - pixel_data = fb.read_color(0, 0, width, height, 4, 0, 'UBYTE') - pixel_data.dimensions = width * height * 4 + pixel_data = fb.read_color(0, 0, width, height, 1, 0, 'UBYTE') + pixel_data.dimensions = width * height * 1 save_pixels(filepath, pixel_data, width, height) finally: offscreen.unbind() @@ -97,7 +97,7 @@ def draw_lines(face_data): shader = gpu.shader.from_builtin('POLYLINE_UNIFORM_COLOR') shader.uniform_float("viewportSize", gpu.state.viewport_get()[2:]) 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.draw(shader) @@ -105,15 +105,19 @@ def draw_lines(face_data): def save_pixels(filepath, pixel_data, width, height): if oiio: - spec = oiio.ImageSpec(width, height, 4, "uint8") + spec = oiio.ImageSpec(width, height, 1, "uint8") image = oiio.ImageOutput.create(filepath) image.open(filepath, spec) image.write_image(pixel_data) image.close() 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.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.pixels = [v / 255 for v in pixel_data] image.save() bpy.data.images.remove(image)