Feedback

Please leave feedback and comments. I am always interested to hear how people get on using these LScripts!
Showing posts with label Modeler. Show all posts
Showing posts with label Modeler. Show all posts

Thursday, 12 April 2018

LScript - Modeler_Compound


LScript (Modeler) to offset points based on total offset by compounding across selected points.

Compatible with Newtek LightWave 9.6 and above.

// LScript Modeler - www.StephenCulley.co.uk
//
// web   address: http://www.stephenculley.co.uk
// email address: email@stephenculley.co.uk

/*  
    LScript Modeler - Compound

    Modeler_Compound.ls

*/

@version 2.2
@warnings
@script modeler
@name *Compound

    // Title
    sTitle = "*Compound";

    // Version
    sVersion = "v1.0";
    
    ctrl_c0, ctrl_c1, ctrl_c2, ctrl_c3;

main
{

    // Store
    bAxisX = recall("bAxisX",true);
    bAxisY = recall("bAxisY",false);
    bAxisZ = recall("bAxisZ",false);
    fDistance = recall("fDistance",0.0);

    reqbegin(sTitle + " " + sVersion);

    // Reset
    ctrl_res0 = ctlbutton("Reset",50,"button_reset"); // Button Reset
    ctlsep();

    // Control
    ctrl_c0 = ctlcheckbox("X", bAxisX);
    ctrl_c1 = ctlcheckbox("Y", bAxisY);
    ctrl_c2 = ctlcheckbox("Z", bAxisZ);
    ctrl_c3 = ctldistance("Distance",fDistance);

    // Developer
    ctlsep();
    ctrl_dev0 = ctltext("","developer: Stephen Culley","http://www.stephenculley.co.uk");

    return if !reqpost();

    bAxisX = getvalue(ctrl_c0); // X
    bAxisY = getvalue(ctrl_c1); // Y
    bAxisZ = getvalue(ctrl_c2); // Z
    fDistance = getvalue(ctrl_c3); // Distance

    // Store
    store("bAxisX",bAxisX); // X
    store("bAxisY",bAxisY); // Y
    store("bAxisZ",bAxisZ); // Z
    store("fDistance",fDistance); // Distance

    // Selection - Point (DIRECT)
    selmode(DIRECT);
    iPointCount = pointcount();
    if(iPointCount <= 1) error("None or not enough points selected.");

    undogroupbegin(); // Undo

    moninit(iPointCount,"Processing...");  // Progress Monitor

    vStep = <fDistance / (iPointCount - 1),fDistance / (iPointCount - 1),fDistance / (iPointCount - 1)>; 
    vCompound = <0.0,0.0,0.0>; // Compound

    editbegin();

        for(iCurrentPoint = 1; iCurrentPoint <= iPointCount; iCurrentPoint++)
          {
          vPoint = pointinfo(points[iCurrentPoint]);
          if(bAxisX) vPoint.x = vPoint.x + vCompound.x; // X
          if(bAxisY) vPoint.y = vPoint.y + vCompound.y; // Y
          if(bAxisZ) vPoint.z = vPoint.z + vCompound.z; // Z
          pointmove(points[iCurrentPoint],vPoint); // Move point           

          // Compound
          vCompound += vStep;

          monstep(); // Progress Monitor
          }

    editend();

    undogroupend(); // Undo
}

button_reset
{
    setvalue(ctrl_c0,true); // X
    setvalue(ctrl_c1,false); // Y
    setvalue(ctrl_c2,false); // Z
    setvalue(ctrl_c3,0.0); // Distance
}
All scripts available at my Google Drive at
https://drive.google.com/open?id=1cR_q2GVUAJHumic1-A3eXV16acQnVTWs

Saturday, 3 March 2018

LScript - Modeler_Converge


LScript (Modeler) to align points based on last or previous selected or average points.

Compatible with Newtek LightWave 9.6 and above.

// LScript Modeler - www.StephenCulley.co.uk
//
// web   address: http://www.stephenculley.co.uk
// email address: email@stephenculley.co.uk

/*  
    LScript Modeler - Converge

    Modeler_Converge.ls

*/

@version 2.2
@warnings
@script modeler
@name *Converge

    // Title
    sTitle = "*Converge";

    // Version
    sVersion = "v1.0";
    
    ctrl_c0, ctrl_c1, ctrl_c2, ctrl_c3;

main
{

    // Store
    bAxisX = recall("bAxisX",true);
    bAxisY = recall("bAxisY",false);
    bAxisZ = recall("bAxisZ",false);
    iSelected = recall("iSelected",1);

    reqbegin(sTitle + " " + sVersion);

    // Reset
    ctrl_res0 = ctlbutton("Reset",50,"button_reset"); // Button Reset
    ctlsep();

    // Control
    ctrl_c0 = ctlcheckbox("X", bAxisX);
    ctrl_c1 = ctlcheckbox("Y", bAxisY);
    ctrl_c2 = ctlcheckbox("Z", bAxisZ);
    ctrl_c3 = ctlchoice("Selected",iSelected,@"First","Last","Average"@);

    // Developer
    ctlsep();
    ctrl_dev0 = ctltext("","developer: Stephen Culley","http://www.stephenculley.co.uk");

    return if !reqpost();

    bAxisX = getvalue(ctrl_c0); // X
    bAxisY = getvalue(ctrl_c1); // Y
    bAxisZ = getvalue(ctrl_c2); // Z
    iSelected = getvalue(ctrl_c3); // Selected

    // Store
    store("bAxisX",bAxisX); // X
    store("bAxisY",bAxisY); // Y
    store("bAxisZ",bAxisZ); // Z
    store("iSelected",iSelected);

    // Selection - Point (DIRECT)
    selmode(DIRECT);
    iPointCount = pointcount();
    if(iPointCount <= 1) error("None or not enough points selected.");

    undogroupbegin(); // Undo

    moninit(iPointCount,"Processing...");  // Progress Monitor

    editbegin();

        if(iSelected == 1) vConvergePoint = pointinfo(points[1]); // First
        if(iSelected == 2) vConvergePoint = pointinfo(points[iPointCount]); // Last
        if(iSelected == 3) // Average
          {
          vConvergePoint = <0 .0="">;
          for(iCurrentPoint = 1; iCurrentPoint <= iPointCount; iCurrentPoint++)
            {
            vConvergePoint += pointinfo(points[iCurrentPoint]);  
            }
          // Resize by points
          vConvergePoint *= 1 / (iPointCount - 1);
          } 

        for(iCurrentPoint = 1; iCurrentPoint <= iPointCount; iCurrentPoint++)
          {
          vPoint = pointinfo(points[iCurrentPoint]);
          if(bAxisX) vPoint.x = vConvergePoint.x; // X
          if(bAxisY) vPoint.y = vConvergePoint.y; // Y
          if(bAxisZ) vPoint.z = vConvergePoint.z; // Z
          pointmove(points[iCurrentPoint],vPoint); // Move point           

          monstep(); // Progress Monitor
          }

    editend();

    undogroupend(); // Undo
}

button_reset
{
    setvalue(ctrl_c0,true); // X
    setvalue(ctrl_c1,false); // Y
    setvalue(ctrl_c2,false); // Z
    setvalue(ctrl_c3,1); // Selected
}
All scripts available at my Google Drive at
https://drive.google.com/open?id=1cR_q2GVUAJHumic1-A3eXV16acQnVTWs

Friday, 27 January 2017

LScript - Modeler_Offset


LScript (Modeler) to offset the position of selected point based on a the position of a second selected point.

Compatible with Newtek LightWave 9.6 and above.

// LScript Modeler - www.StephenCulley.co.uk
//
// web   address: http://www.stephenculley.co.uk
// email address: email@stephenculley.co.uk

/*  
    LScript Modeler - Offset

    Modeler_Offset.ls

*/

@version 2.2
@warnings
@script modeler
@name *Offset

    // Title
    sTitle = "*Offset";

    // Version
    sVersion = "v1.0";

    bDone = false; // Done

    nX,nY,nZ;
    vOffset;    

    ctrl_c0,ctrl_c1,ctrl_c2;
    ctrl_res0;

main
{
    // Selection - Point (DIRECT)
    selmode(DIRECT);
    iPointCount = pointcount();
    if(iPointCount < 2) error("Select two points.");

    editbegin();

      vOffset = pointinfo(points[1]) - pointinfo(points[2]);

    editend();

    nX = vOffset.x;
    nY = vOffset.y;
    nZ = vOffset.z;

    process(); // Process

    reqbegin(sTitle + " " + sVersion);

    // Reset
    ctrl_res0 = ctlbutton("Reset",50,"button_reset"); // Button Reset
    ctlsep();

    // Control    
    ctrl_c0 = ctldistance("X",nX);
    ctrl_c1 = ctldistance("Y",nY);
    ctrl_c2 = ctldistance("Z",nZ);

    // Developer
    ctlsep();
    ctrl_dev0 = ctltext("","developer: Stephen Culley","http://www.stephenculley.co.uk");

    // Refresh
    ctlrefresh(ctrl_c0,"refresh");
    ctlrefresh(ctrl_c1,"refresh");
    ctlrefresh(ctrl_c2,"refresh");

    if (!reqpost())
    {
        // Cancel

        if(bDone){undo();} // Undo

        return;
    }
    else
    {
        // Ok

        if(!bDone || bChange) // Process
        {
        values(); // Values
        process(); // Process
        }

    }

    reqend();
}

refresh:value
{
    bChange = true; // Change
    values(); // Values
    process(); // Process
}

