Jump to content

Converting coffee to python. How hard does it look to you ?


Recommended Posts

I've found some nice coffee script but there is no way to make them work on c4d r24 right ?
 

It seems like a really big script but idk if anyone tried to convert the 3d-meier scripts

 

/********************************************************************
Hadley Attraktor
Plugin für Cinema Version 12.0
(c) Jürgen Meier (info1@3d-meier.de)
Version : 1.01
04.06.2012
*********************************************************************/

// Globale Variablen und Konstanten
   // Plugin ID Nummer
      const var cPluginID = 1012281;
   // Pluginname
      const var cPlugName = "Hadley Attraktor";
   // Pluginhilfstext
      const var cPlugHelp = "Erzeugt den Hadley Attraktor";
   // Objektname
      const var cObjName = "Hadley Attraktor";
   // Index
      var i;
   // Koordinaten der Punkte
      var x,y,z;
   // Differenzen
      var dx,dy,dz;
   // Konstanten
      var a=0.20;
      var b=4.0;
      var f=8.0;
      var g=1.0;
   // Delta
      var Delta=0.005;
   // Anzahl Iterationen
      var N=20000;
   // Startwerte
      var x0=0.1;
      var y0=0.0;
      var z0=0.0;
   // Skalierungsfaktor
      var Faktor=125;
   // Breite des Menütextes
      var Breite=150;
   // Maximalwerte
      var cMaxFloat=1000000;
      var cMaxInt=100000000;
   // Objektvariable
      var qObj;
   // Dialogvariable
      var gDial;


// ******************************************************************
// Funktion zum Objekt aktivieren (c) h.g.seib
// ******************************************************************
fSetActiveObject(vDoc,vObj)
{
   // Aktives Objekt ermitteln
      var vAObj = GetActiveObject(vDoc);
   // Active object Bit bzw. Flag setzen
      if (vAObj) vAObj->DelBit(BIT_AOBJ);
          vObj->SetBit(BIT_AOBJ);
   // Änderung im Dokument bekanngeben (neues Objekt selektiert)
      GeEventAdd(NEW_ACTIVE_OBJECT);
}

// ******************************************************************
// Funktion zur Berechnung des Attraktors
   fAttraktor(vDoc)
   {
   // Variablen deklarieren
      // Felder für die Punkte des Attraktors
         var vPointAry;
      // Variable für VariableChanged und BackupTag deklarieren
         var vVarChanged,vBackupTags;
   // Neues Splineobjekt erzeugen und Namen zuweisen
      qObj=new(SplineObject);
      if (!qObj) return FALSE;
      qObj->SetName(cObjName);
   // Undo Funktion aktivieren
      vDoc->StartUndo();
      vDoc->AddUndo(UNDO_OBJECT_NEW,qObj);
      vDoc->EndUndo();
   // Variable für VariableChanged und BackupTag erzeugen
      vVarChanged = new(VariableChanged);
      vBackupTags = new(BackupTags);
   // Feld für die Punkte erzeugen
      vPointAry = new(array,N);
   // Feld für die Punkte dem Splineobjekt zuordnen
      qObj->SetPoints(vPointAry);
   // ???
      vBackupTags->Init(qObj);
      vVarChanged->Init(0,N);
   // Message der Klasse BaseList2D
      if (!qObj->Message(MSG_POINTS_CHANGED, vVarChanged))
         {
             vBackupTags->Restore();
             return FALSE;
         }
   // Objekt in der Dokumenthierarchie positionieren
      vDoc->InsertObject(qObj,NULL,NULL);
      fSetActiveObject(vDoc,qObj);
      GeEventAdd(DOCUMENT_CHANGED);
   // Variable für den Container (Klasse BaseContainer)
      var vContainer = qObj->GetContainer();
   // Spline Typ festlegen
      vContainer->SetData(SPLINEOBJECT_TYPE,3);
   // Containerdaten dem Spline Objekt zurückgeben
      qObj->SetContainer(vContainer);
   // Punkte des Attraktors berechnen
      // Startwerte übergeben
         x=x0;
         y=y0;
         z=z0;
      // Schleife durchlaufen
         for (i=0;i<N;i++)
             {
              // Delta Werte berechnen
                 dx=-y*y-z*z-a*x+a*f;
                 dy=x*y-b*x*z-y+g;
                 dz=b*x*y+x*z-z; 
              // Neue Koordinaten berechnen
                 x=x + Delta * dx;
                 y=y + Delta * dy;
                 z=z + Delta * dz;
              // Punkte setzen
                 qObj->SetPoint(i,vector(x*Faktor,z*Faktor,y*Faktor));
             }
     return TRUE;
   }

