main(doc,op)
{
  var PunktZahl = op->GetPointCount(); 
  var MorphPunktArray = op->GetPoints(); 
  
  var KnopfVerzeichnis = doc->FindObject("Knoepfe");
  if (!KnopfVerzeichnis) return;

  var ZielZahl = 1;
   var einKnopf = KnopfVerzeichnis->GetDown();
  if (!einKnopf) return;

  // Wie viele Knoepfe sind da?
  while ( einKnopf = einKnopf->GetNext() )
    ZielZahl++;

  //Arrays fuer Mimiken und Grundform (deshalb ZielZahl+1)
  var Ziel = new(array, ZielZahl+1);
  var Gewicht = new(array, ZielZahl+1);
  var GewichtSumme = 0.0;

  //Arrays fuellen
  einKnopf = KnopfVerzeichnis->GetDown();
  var j;
  for(j=1; j<=ZielZahl; j++)
  {
    if (!einKnopf) return;
    var Name = einKnopf->GetName();
    var ZielForm = doc->FindObject(Name+" Form");
    if (!ZielForm) return;
    if (ZielForm->GetPointCount() != PunktZahl) return;
    Ziel[j] = ZielForm;
  
    var Achse = doc->FindObject(Name+" Achse");
    if (!Achse) return;
    var Achsenposition = Achse->GetPosition();  
    var Knopfposition = einKnopf->GetPosition();
    Gewicht[j] = 0.5+0.5*(Knopfposition.y-Achsenposition.y)/60.0;
    GewichtSumme += Gewicht[j];

    einKnopf = einKnopf->GetNext();
  }

  Ziel[0] = doc->FindObject("Z Form");
  if (!Ziel[0]) return;
  Gewicht[0] = 1.0 - GewichtSumme;

  for (j=0; j<=ZielZahl; j++)
  {
    var ZielPunktArray = Ziel[j]->GetPoints();
    var i;
    for (i=0; i<PunktZahl; i++)
    { //in MorphPunktArray gewichtet addieren
      //zu Beginn MorphPunktArray mit 0 fuellen
      var x;
      var y;
      var z;
      if (j==0)
      {
        x=0; y=0; z=0;
      }
      else
      {
        x = MorphPunktArray[i].x;
        y = MorphPunktArray[i].y;
        z = MorphPunktArray[i].z;
      }
      x+=Gewicht[j]*ZielPunktArray[i].x;
      y+=Gewicht[j]*ZielPunktArray[i].y;
      z+=Gewicht[j]*ZielPunktArray[i].z;
      MorphPunktArray[i]=vector(x,y,z);
    }
  }
  
  op->SetPoints(MorphPunktArray); //Geometrie uebertragen
  op->Message(MSG_UPDATE); //Objekt updaten
}
