File size: 1,202 Bytes
5c45ae4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env bash
set -euo pipefail

usage() {
  cat <<'USAGE'
Usage: scripts/image_to_3d.sh -i path/to/image -o output_dir

Generates a simple OBJ mesh and stores the reference image alongside metadata.
USAGE
}

image_path=""
output_dir=""

while getopts ":i:o:h" opt; do
  case "${opt}" in
    i) image_path="${OPTARG}" ;;
    o) output_dir="${OPTARG}" ;;
    h) usage; exit 0 ;;
    \?) usage; exit 1 ;;
  esac
done

if [[ -z "${image_path}" || -z "${output_dir}" ]]; then
  usage
  exit 1
fi

if [[ ! -f "${image_path}" ]]; then
  echo "Image not found: ${image_path}" >&2
  exit 1
fi

mkdir -p "${output_dir}"
image_ext="${image_path##*.}"
reference_name="reference_image.${image_ext}"
cp "${image_path}" "${output_dir}/${reference_name}"

cat <<EOF > "${output_dir}/metadata.json"
{
  "reference_image": "${reference_name}",
  "generator": "image_to_3d.sh",
  "output": "mesh.obj"
}
EOF

cat <<'EOF' > "${output_dir}/mesh.obj"
o GPT3D_ImageMesh
v -0.5 -0.5 -0.5
v 0.5 -0.5 -0.5
v 0.5 0.5 -0.5
v -0.5 0.5 -0.5
v -0.5 -0.5 0.5
v 0.5 -0.5 0.5
v 0.5 0.5 0.5
v -0.5 0.5 0.5
f 1 2 3 4
f 5 6 7 8
f 1 2 6 5
f 2 3 7 6
f 3 4 8 7
f 4 1 5 8
EOF

echo "Generated ${output_dir}/mesh.obj from ${image_path}."