export_meshes.py
Go to the documentation of this file.
00001 #! /usr/bin/env python
00002 
00003 # Copyright (C) 2014 Aldebaran
00004 #
00005 # Licensed under the Apache License, Version 2.0 (the "License");
00006 # you may not use this file except in compliance with the License.
00007 # You may obtain a copy of the License at
00008 #
00009 # http://www.apache.org/licenses/LICENSE-2.0
00010 #
00011 # Unless required by applicable law or agreed to in writing, software
00012 # distributed under the License is distributed on an "AS IS" BASIS,
00013 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014 # See the License for the specific language governing permissions and
00015 # limitations under the License.
00016 #
00017 # export_meshes.py
00018 # Authors: Mikael Arguedas [mikael.arguedas@gmail.com]
00019 
00020 # This script opens a blender file, exports all meshes to collada, merges every mesh group and exports them as .mesh file (OGRE), removes the offset from the colladas, decimates them and exports collision meshes in STL format. Finally cleans your output directory of every .xml files
00021 # This is an Aldebaran specific scripts. It certainly won't work on blender files of robots from other companies
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 # Export meshes as collada files and all the materials of the scene
00076 os.system('./run_blender_script.py -s io_export_visual.py -o ' + path_meshes + ' -f ' + args.file)
00077 
00078 # Import collada files one by one and export each of them as a single .mesh(OGRE) file
00079 os.system('./run_blender_script.py -s io_export_ogre.py -i ' + path_meshes)
00080 
00081 # Normalize exported collada meshes to give them the right scale and orientation
00082 os.system('./run_blender_script.py -s normalize_meshes.py -i ' + path_meshes + ' --scale ' + str(scale))
00083 
00084 # Import all collada meshes, decimate them and export them as stl files
00085 os.system('./run_blender_script.py -s io_export_collision.py -i ' + path_meshes)
00086 
00087 # Remove files left by the OGRE exporter
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))


naoqi_tools
Author(s): Mikael Arguedas
autogenerated on Thu Aug 27 2015 14:05:48