Feedback

Please leave feedback and comments. I am always interested to hear how people get on using these LScripts!

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

Wednesday, 31 July 2013

LScript - Displace_Expand


LScript (Layout) to animate models expanding in to existence. It is best used upon non subdivided and unwelded polygons.

Compatible with Newtek LightWave 9.6 and above.

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

/*  
    LScript Displacement Map - Expand 

    Displace_Expand.ls

*/

@version 2.2
@warnings
@script displace
@name *Expand

    // Title
    sTitle = "*Expand";

    // Version
    sVersion = "v1.0";

    // Item
    Item;

    // Variable
    iCount = 0;
    iPoint = 0;
    iPointCount = 0;
    vPosition = <0.0,0.0,0.0>;

    // Requester
    bRequesterUpdate = false; // Update
    iRequesterFrame = -1; // Frame

    // Envelope
    envAmount; // Amount

    // Control
    ctrl_c0;

create: obj
{
    setdesc(sTitle);

    // Item
    Item = obj;

    // Envelope
    envAmount = Envelope("Amount (" + sTitle + ")",CHAN_NUMBER,sTitle); // Amount
    envAmount.persist(false);
    envAmount.createKey(0,0.0);

    // Info
    info("*Expand - Use with unwelded polygons without subdivions.");
}

destroy
{
}

newtime: id, frame, time
{

    if(reqisopen() && iRequesterFrame != frame)
        {
        bRequesterUpdate = true; // Update       

        setvalue(ctrl_c0,envAmount.value(Scene().currenttime)); // Amount

        iRequesterFrame = frame; // Frame
        bRequesterUpdate = false; // Update
        }

    // Subpatch Level
    SubPatchLevel(0,0);

    // Variable
    nAmount = clip(0.0,1.0,envAmount.value(time));
    iPointCount = Item.pointCount();
    nPoint = nAmount * iPointCount;
    nFrac = frac(nPoint);
    iPoint = nPoint - nFrac;    
    vPosition = linear1D(Item.position(Item.points[max(1,iPoint)]),Item.position(Item.points[min(iPointCount,iPoint + 1)]),nFrac);
    iCount = 0; // Count
}

flags
{
    // WORLD      LOCAL

    return(LOCAL);
}

process: da
{
    iCount++; // Count
    if(iCount <= iPoint)
      {
      }
    else
      {
      // da

      da.source[1] = vPosition.x;
      da.source[2] = vPosition.y;
      da.source[3] = vPosition.z;
      }     
}

// CLIP

clip: min,max,n
{
    if(n < min) n = min;
    if(n > max) n = max;
    return(n);
}

// INTERPOLATION

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

load: what,io
{
    if(what == SCENEMODE)   // processing an ASCII scene file
    {
        if(io.read().asStr() == sTitle + " " + sVersion)
            {
            // Envelope
            envAmount.load(); // Amount
            }
    }
}

save: what,io
{
    if(what == SCENEMODE)
    {    
        // Header
        io.writeln(sTitle + " " + sVersion);

        // Envelope
        envAmount.save(); // Amount
    }
}

options
{
    if(reqisopen())
        {
        reqend();
        return;
        }

    reqbegin(sTitle + " " + sVersion);

    ctrl_c0 = ctlpercent("Amount",envAmount.value(Scene().currenttime)); // Amount
    ctrl_c1e = ctlbutton("E",20,"button_c1e"); // Button

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

    // Refresh
    ctlrefresh(ctrl_c0,"refresh_c0"); // Amount

    reqopen();
}

button_c1e // Amount
{
    envAmount.edit();
}

refresh_c0:value // Amount
{
    if(bRequesterUpdate) return; // Requester Update
    setvalue(ctrl_c0,clip(0.0,1.0,value));
    iKey = envAmount.keyExists(Scene().currenttime);
    if(iKey == nil)
        {envAmount.createKey(Scene().currenttime,clip(0.0,1.0,value));}
    else
        {envAmount.setKeyValue(iKey,clip(0.0,1.0,value));}
}
All scripts available at my Google Drive at
https://drive.google.com/open?id=1cR_q2GVUAJHumic1-A3eXV16acQnVTWs

LScript - Channel_Filter


LScript (Layout) to filter envelopes to smooth it out based on time samples.

Compatible with Newtek LightWave 9.6 and above.

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

/* 
    LScript Channel Filter - Filter

    Channel_Filter.ls

*/

@version 2.2
@warnings
@script channel
@name *Filter

    // Title
    sTitle = "*Filter";

    // Version
    sVersion = "v1.0";

    // Variable
    iFilter = 5;

    // Controls 
    ctrl_c0;

create: channel
{
    setdesc(sTitle + " - " + iFilter);
}