// ******************************************************************
// Ableitung der Klasse MyDialog von GeDialog
// ******************************************************************
class MyDialog : GeDialog
{
   public:
      MyDialog();
      CreateLayout();
      Init();
      CoreMessage(vID,vMSG);
      Command(vID,vMSG);
}
// ******************************************************************
// Deklaration des Konstruktors
   MyDialog::MyDialog()
   {
   // Konstruktor der parent class aufrufen
      super(cPluginID);
   }

// ******************************************************************
// Deklaration der Methode CreateLayout
   MyDialog::CreateLayout()
   {     
   // Plugintitel setzen
      SetTitle(cPlugName);
      AddStaticText(0,BFH_CENTER,200,0,cPlugName,0);
   // Waagerechte Trennlinie
      AddSeparatorH(0);
   // Gruppe für die Konstanten
      AddGroupBeginV(1000,BFH_CENTER,2,"",0);
      {
         AddStaticText(0,BFH_LEFT,Breite,0," Konstante a",0);
         AddEditNumber(2000,BFH_LEFT,100,0);
         AddStaticText(0,BFH_LEFT,Breite,0," Konstante b",0);
         AddEditNumber(2001,BFH_LEFT,100,0);
         AddStaticText(0,BFH_LEFT,Breite,0," Konstante f",0);
         AddEditNumber(2002,BFH_LEFT,100,0);
         AddStaticText(0,BFH_LEFT,Breite,0," Konstante g",0);
         AddEditNumber(2009,BFH_LEFT,100,0);
      }
      // Vertikal orientierte Gruppe schliessen
         AddGroupEnd();
   // Waagerechte Trennlinie
      AddSeparatorH(0);
   // Gruppe für die Startwerte
      AddGroupBeginV(1001,BFH_CENTER,2,"",0);
      {
         AddStaticText(0,BFH_LEFT,Breite,0," Start x",0);
         AddEditNumber(2003,BFH_LEFT,100,0);
         AddStaticText(0,BFH_LEFT,Breite,0," Start y",0);
         AddEditNumber(2004,BFH_LEFT,100,0);
         AddStaticText(0,BFH_LEFT,Breite,0," Start z",0);
         AddEditNumber(2005,BFH_LEFT,100,0);
      }
      // Vertikal orientierte Gruppe schliessen
         AddGroupEnd();
   // Waagerechte Trennlinie
      AddSeparatorH(0);
   // Gruppe für die Parameter der Iteration
      AddGroupBeginV(1002,BFH_CENTER,2,"",0);
      {
         AddStaticText(0,BFH_LEFT,Breite,0," Delta",0);
         AddEditNumber(2006,BFH_LEFT,100,0);
         AddStaticText(0,BFH_LEFT,Breite,0," Anzahl N",0);
         AddEditNumber(2007,BFH_LEFT,100,0);
         AddStaticText(0,BFH_LEFT,Breite,0," Faktor",0);
         AddEditNumber(2008,BFH_LEFT,100,0);
      }
      // Vertikal orientierte Gruppe schliessen
         AddGroupEnd();
   // Waagerechte Trennlinie
      AddSeparatorH(0);
   // Button für den Start der Berechnung
      AddButton (3000,BFH_CENTER,200,0,"Start");
      return TRUE;
   }

