-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodelviewer-generator.sh
72 lines (62 loc) · 1.77 KB
/
modelviewer-generator.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
63
64
65
66
67
68
69
70
71
72
#!/bin/bash
# Run this on a folder of glb files to generate model viewer template sites
# Usage: `bash modelviewer-generator.sh folder`
# Check if the directory is provided as a command line argument
if [ $# -eq 0 ]; then
echo "Please provide the directory path as a command line argument."
exit 1
fi
# Set the directory path
directory="$1"
# Find all GLB files recursively within the directory
glb_files=$(find "$directory" -type f -name "*.glb")
# Loop through all GLB files found
while IFS= read -r glb_file; do
# Extract the directory of the GLB file
glb_dir=$(dirname "$glb_file")
# Extract the base name of the GLB file
base_name=$(basename "$glb_file" .glb)
# Generate the HTML file for the current GLB
html_file="${glb_dir}/${base_name}.html"
# Create the HTML content
cat > "$html_file" <<EOL
<!DOCTYPE html>
<html>
<head>
<title>$base_name</title>
<script type="module" src="https://unpkg.com/@google/model-viewer/dist/model-viewer.min.js"></script>
<style>
html, body {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
background: transparent;
}
model-viewer {
width: 100%;
height: 100%;
touch-action: none;
--progress-bar-color: transparent;
}
.navigation {
position: absolute;
bottom: 20px;
left: 50%;
transform: translateX(-50%);
}
.navigation button {
margin: 0 10px;
}
</style>
</head>
<body>
<model-viewer src="${base_name}.glb" camera-controls tone-mapping="commerce" interaction-prompt="none" shadow-intensity="1" shadow-softness="1"></model-viewer>
<div class="navigation">
</div>
</body>
</html>
EOL
echo "Generated HTML file: $html_file"
done <<< "$glb_files"
echo "HTML files generated in the same location as GLB files."