Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2022-07-29 08:33:17 +0300
committerCampbell Barton <ideasman42@gmail.com>2022-07-29 08:33:17 +0300
commit8669c66177eab49871e9ae758c74da05cce89adf (patch)
tree7705bd59a43fd4174924a873ec9e947f68470eb1
parentec534daa9801efbe5cfb92aaf0b8ecef134941f2 (diff)
Cleanup: run autopep8 on io_mesh_uv_layout
-rw-r--r--io_mesh_uv_layout/export_uv_eps.py6
-rw-r--r--io_mesh_uv_layout/export_uv_png.py20
-rw-r--r--io_mesh_uv_layout/export_uv_svg.py6
3 files changed, 26 insertions, 6 deletions
diff --git a/io_mesh_uv_layout/export_uv_eps.py b/io_mesh_uv_layout/export_uv_eps.py
index 04b8a38e..9e013e13 100644
--- a/io_mesh_uv_layout/export_uv_eps.py
+++ b/io_mesh_uv_layout/export_uv_eps.py
@@ -8,6 +8,7 @@ def export(filepath, face_data, colors, width, height, opacity):
for text in get_file_parts(face_data, colors, width, height, opacity):
file.write(text)
+
def get_file_parts(face_data, colors, width, height, opacity):
yield from header(width, height)
if opacity > 0.0:
@@ -35,6 +36,7 @@ def header(width, height):
yield "1 setlinejoin\n"
yield "1 setlinecap\n"
+
def prepare_colors(colors, out_name_by_color):
for i, color in enumerate(colors):
name = f"COLOR_{i}"
@@ -48,18 +50,21 @@ def prepare_colors(colors, out_name_by_color):
yield "0 setgray\n"
yield "} def\n"
+
def draw_colored_polygons(face_data, name_by_color, width, height):
for uvs, color in face_data:
yield from draw_polygon_path(uvs, width, height)
yield "closepath\n"
yield "%s\n" % name_by_color[color]
+
def draw_lines(face_data, width, height):
for uvs, _ in face_data:
yield from draw_polygon_path(uvs, width, height)
yield "closepath\n"
yield "stroke\n"
+
def draw_polygon_path(uvs, width, height):
yield "newpath\n"
for j, uv in enumerate(uvs):
@@ -69,6 +74,7 @@ def draw_polygon_path(uvs, width, height):
else:
yield "%.5f %.5f lineto\n" % uv_scale
+
def footer():
yield "showpage\n"
yield "%%EOF\n"
diff --git a/io_mesh_uv_layout/export_uv_png.py b/io_mesh_uv_layout/export_uv_png.py
index b7110c73..b051c980 100644
--- a/io_mesh_uv_layout/export_uv_png.py
+++ b/io_mesh_uv_layout/export_uv_png.py
@@ -6,6 +6,7 @@ from mathutils import Vector, Matrix
from mathutils.geometry import tessellate_polygon
from gpu_extras.batch import batch_for_shader
+
def export(filepath, face_data, colors, width, height, opacity):
offscreen = gpu.types.GPUOffScreen(width, height)
offscreen.bind()
@@ -22,6 +23,7 @@ def export(filepath, face_data, colors, width, height, opacity):
offscreen.unbind()
offscreen.free()
+
def draw_image(face_data, opacity):
gpu.state.blend_set('ALPHA_PREMULT')
@@ -34,6 +36,7 @@ def draw_image(face_data, opacity):
gpu.state.blend_set('NONE')
+
def get_normalize_uvs_matrix():
'''matrix maps x and y coordinates from [0, 1] to [-1, 1]'''
matrix = Matrix.Identity(4)
@@ -43,6 +46,7 @@ def get_normalize_uvs_matrix():
matrix[1][1] = 2
return matrix
+
def draw_background_colors(face_data, opacity):
coords = [uv for uvs, _ in face_data for uv in uvs]
colors = [(*color, opacity) for uvs, color in face_data for _ in range(len(uvs))]
@@ -55,28 +59,31 @@ def draw_background_colors(face_data, opacity):
offset += len(uvs)
shader = gpu.shader.from_builtin('2D_FLAT_COLOR')
- batch = batch_for_shader(shader, 'TRIS',
- {"pos" : coords,
- "color" : colors},
- indices=indices)
+ batch = batch_for_shader(
+ shader, 'TRIS',
+ {"pos": coords, "color": colors},
+ indices=indices,
+ )
batch.draw(shader)
+
def tessellate_uvs(uvs):
return tessellate_polygon([uvs])
+
def draw_lines(face_data):
coords = []
for uvs, _ in face_data:
for i in range(len(uvs)):
start = uvs[i]
- end = uvs[(i+1) % len(uvs)]
+ end = uvs[(i + 1) % len(uvs)]
coords.append((start[0], start[1]))
coords.append((end[0], end[1]))
# Use '2D_UNIFORM_COLOR' in the `batch_for_shader` so we don't need to
# convert the coordinates to 3D as in the case of
# '3D_POLYLINE_UNIFORM_COLOR'.
- batch = batch_for_shader(gpu.shader.from_builtin('2D_UNIFORM_COLOR'), 'LINES', {"pos" : coords})
+ batch = batch_for_shader(gpu.shader.from_builtin('2D_UNIFORM_COLOR'), 'LINES', {"pos": coords})
shader = gpu.shader.from_builtin('3D_POLYLINE_UNIFORM_COLOR')
shader.bind()
shader.uniform_float("viewportSize", gpu.state.viewport_get()[2:])
@@ -84,6 +91,7 @@ def draw_lines(face_data):
shader.uniform_float("color", (0, 0, 0, 1))
batch.draw(shader)
+
def save_pixels(filepath, pixel_data, width, height):
image = bpy.data.images.new("temp", width, height, alpha=True)
image.filepath = filepath
diff --git a/io_mesh_uv_layout/export_uv_svg.py b/io_mesh_uv_layout/export_uv_svg.py
index d8e2b5a4..a4b6a3c3 100644
--- a/io_mesh_uv_layout/export_uv_svg.py
+++ b/io_mesh_uv_layout/export_uv_svg.py
@@ -4,16 +4,19 @@ import bpy
from os.path import basename
from xml.sax.saxutils import escape
+
def export(filepath, face_data, colors, width, height, opacity):
with open(filepath, 'w', encoding='utf-8') as file:
for text in get_file_parts(face_data, colors, width, height, opacity):
file.write(text)
+
def get_file_parts(face_data, colors, width, height, opacity):
yield from header(width, height)
yield from draw_polygons(face_data, width, height, opacity)
yield from footer()
+
def header(width, height):
yield '<?xml version="1.0" standalone="no"?>\n'
yield '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" \n'
@@ -23,6 +26,7 @@ def header(width, height):
desc = f"{basename(bpy.data.filepath)}, (Blender {bpy.app.version_string})"
yield f'<desc>{escape(desc)}</desc>\n'
+
def draw_polygons(face_data, width, height, opacity):
for uvs, color in face_data:
fill = f'fill="{get_color_string(color)}"'
@@ -37,10 +41,12 @@ def draw_polygons(face_data, width, height, opacity):
yield f'{x*width:.3f},{y*height:.3f} '
yield '" />\n'
+
def get_color_string(color):
r, g, b = color
return f"rgb({round(r*255)}, {round(g*255)}, {round(b*255)})"
+
def footer():
yield '\n'
yield '</svg>\n'