Page Menu
Home
Search
Configure Global Search
Log In
Files
F17645
mesh_relaxlhc2.py
Public
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Authored By
Tobias Oelgarte (niabot)
Nov 13 2013, 4:02 PM
Size
4 KB
Subscribers
None
mesh_relaxlhc2.py
View Options
# mesh_relax_lhc.py Copyright (C) 2012, Tobias Oelgarte
#
# Relaxes selected vertices while retaining the shape
#
# ***** 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 LICENCE BLOCK *****
bl_info
=
{
"name"
:
"RelaxLHC"
,
"author"
:
"Tobias Oelgarte"
,
"version"
:
(
1
,
1
),
"blender"
:
(
2
,
6
,
3
),
"location"
:
"View3D > Specials > RelaxLHC"
,
"description"
:
"Relaxes the selected vertices while retaining shape"
,
"warning"
:
""
,
"wiki_url"
:
"http://wiki.blender.org/index.php/Extensions:2.6/Py/Scripts/Mesh/RelaxLHC"
,
"tracker_url"
:
"http://projects.blender.org/tracker/index.php?func=detail&aid=32021&group_id=153&atid=467"
,
"category"
:
"Mesh"
}
"""
Usage:
Launch from "W-menu" or from "Mesh -> Vertices -> Relax"
"""
import
bpy
from
mathutils
import
Vector
as
Vec
from
bpy.props
import
FloatProperty
def
relax
(
context
,
strength
,
hcFactor
):
bpy
.
ops
.
object
.
mode_set
(
mode
=
'OBJECT'
)
obj
=
context
.
active_object
mesh
=
obj
.
data
vertices
=
obj
.
active_shape_key
.
data
if
obj
.
active_shape_key
else
mesh
.
vertices
normals
=
[
v
.
normal
for
v
in
mesh
.
vertices
]
selected
=
[
v
.
select
for
v
in
mesh
.
vertices
]
edgeKeys
=
mesh
.
edge_keys
num
=
len
(
vertices
)
data
=
[[
Vec
((
0
,
0
,
0
)),
Vec
((
0
,
0
,
0
)),
Vec
((
0
,
0
,
0
)),
Vec
((
0
,
0
,
0
)),
0
]
for
i
in
range
(
num
)]
for
ek
in
edgeKeys
:
data
[
ek
[
0
]][
0
]
+=
vertices
[
ek
[
1
]]
.
co
data
[
ek
[
1
]][
0
]
+=
vertices
[
ek
[
0
]]
.
co
data
[
ek
[
0
]][
4
]
+=
1
data
[
ek
[
1
]][
4
]
+=
1
for
i
in
range
(
num
):
ve
=
vertices
[
i
]
diff
=
data
[
i
][
0
]
*
(
1.0
/
data
[
i
][
4
])
data
[
i
][
1
]
=
diff
data
[
i
][
2
]
=
diff
-
ve
.
co
for
ek
in
edgeKeys
:
data
[
ek
[
0
]][
3
]
+=
data
[
ek
[
1
]][
2
]
data
[
ek
[
1
]][
3
]
+=
data
[
ek
[
0
]][
2
]
for
i
in
range
(
num
):
ve
=
vertices
[
i
]
no
=
normals
[
i
]
if
selected
[
i
]:
loc_l
=
data
[
i
][
0
]
/
data
[
i
][
4
]
d
=
loc_l
-
ve
.
co
d
=
no
*
(
d
.
dot
(
no
)
/
no
.
length_squared
)
loc_l
-=
d
loc_hc
=
data
[
i
][
1
]
-
0.5
*
(
data
[
i
][
2
]
+
data
[
i
][
3
]
/
data
[
i
][
4
])
loc_lhc
=
loc_l
*
(
1.0
-
hcFactor
)
+
loc_hc
*
hcFactor
ve
.
co
=
ve
.
co
*
(
1.0
-
strength
)
+
loc_lhc
*
strength
bpy
.
ops
.
object
.
mode_set
(
mode
=
'EDIT'
)
class
RelaxLHC
(
bpy
.
types
.
Operator
):
""" Relaxes the selected vertices while retaining shape """
bl_idname
=
"mesh.relaxlhc"
bl_label
=
"RelaxLHC"
bl_options
=
{
'REGISTER'
,
'UNDO'
}
strength
=
FloatProperty
(
\
name
=
"Strength"
,
\
description
=
"Strength of the relaxiation"
,
\
default
=
1.0
,
min
=-
10.0
,
max
=
10.0
,
soft_min
=
0.0
,
soft_max
=
1.0
,
\
step
=
3
,
precision
=
2
)
hcFactor
=
FloatProperty
(
\
name
=
"HC Factor"
,
\
description
=
"Blends from Laplacian to HC relaxiation"
,
\
default
=
0.0
,
min
=
0.0
,
max
=
1.0
,
soft_min
=
0.0
,
soft_max
=
1.0
,
\
step
=
3
,
precision
=
2
)
@classmethod
def
poll
(
self
,
context
):
obj
=
context
.
active_object
return
(
obj
and
obj
.
type
==
'MESH'
)
def
execute
(
self
,
context
):
relax
(
context
,
self
.
strength
,
self
.
hcFactor
)
return
{
"FINISHED"
}
def
menu_func
(
self
,
context
):
self
.
layout
.
operator
(
RelaxLHC
.
bl_idname
,
text
=
"RelaxLHC"
)
def
register
():
bpy
.
utils
.
register_module
(
__name__
)
bpy
.
types
.
VIEW3D_MT_edit_mesh_specials
.
append
(
menu_func
)
bpy
.
types
.
VIEW3D_MT_edit_mesh_vertices
.
append
(
menu_func
)
def
unregister
():
bpy
.
utils
.
unregister_module
(
__name__
)
bpy
.
types
.
VIEW3D_MT_edit_mesh_specials
.
remove
(
menu_func
)
bpy
.
types
.
VIEW3D_MT_edit_mesh_vertices
.
remove
(
menu_func
)
if
__name__
==
"__main__"
:
register
()
File Metadata
Details
Mime Type
text/x-python
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
67/bf/bdd94d799dcf673a5fa6111b41e9
Event Timeline
Log In to Comment