normalize_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 # normalize_meshes.py
00018 # Authors: Mikael Arguedas [mikael.arguedas@gmail.com]
00019 
00020 # Normalize all the matrix element in the collada files in a given folder
00021 
00022 import argparse
00023 from xml.dom.minidom import parse, parseString
00024 import os
00025 
00026 parser = argparse.ArgumentParser(usage='convert offset of all dae files in a directory')
00027 parser.add_argument('-i','--input', default=None, help='inputDirectory')
00028 parser.add_argument('-o','--output', default=None, help='outputDirectory')
00029 parser.add_argument('-s','--scale', default=1, help='scale factor for the meshes')
00030 
00031 args = parser.parse_args()
00032 # Check if the input directory is valid
00033 directory = args.input
00034 output = args.output
00035 
00036 # Open every collada file
00037 file_list = sorted(os.listdir(directory))
00038 for file in file_list:
00039     if file.endswith('.dae'):
00040         dom = parse(directory + '/' + file)
00041         # Look for matrix element in the collada files and replace them by a scales Identity transformation matrix
00042         for node in dom.getElementsByTagName('matrix'):
00043             if node.nodeName == 'matrix':
00044                 node.firstChild.nodeValue = args.scale + " 0 0 0 0 " + args.scale + " 0 0 0 0 " + args.scale + " 0 0 0 0 1"
00045         # Put relative path for textures (based on aldebaran ros packages architecture)
00046         for node in dom.getElementsByTagName('init_from'):
00047             if node.firstChild.nodeValue.startswith('/'):
00048                 node.firstChild.nodeValue= '../../texture/' +str(node.firstChild.nodeValue[node.firstChild.nodeValue.rfind('/')+1:])
00049         print 'processing ' + file
00050         f = open(os.path.join(directory, file),'w+')
00051         # Write the modified xml file
00052         f.write(dom.toxml())
00053         f.close()
00054 


naoqi_tools
Author(s): Mikael Arguedas
autogenerated on Sat Jun 8 2019 20:30:21