-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeblender
More file actions
executable file
·48 lines (40 loc) · 1.08 KB
/
deblender
File metadata and controls
executable file
·48 lines (40 loc) · 1.08 KB
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
#!/bin/sh
# Usage: ./deblender model.obj [x_trans] [y_trans] [z_trans]
# Example: ./deblender cube.obj 0 -0.5 0
if [ $# -eq 0 ]; then
echo "No input file provided."
exit 1
fi
if [ ! -f "$1" ]; then
echo "$1 doesn't exist or is not a file."
exit 1
fi
# Capture arguments (default to 0 if not provided)
TX=${2:-0}
TY=${3:-0}
TZ=${4:-0}
# Process Vertices
echo "point3d_t vs[] = {"
grep "^v " < "$1" | awk -v tx="$TX" -v ty="$TY" -v tz="$TZ" '{
printf " {.x = %.6f, .y = %.6f, .z = %.6f},\n", $2 + tx, $3 + ty, $4 + tz
}'
echo "};"
# Process Faces
echo "fs_t fs[] = {"
grep "^f " < "$1" | awk '
{
# Collect vertex indices from the line (handling v/vt/vn formats)
delete face;
idx_count = 0;
for (i = 2; i <= NF; i++) {
split($i, parts, "/");
# convert from 1-based to 0-based
idx_count++;
face[idx_count] = parts[1] - 1;
}
# Triangulate: fan from first vertex (index 1 in our 1-based awk array)
for (i = 2; i < idx_count; i++) {
print " FSN(" face[1] ", " face[i] ", " face[i+1] "),";
}
}'
echo "};"