From 3156ef67b748827dd3d273c7c96465b5328780d9 Mon Sep 17 00:00:00 2001 From: meta-androcto Date: Fri, 21 Apr 2017 23:10:46 +1000 Subject: Add curve extra objects: update curves galore, spirofit, thanks Jimmy Haze --- add_curve_extra_objects/add_curve_aceous_galore.py | 1088 ++++++++++++-------- .../add_curve_spirofit_bouncespline.py | 451 ++++---- 2 files changed, 901 insertions(+), 638 deletions(-) (limited to 'add_curve_extra_objects') diff --git a/add_curve_extra_objects/add_curve_aceous_galore.py b/add_curve_extra_objects/add_curve_aceous_galore.py index 649bf559..a20dbd67 100644 --- a/add_curve_extra_objects/add_curve_aceous_galore.py +++ b/add_curve_extra_objects/add_curve_aceous_galore.py @@ -33,6 +33,7 @@ bl_info = { # ------------------------------------------------------------ # import modules + import bpy from bpy.props import ( BoolProperty, @@ -44,13 +45,14 @@ from mathutils import ( Matrix, Vector, ) +from bpy.types import Operator from math import ( sin, cos, pi ) import mathutils.noise as Noise -from bpy.types import Operator + # ------------------------------------------------------------ # Some functions to use with others: @@ -78,8 +80,8 @@ def randnum(low=0.0, high=1.0, seed=0): Noise.seed_set(seed) rnum = Noise.random() - rnum = rnum*(high-low) - rnum = rnum+low + rnum = rnum * (high - low) + rnum = rnum + low return rnum @@ -111,12 +113,12 @@ def vTurbNoise(x, y, z, iScale=0.25, Size=1.0, Depth=6, Hard=0, Basis=0, Seed=0) (type=3-float list) """ rand = randnum(-100, 100, Seed) - if Basis == 9: + if Basis is 9: Basis = 14 - vTurb = Noise.turbulence_vector((x/Size+rand, y/Size+rand, z/Size+rand), Depth, Hard, Basis) - tx = vTurb[0]*iScale - ty = vTurb[1]*iScale - tz = vTurb[2]*iScale + vTurb = Noise.turbulence_vector((x / Size + rand, y / Size + rand, z / Size + rand), Depth, Hard, Basis) + tx = vTurb[0] * iScale + ty = vTurb[1] * iScale + tz = vTurb[2] * iScale return tx, ty, tz # ------------------------------------------------------------------- @@ -144,39 +146,49 @@ def ProfileCurve(type=0, a=0.25, b=0.25): """ newpoints = [] - if type == 1: + if type is 1: # H: a *= 0.5 b *= 0.5 - newpoints = [[-1.0, 1.0, 0.0], [-1.0+a, 1.0, 0.0], - [-1.0+a, b, 0.0], [1.0-a, b, 0.0], [1.0-a, 1.0, 0.0], - [1.0, 1.0, 0.0], [1.0, -1.0, 0.0], [1.0-a, -1.0, 0.0], - [1.0-a, -b, 0.0], [-1.0+a, -b, 0.0], [-1.0+a, -1.0, 0.0], - [-1.0, -1.0, 0.0]] - elif type == 2: + newpoints = [ + [-1.0, 1.0, 0.0], [-1.0+a, 1.0, 0.0], + [-1.0 + a, b, 0.0], [1.0 - a, b, 0.0], [1.0 - a, 1.0, 0.0], + [1.0, 1.0, 0.0], [1.0, -1.0, 0.0], [1.0 - a, -1.0, 0.0], + [1.0 - a, -b, 0.0], [-1.0 + a, -b, 0.0], [-1.0 + a, -1.0, 0.0], + [-1.0, -1.0, 0.0] + ] + elif type is 2: # T: a *= 0.5 - newpoints = [[-1.0, 1.0, 0.0], [1.0, 1.0, 0.0], - [1.0, 1.0-b, 0.0], [a, 1.0-b, 0.0], [a, -1.0, 0.0], - [-a, -1.0, 0.0], [-a, 1.0-b, 0.0], [-1.0, 1.0-b, 0.0]] - elif type == 3: + newpoints = [ + [-1.0, 1.0, 0.0], [1.0, 1.0, 0.0], + [1.0, 1.0 - b, 0.0], [a, 1.0 - b, 0.0], [a, -1.0, 0.0], + [-a, -1.0, 0.0], [-a, 1.0 - b, 0.0], [-1.0, 1.0 - b, 0.0] + ] + elif type is 3: # U: a *= 0.5 - newpoints = [[-1.0, 1.0, 0.0], [-1.0+a, 1.0, 0.0], - [-1.0+a, -1.0+b, 0.0], [1.0-a, -1.0+b, 0.0], [1.0-a, 1.0, 0.0], - [1.0, 1.0, 0.0], [1.0, -1.0, 0.0], [-1.0, -1.0, 0.0]] - elif type == 4: + newpoints = [ + [-1.0, 1.0, 0.0], [-1.0 + a, 1.0, 0.0], + [-1.0 + a, -1.0 + b, 0.0], [1.0 - a, -1.0 + b, 0.0], [1.0 - a, 1.0, 0.0], + [1.0, 1.0, 0.0], [1.0, -1.0, 0.0], [-1.0, -1.0, 0.0] + ] + elif type is 4: # Z: a *= 0.5 - newpoints = [[-0.5, 1.0, 0.0], [a, 1.0, 0.0], - [a, -1.0+b, 0.0], [1.0, -1.0+b, 0.0], [1.0, -1.0, 0.0], - [-a, -1.0, 0.0], [-a, 1.0-b, 0.0], [-1.0, 1.0-b, 0.0], - [-1.0, 1.0, 0.0]] + newpoints = [ + [-0.5, 1.0, 0.0], [a, 1.0, 0.0], + [a, -1.0 + b, 0.0], [1.0, -1.0 + b, 0.0], [1.0, -1.0, 0.0], + [-a, -1.0, 0.0], [-a, 1.0 - b, 0.0], [-1.0, 1.0 - b, 0.0], + [-1.0, 1.0, 0.0] + ] else: # L: - newpoints = [[-1.0, 1.0, 0.0], [-1.0+a, 1.0, 0.0], - [-1.0+a, -1.0+b, 0.0], [1.0, -1.0+b, 0.0], - [1.0, -1.0, 0.0], [-1.0, -1.0, 0.0]] + newpoints = [ + [-1.0, 1.0, 0.0], [-1.0 + a, 1.0, 0.0], + [-1.0 + a, -1.0 + b, 0.0], [1.0, -1.0 + b, 0.0], + [1.0, -1.0, 0.0], [-1.0, -1.0, 0.0] + ] return newpoints # ------------------------------------------------------------ @@ -200,15 +212,17 @@ def ArrowCurve(type=1, a=1.0, b=0.5): """ newpoints = [] - if type == 0: + if type is 0: # Arrow1: a *= 0.5 b *= 0.5 - newpoints = [[-1.0, b, 0.0], [-1.0+a, b, 0.0], - [-1.0+a, 1.0, 0.0], [1.0, 0.0, 0.0], - [-1.0+a, -1.0, 0.0], [-1.0+a, -b, 0.0], - [-1.0, -b, 0.0]] - elif type == 1: + newpoints = [ + [-1.0, b, 0.0], [-1.0 + a, b, 0.0], + [-1.0 + a, 1.0, 0.0], [1.0, 0.0, 0.0], + [-1.0 + a, -1.0, 0.0], [-1.0 + a, -b, 0.0], + [-1.0, -b, 0.0] + ] + elif type is 1: # Arrow2: newpoints = [[-a, b, 0.0], [a, 0.0, 0.0], [-a, -b, 0.0], [0.0, 0.0, 0.0]] else: @@ -216,6 +230,7 @@ def ArrowCurve(type=1, a=1.0, b=0.5): newpoints = [[0.0, b, 0.0], [a, 0.0, 0.0], [0.0, -b, 0.0], [-a, 0.0, 0.0]] return newpoints + # ------------------------------------------------------------ # 2DCurve: Square / Rectangle def RectCurve(type=1, a=1.0, b=0.5, c=1.0): @@ -239,13 +254,15 @@ def RectCurve(type=1, a=1.0, b=0.5, c=1.0): """ newpoints = [] - if type == 1: + if type is 1: # Rounded Rectangle: - newpoints = [[-a, b-b*0.2, 0.0], [-a+a*0.05, b-b*0.05, 0.0], [-a+a*0.2, b, 0.0], - [a-a*0.2, b, 0.0], [a-a*0.05, b-b*0.05, 0.0], [a, b-b*0.2, 0.0], - [a, -b+b*0.2, 0.0], [a-a*0.05, -b+b*0.05, 0.0], [a-a*0.2, -b, 0.0], - [-a+a*0.2, -b, 0.0], [-a+a*0.05, -b+b*0.05, 0.0], [-a, -b+b*0.2, 0.0]] - elif type == 2: + newpoints = [ + [-a, b - b * 0.2, 0.0], [-a + a * 0.05, b - b * 0.05, 0.0], [-a + a * 0.2, b, 0.0], + [a - a * 0.2, b, 0.0], [a - a * 0.05, b - b * 0.05, 0.0], [a, b - b * 0.2, 0.0], + [a, -b + b * 0.2, 0.0], [a - a * 0.05, -b + b * 0.05, 0.0], [a - a * 0.2, -b, 0.0], + [-a + a * 0.2, -b, 0.0], [-a + a * 0.05, -b + b * 0.05, 0.0], [-a, -b + b * 0.2, 0.0] + ] + elif type is 2: # Rounded Rectangle II: newpoints = [] x = a @@ -256,14 +273,14 @@ def RectCurve(type=1, a=1.0, b=0.5, c=1.0): if r > y: r = y - 0.0001 if r > 0: - newpoints.append([-x+r, y, 0]) - newpoints.append([x-r, y, 0]) - newpoints.append([x, y-r, 0]) - newpoints.append([x, -y+r, 0]) - newpoints.append([x-r, -y, 0]) - newpoints.append([-x+r, -y, 0]) - newpoints.append([-x, -y+r, 0]) - newpoints.append([-x, y-r, 0]) + newpoints.append([-x + r, y, 0]) + newpoints.append([x - r, y, 0]) + newpoints.append([x, y - r, 0]) + newpoints.append([x, -y + r, 0]) + newpoints.append([x - r, -y, 0]) + newpoints.append([-x + r, -y, 0]) + newpoints.append([-x, -y + r, 0]) + newpoints.append([-x, y - r, 0]) else: newpoints.append([-x, y, 0]) newpoints.append([x, y, 0]) @@ -274,6 +291,7 @@ def RectCurve(type=1, a=1.0, b=0.5, c=1.0): newpoints = [[-a, b, 0.0], [a, b, 0.0], [a, -b, 0.0], [-a, -b, 0.0]] return newpoints + # ------------------------------------------------------------ # 2DCurve: Star: def StarCurve(starpoints=8, innerradius=0.5, outerradius=1.0, twist=0.0): @@ -297,15 +315,15 @@ def StarCurve(starpoints=8, innerradius=0.5, outerradius=1.0, twist=0.0): """ newpoints = [] - step = (2.0/(starpoints)) + step = 2.0 / starpoints i = 0 while i < starpoints: - t = (i*step) - x1 = cos(t*pi)*outerradius - y1 = sin(t*pi)*outerradius + t = i * step + x1 = cos(t * pi) * outerradius + y1 = sin(t * pi) * outerradius newpoints.append([x1, y1, 0]) - x2 = cos(t*pi+(pi/starpoints+twist))*innerradius - y2 = sin(t*pi+(pi/starpoints+twist))*innerradius + x2 = cos(t * pi + (pi / starpoints + twist)) * innerradius + y2 = sin(t * pi + (pi / starpoints + twist)) * innerradius newpoints.append([x2, y2, 0]) i += 1 return newpoints @@ -333,23 +351,24 @@ def FlowerCurve(petals=8, innerradius=0.5, outerradius=1.0, petalwidth=2.0): """ newpoints = [] - step = (2.0/(petals)) - pet = (step/pi*2)*petalwidth + step = 2.0 / petals + pet = (step / pi * 2) * petalwidth i = 0 while i < petals: - t = (i*step) - x1 = cos(t*pi-(pi/petals))*innerradius - y1 = sin(t*pi-(pi/petals))*innerradius + t = i * step + x1 = cos(t * pi - (pi / petals)) * innerradius + y1 = sin(t * pi - (pi / petals)) * innerradius newpoints.append([x1, y1, 0]) - x2 = cos(t*pi-pet)*outerradius - y2 = sin(t*pi-pet)*outerradius + x2 = cos(t * pi - pet) * outerradius + y2 = sin(t * pi - pet) * outerradius newpoints.append([x2, y2, 0]) - x3 = cos(t*pi+pet)*outerradius - y3 = sin(t*pi+pet)*outerradius + x3 = cos(t * pi + pet) * outerradius + y3 = sin(t * pi + pet) * outerradius newpoints.append([x3, y3, 0]) i += 1 return newpoints + # ------------------------------------------------------------ # 2DCurve: Arc,Sector,Segment,Ring: def ArcCurve(sides=6, startangle=0.0, endangle=90.0, innerradius=0.5, outerradius=1.0, type=3): @@ -378,14 +397,14 @@ def ArcCurve(sides=6, startangle=0.0, endangle=90.0, innerradius=0.5, outerradiu newpoints = [] sides += 1 - angle = (2.0*(1.0/360.0)) + angle = 2.0 * (1.0 / 360.0) endangle -= startangle - step = ((angle*endangle)/(sides-1)) + step = (angle * endangle) / (sides - 1) i = 0 while i < sides: - t = (i*step) + angle*startangle - x1 = sin(t*pi)*outerradius - y1 = cos(t*pi)*outerradius + t = (i * step) + angle * startangle + x1 = sin(t * pi) * outerradius + y1 = cos(t * pi) * outerradius newpoints.append([x1, y1, 0]) i += 1 @@ -393,19 +412,20 @@ def ArcCurve(sides=6, startangle=0.0, endangle=90.0, innerradius=0.5, outerradiu # Arc: turn cyclic curve flag off! # Segment: - if type == 2: + if type is 2: newpoints.append([0, 0, 0]) # Ring: - elif type == 3: - j = sides-1 + elif type is 3: + j = sides - 1 while j > -1: - t = (j*step) + angle*startangle - x2 = sin(t*pi)*innerradius - y2 = cos(t*pi)*innerradius + t = (j * step) + angle * startangle + x2 = sin(t * pi) * innerradius + y2 = cos(t * pi) * innerradius newpoints.append([x2, y2, 0]) j -= 1 return newpoints + # ------------------------------------------------------------ # 2DCurve: Cog wheel: def CogCurve(theeth=8, innerradius=0.8, middleradius=0.95, outerradius=1.0, bevel=0.5): @@ -431,33 +451,34 @@ def CogCurve(theeth=8, innerradius=0.8, middleradius=0.95, outerradius=1.0, beve """ newpoints = [] - step = (2.0/(theeth)) - pet = (step/pi*2) - bevel = 1.0-bevel + step = 2.0 / theeth + pet = step / pi * 2 + bevel = 1.0 - bevel i = 0 while i < theeth: - t = (i*step) - x1 = cos(t*pi-(pi/theeth)-pet)*innerradius - y1 = sin(t*pi-(pi/theeth)-pet)*innerradius + t = i * step + x1 = cos(t * pi - (pi / theeth) - pet) * innerradius + y1 = sin(t * pi - (pi / theeth) - pet) * innerradius newpoints.append([x1, y1, 0]) - x2 = cos(t*pi-(pi/theeth)+pet)*innerradius - y2 = sin(t*pi-(pi/theeth)+pet)*innerradius + x2 = cos(t * pi - (pi / theeth) + pet) * innerradius + y2 = sin(t * pi - (pi / theeth) + pet) * innerradius newpoints.append([x2, y2, 0]) - x3 = cos(t*pi-pet)*middleradius - y3 = sin(t*pi-pet)*middleradius + x3 = cos(t * pi - pet) * middleradius + y3 = sin(t * pi - pet) * middleradius newpoints.append([x3, y3, 0]) - x4 = cos(t*pi-(pet*bevel))*outerradius - y4 = sin(t*pi-(pet*bevel))*outerradius + x4 = cos(t * pi - (pet * bevel)) * outerradius + y4 = sin(t * pi - (pet * bevel)) * outerradius newpoints.append([x4, y4, 0]) - x5 = cos(t*pi+(pet*bevel))*outerradius - y5 = sin(t*pi+(pet*bevel))*outerradius + x5 = cos(t * pi + (pet * bevel)) * outerradius + y5 = sin(t * pi + (pet * bevel)) * outerradius newpoints.append([x5, y5, 0]) - x6 = cos(t*pi+pet)*middleradius - y6 = sin(t*pi+pet)*middleradius + x6 = cos(t * pi + pet) * middleradius + y6 = sin(t * pi + pet) * middleradius newpoints.append([x6, y6, 0]) i += 1 return newpoints + # ------------------------------------------------------------ # 2DCurve: nSide: def nSideCurve(sides=6, radius=1.0): @@ -477,12 +498,12 @@ def nSideCurve(sides=6, radius=1.0): """ newpoints = [] - step = (2.0/(sides)) + step = 2.0 / sides i = 0 while i < sides: - t = (i*step) - x = sin(t*pi)*radius - y = cos(t*pi)*radius + t = i * step + x = sin(t * pi) * radius + y = cos(t * pi) * radius newpoints.append([x, y, 0]) i += 1 return newpoints @@ -513,18 +534,19 @@ def SplatCurve(sides=24, scale=1.0, seed=0, basis=0, radius=1.0): """ newpoints = [] - step = (2.0/(sides)) + step = 2.0 / sides i = 0 while i < sides: - t = (i*step) + t = i * step turb = vTurbNoise(t, t, t, 1.0, scale, 6, 0, basis, seed) turb = turb[2] * 0.5 + 0.5 - x = sin(t*pi)*radius * turb - y = cos(t*pi)*radius * turb + x = sin(t * pi) * radius * turb + y = cos(t * pi) * radius * turb newpoints.append([x, y, 0]) i += 1 return newpoints + #------------------------------------------------------------ # Cycloid curve def CycloidCurve(number=100, type=0, R=4.0, r=1.0, d=1.0): @@ -552,37 +574,38 @@ def CycloidCurve(number=100, type=0, R=4.0, r=1.0, d=1.0): a = R b = r newpoints = [] - step = (2.0/(number-1)) + step = 2.0 / (number - 1) i = 0 - if type == 1: + if type is 1: # Hypotrochoid / Hypocycloid while i < number: - t = i*step - x = (((a-b)*cos(t*pi))+(d*cos(((a+b)/b)*t*pi))) - y = (((a-b)*sin(t*pi))-(d*sin(((a+b)/b)*t*pi))) + t = i * step + x = ((a - b) * cos(t * pi)) + (d * cos(((a + b) / b) * t * pi)) + y = ((a - b) * sin(t * pi)) - (d * sin(((a + b) / b) * t * pi)) z = 0 - newpoints.append([x,y,z]) - i+=1 - elif type == 2: + newpoints.append([x, y, z]) + i += 1 + elif type is 2: # Epitrochoid / Epycycloid while i < number: - t = i*step - x = (((a+b)*cos(t*pi))-(d*cos(((a+b)/b)*t*pi))) - y = (((a+b)*sin(t*pi))-(d*sin(((a+b)/b)*t*pi))) + t = i * step + x = ((a + b) * cos(t * pi)) - (d * cos(((a + b) / b) * t * pi)) + y = ((a + b) * sin(t * pi)) - (d * sin(((a + b) / b) * t * pi)) z = 0 - newpoints.append([x,y,z]) - i+=1 + newpoints.append([x, y, z]) + i += 1 else: # Cycloid while i < number: - t = (i*step*pi)*a - x = (t-sin(t)*b) - y = (1-cos(t)*b) + t = (i * step * pi) * a + x = (t - sin(t) * b) + y = (1 - cos(t) * b) z = 0 - newpoints.append([x,y,z]) - i+=1 + newpoints.append([x, y, z]) + i += 1 return newpoints + # ----------------------------------------------------------- # 3D curve shape functions: # ----------------------------------------------------------- @@ -616,24 +639,24 @@ def HelixCurve(number=100, height=2.0, startangle=0.0, endangle=360.0, width=1.0 """ newpoints = [] - angle = (2.0/360.0)*(endangle-startangle) - step = angle/(number-1) - h = height/angle - start = (startangle*2.0/360.0) + angle = (2.0 / 360.0 ) * (endangle - startangle) + step = angle / (number - 1) + h = height / angle + start = startangle * 2.0 / 360.0 a /= angle i = 0 while i < number: - t = (i*step+start) - x = sin((t*pi)) * (1.0 + cos(t * pi * a - (b * pi))) * (0.25 * width) - y = cos((t*pi)) * (1.0 + cos(t * pi * a - (b * pi))) * (0.25 * width) - z = (t * h) - h*start + t = (i * step + start) + x = sin((t * pi)) * (1.0 + cos(t * pi * a - (b * pi))) * (0.25 * width) + y = cos((t * pi)) * (1.0 + cos(t * pi * a - (b * pi))) * (0.25 * width) + z = (t * h) - h * start newpoints.append([x, y, z]) i += 1 return newpoints #------------------------------------------------------------ # 3D Noise curve -def NoiseCurve(type=0, number=100, length=2.0, size=0.5, scale=[0.5,0.5,0.5], taper=0.0, octaves=2, basis=0, seed=0): +def NoiseCurve(type=0, number=100, length=2.0, size=0.5, scale=[0.5,0.5,0.5], octaves=2, basis=0, seed=0): """ Create noise curve @@ -646,8 +669,6 @@ def NoiseCurve(type=0, number=100, length=2.0, size=0.5, scale=[0.5,0.5,0.5], ta (type=float) scale - noise intensity scale x,y,z (type=list) - taper - taper scale - (type=float) basis - noise basis (type=int) seed - noise random seed @@ -660,67 +681,74 @@ def NoiseCurve(type=0, number=100, length=2.0, size=0.5, scale=[0.5,0.5,0.5], ta """ newpoints = [] - step = (length/number) + step = (length / number) i = 0 - if type == 1: + if type is 1: # noise circle / arc while i < number: - t = i*step + t = i * step v = vTurbNoise(t, t, t, 1.0, size, octaves, 0, basis, seed) - x = sin(t*pi)*2.0 + (v[0] * scale[0]) - y = cos(t*pi)*2.0 + (v[1] * scale[1]) - z = v[2]*scale[2] + x = sin(t * pi) * 2.0 + (v[0] * scale[0]) + y = cos(t *pi) * 2.0 + (v[1] * scale[1]) + z = v[2] * scale[2] newpoints.append([x, y, z]) i += 1 - elif type == 2: + elif type is 2: # noise knot / ball while i < number: - t = i*step - v = vTurbNoise(t,t,t, scale[2], 1.0, octaves, 0, basis, seed) + t = i * step + v = vTurbNoise(t, t, t, scale[2], 1.0, octaves, 0, basis, seed) newpoints.append([v[0], v[1], v[2]]) - i+=1 + i += 1 else: # noise linear while i < number: - t = i*step - tap = length-taper*t - v = vTurbNoise(t,t,t, 1.0, size, octaves, 0, basis, seed) - x = t + v[0] * (scale[0]/length) - y = v[1] * (scale[1]/length) * tap - z = v[2] * (scale[2]/length) * tap - newpoints.append([x,y,z]) - i+=1 + t = i * step + v = vTurbNoise(t, t, t, 1.0, size, octaves, 0, basis, seed) + x = t + v[0] * (scale[0] / length) + y = v[1] * (scale[1] / length) + z = v[2] * (scale[2] / length) + newpoints.append([x, y, z]) + i += 1 return newpoints - + + # ------------------------------------------------------------ # calculates the matrix for the new object # depending on user pref def align_matrix(context): + loc = Matrix.Translation(context.scene.cursor_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 + # ------------------------------------------------------------ -# Curve creation functions -# sets bezierhandles to auto +# Curve creation functions, sets bezierhandles to auto def setBezierHandles(obj, mode='AUTOMATIC'): scene = bpy.context.scene + if obj.type != 'CURVE': return + scene.objects.active = obj bpy.ops.object.mode_set(mode='EDIT', toggle=True) bpy.ops.curve.select_all(action='SELECT') bpy.ops.curve.handle_type_set(type=mode) bpy.ops.object.mode_set(mode='OBJECT', toggle=True) + # get array of vertcoordinates acording to splinetype def vertsToPoints(Verts, splineType): + # main vars vertArray = [] @@ -734,21 +762,27 @@ def vertsToPoints(Verts, splineType): for v in Verts: vertArray += v if splineType == 'NURBS': - vertArray.append(1) # for nurbs w=1 - else: # for poly w=0 + # for nurbs w=1 + vertArray.append(1) + else: + # for poly w=0 vertArray.append(0) return vertArray + # create new CurveObject from vertarray and splineType def createCurve(context, vertArray, self, align_matrix): - # options to vars - splineType = self.outputType # output splineType 'POLY' 'NURBS' 'BEZIER' - name = self.ProfileType # GalloreType as name + scene = context.scene + + # output splineType 'POLY' 'NURBS' 'BEZIER' + splineType = self.outputType + + # GalloreType as name + name = self.ProfileType # create curve - scene = context.scene - newCurve = bpy.data.curves.new(name, type='CURVE') # curvedatablock - newSpline = newCurve.splines.new(type=splineType) # spline + newCurve = bpy.data.curves.new(name, type='CURVE') + newSpline = newCurve.splines.new(type=splineType) # create spline from vertarray if splineType == 'BEZIER': @@ -766,11 +800,11 @@ def createCurve(context, vertArray, self, align_matrix): newSpline.order_u = self.order_u # create object with newCurve - new_obj = bpy.data.objects.new(name, newCurve) # object - scene.objects.link(new_obj) # place in active scene - new_obj.select = True # set as selected - scene.objects.active = new_obj # set as active - new_obj.matrix_world = align_matrix # apply matrix + new_obj = bpy.data.objects.new(name, newCurve) + scene.objects.link(new_obj) + new_obj.select = True + scene.objects.active = new_obj + new_obj.matrix_world = align_matrix # set bezierhandles if splineType == 'BEZIER': @@ -784,6 +818,7 @@ def main(context, self, align_matrix): # deselect all objects bpy.ops.object.select_all(action='DESELECT') + # options proType = self.ProfileType splineType = self.outputType @@ -793,74 +828,97 @@ def main(context, self, align_matrix): # get verts if proType == 'Profile': - verts = ProfileCurve(self.ProfileCurveType, - self.ProfileCurvevar1, - self.ProfileCurvevar2) + verts = ProfileCurve( + self.ProfileCurveType, + self.ProfileCurvevar1, + self.ProfileCurvevar2 + ) if proType == 'Arrow': - verts = ArrowCurve(self.MiscCurveType, - self.MiscCurvevar1, - self.MiscCurvevar2) + verts = ArrowCurve( + self.MiscCurveType, + self.MiscCurvevar1, + self.MiscCurvevar2 + ) if proType == 'Rectangle': - verts = RectCurve(self.MiscCurveType, - self.MiscCurvevar1, - self.MiscCurvevar2, - self.MiscCurvevar3) + verts = RectCurve( + self.MiscCurveType, + self.MiscCurvevar1, + self.MiscCurvevar2, + self.MiscCurvevar3 + ) if proType == 'Flower': - verts = FlowerCurve(self.petals, - innerRadius, - outerRadius, - self.petalWidth) + verts = FlowerCurve( + self.petals, + innerRadius, + outerRadius, + self.petalWidth + ) if proType == 'Star': - verts = StarCurve(self.starPoints, - innerRadius, - outerRadius, - self.starTwist) + verts = StarCurve( + self.starPoints, + innerRadius, + outerRadius, + self.starTwist + ) if proType == 'Arc': - verts = ArcCurve(self.arcSides, - self.startAngle, - self.endAngle, - innerRadius, - outerRadius, - self.arcType) + verts = ArcCurve( + self.arcSides, + self.startAngle, + self.endAngle, + innerRadius, + outerRadius, + self.arcType + ) if proType == 'Cogwheel': - verts = CogCurve(self.teeth, - innerRadius, - middleRadius, - outerRadius, - self.bevel) + verts = CogCurve( + self.teeth, + innerRadius, + middleRadius, + outerRadius, + self.bevel + ) if proType == 'Nsided': - verts = nSideCurve(self.Nsides, - outerRadius) + verts = nSideCurve( + self.Nsides, + outerRadius + ) if proType == 'Splat': - verts = SplatCurve(self.splatSides, - self.splatScale, - self.seed, - self.basis, - outerRadius) + verts = SplatCurve( + self.splatSides, + self.splatScale, + self.seed, + self.basis, + outerRadius + ) if proType == 'Cycloid': - verts = CycloidCurve(self.cycloPoints, - self.cycloType, - self.cyclo_a, - self.cyclo_b, - self.cyclo_d) + verts = CycloidCurve( + self.cycloPoints, + self.cycloType, + self.cyclo_a, + self.cyclo_b, + self.cyclo_d + ) if proType == 'Helix': - verts = HelixCurve(self.helixPoints, - self.helixHeight, - self.helixStart, - self.helixEnd, - self.helixWidth, - self.helix_a, - self.helix_b) + verts = HelixCurve( + self.helixPoints, + self.helixHeight, + self.helixStart, + self.helixEnd, + self.helixWidth, + self.helix_a, + self.helix_b + ) if proType == 'Noise': - verts = NoiseCurve(self.noiseType, - self.noisePoints, - self.noiseLength, - self.noiseSize, - [self.noiseScaleX, self.noiseScaleY, self.noiseScaleZ], - self.noiseTaper, - self.noiseOctaves, - self.noiseBasis, - self.noiseSeed) + verts = NoiseCurve( + self.noiseType, + self.noisePoints, + self.noiseLength, + self.noiseSize, + [self.noiseScaleX, self.noiseScaleY, self.noiseScaleZ], + self.noiseOctaves, + self.noiseBasis, + self.noiseSeed + ) # turn verts into array vertArray = vertsToPoints(verts, splineType) @@ -873,7 +931,7 @@ def main(context, self, align_matrix): class Curveaceous_galore(Operator): """Add many types of curves""" bl_idname = "mesh.curveaceous_galore" - bl_label = "2D Profiles" + bl_label = "Curve Profiles" bl_options = {'REGISTER', 'UNDO', 'PRESET'} # align_matrix for the invoke @@ -892,256 +950,406 @@ class Curveaceous_galore(Operator): ('Splat', 'Splat', 'Splat'), ('Cycloid', 'Cycloid', 'Cycloid'), ('Helix', 'Helix (3D)', 'Helix'), - ('Noise', 'Noise (3D)', 'Noise')] - ProfileType = EnumProperty(name="Type", + ('Noise', 'Noise (3D)', 'Noise') + ] + ProfileType = EnumProperty( + name="Type", description="Form of Curve to create", - items=ProfileTypes) + items=ProfileTypes + ) SplineTypes = [ ('POLY', 'Poly', 'POLY'), ('NURBS', 'Nurbs', 'NURBS'), - ('BEZIER', 'Bezier', 'BEZIER')] - outputType = EnumProperty(name="Output splines", + ('BEZIER', 'Bezier', 'BEZIER') + ] + outputType = EnumProperty( + name="Output splines", description="Type of splines to output", - items=SplineTypes) + items=SplineTypes + ) # Curve Options shapeItems = [ ('2D', '2D', '2D'), - ('3D', '3D', '3D')] - shape = EnumProperty(name="2D / 3D", - items=shapeItems, - description="2D or 3D Curve") - use_cyclic_u = BoolProperty(name="Cyclic", + ('3D', '3D', '3D') + ] + shape = EnumProperty( + name="2D / 3D", + description="2D or 3D Curve", + items=shapeItems + ) + use_cyclic_u = BoolProperty( + name="Cyclic", default=True, - description="make curve closed") - endp_u = BoolProperty(name="use_endpoint_u", + description="make curve closed" + ) + endp_u = BoolProperty( + name="use_endpoint_u", default=True, - description="stretch to endpoints") - order_u = IntProperty(name="order_u", + description="stretch to endpoints" + ) + order_u = IntProperty( + name="order_u", default=4, - min=2, soft_min=2, - max=6, soft_max=6, - description="Order of nurbs spline") + min=2, + soft_min=2, + max=6, + soft_max=6, + description="Order of nurbs spline" + ) bezHandles = [ ('VECTOR', 'Vector', 'VECTOR'), - ('AUTOMATIC', 'Auto', 'AUTOMATIC')] - handleType = EnumProperty(name="Handle type", + ('AUTOMATIC', 'Auto', 'AUTOMATIC') + ] + handleType = EnumProperty( + name="Handle type", default='AUTOMATIC', description="bezier handles type", - items=bezHandles) + items=bezHandles + ) # ProfileCurve properties - ProfileCurveType = IntProperty(name="Type", - min=1, soft_min=1, - max=5, soft_max=5, - default=1, - description="Type of ProfileCurve") - ProfileCurvevar1 = FloatProperty(name="var_1", - default=0.25, - description="var1 of ProfileCurve") - ProfileCurvevar2 = FloatProperty(name="var_2", - default=0.25, - description="var2 of ProfileCurve") + ProfileCurveType = IntProperty( + name="Type", + min=1, + soft_min=1, + max=5, + soft_max=5, + default=1, + description="Type of ProfileCurve" + ) + ProfileCurvevar1 = FloatProperty( + name="var_1", + default=0.25, + description="var1 of ProfileCurve" + ) + ProfileCurvevar2 = FloatProperty( + name="var_2", + default=0.25, + description="var2 of ProfileCurve" + ) # Arrow, Rectangle, MiscCurve properties - MiscCurveType = IntProperty(name="Type", - min=0, soft_min=0, - max=3, soft_max=3, - default=0, - description="Type of Curve") - MiscCurvevar1 = FloatProperty(name="var_1", - default=1.0, - description="var1 of Curve") - MiscCurvevar2 = FloatProperty(name="var_2", - default=0.5, - description="var2 of Curve") - MiscCurvevar3 = FloatProperty(name="var_3", - default=0.1, - min=0, soft_min=0, - description="var3 of Curve") + MiscCurveType = IntProperty( + name="Type", + min=0, + soft_min=0, + max=3, + soft_max=3, + default=0, + description="Type of Curve" + ) + MiscCurvevar1 = FloatProperty( + name="var_1", + default=1.0, + description="var1 of Curve" + ) + MiscCurvevar2 = FloatProperty( + name="var_2", + default=0.5, + description="var2 of Curve" + ) + MiscCurvevar3 = FloatProperty( + name="var_3", + default=0.1, + min=0, + soft_min=0, + description="var3 of Curve" + ) # Common properties - innerRadius = FloatProperty(name="Inner radius", - default=0.5, - min=0, soft_min=0, - description="Inner radius") - middleRadius = FloatProperty(name="Middle radius", - default=0.95, - min=0, soft_min=0, - description="Middle radius") - outerRadius = FloatProperty(name="Outer radius", - default=1.0, - min=0, soft_min=0, - description="Outer radius") + innerRadius = FloatProperty( + name="Inner radius", + default=0.5, + min=0, + soft_min=0, + description="Inner radius" + ) + middleRadius = FloatProperty( + name="Middle radius", + default=0.95, + min=0, + soft_min=0, + description="Middle radius" + ) + outerRadius = FloatProperty( + name="Outer radius", + default=1.0, + min=0, + soft_min=0, + description="Outer radius" + ) # Flower properties - petals = IntProperty(name="Petals", - default=8, - min=2, soft_min=2, - description="Number of petals") - petalWidth = FloatProperty(name="Petal width", - default=2.0, - min=0.01, soft_min=0.01, - description="Petal width") + petals = IntProperty( + name="Petals", + default=8, + min=2, + soft_min=2, + description="Number of petals" + ) + petalWidth = FloatProperty( + name="Petal width", + default=2.0, + min=0.01, + soft_min=0.01, + description="Petal width" + ) # Star properties - starPoints = IntProperty(name="Star points", - default=8, - min=2, soft_min=2, - description="Number of star points") - starTwist = FloatProperty(name="Twist", - default=0.0, - description="Twist") + starPoints = IntProperty( + name="Star points", + default=8, + min=2, + soft_min=2, + description="Number of star points" + ) + starTwist = FloatProperty( + name="Twist", + default=0.0, + description="Twist" + ) # Arc properties - arcSides = IntProperty(name="Arc sides", - default=6, - min=1, soft_min=1, - description="Sides of arc") - startAngle = FloatProperty(name="Start angle", - default=0.0, - description="Start angle") - endAngle = FloatProperty(name="End angle", - default=90.0, - description="End angle") - arcType = IntProperty(name="Arc type", - default=3, - min=1, soft_min=1, - max=3, soft_max=3, - description="Sides of arc") + arcSides = IntProperty( + name="Arc sides", + default=6, + min=1, + soft_min=1, + description="Sides of arc" + ) + startAngle = FloatProperty( + name="Start angle", + default=0.0, + description="Start angle" + ) + endAngle = FloatProperty( + name="End angle", + default=90.0, + description="End angle" + ) + arcType = IntProperty( + name="Arc type", + default=3, + min=1, + soft_min=1, + max=3, + soft_max=3, + description="Sides of arc" + ) # Cogwheel properties - teeth = IntProperty(name="Teeth", - default=8, - min=2, soft_min=2, - description="number of teeth") - bevel = FloatProperty(name="Bevel", - default=0.5, - min=0, soft_min=0, - max=1, soft_max=1, - description="Bevel") + teeth = IntProperty( + name="Teeth", + default=8, + min=2, + soft_min=2, + description="number of teeth" + ) + bevel = FloatProperty( + name="Bevel", + default=0.5, + min=0, + soft_min=0, + max=1, + soft_max=1, + description="Bevel" + ) # Nsided property - Nsides = IntProperty(name="Sides", - default=8, - min=3, soft_min=3, - description="Number of sides") + Nsides = IntProperty( + name="Sides", + default=8, + min=3, + soft_min=3, + description="Number of sides" + ) # Splat properties - splatSides = IntProperty(name="Splat sides", - default=24, - min=3, soft_min=3, - description="Splat sides") - splatScale = FloatProperty(name="Splat scale", - default=1.0, - min=0.0001, soft_min=0.0001, - description="Splat scale") - seed = IntProperty(name="Seed", - default=0, - min=0, soft_min=0, - description="Seed") - basis = IntProperty(name="Basis", - default=0, - min=0, soft_min=0, - max=14, soft_max=14, - description="Basis") + splatSides = IntProperty( + name="Splat sides", + default=24, + min=3, + soft_min=3, + description="Splat sides" + ) + splatScale = FloatProperty( + name="Splat scale", + default=1.0, + min=0.0001, + soft_min=0.0001, + description="Splat scale" + ) + seed = IntProperty( + name="Seed", + default=0, + min=0, + soft_min=0, + description="Seed" + ) + basis = IntProperty( + name="Basis", + default=0, + min=0, + soft_min=0, + max=14, + soft_max=14, + description="Basis" + ) # Helix properties - helixPoints = IntProperty(name="resolution", - default=100, - min=3, soft_min=3, - description="resolution") - helixHeight = FloatProperty(name="Height", - default=2.0, - min=0, soft_min=0, - description="Helix height") - helixStart = FloatProperty(name="Start angle", - default=0.0, - description="Helix start angle") - helixEnd = FloatProperty(name="Endangle", - default=360.0, - description="Helix end angle") - helixWidth = FloatProperty(name="Width", - default=1.0, - description="Helix width") - helix_a = FloatProperty(name="var_1", - default=0.0, - description="Helix var1") - helix_b = FloatProperty(name="var_2", - default=0.0, - description="Helix var2") + helixPoints = IntProperty( + name="resolution", + default=100, + min=3, + soft_min=3, + description="resolution" + ) + helixHeight = FloatProperty( + name="Height", + default=2.0, + min=0, soft_min=0, + description="Helix height" + ) + helixStart = FloatProperty( + name="Start angle", + default=0.0, + description="Helix start angle" + ) + helixEnd = FloatProperty( + name="Endangle", + default=360.0, + description="Helix end angle" + ) + helixWidth = FloatProperty( + name="Width", + default=1.0, + description="Helix width" + ) + helix_a = FloatProperty( + name="var_1", + default=0.0, + description="Helix var1" + ) + helix_b = FloatProperty( + name="var_2", + default=0.0, + description="Helix var2" + ) # Cycloid properties - cycloPoints = IntProperty(name="Resolution", - default=100, - min=3, soft_min=3, - description="Resolution") - cycloType = IntProperty(name="Type", - default=1, - min=0, soft_min=0, - max=2, soft_max=2, - description="Type: Cycloid , Hypocycloid / Hypotrochoid , Epicycloid / Epitrochoid") - cyclo_a = FloatProperty(name="R", - default=4.0, - min=0.01, soft_min=0.01, - description="Cycloid: R radius a") - cyclo_b = FloatProperty(name="r", - default=1.0, - min=0.01, soft_min=0.01, - description="Cycloid: r radius b") - cyclo_d = FloatProperty(name="d", - default=1.0, - description="Cycloid: d distance") + cycloPoints = IntProperty( + name="Resolution", + default=100, + min=3, + soft_min=3, + description="Resolution" + ) + cycloType = IntProperty( + name="Type", + default=1, + min=0, + soft_min=0, + max=2, + soft_max=2, + description="Type: Cycloid , Hypocycloid / Hypotrochoid , Epicycloid / Epitrochoid") + cyclo_a = FloatProperty( + name="R", + default=4.0, + min=0.01, + soft_min=0.01, + description="Cycloid: R radius a" + ) + cyclo_b = FloatProperty( + name="r", + default=1.0, + min=0.01, + soft_min=0.01, + description="Cycloid: r radius b" + ) + cyclo_d = FloatProperty( + name="d", + default=1.0, + description="Cycloid: d distance" + ) # Noise properties - noiseType = IntProperty(name="Type", - default=0, - min=0, soft_min=0, - max=2, soft_max=2, - description="Noise curve type: Linear, Circular or Knot") - noisePoints = IntProperty(name="Resolution", - default=100, - min=3, soft_min=3, - description="Resolution") - noiseLength = FloatProperty(name="Length", - default=2.0, - min=0.01, soft_min=0.01, - description="Curve Length") - noiseSize = FloatProperty(name="Noise size", - default=0.25, - min=0.0001, soft_min=0.0001, - description="Noise size") - noiseScaleX = FloatProperty(name="Noise x", - default=0.5, - min=0.0001, soft_min=0.0001, - description="Noise x") - noiseScaleY = FloatProperty(name="Noise y", - default=0.5, - min=0.0001, soft_min=0.0001, - description="Noise y") - noiseScaleZ = FloatProperty(name="Noise z", - default=0.5, - min=0.0001, soft_min=0.0001, - description="Noise z") - noiseTaper = FloatProperty(name="Noise taper", - default=0.0, - min=0.0001, soft_min=0.0001, - max=1.0, soft_max=1.0, - description="Noise taper") - noiseOctaves = IntProperty(name="Octaves", - default=2, - min=1, soft_min=1, - max=16, soft_max=16, - description="Basis") - noiseBasis = IntProperty(name="Basis", - default=0, - min=0, soft_min=0, - max=9, soft_max=9, - description="Basis") - noiseSeed = IntProperty(name="Seed", - default=1, - min=0, soft_min=0, - description="Random Seed") + noiseType = IntProperty( + name="Type", + default=0, + min=0, + soft_min=0, + max=2, + soft_max=2, + description="Noise curve type: Linear, Circular or Knot" + ) + noisePoints = IntProperty( + name="Resolution", + default=100, + min=3, + soft_min=3, + description="Resolution" + ) + noiseLength = FloatProperty( + name="Length", + default=2.0, + min=0.01, + soft_min=0.01, + description="Curve Length" + ) + noiseSize = FloatProperty( + name="Noise size", + default=0.25, + min=0.0001, + soft_min=0.0001, + description="Noise size" + ) + noiseScaleX = FloatProperty( + name="Noise x", + default=0.5, + min=0.0001, + soft_min=0.0001, + description="Noise x" + ) + noiseScaleY = FloatProperty( + name="Noise y", + default=0.5, + min=0.0001, + soft_min=0.0001, + description="Noise y" + ) + noiseScaleZ = FloatProperty( + name="Noise z", + default=0.5, + min=0.0001, + soft_min=0.0001, + description="Noise z" + ) + noiseOctaves = IntProperty( + name="Octaves", + default=2, + min=1, + soft_min=1, + max=16, + soft_max=16, + description="Basis" + ) + noiseBasis = IntProperty( + name="Basis", + default=0, + min=0, + soft_min=0, + max=9, + soft_max=9, + description="Basis" + ) + noiseSeed = IntProperty( + name="Seed", + default=1, + min=0, + soft_min=0, + description="Random Seed" + ) ##### DRAW ##### @@ -1154,7 +1362,7 @@ class Curveaceous_galore(Operator): col.label(text=self.ProfileType + " Options:") # options per ProfileType - box = layout.box() + box = layout.box().column(align=True) if self.ProfileType == 'Profile': box.prop(self, 'ProfileCurveType') box.prop(self, 'ProfileCurvevar1') @@ -1169,7 +1377,7 @@ class Curveaceous_galore(Operator): box.prop(self, 'MiscCurveType') box.prop(self, 'MiscCurvevar1', text='Width') box.prop(self, 'MiscCurvevar2', text='Height') - if self.MiscCurveType == 2: + if self.MiscCurveType is 2: box.prop(self, 'MiscCurvevar3', text='Corners') elif self.ProfileType == 'Flower': @@ -1185,8 +1393,8 @@ class Curveaceous_galore(Operator): box.prop(self, 'outerRadius') elif self.ProfileType == 'Arc': - box.prop(self, 'arcSides') box.prop(self, 'arcType') + box.prop(self, 'arcSides') box.prop(self, 'startAngle') box.prop(self, 'endAngle') box.prop(self, 'innerRadius') @@ -1211,11 +1419,11 @@ class Curveaceous_galore(Operator): box.prop(self, 'basis') elif self.ProfileType == 'Cycloid': - box.prop(self, 'cycloPoints') box.prop(self, 'cycloType') + box.prop(self, 'cycloPoints') box.prop(self, 'cyclo_a') box.prop(self, 'cyclo_b') - if self.cycloType != 0: + if self.cycloType is not 0: box.prop(self, 'cyclo_d') elif self.ProfileType == 'Helix': @@ -1231,13 +1439,11 @@ class Curveaceous_galore(Operator): box.prop(self, 'noiseType') box.prop(self, 'noisePoints') box.prop(self, 'noiseLength') - if self.noiseType in [0,1]: + if self.noiseType in [0, 1]: box.prop(self, 'noiseSize') box.prop(self, 'noiseScaleX') box.prop(self, 'noiseScaleY') box.prop(self, 'noiseScaleZ') - if self.noiseType == 0: - box.prop(self, 'noiseTaper') box.prop(self, 'noiseOctaves') box.prop(self, 'noiseBasis') box.prop(self, 'noiseSeed') @@ -1272,12 +1478,12 @@ class Curveaceous_galore(Operator): if self.ProfileType in ['Helix','Noise', 'Cycloid']: self.use_cyclic_u = False if self.ProfileType in ['Cycloid']: - if self.cycloType == 0: + if self.cycloType is 0: self.use_cyclic_u = False else: self.use_cyclic_u = True else: - if self.ProfileType == 'Arc' and self.arcType == 1: + if self.ProfileType == 'Arc' and self.arcType is 1: self.use_cyclic_u = False else: self.use_cyclic_u = True diff --git a/add_curve_extra_objects/add_curve_spirofit_bouncespline.py b/add_curve_extra_objects/add_curve_spirofit_bouncespline.py index fcd9b6d8..7be535ab 100644 --- a/add_curve_extra_objects/add_curve_spirofit_bouncespline.py +++ b/add_curve_extra_objects/add_curve_spirofit_bouncespline.py @@ -19,7 +19,7 @@ bl_info = { "name": "SpiroFit and BounceSpline", - "author": "Jimmy Hazevoet, Antonio Osprite, Liero, Atom", + "author": "Antonio Osprite, Liero, Atom, Jimmy Hazevoet", "version": (0, 2, 0), "blender": (2, 78, 0), "location": "Toolshelf > Misc Tab", @@ -108,13 +108,14 @@ def distance(v1, v2): def spiral_point(step, radius, z_coord, spires, waves, wave_height, rndm): - x = radius * cos(spires*step) + (r.random()-0.5)*rndm - y = radius * sin(spires*step) + (r.random()-0.5)*rndm - z = z_coord + (cos(waves*step*pi)*wave_height) + (r.random()-0.5)*rndm + x = radius * cos(spires * step) + (r.random() - 0.5) * rndm + y = radius * sin(spires * step) + (r.random() - 0.5) * rndm + z = z_coord + (cos(waves * step * pi) * wave_height) + (r.random() - 0.5) * rndm return [x, y, z] -def do_object_mapping(obj, vert, center, offset): +# ray cast +def object_mapping_ray_cast(obj, vert, center, offset): intersections = [] ray = Vector(vert) orig = Vector(center) @@ -129,7 +130,13 @@ def do_object_mapping(obj, vert, center, offset): mapped = min([(distance(i, vert), i) for i in intersections])[1] else: mapped = orig + return [mapped[0], mapped[1], mapped[2]] + +# closest point +def object_mapping_closest_point(obj, vert, offset): + cpom = obj.closest_point_on_mesh(vert) + mapped = cpom[1] + cpom[2] * offset return [mapped[0], mapped[1], mapped[2]] @@ -139,7 +146,8 @@ def spirofit_spline(obj, waves=0, wave_height=0.0, rndm_spire=0.0, - offset=0.0): + offset=0.0, + map_method='RAYCAST'): points = [] bb = obj.bound_box @@ -157,16 +165,22 @@ def spirofit_spline(obj, center = [cx, cy, bb_zmin] cp = spiral_point(bb_zmin, radius, bb_zmin, spires, waves, wave_height, 0) - cp = do_object_mapping(obj, cp, center, offset) + if map_method == 'RAYCAST': + cp = object_mapping_ray_cast(obj, cp, center, offset) + elif map_method == 'CLOSESTPOINT': + cp = object_mapping_closest_point(obj, cp, offset) steps = spires * spire_resolution - for i in range(1, steps+1): - t = bb_zmin + (2*pi / steps) * i + for i in range(1, steps + 1): + t = bb_zmin + (2 * pi / steps) * i z = bb_zmin + (float(height) / steps) * i center = [cx, cy, z] cp = spiral_point(t, radius, z, spires, waves, wave_height, rndm_spire) - cp = do_object_mapping(obj, cp, center, offset) + if map_method == 'RAYCAST': + cp = object_mapping_ray_cast(obj, cp, center, offset) + elif map_method == 'CLOSESTPOINT': + cp = object_mapping_closest_point(obj, cp, offset) points.append(cp) return points @@ -175,83 +189,113 @@ def spirofit_spline(obj, # ------------------------------------------------------------ class SpiroFitSpline(bpy.types.Operator): - bl_idname = "wm.add_spirofit_spline" + bl_idname = "object.add_spirofit_spline" bl_label = "SpiroFit" - bl_description="Adds a spirofit to selected mesh" + bl_description="Wrap selected mesh in a spiral" bl_options = {'REGISTER', 'UNDO', 'PRESET'} - spire_resolution = bpy.props.IntProperty(name="Spire Resolution", - default=8, - min=3, max=256, - soft_max=128, - description="Spire resolution for one turn") - - spires = bpy.props.IntProperty(name="Spires", - default=4, - min=1, max=512, - soft_max=256, - description="Number of Spire turns") - - waves = bpy.props.IntProperty(name="Waves amount", - default=0, - min=0, - description="Waves amount") - - wave_height = bpy.props.FloatProperty(name="Wave intensity", - default=0.1, - min=0.0, - description="Wave intensity scale") - - rndm_spire = bpy.props.FloatProperty(name="Randomize", - default=0.0, - min=0.0, - description="Randomize spire") - - offset = bpy.props.FloatProperty(name="Offset", - default=0.0, - description="Use normal direction to offset spline") - - splineTypes = [ - ('POLY', 'Poly', 'POLY'), - ('BEZIER', 'Bezier', 'BEZIER')] - spline_type = bpy.props.EnumProperty(name="Spline type", - default='BEZIER', - description="Spline type", - items=splineTypes) - - spline_resolution = bpy.props.IntProperty(name="Resolution u", - default=12, - min=0, - max=64, - description="Curve resolution u") - - bevel = bpy.props.FloatProperty(name="Bevel radius", - default=0.0, - min=0.0, - precision=3, - description="Bevel depth") - - bevel_res = bpy.props.IntProperty(name="Bevel resolution", - default=0, - min=0, - max=32, - description="Bevel resolution") - - spline_random_radius = bpy.props.FloatProperty(name="Random bevel radius", - default=0.0, - min=0.0, - description="Random radius amount") - - random_seed = bpy.props.IntProperty(name="Random seed", - default=2, - min=0, - description="Random seed number") - - x_ray = bpy.props.BoolProperty(name="X-Ray", - default=True, - description = "Make the object draw in front of others") - - updateSpline = bpy.props.BoolProperty(name="Update", description="Update spline", default=False) + map_method = bpy.props.EnumProperty( + name="Mapping Method", + default='CLOSESTPOINT', + description="Mapping method", + items=[('RAYCAST', 'Ray cast', 'Ray cast'), + ('CLOSESTPOINT', 'Closest point', 'Closest point')] + ) + + spire_resolution = bpy.props.IntProperty( + name="Spire Resolution", + default=8, + min=3, + max=256, + soft_max=128, + description="Spire resolution for one turn" + ) + spires = bpy.props.IntProperty( + name="Spires", + default=4, + min=1, + max=512, + soft_max=256, + description="Number of spire turns" + ) + waves = bpy.props.IntProperty( + name="Waves", + default=0, + min=0, + description="Waves amount" + ) + wave_height = bpy.props.FloatProperty( + name="Wave intensity", + default=0.1, + min=0.0, + description="Wave intensity scale" + ) + rndm_spire = bpy.props.FloatProperty( + name="Randomize", + default=0.0, + min=0.0, + description="Randomize spire" + ) + offset = bpy.props.FloatProperty( + name="Offset", + default=0.0, + description="Use normal direction to offset spline" + ) + spline_type = bpy.props.EnumProperty( + name="Spline type", + default='BEZIER', + description="Spline type", + items=[('POLY', 'Poly', 'POLY'), + ('BEZIER', 'Bezier', 'BEZIER')] + ) + spline_resolution = bpy.props.IntProperty( + name="Resolution u", + default=12, + min=0, + max=64, + description="Curve resolution u" + ) + bevel = bpy.props.FloatProperty( + name="Bevel radius", + default=0.0, + min=0.0, + precision=3, + description="Bevel depth" + ) + bevel_res = bpy.props.IntProperty( + name="Bevel resolution", + default=0, + min=0, + max=32, + description="Bevel resolution" + ) + spline_random_radius = bpy.props.FloatProperty( + name="Random bevel radius", + default=0.0, + min=0.0, + description="Random radius amount" + ) + random_seed = bpy.props.IntProperty( + name="Random seed", + default=2, + min=0, + description="Random seed number" + ) + x_ray = bpy.props.BoolProperty( + name="X-Ray", + default=True, + description = "Make the object draw in front of others" + ) + refresh = bpy.props.BoolProperty( + name="Refresh", + description="Refresh spline", + default=False + ) + auto_refresh = bpy.props.BoolProperty( + name="Auto", + description="Auto refresh spline", + default=True + ) @classmethod @@ -263,12 +307,12 @@ class SpiroFitSpline(bpy.types.Operator): def invoke(self, context, event): - self.updateSpline = True + self.refresh = True return self.execute(context) def execute(self, context): - if not self.updateSpline: + if not self.refresh: return {'PASS_THROUGH'} undo = context.user_preferences.edit.use_global_undo @@ -289,7 +333,9 @@ class SpiroFitSpline(bpy.types.Operator): self.waves, self.wave_height, self.rndm_spire, - self.offset) + self.offset, + self.map_method + ) add_curve_object(points, matrix, @@ -298,7 +344,11 @@ class SpiroFitSpline(bpy.types.Operator): self.spline_resolution, self.bevel, self.bevel_res, - self.spline_random_radius) + self.spline_random_radius + ) + + if self.auto_refresh is False: + self.refresh = False context.user_preferences.edit.use_global_undo = undo return {'FINISHED'} @@ -308,39 +358,30 @@ class SpiroFitSpline(bpy.types.Operator): layout = self.layout col = layout.column(align=True) row = col.row(align=True) - row.prop(self, 'x_ray', toggle=True) row.separator() - row.prop(self, 'updateSpline', toggle=True) #, icon='FILE_REFRESH') + if self.auto_refresh is False: + self.refresh = False + elif self.auto_refresh is True: + self.refresh = True + row.prop(self, 'auto_refresh', toggle=True, icon='AUTO', text="") + row.prop(self, 'refresh', toggle=True, icon='FILE_REFRESH', text="") row.separator() - properties = row.operator('wm.add_spirofit_spline', text="Add New") + properties = row.operator('object.add_spirofit_spline', text="Add New") col.separator() - - properties.x_ray = self.x_ray - properties.spire_resolution = self.spire_resolution - properties.spires = self.spires - properties.waves = self.waves - properties.wave_height = self.wave_height - properties.offset = self.offset - properties.rndm_spire = self.rndm_spire - properties.random_seed = self.random_seed - properties.spline_type = self.spline_type - properties.spline_resolution = self.spline_resolution - properties.bevel = self.bevel - properties.bevel_res = self.bevel_res - properties.spline_random_radius = self.spline_random_radius - + col = layout.column(align=False) + col.prop(self, 'map_method') col = layout.column(align=True) col.prop(self, 'spire_resolution') col.prop(self, 'spires') + col.prop(self, 'offset') col.prop(self, 'waves') col.prop(self, 'wave_height') - col.prop(self, 'offset') col.prop(self, 'rndm_spire') col.prop(self, 'random_seed') col.separator() col = layout.column(align=True) - col.prop(self, 'spline_type', text="") + col.prop(self, 'spline_type') col.separator() col.prop(self, 'spline_resolution') col.prop(self, 'bevel') @@ -354,7 +395,6 @@ class SpiroFitSpline(bpy.types.Operator): # Original script by Liero and Atom # https://blenderartists.org/forum/showthread.php?331750-Fiber-Mesh-Emulation # ------------------------------------------------------------ - def noise(var=1): rand = Vector((r.gauss(0,1), r.gauss(0,1), r.gauss(0,1))) vec = rand.normalized() * var @@ -400,81 +440,104 @@ def bounce_spline(obj, return points return points + # ------------------------------------------------------------ class BounceSpline(bpy.types.Operator): - bl_idname = "wm.add_bounce_spline" + bl_idname = "object.add_bounce_spline" bl_label = "BounceSpline" - bl_description="Adds a bounce spline to selected mesh" + bl_description="Fill selected mesh with a bounce spline" bl_options = {'REGISTER', 'UNDO', 'PRESET'} - random_seed = bpy.props.IntProperty(name="Random seed", - default=1, - min=0, - description="Random seed number") - - bounce_number = bpy.props.IntProperty(name="Bounces", - default=500, - min=1, max=99999, - soft_max=9999, - description="Number of Bounces") - - ang_noise = bpy.props.FloatProperty(name="Angular noise", - default=0.25, - min=0.0, - description="Add some noise to ray direction") - - offset = bpy.props.FloatProperty(name="Offset", - default=0.0, - description="Use normal direction to offset spline") - - extra = bpy.props.IntProperty(name="Extra", - default=50, - min=0, max=1000, - soft_min=0, soft_max=500, - description="Number of extra tries if it fails to hit mesh") - - active_face = bpy.props.BoolProperty(name="Active face", - default=False, - description = "Starts from active face or a random one") - - splineTypes = [ - ('POLY', 'Poly', 'POLY'), - ('BEZIER', 'Bezier', 'BEZIER')] - spline_type = bpy.props.EnumProperty(name="Spline type", - default='BEZIER', - description="Spline type", - items=splineTypes) - - spline_resolution = bpy.props.IntProperty(name="Resolution u", - default=12, - min=0, - max=64, - description="Curve resolution u") - - bevel = bpy.props.FloatProperty(name="Bevel radius", - default=0.0, - min=0.0, - precision=3, - description="Bevel depth") - - bevel_res = bpy.props.IntProperty(name="Bevel resolution", - default=0, - min=0, - max=32, - description="Bevel resolution") - - spline_random_radius = bpy.props.FloatProperty(name="Random bevel radius", - default=0.0, - min=0.0, - description="Random radius amount") - - x_ray = bpy.props.BoolProperty(name="X-Ray", - default=True, - description = "Make the object draw in front of others") - - updateSpline = bpy.props.BoolProperty(name="Update", default=False) - + random_seed = bpy.props.IntProperty( + name="Random seed", + default=1, + min=0, + description="Random seed number" + ) + bounce_number = bpy.props.IntProperty( + name="Bounces", + default=500, + min=1, + max=99999, + soft_max=9999, + description="Number of Bounces" + ) + ang_noise = bpy.props.FloatProperty( + name="Angular noise", + default=0.25, + min=0.0, + description="Add some noise to ray direction" + ) + offset = bpy.props.FloatProperty( + name="Offset", + default=0.0, + description="Use normal direction to offset spline" + ) + extra = bpy.props.IntProperty( + name="Extra", + default=50, + min=0, + max=1000, + soft_min=0, + soft_max=500, + description="Number of extra tries if it fails to hit mesh" + ) + active_face = bpy.props.BoolProperty( + name="Active face", + default=False, + description = "Starts from active face or a random one" + ) + spline_type = bpy.props.EnumProperty( + name="Spline type", + default='BEZIER', + description="Spline type", + items=[('POLY', 'Poly', 'POLY'), + ('BEZIER', 'Bezier', 'BEZIER')] + ) + spline_resolution = bpy.props.IntProperty( + name="Resolution u", + default=12, + min=0, + max=64, + description="Curve resolution u" + ) + bevel = bpy.props.FloatProperty( + name="Bevel radius", + default=0.0, + min=0.0, + precision=3, + description="Bevel depth" + ) + + bevel_res = bpy.props.IntProperty( + name="Bevel resolution", + default=0, + min=0, + max=32, + description="Bevel resolution" + ) + spline_random_radius = bpy.props.FloatProperty( + name="Random bevel radius", + default=0.0, + min=0.0, + description="Random radius amount" + ) + x_ray = bpy.props.BoolProperty( + name="X-Ray", + default=True, + description = "Make the object draw in front of others" + ) + refresh = bpy.props.BoolProperty( + name="Refresh", + description="Refresh spline", + default=False + ) + auto_refresh = bpy.props.BoolProperty( + name="Auto", + description="Auto refresh spline", + default=True + ) @classmethod def poll(self, context): @@ -485,12 +548,12 @@ class BounceSpline(bpy.types.Operator): def invoke(self, context, event): - self.updateSpline = True + self.refresh = True return self.execute(context) def execute(self, context): - if not self.updateSpline: + if not self.refresh: return {'PASS_THROUGH'} undo = context.user_preferences.edit.use_global_undo @@ -520,6 +583,9 @@ class BounceSpline(bpy.types.Operator): self.bevel_res, self.spline_random_radius) + if self.auto_refresh is False: + self.refresh = False + context.user_preferences.edit.use_global_undo = undo return {'FINISHED'} @@ -531,24 +597,15 @@ class BounceSpline(bpy.types.Operator): row.prop(self, 'x_ray', toggle=True) row.separator() - row.prop(self, 'updateSpline', toggle=True) #, icon='FILE_REFRESH') + if self.auto_refresh is False: + self.refresh = False + elif self.auto_refresh is True: + self.refresh = True + row.prop(self, 'auto_refresh', toggle=True, icon='AUTO', text="") + row.prop(self, 'refresh', toggle=True, icon='FILE_REFRESH', text="") row.separator() - properties = row.operator('wm.add_bounce_spline', text="Add New") + properties = row.operator('object.add_bounce_spline', text="Add New") col.separator() - - properties.x_ray = self.x_ray - properties.bounce_number = self.bounce_number - properties.ang_noise = self.ang_noise - properties.offset = self.offset - properties.extra = self.extra - properties.random_seed = self.random_seed - properties.active_face = self.active_face - properties.spline_type = self.spline_type - properties.spline_resolution = self.spline_resolution - properties.bevel = self.bevel - properties.bevel_res = self.bevel_res - properties.spline_random_radius = self.spline_random_radius - col = layout.column(align=True) row = col.row(align=True) col.prop(self, 'bounce_number') @@ -559,7 +616,7 @@ class BounceSpline(bpy.types.Operator): col.separator() col.prop(self, 'active_face', toggle=False) col = layout.column(align=True) - col.prop(self, 'spline_type', text="") + col.prop(self, 'spline_type') col.separator() col.prop(self, 'spline_resolution') col.prop(self, 'bevel') -- cgit v1.2.3