@@ -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 )
0 commit comments