//
// Stift Göttweig – EXPERIMENTAL / STYLIZED (OpenSCAD)
// ---------------------------------------------------
// Ziel: ikonische Silhouette (Hofanlage + Türme + barocke Front)
// Nicht maßstabsgetreu – eher “architectural toy / concept model”.
//
// Tipp: F5 Preview, F6 Render, dann STL exportieren.
//

$fn = 72;

// --------- GLOBAL SCALE / LOOK ----------
scale_all = 1.0;        // gesamtes Modell skalieren
base_th   = 3;          // Grundplatte Dicke
wall_h    = 18;         // Gebäudehöhe (Flügel)
roof_h    = 6;          // Dachhöhe (Satteldächer)
court_pad = 10;         // Hof-Luft

// Grundabmessungen (mm-ish)
outer_w = 220;          // Gesamtbreite Anlage
outer_d = 170;          // Gesamttiefe Anlage
wing_t  = 22;           // Flügelstärke (Breite der Gebäuderiegel)
court_w = outer_w - 2*wing_t;
court_d = outer_d - 2*wing_t;

// Türme
tower_r = 10.5;
tower_h = 26;
dome_h  = 16;

// Barocke Front / Kirche (stark vereinfacht)
front_w = 72;
front_d = 36;
front_h = 26;
front_tower_r = 7.5;
front_tower_h = 22;

// Detail-Toggles
add_windows = true;     // optische Fensternuten (sehr stylized)
add_stairs  = true;     // Treppenrampe vorne
add_cuts    = true;     // “grafische” Schnitte (experimental)

// --------- HELPERS ----------
module chamfer_box(size=[10,10,10], c=1.5){
  // einfacher “soft” Look via Minkowski (kann Render verlangsamen)
  minkowski(){
    cube(size - [2*c,2*c,2*c], center=true);
    sphere(r=c);
  }
}

module gable_roof(w=40, d=20, h=6){
  // Satteldach als Prisma
  // Querschnitt: Dreieck
  linear_extrude(height=d, center=true)
    polygon(points=[
      [-w/2, 0],
      [ 0,   h],
      [ w/2, 0]
    ]);
}

module onion_dome(r=10, h=16){
  // “Zwiebeldach” via rotate_extrude
  // Profil (r,z) als Kurve
  rotate_extrude(convexity=10)
    polygon(points=[
      [0,   0],
      [r*0.15, 0],
      [r*0.65, h*0.30],
      [r*0.35, h*0.60],
      [r*0.55, h*0.85],
      [0,   h]
    ]);
}

module tower(pos=[0,0,0], r=10, h=26, dh=16){
  translate(pos){
    // Turmschaft
    cylinder(r=r, h=h);
    // “Laterne”
    translate([0,0,h]) cylinder(r=r*0.55, h=3);
    // Kuppel
    translate([0,0,h+3]) onion_dome(r=r*0.85, h=dh);
    // Kreuz/Spitze
    translate([0,0,h+3+dh]) cylinder(r=0.7, h=6);
  }
}

module wing_block(w=100, d=22, h=18, roof=6, roof_dir="x"){
  // Basis
  translate([0,0,h/2]) cube([w,d,h], center=true);

  // Dach (Satteldach)
  if(roof_dir=="x"){
    translate([0,0,h + roof/2])
      rotate([0,90,0]) gable_roof(w=d*1.05, d=w, h=roof);
  } else {
    translate([0,0,h + roof/2])
      gable_roof(w=w*1.00, d=d, h=roof);
  }
}

module window_grooves(w=100, d=22, h=18, n=10, side="long"){
  // leichte Nuten als “Fenster-Rhythmus”
  // wird via difference() abgezogen
  gro_w = 3.2;
  gro_h = 7.5;
  gro_d = 1.6;

  if(side=="long"){
    for(i=[1:n]){
      x = -w/2 + i*(w/(n+1));
      translate([x, d/2 - gro_d/2, h*0.55])
        cube([gro_w, gro_d, gro_h], center=true);
      translate([x,-d/2 + gro_d/2, h*0.55])
        cube([gro_w, gro_d, gro_h], center=true);
    }
  } else {
    for(i=[1:n]){
      y = -d/2 + i*(d/(n+1));
      translate([ w/2 - gro_d/2, y, h*0.55])
        cube([gro_d, gro_w, gro_h], center=true);
      translate([-w/2 + gro_d/2, y, h*0.55])
        cube([gro_d, gro_w, gro_h], center=true);
    }
  }
}

