[Bf-extensions-cvs] [c901253] master: tabs -> spaces, move info to top (faster scanning)

Campbell Barton noreply at git.blender.org
Tue Feb 10 14:21:08 CET 2015


Commit: c9012531d4480090327660434498add06d233723
Author: Campbell Barton
Date:   Wed Feb 11 00:18:55 2015 +1100
Branches: master
https://developer.blender.org/rBACc9012531d4480090327660434498add06d233723

tabs -> spaces, move info to top (faster scanning)

===================================================================

M	io_export_paper_model.py

===================================================================

diff --git a/io_export_paper_model.py b/io_export_paper_model.py
index 5fd8719..4ed6cbd 100644
--- a/io_export_paper_model.py
+++ b/io_export_paper_model.py
@@ -16,6 +16,20 @@
 #
 # ##### END GPL LICENSE BLOCK #####
 
+bl_info = {
+    "name": "Export Paper Model",
+    "author": "Addam Dominec",
+    "version": (0, 9),
+    "blender": (2, 70, 0),
+    "location": "File > Export > Paper Model",
+    "warning": "",
+    "description": "Export printable net of the active mesh (as an SVG file)",
+    "category": "Import-Export",
+    "wiki_url": "http://wiki.blender.org/index.php/Extensions:2.6/Py/"
+                "Scripts/Import-Export/Paper_Model",
+    "tracker_url": "https://developer.blender.org/T38441"
+}
+
 #### TODO:
 # sanitize the constructors so that they don't edit their parent object
 # rename verts -> vertices, edge.vect -> edge.vector
@@ -32,24 +46,10 @@
 #  * enumerate faces uniquely within all islands of the same name (requires a check that both label and abbr. equals)
 
 
-bl_info = {
-	"name": "Export Paper Model",
-	"author": "Addam Dominec",
-	"version": (0, 9),
-	"blender": (2, 70, 0),
-	"location": "File > Export > Paper Model",
-	"warning": "",
-	"description": "Export printable net of the active mesh",
-	"category": "Import-Export",
-	"wiki_url": "http://wiki.blender.org/index.php/Extensions:2.6/Py/"
-		"Scripts/Import-Export/Paper_Model",
-	"tracker_url": "https://developer.blender.org/T38441"
-}
-
 """
 
 Additional links:
-	e-mail: adominec {at} gmail {dot} com
+    e-mail: adominec {at} gmail {dot} com
 
 """
 import bpy
@@ -61,2092 +61,2092 @@ from itertools import chain
 from math import pi
 
 try:
-	import os.path as os_path
+    import os.path as os_path
 except ImportError:
-	os_path = None
+    os_path = None
 
 try:
-	from blist import blist
+    from blist import blist
 except ImportError:
-	blist = list
+    blist = list
 
 default_priority_effect = {
-	'CONVEX': 0.5,
-	'CONCAVE': 1,
-	'LENGTH': -0.05
+    'CONVEX': 0.5,
+    'CONCAVE': 1,
+    'LENGTH': -0.05
 }
 
 
 def first_letters(text):
-	"""Iterator over the first letter of each word"""
-	for match in first_letters.pattern.finditer(text):
-		yield text[match.start()]
+    """Iterator over the first letter of each word"""
+    for match in first_letters.pattern.finditer(text):
+        yield text[match.start()]
 first_letters.pattern = re_compile("(?<!\w)[\w]")
 
 
 def pairs(sequence):
-	"""Generate consecutive pairs throughout the given sequence; at last, it gives elements last, first."""
-	i = iter(sequence)
-	previous = first = next(i)
-	for this in i:
-		yield previous, this
-		previous = this
-	yield this, first
+    """Generate consecutive pairs throughout the given sequence; at last, it gives elements last, first."""
+    i = iter(sequence)
+    previous = first = next(i)
+    for this in i:
+        yield previous, this
+        previous = this
+    yield this, first
 
 
 def argmax_pair(array, key):
