Feedback

Please leave feedback and comments. I am always interested to hear how people get on using these LScripts!
Showing posts with label Generic. Show all posts
Showing posts with label Generic. Show all posts

Monday, 18 February 2013

LScript - Generic_Blueprint


LScript (Layout) to quickly setup a scene to produce a blueprint look.

Please be aware this script overrides objects surfaces settings.

Compatible with Newtek LightWave 9.6 and above.

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

/*  
    LScript Generic - Blueprint

    Generic_Blurprint.ls

*/

@version 2.2
@warnings
@script generic
@name *Blurprint

    sTitle = "*Blueprint";
    sVersion = "v1.0";    

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

    ctrl_c0 = ctlcolor("Background",<60,100,200>);
    ctrl_c1 = ctlcolor("Lines",<255,255,255>);
    ctrl_c2 = ctlnumber("Opacity",0.2);
    ctrl_c3 = ctlchoice("Show",1,@ "Edge","All" @,false);

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

    return if !reqpost();   

    vBackgroundColor = getvalue(ctrl_c0);
    vLineColor = getvalue(ctrl_c1) * (1/255);
    nOpacity = getvalue(ctrl_c2);
    if(getvalue(ctrl_c3) == 2){iPolygonEdgeFlag = 31;}else{iPolygonEdgeFlag = 15;}
    
    // Background Color
    if(Scene().backdroptype == GRADIENT){CommandInput("GradientBackdrop");}
    CommandInput("BackdropColor " +  (vBackgroundColor.x * (1/255)) + " " + (vBackgroundColor.y * (1/255)) + " " + (vBackgroundColor.z * (1/255)));

    // Item
    Item = Mesh();
    while(Item)
      {

      if(Item.isMesh())
        {
        SelectItem(Item.id);
        CommandInput("PolygonEdgeFlags " + iPolygonEdgeFlag);
        CommandInput("PolygonEdgeThickness 1 1 1 1 1");
        CommandInput("PolygonEdgeColor " + vLineColor.x + " " + vLineColor.y + " " + vLineColor.z);

        // Surface
        Surface = Surface();
        while(Surface)
          {
          Surface.setValue(SURFCOLR,vBackgroundColor); // Color
          Surface.setValue(SURFLUMI,1.0); // Luminosity
          Surface.setValue(SURFDIFF,0.0); // Diffuse
          Surface.setValue(SURFSPEC,0.0); // Specularity
          Surface.setValue(SURFREFL,0.0); // Reflection
          Surface.setValue(SURFTRAN,nOpacity); // Transparency
          Surface.setValue(SURFTRNL,0.0); // Translucency
          Surface.setValue(SURFBUMP,0.0); // Bump
          Surface.setValue(SURFSIDE,1); // Sided
          Surface = Surface.next();
          }

        }

      Item = Item.next();
      }

    info(sTitle + " " + sVersion + " - developer: Stephen Culley - http://www.stephenculley.co.uk");
}


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

LScript - Generic_BoxRig (v1.1)

LScript (Layout) to rig a box so that it can pivot upon its edges and corners. This script sets up the hiearchy and expressions required ready for animation upon any selected objects.

Use "Parent" null to position and rotate box and "Control" null to animate using the rig.

Problem
  • Under LightWave 11 Item Shape is broken due to changes in comring
Changes
  • Fixed parenting (v1.1)
  • Objects require pivot to be resting on ground and centre of object
  • Does not work on clones due to expressions
  • Fixed getting correct boundingbox extents from layers
  • Fixed Parent in Place issues
  • Fixed offset when pivot not at bottom of object
Compatible with Newtek LightWave 9.6 up and prior to 11.0.

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

/*  
    LScript Generic - BoxRig

    Generic_BoxRig.ls

*/

@version 2.2
@warnings
@script generic
@name *Box Rig
  
    // Title
    sTitle = "*Box Rig";

    // Version
    sVersion = "v1.1";    

