Fix T63256: Make Dupli Face was broken since there are collections

This commit is contained in:
2019-04-04 16:37:55 +02:00
parent 3c7a538c9b
commit df3c1dde04

View File

@@ -594,6 +594,7 @@ class MakeDupliFace(Operator):
@staticmethod @staticmethod
def _main(context): def _main(context):
from mathutils import Vector from mathutils import Vector
from collections import defaultdict
SCALE_FAC = 0.01 SCALE_FAC = 0.01
offset = 0.5 * SCALE_FAC offset = 0.5 * SCALE_FAC
@@ -610,11 +611,10 @@ class MakeDupliFace(Operator):
return [(rot @ b) + trans for b in base_tri] return [(rot @ b) + trans for b in base_tri]
scene = context.scene scene = context.scene
linked = {} linked = defaultdict(list)
for obj in context.selected_objects: for obj in context.selected_objects:
data = obj.data if obj.type == 'MESH':
if data: linked[obj.data].append(obj)
linked.setdefault(data, []).append(obj)
for data, objects in linked.items(): for data, objects in linked.items():
face_verts = [axis for obj in objects face_verts = [axis for obj in objects
@@ -637,19 +637,11 @@ class MakeDupliFace(Operator):
mesh.polygons.foreach_set("loop_total", (4,) * nbr_faces) mesh.polygons.foreach_set("loop_total", (4,) * nbr_faces)
mesh.update() # generates edge data mesh.update() # generates edge data
# pick an object to use
obj = objects[0]
ob_new = bpy.data.objects.new(mesh.name, mesh) ob_new = bpy.data.objects.new(mesh.name, mesh)
base = scene.objects.link(ob_new) context.collection.objects.link(ob_new)
base.layers[:] = obj.layers
ob_inst = bpy.data.objects.new(data.name, data) ob_inst = bpy.data.objects.new(data.name, data)
base = scene.objects.link(ob_inst) context.collection.objects.link(ob_inst)
base.layers[:] = obj.layers
for obj in objects:
scene.objects.unlink(obj)
ob_new.instance_type = 'FACES' ob_new.instance_type = 'FACES'
ob_inst.parent = ob_new ob_inst.parent = ob_new
@@ -659,6 +651,10 @@ class MakeDupliFace(Operator):
ob_inst.select_set(True) ob_inst.select_set(True)
ob_new.select_set(True) ob_new.select_set(True)
for obj in objects:
for collection in obj.users_collection:
collection.objects.unlink(obj)
def execute(self, context): def execute(self, context):
self._main(context) self._main(context)
return {'FINISHED'} return {'FINISHED'}