values
{
    nX = getvalue(ctrl_c0); // X
    nY = getvalue(ctrl_c1); // Y
    nZ = getvalue(ctrl_c2); // Z
}

button_reset
{
    setvalue(ctrl_c0,vOffset.x); // X
    setvalue(ctrl_c1,vOffset.y); // Y
    setvalue(ctrl_c2,vOffset.z); // Z
}

process
{
    // Undo
    if(bDone){undo();}
    undogroupbegin();

    // Process

    // Selection - Point (DIRECT)
    selmode(DIRECT);
    iPointCount = pointcount();
    if(iPointCount < 2) error("Select two points.");

    editbegin();

      vPosition = pointinfo(points[2]);
      pointmove(points[1],vPosition + ); // Move point           

    editend();

    // Undo
    undogroupend();

    bChange = false; // Change

    // Done
    bDone = true;
}
All scripts available at my Google Drive at
https://drive.google.com/open?id=1cR_q2GVUAJHumic1-A3eXV16acQnVTWs

Saturday, 14 September 2013

LScript - Modeler_PointNormalToSkelegon


LScript (Modeler) to create skelegons based on the normals at point locations.

Compatible with Newtek LightWave 9.6 and above.

// LScript Modeler - www.StephenCulley.co.uk
//
// web   address: http://www.stephenculley.co.uk
// email address: email@stephenculley.co.uk

/*  
    LScript Modeler - Point Normal To Skelegon

    Modeler_PointNormalToSkelegon.ls

*/

@version 2.2
@warnings
@script modeler
@name *Point Normal To Skelegon

    // Title
    sTitle = "*Point Normal To Skelegon";

    // Version
    sVersion = "v1.0";

    // Variable
    aSelectedPoints = nil;

    ctrl_c0;

main
{

    // Store
    nSize = recall("nSize",0.1); 

    reqbegin(sTitle + " " + sVersion);

    // Reset
    ctrl_res0 = ctlbutton("Reset",50,"button_reset"); // Button Reset
    ctlsep();

    // Control
    ctrl_c0 = ctldistance("Size",nSize);

    // Developer
    ctlsep();
    ctrl_dev0 = ctltext("","developer: Stephen Culley","http://www.stephenculley.co.uk");

    return if !reqpost();

    nSize = getvalue(ctrl_c0);

    // Store
    store("nSize",nSize);

    // Selection - Point (DIRECT)
    selmode(DIRECT);
    iPointCount = pointcount();
    if(iPointCount < 1) error("None or not enough points selected.");

    editbegin();

        aSelectedPoints = points; // Store points for later use

        foreach(iSelectedPoint,aSelectedPoints)
          {
          aPolygons = nil;
          aPolygons = iSelectedPoint.polygon();
          // Error
          if(aPolygons == nil) error("Points must be connected to polygons.");
          foreach(iPolygons,aPolygons)
            {
            aPoints = nil;
            aPoints = polyinfo(iPolygons);
            // Error
            if(sizeof(aPoints) < 4) error("Polygons need a minimum of 3 points.");
          }
        }

    editend();

    undogroupbegin(); // Undo

    moninit(iPointCount,"Processing...");  // Progress Monitor

        foreach(iSelectedPoint,aSelectedPoints)
          {

    // Selection - Point (GLOBAL)
    selmode(GLOBAL);

    editbegin();

          vNorm = pointnormal(iSelectedPoint);   
          i1 = addpoint(pointinfo(iSelectedPoint)); // Returns ID
          i2 = addpoint(vNorm * nSize + pointinfo(iSelectedPoint)); // Returns ID
          aNormalPolygon[1] = i1;
          aNormalPolygon[2] = i2;
          iPolygon = addpolygon(aNormalPolygon);

    editend(); 

          // Selection - Polygon (USER)
          selmode(USER);

          selpolygon(CLEAR); 
          selpolygon(SET,POLYID,iPolygon);
          cmdseq("MakeSkelegons");
          delete(); 

          monstep(); // Progress Monitor
          }

    undogroupend(); // Undo

    info(iPointCount," skelegon(s) added.");
}

button_reset
{
    setvalue(ctrl_c0,0.1); // Size
}

pointnormal: point // v
{
    v = <0.0,0.0,0.0>;
    aPolygons = point.polygon();
    iPolygonCount = size(aPolygons);
    for(p = 1; p <= iPolygonCount; p++)
      {
      v += polynormal(aPolygons[p]);          
      }
    v /= iPolygonCount;
    return(normalize3D(v));
}

// INTERPOLATION

linear1D: n1,n2,i // i = interpolation point (0-1)
{
    return(n1 * (1 - i) + n2 * i);     
}

// VECTOR 3D

crossproduct3D: v1,v2 // v
{
    // Vector
    return();
}

distance3D: v1, v2 // n
{
    // Vector
    return(sqrt(((v2.x - v1.x) * (v2.x - v1.x)) +
                ((v2.y - v1.y) * (v2.y - v1.y)) + 
                ((v2.z - v1.z) * (v2.z - v1.z))));
}

magnitude3D: v // n
{
    // Vector
    return(sqrt((v.x * v.x) + (v.y * v.y) + (v.z * v.z)));
}

normalize3D: v // v
{
    // Vector normalize to 0 - 1
    nMagnitude = magnitude3D(v);
    if(nMagnitude <> 0) nMagnitude = 1 / nMagnitude;
    return(v * nMagnitude);
}


All scripts available at my Google Drive at
https://drive.google.com/open?id=1cR_q2GVUAJHumic1-A3eXV16acQnVTWs

Monday, 4 February 2013

LScript - Modeler_Poke

LScript (Modeler) that replicates poke in Maya to split polygons with an averaged center.

Changes

Compatible with Newtek LightWave 9.6 and above.

// LScript Modeler - www.StephenCulley.co.uk
//
// web   address: http://www.stephenculley.co.uk
// email address: email@stephenculley.co.uk

/*  
    LScript Modeler - Poke

    Modeler_Poke.ls

*/

@version 2.2
@warnings
@script modeler
@name *Poke

    // Title
    sTitle = "*Poke";

    // Version
    sVersion = "v1.1";

main
{
    // Selection - Polygon (DIRECT)
    selmode(DIRECT);
    iPolyCount = polycount();

    if(iPolyCount[1] < 1) error("No polygons selected.");

    undogroupbegin(); // Undo

    editbegin();

    if(iPolyCount[1] >= 1)
      { 
       
      foreach(aPolygon,polygons)
       {
        aPoints = polyinfo(aPolygon); 
        rempoly(aPolygon);
        vAverage = <0.0,0.0,0.0>;
        for(iPointCount = 2; iPointCount <= sizeof(aPoints); iPointCount++)
          {
          vAverage += pointinfo(aPoints[iPointCount]);  
          }
        // Resize by points
        vAverage *= 1 / (sizeof(aPoints) - 1);
        // Make new point
        iAverage = addpoint(vAverage); // Returns ID

        // Add polygons
        for(iPointCount = 2; iPointCount <= sizeof(aPoints) - 1; iPointCount++)
          {
          aNewPolygon[1] = aPoints[iPointCount]; 
          aNewPolygon[2] = aPoints[iPointCount + 1]; 
          aNewPolygon[3] = iAverage; 
          addpolygon(aNewPolygon);  
          }
        aNewPolygon[1] = aPoints[sizeof(aPoints)]; 
        aNewPolygon[2] = aPoints[2]; 
        aNewPolygon[3] = iAverage; 
        addpolygon(aNewPolygon);             
        }

      }

    editend();

    undogroupend(); // Undo

    info(iPolyCount[1]," poly(s) poked.");
}


All scripts available at my Google Drive at
https://drive.google.com/open?id=1cR_q2GVUAJHumic1-A3eXV16acQnVTWs

Saturday, 24 March 2012

LScript - Modeler_Jitter


LScript (Modeler) to offsets vertices based on chosen parameters such as noise and Brownian motion.

Changes

  • Seeded noise
  • Seeded fractal Brownian motion
  • Added control reset
  • Realtime Preview

Compatible with Newtek LightWave 9.6 and above.

// LScript Modeler - www.StephenCulley.co.uk
//
// web   address: http://www.stephenculley.co.uk
// email address: email@stephenculley.co.uk

/*  
    LScript Modeler - Jitter

    Modeler_Jitter.ls

*/

@version 2.2
@warnings
@script modeler
@name *Jitter

    // Title
    sTitle = "*Jitter";

    // Version
    sVersion = "v2.0";
 
    bDone = false; // Done
    bChange = false; // Change
    bPreview; // Preview
    iType;
    bAxisX;
    bAxisY;
    bAxisZ;
    nAmplitude;
    iOctaves;
    nPersistence;
    vScale;
    iSeed;
    iInterpolation;
   
    ctrl_c0,ctrl_c1,ctrl_c2,ctrl_c3,ctrl_c4,ctrl_c5,ctrl_c6,ctrl_c7,ctrl_c8,ctrl_c9;
    ctrl_res0;
    ctrl_prev0;