generic
{

    // Item Select
    Items = Scene().getSelect();  
    if(Items == nil)
      {
      info("Select an object.");
      return;
      }

    // Parent in Place
    bParentInPlace = Scene().generalopts[3];
    if(bParentInPlace){ParentInPlace();}

    for(i = 1; i <= Items.size(); i++)
      {

      if(Items[i].genus == MESH && !Items[i].null)
        {

        GoToFrame(0);

        SelectItem(Items[i].id);
 
        // Box Item
        BoxItem = Mesh(0); // Get Box
        BoxItem_Parent = BoxItem.parent; // Parent
        vPivot = BoxItem.getPivot(0.0);
        vPosition = BoxItem.getPosition(0.0); // Position
        vRotation = BoxItem.getRotation(0.0); // Rotation
        vScaling = BoxItem.getScaling(0.0); // Scaling
        aBoundingBox = BoxItem.position(getlayernumber(BoxItem)); // Bounding Box
        aBoundingBox[1] -= vPivot; 
        aBoundingBox[2] -= vPivot;

        sName = BoxItem.name; // Name

        // Reset Box
        Position(0.0,-aBoundingBox[1].y,0.0);
        Rotation(0.0,0.0,0.0);
        Scale(1.0,1.0,1.0);
        CreateKey(0);

        // Parent Item
        AddNull(sName + "_Parent");
        ParentItem = Mesh(sName + "_Parent"); // Assign to a var       
        ItemColor(12); // Color Dark Red
        Position();
        Rotation(vRotation);
        Scale(vScaling);
        CreateKey(0);
        if(BoxItem_Parent != nil){ParentItem(BoxItem_Parent.id);} // Parent

        // Pivot Item
        AddNull(sName + "_Pivot");
        PivotItem = Mesh(sName + "_Pivot"); // Assign to a var
        ItemColor(5); // Color Dark Red
        ParentItem(ParentItem.id); // Parent

        // Shift Item
        AddNull(sName + "_Shift");
        ShiftItem = Mesh(sName + "_Shift"); // Assign to a var
        ItemColor(5); // Color Dark Red
        ParentItem(PivotItem.id); // Parent
        MoveTool();
        EnableXH();
        EnableYP();
        EnableZB();
        RotateTool();
        EnableXH();
        EnableYP();
        EnableZB();
        SquashTool();
        EnableXH();
        EnableYP();
        EnableZB();

        // Box Item
        BoxItem.select();
        ParentItem(ShiftItem.id); // Parent
        ItemColor(7); // Color Brown
        MoveTool();
        EnableYP();
        RotateTool();
        EnableYP();
        EnableZB();
        SquashTool();
        EnableXH();
        EnableYP();
        EnableZB();

        // Extent Item
        AddNull(sName + "_Extent");
        ExtentItem = Mesh(sName + "_Extent"); // Assign to a var
        ItemColor(5); // Color Dark Red
        ParentItem(ParentItem.id); // Parent
        Position(aBoundingBox[2].x,0.0,aBoundingBox[2].z);
        CreateKey(0);
        MoveTool();
        EnableYP();
        RotateTool();
        EnableXH();
        EnableYP();
        EnableZB();
        SquashTool();
        EnableXH();
        EnableYP();
        EnableZB();

        // Control Item
        AddNull(sName + "_Control");
        ControlItem = Mesh(sName + "_Control"); // Assign to a var
        ItemColor(12); // Color Red
        ParentItem(ParentItem.id); // Parent
        MoveTool();
        EnableYP();
        RotateTool();
        EnableYP();
        EnableZB();
        SquashTool();
        EnableXH();
        EnableYP();
        EnableZB();

        // Custom
        customshape(ParentItem,nil,0,nil,"Parent");
        customshape(PivotItem,ParentItem,8,nil,"Pivot");
        customshape(ShiftItem,ParentItem,8,nil,"Shift");
        customshape(BoxItem,ParentItem,8,nil,"");
        customshape(ExtentItem,ParentItem,8,nil,"Extent");
        customshape(ControlItem,ParentItem,6,0.15,"Control");

    // EXPRESSIONS

        // Shift_X
        createexpression(sName + "_Shift_X","max(min((( - ([" + sName + "_Control.Position.X] * 1000) ) * (1 / 5)) * (  [" + sName + "_Extent.Position.X]  ),[" + sName + "_Extent.Position.X]),-[" + sName + "_Extent.Position.X])");
        ShiftItem.select();
        attachexpression(sName + "_Shift_X",sName + "_Shift.Position.X");

        // Shift_Z
        createexpression(sName + "_Shift_Z","max(min((( - ([" + sName + "_Control.Position.Z] * 1000) ) * (1 / 5)) * (  [" + sName + "_Extent.Position.Z]  ),[" + sName + "_Extent.Position.Z]),-[" + sName + "_Extent.Position.Z])");
        ShiftItem.select();
        attachexpression(sName + "_Shift_Z",sName + "_Shift.Position.Z");

        // Pivot_X
        createexpression(sName + "_Pivot_X","min(max((( - ([" + sName + "_Control.Position.X] * 1000) ) * (1 / 5)) * (  -[" + sName + "_Extent.Position.X]  ),-[" + sName + "_Extent.Position.X]),[" + sName + "_Extent.Position.X])");
        PivotItem.select();
        attachexpression(sName + "_Pivot_X",sName + "_Pivot.Position.X");

        // Pivot_Z
        createexpression(sName + "_Pivot_Z","min(max((( - ([" + sName + "_Control.Position.Z] * 1000) ) * (1 / 5)) * (  -[" + sName + "_Extent.Position.Z]  ),-[" + sName + "_Extent.Position.Z]),[" + sName + "_Extent.Position.Z])");
        PivotItem.select();
        attachexpression(sName + "_Pivot_Z",sName + "_Pivot.Position.Z");

        // Pivot_H
        createexpression(sName + "_Pivot_H","[" + sName + "_Control.Rotation.H]");
        PivotItem.select();
        attachexpression(sName + "_Pivot_H",sName + "_Pivot.Rotation.H");

        // Pivot_P
        createexpression(sName + "_Pivot_P","mapRange([" + sName + "_Control.Position.Z],0.000,[" + sName + "_Extent.Position.Z],0.000,90.000)");
        PivotItem.select();
        attachexpression(sName + "_Pivot_P",sName + "_Pivot.Rotation.P");

        // Pivot_B
        createexpression(sName + "_Pivot_B","- mapRange([" + sName + "_Control.Position.X],0.000,[" + sName + "_Extent.Position.X],0.000,90.000)");
        PivotItem.select();
        attachexpression(sName + "_Pivot_B",sName + "_Pivot.Rotation.B");

    //

        // Control
        ControlItem.select();
        MoveTool();

        }

      }

    // Parent in Place
    if(bParentInPlace){ParentInPlace();}

    info(sTitle + " " + sVersion + " - developer: Stephen Culley - http://www.stephenculley.co.uk");
}

