#!/bin/bash
# ============================================================
# blender-povray.sh — Blender 3D suite + POV-Ray ray-tracer
# ============================================================
# Installs Blender (3D modelling, animation, compositing) via
# Flatpak and POV-Ray (a classic CPU ray-tracer with its own
# scene-description language) via pacman.
#
# Blender is delivered as a Flatpak to get the upstream official
# build with all drivers and Python scripting enabled.
# POV-Ray comes from the official Arch repos because it is a
# small, self-contained CLI tool with no sandboxing concerns.
#
# These are grouped together because POV-Ray integrates with
# Blender via the Blender2POVray addon, allowing Blender scenes
# to be rendered with POV-Ray's photorealistic ray-tracing.
# ============================================================

set -euo pipefail
# Load shared logging helpers and Flatpak utility functions
source "$(dirname "${BASH_SOURCE[0]}")/../../lib/logging.sh"

log "Installing Blender (Flatpak)..."

# ensure_flatpak: checks that the flatpak binary and the Flathub remote exist;
# idempotent — no-op if already set up.
ensure_flatpak

# Install Blender from Flathub. The Flatpak edition ships its own Python,
# CUDA/HIP compute libraries, and codec support pre-bundled, avoiding
# dependency conflicts with the system Python or GPU driver packages.
sudo flatpak install --system -y flathub org.blender.Blender

# apply_flatpak_theme: sets the cyberqueer GTK theme for Blender's dialogs
# (the main 3D viewport uses its own renderer, but file choosers and system
# dialogs benefit from a consistent theme).
apply_flatpak_theme "org.blender.Blender"

# ── POV-Ray via pacman ────────────────────────────────────────────────────────
# povray: the Persistence Of Vision Raytracer, a mature scene-description-
# language-based ray-tracer.  Installed system-wide so the `povray` CLI
# is available to Blender's POV-Ray export add-on and from the terminal.
log "Installing POV-Ray (pacman)..."
sudo pacman -S --noconfirm --needed povray

log "Blender and POV-Ray installed."
