diff options
author | lijenstina <lijenstina@gmail.com> | 2016-12-30 22:33:05 +0300 |
---|---|---|
committer | lijenstina <lijenstina@gmail.com> | 2016-12-30 22:33:05 +0300 |
commit | c86080a455579a8c770545e33b95513b43e1a43b (patch) | |
tree | 6c392b16b914aa3264b373022602e57ad493e7d7 /add_mesh_extra_objects/add_mesh_teapot.py | |
parent | c95e86bcef654c0686d3cf4d52446ff9ff8c819f (diff) |
Add mesh extra objects: Update to version 0.3.1
General Pep8 cleanup
Removed unused variables and imports
Removed a panel from add_empty_as_parent
Standardized the property definitions
across all the scripts
Moved scene props from third_domes_panel_271
to init for proper removal
Added a Enum prop for mesh type in teapot
Fixed a small issue with Geodesic domes self.reports
(problem with value fields message spam)
Fixed props names in Geodesic domes
Consistent tooltips
Reorganized menus:
Mechanical Menu including Pipe joints, Mesh gear
Added separators
Diffstat (limited to 'add_mesh_extra_objects/add_mesh_teapot.py')
-rw-r--r-- | add_mesh_extra_objects/add_mesh_teapot.py | 36 |
1 files changed, 27 insertions, 9 deletions
diff --git a/add_mesh_extra_objects/add_mesh_teapot.py b/add_mesh_extra_objects/add_mesh_teapot.py index 01b16a38..27e7f703 100644 --- a/add_mesh_extra_objects/add_mesh_teapot.py +++ b/add_mesh_extra_objects/add_mesh_teapot.py @@ -1,7 +1,10 @@ # GPL # Author, Anthony D'Agostino import bpy -from bpy.props import IntProperty +from bpy.props import ( + IntProperty, + EnumProperty, + ) import mathutils @@ -9,21 +12,26 @@ 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_description = "Construct a teapot or teaspoon mesh" bl_options = {"REGISTER", "UNDO"} resolution = IntProperty( name="Resolution", description="Resolution of the Teapot", - default=5, min=2, max=15, + default=5, + min=2, max=15, ) - objecttype = IntProperty( + objecttype = EnumProperty( name="Object Type", description="Type of Bezier Object", - default=1, min=1, max=2) + items=(('1', "Teapot", "Construct a teapot mesh"), + ('2', "Tea Spoon", "Construct a teaspoon mesh")), + default='1', + ) def execute(self, context): verts, faces = make_teapot(self.objecttype, @@ -32,6 +40,7 @@ class AddTeapot(bpy.types.Operator): obj = create_mesh_object(context, verts, [], faces, "Teapot") return {'FINISHED'} + def create_mesh_face_hack(faces): # FIXME, faces with duplicate vertices shouldn't be created in the first place. faces_copy = [] @@ -43,6 +52,7 @@ def create_mesh_face_hack(faces): faces_copy.append(f_copy) faces[:] = faces_copy + def create_mesh_object(context, verts, edges, faces, name): create_mesh_face_hack(faces) @@ -60,6 +70,7 @@ def create_mesh_object(context, verts, edges, faces, name): # ========================== # === Bezier patch Block === # ========================== + def read_indexed_patch_file(filename): file = io.StringIO(filename) rawpatches = [] @@ -81,7 +92,7 @@ def read_indexed_patch_file(filename): 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 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] @@ -109,7 +120,7 @@ def make_bezier(ctrlpnts, resolution): 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)] + curveverts = [makevert(i / resolution) for i in range(resolution + 1)] return curveverts @@ -178,14 +189,21 @@ def transpose(rowsbycols): return colsbyrows -def make_teapot(filename, resolution): +def make_teapot(enumname, resolution): filenames = [None, teapot, teaspoon] - filename = filenames[filename] + try: + indexs = int(enumname) + filename = filenames[indexs] + except: + print("Add Teapot Error: EnumProperty could not be set") + filename = filenames[1] + 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 === # ================================= |