Skip to content
Snippets Groups Projects
Commit 288fa424 authored by Spivak Vladimir (cwolf3d)'s avatar Spivak Vladimir (cwolf3d)
Browse files

Added (in add_curve_simple) a type of curve creation.

Implemented the ability to add curves (add_curve_aceous_galore) in edit mode.
parent 22214fda
Branches
No related tags found
No related merge requests found
...@@ -244,13 +244,12 @@ class INFO_MT_curve_knots_add(Menu): ...@@ -244,13 +244,12 @@ class INFO_MT_curve_knots_add(Menu):
# Define "Extras" menus # Define "Extras" menus
def menu_func(self, context): def menu_func(self, context):
if context.mode != 'OBJECT':
# fix in D2142 will allow to work in EDIT_CURVE
return None
layout = self.layout layout = self.layout
layout.operator_menu_enum("curve.curveaceous_galore", "ProfileType", icon='CURVE_DATA') layout.operator_menu_enum("curve.curveaceous_galore", "ProfileType", icon='CURVE_DATA')
if context.mode != 'OBJECT':
# fix in D2142 will allow to work in EDIT_CURVE
return None
layout.operator_menu_enum("curve.spirals", "spiral_type", icon='CURVE_DATA') layout.operator_menu_enum("curve.spirals", "spiral_type", icon='CURVE_DATA')
layout.separator() layout.separator()
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
bl_info = { bl_info = {
"name": "Curveaceous Galore!", "name": "Curveaceous Galore!",
"author": "Jimmy Hazevoet, testscreenings", "author": "Jimmy Hazevoet, testscreenings",
"version": (0, 2, 2), "version": (0, 2, 3),
"blender": (2, 80), "blender": (2, 80),
"location": "View3D > Add > Curve", "location": "View3D > Add > Curve",
"description": "Adds many different types of Curves", "description": "Adds many different types of Curves",
...@@ -32,11 +32,13 @@ bl_info = { ...@@ -32,11 +32,13 @@ bl_info = {
""" """
import bpy import bpy
from bpy_extras import object_utils
from bpy.props import ( from bpy.props import (
BoolProperty, BoolProperty,
EnumProperty, EnumProperty,
FloatProperty, FloatProperty,
IntProperty, IntProperty,
FloatVectorProperty
) )
from mathutils import Matrix, Vector from mathutils import Matrix, Vector
from bpy.types import Operator from bpy.types import Operator
...@@ -717,35 +719,17 @@ def NoiseCurve(type=0, number=100, length=2.0, size=0.5, ...@@ -717,35 +719,17 @@ def NoiseCurve(type=0, number=100, length=2.0, size=0.5,
# ------------------------------------------------------------ # ------------------------------------------------------------
# calculates the matrix for the new object # calculates the matrix for the new object
# depending on user pref # depending on user pref
def align_matrix(context): def align_matrix(context, location):
loc = Matrix.Translation(location)
loc = Matrix.Translation(context.scene.cursor_location)
obj_align = context.preferences.edit.object_align obj_align = context.preferences.edit.object_align
if (context.space_data.type == 'VIEW_3D' and if (context.space_data.type == 'VIEW_3D' and
obj_align == 'VIEW'): obj_align == 'VIEW'):
rot = context.space_data.region_3d.view_matrix.to_3x3().inverted().to_4x4() rot = context.space_data.region_3d.view_matrix.to_3x3().inverted().to_4x4()
else: else:
rot = Matrix() rot = Matrix()
align_matrix = loc @ rot align_matrix = loc @ rot
return align_matrix
# ------------------------------------------------------------
# Curve creation functions, sets bezierhandles to auto
def setBezierHandles(obj, mode='AUTO'):
scene = bpy.context.scene
if obj.type != 'CURVE':
return
#scene.objects.active = obj return align_matrix
#bpy.ops.object.mode_set(mode='EDIT', toggle=True)
#bpy.ops.curve.select_all(action='SELECT')
#obj.select_set(action='SELECT')
#bpy.ops.curve.handle_type_set(type=mode)
#bpy.ops.object.mode_set(mode='OBJECT', toggle=True)
# get array of vertcoordinates according to splinetype # get array of vertcoordinates according to splinetype
def vertsToPoints(Verts, splineType): def vertsToPoints(Verts, splineType):
...@@ -773,17 +757,31 @@ def vertsToPoints(Verts, splineType): ...@@ -773,17 +757,31 @@ def vertsToPoints(Verts, splineType):
# create new CurveObject from vertarray and splineType # create new CurveObject from vertarray and splineType
def createCurve(context, vertArray, self, align_matrix): def createCurve(context, vertArray, self, align_matrix):
scene = bpy.context.scene
# output splineType 'POLY' 'NURBS' 'BEZIER' # output splineType 'POLY' 'NURBS' 'BEZIER'
splineType = self.outputType splineType = self.outputType
# GalloreType as name # GalloreType as name
name = self.ProfileType name = self.ProfileType
# create curve # create object
newCurve = bpy.data.curves.new(name, type='CURVE') if bpy.context.mode == 'EDIT_CURVE':
newSpline = newCurve.splines.new(type=splineType) Curve = context.active_object
newSpline = Curve.data.splines.new(type=splineType) # spline
Curve.matrix_world = align_matrix # apply matrix
Curve.rotation_euler = self.rotation_euler
else:
# create curve
newCurve = bpy.data.curves.new(name, type='CURVE') # curve data block
newSpline = newCurve.splines.new(type=splineType) # spline
# set curveOptions
newCurve.dimensions = self.shape
# create object with newCurve
SimpleCurve = object_utils.object_data_add(context, newCurve, operator=self) # place in active scene
SimpleCurve.select_set(True)
SimpleCurve.matrix_world = align_matrix # apply matrix
SimpleCurve.rotation_euler = self.rotation_euler
# create spline from vertarray # create spline from vertarray
if splineType == 'BEZIER': if splineType == 'BEZIER':
...@@ -798,32 +796,15 @@ def createCurve(context, vertArray, self, align_matrix): ...@@ -798,32 +796,15 @@ def createCurve(context, vertArray, self, align_matrix):
newSpline.use_endpoint_u = True newSpline.use_endpoint_u = True
# set curveOptions # set curveOptions
newCurve.dimensions = self.shape
newSpline.use_cyclic_u = self.use_cyclic_u newSpline.use_cyclic_u = self.use_cyclic_u
newSpline.use_endpoint_u = self.endp_u newSpline.use_endpoint_u = self.endp_u
newSpline.order_u = self.order_u newSpline.order_u = self.order_u
# create object with newCurve
new_obj = bpy.data.objects.new(name, newCurve)
scene.collection.objects.link(new_obj)
new_obj.select_set(True)
#scene.objects.active = new_obj
new_obj.matrix_world = align_matrix
# set bezierhandles
#if splineType == 'BEZIER':
#bpy.ops.curve.handle_type_set(type='AUTO')
#setBezierHandles(new_obj, self.handleType)
return return
# ------------------------------------------------------------ # ------------------------------------------------------------
# Main Function # Main Function
def main(context, self, align_matrix): def main(context, self, align_matrix):
# deselect all objects
#bpy.ops.object.select_all(action='DESELECT')
# options # options
proType = self.ProfileType proType = self.ProfileType
splineType = self.outputType splineType = self.outputType
...@@ -934,14 +915,14 @@ def main(context, self, align_matrix): ...@@ -934,14 +915,14 @@ def main(context, self, align_matrix):
return return
class Curveaceous_galore(Operator): class Curveaceous_galore(Operator, object_utils.AddObjectHelper):
bl_idname = "curve.curveaceous_galore" bl_idname = "curve.curveaceous_galore"
bl_label = "Curve Profiles" bl_label = "Curve Profiles"
bl_description = "Construct many types of curves" bl_description = "Construct many types of curves"
bl_options = {'REGISTER', 'UNDO', 'PRESET'} bl_options = {'REGISTER', 'UNDO', 'PRESET'}
# align_matrix for the invoke # align_matrix for the invoke
align_matrix = None align_matrix : Matrix()
# general properties # general properties
ProfileType : EnumProperty( ProfileType : EnumProperty(
...@@ -1294,6 +1275,19 @@ class Curveaceous_galore(Operator): ...@@ -1294,6 +1275,19 @@ class Curveaceous_galore(Operator):
min=0, min=0,
description="Random Seed" description="Random Seed"
) )
# Line properties
startlocation : FloatVectorProperty(
name="",
description="Start location",
default=(0.0, 0.0, 0.0),
subtype='TRANSLATION'
)
rotation_euler : FloatVectorProperty(
name="",
description="Rotation",
default=(0.0, 0.0, 0.0),
subtype='EULER'
)
def draw(self, context): def draw(self, context):
layout = self.layout layout = self.layout
...@@ -1413,16 +1407,26 @@ class Curveaceous_galore(Operator): ...@@ -1413,16 +1407,26 @@ class Curveaceous_galore(Operator):
col.prop(self, "noiseBasis") col.prop(self, "noiseBasis")
col.prop(self, "noiseSeed") col.prop(self, "noiseSeed")
# output options
col = layout.column() col = layout.column()
col.label(text="Output Curve Type:") col.label(text="Output Curve Type:")
col.row().prop(self, "outputType", expand=True) col.row().prop(self, "outputType", expand=True)
# output options
if self.outputType == 'NURBS': if self.outputType == 'NURBS':
col.prop(self, 'order_u') col.prop(self, 'order_u')
elif self.outputType == 'BEZIER': elif self.outputType == 'BEZIER':
col.row().prop(self, 'handleType', expand=True) col.row().prop(self, 'handleType', expand=True)
#col = layout.column()
#col.row().prop(self, "use_cyclic_u", expand=True)
box = layout.box()
box.label(text="Location:")
box.prop(self, "startlocation")
box = layout.box()
box.label(text="Rotation:")
box.prop(self, "rotation_euler")
@classmethod @classmethod
def poll(cls, context): def poll(cls, context):
return context.scene is not None return context.scene is not None
...@@ -1452,6 +1456,7 @@ class Curveaceous_galore(Operator): ...@@ -1452,6 +1456,7 @@ class Curveaceous_galore(Operator):
self.use_cyclic_u = True self.use_cyclic_u = True
# main function # main function
self.align_matrix = align_matrix(context, self.startlocation)
main(context, self, self.align_matrix or Matrix()) main(context, self, self.align_matrix or Matrix())
# restore pre operator undo state # restore pre operator undo state
...@@ -1459,13 +1464,6 @@ class Curveaceous_galore(Operator): ...@@ -1459,13 +1464,6 @@ class Curveaceous_galore(Operator):
return {'FINISHED'} return {'FINISHED'}
def invoke(self, context, event):
# store creation_matrix
self.align_matrix = align_matrix(context)
self.execute(context)
return {'FINISHED'}
# Register # Register
classes = [ classes = [
Curveaceous_galore Curveaceous_galore
......
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment