#!/bin/sh
of=makedisk4.py

zoffs=5
yoffs_fixed=81.77792
# one step 
yoffs_step=10.8902587890625

scale=2.603153328

# Schleife unten läuft nur bis num-1, deshalb:
# 29 Figuren mit einem Winkel als wären es 30
# die fehlende Figur wird durch den offset des Laufens gefüllt,
# die 29. Figur bekommt offset 29 drauf
# Scheibe braucht aber 30 Marker!

num=30

#############################
cat<<EOF>$of
import bpy
from mathutils import Matrix, Vector

def Rad(deg):
    return (deg/360)*2*3.14159265359

def RotateAboutPoint(obj, point, axis, angle):
    translation = Vector(point)
    rotation = Matrix.Rotation(Rad(angle), 4, -Vector(axis))

    for vert in obj.data.vertices:
        if vert.select:
            vert.co = vert.co-translation
            vert.co = vert.co*rotation
            vert.co = vert.co+translation

obj = bpy.context.object
EOF

#############################
# offsets gelten nur für scale=1.6 !!!
#
offset[1]="+0.07427357882261276"
offset[2]="+0.0"
offset[3]="-0.22926855087280273"
offset[4]="-0.5965583324432373"
offset[5]="-1.0693317651748657"
offset[6]="-1.5934373140335083"
offset[7]="-2.0954179763793945"
offset[8]="-2.5341811180114746"
offset[9]="-2.9864346981048584"
offset[10]="-3.531362295150757"
offset[11]="-4.130057334899902"
offset[12]="-4.715003490447998"
offset[13]="-5.206938743591309"
offset[14]="-5.557569980621338"
offset[15]="-5.725803852081299"
offset[16]="-5.7262725830078125"
offset[17]="-5.838080883026123"
offset[18]="-6.050148963928223"
offset[19]="-6.36018180847168"
offset[20]="-6.760322570800781"
offset[21]="-7.236072540283203"
offset[22]="-7.766079902648926"
offset[23]="-8.324952125549316"
offset[24]="-8.882198333740234"
offset[25]="-9.408269882202148"
offset[26]="-9.878292083740234"
offset[27]="-10.271344184875488"
offset[28]="-10.573075294494629"
offset[29]="-10.775724411010742"

PI=3.141492654
offs_fak=`echo  | gawk "{printf(\"%f\", (-1.0)*$scale/1.6)}"`
#for i in `seq 1 $num`
for i in `seq 1 $(($num-1))`
do
  yoffs=${yoffs_fixed}
  fnum=`printf "%02d" $(($i*2-1))`
  objname="F$fnum"
  fn="\"C:\\\\cygwin\\\\home\\\\tkrawuts\\\\blender\\\\f${fnum}.stl\""
  rotdeg=`echo  | gawk "{printf(\"%f\",(360/$num)*($i-1)) }"`
  rotdeg=`echo  | gawk "{printf(\"%f\", $rotdeg + 360*($offs_fak*${offset[$i]}/(2*$PI*$yoffs_fixed)) )}"`
  echo "$fn : rotate $rotdeg degree, yoffs: $yoffs"

cat<<EOF>>$of
bpy.ops.import_mesh.stl(filepath=$fn)
f$fnum=bpy.data.objects['$objname']
RotateAboutPoint(f$fnum, (0,0,0), (1,0,0), 270)
RotateAboutPoint(f$fnum, (0,0,0), (0,1,0), 270)

f$fnum.location.y=$yoffs
f$fnum.location.z=$zoffs
f$fnum.scale.xyz=$scale
RotateAboutPoint(f$fnum, (0,-($yoffs/$scale),0), (0,0,1), $rotdeg)


EOF
done

