-
-
Notifications
You must be signed in to change notification settings - Fork 55
/
metaballscale.py
104 lines (89 loc) · 3.33 KB
/
metaballscale.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# ##### BEGIN GPL LICENSE BLOCK #####
#
# metaballscale.py
# Scale the size of all selected meta elements
# (c) 2018 Michel Anders (varkenvarken)
#
# 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 #####
bl_info = {
"name": "MetaballSize",
"author": "Michel Anders (varkenvarken)",
"version": (0, 0, 201809231640),
"blender": (2, 79, 0),
"location": "View3D > Metaball",
"description": "Scale attributes of all elements in a metaball",
"warning": "",
"wiki_url": "",
"tracker_url": "",
"category": "Metaballs"}
import bpy
from bpy.props import FloatVectorProperty, FloatProperty, EnumProperty
from bpy.types import Panel
class MetaballSize(bpy.types.Operator):
bl_idname = "mesh.metaballsize"
bl_label = "MetaballSize"
bl_description = "Scale attributes of all elements in a metaball"
bl_options = {'REGISTER', 'UNDO'}
scale = FloatVectorProperty(name="Size", default=(1.0, 1.0, 1.0))
radius = FloatProperty(name="Radius", default=1.0, min=0.0)
stiffness = FloatProperty(name="Stiffness", default=1.0, min=0.0)
type = EnumProperty(name="Type",
items = [('KEEP','Keep','Do not change the type'),
('CUBE','Cube','Cube'),
('ELLIPSOID','Ellipsoid','Ellipsoid'),
('PLANE','Plane','Plane'),
('BALL','Ball','Ball'),
('CAPSULE','Capsule','Capsule')],
default = 'KEEP')
@classmethod
def poll(cls, context):
return context.mode == 'EDIT_METABALL'
def execute(self, context):
# we'd rather do this for just the selected elements but
# apparently the select status is not exposed
# see: https://blender.stackexchange.com/questions/101350/how-can-i-find-the-selected-metaball-elements-in-edit-mode-with-python
for e in context.active_object.data.elements:
e.size_x *= self.scale[0]
e.size_y *= self.scale[1]
e.size_z *= self.scale[2]
e.radius *= self.radius
e.stiffness *= self.stiffness
if self.type != 'KEEP':
for e in context.active_object.data.elements:
e.type = self.type + ''
return {'FINISHED'}
class DATA_PT_metaball_element_extra(Panel):
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = "data"
bl_label = "Active Element II"
@classmethod
def poll(cls, context):
return (context.meta_ball and context.meta_ball.elements.active)
def draw(self, context):
layout = self.layout
metaelem = context.meta_ball.elements.active
layout.prop(metaelem, "radius", text="Radius")
def menu_func(self, context):
self.layout.separator()
self.layout.operator(MetaballSize.bl_idname)
def register():
bpy.utils.register_module(__name__)
bpy.types.VIEW3D_MT_edit_meta.append(menu_func)
def unregister():
bpy.types.VIEW3D_MT_edit_meta.remove(menu_func)
bpy.utils.unregister_module(__name__)