[Bf-extensions-cvs] [ee2cd71] : Backport revisions for the 2.70a release

Sergey Sharybin noreply at git.blender.org
Thu Apr 10 12:56:54 CEST 2014


Commit: ee2cd7105d505a4f6b4613aba26598f532f97f30
Author: Sergey Sharybin
Date:   Wed Apr 9 17:33:37 2014 +0600
https://developer.blender.org/rBAee2cd7105d505a4f6b4613aba26598f532f97f30

Backport revisions for the 2.70a release

fa5cbcd, 95a9c96, 31bccec, c6e1af6.

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

M	add_mesh_extra_objects/add_mesh_teapot.py
M	io_scene_obj/export_obj.py

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

diff --git a/add_mesh_extra_objects/add_mesh_teapot.py b/add_mesh_extra_objects/add_mesh_teapot.py
index 2771dd7..dc4d575 100644
--- a/add_mesh_extra_objects/add_mesh_teapot.py
+++ b/add_mesh_extra_objects/add_mesh_teapot.py
@@ -16,7 +16,7 @@
 #
 # This program is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	See the
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU General Public License for more details.
 #
 # You should have received a copy of the GNU General Public License
@@ -34,44 +34,74 @@ bl_info = {
     "url": "http://wiki.blender.org/index.php/Extensions:2.5/Py/Scripts/Add_Teapot",
     "category": "Add Mesh"}
 '''
-import bpy, mathutils, io, operator, functools
+
+import bpy
+from bpy.props import IntProperty
+
+import mathutils
+
+import io
+import operator
+import functools
+
 
 class AddTeapot(bpy.types.Operator):
-	"""Add a teapot mesh"""
-	bl_idname = "mesh.primitive_teapot_add"
-	bl_label = "Add Teapot"
-	bl_options = {"REGISTER", "UNDO"}
-
-	resolution = bpy.props.IntProperty(name="Resolution",
-		description="Resolution of the Teapot",
-		default=5, min=2, max=15)
-
-	objecttype = bpy.props.IntProperty(name="Object Type",
-		description="Type of Bezier Object",
-		default=1, min=1, max=2)
-
-	def execute(self, context):
-		verts, faces = make_teapot(self.objecttype,
-								   self.resolution)
-		# Actually create the mesh object from this geometry data.
-		obj = create_mesh_object(context, verts, [], faces, "Teapot")
-		return {'FINISHED'}
+    """Add a teapot mesh"""
+    bl_idname = "mesh.primitive_teapot_add"
+    bl_label = "Add Teapot"
+    bl_options = {"REGISTER", "UNDO"}
+
+    resolution = IntProperty(
+            name="Resolution",
+            description="Resolution of the Teapot",
+            default=5, min=2, max=15,
+            )
+    objecttype = IntProperty(
+            name="Object Type",
+            description="Type of Bezier Object",
+            default=1, min=1, max=2)
+
+    def execute(self, context):
+        verts, faces = make_teapot(self.objecttype,
+                                   self.resolution)
+        # Actually create the mesh object from this geometry data.
+        obj = create_mesh_object(context, verts, [], faces, "Teapot")
+        return {'FINISHED'}
+
 
 def menu_func(self, context):
-	self.layout.operator(AddTeapot.bl_idname, text="Teapot+", icon="MESH_CUBE")
+    self.layout.operator(AddTeapot.bl_idname, text="Teapot+", icon="MESH_CUBE")
+
 
 def register():
-	bpy.utils.register_module(__name__)
-	bpy.types.INFO_MT_mesh_add.append(menu_func)
+    bpy.utils.register_module(__name__)
+    bpy.types.INFO_MT_mesh_add.append(menu_func)
+
 
 def unregister():
-	bpy.utils.unregister_module(__name__)
-	bpy.types.INFO_MT_mesh_add.remove(menu_func)
+    bpy.utils.unregister_module(__name__)
+    bpy.types.INFO_MT_mesh_add.remove(menu_func)
 
 if __name__ == "__main__":
-	register()
+    register()
+
+
+def create_mesh_face_hack(faces):
+    # FIXME, faces with duplicate vertices shouldn't be created in the first place.
+    faces_copy = []
+    for f in faces:
+        f_copy = []
+        for i in f:
+            if i not in f_copy:
+                f_copy.append(i)
+        faces_copy.append(f_copy)
+    faces[:] = faces_copy
+
 
 def create_mesh_object(context, verts, edges, faces, name):
+
+    create_mesh_face_hack(faces)
+
     # Create new mesh
     mesh = bpy.data.meshes.new(name)
     # Make a mesh from a list of verts/edges/faces.
@@ -81,139 +111,140 @@ def create_mesh_object(context, verts, edges, faces, name):
     from bpy_extras import object_utils
     return object_utils.object_data_add(context, mesh, operator=None)
 
+
 # ==========================
 # === Bezier patch Block ===
 # ==========================
 def read_indexed_patch_file(filename):
-	file = io.StringIO(filename)
-	rawpatches = []
-	patches = []
-	numpatches = int(file.readline())
-	for i in range(numpatches):
-		line = file.readline()
-		a,b,c,d, e,f,g,h, i,j,k,l, m,n,o,p = map(int, line.split(","))
-		patches.append([[a,b,c,d], [e,f,g,h], [i,j,k,l], [m,n,o,p]])
-		rawpatches.append([[0,0,0,0], [0,0,0,0], [0,0,0,0], [0,0,0,0]])
-	verts = []
-	numverts = int(file.readline())
-	for i in range(numverts):
-		line = file.readline()
-		v1,v2,v3 = map(float, line.split(","))
-		verts.append((v1,v2,v3))
-	for i in range(len(patches)):
-		for j in range(4):	#len(patches[i])):
-			for k in range(4):	#len(patches[i][j])):
-				index = patches[i][j][k] - 1
-				rawpatches[i][j][k] = verts[index]
-	return rawpatches
+    file = io.StringIO(filename)
+    rawpatches = []
+    patches = []
+    numpatches = int(file.readline())
+    for i in range(numpatches):
+        line = file.readline()
+        (a, b, c, d,
+         e, f, g, h,
+         i, j, k, l,
+         m, n, o, p,
+         ) = map(int, line.split(","))
+        patches.append([[a, b, c, d], [e, f, g, h], [i, j, k, l], [m, n, o, p]])
+        rawpatches.append([[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]])
+    verts = []
+    numverts = int(file.readline())
+    for i in range(numverts):
+        line = file.readline()
+        v1, v2, v3 = map(float, line.split(","))
+        verts.append((v1, v2, v3))
+    for i in range(len(patches)):
+        for j in range(4):  # len(patches[i])):
+            for k in range(4):  # len(patches[i][j])):
+                index = patches[i][j][k] - 1
+                rawpatches[i][j][k] = verts[index]
+    return rawpatches
+
 
 def patches_to_raw(patches, resolution):
-	raw = []
-	for patch in patches:
-		verts = make_verts(patch, resolution)
-		faces = make_faces(resolution)
-		rawquads = indexed_to_rawquads(verts, faces)
-		raw.append(rawquads)
-	raw = functools.reduce(operator.add, raw)  # flatten the list
-	return raw
+    raw = []
+    for patch in patches:
+        verts = make_verts(patch, resolution)
+        faces = make_faces(resolution)
+        rawquads = indexed_to_rawquads(verts, faces)
+        raw.append(rawquads)
+    raw = functools.reduce(operator.add, raw)  # flatten the list
+    return raw
 
-def make_bezier(ctrlpnts, resolution):
-	b1 = lambda t: t*t*t
-	b2 = lambda t: 3*t * t * (1-t)
-	b3 = lambda t: 3*t * (1-t) * (1-t)
-	b4 = lambda t: (1-t) * (1-t) * (1-t)
-	makevec = lambda v: mathutils.Vector(v)
-	p1,p2,p3,p4 = map(makevec, ctrlpnts)
-	curveverts = []
-	for i in range(resolution+1):
-		t = i/resolution
-		x,y,z = b1(t)*p1 + b2(t)*p2 + b3(t)*p3 + b4(t)*p4
-		curveverts.append((x,y,z))
-	return curveverts
 
 def make_bezier(ctrlpnts, resolution):
-	b1 = lambda t: t*t*t
-	b2 = lambda t: 3*t * t * (1-t)
-	b3 = lambda t: 3*t * (1-t) * (1-t)
-	b4 = lambda t: (1-t) * (1-t) * (1-t)
-	p1,p2,p3,p4 = map(mathutils.Vector, ctrlpnts)
-	def makevert(t):
-		x,y,z = b1(t)*p1 + b2(t)*p2 + b3(t)*p3 + b4(t)*p4
-		return (x,y,z)
-	curveverts = [makevert(i/resolution) for i in range(resolution+1)]
-	return curveverts
+    b1 = lambda t: t * t * t
+    b2 = lambda t: 3.0 * t * t * (1.0 - t)
+    b3 = lambda t: 3.0 * t * (1.0 - t) * (1.0 - t)
+    b4 = lambda t: (1.0 - t) * (1.0 - t) * (1.0 - t)
+    p1, p2, p3, p4 = map(mathutils.Vector, ctrlpnts)
+
+    def makevert(t):
+        x, y, z = b1(t) * p1 + b2(t) * p2 + b3(t) * p3 + b4(t) * p4
+        return (x, y, z)
+    curveverts = [makevert(i/resolution) for i in range(resolution+1)]
+    return curveverts
+
 
 def make_verts(a, resolution):
-	s = []
-	for i in a:
-		c = make_bezier(i, resolution)
-		s.append(c)
-	b = transpose(s)
-	s = []
-	for i in b:
-		c = make_bezier(i, resolution)
-		s.append(c)
-	verts = s
-	verts = functools.reduce(operator.add, verts)  # flatten the list
-	return verts
+    s = []
+    for i in a:
+        c = make_bezier(i, resolution)
+        s.append(c)
+    b = transpose(s)
+    s = []
+    for i in b:
+        c = make_bezier(i, resolution)
+        s.append(c)
+    verts = s
+    verts = functools.reduce(operator.add, verts)  # flatten the list
+    return verts
+
 
 def make_faces(resolution):
-	n = resolution+1
-	faces = []
-	for i in range(n-1):
-		for j in range(n-1):
-			v1 = (i+1)*n+j
-			v2 = (i+1)*n+j+1
-			v3 = i*n+j+1
-			v4 = i*n+j
-			faces.append([v1,v2,v3,v4])
-	return faces
+    n = resolution + 1
+    faces = []
+    for i in range(resolution):
+        for j in range(resolution):
+            v1 = (i + 1) * n + j
+            v2 = (i + 1) * n + j + 1
+            v3 = i * n + j + 1
+            v4 = i * n + j
+            faces.append([v1, v2, v3, v4])
+    return faces
+
 
 def indexed_to_rawquads(verts, faces):
-	rows = len(faces)
-	cols = len(faces[0])	# or 4
-	rawquads = [[None]*cols for i in range(rows)]
-	for i in range(rows):
-		for j in range(cols):
-			index = faces[i][j]
-			rawquads[i][j] = verts[index]
-	return rawquads
-
-def raw_to_indexed(rawfaces): # Generate verts and faces lists, without dups
-	verts = []
-	coords = {}
-	index = 0
-	for i in range(len(rawfaces)):
-		for j in range(len(rawfaces[i])):
-			vertex = rawfaces[i][j]
-			if vertex not in coords:
-				coords[vertex] = index
-				index += 1
-				verts.append(vertex)
-			rawfaces[i][j] = coords[vertex]
-	return verts, rawfaces
+    rows = len(faces)
+    cols = len(faces[0])    # or 4
+    rawquads = [[None] * cols for i in range(rows)]
+    for i in range(rows):
+        for j in range(cols):
+            index = faces[i][j]
+            rawquads[i][j] = verts[index]
+    return rawquads
+
+
+def raw_to_indexed(rawfaces):
+    # Generate verts and faces lists, without dups
+    verts = []
+    coords = {}
+    index = 0
+    for i in range(len(rawfaces)):
+        for j in range(len(rawfaces[i])):
+            vertex = rawfaces[i][j]
+            if vertex not in coords:
+                coords[vertex] = index
+                index += 1
+                verts.append(vertex)
+            rawfaces[i][j] = coords[vertex]
+    return verts, rawfaces
+
 
 def transpose(rowsbycols):
-	rows = len(rowsbycols)
-	cols = len(rowsbycols[0])
-	colsbyrows = [[None]*rows for i in range(cols)]
-	for i in range(cols):
-		for j in range(rows):
-			colsbyrows[i][j] = rowsbycols[j][i]
-	return co

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list