-	"""Find an (unordered) pair of indices that maximize the given function"""
-	l = len(array)
-	mi, mj, m = None, None, None
-	for i in range(l):
-		for j in range(i+1, l):
-			k = key(array[i], array[j])
-			if not m or k > m:
-				mi, mj, m = i, j, k
-	return mi, mj
+    """Find an (unordered) pair of indices that maximize the given function"""
+    l = len(array)
+    mi, mj, m = None, None, None
+    for i in range(l):
+        for j in range(i+1, l):
+            k = key(array[i], array[j])
+            if not m or k > m:
+                mi, mj, m = i, j, k
+    return mi, mj
 
 
 def fitting_matrix(v1, v2):
-	"""Get a matrix that rotates v1 to the same direction as v2"""
-	return (1 / v1.length_squared) * M.Matrix((
-		(v1.x*v2.x + v1.y*v2.y, v1.y*v2.x - v1.x*v2.y),
-		(v1.x*v2.y - v1.y*v2.x, v1.x*v2.x + v1.y*v2.y)))
+    """Get a matrix that rotates v1 to the same direction as v2"""
+    return (1 / v1.length_squared) * M.Matrix((
+        (v1.x*v2.x + v1.y*v2.y, v1.y*v2.x - v1.x*v2.y),
+        (v1.x*v2.y - v1.y*v2.x, v1.x*v2.x + v1.y*v2.y)))
 
 
 def z_up_matrix(n):
-	"""Get a rotation matrix that aligns given vector upwards."""
-	b = n.xy.length
-	l = n.length
-	if b > 0:
-		return M.Matrix((
-			(n.x*n.z/(b*l), n.y*n.z/(b*l), -b/l),
-			(-n.y/b, n.x/b, 0),
-			(0, 0, 0)
-		))
-	else:
-		# no need for rotation
-		return M.Matrix((
-			(1, 0, 0),
-			(0, (-1 if n.z < 0 else 1), 0),
-			(0, 0, 0)
-		))
+    """Get a rotation matrix that aligns given vector upwards."""
+    b = n.xy.length
+    l = n.length
+    if b > 0:
+        return M.Matrix((
+            (n.x*n.z/(b*l), n.y*n.z/(b*l), -b/l),
+            (-n.y/b, n.x/b, 0),
+            (0, 0, 0)
+        ))
+    else:
+        # no need for rotation
+        return M.Matrix((
+            (1, 0, 0),
+            (0, (-1 if n.z < 0 else 1), 0),
+            (0, 0, 0)
+        ))
 
 
 def create_blank_image(image_name, dimensions, alpha=1):
-	"""Create a new image and assign white color to all its pixels"""
-	image_name = image_name[:64]
-	width, height = int(dimensions.x), int(dimensions.y)
-	image = bpy.data.images.new(image_name, width, height, alpha=True)
-	if image.users > 0:
-		raise UnfoldError("There is something wrong with the material of the model. "
-			"Please report this on the BlenderArtists forum. Export failed.")
-	image.pixels = [1, 1, 1, alpha] * (width * height)
-	image.file_format = 'PNG'
-	return image
+    """Create a new image and assign white color to all its pixels"""
+    image_name = image_name[:64]
+    width, height = int(dimensions.x), int(dimensions.y)
+    image = bpy.data.images.new(image_name, width, height, alpha=True)
+    if image.users > 0:
+        raise UnfoldError("There is something wrong with the material of the model. "
+            "Please report this on the BlenderArtists forum. Export failed.")
+    image.pixels = [1, 1, 1, alpha] * (width * height)
+    image.file_format = 'PNG'
+    return image
 
 
 class UnfoldError(ValueError):
-	pass
+    pass
 
 
 class Unfolder:
