Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
blender-addons
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
blender
blender-addons
Commits
468578b1
Commit
468578b1
authored
13 years ago
by
Campbell Barton
Browse files
Options
Downloads
Patches
Plain Diff
remove some 2d spesific functions, minor refactor
parent
5580c782
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
modules/curve_utils.py
+21
-77
21 additions, 77 deletions
modules/curve_utils.py
with
21 additions
and
77 deletions
modules/curve_utils.py
+
21
−
77
View file @
468578b1
...
...
@@ -25,11 +25,6 @@ def line_point_side_v2(l1, l2, pt):
((
l2
[
0
]
-
pt
[
0
])
*
(
l1
[
1
]
-
pt
[
1
])))
def
shell_angle_to_dist
(
angle
):
from
math
import
cos
return
1.0
if
(
angle
<
0.0001
)
else
abs
(
1.0
/
cos
(
angle
))
def
vis_curve_object
():
scene
=
bpy
.
data
.
scenes
[
0
]
# weak!
cu
=
bpy
.
data
.
curves
.
new
(
name
=
"
Line
"
,
type
=
'
CURVE
'
)
...
...
@@ -74,7 +69,6 @@ def visualize_line(p1, p2, p3=None, rad=None):
if
p3
:
spline
=
ob
.
data
.
splines
.
new
(
type
=
'
POLY
'
)
spline
.
points
[
0
].
co
.
xyz
=
p3
.
to_3d
()
print
(
rad
)
if
rad
is
not
None
:
vis_circle_object
(
p3
,
rad
)
...
...
@@ -137,7 +131,7 @@ def solve_curvature_2d(p1, p2, n1, n2, fac, fallback):
def
points_to_bezier
(
points_orig
,
double_limit
=
0.0001
,
kink_tolerance
=
0.25
,
bezier_tolerance
=
0.
1
,
# error distance, scale dependant
bezier_tolerance
=
0.
02
,
# error distance, scale dependant
subdiv
=
8
,
angle_span
=
0.95
,
# 1.0 tries to evaluate splines of 180d
):
...
...
@@ -165,14 +159,6 @@ def points_to_bezier(points_orig,
va
=
self
.
co
-
self
.
prev
.
co
vb
=
self
.
next
.
co
-
self
.
co
self
.
angle
=
va
.
angle
(
vb
,
0.0
)
# XXX 2D
if
line_point_side_v2
(
self
.
prev
.
co
,
self
.
co
,
self
.
next
.
co
,
)
<
0.0
:
self
.
angle
=
-
self
.
angle
def
angle_diff
(
self
):
"""
use for detecting joints, detect difference in angle from
...
...
@@ -186,21 +172,7 @@ def points_to_bezier(points_orig,
return
abs
(
self
.
angle
-
self
.
prev
.
angle
)
/
math
.
pi
else
:
return
0.0
def
angle_filter
(
self
):
tot
=
1
a
=
self
.
angle
if
self
.
prev
:
tot
+=
1
a
+=
self
.
prev
.
angle
if
self
.
next
:
tot
+=
1
a
+=
self
.
next
.
angle
a
=
a
/
tot
return
0.0
if
abs
(
a
)
<
0.01
else
a
def
calc_normal
(
self
):
v1
=
v2
=
None
if
self
.
prev
and
not
self
.
prev
.
is_joint
:
...
...
@@ -284,8 +256,8 @@ def points_to_bezier(points_orig,
self
.
calc_angle
()
self
.
calc_normal
()
def
total_angle
(
self
):
return
abs
(
sum
((
p
.
angle
for
p
in
self
.
points
)))
#~
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
:
...
...
@@ -560,8 +532,6 @@ def points_to_bezier(points_orig,
fac_1
=
intersect_point_line
(
p2_apex_co
,
p1
.
co
,
p1
.
co
+
l1_tan
)[
1
]
*
fac_fac
fac_2
=
intersect_point_line
(
p1_apex_co
,
p2
.
co
,
p2
.
co
+
l2_tan
)[
1
]
*
fac_fac
# TODO, scale the factors some useful way
h1_fac
=
((
p1
.
co
-
p1_apex_co
).
length
/
0.75
)
-
fac_1
h2_fac
=
((
p2
.
co
-
p2_apex_co
).
length
/
0.75
)
-
fac_2
...
...
@@ -579,14 +549,14 @@ def points_to_bezier(points_orig,
'''
def
bezier_error
(
self
):
def
bezier_error
(
self
,
error_max
=-
1.0
,
test_count
=
8
):
from
mathutils.geometry
import
interpolate_bezier
test_points
=
interpolate_bezier
(
self
.
points
[
0
].
co
.
to_3d
(),
self
.
handle_left
,
self
.
handle_right
,
self
.
points
[
-
1
].
co
.
to_3d
(),
8
,
test_count
,
)
from
mathutils.geometry
import
intersect_point_line
...
...
@@ -616,9 +586,15 @@ def points_to_bezier(points_orig,
length_best
=
length
co_best
=
p_ix
error
+=
length_best
error
+=
length_best
/
test_count
if
error_max
!=
-
1.0
and
error
>
error_max
:
return
True
return
error
if
error_max
!=
-
1.0
:
return
False
else
:
return
error
class
Curve
(
object
):
__slots__
=
(
"
splines
"
,
...
...
@@ -704,10 +680,8 @@ def points_to_bezier(points_orig,
s_prev
=
None
iii
=
0
for
s
in
self
.
splines
:
print
(
iii
)
assert
(
s
.
prev
==
s_prev
)
if
s_prev
:
print
()
assert
(
s_prev
.
next
==
s
)
s_prev
=
s
iii
+=
1
...
...
@@ -795,10 +769,6 @@ def points_to_bezier(points_orig,
base
.
select
=
True
return
cu
points
=
list
(
points_orig
)
...
...
@@ -823,38 +793,12 @@ def points_to_bezier(points_orig,
# return
# curve.validate()
# higher quality but not really needed
'''
curve.redistribute(segment_length / 4.0, smooth=True)
curve.redistribute(segment_length, smooth=False)
def
swap_side
(
p
):
angle
=
p
.
angle_filter
()
if
p
.
prev
.
prev
is
None
:
swap_side
.
last
=
angle
else
:
if
(
swap_side
.
last
>
0.0
)
!=
(
angle
>
0.0
):
if
abs
(
p
.
angle
)
>
0.025
:
swap_side
.
last
=
p
.
angle
return
True
return
False
#curve.split_func_map_point(lambda p: (p.angle_filter() >= 0) != \
# (p.prev.angle_filter() >= 0))
# curve.split_func_map_point(swap_side)
# now split based on total spline angle.
import
math
angle_span_rad
=
angle_span
*
math
.
pi
curve
.
split_func_spline
(
lambda
s
:
len
(
s
.
points
)
//
2
if
(
s
.
total_angle
()
>
angle_span_rad
and
len
(
s
.
points
)
>
2
)
else
-
1
,
recursive
=
True
,
)
'''
curve
.
redistribute
(
segment_length
,
smooth
=
True
)
# debug only!
# to test how good the bezier spline fitting is without corrections
...
...
@@ -866,8 +810,9 @@ def points_to_bezier(points_orig,
# or recursively subdivide...
curve
.
split_func_spline
(
lambda
s
:
len
(
s
.
points
)
//
2
if
((
s
.
bezier_solve
(),
s
.
bezier_error
())[
1
]
>
bezier_tolerance
)
and
(
len
(
s
.
points
))
if
((
s
.
bezier_solve
(),
s
.
bezier_error
(
bezier_tolerance
))[
1
]
and
(
len
(
s
.
points
)))
else
-
1
,
recursive
=
True
,
)
...
...
@@ -883,7 +828,6 @@ def points_to_bezier(points_orig,
if
__name__
==
"
__main__
"
:
print
(
"
A
"
)
bpy
.
ops
.
wm
.
open_mainfile
(
filepath
=
"
/root/curve_test1.blend
"
)
ob
=
bpy
.
data
.
objects
[
"
Curve
"
]
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment