[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [3342] trunk/py/scripts/addons/ add_mesh_extra_objects: Added newell teapot & easter egg (Spoon)

Brendon Murphy meta.androcto1 at gmail.com
Thu May 3 13:51:01 CEST 2012


Revision: 3342
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=3342
Author:   meta-androcto
Date:     2012-05-03 11:51:01 +0000 (Thu, 03 May 2012)
Log Message:
-----------
Added newell teapot & easter egg (Spoon)

Modified Paths:
--------------
    trunk/py/scripts/addons/add_mesh_extra_objects/__init__.py

Added Paths:
-----------
    trunk/py/scripts/addons/add_mesh_extra_objects/add_mesh_teapot.py

Modified: trunk/py/scripts/addons/add_mesh_extra_objects/__init__.py
===================================================================
--- trunk/py/scripts/addons/add_mesh_extra_objects/__init__.py	2012-05-03 03:03:45 UTC (rev 3341)
+++ trunk/py/scripts/addons/add_mesh_extra_objects/__init__.py	2012-05-03 11:51:01 UTC (rev 3342)
@@ -17,7 +17,6 @@
 # ##### END GPL LICENSE BLOCK #####
 # Contributed to by
 # Pontiac, Fourmadmen, varkenvarken, tuga3d, meta-androcto, metalliandy, dreampainter & cotejrp1#
-# Kayo Phoenix, Anthony D'Agostino#
 
 bl_info = {
     "name": "Extra Objects",
@@ -46,6 +45,7 @@
     imp.reload(add_mesh_pyramid)
     imp.reload(add_mesh_torusknot)
     imp.reload(add_mesh_honeycomb)
+    imp.reload(add_mesh_teapot)
 else:
     from . import add_mesh_extra_objects
     from . import add_mesh_twisted_torus
@@ -57,6 +57,7 @@
     from . import add_mesh_pyramid
     from . import add_mesh_torusknot
     from . import add_mesh_honeycomb
+    from . import add_mesh_teapot
 import bpy
 
 
@@ -160,6 +161,8 @@
             text="Step Pyramid")
         layout.operator("mesh.honeycomb_add",
             text="Honeycomb")
+        layout.operator("mesh.primitive_teapot_add",
+            text="Teapot+")
 # Register all operators and panels
 
 # Define "Extras" menu

Added: trunk/py/scripts/addons/add_mesh_extra_objects/add_mesh_teapot.py
===================================================================
--- trunk/py/scripts/addons/add_mesh_extra_objects/add_mesh_teapot.py	                        (rev 0)
+++ trunk/py/scripts/addons/add_mesh_extra_objects/add_mesh_teapot.py	2012-05-03 11:51:01 UTC (rev 3342)
@@ -0,0 +1,832 @@
+'''# +---------------------------------------------------------+
+# | Copyright (c) 2005-2010 Anthony D'Agostino              |
+# | http://home.comcast.net/~chronosphere                   |
+# | scorpius at netzero.com                                    |
+# | February 12, 2005                                       |
+# | Newell Teapot Generator                                 |
+# | Adds the famous missing primitive to Blender            |
+# +---------------------------------------------------------+
+
+# ***** BEGIN GPL LICENSE BLOCK *****
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# 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
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software Foundation,
+# Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+#
+# ***** END GPL LICENCE BLOCK *****
+
+bl_info = {
+	"name": "Teapot+",
+	"author": "Anthony D'Agostino",
+	"version": (1, 0),
+	"blender": (2, 5, 7),
+	"location": "View3D > Add > Mesh ",
+	"url": "http://wiki.blender.org/index.php/Extensions:2.5/Py/Scripts/Add_Teapot",
+	"category": "Add Mesh"}
+'''
+import bpy, mathutils, io, operator, 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"}
+
+def menu_func(self, context):
+	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)
+
+def unregister():
+	bpy.utils.unregister_module(__name__)
+	bpy.types.INFO_MT_mesh_add.remove(menu_func)
+
+if __name__ == "__main__":
+	register()
+
+def create_mesh_object(context, verts, edges, faces, name):
+    # Create new mesh
+    mesh = bpy.data.meshes.new(name)
+    # Make a mesh from a list of verts/edges/faces.
+    mesh.from_pydata(verts, edges, faces)
+    # Update mesh geometry after adding stuff.
+    mesh.update()
+    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
+
+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
+
+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
+
+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
+
+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
+
+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
+
+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 colsbyrows
+
+def make_teapot(filename, resolution):
+	filenames = [None, teapot, teaspoon]
+	filename = filenames[filename]
+	patches = read_indexed_patch_file(filename)
+	raw = patches_to_raw(patches, resolution)
+	verts, faces = raw_to_indexed(raw)
+	return (verts, faces)
+
+# =================================
+# === Indexed Bezier Data Block ===
+# =================================
+teapot="""32
+1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16
+4,17,18,19,8,20,21,22,12,23,24,25,16,26,27,28
+19,29,30,31,22,32,33,34,25,35,36,37,28,38,39,40
+31,41,42,1,34,43,44,5,37,45,46,9,40,47,48,13
+13,14,15,16,49,50,51,52,53,54,55,56,57,58,59,60
+16,26,27,28,52,61,62,63,56,64,65,66,60,67,68,69
+28,38,39,40,63,70,71,72,66,73,74,75,69,76,77,78
+40,47,48,13,72,79,80,49,75,81,82,53,78,83,84,57
+57,58,59,60,85,86,87,88,89,90,91,92,93,94,95,96
+60,67,68,69,88,97,98,99,92,100,101,102,96,103,104,105
+69,76,77,78,99,106,107,108,102,109,110,111,105,112,113,114
+78,83,84,57,108,115,116,85,111,117,118,89,114,119,120,93
+121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136
+124,137,138,121,128,139,140,125,132,141,142,129,136,143,144,133
+133,134,135,136,145,146,147,148,149,150,151,152,69,153,154,155
+136,143,144,133,148,156,157,145,152,158,159,149,155,160,161,69
+162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177
+165,178,179,162,169,180,181,166,173,182,183,170,177,184,185,174
+174,175,176,177,186,187,188,189,190,191,192,193,194,195,196,197
+177,184,185,174,189,198,199,186,193,200,201,190,197,202,203,194
+204,204,204,204,207,208,209,210,211,211,211,211,212,213,214,215
+204,204,204,204,210,217,218,219,211,211,211,211,215,220,221,222
+204,204,204,204,219,224,225,226,211,211,211,211,222,227,228,229
+204,204,204,204,226,230,231,207,211,211,211,211,229,232,233,212
+212,213,214,215,234,235,236,237,238,239,240,241,242,243,244,245
+215,220,221,222,237,246,247,248,241,249,250,251,245,252,253,254
+222,227,228,229,248,255,256,257,251,258,259,260,254,261,262,263
+229,232,233,212,257,264,265,234,260,266,267,238,263,268,269,242
+270,270,270,270,279,280,281,282,275,276,277,278,271,272,273,274
+270,270,270,270,282,289,290,291,278,286,287,288,274,283,284,285
+270,270,270,270,291,298,299,300,288,295,296,297,285,292,293,294
+270,270,270,270,300,305,306,279,297,303,304,275,294,301,302,271
+306
+1.4,0.0,2.4
+1.4,-0.784,2.4
+0.784,-1.4,2.4
+0.0,-1.4,2.4
+1.3375,0.0,2.53125

@@ Diff output truncated at 10240 characters. @@


More information about the Bf-extensions-cvs mailing list