Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 from __future__ import print_function
00029 import os
00030 import argparse
00031 import subprocess
00032
00033 parser = argparse.ArgumentParser(usage='Export meshes and convert them')
00034 parser.add_argument('-b', '--blenderdir', default='/usr/bin',
00035 help='location of your blender directory')
00036 parser.add_argument('-f', '--file', default='nao-v4.blend',
00037 help='full path of the blender file to process')
00038 parser.add_argument('-o', '--outputmeshdir', default=None,
00039 help='directory to export the meshes to')
00040
00041 args = parser.parse_args()
00042
00043 if os.path.basename(args.file).lower().startswith('nao'):
00044 robot = 'nao'
00045 version = 'V40'
00046 suffix = '_meshes'
00047 scale = 0.01
00048 elif os.path.basename(args.file).lower().startswith('juliette') or \
00049 os.path.basename(args.file).lower().startswith('pepper'):
00050 robot = 'pepper'
00051 version = ''
00052 suffix = '_description'
00053 scale = 0.01
00054 elif os.path.basename(args.file).lower().startswith('romeo'):
00055 robot = 'romeo'
00056 version = ''
00057 suffix = '_description'
00058 scale = 1
00059 else:
00060 print('robot name unknown')
00061 exit(1)
00062 package = robot + suffix
00063
00064 if args.outputmeshdir is None:
00065 print('\nno valid output directory, looking for ' + package +
00066 ' ROS package\n')
00067 cmd = 'rospack find ' + package
00068 path_meshes = subprocess.check_output(cmd,
00069 stderr=subprocess.STDOUT,
00070 shell=True)[:-1]
00071 if not path_meshes:
00072 print('package "' + path_meshes + '" not found')
00073 else:
00074 if not os.path.isdir(args.outputmeshdir):
00075 print('creating the output folder because it does not exist')
00076 os.makedirs(args.outputmeshdir)
00077 path_meshes = args.outputmeshdir
00078
00079 extractor_path = subprocess.check_output('rospack find naoqi_tools',
00080 stderr=subprocess.STDOUT,
00081 shell=True)[:-1]
00082 script_path = os.path.join(extractor_path,
00083 'scripts', 'blender')
00084
00085 if version:
00086 path_meshes = os.path.join(path_meshes, version)
00087
00088 print("extractor path :" + extractor_path)
00089
00090
00091 os.system('./run_blender_script.py -s io_export_visual.py -o ' + path_meshes +
00092 ' -f ' + args.file)
00093
00094
00095
00096 os.system('./run_blender_script.py -s io_export_ogre.py -i ' + path_meshes)
00097
00098
00099 os.system('./run_blender_script.py -s normalize_meshes.py -i ' + path_meshes +
00100 ' --scale ' + str(scale))
00101
00102
00103 os.system('./run_blender_script.py -s io_export_collision.py -i ' +
00104 path_meshes)
00105
00106
00107 file_list = sorted(os.listdir(path_meshes))
00108 for file in file_list:
00109 if file.endswith('.mesh.xml') or file.endswith('.mesh') or \
00110 file.endswith('.material'):
00111 print('removing ' + file)
00112 os.remove(os.path.join(path_meshes, file))