diff --git a/utils/Modeller/uv_export_svg.py b/utils/Modeller/uv_export_svg.py index a04701f77..fd70aca29 100644 --- a/utils/Modeller/uv_export_svg.py +++ b/utils/Modeller/uv_export_svg.py @@ -16,7 +16,8 @@ script can be used to re-import such a file. Each object and each group of adjac faces therein will be made a separate SVG group. """ -ID_SEPARATOR = '_____' +ID_SEPARATOR = '_.._' +FILL_COLOR = 'yellow' import Blender, sys @@ -27,7 +28,10 @@ class Abort(Exception): self.msg = msg -def get_adjacent(pool): +def get_adjacent_faces(pool): + if not len(pool): + return [] + i, face = pool.popitem() group = [face] @@ -64,7 +68,7 @@ def write_svg(filename): svg.write('\n') svg.write('\n\n') svg.write('\n' + ' version="1.1" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape">\n' % (size, size, size, size)) svg.write("\tuv_export_svg.py: %s\n" % filename); svg.write('\t\n' @@ -79,25 +83,32 @@ def write_svg(filename): if not mesh.faceUV: continue if mesh.name in unique_meshes: - #print "dropping duplicate mesh", mesh.name, "of object", o.name continue unique_meshes[mesh.name] = True - svg.write('\t\n' % (o.name, o.name)) + svg.write('\t\n' % (FILL_COLOR, o.name, o.name)) pool = {} for f in mesh.faces: pool[f.index] = f + groups = [] while len(pool): - svg.write('\t\t\n') - for f in get_adjacent(pool): - svg.write('\t\t\t\n' % (mesh.name, ID_SEPARATOR, f.index)) - svg.write('\t\t\n') + svg.write('"/>\n') + if len(groups) > 1: + svg.write('\t\t\n') svg.write("\t\n") diff --git a/utils/Modeller/uv_import_svg.py b/utils/Modeller/uv_import_svg.py index e934be5ee..02c5715f6 100755 --- a/utils/Modeller/uv_import_svg.py +++ b/utils/Modeller/uv_import_svg.py @@ -19,7 +19,7 @@ The choice has been made when the file was saved! """ -ID_SEPARATOR = '_____' +ID_SEPARATOR = '_.._' import Blender, sys, math, re @@ -46,12 +46,12 @@ class Matrix: return "[Matrix %f %f %f %f %f %f]" % (self.a, self.b, self.c, self.d, self.e, self.f) def multiply(self, mat): - a = self.a * mat.a + self.c * mat.b - b = self.b * mat.a + self.d * mat.b - c = self.a * mat.c + self.c * mat.d - d = self.b * mat.c + self.d * mat.d - e = self.a * mat.e + self.c * mat.f + self.e - f = self.b * mat.e + self.d * mat.f + self.f + a = mat.a * self.a + mat.c * self.b + b = mat.b * self.a + mat.d * self.b + c = mat.a * self.c + mat.c * self.d + d = mat.b * self.c + mat.d * self.d + e = mat.a * self.e + mat.c * self.f + mat.e + f = mat.b * self.e + mat.d * self.f + mat.f self.a = a; self.b = b; self.c = c; self.d = d; self.e = e; self.f = f def transform(self, u, v): @@ -231,14 +231,12 @@ class import_svg: print('bad polygon "%s"' % ident) return - sep = ident.find(ID_SEPARATOR) - if sep < 0: + try: + meshname, num = ident.strip().split(ID_SEPARATOR, 2) + except: print('broken id "%s"' % ident) return - meshname = str(ident[:sep]) - num = int(ident[sep + len(ID_SEPARATOR):]) - if not meshname in self.meshes: print('unknown mesh "%s"' % meshname) return @@ -254,7 +252,7 @@ class import_svg: u, v = matrix.transform(u, v) transuv.append((u / self.width, 1 - v / self.height)) - for i, uv in enumerate(self.meshes[meshname].faces[num].uv): + for i, uv in enumerate(self.meshes[meshname].faces[int(num)].uv): uv[0] = transuv[i][0] uv[1] = transuv[i][1]