[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [1808] contrib/py/scripts/addons/ gpencil_retopo: support for closed lines, set defailt precision to 40 since in a simple example, 15 was far too low.
Campbell Barton
ideasman42 at gmail.com
Sun Apr 10 16:14:03 CEST 2011
Revision: 1808
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=1808
Author: campbellbarton
Date: 2011-04-10 14:14:03 +0000 (Sun, 10 Apr 2011)
Log Message:
-----------
support for closed lines, set defailt precision to 40 since in a simple example, 15 was far too low.
Modified Paths:
--------------
contrib/py/scripts/addons/gpencil_retopo/__init__.py
contrib/py/scripts/addons/gpencil_retopo/retopo.py
Modified: contrib/py/scripts/addons/gpencil_retopo/__init__.py
===================================================================
--- contrib/py/scripts/addons/gpencil_retopo/__init__.py 2011-04-10 12:22:22 UTC (rev 1807)
+++ contrib/py/scripts/addons/gpencil_retopo/__init__.py 2011-04-10 14:14:03 UTC (rev 1808)
@@ -46,7 +46,7 @@
precision = bpy.props.IntProperty(name="Precision",
description="Lower values result in more removed doubles and "
"smoother less precise results",
- default=15,
+ default=40,
min=2,
soft_max=100)
Modified: contrib/py/scripts/addons/gpencil_retopo/retopo.py
===================================================================
--- contrib/py/scripts/addons/gpencil_retopo/retopo.py 2011-04-10 12:22:22 UTC (rev 1807)
+++ contrib/py/scripts/addons/gpencil_retopo/retopo.py 2011-04-10 14:14:03 UTC (rev 1808)
@@ -225,12 +225,13 @@
class Spline(object):
- __slots__ = "points", "hubs", "length", "bb"
+ __slots__ = "points", "hubs", "closed", "length", "bb"
- def __init__(self, points):
+ def __init__(self, points, precision):
self.points = points
self.hubs = []
self.calc_length()
+ self.closed = self.calc_closed(precision)
self.bb = BBox()
self.bb.calc(points)
@@ -242,6 +243,9 @@
f += (co - co_prev).length
co_prev = co
self.length = f
+
+ def calc_closed(self, precision):
+ return (self.points[0] - self.points[-1]).length < (self.length / precision)
def link(self):
if len(self.hubs) < 2:
@@ -273,16 +277,20 @@
hub_prev.links.append(hub)
hub_prev = hub
+ if self.closed:
+ hubs_order[0].links.append(hubs_order[-1])
+ hubs_order[-1].links.append(hubs_order[0])
+
def get_points(stroke):
return [point.co.copy() for point in stroke.points]
-def get_splines(gp):
+def get_splines(gp, precision):
l = gp.layers.active
if l:
frame = l.active_frame
- return [Spline(get_points(stroke)) for stroke in frame.strokes]
+ return [Spline(get_points(stroke), precision) for stroke in frame.strokes]
else:
return []
@@ -427,7 +435,8 @@
def calculate(gp, precision):
- splines = get_splines(gp)
+ # note, this precision is for closed lines, it could be a different arg.
+ splines = get_splines(gp, precision)
# spline endpoints may be co-linear, join these into single splines
connect_splines(splines, precision)
More information about the Bf-extensions-cvs
mailing list