[Bf-extensions-cvs] [50f8d6d] master: initial commit add_curve_simple.py: T37664
meta-androcto
noreply at git.blender.org
Mon Jun 13 01:37:59 CEST 2016
Commit: 50f8d6d96d14f9247e48c3af8f049a8f25ecf8ba
Author: meta-androcto
Date: Mon Jun 13 09:37:25 2016 +1000
Branches: master
https://developer.blender.org/rBAC50f8d6d96d14f9247e48c3af8f049a8f25ecf8ba
initial commit add_curve_simple.py: T37664
===================================================================
A add_curve_simple.py
===================================================================
diff --git a/add_curve_simple.py b/add_curve_simple.py
new file mode 100644
index 0000000..f348412
--- /dev/null
+++ b/add_curve_simple.py
@@ -0,0 +1,1598 @@
+# ##### 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110 - 1301, USA.
+#
+# ##### END GPL LICENSE BLOCK #####
+
+bl_info = {
+ 'name': 'Simple Curve',
+ 'author': 'Spivak Vladimir (http://cwolf3d.korostyshev.net)',
+ 'version': (1, 5, 2),
+ 'blender': (2, 6, 9),
+ 'location': 'View3D > Add > Curve',
+ 'description': 'Adds Simple Curve',
+ 'warning': '', # used for warning icon and text in addons panel
+ 'wiki_url': 'http://wiki.blender.org/index.php/Extensions:2.6/Py/Scripts/Curve/Simple_curves',
+ 'tracker_url': 'https://developer.blender.org/T37664',
+ 'category': 'Add Curve'}
+
+
+# ------------------------------------------------------------
+#### import modules
+import bpy
+from bpy.props import *
+from mathutils import *
+from math import *
+from bpy_extras.object_utils import *
+from random import *
+
+# ------------------------------------------------------------
+# Point:
+
+
+def SimplePoint():
+ newpoints = []
+
+ newpoints.append([0.0, 0.0, 0.0])
+
+ return newpoints
+
+# ------------------------------------------------------------
+# Line:
+
+
+def SimpleLine(c1=[0.0, 0.0, 0.0], c2=[2.0, 2.0, 2.0]):
+ newpoints = []
+
+ c3 = Vector(c2) - Vector(c1)
+ newpoints.append([0.0, 0.0, 0.0])
+ newpoints.append([c3[0], c3[1], c3[2]])
+
+ return newpoints
+
+# ------------------------------------------------------------
+# Angle:
+
+
+def SimpleAngle(length=1.0, angle=45.0):
+ newpoints = []
+
+ angle = radians(angle)
+ newpoints.append([length, 0.0, 0.0])
+ newpoints.append([0.0, 0.0, 0.0])
+ newpoints.append([length * cos(angle), length * sin(angle), 0.0])
+
+ return newpoints
+
+# ------------------------------------------------------------
+# Distance:
+
+
+def SimpleDistance(length=1.0, center=True):
+ newpoints = []
+
+ if center:
+ newpoints.append([-length / 2, 0.0, 0.0])
+ newpoints.append([length / 2, 0.0, 0.0])
+ else:
+ newpoints.append([0.0, 0.0, 0.0])
+ newpoints.append([length, 0.0, 0.0])
+
+ return newpoints
+
+# ------------------------------------------------------------
+# Circle:
+
+
+def SimpleCircle(sides=4, radius=1.0):
+ newpoints = []
+
+ angle = radians(360) / sides
+ newpoints.append([radius, 0, 0])
+ j = 1
+ while j < sides:
+ t = angle * j
+ x = cos(t) * radius
+ y = sin(t) * radius
+ newpoints.append([x, y, 0])
+ j += 1
+
+ return newpoints
+
+# ------------------------------------------------------------
+# Ellipse:
+
+
+def SimpleEllipse(a=2.0, b=1.0):
+ newpoints = []
+
+ newpoints.append([a, 0.0, 0.0])
+ newpoints.append([0.0, b, 0.0])
+ newpoints.append([-a, 0.0, 0.0])
+ newpoints.append([0.0, -b, 0.0])
+
+ return newpoints
+
+# ------------------------------------------------------------
+# Arc:
+
+
+def SimpleArc(sides=0, radius=1.0, startangle=0.0, endangle=45.0):
+ newpoints = []
+
+ startangle = radians(startangle)
+ endangle = radians(endangle)
+ sides += 1
+
+ angle = (endangle - startangle) / sides
+ x = cos(startangle) * radius
+ y = sin(startangle) * radius
+ newpoints.append([x, y, 0])
+ j = 1
+ while j < sides:
+ t = angle * j
+ x = cos(t + startangle) * radius
+ y = sin(t + startangle) * radius
+ newpoints.append([x, y, 0])
+ j += 1
+ x = cos(endangle) * radius
+ y = sin(endangle) * radius
+ newpoints.append([x, y, 0])
+
+ return newpoints
+
+# ------------------------------------------------------------
+# Sector:
+
+
+def SimpleSector(sides=0, radius=1.0, startangle=0.0, endangle=45.0):
+ newpoints = []
+
+ startangle = radians(startangle)
+ endangle = radians(endangle)
+ sides += 1
+
+ newpoints.append([0, 0, 0])
+ angle = (endangle - startangle) / sides
+ x = cos(startangle) * radius
+ y = sin(startangle) * radius
+ newpoints.append([x, y, 0])
+ j = 1
+ while j < sides:
+ t = angle * j
+ x = cos(t + startangle) * radius
+ y = sin(t + startangle) * radius
+ newpoints.append([x, y, 0])
+ j += 1
+ x = cos(endangle) * radius
+ y = sin(endangle) * radius
+ newpoints.append([x, y, 0])
+
+ return newpoints
+
+# ------------------------------------------------------------
+# Segment:
+
+
+def SimpleSegment(sides=0, a=2.0, b=1.0, startangle=0.0, endangle=45.0):
+ newpoints = []
+
+ startangle = radians(startangle)
+ endangle = radians(endangle)
+ sides += 1
+
+ angle = (endangle - startangle) / sides
+ x = cos(startangle) * a
+ y = sin(startangle) * a
+ newpoints.append([x, y, 0])
+ j = 1
+ while j < sides:
+ t = angle * j
+ x = cos(t + startangle) * a
+ y = sin(t + startangle) * a
+ newpoints.append([x, y, 0])
+ j += 1
+ x = cos(endangle) * a
+ y = sin(endangle) * a
+ newpoints.append([x, y, 0])
+
+ x = cos(endangle) * b
+ y = sin(endangle) * b
+ newpoints.append([x, y, 0])
+ j = sides
+ while j > 0:
+ t = angle * j
+ x = cos(t + startangle) * b
+ y = sin(t + startangle) * b
+ newpoints.append([x, y, 0])
+ j -= 1
+ x = cos(startangle) * b
+ y = sin(startangle) * b
+ newpoints.append([x, y, 0])
+
+ return newpoints
+
+# ------------------------------------------------------------
+# Rectangle:
+
+
+def SimpleRectangle(width=2.0, length=2.0, rounded=0.0, center=True):
+ newpoints = []
+
+ r = rounded / 2
+
+ if center:
+ x = width / 2
+ y = length / 2
+ if rounded != 0.0:
+ newpoints.append([-x + r, y, 0.0])
+ newpoints.append([x - r, y, 0.0])
+ newpoints.append([x, y - r, 0.0])
+ newpoints.append([x, -y + r, 0.0])
+ newpoints.append([x - r, -y, 0.0])
+ newpoints.append([-x + r, -y, 0.0])
+ newpoints.append([-x, -y + r, 0.0])
+ newpoints.append([-x, y - r, 0.0])
+ else:
+ newpoints.append([-x, y, 0.0])
+ newpoints.append([x, y, 0.0])
+ newpoints.append([x, -y, 0.0])
+ newpoints.append([-x, -y, 0.0])
+
+ else:
+ x = width
+ y = length
+ if rounded != 0.0:
+ newpoints.append([r, y, 0.0])
+ newpoints.append([x - r, y, 0.0])
+ newpoints.append([x, y - r, 0.0])
+ newpoints.append([x, r, 0.0])
+ newpoints.append([x - r, 0.0, 0.0])
+ newpoints.append([r, 0.0, 0.0])
+ newpoints.append([0.0, r, 0.0])
+ newpoints.append([0.0, y - r, 0.0])
+ else:
+ newpoints.append([0.0, 0.0, 0.0])
+ newpoints.append([0.0, y, 0.0])
+ newpoints.append([x, y, 0.0])
+ newpoints.append([x, 0.0, 0.0])
+
+ return newpoints
+
+# ------------------------------------------------------------
+# Rhomb:
+
+
+def SimpleRhomb(width=2.0, length=2.0, center=True):
+ newpoints = []
+ x = width / 2
+ y = length / 2
+
+ if center:
+ newpoints.append([-x, 0.0, 0.0])
+ newpoints.append([0.0, y, 0.0])
+ newpoints.append([x, 0.0, 0.0])
+ newpoints.append([0.0, -y, 0.0])
+ else:
+ newpoints.append([x, 0.0, 0.0])
+ newpoints.append([0.0, y, 0.0])
+ newpoints.append([x, length, 0.0])
+ newpoints.append([width, y, 0.0])
+
+ return newpoints
+
+# ------------------------------------------------------------
+# Polygon:
+
+
+def SimplePolygon(sides=3, radius=1.0):
+ newpoints = []
+ angle = radians(360.0) / sides
+ j = 0
+
+ while j < sides:
+ t = angle * j
+ x = sin(t) * radius
+ y = cos(t) * radius
+ newpoints.append([x, y, 0.0])
+ j += 1
+
+ return newpoints
+
+# ------------------------------------------------------------
+# Polygon_ab:
+
+
+def SimplePolygon_ab(sides=3, a=2.0, b=1.0):
+ newpoints = []
+ angle = radians(360.0) / sides
+ j = 0
+
+ while j < sides:
+ t = angle * j
+ x = sin(t) * a
+ y = cos(t) * b
+ newpoints.append([x, y, 0.0])
+ j += 1
+
+ return newpoints
+
+# ------------------------------------------------------------
+# Trapezoid:
+
+
+def SimpleTrapezoid(a=2.0, b=1.0, h=1.0, center=True):
+ newpoints = []
+ x = a / 2
+ y = b / 2
+ r = h / 2
+
+ if center:
+ newpoints.append([-x, -r, 0.0])
+ newpoints.append([-y, r, 0.0])
+ newpoints.append([y, r, 0.0])
+ newpoints.append([x, -r, 0.0])
+
+ else:
+ newpoints.append([0.0, 0.0, 0.0])
+ newpoints.append([x - y, h, 0.0])
+ newpoints.append([x + y, h, 0.0])
+ newpoints.append([a, 0.0, 0.0])
+
+ return newpoints
+
+# ------------------------------------------------------------
+# calculates the matrix for the new object
+# depending on user pref
+
+
+def align_matrix(context, location):
+ loc = Matrix.Translation(location)
+ obj_align = context.user_preferences.edit.object_align
+ if (context.space_data.type == 'VIEW_3D'
+ and obj_align == 'VIEW'):
+ rot = context.space_data.region_3d.view_matrix.to_3x3().inverted().to_4x4()
+ else:
+ rot = Matrix()
+ align_matrix = loc * rot
+
+ return align_matrix
+
+# ------------------------------------------------------
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list