module baroque_front(){
  // sehr vereinfachte “Kirchenfront”: mittlerer Block + 2 kleine Türmchen
  union(){
    translate([0, 0, front_h/2]) cube([front_w, front_d, front_h], center=true);

    // “Portikus” Einschnitt
    difference(){
      translate([0, front_d*0.35, front_h*0.25])
        cube([front_w*0.55, front_d*0.40, front_h*0.55], center=true);
      translate([0, front_d*0.35, front_h*0.12])
        cube([front_w*0.35, front_d*0.55, front_h*0.45], center=true);
    }

    // Türmchen links/rechts
    translate([-front_w*0.34, 0, 0])
      tower([0,0,0], r=front_tower_r, h=front_tower_h, dh=dome_h*0.70);
    translate([ front_w*0.34, 0, 0])
      tower([0,0,0], r=front_tower_r, h=front_tower_h, dh=dome_h*0.70);
  }
}

module experimental_cuts(){
  // “grafische” Schnitte diagonal – macht es mehr “concept model”
  for(k=[0:7]){
    a = 18 + k*11;
    rotate([0,0,a])
      translate([0,0,wall_h*0.55])
        cube([outer_w*1.4, 2.2, wall_h*1.2], center=true);
  }
}

// --------- BUILD ----------
module stift_goettweig_experimental(){
  difference(){
    union(){
      // Grundplatte
      translate([0,0,base_th/2])
        chamfer_box([outer_w+40, outer_d+40, base_th], c=1.6);

      // Hofanlage (4 Flügel)
      // Nord/Süd (lange Flügel)
      translate([0,  (court_d/2 + wing_t/2), 0]) wing_block(w=outer_w, d=wing_t, h=wall_h, roof=roof_h, roof_dir="x");
      translate([0, -(court_d/2 + wing_t/2), 0]) wing_block(w=outer_w, d=wing_t, h=wall_h, roof=roof_h, roof_dir="x");

      // Ost/West (kurze Flügel)
      translate([ (court_w/2 + wing_t/2), 0, 0]) wing_block(w=wing_t, d=outer_d, h=wall_h, roof=roof_h, roof_dir="y");
      translate([-(court_w/2 + wing_t/2), 0, 0]) wing_block(w=wing_t, d=outer_d, h=wall_h, roof=roof_h, roof_dir="y");

      // “Innenhof” als abgesenkter Boden (nur optisch)
      translate([0,0,base_th + 0.8])
        cube([court_w - court_pad, court_d - court_pad, 1.6], center=true);

      // Türme (3 Stück, wie in der Silhouette)
      tower([-(outer_w/2 - wing_t*0.55), -(outer_d/2 - wing_t*0.55), base_th], r=tower_r, h=tower_h, dh=dome_h);
      tower([ (outer_w/2 - wing_t*0.55),  (outer_d/2 - wing_t*0.55), base_th], r=tower_r, h=tower_h, dh=dome_h);
      tower([0, (outer_d/2 - wing_t*0.60), base_th], r=tower_r*0.95, h=tower_h*0.95, dh=dome_h*0.95);

      // Barocke Front (unten/vorne)
      translate([0, -(outer_d/2 + front_d*0.25), base_th])
        baroque_front();

      // Treppe/Rampe vorne
      if(add_stairs){
        translate([0, -(outer_d/2 + 22), base_th])
          rotate([90,0,0])
            linear_extrude(height=44, center=true)
              polygon(points=[
                [-28,0],
                [ 28,0],
                [ 20,12],
                [-20,12]
              ]);
      }
    }

    // Fenster-Nuten
    if(add_windows){
      // Nord/Süd
      translate([0,  (court_d/2 + wing_t/2), base_th]) window_grooves(w=outer_w, d=wing_t, h=wall_h, n=18, side="long");
      translate([0, -(court_d/2 + wing_t/2), base_th]) window_grooves(w=outer_w, d=wing_t, h=wall_h, n=18, side="long");
      // Ost/West (weniger, weil schmal)
      translate([ (court_w/2 + wing_t/2), 0, base_th]) window_grooves(w=wing_t, d=outer_d, h=wall_h, n=14, side="long");
      translate([-(court_w/2 + wing_t/2), 0, base_th]) window_grooves(w=wing_t, d=outer_d, h=wall_h, n=14, side="long");
    }

    // Experimental “Cuts”
    if(add_cuts){
      translate([0,0,base_th]) experimental_cuts();
    }
  }
}

// Ausgabe
scale(scale_all) stift_goettweig_experimental();
