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