main
{

    // Recall
    bPreview = recall("bPreview",true);
    iType = recall("iType",2);
    bAxisX = recall("bAxisX",true);
    bAxisY = recall("bAxisY",true);
    bAxisZ = recall("bAxisZ",true);
    nAmplitude = recall("nAmplitude",0.1);
    iOctaves = recall("iOctaves",3);
    nPersistence = recall("nPersistence",0.25);
    vScale = recall("vScale",<1.0,1.0,1.0>);
    iSeed = recall("iSeed",1);
    iInterpolation = recall("iInterpolation",3);

    reqbegin(sTitle + " " + sVersion);

    // Reset / Preview
    ctrl_res0 = ctlbutton("Reset",50,"button_reset"); // Button Reset
    ctrl_prev0 = ctlcheckbox("Preview",bPreview); // Preview
    ctlsep();

    // Control
    ctrl_c0 = ctlchoice("Type",iType,@"Noise","fBm"@); // Type
    ctrl_c1 = ctlcheckbox("X",bAxisX); // X
    ctrl_c2 = ctlcheckbox("Y",bAxisY); // Y
    ctrl_c3 = ctlcheckbox("Z",bAxisZ); // Z
    ctrl_c4 = ctldistance("Amplitude",nAmplitude); // Amplitude
    ctrl_c5 = ctlslider("Octaves",iOctaves,1,64); // Octaves
    ctrl_c6 = ctlnumber("Persistence",nPersistence); // Persistence
    ctrl_c7 = ctlvector("Scale",vScale); // Scale
    ctrl_c8 = ctlinteger("Seed",iSeed); // Seed
    ctrl_c9 = ctlchoice("Interpolation",iInterpolation,@"None","Linear","Cosine"@); // Interpolation

    // Developer
    ctlsep();
    ctrl_dev0 = ctltext("","developer: Stephen Culley","http://www.stephenculley.co.uk");

    process(); // Process

    // Refresh
    ctlrefresh(ctrl_prev0,"refresh");
    ctlrefresh(ctrl_c0,"refresh");
    ctlrefresh(ctrl_c1,"refresh");
    ctlrefresh(ctrl_c2,"refresh");
    ctlrefresh(ctrl_c3,"refresh");
    ctlrefresh(ctrl_c4,"refresh");
    ctlrefresh(ctrl_c5,"refresh");
    ctlrefresh(ctrl_c6,"refresh");
    ctlrefresh(ctrl_c7,"refresh");
    ctlrefresh(ctrl_c8,"refresh");
    ctlrefresh(ctrl_c9,"refresh");

    if (!reqpost())
    {
        // Cancel

        if(bDone){undo();} // Undo

        return;
    }
    else
    {
        // Ok

        if(!bDone || bChange) // Process
        {
        values(); // Values
        process(); // Process
        }

        // Store
        store("bPreview",bPreview);
        store("iType",iType);
        store("bAxisX",bAxisX);
        store("bAxisY",bAxisY);
        store("bAxisZ",bAxisZ);
        store("nAmplitude",nAmplitude);
        store("iOctaves",iOctaves);
        store("nPersistence",nPersistence);
        store("vScale",vScale);
        store("iSeed",iSeed);
        store("iInterpoltation",iInterpolation);
    }

    reqend();
}

refresh:value
{
    bChange = true; // Change
    values(); // Values
    if(bPreview){process();} // Process
}

values
{
    bPreview = getvalue(ctrl_prev0); // Preview
    iType = getvalue(ctrl_c0); // Type
    bAxisX = getvalue(ctrl_c1); // X
    bAxisY = getvalue(ctrl_c2); // Y
    bAxisZ = getvalue(ctrl_c3); // Z
    nAmplitude = getvalue(ctrl_c4); // Amplitude
    iOctaves = getvalue(ctrl_c5); // Octaves
    nPersistence = getvalue(ctrl_c6); // Persistence
    vScale = getvalue(ctrl_c7); // Scale
    iSeed = getvalue(ctrl_c8); // Seed 
    iInterpolation = getvalue(ctrl_c9); // Interpolation
}

button_reset
{
    setvalue(ctrl_c0,2); // Type
    setvalue(ctrl_c1,true); // X
    setvalue(ctrl_c2,true); // Y
    setvalue(ctrl_c3,true); // Z
    setvalue(ctrl_c4,0.1); // Amplitude
    setvalue(ctrl_c5,3); // Octaves
    setvalue(ctrl_c6,0.25); // Persistence
    setvalue(ctrl_c7,<1.0,1.0,1.0>); // Scale
    setvalue(ctrl_c8,1); // Seed
    setvalue(ctrl_c9,3); // Interpolation
}

process
{
    // Undo
    if(bDone){undo();}
    undogroupbegin();

    // Process

    // Selection - Point (DIRECT)
    selmode(DIRECT);
    iPointCount = pointcount();
    if(iPointCount < 1) error("No points selected.");

    noiseseed(iSeed); // Noise Seed

    for(iO = 1; iO <= 3; iO++)
      {
      aOffset[iO] = ;
      }

    editbegin();

        if((iType == "1") && (iInterpolation == 1)) // Noise
          {
          moninit(iPointCount,"Processing...");  // Progress Monitor
          for(iCurrentPoint = 1; iCurrentPoint <= iPointCount; iCurrentPoint++)
            {
            vOffset = <0.0,0.0,0.0>;
            vPoint = pointinfo(points[iCurrentPoint]) * vScale;
            if(bAxisX){vOffset.x = noise3D(vPoint + aOffset[1]);}
            if(bAxisY){vOffset.y = noise3D(vPoint + aOffset[2]);}
            if(bAxisZ){vOffset.z = noise3D(vPoint + aOffset[3]);}
            pointmove(points[iCurrentPoint],pointinfo(points[iCurrentPoint]) + (vOffset * nAmplitude)); // Move point  
            monstep(); // Progress Monitor
            }
          monend(); // Progress Monitor
          } 

        else if((iType == "1") && (iInterpolation == 2)) // Linear Noise
          {
          moninit(iPointCount,"Processing...");  // Progress Monitor
          for(iCurrentPoint = 1; iCurrentPoint <= iPointCount; iCurrentPoint++)
            {
            vOffset = <0.0,0.0,0.0>;
            vPoint = pointinfo(points[iCurrentPoint]) * vScale;
            if(bAxisX){vOffset.x = linearnoise3D(vPoint + aOffset[1]);}
            if(bAxisY){vOffset.y = linearnoise3D(vPoint + aOffset[2]);}
            if(bAxisZ){vOffset.z = linearnoise3D(vPoint + aOffset[3]);}
            pointmove(points[iCurrentPoint],pointinfo(points[iCurrentPoint]) + (vOffset * nAmplitude)); // Move point  
            monstep(); // Progress Monitor
            }
          monend(); // Progress Monitor
          }

        else if((iType == "1") && (iInterpolation == 3)) // Cosine Noise
          {
          moninit(iPointCount,"Processing...");  // Progress Monitor
          for(iCurrentPoint = 1; iCurrentPoint <= iPointCount; iCurrentPoint++)
            {
            vOffset = <0.0,0.0,0.0>;
            vPoint = pointinfo(points[iCurrentPoint]) * vScale;
            if(bAxisX){vOffset.x = cosinenoise3D(vPoint + aOffset[1]);}
            if(bAxisY){vOffset.y = cosinenoise3D(vPoint + aOffset[2]);}
            if(bAxisZ){vOffset.z = cosinenoise3D(vPoint + aOffset[3]);}
            pointmove(points[iCurrentPoint],pointinfo(points[iCurrentPoint]) + (vOffset * nAmplitude)); // Move point  
            monstep(); // Progress Monitor
            }
          monend(); // Progress Monitor
          }  

        else if((iType == "2") && (iInterpolation == 1)) // fBm Noise
          {
          moninit(iPointCount,"Processing...");  // Progress Monitor
          for(iCurrentPoint = 1; iCurrentPoint <= iPointCount; iCurrentPoint++)
            {
            vOffset = <0.0,0.0,0.0>;
            vPoint = pointinfo(points[iCurrentPoint]) * vScale;
            if(bAxisX){vOffset.x = fBmnoise3D(vPoint + aOffset[1],iOctaves,nPersistence);}
            if(bAxisY){vOffset.y = fBmnoise3D(vPoint + aOffset[2],iOctaves,nPersistence);}
            if(bAxisZ){vOffset.z = fBmnoise3D(vPoint + aOffset[3],iOctaves,nPersistence);}
            pointmove(points[iCurrentPoint],pointinfo(points[iCurrentPoint]) + (vOffset * nAmplitude)); // Move point  
            monstep(); // Progress Monitor
            }
          monend(); // Progress Monitor
          }  

        else if((iType == "2") && (iInterpolation == 2)) // Linear fBm Noise
          {
          moninit(iPointCount,"Processing...");  // Progress Monitor
          for(iCurrentPoint = 1; iCurrentPoint <= iPointCount; iCurrentPoint++)
            {
            vOffset = <0.0,0.0,0.0>;
            vPoint = pointinfo(points[iCurrentPoint]) * vScale;
            if(bAxisX){vOffset.x = linearfBmnoise3D(vPoint + aOffset[1],iOctaves,nPersistence);}
            if(bAxisY){vOffset.y = linearfBmnoise3D(vPoint + aOffset[2],iOctaves,nPersistence);}
            if(bAxisZ){vOffset.z = linearfBmnoise3D(vPoint + aOffset[3],iOctaves,nPersistence);}
            pointmove(points[iCurrentPoint],pointinfo(points[iCurrentPoint]) + (vOffset * nAmplitude)); // Move point  
            monstep(); // Progress Monitor
            }
          monend(); // Progress Monitor
          }

        else if((iType == "2") && (iInterpolation == 3)) // Cosine fBm Noise
          {
          moninit(iPointCount,"Processing...");  // Progress Monitor
          for(iCurrentPoint = 1; iCurrentPoint <= iPointCount; iCurrentPoint++)
            {
            vOffset = <0.0,0.0,0.0>;
            vPoint = pointinfo(points[iCurrentPoint]) * vScale;
            if(bAxisX){vOffset.x = cosinefBmnoise3D(vPoint + aOffset[1],iOctaves,nPersistence);}
            if(bAxisY){vOffset.y = cosinefBmnoise3D(vPoint + aOffset[2],iOctaves,nPersistence);}
            if(bAxisZ){vOffset.z = cosinefBmnoise3D(vPoint + aOffset[3],iOctaves,nPersistence);}
            pointmove(points[iCurrentPoint],pointinfo(points[iCurrentPoint]) + (vOffset * nAmplitude)); // Move point  
            monstep(); // Progress Monitor
            }
          monend(); // Progress Monitor
          }

    editend();

    // Undo
    undogroupend();

    bChange = false; // Change

    // Done
    bDone = true;
}

