Skip to content
Snippets Groups Projects
Commit dfdf5571 authored by lijenstina's avatar lijenstina
Browse files

Fix T52973: Support data dimensions types, restore global_undo

Bump version to 1.0.3

Support the curve.data.dimesions passed to the main function
as the previous code was only properly supporting 2D types

Restore the global_undo properly to it's previous state
Don't use toggle for bpy.ops.object.mode_set
Add error handling in case of failure

Update the tooltip
parent 23b0c956
No related branches found
No related tags found
No related merge requests found
...@@ -19,9 +19,9 @@ ...@@ -19,9 +19,9 @@
bl_info = { bl_info = {
"name": "Simplify Curves", "name": "Simplify Curves",
"author": "testscreenings", "author": "testscreenings",
"version": (1, 0, 2), "version": (1, 0, 3),
"blender": (2, 75, 0), "blender": (2, 75, 0),
"location": "Search > Simplify Curves", "location": "View3D > Add > Curve > Simplify Curves",
"description": "Simplifies 3D Curve objects and animation F-Curves", "description": "Simplifies 3D Curve objects and animation F-Curves",
"warning": "", "warning": "",
"wiki_url": "https://wiki.blender.org/index.php/Extensions:2.6/Py/" "wiki_url": "https://wiki.blender.org/index.php/Extensions:2.6/Py/"
...@@ -48,6 +48,15 @@ from math import ( ...@@ -48,6 +48,15 @@ from math import (
from bpy.types import Operator from bpy.types import Operator
def error_handlers(self, op_name, errors, reports="ERROR"):
if self and reports:
self.report({'INFO'},
reports + ": some operations could not be performed "
"(See Console for more info)")
print("\n[Simplify Curves]\nOperator: {}\nErrors: {}\n".format(op_name, errors))
# Check for curve # Check for curve
# ### simplipoly algorithm ### # ### simplipoly algorithm ###
...@@ -236,7 +245,7 @@ def vertsToPoints(newVerts, splineVerts, splineType): ...@@ -236,7 +245,7 @@ def vertsToPoints(newVerts, splineVerts, splineType):
# ### MAIN OPERATIONS ### # ### MAIN OPERATIONS ###
def main(context, obj, options): def main(context, obj, options, curve_dimension):
mode = options[0] mode = options[0]
output = options[1] output = options[1]
degreeOut = options[5] degreeOut = options[5]
...@@ -247,6 +256,7 @@ def main(context, obj, options): ...@@ -247,6 +256,7 @@ def main(context, obj, options):
# create curvedatablock # create curvedatablock
curve = bpy.data.curves.new("Simple_" + obj.name, type='CURVE') curve = bpy.data.curves.new("Simple_" + obj.name, type='CURVE')
curve.dimensions = curve_dimension
# go through splines # go through splines
for spline_i, spline in enumerate(splines): for spline_i, spline in enumerate(splines):
...@@ -261,11 +271,11 @@ def main(context, obj, options): ...@@ -261,11 +271,11 @@ def main(context, obj, options):
# get vec3 list to simplify # get vec3 list to simplify
if spline.type == 'BEZIER': # get bezierverts if spline.type == 'BEZIER': # get bezierverts
splineVerts = [splineVert.co.copy() splineVerts = [splineVert.co.copy()
for splineVert in spline.bezier_points.values()] for splineVert in spline.bezier_points.values()]
else: # verts from all other types of curves else: # verts from all other types of curves
splineVerts = [splineVert.co.to_3d() splineVerts = [splineVert.co.to_3d()
for splineVert in spline.points.values()] for splineVert in spline.points.values()]
# simplify spline according to mode # simplify spline according to mode
if mode == 'DISTANCE': if mode == 'DISTANCE':
...@@ -295,10 +305,11 @@ def main(context, obj, options): ...@@ -295,10 +305,11 @@ def main(context, obj, options):
# splineoptions # splineoptions
newSpline.use_endpoint_u = spline.use_endpoint_u newSpline.use_endpoint_u = spline.use_endpoint_u
# create ne object and put into scene # create new object and put into scene
newCurve = bpy.data.objects.new("Simple_" + obj.name, curve) newCurve = bpy.data.objects.new("Simple_" + obj.name, curve)
scene.objects.link(newCurve) scene.objects.link(newCurve)
newCurve.select = True newCurve.select = True
scene.objects.active = newCurve scene.objects.active = newCurve
newCurve.matrix_world = obj.matrix_world newCurve.matrix_world = obj.matrix_world
...@@ -386,42 +397,42 @@ class GRAPH_OT_simplify(Operator): ...@@ -386,42 +397,42 @@ class GRAPH_OT_simplify(Operator):
('DISTANCE', 'Distance', 'Distance-based simplification (Poly)'), ('DISTANCE', 'Distance', 'Distance-based simplification (Poly)'),
('CURVATURE', 'Curvature', 'Curvature-based simplification (RDP)')] ('CURVATURE', 'Curvature', 'Curvature-based simplification (RDP)')]
mode = EnumProperty( mode = EnumProperty(
name="Mode", name="Mode",
description="Choose algorithm to use", description="Choose algorithm to use",
items=opModes items=opModes
) )
k_thresh = FloatProperty( k_thresh = FloatProperty(
name="k", name="k",
min=0, soft_min=0, min=0, soft_min=0,
default=0, precision=3, default=0, precision=3,
description="Threshold" description="Threshold"
) )
pointsNr = IntProperty( pointsNr = IntProperty(
name="n", name="n",
min=5, soft_min=5, min=5, soft_min=5,
max=16, soft_max=9, max=16, soft_max=9,
default=5, default=5,
description="Degree of curve to get averaged curvatures" description="Degree of curve to get averaged curvatures"
) )
error = FloatProperty( error = FloatProperty(
name="Error", name="Error",
description="Maximum allowed distance error", description="Maximum allowed distance error",
min=0.0, soft_min=0.0, min=0.0, soft_min=0.0,
default=0, precision=3 default=0, precision=3
) )
degreeOut = IntProperty( degreeOut = IntProperty(
name="Degree", name="Degree",
min=3, soft_min=3, min=3, soft_min=3,
max=7, soft_max=7, max=7, soft_max=7,
default=5, default=5,
description="Degree of new curve" description="Degree of new curve"
) )
dis_error = FloatProperty( dis_error = FloatProperty(
name="Distance error", name="Distance error",
description="Maximum allowed distance error in Blender Units", description="Maximum allowed distance error in Blender Units",
min=0, soft_min=0, min=0, soft_min=0,
default=0.0, precision=3 default=0.0, precision=3
) )
fcurves = [] fcurves = []
def draw(self, context): def draw(self, context):
...@@ -469,63 +480,67 @@ class GRAPH_OT_simplify(Operator): ...@@ -469,63 +480,67 @@ class GRAPH_OT_simplify(Operator):
class CURVE_OT_simplify(Operator): class CURVE_OT_simplify(Operator):
bl_idname = "curve.simplify" bl_idname = "curve.simplify"
bl_label = "Simplify Curves" bl_label = "Simplify Curves"
bl_description = "Simplify Curves" bl_description = ("Simplify the existing Curve based upon the chosen settings\n"
"Notes: Needs an existing Curve object,\n"
"Outputs a new Curve with the Simple prefix in the name")
bl_options = {'REGISTER', 'UNDO'} bl_options = {'REGISTER', 'UNDO'}
# Properties # Properties
opModes = [ opModes = [
('DISTANCE', 'Distance', 'Distance-based simplification (Poly)'), ('DISTANCE', 'Distance', 'Distance-based simplification (Poly)'),
('CURVATURE', 'Curvature', 'Curvature-based simplification (RDP)')] ('CURVATURE', 'Curvature', 'Curvature-based simplification (RDP)')
]
mode = EnumProperty( mode = EnumProperty(
name="Mode", name="Mode",
description="Choose algorithm to use", description="Choose algorithm to use",
items=opModes items=opModes
) )
SplineTypes = [ SplineTypes = [
('INPUT', 'Input', 'Same type as input spline'), ('INPUT', 'Input', 'Same type as input spline'),
('NURBS', 'Nurbs', 'NURBS'), ('NURBS', 'Nurbs', 'NURBS'),
('BEZIER', 'Bezier', 'BEZIER'), ('BEZIER', 'Bezier', 'BEZIER'),
('POLY', 'Poly', 'POLY')] ('POLY', 'Poly', 'POLY')
]
output = EnumProperty( output = EnumProperty(
name="Output splines", name="Output splines",
description="Type of splines to output", description="Type of splines to output",
items=SplineTypes items=SplineTypes
) )
k_thresh = FloatProperty( k_thresh = FloatProperty(
name="k", name="k",
min=0, soft_min=0, min=0, soft_min=0,
default=0, precision=3, default=0, precision=3,
description="Threshold" description="Threshold"
) )
pointsNr = IntProperty(name="n", pointsNr = IntProperty(name="n",
min=5, soft_min=5, min=5, soft_min=5,
max=9, soft_max=9, max=9, soft_max=9,
default=5, default=5,
description="Degree of curve to get averaged curvatures" description="Degree of curve to get averaged curvatures"
) )
error = FloatProperty( error = FloatProperty(
name="Error", name="Error",
description="Maximum allowed distance error in Blender Units", description="Maximum allowed distance error in Blender Units",
min=0, soft_min=0, min=0, soft_min=0,
default=0.0, precision=3 default=0.0, precision=3
) )
degreeOut = IntProperty(name="Degree", degreeOut = IntProperty(name="Degree",
min=3, soft_min=3, min=3, soft_min=3,
max=7, soft_max=7, max=7, soft_max=7,
default=5, default=5,
description="Degree of new curve" description="Degree of new curve"
) )
dis_error = FloatProperty( dis_error = FloatProperty(
name="Distance error", name="Distance error",
description="Maximum allowed distance error in Blender Units", description="Maximum allowed distance error in Blender Units",
min=0, soft_min=0, min=0, soft_min=0,
default=0.0 default=0.0
) )
keepShort = BoolProperty( keepShort = BoolProperty(
name="Keep short splines", name="Keep short splines",
description="Keep short splines (less than 7 points)", description="Keep short splines (less than 7 points)",
default=True default=True
) )
def draw(self, context): def draw(self, context):
layout = self.layout layout = self.layout
...@@ -555,15 +570,22 @@ class CURVE_OT_simplify(Operator): ...@@ -555,15 +570,22 @@ class CURVE_OT_simplify(Operator):
self.dis_error, # 6 self.dis_error, # 6
self.keepShort # 7 self.keepShort # 7
] ]
try:
global_undo = bpy.context.user_preferences.edit.use_global_undo
context.user_preferences.edit.use_global_undo = False
bpy.context.user_preferences.edit.use_global_undo = False bpy.ops.object.mode_set(mode='OBJECT')
obj = context.active_object
curve_dimension = obj.data.dimensions
bpy.ops.object.mode_set(mode='OBJECT', toggle=True) main(context, obj, options, curve_dimension)
obj = context.active_object
main(context, obj, options) context.user_preferences.edit.use_global_undo = global_undo
except Exception as e:
error_handlers(self, "curve.simplify", e, "Simplify Curves")
bpy.context.user_preferences.edit.use_global_undo = True context.user_preferences.edit.use_global_undo = global_undo
return {'CANCELLED'}
return {'FINISHED'} return {'FINISHED'}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment