diff options
author | Arystanbek Dyussenov <arystan.d@gmail.com> | 2010-09-04 22:49:07 +0400 |
---|---|---|
committer | Arystanbek Dyussenov <arystan.d@gmail.com> | 2010-09-04 22:49:07 +0400 |
commit | 90b464d3728d9ed8ec26fdf59058d236b99dbcd9 (patch) | |
tree | e88cab4fb1358e962b19f658064ca8c9f8d29f5b /release/scripts/op/uv.py | |
parent | 08d02dd04d836976b25793bb1d4c6a86b3f924c7 (diff) | |
parent | b0b787ef38f9947b3176642556f5282eb3518f69 (diff) |
COLLADA branch: merge from trunk -r 28015:31610.soc-2009-chingachgook
Diffstat (limited to 'release/scripts/op/uv.py')
-rw-r--r-- | release/scripts/op/uv.py | 46 |
1 files changed, 32 insertions, 14 deletions
diff --git a/release/scripts/op/uv.py b/release/scripts/op/uv.py index f22db9d87a8..238c11d6e06 100644 --- a/release/scripts/op/uv.py +++ b/release/scripts/op/uv.py @@ -29,7 +29,7 @@ class ExportUVLayout(bpy.types.Operator): bl_label = "Export UV Layout" bl_options = {'REGISTER', 'UNDO'} - path = StringProperty(name="File Path", description="File path used for exporting the SVG file", maxlen=1024, default="") + filepath = StringProperty(name="File Path", description="File path used for exporting the SVG file", maxlen=1024, default="") check_existing = BoolProperty(name="Check Existing", description="Check and warn on overwriting existing files", default=True, options={'HIDDEN'}) export_all = BoolProperty(name="All UV's", description="Export all UVs in this mesh (not just the visible ones)", default=False) mode = EnumProperty(items=( @@ -39,7 +39,8 @@ class ExportUVLayout(bpy.types.Operator): description="File format to export the UV layout to", default='SVG') - def poll(self, context): + @classmethod + def poll(cls, context): obj = context.active_object return (obj and obj.type == 'MESH') @@ -68,14 +69,14 @@ class ExportUVLayout(bpy.types.Operator): def _face_uv_iter(self, context): obj = context.active_object mesh = obj.data - uv_layer = mesh.active_uv_texture.data + uv_layer = mesh.uv_textures.active.data uv_layer_len = len(uv_layer) if not self.properties.export_all: local_image = Ellipsis - if context.tool_settings.uv_local_view: + if context.tool_settings.show_uv_local_view: space_data = self._space_image(context) if space_data: local_image = space_data.image @@ -85,9 +86,9 @@ class ExportUVLayout(bpy.types.Operator): for i in range(uv_layer_len): uv_elem = uv_layer[i] # context checks - if faces[i].selected and (local_image is Ellipsis or local_image == uv_elem.image): + if faces[i].select and (local_image is Ellipsis or local_image == uv_elem.image): #~ uv = uv_elem.uv - #~ if False not in uv_elem.uv_selected[:len(uv)]: + #~ if False not in uv_elem.select_uv[:len(uv)]: #~ yield (i, uv) # just write what we see. @@ -113,7 +114,9 @@ class ExportUVLayout(bpy.types.Operator): mode = self.properties.mode - file = open(self.properties.path, "w") + filepath = self.properties.filepath + filepath = bpy.path.ensure_ext(filepath, "." + mode.lower()) + file = open(filepath, "w") fw = file.write if mode == 'SVG': @@ -123,7 +126,7 @@ class ExportUVLayout(bpy.types.Operator): fw(' "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">\n') fw('<svg width="%dpx" height="%dpx" viewBox="0px 0px %dpx %dpx"\n' % (image_width, image_height, image_width, image_height)) fw(' xmlns="http://www.w3.org/2000/svg" version="1.1">\n') - desc = "%s, %s, %s (Blender %s)" % (basename(bpy.data.filename), obj.name, mesh.name, bpy.app.version_string) + desc = "%s, %s, %s (Blender %s)" % (basename(bpy.data.filepath), obj.name, mesh.name, bpy.app.version_string) fw('<desc>%s</desc>\n' % escape(desc)) # svg colors @@ -167,18 +170,34 @@ class ExportUVLayout(bpy.types.Operator): fw('1 setlinewidth\n') fw('1 setlinejoin\n') fw('1 setlinecap\n') + fw('/DRAW {') + # can remove from here to next comment to disable filling, aparently alpha is not supported + fw('gsave\n') + fw('0.7 setgray\n') + fw('fill\n') + fw('grestore\n') + fw('0 setgray\n') + # remove to here + fw('stroke\n') + fw('} def\n') fw('newpath\n') + firstline = True for i, uvs in self._face_uv_iter(context): for j, uv in enumerate(uvs): x, y = uv[0], uv[1] if j == 0: + if not firstline: + fw('closepath\n') + fw('DRAW\n') + fw('newpath\n') + firstline = False fw('%.5f %.5f moveto\n' % (x * image_width, y * image_height)) else: fw('%.5f %.5f lineto\n' % (x * image_width, y * image_height)) fw('closepath\n') - fw('stroke\n') + fw('DRAW\n') fw('showpage\n') fw('%%EOF\n') @@ -194,17 +213,16 @@ class ExportUVLayout(bpy.types.Operator): def menu_func(self, context): - default_path = bpy.data.filename.replace(".blend", ".svg") - self.layout.operator(ExportUVLayout.bl_idname).path = default_path + import os + default_path = os.path.splitext(bpy.data.filepath)[0] + ".svg" + self.layout.operator(ExportUVLayout.bl_idname).filepath = default_path def register(): - bpy.types.register(ExportUVLayout) bpy.types.IMAGE_MT_uvs.append(menu_func) -def unreguster(): - bpy.types.unregister(ExportUVLayout) +def unregister(): bpy.types.IMAGE_MT_uvs.remove(menu_func) if __name__ == "__main__": |