getlayernumber: item
{
    if(item.totallayers == 1){return(1);}
    sTokens = parse(":",item.name);
    iLayer = 0;
    if (strleft(sTokens[2],5)=="Layer")
      {
      iLayer = integer(sTokens[2]);
      }
    else
      {
      iTotal = item.totallayers;
      for(i = 1; i <= iTotal; i++)
        {
        if(item.layerVisible(i) == 1)
          {
          if(item.layerName(i) == sTokens[2])
            {
            iLayer = i;
            break;
            }
          }
        else
          {
          iTotal++;
          }
        }
      }
  return iLayer;
}

createexpression: name, expression
{
    CommandInput("GE_CreateExpression " + "\"" + name + "\"" + " " + "\"" + expression + "\"");
} 

attachexpression: name,channel
{
    CommandInput("GE_OpenWindow");
    CommandInput("GE_SetEnv " + "\"" + channel);
    CommandInput("GE_AttachExpression " + "\"" + channel + "\"" + name);
}

customshape: item,linkto,shape,scale,label
{
    SelectItem(item.id);
    ApplyServer("CustomObjHandler","LW_ItemShape");

    // ItemShapeData structure
    aItemShapeData = @"p",                // ctxt
                      "p","p",            // self, linkTo
                      "d","d","d",        // time, level, scale
                      "i","i","i","i",    // axis, fill, shape, flags
                      "f","f","f",        // clrA
                      "f","f","f",        // clrB
                      "f","f","f",        // clrT
                      "d","d","d",        // linkPos
                      "s:120",            // label
                      "s:100",            // desc
                      "p",                // alreadylist
                      "s:256",            // selfname
                      "s:256",            // linktoname
                      "i"@;               // justify
                    
    comringattach("ItemShapeComRing", "shapecomring");
    aDataBlob = comringencode(aItemShapeData,
                              0,
                              item.id, 0,
                              0.0, 0.0, 0.0,
                              0, 0, 0, 0,
                              0.0, 0.0, 0.0,
                              0.0, 0.0, 0.0,
                              0.0, 0.0, 0.0,
                              0.0, 0.0, 0.0,
                              "",
                              "",
                              0,
                              "",
                              "",
                              0);

    comringmsg("ItemShapeComRing", 100, aDataBlob);
    aItemShape = comringdecode(aItemShapeData, aDataBlob);
    if(linkto != nil){aItemShape[3] = linkto.id;}    // linkto
    if(scale != nil){aItemShape[6] = scale;}    // Scale
    aItemShape[7] = 1;    // Axis
    aItemShape[9] = shape;    // Shape
    aItemShape[23] = label; // Label
    if(linkto != nil)
        aItemShape[27] = linkto.name;  // linkto name
    aDataBlob = comringencode(aItemShapeData,
                                aItemShape[1],
                                aItemShape[2],aItemShape[3],
                                aItemShape[4],aItemShape[5],aItemShape[6],
                                aItemShape[7],aItemShape[8],aItemShape[9],aItemShape[10],
                                aItemShape[11],aItemShape[12],aItemShape[13],
                                aItemShape[14],aItemShape[15],aItemShape[16],
                                aItemShape[17],aItemShape[18],aItemShape[19],
                                aItemShape[20],aItemShape[21],aItemShape[22],
                                aItemShape[23],
                                aItemShape[24],
                                aItemShape[25],
                                aItemShape[26],
                                aItemShape[27],
                                aItemShape[28]);
    comringmsg("ItemShapeComRing", 200, aDataBlob);
    comringdetach("ItemShapeComRing");
}

shapecomring: code, data
{
}


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

LScript - Generic_StackIt (v1.2)

LScript (Layout) to stack an object upon another while parenting them. Select item to stack and then item to stack upon.

Changes
  • Now stacks multiple objects (v1.2)
  • Fixed pivot offset (v1.1)
  • Fixed getting correct boundingbox extents from layers
  • Fixed issue requiring pivot to always be at objects lowest extent
Compatible with Newtek LightWave 9.6 and above.

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

/*  
    LScript Generic - StackIt

    Generic_StackIt.ls

*/

@version 2.2
@warnings
@script generic
@name *Stack It

    sTitle = "*Stack It";
    sVersion = "v1.2";    