// INTERPOLATION

linear1D: n1,n2,i // i = interpolation point (0-1)
{
    return(n1 * (1 - i) + n2 * i);     
}

cosine1D: n1,n2,i // i = interpolation point (0-1)
{
    i2 = (1 - cos(i * 3.1415926535)) * 0.5;
    return(n1 * (1 - i2) + n2 * i2);     
}

// NOISE

_noiseseed = 1;
_noiseresolution = 512;
_noise = nil;
_noiseoffset = nil;
_noiseperm = nil;

noiseinit
{  
    randomseed(_noiseseed); // Random Seed
    for(iN = 1; iN <= _noiseresolution; iN++)
      {
      _noise[iN] = (random() * 2) - 1; // -1.0..1.0
      _noiseperm[iN] = wrap(1,_noiseresolution,integer(random() * _noiseresolution));
      }

    for(iO = 1; iO <= 64; iO++)
      {
      _noiseoffset[iO] = ;
      }
}

noiseseed: seed
{
    _noiseseed = seed;
    noiseinit(); // Init
}

noiseresolution: resolution
{
    _noiseresolution = resolution;
    noiseinit(); // Init 
}

noiseperm1D: n // i
{
// !    if(_noiseperm == nil){noiseinit();} // Init
    return(_noiseperm[wrap(1,_noiseresolution,integer(n))]);
}

noiseperm2D: v // n
{
    return(noiseperm1D(v.y + noiseperm1D(v.x)));
}

noiseperm3D: v // n
{
    return(noiseperm1D(v.z + noiseperm2D(v)));
}

noise3D: v // n
{
// !    if(_noise == nil){noiseinit();} // Init
    return(_noise[noiseperm3D(v)]);
}

linearnoise3D: v // n
{
    v = wrap(1,_noiseresolution,v); 
    vFrac = frac(v);
    vInt = v - vFrac;
    nA1 = noise3D();
    nA2 = noise3D();
    nA3 = noise3D();
    nA4 = noise3D();
    nA = linear1D(linear1D(nA1,nA2,vFrac.x),linear1D(nA3,nA4,vFrac.x),vFrac.z);
    nB1 = noise3D();
    nB2 = noise3D();
    nB3 = noise3D();
    nB4 = noise3D();
    nB = linear1D(linear1D(nB1,nB2,vFrac.x),linear1D(nB3,nB4,vFrac.x),vFrac.z);
    return(linear1D(nA,nB,vFrac.y));
}

cosinenoise3D: v // n
{
    v = wrap(1,_noiseresolution,v); 
    vFrac = frac(v);
    vInt = v - vFrac;
    nA1 = noise3D();
    nA2 = noise3D();
    nA3 = noise3D();
    nA4 = noise3D();
    nA = cosine1D(cosine1D(nA1,nA2,vFrac.x),cosine1D(nA3,nA4,vFrac.x),vFrac.z);
    nB1 = noise3D();
    nB2 = noise3D();
    nB3 = noise3D();
    nB4 = noise3D();
    nB = cosine1D(cosine1D(nB1,nB2,vFrac.x),cosine1D(nB3,nB4,vFrac.x),vFrac.z);
    return(cosine1D(nA,nB,vFrac.y));
}

fBmnoise3D: v,octaves,persistence // octaves = i | persistence = n (0.25) // n
{
// !    if(_noiseoffset == nil){noiseinit();} // Init
    nNoise = 0.0;
    for(iO = 1; iO <= octaves; iO++)
      {
      nNoise += noise3D(<(v.x + _noiseoffset[iO].x) * (2 * iO),(v.y + _noiseoffset[iO].y) * (2 * iO),(v.z + _noiseoffset[iO].z) * (2 * iO)>) * (persistence / iO);
      }
    return(nNoise);
}

linearfBmnoise3D: v,octaves,persistence // octaves = i | persistence = n (0.25) // n
{
// !    if(_noiseoffset == nil){noiseinit();} // Init
    nNoise = 0.0;
    for(iO = 1; iO <= octaves; iO++)
      {
      nNoise += linearnoise3D(<(v.x + _noiseoffset[iO].x) * (2 * iO),(v.y + _noiseoffset[iO].y) * (2 * iO),(v.z + _noiseoffset[iO].z) * (2 * iO)>) * (persistence / iO);
      }
    return(nNoise);
}

cosinefBmnoise3D: v,octaves,persistence // octaves = i | persistence = n (0.25) // n
{
// !    if(_noiseoffset == nil){noiseinit();} // Init
    nNoise = 0.0;
    for(iO = 1; iO <= octaves; iO++)
      {
      nNoise += cosinenoise3D(<(v.x + _noiseoffset[iO].x) * (2 * iO),(v.y + _noiseoffset[iO].y) * (2 * iO),(v.z + _noiseoffset[iO].z) * (2 * iO)>) * (persistence / iO);
      }
    return(nNoise);
}

// RANDOM

_randomseed = 0; // n Seed

randomseed: seed
{
    _randomseed = seed;
}

random
{
    n = (_randomseed * 214013 + 2531011) % 2^^24;
    _randomseed = n;
    n /= 2^^24; // 0..1
    return(n);
}

gaussianrandom
{
    n1 = random();
    n2 = random();
    if(n1 == 0.0){n1 = 0.01;}
    return(sqrt(-2.0 * log(n1)) * cos(2.0 * 3.1415926535 * n2));
}

// WRAP

wrap: min,max,n
{
    n = n - floor((n - min) / (max - min)) * (max - min);
    if(n < 0) n = n + max - min; // error check
    return(n);
}
All scripts available at my Google Drive at
https://drive.google.com/open?id=1cR_q2GVUAJHumic1-A3eXV16acQnVTWs

Friday, 10 February 2012

LScript - Modeler_Cable


LScript (Modeler) creates cables between selected points. You can select more than two points to make it create multiple cables.

All cables are UV Mapped and fully setup for animation in LightWave by just cutting and pasting the two point polys (Surface:DYNAMIC) to one layer and the cables (surface:Cable) in the next layer parenting cables to the Dynamic layer. It was designed to be converted to subdivision surfaces for rendering.

Changes

  • Added control reset
  • Realtime Preview

Compatible with Newtek LightWave 9.6 and above.

// LScript Modeler - www.StephenCulley.co.uk
//
// web   address: http://www.stephenculley.co.uk
// email address: email@stephenculley.co.uk

/*  
    LScript Modeler - Cable

    Modeler_Cable.ls

*/

@version 2.2
@warnings
@script modeler
@name *Cable

    // Title
    sTitle = "*Cable";

    // Version
    sVersion = "v2.0";
 
    bDone = false; // Done
    bChange = false; // Change
    bPreview; // Preview

    bPreview;
    nRadius;
    nRadiusRandom;
    iSegments;
    bCapEnd;
    iSeed;
    vnGravity;
    nDroop;
    nDroopRandom;
    nTurbulance;
    nTurbulanceScale;
    nTurbulanceRandom;
    nNoise;
    iUV;
   
    ctrl_c0,ctrl_c1,ctrl_c2,ctrl_c3,ctrl_c4,ctrl_c5,ctrl_c6,ctrl_c7,ctrl_c8,ctrl_c9,ctrl_c10,ctrl_c11,ctrl_c12;
    ctrl_res0;
    ctrl_prev0;

