Feedback

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

Monday, 4 February 2013

LScript - Motion_VolumeTrick

LScript (Layout) for motion values based on position during motion blur used to fake volume effects.

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

    Motion_VolumeTrick.ls

*/

@version 2.2
@warnings
@script motion
@name *Volume Trick

    // Title
    sTitle = "*Volume Trick";

    // Version
    sVersion = "v1.1";

    // Item
    Item;

    // Variable
    aChannel = @"X","Y","Z","H","P","B","S","SX","SY","SZ"@; 
    iChannel = 1;
    nMin = 0.0;
    nMax = 1.0;

create : id
{
    // Description
    setdesc(sTitle);
 
    // Info
    info("*Volume Trick - Motion blur must be enabled.");

    // Items
    Item = id; // Item
}

destroy
{
}

process: ma, frame, time
{     
    // Variables
    vPosition = ma.get(POSITION,time);
    vRotation = ma.get(ROTATION,time);
    vScaling = ma.get(SCALING,time);

    if(Camera().blurLength(time) <> 0.0)
      {
      // Map Range
      n01 = maprange01(frame * (1 / Scene().fps),(frame + 1) * (1 / Scene().fps),time);

        switch(iChannel)
        {

          case 1: // X
                  vPosition.x = linear1D(vPosition.x + nMin,vPosition.x + (nMax * (1 / Camera().blurLength(time))) - nMin,n01);
                  break;
  
          case 2: // Y
                  vPosition.y = linear1D(vPosition.y + nMin,vPosition.y + (nMax * (1 / Camera().blurLength(time))) - nMin,n01);
                  break;

          case 3: // Y
                  vPosition.z = linear1D(vPosition.z + nMin,vPosition.z + (nMax * (1 / Camera().blurLength(time))) - nMin,n01);
                  break;

          case 4: // H
                  vRotation.x = linear1D(vRotation.x + nMin,vRotation.x + (nMax * (1 / Camera().blurLength(time))) - nMin,n01);
                  break;

          case 5: // P
                  vRotation.y = linear1D(vRotation.y + nMin,vRotation.y + (nMax * (1 / Camera().blurLength(time))) - nMin,n01);
                  break;

          case 6: // B
                  vRotation.z = linear1D(vRotation.z + nMin,vRotation.z + (nMax * (1 / Camera().blurLength(time))) - nMin,n01);
                  break;

          case 7: // S
                  vScaling.x = linear1D(vScaling.x + nMin,vScaling.x + (nMax * (1 / Camera().blurLength(time))) - nMin,n01);
                  vScaling.y = linear1D(vScaling.y + nMin,vScaling.y + (nMax * (1 / Camera().blurLength(time))) - nMin,n01);
                  vScaling.z = linear1D(vScaling.z + nMin,vScaling.z + (nMax * (1 / Camera().blurLength(time))) - nMin,n01);
                  break;

          case 8: // SX
                  vScaling.x = linear1D(vScaling.x + nMin,vScaling.x + (nMax * (1 / Camera().blurLength(time))) - nMin,n01);
                  break;

          case 9: // SY
                  vScaling.y = linear1D(vScaling.y + nMin,vScaling.y + (nMax * (1 / Camera().blurLength(time))) - nMin,n01);
                  break;

         case 10: // SZ
                  vScaling.z = linear1D(vScaling.z + nMin,vScaling.z + (nMax * (1 / Camera().blurLength(time))) - nMin,n01);
                  break;
      

        }      


      } 

// ma

  ma.set(POSITION,vPosition);
  ma.set(ROTATION,vRotation);
  ma.set(SCALING,vScaling);

}

// INTERPOLATION

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

// 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)   // processing an ASCII scene file
    {
        sHeader = io.read().asStr();

        if(sHeader == sTitle + " " + sVersion)
            {
            iChannel = io.read().asInt();
            nMin = io.read().asNum(); // Min
            nMax = io.read().asNum(); // Max
            break;
            }

        if(sHeader == sTitle + " " + sVersion) // v1.0 Compatibility
            {
            iChannel = io.read().asInt();
            nMin := 0.0; // Min
            nMax = io.read().asNum(); // Max          
            break;
            }
    }
}

save: what,io
{
    if(what == SCENEMODE)
    {
        // Header
        io.writeln(sTitle + " " + sVersion);
        io.writeln(iChannel);
        io.writeln(nMin); // Min
        io.writeln(nMax); // Max
    }
}

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

    reqbegin(sTitle + " " + sVersion);

    ctrl_c0 = ctlchoice("Channel",iChannel,@"X","Y","Z","H","P","B","S","SX","SY","SZ"@);
    ctrl_c1 = ctlnumber("Min",nMin);   
    ctrl_c2 = ctlnumber("Max",nMax);   

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

    // Refresh
    ctlrefresh(ctrl_c0,"refresh_c0"); // Channel
    ctlrefresh(ctrl_c1,"refresh_c1"); // Min
    ctlrefresh(ctrl_c2,"refresh_c2"); // Max

    reqopen();
}

refresh_c0:value // Channel
{
    iChannel = value;
}

refresh_c1:value // Min
{
    nMin = value;
}

refresh_c2:value // Max
{
    nMax = value;
}


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

No comments:

Post a comment