generic
{

    // Parent in Place
    bParentInPlace = Scene().generalopts[3];
    if(bParentInPlace){ParentInPlace();}

    // Item Select
    Items = Scene().getSelect();  
    if(Items == nil || Items.size() < 2)
      {
      info("Select an object to stack, then select object to stack upon.");
      return;
      }

    for(i = 1; i <= (Items.size() - 1);++i)
      {
      if(Items[i].genus == MESH && !Items[i].null && Items[i + 1].genus == MESH && !Items[i + 1].null)
        {
        GoToFrame(0); // Go To Frame 0
        vPivot1 = Items[i].getPivot(0.0);
        vPivot2 = Items[i + 1].getPivot(0.0);
        aBoundingBox1 = Items[i].position(getlayernumber(Items[i])); // Bounding Box      
        aBoundingBox2 = Items[i + 1].position(getlayernumber(Items[i + 1])); // Bounding Box      
        aBoundingBox1[1] -= vPivot1; 
        aBoundingBox1[2] -= vPivot1; 
        aBoundingBox2[1] -= vPivot2; 
        aBoundingBox2[2] -= vPivot2; 
        Items[i + 1].select();
        Position(vPivot1.x,aBoundingBox1[2].y - aBoundingBox2[1].y + vPivot1.y,vPivot1.z);
        CreateKey(0);    
        ParentItem(Items[i].id); // Parent
        }
      else
        {
        error("Only objects can be stacked."); 
        }
      }

    // Parent in Place
    if(bParentInPlace){ParentInPlace();}

    info(sTitle + " " + sVersion + " - developer: Stephen Culley - http://www.stephenculley.co.uk");
}

getlayernumber: item
{
    if(item.totallayers == 1){return(1);}
    sTokens = parse(":",item.name);
    iLayer = 0;
    if (strleft(sTokens[2],5)=="Layer")
      {
      iLayer = integer(sTokens[2]);
      }
    else
      {
      iTotal = item.totallayers;
      for(i = 1; i <= iTotal; i++)
        {
        if(item.layerVisible(i) == 1)
          {
          if(item.layerName(i) == sTokens[2])
            {
            iLayer = i;
            break;
            }
          }
        else
          {
          iTotal++;
          }
        }
      }
  return iLayer;
}


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

Monday, 16 April 2012

LScript - Generic_LightColor


LScript (Layout) applies colour to selected lights between frame 0 and 1. It enables changing light colour during spinning light tricks and in old school techniques like faking spectrums. The values are repeated correctly each frame by timing them to the motion blur length.

Compatible with Newtek LightWave 9.6 and above.

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

/*  
    LScript Generic - LightColor

    Generic_LightColor.ls

*/

    // Title
    sTitle = "*LightColor";

    // Version
    sVersion = "v1.0";

    // Variable
    aColor;
    aIntensity;

    // Requester
    bRequesterUpdate = false; // Update

    ctrl_c0,ctrl_c1,ctrl_c2,ctrl_c3,ctrl_c4,ctrl_c5,ctrl_c6,ctrl_c7,ctrl_c8,ctrl_c9,ctrl_c10,ctrl_c11,ctrl_c12,ctrl_c13,ctrl_c14;

