Feedback

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

Monday 13 April 2015

LScript - Image_GameBoy


LScript (Layout) applies a Game Boy style look.

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 - Game Boy

    Image_GameBoy.ls

*/

@version 2.5
@warnings
@script image
@name *Game Boy

    // Title
    sTitle = "*Game Boy";

    // Version
    sVersion = "v1.0";

    nCorrection = 7.5;
    iPixelSize = 4;
    nGridAmount = 0.5;
    iGridWidth = 1; 
    aColor;


    // Control
    ctrl_c0;

create
{
    setdesc(sTitle);

    aColor[1] = <(1 / 255) * 23,(1 / 255) * 74,(1 / 255) * 3>;
    aColor[2] = <(1 / 255) * 39,(1 / 255) * 82,(1 / 255) * 3>;
    aColor[3] = <(1 / 255) * 88,(1 / 255) * 114,(1 / 255) * 3>;
    aColor[4] = <(1 / 255) * 111,(1 / 255) * 127,(1 / 255) * 3>;
    aColor[5] = <(1 / 255) * 131,(1 / 255) * 137,(1 / 255) * 3>;
    aColor[6] = <(1 / 255) * 150,(1 / 255) * 160,(1 / 255) * 3>;
}

process: ifo
{

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

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

    iGridXOffset = abs((ifo.width - (iGridX * iPixelSize)) * 0.5);
    iGridYOffset = abs((ifo.height - (iGridY * iPixelSize)) * 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 
        gameboyIFO(ifo,v1,v2);

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

gameboyIFO: 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.0;
    g = 0.0;
    b = 0.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;
      }

    a = (r + g + b) * (1 / 3);
    a = round(a * nCorrection,0);
    a = max(min(a,5),1);
   
    r = aColor[a].x;
    g = aColor[a].y;
    b = aColor[a].z;
    l1 = nGridAmount;
    l2 = 1.0 - nGridAmount;

    if(iGridWidth <= 0)
      {
     // 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;
         }
       }


      }
    else if(iGridWidth == 1)
      {
     // Draw
     for(y = v1.y; y <= v2.y; ++y)
       {
       for(x = v1.x; x <= v2.x; ++x)
         {
 
         if(x == v1.x || y == v1.y)
           {
           ifo.red[x,y] = (aColor[6].x * l1) + (r * l2);
           ifo.green[x,y] = (aColor[6].y * l1) + (g * l2);
           ifo.blue[x,y] = (aColor[6].z * l1) + (b * l2);
           ifo.alpha[x,y] = 1.0;
           }
         else 
           {
         ifo.red[x,y] = r;
         ifo.green[x,y] = g;
         ifo.blue[x,y] = b;
         ifo.alpha[x,y] = 1.0;
           }
 
         }
       }

      }
    else if(iGridWidth > 1) 
      {

     // Draw
     for(y = v1.y; y <= v2.y; ++y)
       {
       for(x = v1.x; x <= v2.x; ++x)
         {
 
         if(x <= (v1.x + (iGridWidth - 1)) || x >= (v2.x - iGridWidth) || y <= (v1.y + (iGridWidth - 1)) || y >= (v2.y - iGridWidth))
           {
           ifo.red[x,y] = (aColor[6].x * l1) + (r * l2);
           ifo.green[x,y] = (aColor[6].y * l1) + (g * l2);
           ifo.blue[x,y] = (aColor[6].z * l1) + (b * l2);
           ifo.alpha[x,y] = 1.0;
           }
         else 
           {
         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)
            {
            nCorrection = io.read().asNum();
            iPixelSize = io.read().asInt();
            nGridAmount = io.read().asNum();
            iGridWidth = io.read().asInt();
            }
    }
}

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

        io.writeln(nCorrection);
        io.writeln(iPixelSize); 
        io.writeln(nGridAmount);
        io.writeln(iGridWidth);
    }
}

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

    // Control
    ctrl_c0 = ctlnumber("Correction",nCorrection); // Correction
    ctrl_c1 = ctlinteger("Pixel Size",iPixelSize); // Pixel Size
    ctrl_c2 = ctlpercent("Grid Amount",nGridAmount); // Grid Amount
    ctrl_c3 = ctlinteger("Grid Width",iGridWidth); // Grid Width


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

    return if !reqpost();

    nCorrection = getvalue(ctrl_c0); // Correction
    iPixelSize = getvalue(ctrl_c1); // Pixel Size
    nGridAmount = getvalue(ctrl_c2); // Grid Amount
    iGridWidth = getvalue(ctrl_c3); // Grid Width
}


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

Friday 6 March 2015

LScript - Motion_Steadicam


LScript (Layout) smooth camera motions and position camera based upon motion of another object.

Compatible with Newtek LightWave 9.6 and above.

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

/*  
    LScript Item Animation - Steadicam

    Motion_Steadicam.ls

*/

@version 2.2
@warnings
@script motion
@name *Steadicam

    // Title
    sTitle = "*Steadicam";

    // Version
    sVersion = "v1.0";

    // Item
    Item = nil;
    ItemName = "nil";

    iSamples = 3;
    iOffset = 0;
    nBias = 1.0;

create
{
    setdesc(sTitle);
}

destroy
{
}

process: ma, frame, time
{
    nStep = (1 / Scene().fps) * nBias;
    nOffset = (1 / Scene().fps) * iOffset;
    vPosition = <0.0,0.0,0.0>;

    if(ItemName != "nil") {Item = Mesh(ItemName); ItemName = "nil";}
    if(Item)
      {

      iCount = 0;
      for(iS = -iSamples; iS <= iSamples; iS++)
        {
        vPosition += Item.getWorldPosition(time + (iS * nStep) + nOffset);
        iCount++; 
        }
      if(iCount > 1){vPosition = vPosition * (1 / iCount);}

      }
     
// ma

  ma.set(POSITION,vPosition);

}

load: what,io
{
    if(what == SCENEMODE)   // processing an ASCII scene file
    {
        ItemName = io.read().asStr();
        iSamples = io.read().asInt();
        iOffset = io.read().asInt();
        nBias = io.read().asNum();
    }
}

save: what,io
{
    if(what == SCENEMODE)
    {
        if(Item != nil)
            {
            io.writeln(string(Item.name));
            }
        else
            {
            io.writeln("nil");
            } 

        io.writeln(iSamples);
        io.writeln(iOffset);
        io.writeln(nBias);
    }
}

options
{

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

    reqbegin(sTitle + " " + sVersion);

    ctrl_c0 = ctlallitems("Item",Item);
    ctrl_c1 = ctlslider("Samples",iSamples,0,100);
    ctrl_c2 = ctlslider("Offset",iOffset,-100,100);
    ctrl_c3 = ctlpercent("Bias",nBias);

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

    // Refresh
    ctlrefresh(ctrl_c0,"refresh_c0"); // Item
    ctlrefresh(ctrl_c1,"refresh_c1"); // Samples
    ctlrefresh(ctrl_c2,"refresh_c2"); // Offset
    ctlrefresh(ctrl_c3,"refresh_c3"); // Bias

    reqopen();
}

refresh_c0:value // Item
{
    Item = value;
}

refresh_c1:value // Samples
{
    iSamples = value;
}

refresh_c2:value // Offset
{
    iOffset = value;
}

refresh_c3:value // Bias
{
    nBias = value;
}
All scripts available at my Google Drive at
https://drive.google.com/open?id=1cR_q2GVUAJHumic1-A3eXV16acQnVTWs