diff --git a/add_mesh_diamond.py b/add_mesh_diamond.py index 01991d77cbebc5a0773a1713d8fbba4d6b7b94e2..e376c6053e249c62044eac996e4a500d506ad83f 100644 --- a/add_mesh_diamond.py +++ b/add_mesh_diamond.py @@ -41,14 +41,14 @@ def add_diamond(segments, girdle_radius, table_radius, crown_height, pavillion_h verts = [] faces = [] - + tot_verts = segments * 2 + 2 height = crown_height + pavillion_height half_height = height * 0.5 - verts.extend( Vector(0.0, 0.0, -half_height) ) - verts.extend( Vector(0.0, 0.0, half_height) ) + verts.extend(Vector(0.0, 0.0, -half_height)) + verts.extend(Vector(0.0, 0.0, half_height)) i = 2 for index in range(segments): @@ -61,7 +61,7 @@ def add_diamond(segments, girdle_radius, table_radius, crown_height, pavillion_h it1 = i i += 1 - vec = Vector(girdle_radius, 0, half_height-pavillion_height) * quat + vec = Vector(girdle_radius, 0, half_height - pavillion_height) * quat verts.extend([vec.x, vec.y, vec.z]) ib1 = i i += 1 @@ -110,7 +110,7 @@ class AddDiamond(bpy.types.Operator): self.properties.pavillion_height) mesh = bpy.data.meshes.new("Diamond") - + mesh.add_geometry(int(len(verts_loc) / 3), 0, int(len(faces) / 4)) mesh.verts.foreach_set("co", verts_loc) mesh.faces.foreach_set("verts_raw", faces) @@ -126,9 +126,9 @@ class AddDiamond(bpy.types.Operator): scene.objects.link(ob_new) scene.objects.active = ob_new ob_new.selected = True - + ob_new.location = tuple(context.scene.cursor_location) - + return {'FINISHED'} @@ -140,10 +140,12 @@ class AddDiamond(bpy.types.Operator): menu_func = (lambda self, context: self.layout.operator(AddDiamond.bl_idname, text="Add Diamond", icon='PLUGIN')) + def register(): bpy.types.register(AddDiamond) bpy.types.INFO_MT_mesh_add.append(menu_func) + def unregister(): bpy.types.unregister(AddDiamond) bpy.types.INFO_MT_mesh_add.remove(menu_func) diff --git a/add_mesh_gears.py b/add_mesh_gears.py index e6c912ff3f6c405f0f1fe3ed4c581fe4099da46b..9f40a6876f99170320c7902f775cbe83bc1a64e3 100644 --- a/add_mesh_gears.py +++ b/add_mesh_gears.py @@ -101,158 +101,181 @@ def flatten(alist): return sum([list(a) for a in alist],[]) #constants -faces=[[0,5,6,1],[1,6,7,2],[2,7,8,3],[3,8,9,4],[6,10,11,7],[7,11,12,8],[10,13,14,11],[11,14,15,12]] -L=16 # number of vertices +faces=[[0, 5, 6, 1], + [1, 6, 7, 2], + [2, 7, 8, 3], + [3, 8, 9, 4], + [6, 10, 11, 7], + [7, 11, 12, 8], + [10, 13, 14, 11], + [11, 14, 15, 12]] + +L = 16 # number of vertices #edgefaces -ef = [5,6,10,13,14,15,12,8,9] -ef2 = [i+L for i in ef] +ef = [5, 6, 10, 13, 14, 15, 12, 8, 9] +ef2 = [i + L for i in ef] # in python 3, zip() returns a zip object so we have to force the result into a list of lists to keep # deepcopy happy later on in the script. -efc = [ [i,j,k,l] for i,j,k,l in zip(ef[:-1],ef2[:-1],ef2[1:],ef[1:])] -vv = [5,6,8,9,21,22,24,25] #vertices in a valley -tv = [13,14,15,29,30,31] #vertices on a tooth +efc = [[i, j, k, l] for i, j, k, l in zip(ef[:-1], ef2[:-1], ef2[1:], ef[1:])] +vv = [5, 6, 8, 9, 21,22, 24, 25] #vertices in a valley +tv = [13, 14, 15, 29, 30, 31] #vertices on a tooth -spokefaces=((0,1,2,5),(2,3,4,7),(5,2,7,6),(5,6,9,8),(6,7,10,9),(11,8,13,12),(8,9,10,13),(13,10,15,14)) +spokefaces=((0, 1, 2, 5), + (2, 3, 4, 7), + (5, 2, 7, 6), + (5, 6, 9, 8), + (6, 7, 10, 9), + (11, 8, 13, 12), + (8, 9, 10, 13), + (13, 10, 15, 14)) -def add_tooth(a,t,d,r,Ad,De,b,p,rack=0,crown=0.0): + +def add_tooth(a, t, d, r, Ad, De, b, p, rack=0, crown=0.0): """ private function: calculate the vertex coords for a single side section of a gear tooth. returns them as a list of lists. """ - A=[a,a+t/4,a+t/2,a+3*t/4,a+t] - C=[cos(i) for i in A] - S=[sin(i) for i in A] + A = [a, a + t / 4, a + t / 2, a + 3 * t / 4, a + t] + C = [cos(i) for i in A] + S = [sin(i) for i in A] - Ra=r+Ad - Rd=r-De - Rb=Rd-b + Ra= r + Ad + Rd= r - De + Rb= Rd - b #Pressure angle calc - O =Ad*tan(p) - p =atan(O/Ra) - if r<0 : p = -p + O = Ad * tan(p) + p = atan(O/Ra) + if r < 0: + p = -p if rack : S =[sin(t/4)*I for I in range(-2,3)] Sp=[0,sin(-t/4+p),0,sin(t/4-p)] - v=[(Rb,r*S[I],d) for I in range(5)] - v.extend([(Rd,r*S[I],d) for I in range(5)]) - v.extend([(r,r*S[I],d) for I in range(1,4)]) - v.extend([(Ra,r*Sp[I],d) for I in range(1,4)]) + v = [(Rb, r * S[I], d) for I in range(5)] + v.extend([(Rd, r * S[I], d) for I in range(5)]) + v.extend([(r, r * S[I], d) for I in range(1, 4)]) + v.extend([(Ra, r * Sp[I], d) for I in range(1, 4)]) - else : - Cp=[0,cos(a+t/4+p),cos(a+t/2),cos(a+3*t/4-p)] - Sp=[0,sin(a+t/4+p),sin(a+t/2),sin(a+3*t/4-p)] + else: + Cp = [0, cos(a + t / 4 + p), cos(a + t / 2), cos(a + 3 * t / 4 - p)] + Sp = [0, sin(a + t / 4 + p), sin(a + t / 2), sin(a + 3 * t / 4 - p)] - v=[(Rb*C[I],Rb*S[I],d) for I in range(5)] - v.extend([(Rd*C[I],Rd*S[I],d) for I in range(5)]) - v.extend([(r*C[I],r*S[I],d+crown/3) for I in range(1,4)]) - v.extend([(Ra*Cp[I],Ra*Sp[I],d+crown) for I in range(1,4)]) + v = [(Rb * C[I], Rb * S[I], d) for I in range(5)] + v.extend([(Rd * C[I], Rd * S[I], d) for I in range(5)]) + v.extend([(r * C[I],r * S[I],d + crown / 3) for I in range(1, 4)]) + v.extend([(Ra * Cp[I], Ra * Sp[I], d + crown) for I in range(1, 4)]) return v -def add_spoke2(a,t,d,r,De,b,s,w,l,gap=0,width=19): +def add_spoke2(a, t, d, r, De, b, s, w, l, gap=0, width=19): """ EXPERIMENTAL private function: calculate the vertex coords for a single side section of a gearspoke. returns them as a list of lists. """ - Rd=r-De - Rb=Rd-b + Rd=r - De + Rb=Rd - b Rl=Rb - v =[] - ef =[] - ef2=[] - sf =[] + v = [] + ef = [] + ef2 = [] + sf = [] + if not gap : - for N in range(width,1,-2) : + for N in range(width, 1, -2) : ef.append(len(v)) - ts = t/4 - tm = a + 2*ts - te = asin(w/Rb) + ts = t / 4 + tm = a + 2 * ts + te = asin(w / Rb) td = te - ts - t4 = ts+td*(width-N)/(width-3.0) - A=[tm+(i-int(N/2))*t4 for i in range(N)] - C=[cos(i) for i in A] - S=[sin(i) for i in A] - v.extend([ (Rb*I,Rb*J,d) for (I,J) in zip(C,S)]) - ef2.append(len(v)-1) - Rb= Rb-s + t4 = ts + td * (width - N) / (width - 3.0) + A = [tm + (i - int(N / 2)) * t4 for i in range(N)] + C = [cos(i) for i in A] + S = [sin(i) for i in A] + v.extend([ (Rb * I, Rb * J, d) for (I, J) in zip(C,S)]) + ef2.append(len(v) - 1) + Rb= Rb - s n=0 - for N in range(width,3,-2) : - sf.extend([(i+n,i+1+n,i+2+n,i+N+n) for i in range(0,N-1,2)]) - sf.extend([(i+2+n,i+N+n,i+N+1+n,i+N+2+n) for i in range(0,N-3,2)]) + for N in range(width, 3, -2): + sf.extend([(i + n,i + 1 + n,i + 2 + n,i + N + n) for i in range(0, N - 1, 2)]) + sf.extend([(i + 2 + n,i + N + n,i + N + 1 + n,i + N + 2 + n) for i in range(0,N - 3,2)]) n = n + N - return v,ef,ef2,sf + return v, ef, ef2, sf -def add_gear(N,r,Ad,De,b,p,D=1,skew=0,conangle=0,rack=0,crown=0.0, spoke=0,spbevel=0.1,spwidth=0.2,splength=1.0,spresol=9): + +def add_gear(N, r, Ad, De, b, p, D=1, skew=0, conangle=0, rack=0, crown=0.0, spoke=0, spbevel=0.1, spwidth=0.2, splength=1.0, spresol=9): """ """ - worm =0 - if N<5 : (worm,N)=(N,24) - t =2*pi/N - if rack: N=1 - p =rad(p) - conangle=rad(conangle) - skew =rad(skew) - scale = (r - 2*D*tan(conangle) )/r + worm =0 + if N < 5: + worm, N = N, 24 + + t = 2 * pi / N + if rack: + N=1 + p = rad(p) + conangle = rad(conangle) + skew = rad(skew) + scale = (r - 2 * D * tan(conangle)) / r - f =[] - v =[] - tg=[] #vertexgroup of top vertices. - vg=[] #vertexgroup of valley vertices + f = [] + v = [] + tg= [] #vertexgroup of top vertices. + vg= [] #vertexgroup of valley vertices - M=[0] - if worm : (M,skew,D)=(range(32),rad(11.25),D/2) + M = [0] + if worm: + M, skew, D = (range(32), rad(11.25), D / 2) for W in M: - fl=W*N*L*2 - l=0 #number of vertices + fl = W * N * L * 2 + l = 0 #number of vertices for I in range(int(N)): - a=I*t - for(s,d,c,first) in ((W*skew,W*2*D-D,1,1),((W+1)*skew,W*2*D+D,scale,0)): - if worm and I%(int(N)/worm)!=0: - v.extend(add_tooth(a+s,t,d,r-De,0.0,0.0,b,p)) + a = I * t + for (s, d, c, first) in ((W * skew, W * 2 * D - D, 1, 1),((W + 1) * skew, W * 2 * D + D, scale, 0)): + if worm and I % (int(N) / worm) != 0: + v.extend(add_tooth(a + s, t, d, r - De, 0.0, 0.0, b, p)) else: - v.extend(add_tooth(a+s,t,d,r*c,Ad*c,De*c,b*c,p,rack,crown)) - if not worm or (W==0 and first) or (W==(len(M)-1) and not first) : - f.extend([ [j+l+fl for j in i]for i in dc(faces)]) + v.extend(add_tooth(a + s, t, d, r * c, Ad * c, De * c, b * c, p, rack, crown)) + if not worm or (W == 0 and first) or (W == (len(M) - 1) and not first) : + f.extend([ [j + l + fl for j in i] for i in dc(faces)]) l += L #print (len(f)) #print (dc(efc)) - f.extend([ [j+I*L*2+fl for j in i] for i in dc(efc)]) + f.extend([[j + I * L * 2 + fl for j in i] for i in dc(efc)]) #print (len(f)) - tg.extend([i+I*L*2 for i in tv]) - vg.extend([i+I*L*2 for i in vv]) + tg.extend([i + I * L * 2 for i in tv]) + vg.extend([i + I * L * 2 for i in vv]) # EXPERIMENTAL: add spokes - if not worm and spoke>0 : + if not worm and spoke > 0: fl=len(v) for I in range(int(N)): - a=I*t - s=0 # for test - if I%spoke==0 : - for d in (-D,D) : - (sv,ef,ef2,sf) = add_spoke2(a+s,t,d,r*c,De*c,b*c,spbevel,spwidth,splength,0,spresol) + a = I * t + s = 0 # for test + if I % spoke == 0 : + for d in (-D, D) : + sv, ef, ef2, sf = add_spoke2(a + s, t, d, r * c, De * c, b * c, spbevel, spwidth, splength, 0, spresol) v.extend(sv) - f.extend([ [j+fl for j in i]for i in sf]) + f.extend([[j + fl for j in i] for i in sf]) fl += len(sv) - d1 = fl-len(sv) - d2 = fl-2*len(sv) - f.extend([(i+d2,j+d2,j+d1,i+d1) for (i,j) in zip(ef[:-1],ef[1:])]) - f.extend([(i+d2,j+d2,j+d1,i+d1) for (i,j) in zip(ef2[:-1],ef2[1:])]) - else : - for d in (-D,D) : - (sv,ef,ef2,sf) = add_spoke2(a+s,t,d,r*c,De*c,b*c,spbevel,spwidth,splength,1,spresol) + d1 = fl - len(sv) + d2 = fl - 2 * len(sv) + f.extend([(i + d2, j + d2, j + d1, i + d1) for (i, j) in zip(ef[:-1], ef[1:])]) + f.extend([(i + d2, j + d2, j + d1, i + d1) for (i, j) in zip(ef2[:-1], ef2[1:])]) + else: + for d in (-D, D) : + (sv,ef,ef2,sf) = add_spoke2(a + s, t, d, r * c, De * c, b * c, spbevel, spwidth, splength, 1, spresol) v.extend(sv) fl += len(sv) - d1 = fl-len(sv) - d2 = fl-2*len(sv) + d1 = fl - len(sv) + d2 = fl - 2 * len(sv) #f.extend([(i+d2,i+1+d2,i+1+d1,i+d1) for (i) in (0,1,2,3)]) #f.extend([(i+d2,i+1+d2,i+1+d1,i+d1) for (i) in (5,6,7,8)]) @@ -269,8 +292,8 @@ class AddGear(bpy.types.Operator): bl_options = {'REGISTER', 'UNDO'} number_of_teeth = IntProperty(name="Number of Teeth", - description="Number of teeth on the gear", - default=12,min=4,max=200) + description="Number of teeth on the gear", + default=12, min=4, max=200) radius = FloatProperty(name="Radius", description="Radius of the gear, negative for crown gear", default=1.0, min=-100.0, max=100.0) @@ -368,15 +391,17 @@ class AddGear(bpy.types.Operator): menu_func = (lambda self, context: self.layout.operator(AddGear.bl_idname, text="Gear", icon='PLUGIN')) + def register(): bpy.types.register(AddGear) bpy.types.INFO_MT_mesh_add.append(menu_func) + def unregister(): bpy.types.unregister(AddGear) bpy.types.INFO_MT_mesh_add.remove(menu_func) - - # Remove "Gears" menu from the "Add Mesh" menu. + + # Remove "Gears" menu from the "Add Mesh" menu. #space_info.INFO_MT_mesh_add.remove(menu_func) if __name__ == "__main__": diff --git a/add_mesh_gem.py b/add_mesh_gem.py index db3359df70c540657b284a0460a2c54c63e1a438..8e01cbd272754d76198b8660081122352fc385b1 100644 --- a/add_mesh_gem.py +++ b/add_mesh_gem.py @@ -29,29 +29,10 @@ bl_addon_info = { 'url': 'http://wiki.blender.org/index.php/Extensions:2.5/Py/Scripts/Add_Gem', 'category': 'Add Mesh'} -""" -Name: 'Gem' -Blender: 250.1 -Group: 'AddMesh' -Tip: 'Add Gem Object...' -__author__ = ["Dreampainter"] -__version__ = '1.0.1' -__url__ = ["http://blenderartists.org/forum/showpost.php?p=1564840&postcount=173"] -email__=["n/a"] +import bpy -Usage: - -* Launch from Add Mesh menu - -* Modify parameters as desired or keep defaults - -""" -import bpy -import Mathutils -from math import cos,sin,pi -from bpy.props import IntProperty, FloatProperty, BoolProperty def add_gem(r1, r2, seg, h1, h2): """ r1 = pavillion radius @@ -61,89 +42,102 @@ def add_gem(r1, r2, seg, h1, h2): h2 = crown height Generates the vertices and faces of the gem """ + from math import cos, sin, pi tot_verts = 2 + 4 * seg tot_faces = 6 * seg - a = 2*pi/seg # angle between segments - offset = a/2.0 # middle between segments - - r3 = ((r1+r2)/2.0)/cos(offset) # middle of crown - r4 = (r1/2.0)/cos(offset) # middle of pavillion - h3 = h2/2.0 # middle of crown height - h4 = -h1/2.0 # middle of pavillion height - verts = [0,0,-h1,0,0,h2] + a = 2 * pi / seg # angle between segments + offset = a / 2.0 # middle between segments + + r3 = ((r1 + r2) / 2.0) / cos(offset) # middle of crown + r4 = (r1 / 2.0) / cos(offset) # middle of pavillion + h3 = h2 / 2.0 # middle of crown height + h4 = -h1 / 2.0 # middle of pavillion height + verts = [0, 0, -h1, 0, 0, h2] for i in range(seg): - s1 = sin(i*a) - s2 = sin(offset+i*a) - c1 = cos(i*a) - c2 = cos(offset+i*a) - verts.extend([ r4*s1,r4*c1,h4,r1*s2,r1*c2,0, - r3*s1,r3*c1,h3,r2*s2,r2*c2,h2 ]) + s1 = sin(i * a) + s2 = sin(offset + i * a) + c1 = cos(i * a) + c2 = cos(offset + i * a) + verts.extend([ r4 * s1, r4 * c1, h4,r1 * s2, r1 * c2,0, + r3 * s1,r3 * c1, h3, r2 * s2, r2 * c2, h2 ]) faces = [] - + for index in range(seg): - i = index*4 - j = ((index+1)%seg)*4 - faces.extend([0, j+2, i+3, i+2]) - faces.extend([i+3, j+2, j+3, i+3]) - faces.extend([i+3, j+3, j+4, i+3]) - faces.extend([i+3, j+4, i+5, i+4]) - faces.extend([i+5, j+4, j+5, i+5]) - faces.extend([i+5, j+5, 1 , i+5]) + i = index * 4 + j = ((index + 1) % seg) * 4 + faces.extend([0, j + 2, i + 3, i + 2]) + faces.extend([i + 3, j + 2, j +3, i + 3]) + faces.extend([i + 3, j + 3, j +4, i + 3]) + faces.extend([i + 3, j + 4, i +5, i + 4]) + faces.extend([i + 5, j + 4, j +5, i + 5]) + faces.extend([i + 5, j + 5, 1, i + 5]) return verts, faces, tot_verts, tot_faces - + + +from bpy.props import IntProperty, FloatProperty, BoolProperty + + class Parameter_Panel_Gem(bpy.types.Panel): bl_space_type = "VIEW_3D" bl_region_type = "TOOLS" bl_context = "objectmode" bl_label = "Gem parameters" + def poll(self, context): # only show this panel if the object selected has propertie "Gem" try: return "Gem" in context.object - except TypeError: return False + except TypeError: + return False + def draw(self,context): layout = self.layout layout.operator("Gem_Parameter_Edit", text="Edit") + + class EditGem(bpy.types.Operator): """Reapply the operator""" bl_idname = "Gem_Parameter_Edit" bl_label = "Edit Gem" - def invoke(self,context,event): + + def invoke(self, context, event): # invoke the adding operator again, # only this time with the Edit property = true - ob = context.active_object - bpy.ops.mesh.primitive_gem_add(Edit = True, + ob = context.active_object + bpy.ops.mesh.primitive_gem_add(edit=True, segments=ob["Segments"], pav_radius = ob["pav_radius"], crown_radius = ob["tab_radius"], crown_height = ob["tab_height"], pav_height = ob["pav_height"]) return {'FINISHED'} + + class AddGem(bpy.types.Operator): """Add a diamond gem""" bl_idname = "mesh.primitive_gem_add" bl_label = "Add Gem" bl_description = "Create an offset faceted gem." bl_options = {'REGISTER', 'UNDO'} - Edit = BoolProperty(name = "", description = "", - default = False, options = {'HIDDEN'}) # whether to add or update - segments = IntProperty(name = "Segments", + edit = BoolProperty(name="", description="", + default=False, options={'HIDDEN'}) # whether to add or update + segments = IntProperty(name="Segments", description="Longitudial segmentation", default=8, min=3, max=265) - pav_radius = FloatProperty(name = "Radius", + pav_radius = FloatProperty(name="Radius", description="Radius of the gem", - default = 1.0, min = 0.01, max = 100.0) - crown_radius = FloatProperty(name = "Table Radius", - description = "Radius of the table(top).", - default = 0.6, min = 0.01, max = 100.0) - crown_height = FloatProperty(name = "Table height", - description = "Height of the top half.", - default = 0.35, min = 0.01, max = 100.0) - pav_height = FloatProperty(name = "Pavillion height", - description = "Height of bottom half.", - default = 0.8, min = 0.01, max = 100.0) - + default=1.0, min=0.01, max=100.0) + crown_radius = FloatProperty(name="Table Radius", + description="Radius of the table(top).", + default=0.6, min=0.01, max=100.0) + crown_height = FloatProperty(name="Table height", + description="Height of the top half.", + default=0.35, min=0.01, max=100.0) + pav_height = FloatProperty(name="Pavillion height", + description="Height of bottom half.", + default=0.8, min=0.01, max=100.0) + def execute(self, context): # create mesh verts, faces, nV, nF = add_gem(self.properties.pav_radius, @@ -151,58 +145,58 @@ class AddGem(bpy.types.Operator): self.properties.segments, self.properties.pav_height, self.properties.crown_height) - + mesh = bpy.data.meshes.new("Gem") - mesh.add_geometry(nV,0,nF) - mesh.verts.foreach_set("co",verts) - mesh.faces.foreach_set("verts_raw",faces) + mesh.add_geometry(nV, 0, nF) + mesh.verts.foreach_set("co", verts) + mesh.faces.foreach_set("verts_raw", faces) mesh.update() - if self.properties.Edit: + if self.properties.edit: # only update ob_new = context.active_object bpy.ops.object.mode_set(mode='EDIT') bpy.ops.mesh.select_all(action='SELECT') - bpy.ops.mesh.delete(type = 'VERT') + bpy.ops.mesh.delete(type='VERT') bpy.ops.object.mode_set(mode='OBJECT') - + ob_new.data = mesh - + scene = context.scene - + # ugh for ob in scene.objects: ob.selected = False - + ob_new.selected = True scene.objects.active = ob_new bpy.ops.object.shade_flat() else: # create new object scene = context.scene - + # ugh for ob in scene.objects: ob.selected = False - + ob_new = bpy.data.objects.new("Gem", mesh) ob_new.data = mesh scene.objects.link(ob_new) ob_new.selected = True - + ob_new.location = scene.cursor_location - + obj_act = scene.objects.active - + if obj_act and obj_act.mode == 'EDIT': # if the mesh is added in edit mode, add the mesh to the # excisting mesh bpy.ops.object.mode_set(mode='OBJECT') - + obj_act.selected = True scene.update() # apply location - + bpy.ops.object.join() # join into the active. - + bpy.ops.object.mode_set(mode='EDIT') else: # add new object and make faces flat @@ -214,7 +208,7 @@ class AddGem(bpy.types.Operator): # thingy work ob_new["Gem"] = 1 ob_new["Segments"] = self.properties.segments - ob_new["pav_radius"] = self.properties.pav_radius + ob_new["pav_radius"] = self.properties.pav_radius ob_new["tab_radius"] = self.properties.crown_radius ob_new["pav_height"] = self.properties.pav_height ob_new["tab_height"] = self.properties.crown_height @@ -226,12 +220,14 @@ class AddGem(bpy.types.Operator): menu_func = (lambda self, context: self.layout.operator(AddGem.bl_idname, text="Gem", icon='PLUGIN')) + def register(): bpy.types.register(AddGem) bpy.types.register(Parameter_Panel_Gem) bpy.types.register(EditGem) bpy.types.INFO_MT_mesh_add.append(menu_func) + def unregister(): bpy.types.unregister(AddGem) bpy.types.unregister(Parameter_Panel_Gem) @@ -242,4 +238,3 @@ def unregister(): if __name__ == "__main__": register() - diff --git a/add_mesh_star.py b/add_mesh_star.py index 4a41479eff65c018f80632ce4c889c5aa0e318c7..b9b46ee31289730ac368a4556ce29d5756ee3fd1 100644 --- a/add_mesh_star.py +++ b/add_mesh_star.py @@ -11,7 +11,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 @@ -29,136 +29,110 @@ bl_addon_info = { 'url': 'http://wiki.blender.org/index.php/Extensions:2.5/Py/Scripts/Add_Star', 'category': 'Add Mesh'} -""" -Name: 'Add_Mesh_Star' -Blender: 250 -""" -""" -Name: 'Star' -Blender: 250 -Group: 'AddMesh' -Tip: 'Add Star Object...' -__author__ = ["Four Mad Men", "FourMadMen.com"] -__version__ = '2.00' -__url__ = [ - "Script, http://www.fourmadmen.com/blender/scripts/AddMesh/star/add_mesh_star.py", - "Script Index, http://www.fourmadmen.com/blender/scripts/index.html", - "Author Site , http://www.fourmadmen.com" -] -email__=["bwiki {at} fourmadmen {dot} com"] +import bpy +import Mathutils -Usage: +def add_star(points, outer_radius, inner_radius, depth): + from Mathutils import Vector, Quaternion + from math import pi -* Launch from Add Mesh menu + PI_2 = pi * 2 + z_axis = (0, 0, 1) -* Modify parameters as desired or keep defaults + verts = [] + faces = [] -""" + segments = points * 2 + tot_verts = segments * 2 + 2 -import bpy -import Mathutils -from math import pi + half_height = depth * 0.5 -def add_star(points, outer_radius, inner_radius, depth): - Vector = Mathutils.Vector - Quaternion = Mathutils.Quaternion - - PI_2 = pi * 2 - z_axis = (0, 0, 1) - - verts = [] - faces = [] - - segments = points * 2 - tot_verts = segments * 2 + 2 - - half_height = depth * .5 - - verts.extend( Vector(0, 0, -half_height) ) - verts.extend( Vector(0, 0, half_height) ) - - i = 2 - alt_idx = 0 - for index in range(segments): - quat = Quaternion(z_axis, (index / segments) * PI_2) - - radius = alt_idx and inner_radius or outer_radius - - vec = Vector(radius, 0, -half_height) * quat - verts.extend([vec.x, vec.y, vec.z]) - it1 = i - i+=1 - - vec = Vector(radius, 0, half_height) * quat - verts.extend([vec.x, vec.y, vec.z]) - ib1 = i - i+=1 - - if i>4: - faces.extend( [0, it1-2, it1, 0] ) - faces.extend( [it1, it1-2, ib1-2, ib1] ) - faces.extend( [1, ib1, ib1-2, 1] ) - - alt_idx = 1 - alt_idx - - faces.extend( [0, it1, 2, 0] ) - faces.extend( [2, it1, ib1, 3] ) - faces.extend( [1, 3, ib1, 1] ) - - return verts, faces + verts.extend(Vector(0.0, 0.0, -half_height)) + verts.extend(Vector(0.0, 0.0, half_height)) + + i = 2 + alt_idx = 0 + for index in range(segments): + quat = Quaternion(z_axis, (index / segments) * PI_2) + + radius = alt_idx and inner_radius or outer_radius + + vec = Vector(radius, 0, -half_height) * quat + verts.extend([vec.x, vec.y, vec.z]) + it1 = i + i += 1 + + vec = Vector(radius, 0, half_height) * quat + verts.extend([vec.x, vec.y, vec.z]) + ib1 = i + i += 1 + + if i > 4: + faces.extend([0, it1 - 2, it1, 0]) + faces.extend([it1, it1 - 2, ib1 - 2, ib1]) + faces.extend([1, ib1, ib1 - 2, 1]) + + alt_idx = 1 - alt_idx + + faces.extend([0, it1, 2, 0]) + faces.extend([2, it1, ib1, 3]) + faces.extend([1, 3, ib1, 1]) + + return verts, faces from bpy.props import IntProperty, FloatProperty + class AddStar(bpy.types.Operator): - '''Add a star mesh.''' - bl_idname = "mesh.primitive_star_add" - bl_label = "Add Star" - bl_options = {'REGISTER', 'UNDO'} - - points = IntProperty(name="Points", - description="Number of points for the star", - default=5, min=2, max=256) - outer_radius = FloatProperty(name="Outer Radius", - description="Outer radius of the star", - default=1.0, min=0.01, max=100.0) - innter_radius = FloatProperty(name="Inner Radius", - description="Inner radius of the star", - default=0.5, min=0.01, max=100.0) - depth = FloatProperty(name="Depth", - description="Depth of the star", - default=0.5, min=0.01, max=100.0) - - def execute(self, context): - verts_loc, faces = add_star(self.properties.points, - self.properties.outer_radius, - self.properties.innter_radius, - self.properties.depth) - - mesh = bpy.data.meshes.new("Star") - - mesh.add_geometry(int(len(verts_loc) / 3), 0, int(len(faces) / 4)) - mesh.verts.foreach_set("co", verts_loc) - mesh.faces.foreach_set("verts_raw", faces) - - scene = context.scene - - # ugh - for ob in scene.objects: - ob.selected = False - - mesh.update() - - ob_new = bpy.data.objects.new("Star", mesh) - ob_new.data = mesh - scene.objects.link(ob_new) - scene.objects.active = ob_new - ob_new.selected = True - - ob_new.location = tuple(context.scene.cursor_location) - - return {'FINISHED'} + '''Add a star mesh.''' + bl_idname = "mesh.primitive_star_add" + bl_label = "Add Star" + bl_options = {'REGISTER', 'UNDO'} + + points = IntProperty(name="Points", + description="Number of points for the star", + default=5, min=2, max=256) + outer_radius = FloatProperty(name="Outer Radius", + description="Outer radius of the star", + default=1.0, min=0.01, max=100.0) + innter_radius = FloatProperty(name="Inner Radius", + description="Inner radius of the star", + default=0.5, min=0.01, max=100.0) + depth = FloatProperty(name="Depth", + description="Depth of the star", + default=0.5, min=0.01, max=100.0) + + def execute(self, context): + verts_loc, faces = add_star(self.properties.points, + self.properties.outer_radius, + self.properties.innter_radius, + self.properties.depth) + + mesh = bpy.data.meshes.new("Star") + + mesh.add_geometry(int(len(verts_loc) / 3), 0, int(len(faces) / 4)) + mesh.verts.foreach_set("co", verts_loc) + mesh.faces.foreach_set("verts_raw", faces) + + scene = context.scene + + # ugh + for ob in scene.objects: + ob.selected = False + + mesh.update() + + ob_new = bpy.data.objects.new("Star", mesh) + ob_new.data = mesh + scene.objects.link(ob_new) + scene.objects.active = ob_new + ob_new.selected = True + + ob_new.location = tuple(context.scene.cursor_location) + + return {'FINISHED'} # Register the operator # Add to a menu, reuse an icon used elsewhere that happens to have fitting name @@ -168,17 +142,18 @@ class AddStar(bpy.types.Operator): menu_func = (lambda self, context: self.layout.operator(AddStar.bl_idname, text="Star", icon='PLUGIN')) + def register(): bpy.types.register(AddStar) bpy.types.INFO_MT_mesh_add.append(menu_func) + def unregister(): bpy.types.unregister(AddStar) bpy.types.INFO_MT_mesh_add.remove(menu_func) - - # Remove "Star" menu from the "Add Mesh" menu. + + # Remove "Star" menu from the "Add Mesh" menu. #space_info.INFO_MT_mesh_add.remove(menu_func) if __name__ == "__main__": register() - diff --git a/space_view3d_cursor_menu.py b/space_view3d_cursor_menu.py index efd4fd19bc6ecd9b78afb11667830ed218c65835..abacebcef4b722650281966d50e107a3b62a965d 100644 --- a/space_view3d_cursor_menu.py +++ b/space_view3d_cursor_menu.py @@ -22,25 +22,7 @@ # # ##### END GPL LICENSE BLOCK ##### -bl_addon_info = { - 'name': '3d View: Cursor Menu', - 'author': 'JayDez', - 'version': '2.4', - 'blender': (2, 5, 3), - 'location': 'View3D > Mouse > Menu ', - 'url': 'http://wiki.blender.org/index.php/Extensions:2.5/Py/Scripts/3d_Cursor_Menu', - 'category': '3d View'} - - """ -Name: '3D Cursor Menu' -Blender: 250 -Group: 'View3D' -""" -__author__ = ["Jonathan Smith (JayDez)"] -__version__ = '2.3' -__url__ = ["http://blenderartists.org/forum/showthread.php?p=1589350"] -__bpydoc__= """ 3D Cursor Menu This adds a 3D Cursor Menu in the 3DView. @@ -67,34 +49,46 @@ v2.2 - (Crouch) - Fix in register function, fix with random quotation v2.1 - (Crouch) - added unregister() and set pivot point to cursor. v2.0 - (JayDez) - 2.5 script (initial revision) v1.0 - Original 2.49 script - """ + +bl_addon_info = { + 'name': '3d View: Cursor Menu', + 'author': 'JayDez', + 'version': '2.4', + 'blender': (2, 5, 3), + 'location': 'View3D > Mouse > Menu ', + 'url': 'http://wiki.blender.org/index.php/Extensions:2.5/Py/Scripts/3d_Cursor_Menu', + 'category': '3d View'} + import bpy from bpy import * + class pivot_cursor(bpy.types.Operator): bl_idname = "view3d.pivot_cursor" bl_label = "Cursor as Pivot Point" - + def poll(self, context): return bpy.context.space_data.pivot_point != 'CURSOR' - + def execute(self, context): bpy.context.space_data.pivot_point = 'CURSOR' return {'FINISHED'} - + + class revert_pivot(bpy.types.Operator): bl_idname = "view3d.revert_pivot" bl_label = "Reverts Pivot Point to median" def poll(self, context): return bpy.context.space_data.pivot_point != 'MEDIAN_POINT' - + def execute(self, context): bpy.context.space_data.pivot_point = 'MEDIAN_POINT' #change this to 'BOUDNING_BOX_CENTER' if needed... return{'FINISHED'} + class VIEW3D_MT_3D_Cursor_Menu(bpy.types.Menu): bl_label = "3D Cursor Menu" @@ -120,6 +114,7 @@ def register(): kmi = km.add_item('wm.call_menu', 'SELECTMOUSE', 'CLICK') kmi.properties.name = "VIEW3D_MT_3D_Cursor_Menu" + def unregister(): bpy.types.unregister(VIEW3D_MT_3D_Cursor_Menu) bpy.types.unregister(pivot_cursor)