generic
{

    // Item Select
    Items = Scene().getSelect();  

    bLight = false;

    for(i = 1; i <= Items.size(); i++)
      {
      if(Items[i].genus == LIGHT) bLight = true;
      }        

    if(!bLight)
      {
      info("Select a light to apply color to.");
      return;
      }        

    // Recall
    aColor[1] = recall("vColor1",<255.0,255.0,255.0>);
    aIntensity[1] = recall("nIntensity1",1.0);
    aColor[2] = recall("vColor2",<0.0,0.0,0.0>);
    aIntensity[2] = recall("nIntensity2",0.0);
    aColor[3] = recall("vColor3",<0.0,0.0,0.0>);
    aIntensity[3] = recall("nIntensity3",0.0);
    aColor[4] = recall("vColor4",<0.0,0.0,0.0>);
    aIntensity[4] = recall("nIntensity4",0.0);
    aColor[5] = recall("vColor5",<0.0,0.0,0.0>);
    aIntensity[5] = recall("nIntensity5",0.0);
    aColor[6] = recall("vColor6",<0.0,0.0,0.0>);
    aIntensity[6] = recall("nIntensity6",0.0);
    aColor[7] = recall("vColor7",<0.0,0.0,0.0>);
    aIntensity[7] = recall("nIntensity7",1.0);

    reqbegin(sTitle + " " + sVersion);

    // Reset
    ctrl_res0 = ctlbutton("Reset",50,"button_reset"); // Button Reset
    ctlsep();

    // Control
    ctrl_c0 = ctlpopup("Preset",1, @"Gradient",
                                    "RGB",
                                    "Spectrum"@);

    ctlsep();
    ctrl_c1 = ctlcolor("1",aColor[1]);
    ctrl_c2 = ctlpercent("Intensity",aIntensity[1]);
    ctrl_c3 = ctlcolor("2",aColor[2]);
    ctrl_c4 = ctlpercent("Intensity",aIntensity[2]);
    ctrl_c5 = ctlcolor("3",aColor[3]);
    ctrl_c6 = ctlpercent("Intensity",aIntensity[3]);
    ctrl_c7 = ctlcolor("4",aColor[4]);
    ctrl_c8 = ctlpercent("Intensity",aIntensity[4]);
    ctrl_c9 = ctlcolor("5",aColor[5]);
    ctrl_c10 = ctlpercent("Intensity",aIntensity[5]);
    ctrl_c11 = ctlcolor("6",aColor[6]);
    ctrl_c12 = ctlpercent("Intensity",aIntensity[6]);
    ctrl_c13 = ctlcolor("7",aColor[7]);
    ctrl_c14 = ctlpercent("Intensity",aIntensity[7]);

    interpolate();

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

    ctlrefresh(ctrl_c0,"refresh_preset"); // Preset
 
    ctlrefresh(ctrl_c1,"refresh");
    ctlrefresh(ctrl_c2,"refresh");
    ctlrefresh(ctrl_c3,"refresh");
    ctlrefresh(ctrl_c4,"refresh");
    ctlrefresh(ctrl_c5,"refresh");
    ctlrefresh(ctrl_c6,"refresh");
    ctlrefresh(ctrl_c7,"refresh");
    ctlrefresh(ctrl_c8,"refresh");
    ctlrefresh(ctrl_c9,"refresh");
    ctlrefresh(ctrl_c10,"refresh");
    ctlrefresh(ctrl_c11,"refresh");
    ctlrefresh(ctrl_c12,"refresh");
    ctlrefresh(ctrl_c13,"refresh");
    ctlrefresh(ctrl_c14,"refresh");

    return if !reqpost();

    aColor[1] = getvalue(ctrl_c1);
    aIntensity[1] = getvalue(ctrl_c2);
    aColor[2] = getvalue(ctrl_c3);
    aIntensity[2] = getvalue(ctrl_c4);
    aColor[3] = getvalue(ctrl_c5);
    aIntensity[3] = getvalue(ctrl_c6);
    aColor[4] = getvalue(ctrl_c7);
    aIntensity[4] = getvalue(ctrl_c8);
    aColor[5] = getvalue(ctrl_c9);
    aIntensity[5] = getvalue(ctrl_c10);
    aColor[6] = getvalue(ctrl_c11);
    aIntensity[6] = getvalue(ctrl_c12);
    aColor[7] = getvalue(ctrl_c13);
    aIntensity[7] = getvalue(ctrl_c14);

    // Store
    store("vColor1",aColor[1]);
    store("nIntensity1",aIntensity[1]);
    store("vColor2",aColor[2]);
    store("nIntensity2",aIntensity[2]);
    store("vColor3",aColor[3]);
    store("nIntensity3",aIntensity[3]);
    store("vColor4",aColor[4]);
    store("nIntensity4",aIntensity[4]);
    store("vColor5",aColor[5]);
    store("nIntensity5",aIntensity[5]);
    store("vColor6",aColor[6]);
    store("nIntensity6",aIntensity[6]);
    store("vColor7",aColor[7]);
    store("nIntensity7",aIntensity[7]);

    // Error
    bError = true;
    for(i = 1; i <= 7; i++)
      {
      if(aIntensity[i] > 0.0){bError = false;}
      }
    if(bError)
      {
      info("Intensity on atleast one color must be above 0.0%");
      return;
      }  

    // Camera Blur Length
    if(Camera().blurLength(0.0) < 1.0)
      {
      nCameraBlurLength = Camera().blurLength(0.0);
      }
    else
      {
      nCameraBlurLength = 1.0;
      }

    for(i = 1; i <= Items.size(); i++)
      {

      if(Items[i].genus == LIGHT)
        {

        Items[i].select();
      
    // Envelope

        AddEnvelope("Color");
        envRed = Envelope("Color.R",CHAN_PERCENT,Items[i].name);
        envGreen = Envelope("Color.G",CHAN_PERCENT,Items[i].name);
        envBlue = Envelope("Color.B",CHAN_PERCENT,Items[i].name);

        // Clear 
        while(envRed.keyCount >= 1)
          {
          envRed.deleteKey(envRed.keys[1]);       
          }
        while(envGreen.keyCount >= 1)
          {
          envGreen.deleteKey(envGreen.keys[1]);       
          }
        while(envBlue.keyCount >= 1)
          {
          envBlue.deleteKey(envBlue.keys[1]);       
          }

        if(aIntensity[1] > 0.0)
          {
          envRed.createKey(0.0,aColor[1].x * (1/255) * aIntensity[1]); 
          envRed.setKeyCurve(0.0,CHAN_LINEAR);        
          envGreen.createKey(0.0,aColor[1].y * (1/255) * aIntensity[1]); 
          envGreen.setKeyCurve(0.0,CHAN_LINEAR);        
          envBlue.createKey(0.0,aColor[1].z * (1/255) * aIntensity[1]); 
          envBlue.setKeyCurve(0.0,CHAN_LINEAR);        
          }
        else
          {
          iColor = 0;
          for(c = 1; c <= 7; c++)
            {
            if(aIntensity[c] > 0.0){iColor = c; break;}
            }
          envRed.createKey(0.0,aColor[iColor].x * (1/255) * aIntensity[iColor]); 
          envRed.setKeyCurve(0.0,CHAN_LINEAR);        
          envGreen.createKey(0.0,aColor[iColor].y * (1/255) * aIntensity[iColor]); 
          envGreen.setKeyCurve(0.0,CHAN_LINEAR);        
          envBlue.createKey(0.0,aColor[iColor].z * (1/255) * aIntensity[iColor]); 
          envBlue.setKeyCurve(0.0,CHAN_LINEAR);   
          }

        if(aIntensity[2] > 0.0)
          {           
          envRed.createKey((1 / Scene().fps) * nCameraBlurLength * ((1 / 6) * 1),aColor[2].x * (1/255) * aIntensity[2]); 
          envRed.setKeyCurve((1 / Scene().fps) * nCameraBlurLength * ((1 / 6) * 1),CHAN_LINEAR);        
          envGreen.createKey((1 / Scene().fps) * nCameraBlurLength * ((1 / 6) * 1),aColor[2].y * (1/255) * aIntensity[2]); 
          envGreen.setKeyCurve((1 / Scene().fps) * nCameraBlurLength * ((1 / 6) * 1),CHAN_LINEAR);        
          envBlue.createKey((1 / Scene().fps) * nCameraBlurLength * ((1 / 6) * 1),aColor[2].z * (1/255) * aIntensity[2]); 
          envBlue.setKeyCurve((1 / Scene().fps) * nCameraBlurLength * ((1 / 6) * 1),CHAN_LINEAR); 
          }

        if(aIntensity[3] > 0.0)
          {           
          envRed.createKey((1 / Scene().fps) * nCameraBlurLength * ((1 / 6) * 2),aColor[3].x * (1/255) * aIntensity[3]); 
          envRed.setKeyCurve((1 / Scene().fps) * nCameraBlurLength * ((1 / 6) * 2),CHAN_LINEAR);        
          envGreen.createKey((1 / Scene().fps) * nCameraBlurLength * ((1 / 6) * 2),aColor[3].y * (1/255) * aIntensity[3]); 
          envGreen.setKeyCurve((1 / Scene().fps) * nCameraBlurLength * ((1 / 6) * 2),CHAN_LINEAR);        
          envBlue.createKey((1 / Scene().fps) * nCameraBlurLength * ((1 / 6) * 2),aColor[3].z * (1/255) * aIntensity[3]); 
          envBlue.setKeyCurve((1 / Scene().fps) * nCameraBlurLength * ((1 / 6) * 2),CHAN_LINEAR); 
          }

        if(aIntensity[4] > 0.0)
          {           
          envRed.createKey((1 / Scene().fps) * nCameraBlurLength * ((1 / 6) * 3),aColor[4].x * (1/255) * aIntensity[4]); 
          envRed.setKeyCurve((1 / Scene().fps) * nCameraBlurLength * ((1 / 6) * 3),CHAN_LINEAR);        
          envGreen.createKey((1 / Scene().fps) * nCameraBlurLength * ((1 / 6) * 3),aColor[4].y * (1/255) * aIntensity[4]); 
          envGreen.setKeyCurve((1 / Scene().fps) * nCameraBlurLength * ((1 / 6) * 3),CHAN_LINEAR);        
          envBlue.createKey((1 / Scene().fps) * nCameraBlurLength * ((1 / 6) * 3),aColor[4].z * (1/255) * aIntensity[4]); 
          envBlue.setKeyCurve((1 / Scene().fps) * nCameraBlurLength * ((1 / 6) * 3),CHAN_LINEAR); 
          }

        if(aIntensity[5] > 0.0)
          {           
          envRed.createKey((1 / Scene().fps) * nCameraBlurLength * ((1 / 6) * 4),aColor[5].x * (1/255) * aIntensity[5]); 
          envRed.setKeyCurve((1 / Scene().fps) * nCameraBlurLength * ((1 / 6) * 4),CHAN_LINEAR);        
          envGreen.createKey((1 / Scene().fps) * nCameraBlurLength * ((1 / 6) * 4),aColor[5].y * (1/255) * aIntensity[5]); 
          envGreen.setKeyCurve((1 / Scene().fps) * nCameraBlurLength * ((1 / 6) * 4),CHAN_LINEAR);        
          envBlue.createKey((1 / Scene().fps) * nCameraBlurLength * ((1 / 6) * 4),aColor[5].z * (1/255) * aIntensity[5]); 
          envBlue.setKeyCurve((1 / Scene().fps) * nCameraBlurLength * ((1 / 6) * 4),CHAN_LINEAR); 
          }

        if(aIntensity[6] > 0.0)
          {           
          envRed.createKey((1 / Scene().fps) * nCameraBlurLength * ((1 / 6) * 5),aColor[6].x * (1/255) * aIntensity[6]); 
          envRed.setKeyCurve((1 / Scene().fps) * nCameraBlurLength * ((1 / 6) * 5),CHAN_LINEAR);        
          envGreen.createKey((1 / Scene().fps) * nCameraBlurLength * ((1 / 6) * 5),aColor[6].y * (1/255) * aIntensity[6]); 
          envGreen.setKeyCurve((1 / Scene().fps) * nCameraBlurLength * ((1 / 6) * 5),CHAN_LINEAR);        
          envBlue.createKey((1 / Scene().fps) * nCameraBlurLength * ((1 / 6) * 5),aColor[6].z * (1/255) * aIntensity[6]); 
          envBlue.setKeyCurve((1 / Scene().fps) * nCameraBlurLength * ((1 / 6) * 5),CHAN_LINEAR); 
          }

        if(aIntensity[7] > 0.0)
          {           
          envRed.createKey((1 / Scene().fps) * nCameraBlurLength * ((1 / 6) * 6),aColor[7].x * (1/255) * aIntensity[7]); 
          envRed.setKeyCurve((1 / Scene().fps) * nCameraBlurLength * ((1 / 6) * 6),CHAN_LINEAR);        
          envGreen.createKey((1 / Scene().fps) * nCameraBlurLength * ((1 / 6) * 6),aColor[7].y * (1/255) * aIntensity[7]); 
          envGreen.setKeyCurve((1 / Scene().fps) * nCameraBlurLength * ((1 / 6) * 6),CHAN_LINEAR);        
          envBlue.createKey((1 / Scene().fps) * nCameraBlurLength * ((1 / 6) * 6),aColor[7].z * (1/255) * aIntensity[7]); 
          envBlue.setKeyCurve((1 / Scene().fps) * nCameraBlurLength * ((1 / 6) * 6),CHAN_LINEAR); 
          }

        if(aIntensity[7] <= 0.0 || nCameraBlurLength < 1.0)
          {
          iColor = 0;
          for(c = 7; c >= 1; c--)
            {
            if(aIntensity[c] > 0.0){iColor = c; break;}
            }
          envRed.createKey(1 / Scene().fps,aColor[iColor].x * (1/255) * aIntensity[iColor]); 
          envRed.setKeyCurve(1 / Scene().fps,CHAN_LINEAR);        
          envGreen.createKey(1 / Scene().fps,aColor[iColor].y * (1/255) * aIntensity[iColor]); 
          envGreen.setKeyCurve(1 / Scene().fps,CHAN_LINEAR);        
          envBlue.createKey(1 / Scene().fps,aColor[iColor].z * (1/255) * aIntensity[iColor]); 
          envBlue.setKeyCurve(1 / Scene().fps,CHAN_LINEAR);   
          }
            
          // Repeat
          envRed.preBehavior = CHAN_REPEAT;
          envRed.postBehavior = CHAN_REPEAT;
          envGreen.preBehavior = CHAN_REPEAT;
          envGreen.postBehavior = CHAN_REPEAT;
          envBlue.preBehavior = CHAN_REPEAT;
          envBlue.postBehavior = CHAN_REPEAT;

    //

        }

      }   

}

