Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cleanup, approching pep8 pep257 compliance #56

Merged
merged 3 commits into from Aug 30, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 8 additions & 4 deletions naoqi_tools/scripts/compare_xacro.py
Expand Up @@ -25,14 +25,18 @@
from xmldiff.xmldiff import compareFiles

if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Compares all the .xacro in two folders.')
parser = argparse.ArgumentParser(
description='Compares all the .xacro in two folders.')
parser.add_argument('folder1')
parser.add_argument('folder2')
args = parser.parse_args()
files1 = set([ i for i in os.listdir(args.folder1) if i.endswith('.xacro')])
files2 = set([ i for i in os.listdir(args.folder2) if i.endswith('.xacro')])
files1 = set([i for i in os.listdir(args.folder1)
if i.endswith('.xacro')])
files2 = set([i for i in os.listdir(args.folder2)
if i.endswith('.xacro')])
for i in files1.intersection(files2):
diff = compareFiles(os.path.join(args.folder1, i), os.path.join(args.folder2, i))
diff = compareFiles(os.path.join(args.folder1, i),
os.path.join(args.folder2, i))
if diff:
print('---------------------------------------------------------')
print('File %s in common' % i)
Expand Down
76 changes: 48 additions & 28 deletions naoqi_tools/scripts/export_meshes.py
Expand Up @@ -17,76 +17,96 @@
# export_meshes.py
# Authors: Mikael Arguedas [mikael.arguedas@gmail.com]

# 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
# This is an Aldebaran specific scripts. It certainly won't work on blender files of robots from other companies
# 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
# exports collision meshes in STL format.
# Finally cleans your output directory of every .xml files
# This is an Aldebaran robots specific scripts.
# It will very likely not work on blender files of robots from other companies

from __future__ import print_function
import os
import argparse
import subprocess

parser = argparse.ArgumentParser(usage='Export meshes and convert them')
parser.add_argument('-b','--blenderdir', default='/usr/bin', help='location of your blender directory')
parser.add_argument('-f','--file', default='nao-v4.blend',help='full path of the blender file to process')
parser.add_argument('-o','--outputmeshdir',default=None, help='directory to export the meshes to')
parser.add_argument('-b', '--blenderdir', default='/usr/bin',
help='location of your blender directory')
parser.add_argument('-f', '--file', default='nao-v4.blend',
help='full path of the blender file to process')
parser.add_argument('-o', '--outputmeshdir', default=None,
help='directory to export the meshes to')

args = parser.parse_args()

if os.path.basename(args.file).lower().startswith('nao'):
robot='nao'
version='V40'
robot = 'nao'
version = 'V40'
suffix = '_meshes'
scale = 0.01
elif os.path.basename(args.file).lower().startswith('juliette') or os.path.basename(args.file).lower().startswith('pepper') :
robot='pepper'
elif os.path.basename(args.file).lower().startswith('juliette') or \
os.path.basename(args.file).lower().startswith('pepper'):
robot = 'pepper'
version = ''
suffix = '_description'
scale = 0.01
elif os.path.basename(args.file).lower().startswith('romeo'):
robot='romeo'
version = ""
robot = 'romeo'
version = ''
suffix = '_description'
scale = 1
else:
print("robot name unknown")
print('robot name unknown')
exit(1)
package = robot + suffix

if args.outputmeshdir == None :
print("\nno valid output directory, looking for " + package + " ROS package\n")
cmd= 'rospack find ' + package
path_meshes = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True)[:-1]
if args.outputmeshdir is None:
print('\nno valid output directory, looking for ' + package +
' ROS package\n')
cmd = 'rospack find ' + package
path_meshes = subprocess.check_output(cmd,
stderr=subprocess.STDOUT,
shell=True)[:-1]
if not path_meshes:
print('package "' + path_meshes + '" not found')
print('package "' + path_meshes + '" not found')
else:
if not os.path.isdir(args.outputmeshdir):
print('creating the output folder because it does not exist')
os.makedirs(args.outputmeshdir)
print('creating the output folder because it does not exist')
os.makedirs(args.outputmeshdir)
path_meshes = args.outputmeshdir

extractor_path = subprocess.check_output('rospack find naoqi_tools', stderr=subprocess.STDOUT, shell=True)[:-1]
script_path = os.path.join(extractor_path , 'scripts', 'blender')
extractor_path = subprocess.check_output('rospack find naoqi_tools',
stderr=subprocess.STDOUT,
shell=True)[:-1]
script_path = os.path.join(extractor_path,
'scripts', 'blender')

if version:
path_meshes = os.path.join(path_meshes, version)

print("extractor path :" + extractor_path)

# Export meshes as collada files and all the materials of the scene
os.system('./run_blender_script.py -s io_export_visual.py -o ' + path_meshes + ' -f ' + args.file)
os.system('./run_blender_script.py -s io_export_visual.py -o ' + path_meshes +
' -f ' + args.file)

# Import collada files one by one and export each of them as a single .mesh(OGRE) file
# Import collada files one by one
# export each of them as a single .mesh(OGRE) file
os.system('./run_blender_script.py -s io_export_ogre.py -i ' + path_meshes)

# Normalize exported collada meshes to give them the right scale and orientation
os.system('./run_blender_script.py -s normalize_meshes.py -i ' + path_meshes + ' --scale ' + str(scale))
# Normalize collada meshes to give them the right scale and orientation
os.system('./run_blender_script.py -s normalize_meshes.py -i ' + path_meshes +
' --scale ' + str(scale))

# Import all collada meshes, decimate them and export them as stl files
os.system('./run_blender_script.py -s io_export_collision.py -i ' + path_meshes)
os.system('./run_blender_script.py -s io_export_collision.py -i ' +
path_meshes)

# Remove files left by the OGRE exporter
file_list = sorted(os.listdir(path_meshes))
for file in file_list:
if file.endswith('.mesh.xml') or file.endswith('.mesh') or file.endswith('.material'):
if file.endswith('.mesh.xml') or file.endswith('.mesh') or \
file.endswith('.material'):
print('removing ' + file)
os.remove(os.path.join(path_meshes , file))
os.remove(os.path.join(path_meshes, file))