Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlijenstina <lijenstina@gmail.com>2016-12-30 22:33:05 +0300
committerlijenstina <lijenstina@gmail.com>2016-12-30 22:33:05 +0300
commitc86080a455579a8c770545e33b95513b43e1a43b (patch)
tree6c392b16b914aa3264b373022602e57ad493e7d7 /add_mesh_extra_objects/add_mesh_torusknot.py
parentc95e86bcef654c0686d3cf4d52446ff9ff8c819f (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_torusknot.py')
-rw-r--r--add_mesh_extra_objects/add_mesh_torusknot.py161
1 files changed, 89 insertions, 72 deletions
diff --git a/add_mesh_extra_objects/add_mesh_torusknot.py b/add_mesh_extra_objects/add_mesh_torusknot.py
index 24bb9b4e..1cdac6b6 100644
--- a/add_mesh_extra_objects/add_mesh_torusknot.py
+++ b/add_mesh_extra_objects/add_mesh_torusknot.py
@@ -1,6 +1,10 @@
# GPL # Author, Anthony D'Agostino
-import bpy, mathutils, math
+import bpy
+from mathutils import Vector
+from math import sin, cos, pi
+from bpy.props import IntProperty
+
def create_mesh_object(context, verts, edges, faces, name):
# Create new mesh
@@ -12,90 +16,103 @@ 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)
+
# ========================
# === Torus Knot Block ===
# ========================
+
def k1(t):
- x = math.cos(t) - 2*math.cos(2*t)
- y = math.sin(t) + 2*math.sin(2*t)
- z = math.sin(3*t)
- return mathutils.Vector([x,y,z])
+ x = cos(t) - 2 * cos(2 * t)
+ y = sin(t) + 2 * sin(2 * t)
+ z = sin(3 * t)
+ return Vector([x, y, z])
+
def k2(t):
- x = 10 * (math.cos(t) + math.cos(3*t)) + math.cos(2*t) + math.cos(4*t)
- y = 6 * math.sin(t) + 10 * math.sin(3*t)
- z = 4 * math.sin(3*t) * math.sin(5*t/2) + 4*math.sin(4*t) - 2*math.sin(6*t)
- return mathutils.Vector([x,y,z]) * 0.2
+ x = 10 * (cos(t) + cos(3 * t)) + cos(2 * t) + cos(4 * t)
+ y = 6 * sin(t) + 10 * sin(3 * t)
+ z = 4 * sin(3 * t) * sin(5 * t / 2) + 4 * sin(4 * t) - 2 * sin(6 * t)
+ return Vector([x, y, z]) * 0.2
+
def k3(t):
- x = 2.5*math.cos(t+math.pi)/3 + 2*math.cos(3*t)
- y = 2.5*math.sin(t)/3 + 2*math.sin(3*t)
- z = 1.5*math.sin(4*t) + math.sin(2*t)/3
- return mathutils.Vector([x,y,z])
+ x = 2.5 * cos(t + pi) / 3 + 2 * cos(3 * t)
+ y = 2.5 * sin(t) / 3 + 2 * sin(3 * t)
+ z = 1.5 * sin(4 * t) + sin(2 * t) / 3
+ return Vector([x, y, z])
+
def make_verts(ures, vres, r2, knotfunc):
- verts = []
- for i in range(ures):
- t1 = (i+0) * 2*math.pi/ures
- t2 = (i+1) * 2*math.pi/ures
- a = knotfunc(t1) # curr point
- b = knotfunc(t2) # next point
- a,b = map(mathutils.Vector, (a,b))
- e = a-b
- f = a+b
- g = e.cross(f)
- h = e.cross(g)
- g.normalize()
- h.normalize()
- for j in range(vres):
- k = j * 2*math.pi/vres
- l = (math.cos(k),0.0,math.sin(k))
- l = mathutils.Vector(l)
- m = l * r2
- x,y,z = m
- n = h*x
- o = g*z
- p = n+o
- q = a+p
- verts.append(q)
- return verts
+ verts = []
+ for i in range(ures):
+ t1 = (i + 0) * 2 * pi / ures
+ t2 = (i + 1) * 2 * pi / ures
+ a = knotfunc(t1) # curr point
+ b = knotfunc(t2) # next point
+ a, b = map(Vector, (a, b))
+ e = a - b
+ f = a + b
+ g = e.cross(f)
+ h = e.cross(g)
+ g.normalize()
+ h.normalize()
+ for j in range(vres):
+ k = j * 2 * pi / vres
+ l = (cos(k), 0.0, sin(k))
+ l = Vector(l)
+ m = l * r2
+ x, y, z = m
+ n = h * x
+ o = g * z
+ p = n + o
+ q = a + p
+ verts.append(q)
+ return verts
+
def make_faces(ures, vres):
- faces = []
- for u in range(0, ures):
- for v in range(0, vres):
- p1 = v + u*vres
- p2 = v + ((u+1)%ures)*vres
- p4 = (v+1)%vres + u*vres
- p3 = (v+1)%vres + ((u+1)%ures)*vres
- faces.append([p4, p3, p2, p1])
- return faces
+ faces = []
+ for u in range(0, ures):
+ for v in range(0, vres):
+ p1 = v + u * vres
+ p2 = v + ((u + 1) % ures) * vres
+ p4 = (v + 1) % vres + u * vres
+ p3 = (v + 1) % vres + ((u + 1) % ures) * vres
+ faces.append([p4, p3, p2, p1])
+ return faces
+
def make_knot(knotidx, ures):
- knots = [k1,k2,k3]
- knotfunc = knots[knotidx-1]
- vres = ures//10
- r2 = 0.5
- verts = make_verts(ures, vres, r2, knotfunc)
- faces = make_faces(ures, vres)
- return (verts, faces)
+ knots = [k1, k2, k3]
+ knotfunc = knots[knotidx - 1]
+ vres = ures // 10
+ r2 = 0.5
+ verts = make_verts(ures, vres, r2, knotfunc)
+ faces = make_faces(ures, vres)
+ return (verts, faces)
+
class AddTorusKnot(bpy.types.Operator):
- """Add a torus-knot mesh"""
- bl_idname = "mesh.primitive_torusknot_add"
- bl_label = "Add Torus Knot"
- bl_options = {"REGISTER", "UNDO"}
-
- resolution = bpy.props.IntProperty(name="Resolution",
- description="Resolution of the Torus Knot",
- default=80, min=30, max=256)
-
- objecttype = bpy.props.IntProperty(name="Knot Type",
- description="Type of Knot",
- default=1, min=1, max=3)
-
- def execute(self, context):
- verts, faces = make_knot(self.objecttype,
- self.resolution)
- obj = create_mesh_object(context, verts, [], faces, "Torus Knot")
- return {'FINISHED'}
+ bl_idname = "mesh.primitive_torusknot_add"
+ bl_label = "Add Torus Knot"
+ bl_description = "Construct a torus knot mesh"
+ bl_options = {"REGISTER", "UNDO"}
+
+ resolution = IntProperty(
+ name="Resolution",
+ description="Resolution of the Torus Knot",
+ default=80,
+ min=30, max=256
+ )
+ objecttype = IntProperty(
+ name="Knot Type",
+ description="Type of Knot",
+ default=1,
+ min=1, max=3
+ )
+
+ def execute(self, context):
+ verts, faces = make_knot(self.objecttype, self.resolution)
+ obj = create_mesh_object(context, verts, [], faces, "Torus Knot")
+
+ return {'FINISHED'}