button_reset
{
    bRequesterUpdate = true;

    setvalue(ctrl_c1,<1.0,1.0,1.0>); // Color 1
    setvalue(ctrl_c2,1.0); // Intensity 1
    setvalue(ctrl_c3,<0.0,0.0,0.0>); // Color 2
    setvalue(ctrl_c4,0.0); // Intensity 2
    setvalue(ctrl_c5,<0.0,0.0,0.0>); // Color 3
    setvalue(ctrl_c6,0.0); // Intensity 3
    setvalue(ctrl_c7,<0.0,0.0,0.0>); // Color 4
    setvalue(ctrl_c8,0.0); // Intensity 4
    setvalue(ctrl_c9,<0.0,0.0,0.0>); // Color 5
    setvalue(ctrl_c10,0.0); // Intensity 5
    setvalue(ctrl_c11,<0.0,0.0,0.0>); // Color 6
    setvalue(ctrl_c12,0.0); // Intensity 6
    setvalue(ctrl_c13,<0.0,0.0,0.0>); // Color 7
    setvalue(ctrl_c14,1.0); // Intensity 7

    // Update
    aColor[1] = getvalue(ctrl_c1);
    aIntensity[1] = getvalue(ctrl_c2);
    aColor[2] = getvalue(ctrl_c3);
    aIntensity[2] = getvalue(ctrl_c4);
    aColor[3] = getvalue(ctrl_c5);
    aIntensity[3] = getvalue(ctrl_c6);
    aColor[4] = getvalue(ctrl_c7);
    aIntensity[4] = getvalue(ctrl_c8);
    aColor[5] = getvalue(ctrl_c9);
    aIntensity[5] = getvalue(ctrl_c10);
    aColor[6] = getvalue(ctrl_c11);
    aIntensity[6] = getvalue(ctrl_c12);
    aColor[7] = getvalue(ctrl_c13);
    aIntensity[7] = getvalue(ctrl_c14); 

    bRequesterUpdate = false;

    interpolate();
}

