Skip to content

Commit 27f2366

Browse files
committed
Rename Layer to Collection
- linting - added comment
1 parent 7e1ee32 commit 27f2366

File tree

2 files changed

+13
-20
lines changed

2 files changed

+13
-20
lines changed

src/compas_blender/artists/robotmodelartist.py

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@ class RobotModelArtist(BaseRobotModelArtist):
2020
The name of the layer that will contain the robot meshes.
2121
"""
2222

23-
def __init__(self, model, layer=None):
24-
self.layer = layer
23+
def __init__(self, model, collection=None, layer=None):
24+
self.view_layer = layer
25+
self.collection = collection
2526
super(RobotModelArtist, self).__init__(model)
2627

2728
def transform(self, native_mesh, transformation):
2829
native_mesh.matrix_world @= mathutils.Matrix(transformation.matrix)
2930

3031
def draw_geometry(self, geometry, name=None, color=None):
3132
# Imported colors take priority over a the parameter color
32-
# TODO: cleanup confusion between layers and collections
3333

3434
if 'mesh_color.diffuse' in geometry.attributes:
3535
color = geometry.attributes['mesh_color.diffuse']
@@ -41,23 +41,16 @@ def draw_geometry(self, geometry, name=None, color=None):
4141
else:
4242
color = [1., 1., 1.]
4343

44-
if self.layer:
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-
44+
if self.collection:
45+
if self.collection not in bpy.data.collections.keys():
46+
target_collection = bpy.data.collections.new(self.collection) # create new collection if none exists
47+
bpy.context.scene.collection.children.link(target_collection) # link the new collection to the base collection
48+
else: # not necessary: linking the object to an existing collection is done in compas_blender.draw_mesh
49+
target_collection = bpy.data.collections.get(self.collection)
5750

5851
v, f = geometry.to_vertices_and_faces()
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)
52+
# Draw the mesh in Blender in the specified collection
53+
return compas_blender.draw_mesh(vertices=v, faces=f, name=name, color=color, centroid=False, collection=self.collection)
6154

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

src/compas_blender/utilities/drawing.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +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-
49+
5050
for o in objects:
5151
for c in o.users_collection:
5252
c.objects.unlink(o)
53-
collection.objects.link(o) # TODO: why does this not work
53+
collection.objects.link(o)
5454
# layer_collection.objects.link(o)
5555

5656

0 commit comments

Comments
 (0)