main
{

    // Recall
    bPreview = recall("bPreview",true);
    nRadius = recall("nRadius",0.05);
    nRadiusRandom = recall("nRadiusRandom",0.0);
    iSegments = recall("iSegments",20);
    bCapEnd = recall("bCapEnd",false);
    iSeed = recall("iSeed",1);
    vnGravity = recall("vnGravity",<0.0,-9.8,0.0>);
    nDroop = recall("nDroop",0.25);
    nDroopRandom = recall("nDropRandom",0.0);
    nTurbulance = recall("nTurbulance",0.0);
    nTurbulanceScale = recall("nTurbulanceScale",1.0);
    nTurbulanceRandom = recall("nTurbulanceRandom",0.1);
    nNoise = recall("nNoise",0.0);
    iUV = recall("iUV",3);

    reqbegin(sTitle + " " + sVersion);

    // Reset / Preview
    ctrl_res0 = ctlbutton("Reset",50,"button_reset"); // Button Reset
    ctrl_prev0 = ctlcheckbox("Preview",bPreview); // Preview
    ctlsep();

    // Control
    ctrl_c0 = ctldistance("Radius",nRadius);
    ctrl_c1 = ctldistance("Radius Random",nRadiusRandom);
    ctrl_c2 = ctlinteger("Segments",iSegments);
    ctrl_c3 = ctlcheckbox("Cap Ends (cross-section)",bCapEnd);
    ctlsep();
    ctrl_c4 = ctlinteger("Seed",iSeed);
    ctlsep();
    ctrl_c5 = ctlvector("Gravity",vnGravity);
    ctrl_c6 = ctlpercent("Droop",nDroop);
    ctrl_c7 = ctlpercent("Droop Random",nDroopRandom);
    ctlsep();
    ctrl_c8 = ctldistance("Turbulance",nTurbulance);
    ctrl_c9 = ctlnumber("Turbulance Scale",nTurbulanceScale);
    ctrl_c10 = ctlnumber("Turbulance Random",nTurbulanceRandom);
    ctlsep();
    ctrl_c11 = ctldistance("Noise Amount",nNoise);
    ctlsep();
    ctrl_c12 = ctlchoice("Make UVs",iUV,@"Segment","Object","Ratio (1:1)"@,false);

    // Developer
    ctlsep();
    ctrl_dev0 = ctltext("","developer: Stephen Culley","http://www.stephenculley.co.uk");

    process(); // Process

    // Refresh
    ctlrefresh(ctrl_prev0,"refresh");
    ctlrefresh(ctrl_c0,"refresh");
    ctlrefresh(ctrl_c1,"refresh");
    ctlrefresh(ctrl_c2,"refresh");
    ctlrefresh(ctrl_c3,"refresh");
    ctlrefresh(ctrl_c4,"refresh");
    ctlrefresh(ctrl_c5,"refresh");
    ctlrefresh(ctrl_c6,"refresh");
    ctlrefresh(ctrl_c7,"refresh");
    ctlrefresh(ctrl_c8,"refresh");
    ctlrefresh(ctrl_c9,"refresh");
    ctlrefresh(ctrl_c10,"refresh");
    ctlrefresh(ctrl_c11,"refresh");
    ctlrefresh(ctrl_c12,"refresh");

    if (!reqpost())
    {
        // Cancel

        if(bDone){undo();} // Undo

        return;
    }
    else
    {
        // Ok

        if(!bDone || bChange) // Process
        {
        values(); // Values
        process(); // Process
        }

        // Store
        store("bPreview",bPreview);
        store("nRadius",nRadius);
        store("nRadiusRandom",nRadiusRandom);
        store("iSegments",iSegments);
        store("bCapEnd",bCapEnd);
        store("iSeed",iSeed);
        store("vnGravity",vnGravity);
        store("nDroop",nDroop);
        store("nDropRandom",nDroopRandom);
        store("nTurbulance",nTurbulance);
        store("nTurbulanceScale",nTurbulanceScale);
        store("nTurbulanceRandom",nTurbulanceRandom);
        store("nNoise",nNoise);
        store("iUV",iUV);
    }

    reqend();
}

refresh:value
{
    bChange = true; // Change
    values(); // Values
    if(bPreview){process();} // Process
}

values
{
    bPreview = getvalue(ctrl_prev0); // Preview
    nRadius = getvalue(ctrl_c0); // n Radius
    nRadiusRandom = getvalue(ctrl_c1); // n Radius Random
    iSegments = getvalue(ctrl_c2); // i Segments
    bCapEnd = getvalue(ctrl_c3); // b Cap End
    iSeed = getvalue(ctrl_c4); // i Seed
    vnGravity = normalize3D(getvalue(ctrl_c5)); // vn Gravity
    nDroop = getvalue(ctrl_c6); // n Droop
    nDroopRandom = getvalue(ctrl_c7); // n Droop Random
    nTurbulance = getvalue(ctrl_c8); // n Turbulance
    if(getvalue(ctrl_c9) <> 0.0){nTurbulanceScale = 1 / getvalue(ctrl_c9);}else{nTurbulanceScale = 0.0;} // n Turbulance Scale
    nTurbulanceRandom = getvalue(ctrl_c10); // n Turbulance Random
    nNoise = getvalue(ctrl_c11); // n Noise
    iUV = getvalue(ctrl_c12); // i UV
}

button_reset
{
    setvalue(ctrl_c0,0.05); // Radius
    setvalue(ctrl_c1,0.0); // Radius Random
    setvalue(ctrl_c2,20); // Segments
    setvalue(ctrl_c3,false); // Cap End
    setvalue(ctrl_c4,1); // Seed
    setvalue(ctrl_c5,<0.0,-9.8,0.0>); // Gravity
    setvalue(ctrl_c6,0.25); // Droop
    setvalue(ctrl_c7,0.0); // Droop Random
    setvalue(ctrl_c8,0.0); // Turbulance
    setvalue(ctrl_c9,1.0); // Turbulance Scale
    setvalue(ctrl_c10,0.1); // Turbulance Random
    setvalue(ctrl_c11,0.0); // Noise
    setvalue(ctrl_c12,3); // UV
}

