forked from eurogroep/gzweb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webify_models.py
executable file
·61 lines (50 loc) · 1.75 KB
/
webify_models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/python
# To be deprecated and replaced by webify_models_v2.py
# A script to update gazebo models to be web-friendly.
# It converts all textures to png format and make sure they are
# stored in the [model_name]/meshes/ directory alongside the
# dae files.
import os
import subprocess
import sys
import shutil
print "**************************************"
print "* 'webify_models.py' is deprecated. *"
print "* Use 'webify_models_v2.py' instead. *"
print "**************************************"
path = sys.argv[1]
files = os.listdir(path)
find_cmd = ['find', path, '-name','*']
files = subprocess.check_output(find_cmd).split()
for file in files:
try:
path, filename = os.path.split(file)
name, format = filename.split(".")[-2:]
except:
continue # not a texture
try:
# dest_dir = path.replace('materials/textures', 'meshes')
dest_dir = path
dest_path = "%s/%s.png" % (dest_dir, name)
cmd = None
if format.lower() in ['tif', 'tga', 'tiff', 'jpeg', 'jpg', 'gif', 'png']:
if dest_path != file:
cmd = ['convert', file, dest_path]
subprocess.check_call(cmd)
mesh_dest_dir = path.replace('materials/textures', 'meshes')
if mesh_dest_dir != dest_dir:
cmd = ['cp', dest_path, mesh_dest_dir]
# if format.lower() == 'png':
# cmd = ['cp', file, mesh_dest_dir]
print cmd
subprocess.check_call(cmd)
if format.lower() in ['dae']:
sed_cmd = ["sed", "-i", "-e", 's/\.tga/\.png/g', "-e",
's/\.tiff/\.png/g', "-e", 's/\.tif/\.png/g',
"-e", 's/\.jpg/\.png/g', "-e", 's/\.jpeg/\.png/g',
"-e", 's/\.gif/\.png/g', file]
print sed_cmd
subprocess.check_call(sed_cmd)
except Exception, e:
print "error %s" % e
raise