24 from __future__
import print_function
29 parser = argparse.ArgumentParser(usage=
'Export meshes and convert them')
30 parser.add_argument(
'-s',
'--scriptfile', default=
'io_export_collision.py',
31 help=
'name of the blender script to Launch')
32 parser.add_argument(
'-b',
'--blenderdir', default=
'/usr/bin',
33 help=
'location of your blender directory')
34 parser.add_argument(
'-i',
'--inputmeshdir', default=
None,
35 help=
'directory where collada meshes are located')
36 parser.add_argument(
'-o',
'--outputdir', default=
None,
37 help=
'directory to export the meshes to')
38 parser.add_argument(
'-r',
'--ratio', default=0.1,
39 help=
'float value, ratio used to decimate meshes',
41 parser.add_argument(
'-t',
'--threshold', default=50,
42 help=
'integer: minimum number of vertices for decimation',
44 parser.add_argument(
'--scale', default=1,
45 help=
'scale to resize the collada meshes to', type=float)
46 parser.add_argument(
'-n',
'--outputfilename', default=
None,
47 help=
'name of the output file (for material file)')
48 parser.add_argument(
'-f',
'--blenderfile', default=
None,
49 help=
'path of the blender file to process')
51 args = parser.parse_args()
57 if not os.path.isdir(out):
58 print(
'creating the output folder because it does not exist')
63 script_path = subprocess.check_output(
'rospack find naoqi_tools',
64 stderr=subprocess.STDOUT,
66 script_path = os.path.join(script_path,
'scripts',
'blender', args.scriptfile)
68 if(
not os.path.isfile(script_path)):
69 print(
"script doesn't exist\nExiting now")
73 if args.scriptfile !=
'io_export_visual.py':
74 if args.outputdir
is None:
75 print(
'\nno valid output directory: using ' + str(args.inputmeshdir) +
76 ' as destination folder')
77 output_dir = args.inputmeshdir
82 if args.inputmeshdir
is None or not os.path.isdir(args.inputmeshdir):
83 print(
'Invalid mesh folder provided\nExiting now')
86 if args.outputdir
is None:
87 output_dir = os.path.dirname(args.blenderfile)
88 print(
'\nno valid output directory: using ' +
89 output_dir +
' as destination folder')
94 if(args.scriptfile ==
'normalize_meshes.py'):
95 cmd = (script_path +
' -i ' + args.inputmeshdir +
' -s ' +
96 str(args.scale) +
' -o ' + output_dir)
98 elif(args.scriptfile ==
'io_export_collision.py'):
99 cmd = (args.blenderdir +
'/blender --background -P ' + script_path +
100 ' -- ' + args.inputmeshdir +
' ' + str(args.ratio) +
' ' +
101 str(args.threshold) +
' ' + output_dir)
103 elif(args.scriptfile ==
'io_export_visual.py'):
104 if(args.blenderfile
is None or not os.path.isfile(args.blenderfile)):
105 print(
'invalid blender file provided\nExiting now')
107 if(args.outputfilename
is None):
108 basename = os.path.basename(args.blenderfile)
109 print(
'no name specified for output material file. unsing: ' +
112 basename = os.path.basename(args.outputfilename)
113 if(basename.rfind(
'.') != -1):
114 basename = basename[0:basename.rfind(
'.')]
115 print(
'exporting material to ' + basename +
'.material')
116 cmd = (os.path.join(args.blenderdir,
'blender') +
' ' + args.blenderfile +
117 ' -P ' + script_path +
' -- ' + output_dir +
120 elif(args.scriptfile ==
'io_export_ogre.py'):
121 cmd = ((os.path.join(args.blenderdir,
'blender')) +
' -P ' + script_path +
122 ' -- ' + args.inputmeshdir +
' ' + output_dir)
130 file_list = sorted(os.listdir(output_dir))
131 for file
in file_list:
132 if file.endswith(
'.mesh.xml'):
133 print(
'removing ' + file)
134 os.remove(os.path.join(output_dir, file))
def check_output_dir(out)