process
{
    // Undo
    if(bDone){undo();}
    undogroupbegin();

    // Process

    // Selection - Point (GLOBAL)
    selmode(GLOBAL);
    iPointCountBefore = pointcount();

    // Selection - Point (DIRECT)
    selmode(DIRECT);
    iPointCount = pointcount();
    if(iPointCount <= 1) error("None or not enough points selected.");

    if((iPointCount & 1) != 0) iPointCount--; // Check if odd

    editbegin();

        mapFIXED = VMap(VMSELECT,"FIXED",1); // Selection Map
        mapUV = VMap(VMTEXTURE,"UV_Cable",2); // UV Map

    editend();

    noiseseed(iSeed); // Noise Seed

    moninit((iPointCount / 2),"Processing...");  // Progress Monitor

    editbegin();

        for(iCablePoint = 1; iCablePoint <= iPointCount; iCablePoint += 2)
          {
        
          vStartPoint = pointinfo(points[iCablePoint]);
          vEndPoint = pointinfo(points[iCablePoint + 1]);

          if(abs(normalize3D(vEndPoint - vStartPoint)) == <0.0,1.0,0.0>)
            {
            if(vEndPoint.y <= vStartPoint.y)
              {vEndPoint += <((random() * 2) - 1) * 0.00001,0.0,((random() * 2) - 1) * 0.00001>;}
            else
              {vStartPoint += <((random() * 2) - 1) * 0.00001,0.0,((random() * 2) - 1) * 0.00001>;}
            } 

          nSegmentInc = 1 / iSegments;
          nSegment = 0.0;
          vStart = vStartPoint;
          vEnd = vEndPoint - vStartPoint;
          nRadiusMultiplier = nRadius + (random() * nRadiusRandom);
          nDroopMultiplier = (nDroop * distance3D(vStartPoint,vEndPoint)) + (random() * nDroopRandom * distance3D(vStartPoint,vEndPoint)); // Droop Noise
          vTurbulanceOffset =  * nTurbulanceRandom; // Turbulance Variance

          aPointsCable[1] = vStartPoint; // Start Point
 
          aPointsCable[iSegments + 1] = vEndPoint; // End Point 

          for(iCurrentPoint = 2; iCurrentPoint <= iSegments; iCurrentPoint++) // Middle Points
            {
            nSegment += nSegmentInc;
            // Multiplier
            nMultiplier = cos((nSegment * 3.1415926535) - 1.57079632675);
            // Droop
            aPointsCable[iCurrentPoint] = vStart + (vEnd * nSegment) + (vnGravity * nMultiplier * nDroopMultiplier);
            // Turbulance
            if(nTurbulance <> 0.0)
              {
              aPointsCable[iCurrentPoint] += cosinenoise3D((aPointsCable[iCurrentPoint] * nTurbulanceScale) + vTurbulanceOffset) * nMultiplier * nTurbulance;
              }
            // Noise
            if(nNoise <> 0.0)
              {
              aPointsCable[iCurrentPoint] += <(random() * 2) - 1,(random() * 2) - 1,(random() * 2) - 1> * nNoise;  
              }    
            }

        // Create Points

          // Start Point
          vPoint = aPointsCable[1];
          vnForward = normalize3D(aPointsCable[2] - aPointsCable[1]);
          vnUp = normalize3D(crossproduct3D(vnForward,<0.0,1.0,0.0>));
          vnRight = normalize3D(crossproduct3D(vnUp,vnForward));
          aPolygonCable[1][1] = vPoint + (vnUp * nRadiusMultiplier) + (vnRight * nRadiusMultiplier);
          aPolygonCable[1][2] = vPoint + (vnUp * nRadiusMultiplier) + (vnRight * -nRadiusMultiplier);
          aPolygonCable[1][3] = vPoint + (vnUp * -nRadiusMultiplier) + (vnRight * -nRadiusMultiplier);
          aPolygonCable[1][4] = vPoint + (vnUp * -nRadiusMultiplier) + (vnRight * nRadiusMultiplier);

          // Mid Points
          for(iCurrentPoint = 2; iCurrentPoint <= iSegments; iCurrentPoint++)
            {
            vPoint = aPointsCable[iCurrentPoint];
            vnForward = normalize3D(aPointsCable[iCurrentPoint + 1] - aPointsCable[iCurrentPoint - 1]);
            vnUp = normalize3D(crossproduct3D(vnForward,<0.0,1.0,0.0>));
            vnRight = normalize3D(crossproduct3D(vnUp,vnForward));
            aPolygonCable[iCurrentPoint][1] = vPoint + (vnUp * nRadiusMultiplier) + (vnRight * nRadiusMultiplier);
            aPolygonCable[iCurrentPoint][2] = vPoint + (vnUp * nRadiusMultiplier) + (vnRight * -nRadiusMultiplier);
            aPolygonCable[iCurrentPoint][3] = vPoint + (vnUp * -nRadiusMultiplier) + (vnRight * -nRadiusMultiplier);
            aPolygonCable[iCurrentPoint][4] = vPoint + (vnUp * -nRadiusMultiplier) + (vnRight * nRadiusMultiplier);
            }

          // End Point
          vPoint = aPointsCable[iSegments + 1];
          vnForward = normalize3D(aPointsCable[iSegments + 1] - aPointsCable[iSegments]);
          vnUp = normalize3D(crossproduct3D(vnForward,<0.0,1.0,0.0>));
          vnRight = normalize3D(crossproduct3D(vnUp,vnForward));
          aPolygonCable[iSegments + 1][1] = vPoint + (vnUp * nRadiusMultiplier) + (vnRight * nRadiusMultiplier);
          aPolygonCable[iSegments + 1][2] = vPoint + (vnUp * nRadiusMultiplier) + (vnRight * -nRadiusMultiplier);
          aPolygonCable[iSegments + 1][3] = vPoint + (vnUp * -nRadiusMultiplier) + (vnRight * -nRadiusMultiplier);
          aPolygonCable[iSegments + 1][4] = vPoint + (vnUp * -nRadiusMultiplier) + (vnRight * nRadiusMultiplier);

      editend();

    // 2 Point Poly Chain

      // Surface
      setsurface("DYNAMIC");
      changesurface("DYNAMIC");

      editbegin();

          for(iCurrentPoint = 1; iCurrentPoint <= iSegments; iCurrentPoint++)
           {
           aPoints[1] = addpoint(aPointsCable[iCurrentPoint]);
           aPoints[2] = addpoint(aPointsCable[iCurrentPoint + 1]);
           addpolygon(aPoints);
           if(iCurrentPoint == 1)
             {
             mapFIXED.setValue(aPoints[1],1);
             }
           if(iCurrentPoint == iSegments)
             {
             mapFIXED.setValue(aPoints[2],1);
             }

           aPoints = nil;
           }

      editend();

    // Polygon

      setsurface("Cable");
      changesurface("Cable");

      editbegin();

          nDistance = 0.0;
          nCircumference = 3.1415926535 * (nRadiusMultiplier * 2);

          for(iCurrentPoint = 1; iCurrentPoint <= iSegments; iCurrentPoint++)
            {
            if(iUV == 1) // UV Segment
              { 
              aUV[1] = 0.0;
              aUV[2] = 1.0;
              }
            else if(iUV == 2) // UV Object
              {
              aUV[1] = (1 / iSegments) * (iCurrentPoint - 1);
              aUV[2] = (1 / iSegments) * iCurrentPoint;
              }
            else if(iUV == 3) // UV Ratio (1:1)
              {
              aUV[1] = (1 / nCircumference) * nDistance;
              nDistance += distance3D(aPointsCable[iCurrentPoint],aPointsCable[iCurrentPoint + 1]);
              aUV[2] = (1 / nCircumference) * nDistance;
              }

            // 1
            aPoints[1] = addpoint(aPolygonCable[iCurrentPoint + 1][1]);
            aPoints[2] = addpoint(aPolygonCable[iCurrentPoint][1]);
            aPoints[3] = addpoint(aPolygonCable[iCurrentPoint][2]);
            aPoints[4] = addpoint(aPolygonCable[iCurrentPoint + 1][2]);
            addpolygon(aPoints);
            mapUV.setValue(aPoints[1],@aUV[2],0.0@);
            mapUV.setValue(aPoints[2],@aUV[1],0.0@);
            mapUV.setValue(aPoints[3],@aUV[1],0.25@);
            mapUV.setValue(aPoints[4],@aUV[2],0.25@);
            // 2
            aPoints[1] = addpoint(aPolygonCable[iCurrentPoint + 1][2]);
            aPoints[2] = addpoint(aPolygonCable[iCurrentPoint][2]);
            aPoints[3] = addpoint(aPolygonCable[iCurrentPoint][3]);
            aPoints[4] = addpoint(aPolygonCable[iCurrentPoint + 1][3]);
            addpolygon(aPoints);
            mapUV.setValue(aPoints[1],@aUV[2],0.25@);
            mapUV.setValue(aPoints[2],@aUV[1],0.25@);
            mapUV.setValue(aPoints[3],@aUV[1],0.5@);
            mapUV.setValue(aPoints[4],@aUV[2],0.5@);
            // 3
            aPoints[1] = addpoint(aPolygonCable[iCurrentPoint + 1][3]);
            aPoints[2] = addpoint(aPolygonCable[iCurrentPoint][3]);
            aPoints[3] = addpoint(aPolygonCable[iCurrentPoint][4]);
            aPoints[4] = addpoint(aPolygonCable[iCurrentPoint + 1][4]);
            addpolygon(aPoints);
            mapUV.setValue(aPoints[1],@aUV[2],0.5@);
            mapUV.setValue(aPoints[2],@aUV[1],0.5@);
            mapUV.setValue(aPoints[3],@aUV[1],0.75@);
            mapUV.setValue(aPoints[4],@aUV[2],0.75@);
            // 4
            aPoints[1] = addpoint(aPolygonCable[iCurrentPoint + 1][4]);
            aPoints[2] = addpoint(aPolygonCable[iCurrentPoint][4]);
            aPoints[3] = addpoint(aPolygonCable[iCurrentPoint][1]);
            aPoints[4] = addpoint(aPolygonCable[iCurrentPoint + 1][1]);
            addpolygon(aPoints);
            mapUV.setValue(aPoints[1],@aUV[2],0.75@);
            mapUV.setValue(aPoints[2],@aUV[1],0.75@);
            mapUV.setValue(aPoints[3],@aUV[1],1.0@);
            mapUV.setValue(aPoints[4],@aUV[2],1.0@);
 
            aPoints = nil;
            }

          // Cap End

          if(bCapEnd == 1)
            {

            editend();

            setsurface("Cable (cross-section)");
            changesurface("Cable (cross-section)");

            editbegin();

                // Start
                aPoints[1] = addpoint(aPolygonCable[1][4]);
                aPoints[2] = addpoint(aPolygonCable[1][3]);
                aPoints[3] = addpoint(aPolygonCable[1][2]);
                aPoints[4] = addpoint(aPolygonCable[1][1]);
                addpolygon(aPoints);
                mapUV.setValue(aPoints[1],@0.0,1.0@);
                mapUV.setValue(aPoints[2],@1.0,1.0@);
                mapUV.setValue(aPoints[3],@1.0,0.0@);
                mapUV.setValue(aPoints[4],@0.0,0.0@);                
                // End
                aPoints[1] = addpoint(aPolygonCable[iSegments + 1][1]);
                aPoints[2] = addpoint(aPolygonCable[iSegments + 1][2]);
                aPoints[3] = addpoint(aPolygonCable[iSegments + 1][3]);
                aPoints[4] = addpoint(aPolygonCable[iSegments + 1][4]);
                addpolygon(aPoints);
                mapUV.setValue(aPoints[1],@0.0,1.0@);
                mapUV.setValue(aPoints[2],@1.0,1.0@);
                mapUV.setValue(aPoints[3],@1.0,0.0@);
                mapUV.setValue(aPoints[4],@0.0,0.0@);                  
                aPoints = nil;
            }

          monstep(); // Progress Monitor
          }
          
    editend();

    monend(); // Progress Monitor

    // Selection - Point (GLOBAL)
    selmode(GLOBAL);
    iPointCountAfter = pointcount();
    if((iPointCountAfter - iPointCountBefore) > 0)
      {
      for(s = 1; s <= (iPointCountAfter - iPointCountBefore) ; s++){aSelection[s] = s + iPointCountBefore;}
      selmode(USER);
      selpoint(SET, POINTNDX, aSelection);

      mergepoints(0.0); // Merge Points
      }

    // Undo
    undogroupend();

    bChange = false; // Change

    // Done
    bDone = true;
}

// INTERPOLATION

cosine1D: n1,n2,i // i = interpolation point (0-1)
{
    i2 = (1 - cos(i * 3.1415926535)) * 0.5;
    return(n1 * (1 - i2) + n2 * i2);     
}

// NOISE

_noiseseed = 1;
_noiseresolution = 512;
_noise = nil;
_noiseperm = nil;

noiseinit
{  
    randomseed(_noiseseed); // Random Seed
    for(iN = 1; iN <= _noiseresolution; iN++)
      {
      _noise[iN] = (random() * 2) - 1; // -1.0..1.0
      _noiseperm[iN] = wrap(1,_noiseresolution,integer(random() * _noiseresolution));
      }
}

noiseseed: seed
{
    _noiseseed = seed;
    noiseinit(); // Init
}

noiseresolution: resolution
{
    _noiseresolution = resolution;
    noiseinit(); // Init 
}

noiseperm1D: n // i
{
// !     if(_noiseperm == nil){noiseinit();} // Init
    return(_noiseperm[wrap(1,_noiseresolution,integer(n))]);
}

noiseperm2D: v // n
{
    return(noiseperm1D(v.y + noiseperm1D(v.x)));
}

noiseperm3D: v // n
{
    return(noiseperm1D(v.z + noiseperm2D(v)));
}

noise3D: v // n
{
// !    if(_noise == nil){noiseinit();} // Init
    return(_noise[noiseperm3D(v)]);
}

cosinenoise3D: v // n
{
    v = wrap(1,_noiseresolution,v); 
    vFrac = frac(v);
    vInt = v - vFrac;
    nA1 = noise3D();
    nA2 = noise3D();
    nA3 = noise3D();
    nA4 = noise3D();
    nA = cosine1D(cosine1D(nA1,nA2,vFrac.x),cosine1D(nA3,nA4,vFrac.x),vFrac.z);
    nB1 = noise3D();
    nB2 = noise3D();
    nB3 = noise3D();
    nB4 = noise3D();
    nB = cosine1D(cosine1D(nB1,nB2,vFrac.x),cosine1D(nB3,nB4,vFrac.x),vFrac.z);
    return(cosine1D(nA,nB,vFrac.y));
}

