File: //opt/kw-schueler.bak.21032025/create_usdz.py
#!/usr/bin/env python3
"""
Dieses Skript erstellt eine einfache USDZ-Datei für iOS AR Quick Look.
Es erstellt eine sehr grundlegende USD-ASCII-Datei (.usda),
die dann als ZIP-Archiv komprimiert wird (das ist im Wesentlichen, was eine USDZ-Datei ist).
"""
import os
import shutil
import zipfile
import tempfile
import subprocess
import json
# Pfade konfigurieren
OUTPUT_DIR = "static"
OUTPUT_FILE = os.path.join(OUTPUT_DIR, "radar_placeholder.usdz")
def create_simple_usda():
"""Erstellt eine einfache USD-ASCII-Datei für AR."""
with tempfile.TemporaryDirectory() as temp_dir:
# Pfad für die temporäre USDA-Datei
usda_path = os.path.join(temp_dir, "radar.usda")
# Erstelle die USDA-Datei
with open(usda_path, 'w') as f:
f.write("""#usda 1.0
(
customLayerData = {
string creator = "Klausurenweb AR Viewer"
}
metersPerUnit = 1
upAxis = "Y"
)
def Xform "RadarChart"
{
float3 xformOp:scale = (2, 2, 2)
uniform token[] xformOpOrder = ["xformOp:scale"]
def Sphere "Center"
{
color3f[] primvars:displayColor = [(0.2, 0.6, 1.0)]
float radius = 0.05
}
def Cylinder "Axis1"
{
color3f[] primvars:displayColor = [(0.7, 0.7, 0.7)]
double radius = 0.01
double height = 1.0
matrix4d xformOp:transform = ( (1, 0, 0, 0), (0, 0, 1, 0), (0, 1, 0, 0), (0, 0, 0, 1) )
uniform token[] xformOpOrder = ["xformOp:transform"]
}
def Cylinder "Axis2"
{
color3f[] primvars:displayColor = [(0.7, 0.7, 0.7)]
double radius = 0.01
double height = 1.0
matrix4d xformOp:transform = ( (0, 0, 1, 0), (0, 1, 0, 0), (1, 0, 0, 0), (0, 0, 0, 1) )
uniform token[] xformOpOrder = ["xformOp:transform"]
}
def Cylinder "Axis3"
{
color3f[] primvars:displayColor = [(0.7, 0.7, 0.7)]
double radius = 0.01
double height = 1.0
matrix4d xformOp:transform = ( (-0.5, 0, 0.866, 0), (0, 1, 0, 0), (0.866, 0, 0.5, 0), (0, 0, 0, 1) )
uniform token[] xformOpOrder = ["xformOp:transform"]
}
def Sphere "Value1"
{
color3f[] primvars:displayColor = [(1.0, 0.3, 0.3)]
float radius = 0.08
float3 xformOp:translate = (0.8, 0, 0)
uniform token[] xformOpOrder = ["xformOp:translate"]
}
def Sphere "Value2"
{
color3f[] primvars:displayColor = [(0.3, 1.0, 0.3)]
float radius = 0.08
float3 xformOp:translate = (0, 0, 0.7)
uniform token[] xformOpOrder = ["xformOp:translate"]
}
def Sphere "Value3"
{
color3f[] primvars:displayColor = [(0.3, 0.3, 1.0)]
float radius = 0.08
float3 xformOp:translate = (0.5, 0, -0.6)
uniform token[] xformOpOrder = ["xformOp:translate"]
}
def Mesh "RadarFill"
{
int[] faceVertexCounts = [3, 3]
int[] faceVertexIndices = [0, 1, 2, 0, 2, 3]
point3f[] points = [(0, 0, 0), (0.8, 0, 0), (0, 0, 0.7), (0.5, 0, -0.6)]
color3f[] primvars:displayColor = [(0.2, 0.6, 1.0)]
float opacity = 0.7
}
}
""")
# Komprimiere die USDA-Datei als ZIP
with zipfile.ZipFile(OUTPUT_FILE, 'w') as zipf:
zipf.write(usda_path, arcname=os.path.basename(usda_path))
print(f"Einfache USDZ-Datei erstellt: {OUTPUT_FILE}")
def create_advanced_usdz():
"""Versucht, eine bessere USDZ-Datei mit externen Tools zu erstellen."""
try:
# Prüfe, ob wir das Python USD-Tool installieren können
subprocess.run(["pip", "install", "--upgrade", "usd-core"], check=True)
print("USD-Core installiert. Versuche, eine bessere USDZ-Datei zu erstellen...")
# Hier könnten weitere Schritte zur Erstellung eines besseren USDZ folgen
# Dies erfordert jedoch komplexe Abhängigkeiten, die auf macOS besser funktionieren
return True
except Exception as e:
print(f"Konnte keine erweiterte USDZ-Datei erstellen: {e}")
return False
if __name__ == "__main__":
# Einfache Variante immer ausführen
os.makedirs(OUTPUT_DIR, exist_ok=True)
# Einfache USDA-Datei erstellen und als USDZ verpacken
create_simple_usda()
print(f"\nUSDZ-Datei wurde erstellt: {OUTPUT_FILE}")
print("Diese Datei kann in iOS AR Quick Look verwendet werden.")
print("\nHinweis: Für optimale Ergebnisse sollten Sie diese Datei auf einem")
print("macOS-System mit Apple's Reality Converter in ein besseres Format konvertieren.")