Hey #b3d peeps!!
ということで作っておきました。(元→「オブジェクトにフィットするLatticeを追加」)
coordinatedlattice.py という名前で適当な場所に保存した上で、Add-onを追加、使用可能にする手順を行います。
コマンド実行は(Add-on有効にした.後で) スペースキーのコマンド検索から、 "coo" 等、適当に。
ソースコード(coordinatedlattice.py)
ソースコードは http://www.pasteall.org/61575/python に貼り付けておきましたのでそちらからでもどうぞ。
#!BPY # ##### BEGIN GPL LICENSE BLOCK ##### # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software Foundation, # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # # ##### END GPL LICENSE BLOCK ##### import bpy import mathutils bl_info = { "name": "Add Coordinated Lattice", "author": "blugjp", "blender": (2, 76, 0), "location": "Command search (Space bar) > Add Coordinated Lattice", "description": "Add Lattice Object, Along the bounding box ", "warning": "", "category": "Object", } def addcoordinatedlattice(obj): maxx = maxy = maxz = None minx = miny = minz = None for v in obj.bound_box: maxx= max(v[0],maxx) if maxx!=None else v[0] maxy= max(v[1],maxy) if maxy!=None else v[1] maxz= max(v[2],maxz) if maxz!=None else v[2] minx= min(v[0],minx) if minx!=None else v[0] miny= min(v[1],miny) if miny!=None else v[1] minz= min(v[2],minz) if minz!=None else v[2] # get center of boundingbox cx = (maxx +minx ) /2 cy = (maxy +miny ) /2 cz = (maxz +minz ) /2 # get boundingbox size sx = (maxx -minx ) sy = (maxy -miny ) sz = (maxz -minz ) # get lattice location (= boundingbox center) cv = mathutils.Vector((cx,cy,cz)) dv = mathutils.Vector(x * y for x, y in zip(cv, obj.scale)) eul = obj.rotation_euler dv.rotate(eul) loc = obj.location + dv # add lattice bpy.ops.object.add(radius=1, type='LATTICE', view_align=False, enter_editmode=False, location=loc, layers=(True, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False)) lat = bpy.context.object # set lattice rotation and size lat.rotation_euler = obj.rotation_euler sv = mathutils.Vector((sx,sy,sz)) lat.scale= mathutils.Vector(x * y for x, y in zip(sv, obj.scale)) # make parents with lattice deform (obj -> lat) obj.select = True bpy.ops.object.parent_set(type='LATTICE') class DialogOperator(bpy.types.Operator): bl_idname = "object.dialog_operator" bl_label = "Information" def execute(self, context): return {'FINISHED'} def invoke(self, context, event): wm = context.window_manager return wm.invoke_props_dialog(self) def draw(self, context): layout = self.layout col = layout.column() col.label(text=bpy.context.scene.clatdialog_message) class CoordinatedLatticeOperator(bpy.types.Operator): """Add Coordinated Lattice""" bl_label = "Add Coordinated Lattice" bl_idname = "object.add_coordinated_lattice" def execute(self, context): if bpy.context.mode == 'OBJECT': obj = bpy.context.object if obj.type == 'MESH' or obj.type == 'CURVE': addcoordinatedlattice(obj) else: bpy.context.scene.clatdialog_message = "This command is only for Mesh or Curve." bpy.ops.object.dialog_operator('INVOKE_DEFAULT') return {'CANCELLED'} else: bpy.context.scene.clatdialog_message = "Please change the mode to Object mode." bpy.ops.object.dialog_operator('INVOKE_DEFAULT') return {'CANCELLED'} return {'FINISHED'} # Registration def register(): bpy.utils.register_class(CoordinatedLatticeOperator) bpy.utils.register_class(DialogOperator) bpy.types.Scene.clatdialog_message =\ bpy.props.StringProperty(name="message", default='') def unregister(): bpy.utils.unregister_class(CoordinatedLatticeOperator) bpy.utils.unregister_class(DialogOperator) del bpy.types.Scene.clatdialog_message if __name__ == "__main__": register()