Skip to content
Snippets Groups Projects
add_curve_aceous_galore.py 43.9 KiB
Newer Older
  • Learn to ignore specific revisions
  • # SPDX-License-Identifier: GPL-2.0-or-later
    
    Brendon Murphy's avatar
    fix
    Brendon Murphy committed
    bl_info = {
        "name": "Curveaceous Galore!",
        "author": "Jimmy Hazevoet, testscreenings",
    
        "blender": (2, 80),
    
    Brendon Murphy's avatar
    fix
    Brendon Murphy committed
        "location": "View3D > Add > Curve",
        "description": "Adds many different types of Curves",
    
        "doc_url": "{BLENDER_MANUAL_URL}/addons/add_curve/extra_objects.html",
    
    Brendon Murphy's avatar
    fix
    Brendon Murphy committed
        "category": "Add Curve",
    }
    
    Brendon Murphy's avatar
    fix
    Brendon Murphy committed
    import bpy
    
    from bpy_extras import object_utils
    
    from bpy.props import (
            BoolProperty,
            EnumProperty,
            FloatProperty,
            IntProperty,
    
    from mathutils import Matrix, Vector
    
    Brendon Murphy's avatar
    fix
    Brendon Murphy committed
    import mathutils.noise as Noise
    
    # ------------------------------------------------------------
    # Some functions to use with others:
    # ------------------------------------------------------------
    
    Brendon Murphy's avatar
    fix
    Brendon Murphy committed
    
    
    # ------------------------------------------------------------
    
    Brendon Murphy's avatar
    fix
    Brendon Murphy committed
    # Generate random number:
    def randnum(low=0.0, high=1.0, seed=0):
        """
        randnum( low=0.0, high=1.0, seed=0 )
    
        Create random number
    
        Parameters:
            low - lower range
                (type=float)
            high - higher range
                (type=float)
    
            seed - the random seed number, if seed == 0, the current time will be used instead
    
                (type=int)
        Returns:
            a random number
                (type=float)
    
    Brendon Murphy's avatar
    fix
    Brendon Murphy committed
        """
    
        Noise.seed_set(seed)
        rnum = Noise.random()
    
        rnum = rnum * (high - low)
        rnum = rnum + low
    
    Brendon Murphy's avatar
    fix
    Brendon Murphy committed
        return rnum
    
    
    
    # ------------------------------------------------------------
    
    Brendon Murphy's avatar
    fix
    Brendon Murphy committed
    # Make some noise:
    
    def vTurbNoise(x, y, z, iScale=0.25, Size=1.0, Depth=6, Hard=False, Basis=0, Seed=0):
    
    Brendon Murphy's avatar
    fix
    Brendon Murphy committed
        """
        vTurbNoise((x,y,z), iScale=0.25, Size=1.0, Depth=6, Hard=0, Basis=0, Seed=0 )
    
        Create randomised vTurbulence noise
    
    
        Parameters:
            xyz - (x,y,z) float values.
                (type=3-float tuple)
            iScale - noise intensity scale
                (type=float)
            Size - noise size
                (type=float)
            Depth - number of noise values added.
                (type=int)
    
            Hard - noise hardness: True - soft noise; False - hard noise
    
                (type=int)
            basis - type of noise used for turbulence
                (type=int)
    
            Seed - the random seed number, if seed == 0, the current time will be used instead
    
                (type=int)
        Returns:
            the generated turbulence vector.
                (type=3-float list)
    
    Brendon Murphy's avatar
    fix
    Brendon Murphy committed
        """
    
        rand = randnum(-100, 100, Seed)
    
        vec = Vector((x / Size + rand, y / Size + rand, z / Size + rand))
        vTurb = Noise.turbulence_vector(vec, Depth, Hard)
        #mathutils.noise.turbulence_vector(position, octaves, hard, noise_basis='PERLIN_ORIGINAL', amplitude_scale=0.5, frequency_scale=2.0)
    
        tx = vTurb[0] * iScale
        ty = vTurb[1] * iScale
        tz = vTurb[2] * iScale
    
    Brendon Murphy's avatar
    fix
    Brendon Murphy committed
    
    
    # -------------------------------------------------------------------
    # 2D Curve shape functions:
    # -------------------------------------------------------------------
    
    Brendon Murphy's avatar
    fix
    Brendon Murphy committed
    
    
    # ------------------------------------------------------------
    
    Brendon Murphy's avatar
    fix
    Brendon Murphy committed
    # 2DCurve: Profile:  L, H, T, U, Z
    def ProfileCurve(type=0, a=0.25, b=0.25):
        """
        ProfileCurve( type=0, a=0.25, b=0.25 )
    
        Create profile curve
    
    
        Parameters:
            type - select profile type, L, H, T, U, Z
                (type=int)
            a - a scaling parameter
                (type=float)
            b - b scaling parameter
                (type=float)
        Returns:
            a list with lists of x,y,z coordinates for curve points, [[x,y,z],[x,y,z],...n]
            (type=list)
    
    Brendon Murphy's avatar
    fix
    Brendon Murphy committed
        """
    
        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]
                    ]
    
                    [-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]
                    ]
    
                    [-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]
                    ]
    
                    [-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]
                    ]
    
    Brendon Murphy's avatar
    fix
    Brendon Murphy committed
        else:
    
                    [-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]
                    ]
    
    Brendon Murphy's avatar
    fix
    Brendon Murphy committed
        return newpoints
    
    
    # ------------------------------------------------------------
    
    def ArrowCurve(type=1, a=1.0, b=0.5):
    
    Brendon Murphy's avatar
    fix
    Brendon Murphy committed
        """
    
        ArrowCurve( type=1, a=1.0, b=0.5, c=1.0 )
    
    Brendon Murphy's avatar
    fix
    Brendon Murphy committed
    
    
    Brendon Murphy's avatar
    fix
    Brendon Murphy committed
    
    
        Parameters:
            type - select type, Arrow1, Arrow2
                (type=int)
            a - a scaling parameter
                (type=float)
            b - b scaling parameter
                (type=float)
        Returns:
            a list with lists of x,y,z coordinates for curve points, [[x,y,z],[x,y,z],...n]
            (type=list)
    
    Brendon Murphy's avatar
    fix
    Brendon Murphy committed
        """
    
        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]
                    ]
    
            # Arrow2:
            newpoints = [[-a, b, 0.0], [a, 0.0, 0.0], [-a, -b, 0.0], [0.0, 0.0, 0.0]]
        else:
            # diamond:
            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):
        """
        RectCurve( type=1, a=1.0, b=0.5, c=1.0 )
    
    
        Parameters:
            type - select type, Square, Rounded square 1, Rounded square 2
                (type=int)
            a - a scaling parameter
                (type=float)
            b - b scaling parameter
                (type=float)
            c - c scaling parameter
                (type=float)
        Returns:
            a list with lists of x,y,z coordinates for curve points, [[x,y,z],[x,y,z],...n]
            (type=list)
    
            # Rounded Rectangle:
    
                    [-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]
                    ]
    
            # Rounded Rectangle II:
    
    Brendon Murphy's avatar
    fix
    Brendon Murphy committed
            newpoints = []
    
    Brendon Murphy's avatar
    fix
    Brendon Murphy committed
            if r > x:
                r = x - 0.0001
            if r > y:
                r = y - 0.0001
    
                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])
    
    Brendon Murphy's avatar
    fix
    Brendon Murphy committed
            else:
    
                newpoints.append([-x, y, 0])
                newpoints.append([x, y, 0])
                newpoints.append([x, -y, 0])
                newpoints.append([-x, -y, 0])
    
    Brendon Murphy's avatar
    fix
    Brendon Murphy committed
        else:
    
            newpoints = [[-a, b, 0.0], [a, b, 0.0], [a, -b, 0.0], [-a, -b, 0.0]]
    
    Brendon Murphy's avatar
    fix
    Brendon Murphy committed
        return newpoints
    
    
    # ------------------------------------------------------------
    
    Brendon Murphy's avatar
    fix
    Brendon Murphy committed
    # 2DCurve: Star:
    def StarCurve(starpoints=8, innerradius=0.5, outerradius=1.0, twist=0.0):
        """
        StarCurve( starpoints=8, innerradius=0.5, outerradius=1.0, twist=0.0 )
    
        Create star shaped curve
    
    
        Parameters:
            starpoints - the number of points
                (type=int)
            innerradius - innerradius
                (type=float)
            outerradius - outerradius
                (type=float)
            twist - twist amount
                (type=float)
        Returns:
            a list with lists of x,y,z coordinates for curve points, [[x,y,z],[x,y,z],...n]
            (type=list)
    
    Brendon Murphy's avatar
    fix
    Brendon Murphy committed
        """
    
        newpoints = []
    
    Brendon Murphy's avatar
    fix
    Brendon Murphy committed
        i = 0
        while i < starpoints:
    
            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
    
            newpoints.append([x2, y2, 0])
            i += 1
    
    Brendon Murphy's avatar
    fix
    Brendon Murphy committed
        return newpoints
    
    
    # ------------------------------------------------------------
    
    Brendon Murphy's avatar
    fix
    Brendon Murphy committed
    # 2DCurve: Flower:
    def FlowerCurve(petals=8, innerradius=0.5, outerradius=1.0, petalwidth=2.0):
        """
        FlowerCurve( petals=8, innerradius=0.5, outerradius=1.0, petalwidth=2.0 )
    
        Create flower shaped curve
    
    
        Parameters:
            petals - the number of petals
                (type=int)
            innerradius - innerradius
                (type=float)
            outerradius - outerradius
                (type=float)
            petalwidth - width of petals
                (type=float)
        Returns:
            a list with lists of x,y,z coordinates for curve points, [[x,y,z],[x,y,z],...n]
            (type=list)
    
    Brendon Murphy's avatar
    fix
    Brendon Murphy committed
        """
    
        newpoints = []
    
        step = 2.0 / petals
        pet = (step / pi * 2) * petalwidth
    
    Brendon Murphy's avatar
    fix
    Brendon Murphy committed
        i = 0
        while i < petals:
    
            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
    
            newpoints.append([x2, y2, 0])
    
            x3 = cos(t * pi + pet) * outerradius
            y3 = sin(t * pi + pet) * outerradius
    
            newpoints.append([x3, y3, 0])
            i += 1
    
    Brendon Murphy's avatar
    fix
    Brendon Murphy committed
        return newpoints
    
    
    # ------------------------------------------------------------
    
    Brendon Murphy's avatar
    fix
    Brendon Murphy committed
    # 2DCurve: Arc,Sector,Segment,Ring:
    def ArcCurve(sides=6, startangle=0.0, endangle=90.0, innerradius=0.5, outerradius=1.0, type=3):
        """
        ArcCurve( sides=6, startangle=0.0, endangle=90.0, innerradius=0.5, outerradius=1.0, type=3 )
    
        Create arc shaped curve
    
    
        Parameters:
            sides - number of sides
                (type=int)
            startangle - startangle
                (type=float)
            endangle - endangle
                (type=float)
            innerradius - innerradius
                (type=float)
            outerradius - outerradius
                (type=float)
            type - select type Arc,Sector,Segment,Ring
                (type=int)
        Returns:
            a list with lists of x,y,z coordinates for curve points, [[x,y,z],[x,y,z],...n]
            (type=list)
    
    Brendon Murphy's avatar
    fix
    Brendon Murphy committed
        """
    
        newpoints = []
        sides += 1
    
        endangle -= startangle
    
        step = (angle * endangle) / (sides - 1)
    
    Brendon Murphy's avatar
    fix
    Brendon Murphy committed
        i = 0
        while i < sides:
    
            t = (i * step) + angle * startangle
            x1 = sin(t * pi) * outerradius
            y1 = cos(t * pi) * outerradius
    
            newpoints.append([x1, y1, 0])
            i += 1
    
    Brendon Murphy's avatar
    fix
    Brendon Murphy committed
    
    
    Brendon Murphy's avatar
    fix
    Brendon Murphy committed
            # Arc: turn cyclic curve flag off!
    
        # Segment:
    
            newpoints.append([0, 0, 0])
    
    Brendon Murphy's avatar
    fix
    Brendon Murphy committed
        # Ring:
    
    Brendon Murphy's avatar
    fix
    Brendon Murphy committed
            while j > -1:
    
                t = (j * step) + angle * startangle
                x2 = sin(t * pi) * innerradius
                y2 = cos(t * pi) * innerradius
    
                newpoints.append([x2, y2, 0])
                j -= 1
    
    Brendon Murphy's avatar
    fix
    Brendon Murphy committed
        return newpoints
    
    
    # ------------------------------------------------------------
    
    Brendon Murphy's avatar
    fix
    Brendon Murphy committed
    # 2DCurve: Cog wheel:
    def CogCurve(theeth=8, innerradius=0.8, middleradius=0.95, outerradius=1.0, bevel=0.5):
        """
        CogCurve( theeth=8, innerradius=0.8, middleradius=0.95, outerradius=1.0, bevel=0.5 )
    
        Create cog wheel shaped curve
    
    
        Parameters:
            theeth - number of theeth
                (type=int)
            innerradius - innerradius
                (type=float)
            middleradius - middleradius
                (type=float)
            outerradius - outerradius
                (type=float)
            bevel - bevel amount
                (type=float)
        Returns:
            a list with lists of x,y,z coordinates for curve points, [[x,y,z],[x,y,z],...n]
            (type=list)
    
    Brendon Murphy's avatar
    fix
    Brendon Murphy committed
        """
    
        newpoints = []
    
        step = 2.0 / theeth
        pet = step / pi * 2
        bevel = 1.0 - bevel
    
    Brendon Murphy's avatar
    fix
    Brendon Murphy committed
        i = 0
        while i < theeth:
    
            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
    
            newpoints.append([x2, y2, 0])
    
            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
    
            newpoints.append([x4, y4, 0])
    
            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
    
            newpoints.append([x6, y6, 0])
            i += 1
    
    Brendon Murphy's avatar
    fix
    Brendon Murphy committed
        return newpoints
    
    
    # ------------------------------------------------------------
    
    Brendon Murphy's avatar
    fix
    Brendon Murphy committed
    # 2DCurve: nSide:
    def nSideCurve(sides=6, radius=1.0):
        """
        nSideCurve( sides=6, radius=1.0 )
    
        Create n-sided curve
    
            Parameters:
                sides - number of sides
                    (type=int)
                radius - radius
                    (type=float)
            Returns:
                a list with lists of x,y,z coordinates for curve points, [[x,y,z],[x,y,z],...n]
                (type=list)
        """
    
        newpoints = []
    
    Brendon Murphy's avatar
    fix
    Brendon Murphy committed
        i = 0
        while i < sides:
    
            t = i * step
            x = sin(t * pi) * radius
            y = cos(t * pi) * radius
    
            newpoints.append([x, y, 0])
            i += 1
    
    Brendon Murphy's avatar
    fix
    Brendon Murphy committed
        return newpoints
    
    
    
    # ------------------------------------------------------------
    
    Brendon Murphy's avatar
    fix
    Brendon Murphy committed
    # 2DCurve: Splat:
    def SplatCurve(sides=24, scale=1.0, seed=0, basis=0, radius=1.0):
        """
        SplatCurve( sides=24, scale=1.0, seed=0, basis=0, radius=1.0 )
    
        Create splat curve
    
    
        Parameters:
            sides - number of sides
                (type=int)
            scale - noise size
                (type=float)
            seed - noise random seed
                (type=int)
            basis - noise basis
                (type=int)
            radius - radius
                (type=float)
        Returns:
            a list with lists of x,y,z coordinates for curve points, [[x,y,z],[x,y,z],...n]
            (type=list)
    
    Brendon Murphy's avatar
    fix
    Brendon Murphy committed
        """
    
        newpoints = []
    
    Brendon Murphy's avatar
    fix
    Brendon Murphy committed
        i = 0
        while i < sides:
    
            turb = vTurbNoise(t, t, t, 1.0, scale, 6, False, basis, seed)
    
    Brendon Murphy's avatar
    fix
    Brendon Murphy committed
            turb = turb[2] * 0.5 + 0.5
    
            x = sin(t * pi) * radius * turb
            y = cos(t * pi) * radius * turb
    
            newpoints.append([x, y, 0])
            i += 1
    
    Brendon Murphy's avatar
    fix
    Brendon Murphy committed
        return newpoints
    
    
    # -----------------------------------------------------------
    
    # Cycloid curve
    def CycloidCurve(number=100, type=0, R=4.0, r=1.0, d=1.0):
    
    Brendon Murphy's avatar
    fix
    Brendon Murphy committed
        """
    
        CycloidCurve( number=100, type=0, a=4.0, b=1.0 )
    
    Brendon Murphy's avatar
    fix
    Brendon Murphy committed
    
    
        Create a Cycloid, Hypotrochoid / Hypocycloid or Epitrochoid / Epycycloid type of curve
    
    Brendon Murphy's avatar
    fix
    Brendon Murphy committed
    
    
        Parameters:
            number - the number of points
                (type=int)
            type - types: Cycloid, Hypocycloid, Epicycloid
                (type=int)
            R = Radius a scaling parameter
                (type=float)
            r = Radius b scaling parameter
                (type=float)
            d = Distance scaling parameter
                (type=float)
        Returns:
            a list with lists of x,y,z coordinates for curve points, [[x,y,z],[x,y,z],...n]
            (type=list)
    
    Brendon Murphy's avatar
    fix
    Brendon Murphy committed
        """
    
    
    Brendon Murphy's avatar
    fix
    Brendon Murphy committed
        newpoints = []
    
    Brendon Murphy's avatar
    fix
    Brendon Murphy committed
        i = 0
    
            # Hypotrochoid / Hypocycloid
    
    Brendon Murphy's avatar
    fix
    Brendon Murphy committed
            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))
    
            # 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))
    
        else:
            # Cycloid
            while i < number:
    
                t = (i * step * pi)
                x = (t - sin(t) * b) * a / pi
                y = (1 - cos(t) * b) * a / pi
    
    # -----------------------------------------------------------
    # 3D curve shape functions:
    # -----------------------------------------------------------
    
    # ------------------------------------------------------------
    # 3DCurve: Helix:
    def HelixCurve(number=100, height=2.0, startangle=0.0, endangle=360.0, width=1.0, a=0.0, b=0.0):
        """
        HelixCurve( number=100, height=2.0, startangle=0.0, endangle=360.0, width=1.0, a=0.0, b=0.0 )
    
        Create helix curve
    
    
        Parameters:
            number - the number of points
                (type=int)
            height - height
                (type=float)
            startangle - startangle
                (type=float)
            endangle - endangle
                (type=float)
            width - width
                (type=float)
            a - a
                (type=float)
            b - b
                (type=float)
        Returns:
            a list with lists of x,y,z coordinates for curve points, [[x,y,z],[x,y,z],...n]
            (type=list)
    
        angle = (2.0 / 360.0) * (endangle - startangle)
    
        step = angle / (number - 1)
        h = height / angle
        start = startangle * 2.0 / 360.0
    
            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
    
    
    # -----------------------------------------------------------
    
    # 3D Noise curve
    
    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):
    
        Parameters:
            number - number of points
                (type=int)
            length - curve length
                (type=float)
            size - noise size
                (type=float)
            scale - noise intensity scale x,y,z
    
            basis - noise basis
                (type=int)
            seed - noise random seed
                (type=int)
            type - noise curve type
                (type=int)
        Returns:
            a list with lists of x,y,z coordinates for curve points, [[x,y,z],[x,y,z],...n]
            (type=list)
    
    jimmyhaze's avatar
    jimmyhaze committed
            # noise circle
    
            while i < number:
    
                v = vTurbNoise(t, t, t, 1.0, size, octaves, False, basis, seed)
    
    jimmyhaze's avatar
    jimmyhaze committed
                x = sin(t * pi) + (v[0] * scale[0])
    
                y = cos(t * pi) + (v[1] * scale[1])
    
                v = vTurbNoise(t, t, t, 1.0, 1.0, octaves, False, basis, seed)
    
    jimmyhaze's avatar
    jimmyhaze committed
                x = v[0] * scale[0] * size
                y = v[1] * scale[1] * size
                z = v[2] * scale[2] * size
                newpoints.append([x, y, z])
    
    Brendon Murphy's avatar
    fix
    Brendon Murphy committed
        else:
    
            # noise linear
            while i < number:
    
                v = vTurbNoise(t, t, t, 1.0, size, octaves, False, basis, seed)
    
    jimmyhaze's avatar
    jimmyhaze committed
                x = t + v[0] * scale[0]
                y = v[1] * scale[1]
                z = v[2] * scale[2]
    
    Brendon Murphy's avatar
    fix
    Brendon Murphy committed
        return newpoints
    
    # get array of vertcoordinates according to splinetype
    
    Brendon Murphy's avatar
    fix
    Brendon Murphy committed
    def vertsToPoints(Verts, splineType):
    
    Brendon Murphy's avatar
    fix
    Brendon Murphy committed
        # main vars
        vertArray = []
    
        # array for BEZIER spline output (V3)
        if splineType == 'BEZIER':
            for v in Verts:
                vertArray += v
    
        # array for nonBEZIER output (V4)
        else:
            for v in Verts:
                vertArray += v
                if splineType == 'NURBS':
    
    Brendon Murphy's avatar
    fix
    Brendon Murphy committed
                    vertArray.append(0)
        return vertArray
    
    
    Brendon Murphy's avatar
    fix
    Brendon Murphy committed
    # create new CurveObject from vertarray and splineType
    
    def createCurve(context, vertArray, self):
    
        # output splineType 'POLY' 'NURBS' 'BEZIER'
    
        splineType = self.outputType
    
        # GalloreType as name
        name = self.ProfileType
    
        # create object
        if bpy.context.mode == 'EDIT_CURVE':
            Curve = context.active_object
            newSpline = Curve.data.splines.new(type=splineType)          # spline
        else:
            # create curve
    
            dataCurve = bpy.data.curves.new(name, type='CURVE')  # curve data block
            newSpline = dataCurve.splines.new(type=splineType)          # spline
    
            Curve = object_utils.object_data_add(context, dataCurve, operator=self)  # place in active scene
    
        # set newSpline Options
        newSpline.use_cyclic_u = self.use_cyclic_u
        newSpline.use_endpoint_u = self.endp_u
        newSpline.order_u = self.order_u
    
        # set curve Options
        Curve.data.dimensions = self.shape
        Curve.data.use_path = True
        if self.shape == '3D':
            Curve.data.fill_mode = 'FULL'
        else:
            Curve.data.fill_mode = 'BOTH'
    
        for spline in Curve.data.splines:
            if spline.type == 'BEZIER':
                for point in spline.bezier_points:
                    point.select_control_point = False
                    point.select_left_handle = False
                    point.select_right_handle = False
            else:
                for point in spline.points:
                    point.select = False
    
    Brendon Murphy's avatar
    fix
    Brendon Murphy committed
        # create spline from vertarray
        if splineType == 'BEZIER':
    
            newSpline.bezier_points.add(int(len(vertArray) * 0.33))
    
    Brendon Murphy's avatar
    fix
    Brendon Murphy committed
            newSpline.bezier_points.foreach_set('co', vertArray)
    
            for point in newSpline.bezier_points:
                point.handle_right_type = self.handleType
                point.handle_left_type = self.handleType
    
                point.select_control_point = True
                point.select_left_handle = True
                point.select_right_handle = True
    
    Brendon Murphy's avatar
    fix
    Brendon Murphy committed
        else:
    
            newSpline.points.add(int(len(vertArray) * 0.25 - 1))
    
    Brendon Murphy's avatar
    fix
    Brendon Murphy committed
            newSpline.points.foreach_set('co', vertArray)
            newSpline.use_endpoint_u = True
    
            for point in newSpline.points:
                point.select = True
    
        # move and rotate spline in edit mode
        if bpy.context.mode == 'EDIT_CURVE':
    
            if self.align == "WORLD":
                location = self.location - context.active_object.location
                bpy.ops.transform.translate(value = location, orient_type='GLOBAL')
                bpy.ops.transform.rotate(value = self.rotation[0], orient_axis = 'X', orient_type='GLOBAL')
                bpy.ops.transform.rotate(value = self.rotation[1], orient_axis = 'Y', orient_type='GLOBAL')
                bpy.ops.transform.rotate(value = self.rotation[2], orient_axis = 'Z', orient_type='GLOBAL')
    
            elif self.align == "VIEW":
                bpy.ops.transform.translate(value = self.location)
                bpy.ops.transform.rotate(value = self.rotation[0], orient_axis = 'X')
                bpy.ops.transform.rotate(value = self.rotation[1], orient_axis = 'Y')
                bpy.ops.transform.rotate(value = self.rotation[2], orient_axis = 'Z')
    
            elif self.align == "CURSOR":
                location = context.active_object.location
                self.location = bpy.context.scene.cursor.location - location
                self.rotation = bpy.context.scene.cursor.rotation_euler
    
                bpy.ops.transform.translate(value = self.location)
                bpy.ops.transform.rotate(value = self.rotation[0], orient_axis = 'X')
                bpy.ops.transform.rotate(value = self.rotation[1], orient_axis = 'Y')
                bpy.ops.transform.rotate(value = self.rotation[2], orient_axis = 'Z')
    
    Brendon Murphy's avatar
    fix
    Brendon Murphy committed
    
        return
    
    
    # ------------------------------------------------------------
    
    Brendon Murphy's avatar
    fix
    Brendon Murphy committed
    # Main Function
    
    Brendon Murphy's avatar
    fix
    Brendon Murphy committed
        # options
    
        proType = self.ProfileType
    
    Brendon Murphy's avatar
    fix
    Brendon Murphy committed
        splineType = self.outputType
        innerRadius = self.innerRadius
        middleRadius = self.middleRadius
        outerRadius = self.outerRadius
    
        # get verts
    
            verts = ProfileCurve(
                    self.ProfileCurveType,
                    self.ProfileCurvevar1,
                    self.ProfileCurvevar2
                    )
    
        if proType == 'Arrow':
    
            verts = ArrowCurve(
                    self.MiscCurveType,
                    self.MiscCurvevar1,
                    self.MiscCurvevar2
                    )
    
        if proType == 'Rectangle':
    
            verts = RectCurve(
                    self.MiscCurveType,
                    self.MiscCurvevar1,
                    self.MiscCurvevar2,
                    self.MiscCurvevar3
                    )
    
            verts = FlowerCurve(
                    self.petals,
                    innerRadius,
                    outerRadius,
                    self.petalWidth
                    )
    
            verts = StarCurve(
                    self.starPoints,
                    innerRadius,
                    outerRadius,
                    self.starTwist
                    )
    
            verts = ArcCurve(
                    self.arcSides,
                    self.startAngle,
                    self.endAngle,
                    innerRadius,
                    outerRadius,
                    self.arcType
                    )
    
            verts = CogCurve(
                    self.teeth,
                    innerRadius,
                    middleRadius,
                    outerRadius,
                    self.bevel
                    )
    
            verts = SplatCurve(
                    self.splatSides,
                    self.splatScale,
                    self.seed,
                    self.basis,
                    outerRadius
                    )
    
            verts = CycloidCurve(
                    self.cycloPoints,
                    self.cycloType,
                    self.cyclo_a,
                    self.cyclo_b,
                    self.cyclo_d
                    )
    
            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.noiseOctaves,
                    self.noiseBasis,
                    self.noiseSeed
                    )
    
    Brendon Murphy's avatar
    fix
    Brendon Murphy committed
    
        # turn verts into array
        vertArray = vertsToPoints(verts, splineType)
    
        # create object
    
        createCurve(context, vertArray, self)
    
    Brendon Murphy's avatar
    fix
    Brendon Murphy committed
    
        return
    
    
    class Curveaceous_galore(Operator, object_utils.AddObjectHelper):
    
        bl_idname = "curve.curveaceous_galore"
    
        bl_description = "Construct many types of curves"
    
    Brendon Murphy's avatar
    fix
    Brendon Murphy committed
        bl_options = {'REGISTER', 'UNDO', 'PRESET'}
    
    
        ProfileType : EnumProperty(
    
                name="Type",
                description="Form of Curve to create",
                items=[
                ('Arc', "Arc", "Arc"),
                ('Arrow', "Arrow", "Arrow"),
                ('Cogwheel', "Cogwheel", "Cogwheel"),
                ('Cycloid', "Cycloid", "Cycloid"),
                ('Flower', "Flower", "Flower"),
                ('Helix', "Helix (3D)", "Helix"),
                ('Noise', "Noise (3D)", "Noise"),
                ('Nsided', "Nsided", "Nsided"),
                ('Profile', "Profile", "Profile"),
                ('Rectangle', "Rectangle", "Rectangle"),
                ('Splat', "Splat", "Splat"),
                ('Star', "Star", "Star")]
                )
    
        outputType : EnumProperty(
    
                name="Output splines",
                description="Type of splines to output",
                items=[
                ('POLY', "Poly", "Poly Spline type"),
                ('NURBS', "Nurbs", "Nurbs Spline type"),
                ('BEZIER', "Bezier", "Bezier Spline type")]
                )
    
        shape : EnumProperty(
    
                name="2D / 3D",
                description="2D or 3D Curve",
                items=[
                ('2D', "2D", "2D"),
                ('3D', "3D", "3D")
    
    jimmyhaze's avatar
    jimmyhaze committed
                ]
    
        use_cyclic_u : BoolProperty(
    
                name="Cyclic",
                default=True,
                description="make curve closed"
                )
    
        endp_u : BoolProperty(
    
                name="Use endpoint u",
                default=True,
                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"
                )
    
        handleType : EnumProperty(
    
                default='AUTO',
    
                description="Bezier handles type",
                items=[
                ('VECTOR', "Vector", "Vector type Bezier handles"),
    
                ('AUTO', "Auto", "Automatic type Bezier handles")]
    
        # ProfileCurve properties
    
        ProfileCurveType : IntProperty(
    
                name="Type",
                min=1,
                max=5,
                default=1,
                description="Type of Curve's Profile"
                )