Skip to content

Commit 7e1ee32

Browse files
committed
Blender Robotartist: only create one collection and place geometry inside
Issue #759
1 parent 303cb1d commit 7e1ee32

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

src/compas_blender/artists/robotmodelartist.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ def transform(self, native_mesh, transformation):
2929

3030
def draw_geometry(self, geometry, name=None, color=None):
3131
# Imported colors take priority over a the parameter color
32+
# TODO: cleanup confusion between layers and collections
33+
3234
if 'mesh_color.diffuse' in geometry.attributes:
3335
color = geometry.attributes['mesh_color.diffuse']
3436

@@ -40,11 +42,22 @@ def draw_geometry(self, geometry, name=None, color=None):
4042
color = [1., 1., 1.]
4143

4244
if self.layer:
43-
collection = bpy.data.collections.new(self.layer)
44-
bpy.context.scene.collection.children.link(collection)
45+
46+
current_collections = bpy.data.collections.items()
47+
#print(bpy.data.collections)
48+
#print(bpy.data.collections.keys())
49+
50+
if self.layer not in bpy.data.collections.keys():
51+
collection = bpy.data.collections.new(self.layer) # create new collection if none exists
52+
bpy.context.scene.collection.children.link(collection) # link the new collection to the base collection
53+
else:
54+
collection = bpy.data.collections.get(self.layer)
55+
# print(collection)
56+
4557

4658
v, f = geometry.to_vertices_and_faces()
47-
return compas_blender.draw_mesh(vertices=v, faces=f, name=name, color=color, centroid=False, layer=self.layer)
59+
# Draw the mesh in blender in the specified collection
60+
return compas_blender.draw_mesh(vertices=v, faces=f, name=name, color=color, centroid=False, collection=self.layer)
4861

4962
def redraw(self, timeout=None):
5063
bpy.ops.wm.redraw_timer(type='DRAW_WIN_SWAP', iterations=1)

src/compas_blender/utilities/drawing.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,11 @@ def _link_objects(objects, collection=None, layer=None):
4646
# if not layer:
4747
# layer = bpy.context.view_layer
4848
# layer_collection = layer.active_layer_collection.collection
49+
4950
for o in objects:
5051
for c in o.users_collection:
5152
c.objects.unlink(o)
52-
collection.objects.link(o)
53+
collection.objects.link(o) # TODO: why does this not work
5354
# layer_collection.objects.link(o)
5455

5556

0 commit comments

Comments
 (0)