refresh:value
{
    if(!bRequesterUpdate)
      {
      aColor[1] = getvalue(ctrl_c1);
      aIntensity[1] = getvalue(ctrl_c2);
      aColor[2] = getvalue(ctrl_c3);
      aIntensity[2] = getvalue(ctrl_c4);
      aColor[3] = getvalue(ctrl_c5);
      aIntensity[3] = getvalue(ctrl_c6);
      aColor[4] = getvalue(ctrl_c7);
      aIntensity[4] = getvalue(ctrl_c8);
      aColor[5] = getvalue(ctrl_c9);
      aIntensity[5] = getvalue(ctrl_c10);
      aColor[6] = getvalue(ctrl_c11);
      aIntensity[6] = getvalue(ctrl_c12);
      aColor[7] = getvalue(ctrl_c13);
      aIntensity[7] = getvalue(ctrl_c14);

      interpolate();
      }
}

refresh_preset:value
{

    bRequesterUpdate = true;

    if(value == 1) // Gradient
      {
      setvalue(ctrl_c1,<1.0,1.0,1.0>); // Color 1
      setvalue(ctrl_c2,1.0); // Intensity 1
      setvalue(ctrl_c3,<0.0,0.0,0.0>); // Color 2
      setvalue(ctrl_c4,0.0); // Intensity 2
      setvalue(ctrl_c5,<0.0,0.0,0.0>); // Color 3
      setvalue(ctrl_c6,0.0); // Intensity 3
      setvalue(ctrl_c7,<0.0,0.0,0.0>); // Color 4
      setvalue(ctrl_c8,0.0); // Intensity 4
      setvalue(ctrl_c9,<0.0,0.0,0.0>); // Color 5
      setvalue(ctrl_c10,0.0); // Intensity 5
      setvalue(ctrl_c11,<0.0,0.0,0.0>); // Color 6
      setvalue(ctrl_c12,0.0); // Intensity 6
      setvalue(ctrl_c13,<0.0,0.0,0.0>); // Color 7
      setvalue(ctrl_c14,1.0); // Intensity 7
      }  

    if(value == 2) // RGB
      {
      setvalue(ctrl_c1,<1.0,0.0,0.0>); // Color 1
      setvalue(ctrl_c2,1.0); // Intensity 1
      setvalue(ctrl_c3,<0.0,0.0,0.0>); // Color 2
      setvalue(ctrl_c4,0.0); // Intensity 2
      setvalue(ctrl_c5,<0.0,0.0,0.0>); // Color 3
      setvalue(ctrl_c6,0.0); // Intensity 3
      setvalue(ctrl_c7,<0.0,1.0,0.0>); // Color 4
      setvalue(ctrl_c8,1.0); // Intensity 4
      setvalue(ctrl_c9,<0.0,0.0,0.0>); // Color 5
      setvalue(ctrl_c10,0.0); // Intensity 5
      setvalue(ctrl_c11,<0.0,0.0,0.0>); // Color 6
      setvalue(ctrl_c12,0.0); // Intensity 6
      setvalue(ctrl_c13,<0.0,0.0,1.0>); // Color 7
      setvalue(ctrl_c14,1.0); // Intensity 7
      } 

    if(value == 3) // Spectrum
      {
      setvalue(ctrl_c1,<1.0,0.0,0.0>); // Color 1
      setvalue(ctrl_c2,1.0); // Intensity 1
      setvalue(ctrl_c3,<1.0,0.5,0.0>); // Color 2
      setvalue(ctrl_c4,1.0); // Intensity 2
      setvalue(ctrl_c5,<1.0,1.0,0.0>); // Color 3
      setvalue(ctrl_c6,1.0); // Intensity 3
      setvalue(ctrl_c7,<0.0,1.0,0.0>); // Color 4
      setvalue(ctrl_c8,1.0); // Intensity 4
      setvalue(ctrl_c9,<0.0,1.0,1.0>); // Color 5
      setvalue(ctrl_c10,1.0); // Intensity 5
      setvalue(ctrl_c11,<0.0,0.0,0.6255>); // Color 6
      setvalue(ctrl_c12,1.0); // Intensity 6
      setvalue(ctrl_c13,<0.5,0.0,0.5>); // Color 7
      setvalue(ctrl_c14,1.0); // Intensity 7
      }


    // Update
    aColor[1] = getvalue(ctrl_c1);
    aIntensity[1] = getvalue(ctrl_c2);
    aColor[2] = getvalue(ctrl_c3);
    aIntensity[2] = getvalue(ctrl_c4);
    aColor[3] = getvalue(ctrl_c5);
    aIntensity[3] = getvalue(ctrl_c6);
    aColor[4] = getvalue(ctrl_c7);
    aIntensity[4] = getvalue(ctrl_c8);
    aColor[5] = getvalue(ctrl_c9);
    aIntensity[5] = getvalue(ctrl_c10);
    aColor[6] = getvalue(ctrl_c11);
    aIntensity[6] = getvalue(ctrl_c12);
    aColor[7] = getvalue(ctrl_c13);
    aIntensity[7] = getvalue(ctrl_c14); 

    bRequesterUpdate = false;

    interpolate();
}

