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 from __future__ import print_function
00024 import os
00025 import argparse
00026 import subprocess
00027
00028 parser = argparse.ArgumentParser(usage='Export meshes and convert them')
00029 parser.add_argument('-b','--blenderdir', default='/usr/bin', help='location of your blender directory')
00030 parser.add_argument('-f','--file', default='nao-v4.blend',help='full path of the blender file to process')
00031 parser.add_argument('-o','--outputmeshdir',default=None, help='directory to export the meshes to')
00032
00033 args = parser.parse_args()
00034
00035 if os.path.basename(args.file).lower().startswith('nao'):
00036 robot='nao'
00037 version='V40'
00038 suffix = '_meshes'
00039 scale = 0.01
00040 elif os.path.basename(args.file).lower().startswith('juliette') or os.path.basename(args.file).lower().startswith('pepper') :
00041 robot='pepper'
00042 version = ''
00043 suffix = '_description'
00044 scale = 0.01
00045 elif os.path.basename(args.file).lower().startswith('romeo'):
00046 robot='romeo'
00047 version = ""
00048 suffix = '_description'
00049 scale = 1
00050 else:
00051 print("robot name unknown")
00052 exit(1)
00053 package = robot + suffix
00054
00055 if args.outputmeshdir == None :
00056 print("\nno valid output directory, looking for " + package + " ROS package\n")
00057 cmd= 'rospack find ' + package
00058 path_meshes = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True)[:-1]
00059 if not path_meshes:
00060 print('package "' + path_meshes + '" not found')
00061 else:
00062 if not os.path.isdir(args.outputmeshdir):
00063 print('creating the output folder because it does not exist')
00064 os.makedirs(args.outputmeshdir)
00065 path_meshes = args.outputmeshdir
00066
00067 extractor_path = subprocess.check_output('rospack find naoqi_tools', stderr=subprocess.STDOUT, shell=True)[:-1]
00068 script_path = os.path.join(extractor_path , 'scripts', 'blender')
00069
00070 if version:
00071 path_meshes = os.path.join(path_meshes, version)
00072
00073 print("extractor path :" + extractor_path)
00074
00075
00076 os.system('./run_blender_script.py -s io_export_visual.py -o ' + path_meshes + ' -f ' + args.file)
00077
00078
00079 os.system('./run_blender_script.py -s io_export_ogre.py -i ' + path_meshes)
00080
00081
00082 os.system('./run_blender_script.py -s normalize_meshes.py -i ' + path_meshes + ' --scale ' + str(scale))
00083
00084
00085 os.system('./run_blender_script.py -s io_export_collision.py -i ' + path_meshes)
00086
00087
00088 file_list = sorted(os.listdir(path_meshes))
00089 for file in file_list:
00090 if file.endswith('.mesh.xml') or file.endswith('.mesh') or file.endswith('.material'):
00091 print('removing ' + file)
00092 os.remove(os.path.join(path_meshes , file))