[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [2395] trunk/py/scripts/addons/modules/ curve_utils.py: removng curve utils, Id like to keep working on this but currently its not used anywhere.
Campbell Barton
ideasman42 at gmail.com
Thu Oct 6 02:05:28 CEST 2011
Revision: 2395
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=2395
Author: campbellbarton
Date: 2011-10-06 00:05:27 +0000 (Thu, 06 Oct 2011)
Log Message:
-----------
removng curve utils, Id like to keep working on this but currently its not used anywhere.
Removed Paths:
-------------
trunk/py/scripts/addons/modules/curve_utils.py
Deleted: trunk/py/scripts/addons/modules/curve_utils.py
===================================================================
--- trunk/py/scripts/addons/modules/curve_utils.py 2011-10-05 06:04:58 UTC (rev 2394)
+++ trunk/py/scripts/addons/modules/curve_utils.py 2011-10-06 00:05:27 UTC (rev 2395)
@@ -1,994 +0,0 @@
-# ##### BEGIN GPL LICENSE BLOCK #####
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License
-# as published by the Free Software Foundation; either version 2
-# of the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software Foundation,
-# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-#
-# ##### END GPL LICENSE BLOCK #####
-
-# <pep8 compliant>
-
-import bpy
-
-
-def vis_curve_object():
- scene = bpy.data.scenes[0] # weak!
- cu = bpy.data.curves.new(name="Line", type='CURVE')
- ob = bpy.data.objects.new(name="Test", object_data=cu)
- ob.layers = [True] * 20
- base = scene.objects.link(ob)
- return ob
-
-
-def vis_curve_spline(p1, h1, p2, h2):
- ob = vis_curve_object()
- spline = ob.data.splines.new(type='BEZIER')
- spline.bezier_points.add(1)
- spline.bezier_points[0].co = p1.to_3d()
- spline.bezier_points[1].co = p2.to_3d()
-
- spline.bezier_points[0].handle_right = h1.to_3d()
- spline.bezier_points[1].handle_left = h2.to_3d()
-
-
-def vis_circle_object(co, rad=1.0):
- import math
- scene = bpy.data.scenes[0] # weak!
- ob = bpy.data.objects.new(name="Circle", object_data=None)
- ob.rotation_euler.x = math.pi / 2
- ob.location = co.to_3d()
- ob.empty_draw_size = rad
- ob.layers = [True] * 20
- base = scene.objects.link(ob)
- return ob
-
-
-def visualize_line(p1, p2, p3=None, rad=None):
- pair = p1.to_3d(), p2.to_3d()
-
- ob = vis_curve_object()
- spline = ob.data.splines.new(type='POLY')
- spline.points.add(1)
- for co, v in zip((pair), spline.points):
- v.co.xyz = co
-
- if p3:
- spline = ob.data.splines.new(type='POLY')
- spline.points[0].co.xyz = p3.to_3d()
- if rad is not None:
- vis_circle_object(p3, rad)
-
-
-def treat_points(points,
- double_limit=0.0001,
- ):
-
- # first remove doubles
- tot_len = 0.0
- if double_limit != 0.0:
- i = len(points) - 1
- while i > 0:
- length = (points[i] - points[i - 1]).length
- if length < double_limit:
- del points[i]
- if i >= len(points):
- i -= 1
- else:
- tot_len += length
- i -= 1
- return tot_len
-
-
-def solve_curvature(p1, p2, n1, n2, fac, fallback):
- """ Add a nice circular curvature on
- """
- from mathutils.geometry import (intersect_line_line,
- )
-
- p1_a = p1 + n1
- p2_a = p2 - n2
-
- isect = intersect_line_line(p1,
- p1_a,
- p2,
- p2_a,
- )
-
- if isect:
- corner = isect[0].lerp(isect[1], 0.5)
- else:
- corner = None
-
- if corner:
- p1_first_order = p1.lerp(corner, fac)
- p2_first_order = corner.lerp(p2, fac)
- co = p1_first_order.lerp(p2_first_order, fac)
-
- return co
- else:
- # cant interpolate. just return interpolated value
- return fallback.copy() # p1.lerp(p2, fac)
-
-
-def points_to_bezier(points_orig,
- double_limit=0.0001,
- kink_tolerance=0.25,
- bezier_tolerance=0.05, # error distance, scale dependant
- subdiv=8,
- angle_span=0.95, # 1.0 tries to evaluate splines of 180d
- ):
-
- import math
- from mathutils import Vector
-
- class Point(object):
- __slots__ = ("co",
- "angle",
- "no",
- "is_joint",
- "next",
- "prev",
- )
-
- def __init__(self, co):
- self.co = co
- self.is_joint = False
-
- def calc_angle(self):
- if self.prev is None or self.next is None:
- self.angle = 0.0
- else:
- va = self.co - self.prev.co
- vb = self.next.co - self.co
- self.angle = va.angle(vb, 0.0)
-
- def angle_diff(self):
- """ use for detecting joints, detect difference in angle from
- surrounding points.
- """
- if self.prev is None or self.next is None:
- return 0.0
- else:
- if (self.angle > self.prev.angle and
- self.angle > self.next.angle):
- return abs(self.angle - self.prev.angle) / math.pi
- else:
- return 0.0
-
- def calc_normal(self):
- v1 = v2 = None
- if self.prev and not self.prev.is_joint:
- v1 = (self.co - self.prev.co).normalized()
- if self.next and not self.next.is_joint:
- v2 = (self.next.co - self.co).normalized()
-
- if v1 and v2:
- self.no = (v1 + v2).normalized()
- elif v1:
- self.no = v1
- elif v2:
- self.no = v2
- else:
- print("Warning, assigning dummy normal")
- self.no = Vector((0.0, 1, 0.0))
-
- class Spline(object):
- __slots__ = ("points",
- "handle_left",
- "handle_right",
- "next",
- "prev",
- )
-
- def __init__(self, points):
- self.points = points
-
- def link_points(self):
-
- if hasattr(self.points[0], "prev"):
- raise Exception("already linked")
-
- p_prev = None
- for p in self.points:
- p.prev = p_prev
- p_prev = p
-
- p_prev = None
- for p in reversed(self.points):
- p.next = p_prev
- p_prev = p
-
- def split(self, i, is_joint=False):
- prev = self.prev
- next = self.next
-
- if is_joint:
- self.points[i].is_joint = True
-
- # share a point
- spline_a = Spline(self.points[:i + 1])
- spline_b = Spline(self.points[i:])
-
- # invalidate self, dont reuse!
- self.points = None
-
- spline_a.next = spline_b
- spline_b.prev = spline_a
-
- spline_a.prev = prev
- spline_b.next = next
- if prev:
- prev.next = spline_a
- if next:
- next.prev = spline_b
-
- return spline_a, spline_b
-
- def calc_angle(self):
- for p in self.points:
- p.calc_angle()
-
- def calc_normal(self):
- for p in self.points:
- p.calc_normal()
-
- def calc_all(self):
- self.link_points()
- self.calc_angle()
- self.calc_normal()
-
- #~ def total_angle(self):
- #~ return abs(sum((p.angle for p in self.points)))
-
- def redistribute(self, segment_length, smooth=False):
- if len(self.points) == 1:
- return
-
- from mathutils.geometry import intersect_line_sphere
-
- p_line = p = self.points[0]
- points = [(p.co.copy(), p.co.copy())]
- p = p.next
-
- def point_add(co, p=None):
- co = co.copy()
- co_smooth = co.copy()
-
- if smooth:
- if p is None:
- pass # works ok but no smoothing
- elif (p.prev.no - p.no).length < 0.001:
- pass # normals are too similar, paralelle
- elif (p.angle > 0.0) != (p.prev.angle > 0.0):
- pass
- else:
- # visualize_line(p.co, p.co + p.no)
-
- # this assumes co is on the line
- fac = ((p.prev.co - co).length /
- (p.prev.co - p.co).length)
-
- assert(fac >= 0.0 and fac <= 1.0)
-
- co_smooth = solve_curvature(p.prev.co,
- p.co,
- p.prev.no,
- p.no,
- fac,
- co,
- )
-
- points.append((co, co_smooth))
-
- def point_step(p):
- if p.is_joint or p.next is None:
- point_add(p.co)
- return None
- else:
- return p.next
-
- print("START")
- while p:
- # we want the first pont past the segment size
-
- #if p.is_joint:
- # vis_circle_object(p.co)
-
- length = (points[-1][0] - p.co).length
-
- if abs(length - segment_length) < 0.00001:
- # close enough to be considered on the circle bounds
- point_add(p.co)
- p_line = p
- p = point_step(p)
- elif length < segment_length:
- p = point_step(p)
- else:
- # the point is further then the segment width
- p_start = points[-1][0] if p.prev is p_line else p.prev.co
-
- if (p_start - points[-1][0]).length > segment_length:
- raise Exception("eek2")
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list