// RANDOM

_randomseed = 0; // n Seed

randomseed: seed
{
    _randomseed = seed;
}

random
{
    n = (_randomseed * 214013 + 2531011) % 2^^24;
    _randomseed = n;
    n /= 2^^24; // 0..1
    return(n);
}

// VECTOR 3D

crossproduct3D: v1,v2 // v
{
    // Vector
    return();
}

distance3D: v1, v2 // n
{
    // Vector
    return(sqrt(((v2.x - v1.x) * (v2.x - v1.x)) +
                ((v2.y - v1.y) * (v2.y - v1.y)) + 
                ((v2.z - v1.z) * (v2.z - v1.z))));
}

magnitude3D: v // n
{
    // Vector
    return(sqrt((v.x * v.x) + (v.y * v.y) + (v.z * v.z)));
}

normalize3D: v // v
{
    // Vector normalize to 0 - 1
    nMagnitude = magnitude3D(v);
    if(nMagnitude <> 0) nMagnitude = 1 / nMagnitude;
    return(v * nMagnitude);
}

// WRAP

wrap: min,max,n
{
    n = n - floor((n - min) / (max - min)) * (max - min);
    if(n < 0) n = n + max - min; // error check
    return(n);
}


All scripts available at my Google Drive at
https://drive.google.com/open?id=1cR_q2GVUAJHumic1-A3eXV16acQnVTWs

Tuesday, 21 June 2011

LScript - Modeler_StitchWeldAverage

LScript (Modeler) works like average weld points but in selected pairs. This allows you to average weld multiple selected points in one go instead of needing to weld individually.

Compatible with Newtek LightWave 9.6 and above.

// LScript Modeler - www.StephenCulley.co.uk
//
// web   address: http://www.stephenculley.co.uk
// email address: email@stephenculley.co.uk

/*  
    LScript Modeler - Stitch Weld Average

    Modeler_StitchWeldAverage.ls

*/

@version 2.2
@warnings
@script modeler
@name *Stitch Weld Average

    // Title
    sTitle = "*Stitch Weld Average";

    // Version
    sVersion = "v1.0";

main
{
    // Selection - Point (DIRECT)
    selmode(DIRECT);
    iPointCount = pointcount();
    if(iPointCount <= 1) error("None or not enough points selected.");

    if((iPointCount & 1) != 0) iPointCount--; // Check if odd

    editbegin();

        for(iCurrentPoint = 1; iCurrentPoint <= iPointCount; iCurrentPoint += 2)
          {
         vAverage = (pointinfo(points[iCurrentPoint]) + pointinfo(points[iCurrentPoint + 1])) * 0.5; // Average Vector
          pointmove(points[iCurrentPoint],vAverage); // Move point           
          pointmove(points[iCurrentPoint + 1],vAverage); // Move point           
          }

    editend();

    mergepoints(0.0); // Merge Points

    info(iPointCount," point(s) welded.");
}
All scripts available at my Google Drive at
https://drive.google.com/open?id=1cR_q2GVUAJHumic1-A3eXV16acQnVTWs

LScript - Modeler_StitchWeld

LScript (Modeler) to weld points but in selected pairs. This allows you to stitch multiple selected points in one go instead of needing to weld individually.

Compatible with Newtek LightWave 9.6 and above.

// LScript Modeler - www.StephenCulley.co.uk
//
// web   address: http://www.stephenculley.co.uk
// email address: email@stephenculley.co.uk

/*  
    LScript Modeler - Stitch Weld

    Modeler_StitchWeld.ls

*/

@version 2.2
@warnings
@script modeler
@name *Stitch Weld

    // Title
    sTitle = "*Stitch Weld";

    // Version
    sVersion = "v1.0";

main
{
    // Selection - Point (DIRECT)
    selmode(DIRECT);
    iPointCount = pointcount();
    if(iPointCount <= 1) error("None or not enough points selected.");

    if((iPointCount & 1) != 0) iPointCount--; // Check if odd

    editbegin();

        for(iCurrentPoint = 1; iCurrentPoint <= iPointCount; iCurrentPoint += 2)
          {
          pointmove(points[iCurrentPoint],pointinfo(points[iCurrentPoint + 1])); // Move point           
          }

    editend();

    mergepoints(0.0); // Merge Points

    info(iPointCount," point(s) welded.");
}
All scripts available at my Google Drive at
https://drive.google.com/open?id=1cR_q2GVUAJHumic1-A3eXV16acQnVTWs

LScript - Modeler_RestOnGround

LScript (Modeler) for a single click rest on ground which only translates selected points so that they rest on the Y plane.

Compatible with Newtek LightWave 9.6 and above.

// LScript Modeler - www.StephenCulley.co.uk
//
// web   address: http://www.stephenculley.co.uk
// email address: email@stephenculley.co.uk

/*  
    LScript Modeler - Rest On Ground

    Modeler_RestOnGround.ls

*/

@version 2.2
@warnings
@script modeler
@name *Rest On Ground

    // Title
    sTitle = "*Rest On Ground";

    // Version
    sVersion = "v1.0";

main
{
    // Selection - Point (DIRECT)
    selmode(DIRECT);
    iPointCount = pointcount();
    if(iPointCount < 1) error("No points selected.");

    editbegin();

    vOffset = pointinfo(points[1]);

    if(iPointCount > 1)
      {   
      for(iCurrentPoint = 2; iCurrentPoint <= iPointCount; iCurrentPoint++)
        {
        vPoint = pointinfo(points[iCurrentPoint]);
        if(vPoint.y < vOffset.y) vOffset = vPoint;  
        }
      }

    vOffset = <0.0,-vOffset.y,0.0>;

    for(iCurrentPoint = 1; iCurrentPoint <= iPointCount; iCurrentPoint++)
      {
      pointmove(points[iCurrentPoint],pointinfo(points[iCurrentPoint]) + vOffset); // Move point           
      }

    editend();
}
All scripts available at my Google Drive at
https://drive.google.com/open?id=1cR_q2GVUAJHumic1-A3eXV16acQnVTWs

Friday, 10 June 2011

LScript - Modeler_Snap


LScript (Modeler) to snaps points in different ways to other points. It can align points in linear, either side of currently selected points or by making points snap to there nearest neighbour a set distance away.

Compatible with Newtek LightWave 9.6 and above.

// LScript Modeler - www.StephenCulley.co.uk
//
// web   address: http://www.stephenculley.co.uk
// email address: email@stephenculley.co.uk

/*  
    LScript Modeler - Snap

    Modeler_Snap.ls

*/

@version 2.2
@warnings
@script modeler
@name *Snap

    // Title
    sTitle = "*Snap";

    // Version
    sVersion = "v1.0";

    ctrl_c0,ctrl_c1,ctrl_c2,ctrl_c3,ctrl_c4,ctrl_c5;