destroy
{
    // take care of final clean-up activities here
}

process: ca, frame, time
{
    fps = (1 / Scene().fps);
    iCount = 0;
    nValue = 0.0;
    for(iS = -iFilter; iS <= iFilter; iS++)
      {
      nValue += ca.get(time + (iS * fps));
      iCount++; 
      }
    if(iCount > 1){nValue = nValue * (1 / iCount);}

    // ca    
    ca.set(nValue);
}

load: what,io
{
    if(what == SCENEMODE)   // processing an ASCII scene file
    {
        if(io.read().asStr() == sTitle + " " + sVersion)
            {
            iFilter = io.read().asInt(); // Filter
            setdesc(sTitle + " - " + iFilter);
            }
    }
}

save: what,io
{
    if(what == SCENEMODE)
    {
        // Header
        io.writeln(sTitle + " " + sVersion);
        io.writeln(iFilter); // Filter
    }
}

options
{
    if(reqisopen())
        {
        reqend();
        return;
        }

    reqbegin(sTitle + " " + sVersion);

    ctrl_c0 = ctlinteger("Filter",iFilter);   

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

    // Refresh
    ctlrefresh(ctrl_c0,"refresh_c0"); // Filter

    reqopen();
}

refresh_c0:value // Filter
{
    iFilter = min(max(0,value),100);
    setvalue(ctrl_c0,iFilter); 
    setdesc(sTitle + " - " + iFilter);
}
All scripts available at my Google Drive at
https://drive.google.com/open?id=1cR_q2GVUAJHumic1-A3eXV16acQnVTWs

Thursday, 28 March 2013

Free Stuff - Tin Cans (Object)


Free objects for LightWave : Various high quality sub-division modeled tin cans (10).

Compatible with Newtek LightWave 9.6 and above.

Download - zipped object (.zip)

Tuesday, 26 March 2013

LScript - Image_Alpha

LScript (Layout) to create compressed video artifact effect.

Compatible with Newtek LightWave 9.6 and above.

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

/* 
    LScript Image Filter - Alpha

    Image_Alpha.ls

*/

@version 2.5
@warnings
@script image
@name *Alpha

    // Title
    sTitle = "*Alpha";

    // Version
    sVersion = "v1.0";

    aType = @"Solid","Luma","Luma (Invert)"@;
    iType = 1;

create
{
    setdesc(sTitle + " - " + aType[iType]);
}

process: ifo
{

    if(iType == 1) // Solid
      {

      iProgress = ifo.height;
      if(runningUnder() != SCREAMERNET) moninit(iProgress);
      for(i = 1;i <= ifo.height;++i)
        {
        for(j = 1;j <= ifo.width;++j)
          {
          ifo.alpha[j,i] = 1.0;
          }
        if(runningUnder() != SCREAMERNET) if(monstep()) return;
        }

      }

    if(iType == 2) // Luma
      {

      iProgress = ifo.height;
      if(runningUnder() != SCREAMERNET) moninit(iProgress);
      for(i = 1;i <= ifo.height;++i)
        {
        for(j = 1;j <= ifo.width;++j)
          {
          ifo.alpha[j,i] = clip(0.0,1.0,(ifo.red[j,i] + ifo.green[j,i] + ifo.blue[j,i]) * (1 / 3));
          }
        if(runningUnder() != SCREAMERNET) if(monstep()) return;
        }

      }

    if(iType == 3) // Luma (Invert)
      {

      iProgress = ifo.height;
      if(runningUnder() != SCREAMERNET) moninit(iProgress);
      for(i = 1;i <= ifo.height;++i)
        {
        for(j = 1;j <= ifo.width;++j)
          {
          ifo.alpha[j,i] = clip(0.0,1.0,1.0 - ((ifo.red[j,i] + ifo.green[j,i] + ifo.blue[j,i]) * (1 / 3)));
          }
        if(runningUnder() != SCREAMERNET) if(monstep()) return;
        }

      }

}

// CLIP

clip: min,max,n
{
    if(n < min) n = min;
    if(n > max) n = max;
    return(n);
}

load: what,io
{
    if(what == SCENEMODE)
    {
        iType = io.read().asInt();

        setdesc(sTitle + " - " + aType[iType]);
    }
}

save: what,io
{
    if(what == SCENEMODE)
    {
        io.writeln(iType);
    }
}

options
{
    reqbegin(sTitle + " " + sVersion);


    // Control
    ctrl_c0 = ctlchoice("Type",iType,@"Solid","Luma","Luma Invert"@); // Type

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

    return if !reqpost();

    iType = getvalue(ctrl_c0);

    setdesc(sTitle + " - " + aType[iType]);

    reqend();
}


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