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 from __future__ import print_function
00025 import os
00026 import argparse
00027 import subprocess
00028
00029 parser = argparse.ArgumentParser(usage='Export meshes and convert them')
00030 parser.add_argument('-s', '--scriptfile', default='io_export_collision.py',
00031 help='name of the blender script to Launch')
00032 parser.add_argument('-b', '--blenderdir', default='/usr/bin',
00033 help='location of your blender directory')
00034 parser.add_argument('-i', '--inputmeshdir', default=None,
00035 help='directory where collada meshes are located')
00036 parser.add_argument('-o', '--outputdir', default=None,
00037 help='directory to export the meshes to')
00038 parser.add_argument('-r', '--ratio', default=0.1,
00039 help='float value, ratio used to decimate meshes',
00040 type=float)
00041 parser.add_argument('-t', '--threshold', default=50,
00042 help='integer: minimum number of vertices for decimation',
00043 type=int)
00044 parser.add_argument('--scale', default=1,
00045 help='scale to resize the collada meshes to', type=float)
00046 parser.add_argument('-n', '--outputfilename', default=None,
00047 help='name of the output file (for material file)')
00048 parser.add_argument('-f', '--blenderfile', default=None,
00049 help='path of the blender file to process')
00050
00051 args = parser.parse_args()
00052
00053 clean = False
00054
00055
00056 def check_output_dir(out):
00057 if not os.path.isdir(out):
00058 print('creating the output folder because it does not exist')
00059 os.makedirs(out)
00060 return out
00061
00062
00063 script_path = subprocess.check_output('rospack find naoqi_tools',
00064 stderr=subprocess.STDOUT,
00065 shell=True)[:-1]
00066 script_path = os.path.join(script_path, 'scripts', 'blender', args.scriptfile)
00067
00068 if(not os.path.isfile(script_path)):
00069 print("script doesn't exist\nExiting now")
00070 exit(1)
00071
00072
00073 if args.scriptfile != 'io_export_visual.py':
00074 if args.outputdir is None:
00075 print('\nno valid output directory: using ' + str(args.inputmeshdir) +
00076 ' as destination folder')
00077 output_dir = args.inputmeshdir
00078 else:
00079 output_dir = check_output_dir(args.outputdir)
00080
00081
00082 if args.inputmeshdir is None or not os.path.isdir(args.inputmeshdir):
00083 print('Invalid mesh folder provided\nExiting now')
00084 exit(1)
00085 else:
00086 if args.outputdir is None:
00087 output_dir = os.path.dirname(args.blenderfile)
00088 print('\nno valid output directory: using ' +
00089 output_dir + ' as destination folder')
00090 else:
00091 output_dir = check_output_dir(args.outputdir)
00092
00093
00094 if(args.scriptfile == 'normalize_meshes.py'):
00095 cmd = (script_path + ' -i ' + args.inputmeshdir + ' -s ' +
00096 str(args.scale) + ' -o ' + output_dir)
00097
00098 elif(args.scriptfile == 'io_export_collision.py'):
00099 cmd = (args.blenderdir + '/blender --background -P ' + script_path +
00100 ' -- ' + args.inputmeshdir + ' ' + str(args.ratio) + ' ' +
00101 str(args.threshold) + ' ' + output_dir)
00102
00103 elif(args.scriptfile == 'io_export_visual.py'):
00104 if(args.blenderfile is None or not os.path.isfile(args.blenderfile)):
00105 print('invalid blender file provided\nExiting now')
00106 exit(1)
00107 if(args.outputfilename is None):
00108 basename = os.path.basename(args.blenderfile)
00109 print('no name specified for output material file. unsing: ' +
00110 basename)
00111 else:
00112 basename = os.path.basename(args.outputfilename)
00113 if(basename.rfind('.') != -1):
00114 basename = basename[0:basename.rfind('.')]
00115 print('exporting material to ' + basename + '.material')
00116 cmd = (os.path.join(args.blenderdir, 'blender') + ' ' + args.blenderfile +
00117 ' -P ' + script_path + ' -- ' + output_dir +
00118 ' ' + basename)
00119
00120 elif(args.scriptfile == 'io_export_ogre.py'):
00121 cmd = ((os.path.join(args.blenderdir, 'blender')) + ' -P ' + script_path +
00122 ' -- ' + args.inputmeshdir + ' ' + output_dir)
00123 clean = True
00124
00125 os.system(cmd)
00126
00127
00128
00129 if clean is True:
00130 file_list = sorted(os.listdir(output_dir))
00131 for file in file_list:
00132 if file.endswith('.mesh.xml'):
00133 print('removing ' + file)
00134 os.remove(os.path.join(output_dir, file))