interpolate
{

    bRequesterUpdate = true;

    for(i = 1; i <= 7; i++)
      {
      if(aIntensity[i] <= 0.0)
        {


        iColorA = 0;
        for(c = i; c >= 1; c--)
          {
          if(aIntensity[c] > 0.0){iColorA = c; break;}
          }

        iColorB = 0;
        for(c = i; c <= 7; c++)
          {
          if(aIntensity[c] > 0.0){iColorB = c; break;}
          }

        if(iColorA == 0)
          {aColor[i] = aColor[iColorB];}
        else if(iColorB == 0)
          {aColor[i] = aColor[iColorA];}
        else
          {
          aColor[i] = linear1D(aColor[iColorA],aColor[iColorB],maprange01(iColorA,iColorB,i)); 
          } 


        } 
      }

      if(aIntensity[1] <= 0.0){setvalue(ctrl_c1,(1/255) * aColor[1]);} // Color 1
      if(aIntensity[2] <= 0.0){setvalue(ctrl_c3,(1/255) * aColor[2]);} // Color 2
      if(aIntensity[3] <= 0.0){setvalue(ctrl_c5,(1/255) * aColor[3]);} // Color 3
      if(aIntensity[4] <= 0.0){setvalue(ctrl_c7,(1/255) * aColor[4]);} // Color 4
      if(aIntensity[5] <= 0.0){setvalue(ctrl_c9,(1/255) * aColor[5]);} // Color 5
      if(aIntensity[6] <= 0.0){setvalue(ctrl_c11,(1/255) * aColor[6]);} // Color 6
      if(aIntensity[7] <= 0.0){setvalue(ctrl_c13,(1/255) * aColor[7]);} // Color 7

    bRequesterUpdate = false;

}

// MAP RANGE

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

// INTERPOLATION

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


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