// ******************************************************************
// Deklaration der Methode Init
   MyDialog::Init()
   {
   // Startwerte setzen
      SetFloat(2000,a,-cMaxFloat,cMaxFloat,0);
      SetFloat(2001,b,-cMaxFloat,cMaxFloat,0);
      SetFloat(2002,f,-cMaxFloat,cMaxFloat,0);
      SetFloat(2009,g,-cMaxFloat,cMaxFloat,0);
      SetFloat(2003,x0,-cMaxFloat,cMaxFloat,0);
      SetFloat(2004,y0,-cMaxFloat,cMaxFloat,0);
      SetFloat(2005,z0,-cMaxFloat,cMaxFloat,0);
      SetFloat(2006,Delta,-cMaxFloat,cMaxFloat,0);
      SetInt(2007,N,0,cMaxInt,0);
      SetInt(2008,Faktor,0,cMaxInt,0);
      return TRUE;
   }

// ******************************************************************
// Deklaration der Methode CoreMessage
   MyDialog::CoreMessage(vID,vMSG)
   {
      switch (vID)
         {
            case NEW_DOCUMENT:
            case DOCUMENT_CHANGED:
            case NEW_ACTIVE_OBJECT:
            case ACTIVE_OBJECT_CHANGED:
            return TRUE;
            break;
         }
      return FALSE;
   }

// ******************************************************************
// Deklaration der Methode Command
   MyDialog::Command(vID,vMSG)
   {
      var vDoc;
   //
      StopAllThreads();
      switch (vID)
      {
      case 3000 : // Start Button gedrückt
                    {
                       vDoc = GetActiveDocument();
                       if (!vDoc) return FALSE;
                       fAttraktor(vDoc);
                    }
      case 2000 : a=GetFloat(2000);
      case 2001 : b=GetFloat(2001);
      case 2002 : f=GetFloat(2002);
      case 2009 : g=GetFloat(2009);
      case 2003 : x0=GetFloat(2003);
      case 2004 : y0=GetFloat(2004);
      case 2005 : z0=GetFloat(2005);
      case 2006 : Delta=GetFloat(2006);
      case 2007 : N=GetInt(2007);
      case 2008 : Faktor=GetInt(2008);
      }
      return TRUE;
   }


// ******************************************************************
// Ableitung der Klasse MyMenuPlugin von MenuPlugin
// ******************************************************************
class MyMenuPlugin : MenuPlugin
{     public:
          MyMenuPlugin();
          GetID();
          GetName();
          GetHelp();
          Execute(doc);
          RestoreLayout(secret);
}
// ******************************************************************
// Deklaration des Konstruktors
   MyMenuPlugin::MyMenuPlugin()
   { 
      super();
   }

// ******************************************************************
// Deklaration der Methode GetID
   MyMenuPlugin::GetID()
   {
      return cPluginID;
   }

// ******************************************************************
// Deklaration der Methode GetName
   MyMenuPlugin::GetName()
   {
       return cPlugName;
   }

// ******************************************************************
// Deklaration der Methode GetHelp
   MyMenuPlugin::GetHelp()
   {
       return cPlugHelp;
   }

// ******************************************************************
// Deklaration der Methode Execute
   MyMenuPlugin::Execute(doc)
   {
      if (!gDial)
         gDial=new(MyDialog);
     gDial->Open(TRUE,-1,-1);
   }
// ******************************************************************
// Deklaration der Methode RestoreLayout
   MyMenuPlugin::RestoreLayout(secret)
   {
      if (!gDial)
         gDial=new(MyDialog);
      gDial->RestoreLayout(secret);
   }

// ******************************************************************
main()
{
    Register(MyMenuPlugin);
}

 

Link to post

Looks fairly straightforward but it obviously reserves copyright so you'd need to ask the author for permission.

(And it's still a day's work; how important is that plugin to you?)

Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    No registered users viewing this page.

  • LATEST ACTIVITIES

    1. 0

      Picture viewer much brighter than viewport

    2. 4

      Make a hat fall through the air with controlable turbulence, lift and wind???

    3. 3

      Corona Renderer 7

    4. 4

      Make a hat fall through the air with controlable turbulence, lift and wind???

    5. 175

      Houdini Tests and Impressions

×
×
  • Create New...

Copyright Core 4D © 2021 Powered by Invision Community