Feedback

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

Monday, 4 March 2013

LScript - Image_Depth


LScript (Layout) to create a grey scale representation of the depth buffer.

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

    Image_Depth.ls

*/

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

    // Title
    sTitle = "*Depth";

    // Version
    sVersion = "v1.0";

    nMin = 0.0;
    nMax = 10.0;

create
{
    setdesc(sTitle);
}

process: ifo
{
    iProgress = ifo.height;
    if(runningUnder() != SCREAMERNET) moninit(iProgress);
    for(i = 1;i <= ifo.height;++i)
      {
      for(j = 1;j <= ifo.width;++j)
        {
        nDepth = 1 - clip(0.0,1.0,maprange01(nMin,nMax,ifo.depth[j,i]));        
        ifo.red[j,i] = nDepth;
        ifo.green[j,i] = nDepth;
        ifo.blue[j,i] = nDepth;
        }
      if(runningUnder() != SCREAMERNET) if(monstep()) return;
      }
}

// CLIP

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

// MAP RANGE

maprange01: n1,n2,i
{    
    if(n2-n1 == 0.0){return(0.0);}
  else
    {return((1/(n2-n1)) * (i-n1));}
}

load: what,io
{
    if(what == SCENEMODE)
    {
        nMin = io.read().asNum();
        nMax = io.read().asNum();
    }
}

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

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

    // Control
    ctrl_c0 = ctlnumber("Min (m)",nMin);
    ctrl_c1 = ctlnumber("Max (m)",nMax);

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

    return if !reqpost();

    nMin = getvalue(ctrl_c0);
    nMax = getvalue(ctrl_c1);

    reqend();
}


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

2 comments: