Feedback

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

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

Friday, 15 March 2013

LScript - Image_Pixelate

LScript (Layout) to create a pixelated effect with envelope control.

Changes
  • Override alpha

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 - Pixelate

    Image_Pixelate.ls

*/

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

    // Title
    sTitle = "*Pixelate";

    // Version
    sVersion = "v1.0";

    // Envelope
    envSize; // Size

    // Control
    ctrl_c0;

create
{
    setdesc(sTitle);

    // Envelope
    envSize = Envelope("Size (" + sTitle + ")",CHAN_NUMBER,sTitle); // Size
    envSize.persist(false);
    envSize.createKey(0,20.0);
}

process: ifo
{
    // Variable
    iSize = ceil(envSize.value(Scene().currenttime));

    // Error
    if(iSize < 2){return;}
    if(ifo.width < 1 || ifo.height < 1){return;}

    iGridX = ceil(ifo.width / iSize);
    iGridY = ceil(ifo.height / iSize);

    iGridXOffset = abs((ifo.width - (iGridX * iSize)) * 0.5);
    iGridYOffset = abs((ifo.height - (iGridY * iSize)) * 0.5);

    iProgress = iGridX * iGridY;
    if(runningUnder() != SCREAMERNET) moninit(iProgress);

    for(y = 0;y <= iGridY - 1; ++y)
      {

      for(x = 0;x <= iGridX - 1; ++x)
        {
        v1 = ;
        v2 = ;

        // Draw 
        pixelateIFO(ifo,v1,v2);

        if(runningUnder() != SCREAMERNET) if(monstep()) return;
        }      
      }
  
}

pixelateIFO: ifo,v1,v2 // vector,red,green,blue
{
    // Order
    if(v1.x > v2.x){n = v2.x;v2.x = v1.x; v1.x = n;}
    if(v1.y > v2.y){n = v2.y;v2.y = v1.y; v1.y = n;}

    if(v1.x < 1 || v2.x > ifo.width ||
       v1.y < 1 || v2.y > ifo.height)
      {
      // Offscreen
      if(v2.x < 1){return;}
      if(v1.x > ifo.width){return;}
      if(v2.y < 1){return;}
      if(v1.y > ifo.width){return;}
  
      // Clip
      if(v1.x < 1){v1.x = 1;}
      if(v1.x > ifo.width){v1.x = ifo.width;}
      if(v1.y < 1){v1.y = 1;}
      if(v1.y > ifo.height){v1.y = ifo.height;}
      if(v2.x < 1){v2.x = 1;}
      if(v2.x > ifo.width){v2.x = ifo.width;}
      if(v2.y < 1){v2.y = 1;}
      if(v2.y > ifo.height){v2.y = ifo.height;}
      }

    r = 0;
    g = 0;
    b = 0;
    c = 0;
    
    // Average
    for(y = v1.y; y <= v2.y; ++y)
      {
      for(x = v1.x; x <= v2.x; ++x)
        {
        r += ifo.red[x,y];
        g += ifo.green[x,y];
        b += ifo.blue[x,y];
        ++c;
        }
      }

    if(c > 1)
      {
      r *= 1 / c;
      g *= 1 / c;
      b *= 1 / c;
      }

    // Draw
    for(y = v1.y; y <= v2.y; ++y)
      {
      for(x = v1.x; x <= v2.x; ++x)
        {
        ifo.red[x,y] = r;
        ifo.green[x,y] = g;
        ifo.blue[x,y] = b;
        ifo.alpha[x,y] = 1.0;
        }
      }
}

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

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

        // Envelope
        envSize.save(); // Size
    }
}

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

    reqbegin(sTitle + " " + sVersion);

    ctrl_c0 = ctlpercent("Size",envSize.value(Scene().currenttime) * 0.01); // Size
    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"); // Size

    reqopen();
}

button_c1e // Size
{
    envSize.edit();
}

refresh_c0:value // Size
{
    setvalue(ctrl_c0,max(0.0,value));
    iKey = envSize.keyExists(Scene().currenttime);
    if(iKey == nil)
        {envSize.createKey(Scene().currenttime,max(0.0,value * 100));}
    else
        {envSize.setKeyValue(iKey,max(0.0,value * 100));}
}


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