-	def __init__(self, ob):
-		self.ob = ob
-		self.mesh = Mesh(ob.data, ob.matrix_world)
-		self.tex = None
-
-	def prepare(self, cage_size=None, create_uvmap=False, mark_seams=False, priority_effect=default_priority_effect, scale=1):
-		"""Create the islands of the net"""
-		self.mesh.generate_cuts(cage_size / scale if cage_size else None, priority_effect)
-		self.mesh.finalize_islands()
-		self.mesh.enumerate_islands()
-		if create_uvmap:
-			self.tex = self.mesh.save_uv()
-		if mark_seams:
-			self.mesh.mark_cuts()
-	
-	def copy_island_names(self, island_list):
-		"""Copy island label and abbreviation from the best matching island in the list"""
-		orig_list = {(frozenset(face.id for face in item.faces), item.label, item.abbreviation) for item in island_list}
-		for island in self.mesh.islands:
-			islfaces = {uvface.face.index for uvface in island.faces}
-			match = max(orig_list, key=lambda item: islfaces.intersection(item[0]))
-			island.label = match[1]
-			island.abbreviation = match[2]
-	
-	def save(self, properties):
-		"""Export the document"""
-		# Note about scale: input is direcly in blender length
-		# Island.apply_scale multiplies everything by a user-defined ratio
-		# SVG object multiplies everything by ppm (output in pixels)
-		filepath = properties.filepath
-		if filepath.lower().endswith((".svg", ".png")):
-			filepath = filepath[0:-4]
-		# page size in meters
-		page_size = M.Vector((properties.output_size_x, properties.output_size_y))
-		# printable area size in meters
-		printable_size = page_size - 2 * properties.output_margin * M.Vector((1, 1))
-		unit_scale = bpy.context.scene.unit_settings.scale_length
-		ppm = properties.output_dpi * 100 / 2.54  # pixels per meter
-		
-		# after this call, all dimensions will be in meters
-		self.mesh.scale_islands(unit_scale/properties.scale)
-		if properties.do_create_stickers:
-			self.mesh.generate_stickers(properties.sticker_width, properties.do_create_numbers)
-		elif properties.do_create_numbers:
-			self.mesh.generate_numbers_alone(properties.sticker_width)
-			
-		text_height = properties.sticker_width if (properties.do_create_numbers and len(self.mesh.islands) > 1) else 0
-		aspect_ratio = printable_size.x / printable_size.y
-		# finalizing islands will scale everything so that the page height is 1
-		self.mesh.finalize_islands(title_height=text_height)
-		self.mesh.fit_islands(cage_size=printable_size)
-		
-		if properties.output_type != 'NONE':
-			# bake an image and save it as a PNG to disk or into memory
-			use_separate_images = properties.image_packing in ('ISLAND_LINK', 'ISLAND_EMBED')
-			tex = self.mesh.save_uv(cage_size=printable_size, separate_image=use_separate_images, tex=self.tex)
-			if not tex:
-				raise UnfoldError("The mesh has no UV Map slots left. Either delete a UV Map or export the net without textures.")
-			rd = bpy.context.scene.render
-			recall = rd.bake_type, rd.use_bake_to_vertex_color, rd.use_bake_selected_to_active, rd.bake_distance, rd.bake_bias, rd.bake_margin, rd.use_bake_clear
-			
-			rd.bake_type = 'TEXTURE' if properties.output_type == 'TEXTURE' else 'FULL'
-			rd.use_bake_selected_to_active = (properties.output_type == 'SELECTED_TO_ACTIVE')
-			
-			rd.bake_margin, rd.bake_distance, rd.bake_bias, rd.use_bake_to_vertex_color, rd.use_bake_clear = 0, 0, 0.001, False, False
-			if properties.image_packing == 'PAGE_LINK':
-				self.mesh.save_image(tex, printable_size * ppm, filepath)
-			elif properties.image_packing == 'ISLAND_LINK':
-				self.mesh.save_separate_images(tex, printable_size.y * ppm, filepath)
-			elif properties.image_packing == 'ISLAND_EMBED':
-				self.mesh.save_separate_images(tex, printable_size.y * ppm, filepath, do_embed=True)
-			
-			# revoke settings
-			rd.bake_type, rd.use_bake_to_vertex_color, rd.use_bake_selected_to_active, rd.bake_distance, rd.bake_bias, rd.bake_margin, rd.use_bake_clear = recall
-			if not properties.do_create_uvmap:
-				tex.active = True
-				bpy.ops.mesh.uv_texture_remove()
-
-		svg = SVG(page_size, ppm, properties.style, (properties.output_type == 'NONE'))
-		svg.do_create_stickers = properties.do_create_stickers
-		svg.margin = properties.output_margin
-		svg.text_size = properties.sticker_width
-		svg.write(self.

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list