-
Notifications
You must be signed in to change notification settings - Fork 310
/
update-mass-data.sh
executable file
·62 lines (44 loc) · 1.34 KB
/
update-mass-data.sh
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
62
#!/bin/bash
usage() {
echo "Usage: update-mass-data.sh <src-dir>"
echo " src-dir: all scenes in this folder will be affected"
}
if [ "$#" -ne 1 ]; then
echo "Illegal number of parameters ($#, should be one: <src-dir>)"
usage; exit 1
else
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
SRC_DIR="$(cd "$1" && pwd)"
fi
if [ ! -d "$SRC_DIR" ]; then
echo "Wrong src-dir";
usage; exit 1
fi
files_to_update() {
/usr/bin/find "$SRC_DIR" -regex ".*\.\(scn\|xml\)$"
}
update_mass_data() {
file="$1"
sed -i -e "s/^\([ ]*<[ ]*UniformMass.*[ ]\)mass\([ ]*=.*\)$/\1vertexMass\2/g" "$file"
sed -i -e "s/^\([ ]*<[ ]*UniformMass.*[ ]\)totalmass\([ ]*=.*\)$/\1totalMass\2/g" "$file"
sed -i -e "s/^\([ ]*<[ ]*DiagonalMass.*[ ]\)mass\([ ]*=.*\)$/\1vertexMass\2/g" "$file"
rm -f "$file.bak" 2> /dev/null # Created by Windows only
}
main() {
local files_count="$(files_to_update | wc -l)"
local i=0
export filesmodified=0
files_to_update | while read file; do
i=$((i+1))
if [ ! -e "$file" ]; then
echo "$file: file not found."
continue
fi
update_mass_data "$file"
filesmodified=$((filesmodified+1))
done
echo ""
unset filesmodified
}
# Start script
main