normalize_meshes.py
Go to the documentation of this file.
1 #! /usr/bin/env python
2 
3 # Copyright (C) 2014 Aldebaran
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 #
17 # normalize_meshes.py
18 # Authors: Mikael Arguedas [mikael.arguedas@gmail.com]
19 
20 # Normalize all the matrix element in the collada files in a given folder
21 
22 import argparse
23 from xml.dom.minidom import parse, parseString
24 import os
25 
26 parser = argparse.ArgumentParser(usage='convert offset of all dae files in a directory')
27 parser.add_argument('-i','--input', default=None, help='inputDirectory')
28 parser.add_argument('-o','--output', default=None, help='outputDirectory')
29 parser.add_argument('-s','--scale', default=1, help='scale factor for the meshes')
30 
31 args = parser.parse_args()
32 # Check if the input directory is valid
33 directory = args.input
34 output = args.output
35 
36 # Open every collada file
37 file_list = sorted(os.listdir(directory))
38 for file in file_list:
39  if file.endswith('.dae'):
40  dom = parse(directory + '/' + file)
41  # Look for matrix element in the collada files and replace them by a scales Identity transformation matrix
42  for node in dom.getElementsByTagName('matrix'):
43  if node.nodeName == 'matrix':
44  node.firstChild.nodeValue = args.scale + " 0 0 0 0 " + args.scale + " 0 0 0 0 " + args.scale + " 0 0 0 0 1"
45  # Put relative path for textures (based on aldebaran ros packages architecture)
46  for node in dom.getElementsByTagName('init_from'):
47  if node.firstChild.nodeValue.startswith('/'):
48  node.firstChild.nodeValue= '../../texture/' +str(node.firstChild.nodeValue[node.firstChild.nodeValue.rfind('/')+1:])
49  print 'processing ' + file
50  f = open(os.path.join(directory, file),'w+')
51  # Write the modified xml file
52  f.write(dom.toxml())
53  f.close()
54 


naoqi_tools
Author(s): Mikael Arguedas
autogenerated on Thu Jul 16 2020 03:18:37