diff options
author | lijenstina <lijenstina@gmail.com> | 2017-06-03 14:37:35 +0300 |
---|---|---|
committer | lijenstina <lijenstina@gmail.com> | 2017-06-03 14:37:35 +0300 |
commit | 9c045fdd8808b8745d0af66ce7dda1e0da592332 (patch) | |
tree | 20ac5b516277df002f4977c5c1437b0891889f26 /add_curve_extra_objects/add_surface_plane_cone.py | |
parent | 77a836a2455bac9f56d6b3ae65bb37a64dea1b1c (diff) |
Add Curve Extra Objects: Cleanup, refactor some code
Bumped version to 0.1.2
Pep8 cleanup
Consistent property definitions
Remove star imports
Some small UI fixes
Reorder the submenu items types Alphabetically
Add Curve braid: merge in the bpybraid and braid scripts
since they are relatively small
Add Simple Curve - use a property group for scene props
Add list of Menus and Panels available in the User Preferences
Diffstat (limited to 'add_curve_extra_objects/add_surface_plane_cone.py')
-rw-r--r-- | add_curve_extra_objects/add_surface_plane_cone.py | 346 |
1 files changed, 124 insertions, 222 deletions
diff --git a/add_curve_extra_objects/add_surface_plane_cone.py b/add_curve_extra_objects/add_surface_plane_cone.py index 58ca48f2..dcbb5b52 100644 --- a/add_curve_extra_objects/add_surface_plane_cone.py +++ b/add_curve_extra_objects/add_surface_plane_cone.py @@ -1,91 +1,99 @@ +# gpl: author Folkert de Vries + bl_info = { - "name": "Surface: plane/cone/star/wedge", - "description": "create a NURBS surface plane.", + "name": "Surface: Plane / Cone/ Star / Wedge", + "description": "Create a NURBS surface plane", "author": "Folkert de Vries", - "version": (1, 0), + "version": (1, 0, 1), "blender": (2, 5, 9), - "api": 31236, - "location": "View3D > Add> Surface", - "warning": '', # used for warning icon and text in addons panel - "wiki_url": " "\ - " ", - "tracker_url": " "\ - " ", + "location": "View3D > Add > Surface", + "warning": "", + "wiki_url": "", "category": "Add Mesh" } -# info: -''' -to add a surface star, plane or cone, go to add menu>surface>star,plane or cone -next parameters like scale and u and v resolution can be adjusted in the toolshelf. - -have fun using this addon -''' +""" +Info: +to add a surface star, plane or cone, go to add Menu > Surface > Star, Plane or Cone +next parameters like scale and u and v resolution can be adjusted in the toolshelf +have fun using this add-on +""" import bpy from bpy.props import ( FloatProperty, IntProperty, ) - from bpy.types import Operator -from bpy.utils import register_class, unregister_class -class MakeSurfaceWedge(Operator): - bl_idname = 'object.add_surface_wedge' - bl_label = 'Add Surface Wedge' - bl_space_type = 'VIEW_3D' - bl_region_type = 'WINDOW' - bl_context = "object" - bl_options = {'REGISTER', 'UNDO'} -# get input for size and resolution - +# generic class for inheritance +class MakeSurfaceHelpers: + # get input for size and resolution size = FloatProperty( - name="Size", - description="Size of the object", - default=1.0, - min=0.01, - max=100.0, - unit="LENGTH", - ) + name="Size", + description="Size of the object", + default=1.0, + min=0.01, + max=100.0, + unit="LENGTH", + ) res_u = IntProperty( - name="Resolution U", - description="Surface resolution in u direction", - default=1, - min=1, - max=500, - ) + name="Resolution U", + description="Surface resolution in u direction", + default=1, + min=1, + max=500, + ) res_v = IntProperty( - name="Resolution V", - description="Surface resolution in v direction", - default=1, - min=1, - max=500, - ) + name="Resolution V", + description="Surface resolution in v direction", + default=1, + min=1, + max=500, + ) @classmethod def poll(cls, context): return context.mode == 'OBJECT' + def draw(self, context): + layout = self.layout + layout.prop(self, "size") + + col = layout.column(align=True) + col.prop(self, "res_u") + col.prop(self, "res_v") + + +class MakeSurfaceWedge(Operator, MakeSurfaceHelpers): + bl_idname = "object.add_surface_wedge" + bl_label = "Add Surface Wedge" + bl_description = "Construct a Surface Wedge" + bl_options = {'REGISTER', 'UNDO'} + def execute(self, context): # variables size = self.size res_u = self.res_u res_v = self.res_v + # add a surface Plane bpy.ops.object.add_surface_plane() - # save some time, by getting instant acces to those values. + # save some time, by getting instant acces to those values ao = context.active_object point = ao.data.splines[0].points + # rotate 90 degrees on the z axis ao.rotation_euler[0] = 0.0 ao.rotation_euler[1] = 0.0 ao.rotation_euler[2] = 1.570796 + # go into edit mode and deselect bpy.ops.object.mode_set(mode='EDIT') bpy.ops.curve.select_all(action='DESELECT') + # select points 0 and 1, and extrudde them # declaring ao and point again seems necesary... ao = context.active_object @@ -124,44 +132,13 @@ class MakeSurfaceWedge(Operator): return{'FINISHED'} - positions = [(1.0, 1.0, -1.0, 1.0), (1.0, -1.0, -1.0, 1.0), (-1.0, -1.0, -1.0, 1.0), (-1.0, 1.0, -1.0, 1.0), (1.0, 0.0, 1.0, 1.0), (-1.0, 0.0, 1.0, 1.0)] - -class MakeSurfaceCone(Operator): - bl_idname = 'object.add_surface_cone' - bl_label = 'Add Surface Cone' - bl_space_type = 'VIEW_3D' - bl_region_type = 'WINDOW' - bl_context = "object" +class MakeSurfaceCone(Operator, MakeSurfaceHelpers): + bl_idname = "object.add_surface_cone" + bl_label = "Add Surface Cone" + bl_description = "Construct a Surface Cone" bl_options = {'REGISTER', 'UNDO'} - size = FloatProperty( - name="Size", - description="Size of the object", - default=1.0, - min=0.01, - max=100.0, - unit="LENGTH", - ) - res_u = IntProperty( - name="Resolution U", - description="Surface resolution in u direction", - default=4, - min=1, - max=500, - ) - res_v = IntProperty( - name="Resolution V", - description="Surface resolution in v direction", - default=4, - min=1, - max=500, - ) - - @classmethod - def poll(cls, context): - return context.mode == 'OBJECT' - def execute(self, context): size = self.size res_u = self.res_u @@ -170,8 +147,9 @@ class MakeSurfaceCone(Operator): # add basemesh, a nurbs torus bpy.ops.surface.primitive_nurbs_surface_torus_add(location=(0, 0, 0)) # get active object and active object name + ao = context.active_object - aoname = context.active_object.name + # go to edit mode bpy.ops.object.mode_set(mode='EDIT') # deselect all @@ -194,6 +172,7 @@ class MakeSurfaceCone(Operator): ToKeep = [1, 3, 5, 7, 9, 11, 13, 15, 17] for i in range(0, len(ToKeep) - 1): point[ToKeep[i]].select = True + bpy.ops.transform.resize(value=(0, 0, 0)) bpy.ops.curve.cyclic_toggle(direction='CYCLIC_U') bpy.ops.transform.translate(value=(0, 0, 2)) @@ -218,41 +197,12 @@ class MakeSurfaceCone(Operator): return{'FINISHED'} -class MakeSurfaceStar(Operator): - bl_idname = 'object.add_surface_star' - bl_label = 'Add Surface Star' - bl_space_type = 'VIEW_3D' - bl_region_type = 'WINDOW' - bl_context = "object" +class MakeSurfaceStar(Operator, MakeSurfaceHelpers): + bl_idname = "object.add_surface_star" + bl_label = "Add Surface Star" + bl_description = "Contruct a Surface Star" bl_options = {'REGISTER', 'UNDO'} - size = FloatProperty( - name="Size", - description="Size of the object", - default=1.0, - min=0.01, - max=100.0, - unit="LENGTH", - ) - res_u = IntProperty( - name="Resolution U", - description="Surface resolution in u direction", - default=1, - min=1, - max=500, - ) - res_v = IntProperty( - name="Resolution V", - description="Surface resolution in v direction", - default=1, - min=1, - max=500, - ) - - @classmethod - def poll(cls, context): - return context.mode == 'OBJECT' - def execute(self, context): size = self.size res_u = self.res_u @@ -281,16 +231,18 @@ class MakeSurfaceStar(Operator): bpy.ops.curve.subdivide() bpy.ops.curve.select_all(action='DESELECT') - ListOfCoords = [(0.5, 0.0, 0.25, 1.0), - (0.80901700258255, 0.5877853035926819, 0.25, 1.0), - (0.1545085906982422, 0.4755282402038574, 0.25, 1.0), - (-0.30901703238487244, 0.9510565400123596, 0.25, 1.0), - (-0.4045085608959198, 0.293892502784729, 0.2499999850988388, 1.0), - (-1.0, 0.0, 0.25, 1.0), - (-0.4045085608959198, -0.293892502784729, 0.2499999850988388, 1.0), - (-0.30901703238487244, -0.9510565400123596, 0.25, 1.0), - (0.1545085906982422, -0.4755282402038574, 0.25, 1.0), - (0.8090166449546814, -0.5877856612205505, 0.2499999850988388, 1.0)] + ListOfCoords = [ + (0.5, 0.0, 0.25, 1.0), + (0.80901700258255, 0.5877853035926819, 0.25, 1.0), + (0.1545085906982422, 0.4755282402038574, 0.25, 1.0), + (-0.30901703238487244, 0.9510565400123596, 0.25, 1.0), + (-0.4045085608959198, 0.293892502784729, 0.2499999850988388, 1.0), + (-1.0, 0.0, 0.25, 1.0), + (-0.4045085608959198, -0.293892502784729, 0.2499999850988388, 1.0), + (-0.30901703238487244, -0.9510565400123596, 0.25, 1.0), + (0.1545085906982422, -0.4755282402038574, 0.25, 1.0), + (0.8090166449546814, -0.5877856612205505, 0.2499999850988388, 1.0) + ] for i in range(0, 10): context.active_object.data.splines[0].points[i].co = ListOfCoords[i] @@ -303,7 +255,10 @@ class MakeSurfaceStar(Operator): # extrude the star bpy.ops.curve.extrude(mode='TRANSLATION') # bring extruded part up - bpy.ops.transform.translate(value=(0, 0, 0.5), constraint_axis=(False, False, True)) + bpy.ops.transform.translate( + value=(0, 0, 0.5), + constraint_axis=(False, False, True) + ) # flip normals bpy.ops.curve.switch_direction() # go back to object mode @@ -324,41 +279,12 @@ class MakeSurfaceStar(Operator): return{'FINISHED'} -class MakeSurfacePlane(Operator): - bl_idname = 'object.add_surface_plane' - bl_label = 'Add Surface Plane' - bl_space_type = 'VIEW_3D' - bl_region_type = 'WINDOW' - bl_context = "object" +class MakeSurfacePlane(Operator, MakeSurfaceHelpers): + bl_idname = "object.add_surface_plane" + bl_label = "Add Surface Plane" + bl_description = "Contruct a Surface Plane" bl_options = {'REGISTER', 'UNDO'} - size = FloatProperty( - name="Size", - description="Size of the object", - default=1.0, - min=0.01, - max=100.0, - unit="LENGTH", - ) - res_u = IntProperty( - name="Resolution U", - description="Surface resolution in u direction", - default=1, - min=1, - max=500, - ) - res_v = IntProperty( - name="Resolution V", - description="Surface resolution in v direction", - default=1, - min=1, - max=500, - ) - - @classmethod - def poll(cls, context): - return context.mode == 'OBJECT' - def execute(self, context): size = self.size res_u = self.res_u @@ -366,11 +292,14 @@ class MakeSurfacePlane(Operator): bpy.ops.surface.primitive_nurbs_surface_surface_add() # add the base mesh, a NURBS Surface - bpy.ops.transform.resize(value=(1, 1, 0.0001), constraint_axis=(False, False, True)) # make it flat - ao = context.active_object.name # get the active object' s name + bpy.ops.transform.resize( + value=(1, 1, 0.0001), + constraint_axis=(False, False, True) + ) # make it flat + # added surface has 16 points - # deleting points to get plane shape. + # deleting points to get plane shape bpy.ops.object.mode_set(mode='EDIT') bpy.ops.curve.select_all(action='DESELECT') @@ -394,7 +323,7 @@ class MakeSurfacePlane(Operator): bpy.ops.curve.delete(type='VERT') # assigning name - context.active_object.name = 'SurfacePlane' + context.active_object.name = "SurfacePlane" # select all bpy.ops.curve.select_all(action='SELECT') # bringing origin to center: @@ -402,7 +331,8 @@ class MakeSurfacePlane(Operator): bpy.ops.object.origin_set(type='ORIGIN_GEOMETRY', center='MEDIAN') # transform scale bpy.ops.object.transform_apply(scale=True) - # bring object to 3d cursor. + + # bring object to 3d cursor bpy.ops.object.mode_set(mode='OBJECT') context.active_object.location = context.scene.cursor_location bpy.ops.transform.resize(value=(size, size, size)) @@ -415,81 +345,53 @@ class MakeSurfacePlane(Operator): class SmoothXtimes(Operator): - bl_idname = 'curve.smooth_x_times' - bl_label = 'Smooth X Times' - bl_space_type = 'VIEW_3D' - bl_region_type = 'WINDOW' - bl_context = "object" + bl_idname = "curve.smooth_x_times" + bl_label = "Smooth X Times" + bl_space_type = "VIEW_3D" bl_options = {'REGISTER', 'UNDO'} - '''use of this class: - lets you smooth till a thousand times. this is normally difficult, because - you have to press w, click, press w, click ect.''' + + # use of this class: + # lets you smooth till a thousand times. this is normally difficult, because + # you have to press w, click, press w, click etc. # get values - times = IntProperty(name='smooth x times', - min=1, - max=1000, - default=1, - description='amount of smooths') + times = IntProperty( + name="Smooth x Times", + min=1, + max=1000, + default=1, + description="Smooth amount" + ) @classmethod def poll(cls, context): return context.mode == 'EDIT_SURFACE' def execute(self, context): - # smooth times time(s). + # smooth times times = self.times for i in range(1, times): bpy.ops.curve.smooth() - return{'FINISHED'} - - -def Surface_plane_button(self, context): - self.layout.operator(MakeSurfacePlane.bl_idname, text="surface plane", icon="MOD_CURVE") - -def Surface_cone_button(self, context): - self.layout.operator(MakeSurfaceCone.bl_idname, text="surface cone", icon="MOD_CURVE") - - -def Surface_star_button(self, context): - self.layout.operator(MakeSurfaceStar.bl_idname, text="surface star", icon="MOD_CURVE") - - -def Surface_wedge_button(self, context): - self.layout.operator(MakeSurfaceWedge.bl_idname, text="surface wedge", icon="MOD_CURVE") - - -def SmoothXtimes_button(self, context): - self.layout.operator(SmoothXtimes.bl_idname, text="smooth x times", icon="MOD_CURVE") + return{'FINISHED'} def register(): - register_class(UserInterface) - register_class(MakeSurfacePlane) - register_class(MakeSurfaceCone) - register_class(MakeSurfaceStar) - register_class(MakeSurfaceWedge) - register_class(SmoothXtimes) - bpy.types.INFO_MT_surface_add.append(Surface_plane_button) - bpy.types.INFO_MT_surface_add.append(Surface_cone_button) - bpy.types.INFO_MT_surface_add.append(Surface_star_button) - bpy.types.INFO_MT_surface_add.append(Surface_wedge_button) - bpy.types.VIEW3D_MT_edit_curve_specials.append(SmoothXtimes_button) + bpy.utils.register_class(MakeSurfaceHelpers) + bpy.utils.register_class(MakeSurfacePlane) + bpy.utils.register_class(MakeSurfaceCone) + bpy.utils.register_class(MakeSurfaceStar) + bpy.utils.register_class(MakeSurfaceWedge) + bpy.utils.register_class(SmoothXtimes) def unregister(): - unregister_class(UserInterface) - unregister_class(MakeSurfacePlane) - unregister_class(MakeSurfaceCone) - unregister_class(MakeSurfaceStar) - unregister_class(MakeSurfaceWedge) - unregister_class(SmoothXtimes) - bpy.types.INFO_MT_surface_add.remove(Surface_plane_button) - bpy.types.INFO_MT_surface_add.remove(Surface_cone_button) - bpy.types.INFO_MT_surface_add.remove(Surface_star_button) - bpy.types.INFO_MT_surface_add.remove(Surface_wedge_button) - bpy.types.VIEW3D_MT_edit_curve_specials.remove(SmoothXtimes_button) + bpy.utils.unregister_class(MakeSurfaceHelpers) + bpy.utils.unregister_class(MakeSurfacePlane) + bpy.utils.unregister_class(MakeSurfaceCone) + bpy.utils.unregister_class(MakeSurfaceStar) + bpy.utils.unregister_class(MakeSurfaceWedge) + bpy.utils.unregister_class(SmoothXtimes) if __name__ == "__main__": |