main
{

    // Store
    bAxisX = recall("bAxisX",true);
    bAxisY = recall("bAxisY",true);
    bAxisZ = recall("bAxisZ",true);
    nSeperation = recall("nSeperation",0.1);
    iType = recall("iType",1);
    bTwoPointPolygon = recall("bTwoPointPolygon",false);

    reqbegin(sTitle + " " + sVersion);

    // Reset
    ctrl_res0 = ctlbutton("Reset",50,"button_reset"); // Button Reset
    ctlsep();

    // Control
    ctrl_c0 = ctlcheckbox("X", bAxisX);
    ctrl_c1 = ctlcheckbox("Y", bAxisY);
    ctrl_c2 = ctlcheckbox("Z", bAxisZ);
    ctrl_c3 = ctldistance("Seperation",nSeperation);
    ctrl_c4 = ctlchoice("Type",iType,@"Linear","+/-","Nearest"@);
    ctrl_c5 = ctlcheckbox("Make Two Point Polygons", bTwoPointPolygon);

    // Developer
    ctlsep();
    ctrl_dev0 = ctltext("","developer: Stephen Culley","http://www.stephenculley.co.uk");

    return if !reqpost();

    bAxisX = getvalue(ctrl_c0); // X
    bAxisY = getvalue(ctrl_c1); // Y
    bAxisZ = getvalue(ctrl_c2); // Z
    nSeperation = getvalue(ctrl_c3);
    iType = getvalue(ctrl_c4);
    bTwoPointPolygon = getvalue(ctrl_c5);

    // Store
    store("bAxisX",bAxisX);
    store("bAxisY",bAxisY);
    store("bAxisZ",bAxisZ);
    store("nSeperation",nSeperation);
    store("iType",iType);
    store("bTwoPointPolygon",bTwoPointPolygon);

    // Selection - Point (GLOBAL)
    selmode(GLOBAL);
    iPointCountBefore = pointcount();

    // Selection - Point (DIRECT)
    selmode(DIRECT);
    iPointCount = pointcount();
    if(iPointCount <= 1) error("None or not enough points selected.");

    undogroupbegin(); // Undo

    moninit(iPointCount,"Processing...");  // Progress Monitor

    if(iType == 1) // Linear
    {
    editbegin();

        vSnapPoint = pointinfo(points[1]);
        vTempPoint = vSnapPoint;
        for(iCurrentPoint = 2; iCurrentPoint <= iPointCount; iCurrentPoint++)
          {
          if(bAxisX) vSnapPoint.x += nSeperation; // X
          if(bAxisY) vSnapPoint.y += nSeperation; // Y
          if(bAxisZ) vSnapPoint.z += nSeperation; // Z
          pointmove(points[iCurrentPoint],vSnapPoint); // Move point           

          // Two Point Polygon
          if(bTwoPointPolygon)
            {
            point[1] = addpoint(vTempPoint);
            point[2] = addpoint(vSnapPoint);
            addpolygon(point);
            }

          vTempPoint = vSnapPoint;

          monstep(); // Progress Monitor
          }

    editend();
    }

    if(iType == 2) // +/-
    {
    editbegin();

        vSnapPoint = pointinfo(points[1]);
        for(iCurrentPoint = 2; iCurrentPoint <= iPointCount; iCurrentPoint++)
          {
          vPoint = pointinfo(points[iCurrentPoint]);
          vTempPoint = vSnapPoint;
          if(bAxisX) vTempPoint.x = snap(vPoint.x,vSnapPoint.x,nSeperation); // X
          if(bAxisY) vTempPoint.y = snap(vPoint.y,vSnapPoint.y,nSeperation); // Y
          if(bAxisZ) vTempPoint.z = snap(vPoint.z,vSnapPoint.z,nSeperation); // Z
          pointmove(points[iCurrentPoint],vTempPoint); // Move point           

          // Two Point Polygon
          if(bTwoPointPolygon)
            {
            point[1] = addpoint(vTempPoint);
            point[2] = addpoint(vSnapPoint);
            addpolygon(point);
            }

          vSnapPoint = vTempPoint;

          monstep(); // Progress Monitor
          }

    editend();
    }

    if(iType == 3) // Nearest
    {
    editbegin();

        aPoints[1] = pointinfo(points[1]); // Add point to array
        for(iCurrentPoint = 2; iCurrentPoint <= iPointCount; iCurrentPoint++)
          {
          vPoint = pointinfo(points[iCurrentPoint]);
          vSnapPoint = aPoints[1];
          Distance = distance3D(vPoint,vSnapPoint);
          for(iCurrentPoint = 1; iCurrentPoint <= aPoints.size(); iCurrentPoint++)
            {
            DistanceNew = distance3D(vPoint,aPoints[iCurrentPoint]);
            if(DistanceNew < Distance)
              {
              vSnapPoint = aPoints[iCurrentPoint];
              Distance = DistanceNew;            
              }
            }
          vTempPoint = vSnapPoint;
          if(bAxisX) vTempPoint.x = snap(vPoint.x,vSnapPoint.x,nSeperation); // X
          if(bAxisY) vTempPoint.y = snap(vPoint.y,vSnapPoint.y,nSeperation); // Y
          if(bAxisZ) vTempPoint.z = snap(vPoint.z,vSnapPoint.z,nSeperation); // Z
          pointmove(points[iCurrentPoint],vTempPoint); // Move point

          // Two Point Polygon
          if(bTwoPointPolygon)
            {
            point[1] = addpoint(vTempPoint);
            point[2] = addpoint(vSnapPoint);
            addpolygon(point);
            }
           
          aPoints[iCurrentPoint] = vTempPoint; // Add to array

          monstep(); // Progress Monitor
          }

    editend();

    monend(); // Progress Monitor
    }

    // Selection - Point (GLOBAL)
    selmode(GLOBAL);
    iPointCountAfter = pointcount();
    if((iPointCountAfter - iPointCountBefore) > 0)
      {
      for(s = 1; s <= (iPointCountAfter - iPointCountBefore) ; s++){aSelection[s] = s + iPointCountBefore;}
      selmode(USER);
      selpoint(SET, POINTNDX, aSelection);

      mergepoints(0.0); // Merge Points
      }

    undogroupend(); // Undo

}

button_reset
{
    setvalue(ctrl_c0,true); // X
    setvalue(ctrl_c1,true); // Y
    setvalue(ctrl_c2,true); // Z
    setvalue(ctrl_c3,0.1); // Seperation
    setvalue(ctrl_c4,1); // Type
    setvalue(ctrl_c5,false); // Two Point Polygon
}

// SNAP

snap: n1,n2,n
{
    if(n1 < n2){return(n2 - n);}
  else
    {return(n2 + n);}
}

// VECTOR

distance3D: v1, v2 // n
{
    // Vector
    return(sqrt(((v2.x - v1.x) * (v2.x - v1.x)) +
                ((v2.y - v1.y) * (v2.y - v1.y)) + 
                ((v2.z - v1.z) * (v2.z - v1.z))));
}
All scripts available at my Google Drive at
https://drive.google.com/open?id=1cR_q2GVUAJHumic1-A3eXV16acQnVTWs

LScript - Modeler_2PointPolyChain


LScript (Modeler) to produces a 2 point polychain between two selected points.

Compatible with Newtek LightWave 9.6 and above.

// LScript Modeler - www.StephenCulley.co.uk
//
// web   address: http://www.stephenculley.co.uk
// email address: email@stephenculley.co.uk

/*  
    LScript Modeler - 2PointPolyChain

    Modeler_2PointPolyChain.ls

*/

@version 2.2
@warnings
@script modeler
@name *2 Point Poly Chain

    // Title
    sTitle = "*2 Point Poly Chain";

    // Version
    sVersion = "v1.0";

    ctrl_c0;

main
{

    // Recall
    iNumber = recall("iNumber",10);

    reqbegin(sTitle + " " + sVersion);

    // Reset
    ctrl_res0 = ctlbutton("Reset",50,"button_reset"); // Button Reset
    ctlsep();

    // Control
    ctrl_c0 = ctlinteger("Number",iNumber);

    // Developer
    ctlsep();
    ctrl_dev0 = ctltext("","developer: Stephen Culley","http://www.stephenculley.co.uk");

    return if !reqpost();

    iNumber = getvalue(ctrl_c0);

    // Store
    store("iNumber",iNumber);

    // Selection - Point (GLOBAL)
    selmode(GLOBAL);
    iPointCountBefore = pointcount();

    // Selection - Point (DIRECT)
    selmode(DIRECT);
    iPointCount = pointcount();
    if(iPointCount <= 1) error("Select two points.");
    if(iPointCount > 2) error("Select two points.");

    moninit(iNumber,"Processing...");  // Progress Monitor

        editbegin();

            vStart = pointinfo(points[1]);
            vEnd = pointinfo(points[2]);

            nDistance = distance3D(vStart,vEnd);
            if(iNumber <> 0.0){vOffset = (vEnd - vStart) / iNumber;}else{vOffset = <0.0,0.0,0.0>;}
           
            for(n = 1; n <= iNumber; n++)
              {
              aPoints[1] = addpoint(vStart + (vOffset * (n - 1)));
              aPoints[2] = addpoint(vStart + (vOffset * n));
              addpolygon(aPoints);

              monstep(); // Progress Monitor
              } 

        editend();

    monend(); // Progress Monitor

    // Selection - Point (GLOBAL)
    selmode(GLOBAL);
    iPointCountAfter = pointcount();
    if((iPointCountAfter - iPointCountBefore) > 0)
      {
      for(s = 1; s <= (iPointCountAfter - iPointCountBefore) ; s++){aSelection[s] = s + iPointCountBefore;}
      selmode(USER);
      selpoint(SET, POINTNDX, aSelection);

      mergepoints(0.0); // Merge Points
      }
}

button_reset
{
    setvalue(ctrl_c0,10); // Number
}

// VECTOR 3D

distance3D: v1, v2 // n
{
    // Vector
    return(sqrt(((v2.x - v1.x) * (v2.x - v1.x)) +
                ((v2.y - v1.y) * (v2.y - v1.y)) + 
                ((v2.z - v1.z) * (v2.z - v1.z))));
}
All scripts available at my Google Drive at
https://drive.google.com/open?id=1cR_q2GVUAJHumic1-A3eXV16acQnVTWs

LScript - Modeler_2PointPoly


LScript (Modeler) to produce standalone 2 point polys for use with "VOLT" and some other of my lscripts. It produces 2 point poly's that are unconnected and all located at <0.0,0.0,0.0> that can then be displaced inside of layout.

Compatible with Newtek LightWave 9.6 and above.

// LScript Modeler - www.StephenCulley.co.uk
//
// web   address: http://www.stephenculley.co.uk
// email address: email@stephenculley.co.uk

/*  
    LScript Modeler - 2 Point Poly

    Modeler_2PointPoly.ls

*/

@version 2.2
@warnings
@script modeler
@name *2 Point Poly

    // Title
    sTitle = "*2 Point Poly";

    // Version
    sVersion = "v1.0";

    ctrl_c0;

main
{

    // Recall
    iNumber = recall("iNumber",1024);

    reqbegin(sTitle + " " + sVersion);

    // Reset
    ctrl_res0 = ctlbutton("Reset",50,"button_reset"); // Button Reset
    ctlsep();

    // Control
    ctrl_c0 = ctlinteger("Number",iNumber);

    // Developer
    ctlsep();
    ctrl_dev0 = ctltext("","developer: Stephen Culley","http://www.stephenculley.co.uk");

    return if !reqpost();

    iNumber = getvalue(ctrl_c0);

    // Store
    store("iNumber",iNumber);

    moninit(iNumber,"Processing...");  // Progress Monitor

        editbegin();
            
            for(n = 1; n <= iNumber; n++)
              {
              aPoints[1] = addpoint(0.0,0.0,0.0);
              aPoints[2] = addpoint(0.0,0.0,0.0);
              addpolygon(aPoints);
            
              monstep(); // Progress Monitor
              } 

        editend();

    monend(); // Progress Monitor
}

button_reset
{
    setvalue(ctrl_c0,1024); // Number
}
All scripts available at my Google Drive at
https://drive.google.com/open?id=1cR_q2GVUAJHumic1-A3eXV16acQnVTWs