Robowflex  v0.1
Making MoveIt Easy
robowflex_visualization.primitives Namespace Reference

Functions

def add_box (box)
 
def add_sphere (sphere)
 
def add_cylinder (cylinder)
 
def add_cone (cone)
 
def add_mesh (mesh)
 
def add_shape (shape)
 

Variables

dictionary SHAPE_MAP
 

Function Documentation

◆ add_box()

def robowflex_visualization.primitives.add_box (   box)
Creates and adds a dict of shape_msgs::SolidPrimitive box to the blender scene.

Definition at line 10 of file primitives.py.

10 def add_box(box):
11  '''Creates and adds a dict of shape_msgs::SolidPrimitive box to the blender scene.
12  '''
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)
17  return obj
18 
19 

◆ add_cone()

def robowflex_visualization.primitives.add_cone (   cone)
Creates and adds a dict of shape_msgs::SolidPrimitive cone to the blender scene.

Definition at line 40 of file primitives.py.

40 def add_cone(cone):
41  '''Creates and adds a dict of shape_msgs::SolidPrimitive cone to the blender scene.
42  '''
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)
48  return obj
49 
50 

◆ add_cylinder()

def robowflex_visualization.primitives.add_cylinder (   cylinder)
Creates and adds a dict of shape_msgs::SolidPrimitive cylinder to the blender scene.

Definition at line 29 of file primitives.py.

29 def add_cylinder(cylinder):
30  '''Creates and adds a dict of shape_msgs::SolidPrimitive cylinder to the blender scene.
31  '''
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)
37  return obj
38 
39 

◆ add_mesh()

def robowflex_visualization.primitives.add_mesh (   mesh)
Loads and adds a mesh to the blender scene.

Definition at line 51 of file primitives.py.

51 def add_mesh(mesh):
52  '''Loads and adds a mesh to the blender scene.
53  '''
54 
55  # Mark all existing objects as already imported
56  old = set([obj.name for obj in bpy.data.objects])
57 
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)
65  else:
66  return None
67 
68  # Compare all imported objects to what we saw before loading the mesh.
69  new = set([obj.name for obj in bpy.data.objects])
70  imported_names = new - old
71  obj_list = []
72 
73  top = None
74  for name in imported_names:
75  rv.utils.deselect_all()
76  i_obj = bpy.data.objects[name]
77 
78  # If an object comes with extra cameras or lamps, delete those.
79  if 'Camera' in name or 'Lamp' in name:
80  i_obj.select_set(True)
81  bpy.ops.object.delete()
82  continue
83 
84  if not i_obj.parent:
85  top = i_obj
86 
87  rv.utils.clear_alpha(i_obj)
88 
89  if "materials" in i_obj.data:
90  if not i_obj.data.materials:
91  rv.utils.set_color(i_obj, mesh)
92 
93  obj_list.append(i_obj)
94 
95  if 'dimensions' in mesh and top:
96  top.scale = mesh['dimensions']
97 
98  return obj_list, top
99 
100 

◆ add_shape()

def robowflex_visualization.primitives.add_shape (   shape)
Add a shape_msgs::SolidPrimitive to the scene.

Definition at line 113 of file primitives.py.

113 def add_shape(shape):
114  '''Add a shape_msgs::SolidPrimitive to the scene.
115  '''
116  if 'resource' in shape:
117  meshes, top = add_mesh(shape)
118  return top
119 
120  else:
121  return SHAPE_MAP[shape['type']](shape)

◆ add_sphere()

def robowflex_visualization.primitives.add_sphere (   sphere)
Creates and adds a dict of shape_msgs::SolidPrimitive sphere to the blender scene.

Definition at line 20 of file primitives.py.

20 def add_sphere(sphere):
21  '''Creates and adds a dict of shape_msgs::SolidPrimitive sphere to the blender scene.
22  '''
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)
26  return obj
27 
28 

Variable Documentation

◆ SHAPE_MAP

dictionary robowflex_visualization.primitives.SHAPE_MAP
Initial value:
1 = {
2  'box' : add_box,
3  1 : add_box,
4  'sphere' : add_sphere,
5  2 : add_sphere,
6  'cylinder': add_cylinder,
7  3 : add_cylinder,
8  'cone' : add_cone,
9  4 : add_cone
10 }

Definition at line 101 of file primitives.py.