faces therein will be made a separate SVG group.
"""
-ID_SEPARATOR = '_____'
+ID_SEPARATOR = '_.._'
+FILL_COLOR = 'yellow'
import Blender, sys
self.msg = msg
-def get_adjacent(pool):
+def get_adjacent_faces(pool):
+ if not len(pool):
+ return []
+
i, face = pool.popitem()
group = [face]
svg.write('<?xml version="1.0" standalone="no"?>\n')
svg.write('<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">\n\n')
svg.write('<svg width="%spx" height="%spx" viewBox="0 0 %d %d" xmlns="http://www.w3.org/2000/svg"' \
- 'version="1.1" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape">\n'
+ ' version="1.1" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape">\n'
% (size, size, size, size))
svg.write("\t<desc>uv_export_svg.py: %s</desc>\n" % filename);
svg.write('\t<rect x="0" y="0" width="%d" height="%d" fill="none" stroke="blue" stroke-width="%f"/>\n'
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<g style="fill:yellow; stroke:black stroke-width:1px" inkscape:label="%s" ' \
- 'id="%s">\n' % (o.name, o.name))
+ svg.write('\t<g style="fill:%s; stroke:black stroke-width:1px" inkscape:label="%s" ' \
+ 'id="%s">\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<g>\n')
- for f in get_adjacent(pool):
- svg.write('\t\t\t<polygon points="')
+ groups.append(get_adjacent_faces(pool))
+
+ for faces in groups:
+ indent = '\t\t'
+ if len(groups) > 1:
+ svg.write('\t\t<g>\n')
+ indent = '\t\t\t'
+ for f in faces:
+ svg.write('%s<polygon id="%s%s%d" points="' % (indent, mesh.name, ID_SEPARATOR, f.index))
for p in f.uv:
svg.write('%.8f,%.8f ' % (p[0] * size, size - p[1] * size))
- svg.write('" id="%s%s%d"/>\n' % (mesh.name, ID_SEPARATOR, f.index))
- svg.write('\t\t</g>\n')
+ svg.write('"/>\n')
+ if len(groups) > 1:
+ svg.write('\t\t</g>\n')
svg.write("\t</g>\n")
"""
-ID_SEPARATOR = '_____'
+ID_SEPARATOR = '_.._'
import Blender, sys, math, re
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):
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
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]