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
c7b5ffcf
Commit
c7b5ffcf
authored
5 years ago
by
meta-androcto
Browse files
Options
Downloads
Patches
Plain Diff
curve_simplify: add merge by distance: T53367
parent
20a8e9d3
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
curve_simplify.py
+92
-8
92 additions, 8 deletions
curve_simplify.py
with
92 additions
and
8 deletions
curve_simplify.py
+
92
−
8
View file @
c7b5ffcf
...
...
@@ -17,12 +17,12 @@
# ##### END GPL LICENSE BLOCK #####
bl_info
=
{
"
name
"
:
"
Simplify Curves
"
,
"
author
"
:
"
testscreenings
"
,
"
version
"
:
(
1
,
0
,
3
),
"
name
"
:
"
Simplify Curves
+
"
,
"
author
"
:
"
testscreenings
, Michael Soluyanov
"
,
"
version
"
:
(
1
,
1
,
1
),
"
blender
"
:
(
2
,
80
,
0
),
"
location
"
:
"
View
3D > Add > Curve > Simplify Curve
s
"
,
"
description
"
:
"
Simplif
ies 3D Curve objects and animation F-Curves
"
,
"
location
"
:
"
3D
View
, Dopesheet & Graph Editor
s
"
,
"
description
"
:
"
Simplif
y Curves: 3dview, Dopesheet, Graph. Distance Merge: 3d view curve edit
"
,
"
warning
"
:
""
,
"
wiki_url
"
:
"
https://wiki.blender.org/index.php/Extensions:2.6/Py/
"
"
Scripts/Curve/Curve_Simplify
"
,
...
...
@@ -30,7 +30,8 @@ bl_info = {
}
"""
This script simplifies Curve objects and animation F-Curves.
This script simplifies Curve objects and animation F-Curves
This script will also Merge by Distance 3d view curves in edit mode
"""
import
bpy
...
...
@@ -40,7 +41,7 @@ from bpy.props import (
FloatProperty
,
IntProperty
,
)
from
mathutils
import
Vector
import
mathutils
from
math
import
(
sin
,
pow
,
...
...
@@ -585,11 +586,91 @@ class CURVE_OT_simplify(Operator):
return
{
'
FINISHED
'
}
## Initial use Curve Remove Doubles ##
def
main
(
context
,
distance
=
0.01
):
obj
=
context
.
active_object
dellist
=
[]
for
spline
in
obj
.
data
.
splines
:
if
len
(
spline
.
bezier_points
)
>
1
:
for
i
in
range
(
0
,
len
(
spline
.
bezier_points
)):
if
i
==
0
:
ii
=
len
(
spline
.
bezier_points
)
-
1
else
:
ii
=
i
-
1
dot
=
spline
.
bezier_points
[
i
];
dot1
=
spline
.
bezier_points
[
ii
];
while
dot1
in
dellist
and
i
!=
ii
:
ii
-=
1
if
ii
<
0
:
ii
=
len
(
spline
.
bezier_points
)
-
1
dot1
=
spline
.
bezier_points
[
ii
]
if
dot
.
select_control_point
and
dot1
.
select_control_point
and
(
i
!=
0
or
spline
.
use_cyclic_u
):
if
(
dot
.
co
-
dot1
.
co
).
length
<
distance
:
# remove points and recreate hangles
dot1
.
handle_right_type
=
"
FREE
"
dot1
.
handle_right
=
dot
.
handle_right
dot1
.
co
=
(
dot
.
co
+
dot1
.
co
)
/
2
dellist
.
append
(
dot
)
else
:
# Handles that are on main point position converts to vector,
# if next handle are also vector
if
dot
.
handle_left_type
==
'
VECTOR
'
and
(
dot1
.
handle_right
-
dot1
.
co
).
length
<
distance
:
dot1
.
handle_right_type
=
"
VECTOR
"
if
dot1
.
handle_right_type
==
'
VECTOR
'
and
(
dot
.
handle_left
-
dot
.
co
).
length
<
distance
:
dot
.
handle_left_type
=
"
VECTOR
"
bpy
.
ops
.
curve
.
select_all
(
action
=
'
DESELECT
'
)
for
dot
in
dellist
:
dot
.
select_control_point
=
True
count
=
len
(
dellist
)
bpy
.
ops
.
curve
.
delete
(
type
=
'
VERT
'
)
bpy
.
ops
.
curve
.
select_all
(
action
=
'
SELECT
'
)
return
count
class
Curve_OT_CurveRemvDbs
(
bpy
.
types
.
Operator
):
"""
Merge consecutive points that are near to each other
"""
bl_idname
=
'
curve.remove_doubles
'
bl_label
=
'
Merge By Distance
'
bl_options
=
{
'
REGISTER
'
,
'
UNDO
'
}
distance
:
bpy
.
props
.
FloatProperty
(
name
=
'
Distance
'
,
default
=
0.01
,
min
=
0.0001
,
max
=
10.0
,
step
=
1
)
@classmethod
def
poll
(
cls
,
context
):
obj
=
context
.
active_object
return
(
obj
and
obj
.
type
==
'
CURVE
'
)
def
execute
(
self
,
context
):
removed
=
main
(
context
,
self
.
distance
)
self
.
report
({
'
INFO
'
},
"
Removed %d bezier points
"
%
removed
)
return
{
'
FINISHED
'
}
def
menu_func_rd
(
self
,
context
):
self
.
layout
.
operator
(
Curve_OT_CurveRemvDbs
.
bl_idname
,
text
=
'
Merge By Distance
'
)
# Register
classes
=
[
GRAPH_OT_simplify
,
CURVE_OT_simplify
,
Curve_OT_CurveRemvDbs
,
]
...
...
@@ -601,6 +682,8 @@ def register():
bpy
.
types
.
GRAPH_MT_channel
.
append
(
menu_func
)
bpy
.
types
.
DOPESHEET_MT_channel
.
append
(
menu_func
)
bpy
.
types
.
VIEW3D_MT_curve_add
.
append
(
menu
)
bpy
.
types
.
VIEW3D_MT_edit_curve_context_menu
.
prepend
(
menu
)
bpy
.
types
.
VIEW3D_MT_edit_curve_context_menu
.
prepend
(
menu_func_rd
)
def
unregister
():
...
...
@@ -611,7 +694,8 @@ def unregister():
bpy
.
types
.
GRAPH_MT_channel
.
remove
(
menu_func
)
bpy
.
types
.
DOPESHEET_MT_channel
.
remove
(
menu_func
)
bpy
.
types
.
VIEW3D_MT_curve_add
.
remove
(
menu
)
bpy
.
types
.
VIEW3D_MT_edit_curve_context_menu
.
remove
(
menu
)
bpy
.
types
.
VIEW3D_MT_edit_curve_context_menu
.
remove
(
menu_func_rd
)
if
__name__
==
"
__main__
"
:
register
()
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