diff options
author | Campbell Barton <ideasman42@gmail.com> | 2010-02-10 19:10:47 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2010-02-10 19:10:47 +0300 |
commit | 358c9566379c46d443b94ae1e701d1da562c1a4e (patch) | |
tree | 08782fc50246dbed79dc7a3a4c1f657aa0b4d182 /release | |
parent | 5df1bb84d8fa455f337024f5d32969244215dd0a (diff) |
make dupliface operator (access from object menu)
scene.object.link() now returns the new ObjectBase
Diffstat (limited to 'release')
-rw-r--r-- | release/scripts/op/object.py | 71 | ||||
-rw-r--r-- | release/scripts/ui/space_view3d.py | 1 |
2 files changed, 70 insertions, 2 deletions
diff --git a/release/scripts/op/object.py b/release/scripts/op/object.py index 6fb15f1504c..5d84c0f1222 100644 --- a/release/scripts/op/object.py +++ b/release/scripts/op/object.py @@ -379,11 +379,78 @@ class JoinUVs(bpy.types.Operator): self._main(context) return {'FINISHED'} -if __name__ == "__main__": - bpy.ops.uv.simple_operator() +class MakeDupliFace(bpy.types.Operator): + '''Make linked objects into dupli-faces''' + bl_idname = "object.make_dupli_face" + bl_label = "Make DupliFace" + + def poll(self, context): + obj = context.active_object + return (obj and obj.type == 'MESH') + + def _main(self, context): + from Mathutils import Vector + from math import sqrt + + SCALE_FAC = 0.01 + offset = 0.5 * SCALE_FAC + base_tri = Vector(-offset, -offset, 0.0), Vector(-offset, offset, 0.0), Vector(offset, offset, 0.0), Vector(offset, -offset, 0.0) + + def matrix_to_quat(matrix): + # scale = matrix.median_scale + trans = matrix.translation_part() + rot = matrix.rotation_part() # also contains scale + + return [(rot * b) + trans for b in base_tri] + scene = bpy.context.scene + linked = {} + for obj in bpy.context.selected_objects: + data = obj.data + if data: + linked.setdefault(data, []).append(obj) + + for data, objects in linked.items(): + face_verts = [axis for obj in objects for v in matrix_to_quat(obj.matrix) for axis in v] + faces = list(range(int(len(face_verts) / 3))) + + mesh = bpy.data.meshes.new(data.name + "_dupli") + + mesh.add_geometry(int(len(face_verts) / 3), 0, int(len(face_verts) / (4 * 3))) + mesh.verts.foreach_set("co", face_verts) + mesh.faces.foreach_set("verts_raw", faces) + mesh.update() # generates edge data + + # pick an object to use + obj = objects[0] + + ob_new = bpy.data.objects.new(mesh.name, 'MESH') + ob_new.data = mesh + base = scene.objects.link(ob_new) + base.layers[:] = obj.layers + + ob_inst = bpy.data.objects.new(data.name, obj.type) + ob_inst.data = data + base = scene.objects.link(ob_inst) + base.layers[:] = obj.layers + + for obj in objects: + scene.objects.unlink(obj) + + ob_new.dupli_type = 'FACES' + ob_inst.parent = ob_new + ob_new.use_dupli_faces_scale = True + ob_new.dupli_faces_scale = 1.0 / SCALE_FAC + + def execute(self, context): + self._main(context) + return {'FINISHED'} + +# if __name__ == "__main__": +# bpy.ops.uv.simple_operator() bpy.types.register(SelectPattern) bpy.types.register(SubdivisionSet) bpy.types.register(ShapeTransfer) bpy.types.register(JoinUVs) +bpy.types.register(MakeDupliFace) diff --git a/release/scripts/ui/space_view3d.py b/release/scripts/ui/space_view3d.py index 880ab51b87f..b6a8af8debe 100644 --- a/release/scripts/ui/space_view3d.py +++ b/release/scripts/ui/space_view3d.py @@ -659,6 +659,7 @@ class VIEW3D_MT_object(bpy.types.Menu): layout.operator("object.delete", text="Delete...") layout.operator("object.proxy_make", text="Make Proxy...") layout.menu("VIEW3D_MT_make_links", text="Make Links...") + layout.operator("object.make_dupli_face", text="Make Dupliface...") layout.operator_menu_enum("object.make_local", "type", text="Make Local...") layout.menu("VIEW3D_MT_make_single_user") |