7 import robowflex_visualization
as rv
11 '''Creates and adds a dict of shape_msgs::SolidPrimitive box to the blender scene.
13 bpy.ops.mesh.primitive_cube_add()
14 obj = bpy.context.active_object
15 obj.scale = [d / 2.0
for d
in box[
'dimensions']]
16 rv.utils.set_color(obj, box)
21 '''Creates and adds a dict of shape_msgs::SolidPrimitive sphere to the blender scene.
23 bpy.ops.mesh.primitive_uv_sphere_add(size = sphere[
'dimensions'][0])
24 obj = bpy.context.active_object
25 rv.utils.set_color(obj, sphere)
30 '''Creates and adds a dict of shape_msgs::SolidPrimitive cylinder to the blender scene.
32 height = cylinder[
'dimensions'][0]
33 radius = cylinder[
'dimensions'][1]
34 bpy.ops.mesh.primitive_cylinder_add(radius = radius, depth = height)
35 obj = bpy.context.active_object
36 rv.utils.set_color(obj, cylinder)
41 '''Creates and adds a dict of shape_msgs::SolidPrimitive cone to the blender scene.
43 height = cone[
'dimensions'][0]
44 radius = cone[
'dimensions'][1]
45 bpy.ops.mesh.primitive_cylinder_add(radius = radius, depth = height)
46 obj = bpy.context.active_object
47 rv.utils.set_color(obj, cone)
52 '''Loads and adds a mesh to the blender scene.
56 old = set([obj.name
for obj
in bpy.data.objects])
58 mesh_file = rv.utils.resolve_path(mesh[
'resource'])
59 if '.dae' in mesh_file.lower():
60 bpy.ops.wm.collada_import(filepath = mesh_file)
61 elif '.stl' in mesh_file.lower():
62 bpy.ops.import_mesh.stl(filepath = mesh_file)
63 elif '.ply' in mesh_file.lower():
64 bpy.ops.import_mesh.ply(filepath = mesh_file)
69 new = set([obj.name
for obj
in bpy.data.objects])
70 imported_names = new - old
74 for name
in imported_names:
75 rv.utils.deselect_all()
76 i_obj = bpy.data.objects[name]
79 if 'Camera' in name
or 'Lamp' in name:
80 i_obj.select_set(
True)
81 bpy.ops.object.delete()
87 rv.utils.clear_alpha(i_obj)
89 if "materials" in i_obj.data:
90 if not i_obj.data.materials:
91 rv.utils.set_color(i_obj, mesh)
93 obj_list.append(i_obj)
95 if 'dimensions' in mesh
and top:
96 top.scale = mesh[
'dimensions']
104 'sphere' : add_sphere,
106 'cylinder': add_cylinder,
114 '''Add a shape_msgs::SolidPrimitive to the scene.
116 if 'resource' in shape:
121 return SHAPE_MAP[shape[
'type']](shape)
def add_cylinder(cylinder)