export_meshes.py
Go to the documentation of this file.
1 #! /usr/bin/env python
2 
3 # Copyright (C) 2014 Aldebaran
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 #
17 # export_meshes.py
18 # Authors: Mikael Arguedas [mikael.arguedas@gmail.com]
19 
20 # This script opens a blender file, exports all meshes to collada,
21 # merges every mesh group and exports them as .mesh file (OGRE),
22 # removes the offset from the colladas, decimates them
23 # exports collision meshes in STL format.
24 # Finally cleans your output directory of every .xml files
25 # This is an Aldebaran robots specific scripts.
26 # It will very likely not work on blender files of robots from other companies
27 
28 from __future__ import print_function
29 import os
30 import argparse
31 import subprocess
32 
33 parser = argparse.ArgumentParser(usage='Export meshes and convert them')
34 parser.add_argument('-b', '--blenderdir', default='/usr/bin',
35  help='location of your blender directory')
36 parser.add_argument('-f', '--file', default='nao-v4.blend',
37  help='full path of the blender file to process')
38 parser.add_argument('-o', '--outputmeshdir', default=None,
39  help='directory to export the meshes to')
40 
41 args = parser.parse_args()
42 
43 if os.path.basename(args.file).lower().startswith('nao'):
44  robot = 'nao'
45  version = 'V40'
46  suffix = '_meshes'
47  scale = 0.01
48 elif os.path.basename(args.file).lower().startswith('juliette') or \
49  os.path.basename(args.file).lower().startswith('pepper'):
50  robot = 'pepper'
51  version = ''
52  suffix = '_description'
53  scale = 0.01
54 elif os.path.basename(args.file).lower().startswith('romeo'):
55  robot = 'romeo'
56  version = ''
57  suffix = '_description'
58  scale = 1
59 else:
60  print('robot name unknown')
61  exit(1)
62 package = robot + suffix
63 
64 if args.outputmeshdir is None:
65  print('\nno valid output directory, looking for ' + package +
66  ' ROS package\n')
67  cmd = 'rospack find ' + package
68  path_meshes = subprocess.check_output(cmd,
69  stderr=subprocess.STDOUT,
70  shell=True)[:-1]
71  if not path_meshes:
72  print('package "' + path_meshes + '" not found')
73 else:
74  if not os.path.isdir(args.outputmeshdir):
75  print('creating the output folder because it does not exist')
76  os.makedirs(args.outputmeshdir)
77  path_meshes = args.outputmeshdir
78 
79 extractor_path = subprocess.check_output('rospack find naoqi_tools',
80  stderr=subprocess.STDOUT,
81  shell=True)[:-1]
82 script_path = os.path.join(extractor_path,
83  'scripts', 'blender')
84 
85 if version:
86  path_meshes = os.path.join(path_meshes, version)
87 
88 print("extractor path :" + extractor_path)
89 
90 # Export meshes as collada files and all the materials of the scene
91 os.system('./run_blender_script.py -s io_export_visual.py -o ' + path_meshes +
92  ' -f ' + args.file)
93 
94 # Import collada files one by one
95 # export each of them as a single .mesh(OGRE) file
96 os.system('./run_blender_script.py -s io_export_ogre.py -i ' + path_meshes)
97 
98 # Normalize collada meshes to give them the right scale and orientation
99 os.system('./run_blender_script.py -s normalize_meshes.py -i ' + path_meshes +
100  ' --scale ' + str(scale))
101 
102 # Import all collada meshes, decimate them and export them as stl files
103 os.system('./run_blender_script.py -s io_export_collision.py -i ' +
104  path_meshes)
105 
106 # Remove files left by the OGRE exporter
107 file_list = sorted(os.listdir(path_meshes))
108 for file in file_list:
109  if file.endswith('.mesh.xml') or file.endswith('.mesh') or \
110  file.endswith('.material'):
111  print('removing ' + file)
112  os.remove(os.path.join(path_meshes, file))


naoqi_tools
Author(s): Mikael Arguedas
autogenerated on Thu Jul 16 2020 03:18:36