├── .gitignore
├── util.py
├── preferences.py
├── README.md
├── __init__.py
├── op_LatticeRemove.py
├── op_LatticeApply.py
├── op_LatticeCreate.py
└── LICENSE
/.gitignore:
--------------------------------------------------------------------------------
1 | .vscode
2 | __pycache__/
3 |
4 | *.code-workspace
5 |
--------------------------------------------------------------------------------
/util.py:
--------------------------------------------------------------------------------
1 | #Version 0.1.6
2 |
3 | import bpy
4 | from mathutils import *
5 | import collections
6 |
7 | allowed_object_types = set(['MESH', 'CURVE', 'SURFACE',
8 | 'FONT', 'GPENCIL', 'LATTICE'])
9 |
10 | # https://blender.stackexchange.com/questions/32283/what-are-all-values-in-bound-box
11 | def bounds(local_coords, orientation=None):
12 | if orientation:
13 | def apply_orientation(p): return orientation @ Vector(p[:])
14 | coords = [apply_orientation(p).to_tuple() for p in local_coords]
15 | else:
16 | coords = [p[:] for p in local_coords]
17 |
18 | rotated = zip(*coords[::-1])
19 |
20 | push_axis = []
21 | for (axis, _list) in zip('xyz', rotated):
22 | def info(): return None
23 | info.max = max(_list)
24 | info.min = min(_list)
25 | info.distance = info.max - info.min
26 | push_axis.append(info)
27 |
28 | originals = dict(zip(['x', 'y', 'z'], push_axis))
29 |
30 | o_details = collections.namedtuple('object_details', 'x y z')
31 | return o_details(**originals)
32 |
--------------------------------------------------------------------------------
/preferences.py:
--------------------------------------------------------------------------------
1 | #Version 0.1.6
2 |
3 | import bpy
4 |
5 |
6 | class SimpleLatticePrefs(bpy.types.AddonPreferences):
7 | bl_idname = __package__
8 |
9 | orientation_types = (('GLOBAL', 'Global', ''),
10 | ('LOCAL', 'Local', ''),
11 | ('CURSOR', 'Cursor', ''),
12 | ('NORMAL', 'Normal', ''))
13 |
14 | # position_types = (('on_top','On Top',''),
15 | # ('bottom','Bottom',''))
16 |
17 | interpolation_types = (('KEY_LINEAR', 'Linear', ''),
18 | ('KEY_CARDINAL', 'Cardinal', ''),
19 | ('KEY_CATMULL_ROM', 'Catmull-Rom', ''),
20 | ('KEY_BSPLINE', 'BSpline', ''))
21 |
22 | default_orientation: bpy.props.EnumProperty(
23 | name="Default Orientation",
24 | items=orientation_types,
25 | default='GLOBAL'
26 | )
27 |
28 | # default_position: bpy.props.EnumProperty(
29 | # name="Default Position",
30 | # items=position_types,
31 | # default='bottom'
32 | # )
33 |
34 | default_ignore_mods: bpy.props.BoolProperty(
35 | name="Ignore Modifiers",
36 | default = False,
37 | description="Ignore Modifiers for calculation BBOX for lattice")
38 |
39 | default_resolution_u: bpy.props.IntProperty(
40 | #name="Default U",
41 | default=2,
42 | min=2
43 | )
44 |
45 | default_resolution_v: bpy.props.IntProperty(
46 | #name="Default V",
47 | default=2,
48 | min=2
49 | )
50 |
51 | default_resolution_w: bpy.props.IntProperty(
52 | #name="Default W",
53 | default=2,
54 | min=2
55 | )
56 |
57 | default_interpolation: bpy.props.EnumProperty(
58 | name="Default Interpolation",
59 | items=interpolation_types,
60 | default='KEY_LINEAR'
61 | )
62 |
63 | default_scale: bpy.props.FloatProperty(
64 | name="Scale",
65 | default=1.0,
66 | min=0.001,
67 | soft_min=0.1,
68 | soft_max=2.0
69 | )
70 |
71 | def draw(self, context):
72 | layout = self.layout
73 | layout.use_property_split = True
74 |
75 | box = layout.box()
76 | col = box.column()
77 | sub = col.row()
78 | sub.prop(self, "default_orientation", expand=True)
79 |
80 | # col.separator()
81 | # sub = col.row()
82 | # sub.prop(self, "default_position", expand=True)
83 |
84 | col.separator()
85 | sub = col.row()
86 | sub.prop(self, "default_ignore_mods")
87 |
88 | col.separator()
89 | sub = col.row()
90 | sub2 = sub.column(align=True)
91 | sub2.prop(self, "default_resolution_u", text="Default U")
92 | sub2.prop(self, "default_resolution_v", text="V")
93 | sub2.prop(self, "default_resolution_w", text="W")
94 |
95 | col.separator()
96 | sub = col.row()
97 | sub.prop(self, "default_interpolation")
98 |
99 | col.separator()
100 | sub = col.row()
101 | sub.prop(self, "default_scale")
102 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # SimpleLattice
2 |
3 | a small blender 2.9 addon to make working with lattices simpler.
4 |
5 | Basically just select objects/vertices and run>SimpleLattice. This will add a lattice object, creates modifiers and vertex groups.
6 | You can choose the alignment of the lattice, the number of control points and the interplation type.
7 |
8 | It also does auto cleanup in the back, but only on modifiers & vertex groups with "SimpleLattice" in the name.
9 |
10 | How to use:
11 |
12 | 1. RMB on selected objects or elements - Create Lattice.
13 | 2. RMB on lattice object - Apply/Remove or tweak strength.
14 |
15 | Examples:
16 |
17 | 1. Object mode - multiple objects
18 |
19 | https://user-images.githubusercontent.com/87300864/129005850-5dd55a01-a4b6-4563-a1a3-bb604aecedec.mp4
20 |
21 | 2. Edit mode - multiple objects
22 |
23 | https://user-images.githubusercontent.com/87300864/129006117-9be021ac-ddcc-401c-b9ce-5fc3e12b24bc.mp4
24 |
25 | 3. Single object editing
26 |
27 | https://user-images.githubusercontent.com/87300864/129006206-5f0216a5-43be-4c3d-bb6c-3915fed2c579.mp4
28 |
29 | -----------------------------------------------------------------------------------------------------
30 |
31 | ## Update 0.1.1
32 | 1. Added new orientation - Normal. It simply create orientation from selection and align Lattice.
33 | 2. Added possibility to change Lattice resolution in RMB menu, when Lattice is selected.
34 |
35 | https://user-images.githubusercontent.com/87300864/130314258-247fdae1-cb4c-4a04-9325-b5ede65cbcb1.mp4
36 |
37 | https://user-images.githubusercontent.com/87300864/130314393-aa7842e3-978c-4d40-aa35-995bc98be90c.mp4
38 |
39 | -----------------------------------------------------------------------------------------------------
40 |
41 | ## Update 0.1.2
42 | 1. Little UI tweaks.
43 | 2. Added Addon preferences - where you can define default values for adding Lattice.
44 |
45 | 
46 | 
47 |
48 | ------------------------------------------------------------------------------------------------------
49 |
50 | ## Update 0.1.3
51 | 1. Added option "Ignore Modifiers". For cases where you need to modify only original object.
52 | 
53 | 2. Added Addon preference for "Ignore Modifiers".
54 | 
55 |
56 | ------------------------------------------------------------------------------------------------------
57 |
58 | ## Update 0.1.4
59 | 1. Fix for "Flat" surfaces (was impossible to manipulate lattice points)
60 | 2. Fix for Grease Pencil objects (can create lattice for object, but not for gpencil selection points)
61 |
62 | ------------------------------------------------------------------------------------------------------
63 |
64 | ## Update 0.1.5
65 | 1. Minor UI changes for search operator
66 |
67 | 
68 | 
69 |
70 | 2. Added menu entry to Object and Mesh
71 |
72 | 
73 | 
74 |
75 | 3. Fix for instanced object/s. Now, before applying the lattice, it makes a single user and then applies the lattice.
76 |
77 | ------------------------------------------------------------------------------------------------------
78 |
79 | ## Update 0.1.6
80 | 1. More accurate bbox calculation for MESH objects if object have custom rotation
81 | 
82 |
83 | 2. New feature to tweak angles for created lattice object
84 | 
85 |
86 | https://user-images.githubusercontent.com/87300864/229339025-baf61493-59dc-4dc4-878e-4fc9bcb01a9e.mp4
87 |
--------------------------------------------------------------------------------
/__init__.py:
--------------------------------------------------------------------------------
1 | # This program is free software; you can redistribute it and/or modify
2 | # it under the terms of the GNU General Public License as published by
3 | # the Free Software Foundation; either version 3 of the License, or
4 | # (at your option) any later version.
5 | #
6 | # This program is distributed in the hope that it will be useful, but
7 | # WITHOUT ANY WARRANTY; without even the implied warranty of
8 | # MERCHANTIBILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9 | # General Public License for more details.
10 | #
11 | # You should have received a copy of the GNU General Public License
12 | # along with this program. If not, see .
13 |
14 | import bpy
15 | from bpy.props import FloatProperty
16 | from bpy.types import PropertyGroup
17 |
18 | bl_info = {
19 | "name" : "SimpleLattice",
20 | "author" : "benjamin.sauder, Eugene Dudavkin",
21 | "version": (0, 1, 6),
22 | "blender" : (2, 93, 0),
23 | "location": "View3D",
24 | "description" : "A tool to simplify the workflow with lattice objects.",
25 | "doc_url": "https://blenderartists.org/t/simplelattice-deform-with-pleasure/1321032",
26 | "tracker_url": "https://github.com/BenjaminSauder/SimpleLattice",
27 | "category" : "Object",
28 | }
29 |
30 |
31 | from . import op_LatticeCreate
32 | from . import op_LatticeApply
33 | from . import op_LatticeRemove
34 | from . import preferences
35 |
36 |
37 | def get_u(self):
38 | lattice = bpy.context.active_object
39 | res = bpy.data.lattices[lattice.name]
40 | return res.points_u
41 |
42 | def set_u(self, value):
43 | lattice = bpy.context.active_object
44 | res = bpy.data.lattices[lattice.name]
45 | res.points_u = value
46 |
47 | def get_v(self):
48 | lattice = bpy.context.active_object
49 | res = bpy.data.lattices[lattice.name]
50 | return res.points_v
51 |
52 | def set_v(self, value):
53 | lattice = bpy.context.active_object
54 | res = bpy.data.lattices[lattice.name]
55 | res.points_v = value
56 |
57 | def get_w(self):
58 | lattice = bpy.context.active_object
59 | res = bpy.data.lattices[lattice.name]
60 | return res.points_w
61 |
62 | def set_w(self, value):
63 | lattice = bpy.context.active_object
64 | res = bpy.data.lattices[lattice.name]
65 | res.points_w = value
66 |
67 |
68 | class MODIFIERSTRENGTH_PG_main(PropertyGroup):
69 |
70 | def update_modifierstrength(self, context):
71 | lattice = context.active_object
72 | for o in bpy.data.objects:
73 | for modifier in o.modifiers:
74 | if modifier.type == 'LATTICE' and "SimpleLattice" in modifier.name:
75 | if modifier.object == lattice:
76 | modifier.strength = self.str_obj
77 |
78 | str_obj: bpy.props.FloatProperty(
79 | description = "Change strength for Lattice modifier in objects affected by lattice",
80 | name = "Strength",
81 | min = 0.0,
82 | max = 1.0,
83 | step = 1,
84 | default = 1,
85 | update = update_modifierstrength
86 | )
87 |
88 |
89 | class RESOLUTIONUVW_PG_main(PropertyGroup):
90 |
91 | change_u: bpy.props.IntProperty(
92 | min = 2,
93 | max = 20,
94 | get=get_u,
95 | set=set_u
96 | )
97 |
98 | change_v: bpy.props.IntProperty(
99 | min = 2,
100 | max = 20,
101 | get=get_v,
102 | set=set_v
103 | )
104 |
105 | change_w: bpy.props.IntProperty(
106 | min = 2,
107 | max = 20,
108 | get=get_w,
109 | set=set_w
110 | )
111 |
112 |
113 | classes = [
114 | preferences.SimpleLatticePrefs,
115 | op_LatticeCreate.Op_LatticeCreateOperator,
116 | op_LatticeApply.Op_LatticeApplyOperator,
117 | op_LatticeRemove.Op_LatticeRemoveOperator,
118 | MODIFIERSTRENGTH_PG_main,
119 | RESOLUTIONUVW_PG_main
120 | ]
121 |
122 |
123 | prepend_menus = [
124 | # removing this as it add top menu entry
125 | # bpy.types.VIEW3D_MT_edit_mesh,
126 | # bpy.types.VIEW3D_MT_object,
127 |
128 | bpy.types.VIEW3D_MT_object_context_menu,
129 |
130 | bpy.types.VIEW3D_MT_edit_mesh_context_menu,
131 |
132 | bpy.types.VIEW3D_MT_gpencil_edit_context_menu,
133 |
134 | bpy.types.VIEW3D_MT_edit_lattice_context_menu,
135 |
136 | bpy.types.VIEW3D_MT_edit_lattice,
137 | ]
138 |
139 | append_menus = [
140 | # removing this as it add bottom menu entry
141 | bpy.types.VIEW3D_MT_edit_mesh,
142 | bpy.types.VIEW3D_MT_object,
143 | ]
144 |
145 | def context_menu(self, context):
146 | #selected_objects = context.selected_objects
147 | #lattice = context.active_object
148 | layout = self.layout
149 |
150 | show_apply_op = op_LatticeApply.Op_LatticeApplyOperator.poll(context)
151 | show_remove_op = op_LatticeRemove.Op_LatticeRemoveOperator.poll(context)
152 | show_create_op = op_LatticeCreate.Op_LatticeCreateOperator.poll(context)
153 | do_show = show_apply_op or show_create_op
154 |
155 | if do_show and type(self in append_menus):
156 | layout.separator()
157 |
158 | if show_apply_op:
159 | layout.operator("object.op_lattice_apply")
160 |
161 | if show_remove_op:
162 | layout.operator("object.op_lattice_remove")
163 |
164 | if show_create_op and not show_apply_op:
165 | layout.operator("object.op_lattice_create")
166 |
167 | if do_show and type(self in prepend_menus):
168 | layout.separator()
169 |
170 | layout.separator()
171 |
172 | if (context.active_object is not None) and (context.active_object.type == 'LATTICE') \
173 | and ("SimpleLattice" in context.active_object.name) \
174 | and (context.active_object.mode == 'EDIT'):
175 | layout.label(text="Simple Lattice Resolution:")
176 | col = layout.column()
177 | sub = col.column(align=True)
178 | res = context.scene.RESOLUTIONUVW_PG_main
179 | sub.prop(res, "change_u", text=" U")
180 | sub.prop(res, "change_v", text=" V")
181 | sub.prop(res, "change_w", text=" W")
182 |
183 | layout.separator()
184 |
185 | if (context.active_object is not None) and (context.active_object.type == 'LATTICE') \
186 | and ("SimpleLattice" in context.active_object.name) \
187 | and (context.active_object.mode == 'EDIT'):
188 | props = context.scene.MODIFIERSTRENGTH_PG_main
189 | layout.prop(props, "str_obj", text=" Simple Lattice Strength")
190 |
191 | layout.separator()
192 |
193 | def object_mesh_menu(self, context):
194 | layout = self.layout
195 |
196 | show_apply_op = op_LatticeApply.Op_LatticeApplyOperator.poll(context)
197 | show_remove_op = op_LatticeRemove.Op_LatticeRemoveOperator.poll(context)
198 | show_create_op = op_LatticeCreate.Op_LatticeCreateOperator.poll(context)
199 | do_show = show_apply_op or show_create_op
200 |
201 | if do_show and type(self in append_menus):
202 | layout.separator()
203 |
204 | if show_apply_op:
205 | layout.operator("object.op_lattice_apply")
206 |
207 | if show_remove_op:
208 | layout.operator("object.op_lattice_remove")
209 |
210 | if show_create_op and not show_apply_op:
211 | layout.operator("object.op_lattice_create")
212 |
213 | # if (context.active_object is not None) and (context.active_object.type == 'LATTICE') \
214 | # and ("SimpleLattice" in context.active_object.name):
215 | # props = context.scene.MODIFIERSTRENGTH_PG_main
216 | # layout.prop(props, "str_obj", text=" Simple Lattice Strength")
217 |
218 | def register():
219 | for menu in prepend_menus:
220 | menu.prepend(context_menu)
221 |
222 | for menu in append_menus:
223 | menu.append(object_mesh_menu)
224 |
225 | for c in classes:
226 | bpy.utils.register_class(c)
227 |
228 | bpy.types.Scene.MODIFIERSTRENGTH_PG_main = bpy.props.PointerProperty(type = MODIFIERSTRENGTH_PG_main)
229 | bpy.types.Scene.RESOLUTIONUVW_PG_main = bpy.props.PointerProperty(type = RESOLUTIONUVW_PG_main)
230 |
231 | def unregister():
232 | # menus = prepend_menus
233 | # menus.extend(append_menus)
234 |
235 | # for menu in menus:
236 | # menu.remove(context_menu)
237 |
238 | for menu in prepend_menus:
239 | menu.remove(context_menu)
240 |
241 | for menu in append_menus:
242 | menu.remove(object_mesh_menu)
243 |
244 | for c in classes:
245 | bpy.utils.unregister_class(c)
246 |
247 | del bpy.types.Scene.MODIFIERSTRENGTH_PG_main
248 | del bpy.types.Scene.RESOLUTIONUVW_PG_main
249 |
250 | if __name__ == "__main__":
251 | register()
252 |
--------------------------------------------------------------------------------
/op_LatticeRemove.py:
--------------------------------------------------------------------------------
1 | #Version 0.1.6
2 |
3 | import bpy
4 |
5 | from . import util
6 |
7 |
8 | class Op_LatticeRemoveOperator(bpy.types.Operator):
9 | bl_idname = "object.op_lattice_remove"
10 | bl_label = "Simple Lattice Remove"
11 | bl_description = "Remove the lattice for all objects whose FFD modifiers are targeting it"
12 | bl_space_type = "VIEW_3D"
13 | bl_region_type = "TOOLS"
14 | bl_options = {"REGISTER", "UNDO"}
15 |
16 | def execute(self, context):
17 | lattice = context.active_object
18 |
19 | if lattice.mode == "EDIT":
20 | bpy.ops.object.editmode_toggle()
21 |
22 | vertex_groups = []
23 |
24 | for obj in context.view_layer.objects:
25 | if obj.type in util.allowed_object_types:
26 | vertex_groups.clear()
27 |
28 | if obj.type == "MESH" or obj.type == "CURVE" or obj.type == "SURFACE" or obj.type == "FONT":
29 | for modifier in obj.modifiers:
30 | if modifier.type == 'LATTICE' and "SimpleLattice" in modifier.name:
31 | if modifier.object == lattice:
32 | vertex_group = self.kill_lattice_modifer(context, modifier, lattice)
33 | if vertex_group:
34 | vertex_groups.append(vertex_group)
35 |
36 | # Clear any selection
37 | for f in obj.data.polygons:
38 | f.select = False
39 | for e in obj.data.edges:
40 | e.select = False
41 | for v in obj.data.vertices:
42 | v.select = False
43 | # Get verts in vertex group
44 | verts = [v for v in obj.data.vertices if obj.vertex_groups[vertex_group].index in [i.group for i in v.groups]]
45 | # Select verts in vertex group
46 | for v in verts:
47 | v.select = True
48 |
49 | # if apply with vertex groups
50 | # then select all objects and switch to EDIT mode
51 | obj.select_set(True)
52 | bpy.ops.object.editmode_toggle()
53 | bpy.ops.mesh.select_mode(type="VERT")
54 |
55 | if not vertex_group:
56 | # if apply without vertex groups
57 | # then select all objects and stay in OBJECT mode
58 | obj.select_set(True)
59 |
60 | if obj.type == "GPENCIL":
61 | for modifier in obj.grease_pencil_modifiers:
62 | if modifier.type == 'GP_LATTICE' and "SimpleLattice" in modifier.name:
63 | if modifier.object == lattice:
64 | # checking for lattice on top of the grease_pencil_modifiers stack (for any reason)
65 | # https://blender.stackexchange.com/questions/233357/how-to-get-modifier-position
66 | if obj.grease_pencil_modifiers[0].type == "GP_LATTICE" and obj.grease_pencil_modifiers[0].object == lattice:
67 | self.report({'INFO'}, 'Modifier applied')
68 | else:
69 | self.report({'INFO'}, 'Applied modifier was not first, result may not be as expected')
70 |
71 | vertex_group = self.kill_lattice_gpencil_modifer(context, modifier, lattice)
72 | ''' NOT IMPLEMENTED IN API YET
73 | if vertex_group:
74 | vertex_groups.append(vertex_group)
75 |
76 | # Clear any selection
77 | for layer in obj.data.layers:
78 | for frame in layer.frames:
79 | for stroke in frame.strokes:
80 | for point in stroke.points:
81 | point.select = False
82 |
83 | # Get points in vertex group
84 | all_points = []
85 | for layer in obj.data.layers:
86 | for frame in layer.frames:
87 | for stroke in frame.strokes:
88 | for point in stroke.points:
89 | all_points.append(point)
90 | points = [v for v in all_points if obj.vertex_groups[vertex_group].index in [i.group for i in v.groups]]
91 | # Select points in vertex group
92 | for point in points:
93 | point.select = True
94 |
95 | # if apply with vertex groups
96 | # then select all objects and switch to EDIT mode
97 | obj.select_set(True)
98 | bpy.ops.object.editmode_toggle()
99 | bpy.ops.mesh.select_mode(type="VERT")
100 | '''
101 |
102 | if not vertex_group:
103 | # if apply without vertex groups
104 | # then select all objects and stay in OBJECT mode
105 | obj.select_set(True)
106 |
107 | self.kill_vertex_groups(obj, vertex_groups)
108 |
109 | # try:
110 | # self.kill_custom_orientation()
111 | # except:
112 | # pass
113 |
114 | # removing Lattice object with its data
115 | # https://blender.stackexchange.com/questions/233204/how-can-i-purge-recently-deleted-objects
116 | lattice_obs = [o for o in context.selected_objects if o.type == 'LATTICE']
117 | purge_data = set(o.data for o in lattice_obs)
118 | bpy.data.batch_remove(lattice_obs)
119 | bpy.data.batch_remove([o for o in purge_data if not o.users])
120 | self.report({'INFO'}, 'Lattice was removed')
121 |
122 | context.view_layer.update()
123 | return {'FINISHED'}
124 |
125 | @classmethod
126 | def poll(self, context):
127 | return (len(context.selected_objects) == 1 and
128 | context.active_object and
129 | context.active_object.type == 'LATTICE' and
130 | context.active_object.select_get())
131 |
132 | def set_active(self, context, object):
133 | context.view_layer.objects.active = object
134 |
135 | def kill_lattice_modifer(self, context, modifier, target):
136 | vertex_group = ""
137 |
138 | if modifier.type != "LATTICE" or modifier.object != target:
139 | return vertex_group
140 |
141 | if context.active_object != modifier.id_data:
142 | self.set_active(context, modifier.id_data)
143 |
144 | if modifier.vertex_group != None:
145 | vertex_group = modifier.vertex_group
146 |
147 | if modifier.show_viewport:
148 |
149 | if modifier.id_data.mode != 'OBJECT':
150 | bpy.ops.object.editmode_toggle()
151 |
152 | bpy.ops.object.modifier_remove(modifier=modifier.name)
153 |
154 | return vertex_group
155 |
156 | def kill_lattice_gpencil_modifer(self, context, modifier, target):
157 | vertex_group = ""
158 |
159 | if modifier.type != "GP_LATTICE" or modifier.object != target:
160 | return vertex_group
161 |
162 | if context.active_object != modifier.id_data:
163 | self.set_active(context, modifier.id_data)
164 |
165 | if modifier.vertex_group != None:
166 | vertex_group = modifier.vertex_group
167 |
168 | if modifier.show_viewport:
169 |
170 | if modifier.id_data.mode != 'OBJECT':
171 | bpy.ops.object.editmode_toggle()
172 |
173 | bpy.ops.object.gpencil_modifier_remove(modifier=modifier.name)
174 |
175 | return vertex_group
176 |
177 | def kill_vertex_groups(self, obj, vertex_groups):
178 | if len(vertex_groups) == 0:
179 | return
180 |
181 | modifiers = filter(lambda modifier: hasattr(modifier, "vertex_group")
182 | and modifier.vertex_group, obj.modifiers)
183 | used_vertex_groups = set(
184 | map(lambda modifier: modifier.vertex_group, modifiers))
185 |
186 | obsolete = filter(
187 | lambda group: group not in used_vertex_groups, vertex_groups)
188 |
189 | for group in obsolete:
190 | print(f"removed vertex_group: {group}")
191 | vg = obj.vertex_groups.get(group)
192 | obj.vertex_groups.remove(vg)
193 |
194 | # def kill_custom_orientation(self):
195 | # orig_transform = bpy.context.scene.transform_orientation_slots[0].type
196 | # bpy.context.scene.transform_orientation_slots[0].type = 'SimpleLattice_Orientation'
197 | # bpy.ops.transform.delete_orientation()
198 | # bpy.data.scenes[0].transform_orientation_slots[0].type = orig_transform
199 |
--------------------------------------------------------------------------------
/op_LatticeApply.py:
--------------------------------------------------------------------------------
1 | #Version 0.1.6
2 |
3 | import bpy
4 |
5 | from . import util
6 |
7 |
8 | class Op_LatticeApplyOperator(bpy.types.Operator):
9 | bl_idname = "object.op_lattice_apply"
10 | bl_label = "Simple Lattice Apply"
11 | bl_description = "Applies the lattice to all objects whose FFD modifiers are targeting it"
12 | bl_space_type = "VIEW_3D"
13 | bl_region_type = "TOOLS"
14 | bl_options = {"REGISTER", "UNDO"}
15 |
16 | def execute(self, context):
17 | lattice = context.active_object
18 |
19 | if lattice.mode == "EDIT":
20 | bpy.ops.object.editmode_toggle()
21 |
22 | vertex_groups = []
23 |
24 | for obj in context.view_layer.objects:
25 | if obj.type in util.allowed_object_types:
26 | vertex_groups.clear()
27 |
28 | if obj.type == "MESH" or obj.type == "CURVE" or obj.type == "SURFACE":
29 | for modifier in obj.modifiers:
30 | if modifier.type == 'LATTICE' and "SimpleLattice" in modifier.name:
31 | if modifier.object == lattice:
32 | # checking for lattice on top of the modifiers stack (for any reason)
33 | # https://blender.stackexchange.com/questions/233357/how-to-get-modifier-position
34 | if obj.modifiers[0].type == "LATTICE" and obj.modifiers[0].object == lattice:
35 | self.report({'INFO'}, 'Modifier applied')
36 | else:
37 | self.report({'INFO'}, 'Applied modifier was not first, result may not be as expected')
38 |
39 | vertex_group = self.kill_lattice_modifer(context, modifier, lattice)
40 | if vertex_group:
41 | vertex_groups.append(vertex_group)
42 |
43 | # Clear any selection
44 | for f in obj.data.polygons:
45 | f.select = False
46 | for e in obj.data.edges:
47 | e.select = False
48 | for v in obj.data.vertices:
49 | v.select = False
50 | # Get verts in vertex group
51 | verts = [v for v in obj.data.vertices if obj.vertex_groups[vertex_group].index in [i.group for i in v.groups]]
52 | # Select verts in vertex group
53 | for v in verts:
54 | v.select = True
55 |
56 | # if apply with vertex groups
57 | # then select all objects and switch to EDIT mode
58 | obj.select_set(True)
59 | bpy.ops.object.editmode_toggle()
60 | bpy.ops.mesh.select_mode(type="VERT")
61 |
62 | if not vertex_group:
63 | # if apply without vertex groups
64 | # then select all objects and stay in OBJECT mode
65 | obj.select_set(True)
66 |
67 | if obj.type == "GPENCIL":
68 | for modifier in obj.grease_pencil_modifiers:
69 | if modifier.type == 'GP_LATTICE' and "SimpleLattice" in modifier.name:
70 | if modifier.object == lattice:
71 | # checking for lattice on top of the grease_pencil_modifiers stack (for any reason)
72 | # https://blender.stackexchange.com/questions/233357/how-to-get-modifier-position
73 | if obj.grease_pencil_modifiers[0].type == "GP_LATTICE" and obj.grease_pencil_modifiers[0].object == lattice:
74 | self.report({'INFO'}, 'Modifier applied')
75 | else:
76 | self.report({'INFO'}, 'Applied modifier was not first, result may not be as expected')
77 |
78 | vertex_group = self.kill_lattice_gpencil_modifer(context, modifier, lattice)
79 | ''' NOT IMPLEMENTED IN API YET
80 | if vertex_group:
81 | vertex_groups.append(vertex_group)
82 |
83 | # Clear any selection
84 | for layer in obj.data.layers:
85 | for frame in layer.frames:
86 | for stroke in frame.strokes:
87 | for point in stroke.points:
88 | point.select = False
89 |
90 | # Get points in vertex group
91 | all_points = []
92 | for layer in obj.data.layers:
93 | for frame in layer.frames:
94 | for stroke in frame.strokes:
95 | for point in stroke.points:
96 | all_points.append(point)
97 | points = [v for v in all_points if obj.vertex_groups[vertex_group].index in [i.group for i in v.groups]]
98 | # Select points in vertex group
99 | for point in points:
100 | point.select = True
101 |
102 | # if apply with vertex groups
103 | # then select all objects and switch to EDIT mode
104 | obj.select_set(True)
105 | bpy.ops.object.editmode_toggle()
106 | bpy.ops.mesh.select_mode(type="VERT")
107 | '''
108 |
109 | if not vertex_group:
110 | # if apply without vertex groups
111 | # then select all objects and stay in OBJECT mode
112 | obj.select_set(True)
113 |
114 | if obj.type == "FONT":
115 | for modifier in obj.modifiers:
116 | if modifier.type == 'LATTICE' and "SimpleLattice" in modifier.name:
117 | if modifier.object == lattice:
118 | # checking for lattice on top of the modifiers stack (for any reason)
119 | # https://blender.stackexchange.com/questions/233357/how-to-get-modifier-position
120 | if obj.modifiers[0].type == "LATTICE" and obj.modifiers[0].object == lattice:
121 | self.report({'INFO'}, 'Modifier applied')
122 | else:
123 | self.report({'INFO'}, 'Applied modifier was not first, result may not be as expected')
124 |
125 | vertex_group = self.kill_lattice_font_modifer(context, modifier, lattice)
126 |
127 | self.kill_vertex_groups(obj, vertex_groups)
128 |
129 | # try:
130 | # self.kill_custom_orientation()
131 | # except:
132 | # pass
133 |
134 | # removing Lattice object with its data
135 | # https://blender.stackexchange.com/questions/233204/how-can-i-purge-recently-deleted-objects
136 | lattice_obs = [o for o in context.selected_objects if o.type == 'LATTICE']
137 | purge_data = set(o.data for o in lattice_obs)
138 | bpy.data.batch_remove(lattice_obs)
139 | bpy.data.batch_remove([o for o in purge_data if not o.users])
140 | #self.report({'INFO'}, 'Applied modifier was not first, result may not be as expected')
141 |
142 | context.view_layer.update()
143 | return {'FINISHED'}
144 |
145 | @classmethod
146 | def poll(self, context):
147 | return (len(context.selected_objects) == 1 and
148 | context.active_object and
149 | context.active_object.type == 'LATTICE' and
150 | context.active_object.select_get())
151 |
152 | def set_active(self, context, object):
153 | context.view_layer.objects.active = object
154 |
155 | def kill_lattice_modifer(self, context, modifier, target):
156 | vertex_group = ""
157 |
158 | if modifier.type != "LATTICE" or modifier.object != target:
159 | return vertex_group
160 |
161 | if context.active_object != modifier.id_data:
162 | self.set_active(context, modifier.id_data)
163 |
164 | if modifier.vertex_group != None:
165 | vertex_group = modifier.vertex_group
166 |
167 | if modifier.show_viewport:
168 |
169 | if modifier.id_data.mode != 'OBJECT':
170 | bpy.ops.object.editmode_toggle()
171 |
172 | try:
173 | bpy.ops.object.modifier_apply(modifier=modifier.name)
174 | except:
175 | self.report({'WARNING'}, 'Modifier applied to multi-user data. Creating single-user and applying.')
176 | bpy.ops.object.modifier_apply(modifier=modifier.name, single_user=True)
177 |
178 | else:
179 | bpy.ops.object.modifier_remove(modifier=modifier.name)
180 |
181 | return vertex_group
182 |
183 | def kill_lattice_gpencil_modifer(self, context, modifier, target):
184 | vertex_group = ""
185 |
186 | if modifier.type != "GP_LATTICE" or modifier.object != target:
187 | return vertex_group
188 |
189 | if context.active_object != modifier.id_data:
190 | self.set_active(context, modifier.id_data)
191 |
192 | if modifier.vertex_group != None:
193 | vertex_group = modifier.vertex_group
194 |
195 | if modifier.show_viewport:
196 |
197 | if modifier.id_data.mode != 'OBJECT':
198 | bpy.ops.object.editmode_toggle()
199 |
200 | try:
201 | bpy.ops.object.gpencil_modifier_apply(modifier=modifier.name)
202 | except:
203 | self.report({'WARNING'}, 'Modifier applied to multi-user data. Creating single-user and applying.')
204 | #all this for only one unimplemented yet single_user for bpy.ops.object.gpencil_modifier_apply(modifier=modifier.name, single_user=True)
205 | bpy.context.view_layer.objects.active.name = modifier.name
206 | bpy.context.view_layer.objects.active.select_set(True)
207 | bpy.ops.object.make_single_user(object=True, obdata=True, material=False, animation=False, obdata_animation=False)
208 | bpy.ops.object.gpencil_modifier_apply(modifier=modifier.name)
209 | #=======================================================================================================================================
210 | #bpy.ops.object.gpencil_modifier_apply(modifier=modifier.name, single_user=True)
211 |
212 | else:
213 | bpy.ops.object.gpencil_modifier_remove(modifier=modifier.name)
214 |
215 | return vertex_group
216 |
217 | def kill_lattice_font_modifer(self, context, modifier, target):
218 | vertex_group = ""
219 |
220 | if modifier.type != "LATTICE" or modifier.object != target:
221 | return vertex_group
222 |
223 | if context.active_object != modifier.id_data:
224 | self.set_active(context, modifier.id_data)
225 |
226 | if modifier.vertex_group != None:
227 | vertex_group = modifier.vertex_group
228 |
229 | if modifier.show_viewport:
230 |
231 | if modifier.id_data.mode != 'OBJECT':
232 | bpy.ops.object.editmode_toggle()
233 |
234 | self.report({'WARNING'}, "Can't apply lattice for FONT object. Converting to MESH and applying.")
235 | #all this for only one unimplemented yet single_user for bpy.ops.object.gpencil_modifier_apply(modifier=modifier.name, single_user=True)
236 | bpy.context.view_layer.objects.active.name = modifier.name
237 | bpy.context.view_layer.objects.active.select_set(True)
238 | bpy.ops.object.convert(target='MESH')
239 | bpy.ops.object.modifier_apply(modifier=modifier.name)
240 |
241 | else:
242 | bpy.ops.object.modifier_remove(modifier=modifier.name)
243 |
244 | return vertex_group
245 |
246 | def kill_vertex_groups(self, obj, vertex_groups):
247 | if len(vertex_groups) == 0:
248 | return
249 |
250 | modifiers = filter(lambda modifier: hasattr(modifier, "vertex_group")
251 | and modifier.vertex_group, obj.modifiers)
252 | used_vertex_groups = set(
253 | map(lambda modifier: modifier.vertex_group, modifiers))
254 |
255 | obsolete = filter(
256 | lambda group: group not in used_vertex_groups, vertex_groups)
257 |
258 | for group in obsolete:
259 | print(f"removed vertex_group: {group}")
260 | vg = obj.vertex_groups.get(group)
261 | obj.vertex_groups.remove(vg)
262 |
263 | # def kill_custom_orientation(self):
264 | # orig_transform = bpy.context.scene.transform_orientation_slots[0].type
265 | # bpy.context.scene.transform_orientation_slots[0].type = 'SimpleLattice_Orientation'
266 | # bpy.ops.transform.delete_orientation()
267 | # bpy.data.scenes[0].transform_orientation_slots[0].type = orig_transform
268 |
--------------------------------------------------------------------------------
/op_LatticeCreate.py:
--------------------------------------------------------------------------------
1 | #Version 0.1.6
2 |
3 | import bpy
4 | from mathutils import Vector, Matrix, Quaternion, Euler
5 |
6 | from . import util
7 |
8 |
9 | # Recursivly transverse layer_collection for a particular name
10 | def recurLayerCollection(layerColl, collName):
11 | found = None
12 | if (layerColl.name == collName):
13 | return layerColl
14 | for layer in layerColl.children:
15 | found = recurLayerCollection(layer, collName)
16 | if found:
17 | return found
18 |
19 | class Op_LatticeCreateOperator(bpy.types.Operator):
20 | bl_idname = "object.op_lattice_create"
21 | bl_label = "Simple Lattice Create"
22 | bl_description = "Creates and binds a lattice object to the current selection."
23 | bl_space_type = "VIEW_3D"
24 | bl_region_type = "TOOLS"
25 | bl_options = {"REGISTER", "UNDO"}
26 |
27 |
28 | init = False
29 |
30 | # presets = (('2', '2x2x2', ''),
31 | # ('3', '3x3x3', ''),
32 | # ('4', '4x4x4', ''))
33 |
34 | # preset: bpy.props.EnumProperty(name="Presets", items=presets, default='2')
35 | orientation_types = (('GLOBAL', 'Global', ''),
36 | ('LOCAL', 'Local', ''),
37 | ('CURSOR', 'Cursor', ''),
38 | ('NORMAL', 'Normal', ''))
39 |
40 | # position_types = (('on_top','On Top',''),
41 | # ('bottom','Bottom',''))
42 |
43 | interpolation_types = (('KEY_LINEAR', 'Linear', ''),
44 | ('KEY_CARDINAL', 'Cardinal', ''),
45 | ('KEY_CATMULL_ROM', 'Catmull-Rom', ''),
46 | ('KEY_BSPLINE', 'BSpline', ''))
47 |
48 | orientation: bpy.props.EnumProperty(
49 | name="Orientation",
50 | items=orientation_types,
51 | default='NORMAL'
52 | )
53 |
54 | ignore_mods: bpy.props.BoolProperty (
55 | name="Ignore Modifiers",
56 | default = False,
57 | description="Ignore Modifiers to calculate BBOX for lattice"
58 | )
59 |
60 | # modifier_position: bpy.props.EnumProperty (
61 | # name="Modifier",
62 | # items=position_types,
63 | # default="bottom",
64 | # description="Move modifier on top or bottom in the stack"
65 | # )
66 |
67 | resolution_u: bpy.props.IntProperty(
68 | name="u",
69 | default=2,
70 | min=2
71 | )
72 |
73 | resolution_v: bpy.props.IntProperty(
74 | name="v",
75 | default=2,
76 | min=2
77 | )
78 |
79 | resolution_w: bpy.props.IntProperty(
80 | name="w",
81 | default=2,
82 | min=2
83 | )
84 |
85 | interpolation: bpy.props.EnumProperty(
86 | name="Interpolation",
87 | items=interpolation_types,
88 | default='KEY_LINEAR'
89 | )
90 |
91 | scale: bpy.props.FloatProperty(
92 | name="Scale",
93 | default=1.0,
94 | min=0.001,
95 | soft_min=0.1,
96 | soft_max=2.0
97 | )
98 |
99 | tweak_angles: bpy.props.BoolProperty(
100 | name="Tweak Angles",
101 | description="Tweak created lattice angles",
102 | default=False,
103 | options={'SKIP_SAVE'}
104 | )
105 |
106 | rot_x: bpy.props.FloatProperty(
107 | name="X",
108 | subtype='ANGLE',
109 | default=0.0,
110 | step=100.0,
111 | precision=4,
112 | options={'SKIP_SAVE'}
113 | )
114 |
115 | rot_y: bpy.props.FloatProperty(
116 | name="Y",
117 | subtype='ANGLE',
118 | default=0.0,
119 | step=100.0,
120 | precision=4,
121 | options={'SKIP_SAVE'}
122 | )
123 |
124 | rot_z: bpy.props.FloatProperty(
125 | name="Z",
126 | subtype='ANGLE',
127 | default=0.0,
128 | step=100.0,
129 | precision=4,
130 | options={'SKIP_SAVE'}
131 | )
132 |
133 | def draw(self, context):
134 | layout = self.layout
135 | layout.use_property_split = True
136 |
137 | col = layout.column()
138 | sub = col.row()
139 | sub.prop(self, "orientation")
140 |
141 | # col.separator()
142 | # sub = col.row()
143 | # sub.prop(self, "modifier_position", expand=True)
144 |
145 | col.separator()
146 | sub = col.row()
147 | sub.prop(self, "ignore_mods")
148 |
149 | col.separator()
150 | sub = col.row()
151 | sub2 = sub.column(align=True)
152 | sub2.prop(self, "resolution_u", text="Resolution U")
153 | sub2.prop(self, "resolution_v", text="V")
154 | sub2.prop(self, "resolution_w", text="W")
155 |
156 | col.separator()
157 | sub = col.row()
158 | sub.prop(self, "interpolation")
159 |
160 | col.separator()
161 | sub = col.row()
162 | sub.prop(self, "scale")
163 |
164 | col.separator()
165 | sub = col.row()
166 | sub.prop(self, "tweak_angles")
167 | sub = col.row()
168 | if self.tweak_angles:
169 | sub2 = sub.box().column(align=True)
170 | #sub2.enabled = False
171 | sub2.prop(self, "rot_x", text="Rotation X")
172 | sub2.prop(self, "rot_y")
173 | sub2.prop(self, "rot_z")
174 |
175 | @classmethod
176 | def poll(self, context):
177 | if (context.active_object is not None and
178 | context.active_object.type in util.allowed_object_types and
179 | context.active_object.mode == 'EDIT'):
180 | return True
181 |
182 | has_selection = len(context.selected_objects) != 0
183 | if has_selection:
184 | for obj in context.selected_objects:
185 | if obj.type in util.allowed_object_types:
186 | return True
187 |
188 | return False
189 |
190 | def execute(self, context):
191 | # if add lattice in Edit mode,
192 | # preventing undo objects data if settings in "Adjust last action" panel was changed
193 | self.for_edit_mode(context)
194 |
195 | # Defaults from Addon preferences
196 | if not Op_LatticeCreateOperator.init:
197 | prefs = bpy.context.preferences.addons[__package__].preferences
198 |
199 | self.orientation = prefs.default_orientation
200 | # self.modifier_position = prefs.default_position
201 | self.ignore_mods = prefs.default_ignore_mods
202 | self.resolution_u = prefs.default_resolution_u
203 | self.resolution_v = prefs.default_resolution_v
204 | self.resolution_w = prefs.default_resolution_w
205 | self.interpolation = prefs.default_interpolation
206 | self.scale = prefs.default_scale
207 |
208 | Op_LatticeCreateOperator.init = True
209 |
210 | objects = []
211 | all_objecst_are_meshes = True
212 |
213 | for obj in context.selected_objects:
214 | if obj.type in util.allowed_object_types:
215 | objects.append(obj)
216 |
217 | if all_objecst_are_meshes and obj.type != 'MESH':
218 | all_objecst_are_meshes = False
219 |
220 | # for the shitty case when the active object is in edit mode,
221 | # but is not selected..
222 | if len(objects) == 0:
223 | objects.append(context.active_object)
224 |
225 | self.vertex_mode = all_objecst_are_meshes and objects[0].mode == 'EDIT'
226 | # or objects[0].mode == 'EDIT_GPENCIL'
227 |
228 | if len(objects) > 0:
229 | #self.mapping = None
230 | self.group_mapping = None
231 | self.vert_mapping = None
232 | #self.object_names = list(map(lambda x: x.name, objects))
233 |
234 | self.cleanup(objects)
235 |
236 | #---------
237 | # modifiers_not_visible = []
238 | # for obj in objects:
239 | # for modifier in obj.modifiers:
240 | # if modifier.show_viewport == False:
241 | # modifiers_not_visible.append(modifier)
242 | # print("Modifiers hidden = ", modifier.name)
243 | # if self.ignore_mods == True:
244 | # modifier.show_viewport = False
245 | # if context.mode == 'OBJECT':
246 | # context.view_layer.update()
247 | #---------
248 |
249 | if self.vertex_mode:
250 | self.coords, self.vert_mapping = self.get_coords_from_verts(objects)
251 |
252 | if len(self.coords) == 0:
253 | bpy.ops.object.mode_set(mode='EDIT')
254 | self.report({'INFO'}, 'Need to be at least 1 vertex selected')
255 | return {'CANCELLED'}
256 |
257 | self.group_mapping = self.set_vertex_group(objects, self.vert_mapping)
258 |
259 | else:
260 | self.coords = self.get_coords_from_objects(objects)
261 |
262 | lattice = self.createLattice(context)
263 | #self.lattice = lattice
264 | #self.lattice_name = lattice.name
265 |
266 | self.matrix = context.active_object.matrix_world.copy()
267 |
268 | self.update_lattice_from_bbox(context, lattice, self.coords, self.matrix)
269 |
270 | self.add_ffd_modifier(objects, lattice, self.group_mapping)
271 |
272 | self.set_selection(context, lattice, objects)
273 |
274 | context.view_layer.update()
275 |
276 | #---------
277 | # for obj in objects:
278 | # for modifier in obj.modifiers:
279 | # modifier.show_viewport = True
280 | # for modifier in modifiers_not_visible:
281 | # modifier.show_viewport = False
282 | #---------
283 |
284 | return {'FINISHED'}
285 | else:
286 | return {'CANCELLED'}
287 |
288 | def set_selection(self, context, lattice, other):
289 | bpy.ops.object.mode_set(mode='OBJECT')
290 | bpy.ops.object.select_all(action='DESELECT')
291 |
292 | lattice.select_set(True)
293 | context.view_layer.objects.active = lattice
294 | bpy.ops.object.editmode_toggle()
295 |
296 | def get_coords_from_verts(self, objects):
297 | worldspace_verts = []
298 | vert_mapping = {}
299 |
300 | for obj in objects:
301 | vert_indices = []
302 |
303 | if obj.type == "MESH":
304 | bpy.ops.object.editmode_toggle()
305 | vertices = obj.data.vertices
306 |
307 | for vert in vertices:
308 | if vert.select == True:
309 | index = vert.index
310 | vert_indices.append(index)
311 | worldspace_verts.append(obj.matrix_world @ vert.co)
312 |
313 | #==================================
314 | '''
315 | https://blender.stackexchange.com/questions/155844/how-can-i-calculate-global-coordinates-for-gpencilstrokepoint-in-blender-2-8-and
316 |
317 | NOT IMPLEMENTED YET IN BLENDER API
318 | https://blender.stackexchange.com/questions/282126/create-vertex-group-for-selected-points-in-grease-pencil-object
319 | '''
320 | if obj.type == "GPENCIL":
321 | vertices = []
322 | for layer in obj.data.layers:
323 | for frame in layer.frames:
324 | for stroke in frame.strokes:
325 | for point in stroke.points:
326 | vertices.append(point)
327 |
328 | for i, vert in enumerate(vertices):
329 | if vert.select == True:
330 | vert_indices.append(i)
331 | #==================================
332 |
333 | vert_mapping[obj.name] = vert_indices
334 |
335 | return worldspace_verts, vert_mapping
336 |
337 | def get_coords_from_objects(self, objects):
338 | # exeption if create lattice for GPENCIL in edit mode
339 | if objects[0].mode == 'EDIT_GPENCIL':
340 | self.report({'WARNING'}, 'Lattice for GPENCIL points not supported yet in Blender API. Switching to object mode.')
341 | bpy.ops.object.mode_set(mode='OBJECT')
342 |
343 | bbox_world_coords = []
344 | for obj in objects:
345 | if obj.type == 'MESH' and self.ignore_mods == True:
346 | vertices = obj.data.vertices
347 | for vert in vertices:
348 | bbox_world_coords.append(obj.matrix_world @ vert.co)
349 | else:
350 | coords = obj.bound_box[:]
351 | coords = [(obj.matrix_world @ Vector(p[:])).to_tuple() for p in coords]
352 | bbox_world_coords.extend(coords)
353 |
354 | return bbox_world_coords
355 |
356 | def update_lattice_from_bbox(self, context, lattice, bbox_world_coords, matrix_world):
357 | if self.orientation == 'GLOBAL':
358 | rotation = Matrix.Identity(4)
359 | # bbox = util.bounds(bbox_world_coords)
360 | bpy.context.scene.transform_orientation_slots[0].type = 'GLOBAL'
361 |
362 | elif self.orientation == 'NORMAL':
363 | try:
364 | orig_transform = bpy.context.scene.transform_orientation_slots[0].type
365 | bpy.context.scene.transform_orientation_slots[0].type = 'SimpleLattice_Orientation'
366 | co = bpy.context.scene.transform_orientation_slots[0].custom_orientation
367 | # bpy.ops.transform.delete_orientation()
368 | bpy.data.scenes[0].transform_orientation_slots[0].type = orig_transform
369 |
370 | rotation = co.matrix.to_quaternion().to_matrix().to_4x4()
371 | except:
372 | rotation = matrix_world.to_quaternion().to_matrix().to_4x4()
373 |
374 | # bbox = util.bounds(bbox_world_coords, rotation.inverted())
375 | bpy.context.scene.transform_orientation_slots[0].type = 'LOCAL'
376 |
377 | elif self.orientation == 'LOCAL':
378 | rotation = matrix_world.to_quaternion().to_matrix().to_4x4()
379 | # bbox = util.bounds(bbox_world_coords, rotation.inverted())
380 | bpy.context.scene.transform_orientation_slots[0].type = 'LOCAL'
381 |
382 | elif self.orientation == 'CURSOR':
383 | mode = context.scene.cursor.rotation_mode
384 | if mode == "QUATERNION":
385 | rotation = context.scene.cursor.rotation_quaternion.to_matrix().to_4x4()
386 | elif mode == "AXIS_ANGLE":
387 | axis_angle = context.scene.cursor.rotation_axis_angle
388 | rotation = Quaternion(axis_angle[1:], axis_angle[0])
389 | rotation = rotation.to_matrix().to_4x4()
390 | else:
391 | rotation = context.scene.cursor.rotation_euler.to_matrix().to_4x4()
392 |
393 | # bbox = util.bounds(bbox_world_coords, rotation.inverted())
394 | bpy.context.scene.transform_orientation_slots[0].type = 'CURSOR'
395 |
396 | # new rot angles
397 | if not self.tweak_angles:
398 | rot_x = 0
399 | rot_y = 0
400 | rot_z = 0
401 |
402 | if self.tweak_angles:
403 | rot_x = self.rot_x
404 | rot_y = self.rot_y
405 | rot_z = self.rot_z
406 |
407 | rot_new = Euler((rot_x, rot_y, rot_z)).to_matrix()
408 |
409 | rotation = rotation @ rot_new.to_4x4()
410 | bbox = util.bounds(bbox_world_coords, rotation.inverted())
411 |
412 | # removing custom orientation
413 | try:
414 | orig_transform = bpy.context.scene.transform_orientation_slots[0].type
415 | bpy.context.scene.transform_orientation_slots[0].type = 'SimpleLattice_Orientation'
416 | bpy.ops.transform.delete_orientation()
417 | bpy.data.scenes[0].transform_orientation_slots[0].type = orig_transform
418 | except: pass
419 |
420 | # calc lattice center
421 | bound_min = Vector((bbox.x.min, bbox.y.min, bbox.z.min))
422 | bound_max = Vector((bbox.x.max, bbox.y.max, bbox.z.max))
423 | offset = (bound_min + bound_max) * 0.5
424 |
425 | # finally gather position/rotation/scaling for the lattice
426 | location = rotation @ offset
427 | scale = Vector((abs(bound_max.x - bound_min.x),
428 | abs(bound_max.y - bound_min.y),
429 | abs(bound_max.z - bound_min.z)))
430 |
431 | self.updateLattice(lattice, location, rotation, scale)
432 |
433 | def createLattice(self, context):
434 | object_active = bpy.context.view_layer.objects.active
435 | lattice_data = bpy.data.lattices.new(object_active.name + '_SimpleLattice')
436 | lattice_obj = bpy.data.objects.new(object_active.name + '_SimpleLattice', lattice_data)
437 |
438 | # create Lattice in the collection with the active selected object
439 | obj = bpy.context.object
440 | ucol = obj.users_collection
441 | try:
442 | for i in ucol:
443 | layer_collection = bpy.context.view_layer.layer_collection
444 | layerColl = recurLayerCollection(layer_collection, i.name)
445 | bpy.data.collections[layerColl.name].objects.link(lattice_obj)
446 | except:
447 | context.scene.collection.objects.link(lattice_obj)
448 |
449 | return lattice_obj
450 |
451 | def updateLattice(self, lattice, location, rotation, scale):
452 | lattice.data.points_u = self.resolution_u
453 | lattice.data.points_v = self.resolution_v
454 | lattice.data.points_w = self.resolution_w
455 |
456 | lattice.data.interpolation_type_u = self.interpolation
457 | lattice.data.interpolation_type_v = self.interpolation
458 | lattice.data.interpolation_type_w = self.interpolation
459 |
460 | lattice.location = location
461 | lattice.rotation_euler = rotation.to_euler()
462 |
463 | #fix for flat selection or surface
464 | if scale.x == 0:
465 | scale.x=scale.x+0.0001
466 | if scale.y == 0:
467 | scale.y=scale.y+0.0001
468 | if scale.z == 0:
469 | scale.z=scale.z+0.0001
470 | #=================================
471 |
472 | lattice.scale = Vector((scale.x * self.scale,
473 | scale.y * self.scale,
474 | scale.z * self.scale))
475 |
476 | def add_ffd_modifier(self, objects, lattice, group_mapping):
477 | for obj in objects:
478 | if obj.type == "MESH" or obj.type == "CURVE" or obj.type == "SURFACE" or obj.type == "FONT":
479 | ffd = obj.modifiers.new("SimpleLattice", "LATTICE")
480 |
481 | # good to see modified vertices if add more than one Lattice to the mesh/es
482 | obj.modifiers[ffd.name].show_in_editmode = True
483 | obj.modifiers[ffd.name].show_on_cage = True
484 |
485 | if obj.type == "GPENCIL":
486 | ffd = obj.grease_pencil_modifiers.new("SimpleLattice", "GP_LATTICE")
487 | obj.grease_pencil_modifiers[ffd.name].show_in_editmode = True
488 |
489 | # Move Lattice modifier to the top of modifiers stack (if needed)
490 | # https://blender.stackexchange.com/questions/223134/adding-a-modifier-to-the-top-of-the-stack-of-multiple-objects-without-overwritin
491 | # if self.modifier_position == 'on_top':
492 | # obj.select_set(True)
493 | # bpy.context.view_layer.objects.active = obj
494 | # bpy.ops.object.modifier_move_to_index(modifier=ffd.name, index=0)
495 | # if self.modifier_position == 'bottom':
496 | # pass
497 |
498 | ffd.object = lattice
499 | if group_mapping != None:
500 | vertex_group_name = group_mapping[obj.name]
501 | ffd.name = vertex_group_name
502 | ffd.vertex_group = vertex_group_name
503 |
504 | obj.update_tag()
505 |
506 | def cleanup(self, objects):
507 | for obj in objects:
508 | used_vertex_groups = set()
509 | obsolete_modifiers = []
510 |
511 | if obj.type == "MESH":
512 | for modifier in obj.modifiers:
513 | if modifier.type == 'LATTICE' and "SimpleLattice" in modifier.name:
514 | if modifier.vertex_group != "":
515 | used_vertex_groups.add(modifier.vertex_group)
516 | elif (modifier.object == None or (modifier.vertex_group == "" and modifier.vertex_group not in obj.vertex_groups)):
517 | #a,b,c = modifier.object == None, modifier.vertex_group == "", modifier.vertex_group not in obj.vertex_groups
518 | #print(f"obj:{a} - vertexgrp empty: {b} - not in groups: {c}" )
519 | obsolete_modifiers.append(modifier)
520 |
521 | if obj.type == "GPENCIL":
522 | for modifier in obj.grease_pencil_modifiers:
523 | if modifier.type == 'GP_LATTICE' and "SimpleLattice" in modifier.name:
524 | if modifier.vertex_group != "":
525 | used_vertex_groups.add(modifier.vertex_group)
526 | elif (modifier.object == None or (modifier.vertex_group == "" and modifier.vertex_group not in obj.vertex_groups)):
527 | #a,b,c = modifier.object == None, modifier.vertex_group == "", modifier.vertex_group not in obj.vertex_groups
528 | #print(f"obj:{a} - vertexgrp empty: {b} - not in groups: {c}" )
529 | obsolete_modifiers.append(modifier)
530 |
531 | obsolete_groups = []
532 | for grp in obj.vertex_groups:
533 | if "SimpleLattice" in grp.name:
534 | if grp.name not in used_vertex_groups:
535 | obsolete_groups.append(grp)
536 |
537 | for group in obsolete_groups:
538 | print(f"removed vertex_group: {group.name}")
539 | obj.vertex_groups.remove(group)
540 | for modifier in obsolete_modifiers:
541 | if obj.type == "MESH":
542 | print(f"removed modifier: {modifier.name}")
543 | obj.modifiers.remove(modifier)
544 | if obj.type == "GPENCIL":
545 | print(f"removed grease pencil modifier: {modifier.name}")
546 | obj.grease_pencil_modifiers.remove(modifier)
547 |
548 | def set_vertex_group(self, objects, vert_mapping):
549 | group_mapping = {}
550 | for obj in objects:
551 |
552 | mode = obj.mode
553 | if obj.mode == 'EDIT':
554 | bpy.ops.object.editmode_toggle()
555 |
556 | #group_index = 0
557 | #for grp in obj.vertex_groups:
558 | #if "SimpleLattice." in grp.name:
559 | #index = int(grp.name.split(".")[-1])
560 | #group_index = max(group_index, index)
561 |
562 | #group = obj.vertex_groups.new(name=f"SimpleLattice.{group_index}")
563 | if obj.type == 'MESH':
564 | #print("creating group for MESH")
565 | group = obj.vertex_groups.new(name=f"SimpleLattice")
566 |
567 | group.add(vert_mapping[obj.name], 1.0, "REPLACE")
568 | group_mapping[obj.name] = group.name
569 |
570 | if obj.type == 'GPENCIL': # <<==================== NOT IMPLEMENTING IN API YET
571 | #print("creating group for GP")
572 | group = obj.vertex_groups.new(name=f"SimpleLattice")
573 |
574 | group.add(vert_mapping[obj.name], 1.0, "REPLACE")
575 | group_mapping[obj.name] = group.name
576 |
577 | if mode != obj.mode:
578 | bpy.ops.object.editmode_toggle()
579 |
580 | return group_mapping
581 |
582 | def for_edit_mode(self, context):
583 | active_object = context.view_layer.objects.active
584 | # try:
585 | # bpy.ops.transform.create_orientation(name="SimpleLattice_Orientation", use=False, overwrite=True)
586 | # except:
587 | # EXPERIMENTAL Solution for Normal orientation
588 | if active_object.type == 'MESH':
589 | if bpy.context.mode == 'EDIT_MESH':
590 | # bpy.ops.object.mode_set(mode='OBJECT')
591 | bpy.ops.transform.create_orientation(name="SimpleLattice_Orientation", use=False, overwrite=True)
592 | if bpy.context.mode == 'OBJECT':
593 | bpy.ops.object.mode_set(mode='EDIT')
594 | bpy.ops.mesh.select_mode(type="VERT")
595 | bpy.ops.mesh.select_all(action='SELECT')
596 | bpy.ops.mesh.duplicate()
597 | bpy.ops.mesh.edge_face_add()
598 | bpy.ops.transform.create_orientation(name="SimpleLattice_Orientation", use=False, overwrite=True)
599 | bpy.ops.mesh.delete(type='VERT')
600 | bpy.ops.object.mode_set(mode='OBJECT')
601 |
602 | if active_object.mode == 'EDIT':
603 | objects_originals = context.selected_objects
604 |
605 | bpy.ops.object.mode_set(mode = 'OBJECT')
606 | bpy.ops.object.empty_add()
607 | bpy.ops.object.delete(use_global=False, confirm=False)
608 |
609 | # selecting original objects with active
610 | for obj in objects_originals:
611 | obj.select_set(True)
612 | context.view_layer.objects.active = active_object
613 |
614 | bpy.ops.object.mode_set(mode = 'EDIT')
615 |
616 | bpy.ops.ed.undo_push()
617 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------