Feedback

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

Friday, 10 June 2011

LScript - Motion_Channel


LScript (Layout) to make one selected channel drive another selected channel.
Changes

  • Input Channels - X,Y,Z,H,P,B,SX.SY,SZ
  • Output Channels - X,Y,Z,H,P,B,SX.SY,SZ
  • Operators - -,+,Abs
  • Channel "multiplier" added

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

    Motion_Channel.ls

*/

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

    // Title
    sTitle = "*Channel";

    // Version
    sVersion = "v1.0";

    ChannelItem = nil;
    ChannelItemName = "nil";

    iInputChannel = 1;
    iOutputChannel = 1;
    iOperator = 1;
    nMultiplier = 1.0;

create
{
    setdesc("*Channel - Select Item");

    info("Channel - Select Item");
}

destroy
{
}

process: ma, frame, time
{     
    // Variables

    vPosition = ma.get(POSITION,time);
    vRotation = ma.get(ROTATION,time);
    vScaling = ma.get(SCALING,time);

    nInput = 0.0;

    if(ChannelItemName != "nil") {ChannelItem = Mesh(ChannelItemName); ChannelItemName = "nil";}
    if(ChannelItem)
        {
        setdesc(sTitle + " - " + ChannelItem.name); 
        vChannelPosition = ChannelItem.getPosition(time);
        vChannelRotation = ChannelItem.getRotation(time);
        vChannelScaling = ChannelItem.getScaling(time);
        }
    else
        {
        setdesc(sTitle + " - Select Item");
        vChannelPosition = <0,0,0>;
        vChannelRotation = <0,0,0>;
        vChannelScaling = <0,0,0>;
        }
       

    // Input Channel
    if(iInputChannel == 1)
      nInput = vChannelPosition.x;
    else if(iInputChannel == 2)
      nInput = vChannelPosition.y;
    else if(iInputChannel == 3)
      nInput = vChannelPosition.z;
    else if(iInputChannel == 4)
      nInput = vChannelRotation.x;
    else if(iInputChannel == 5)
      nInput = vChannelRotation.y;
    else if(iInputChannel == 6)
      nInput = vChannelRotation.z;
    else if(iInputChannel == 7)
      nInput = vChannelScaling.x;
    else if(iInputChannel == 8)
      nInput = vChannelScaling.y;
    else if(iInputChannel == 9)
      nInput = vChannelScaling.z;

    // Multiplier
    nInput *= nMultiplier;

    // Output

    // +
    if(iOperator == 1)
        {
        if(iOutputChannel == 1)
          vPosition.x += nInput;
        else if(iOutputChannel == 2)
          vPosition.y += nInput;
        else if(iOutputChannel == 3)
          vPosition.z += nInput;
        else if(iOutputChannel == 4)
          vRotation.x += nInput;
        else if(iOutputChannel == 5)
          vRotation.y += nInput;
        else if(iOutputChannel == 6)
          vRotation.z += nInput;
        else if(iOutputChannel == 7)
          vScaling.x += nInput;
        else if(iOutputChannel == 8)
          vScaling.y += nInput;
        else if(iOutputChannel == 9)
          vScaling.z += nInput;
        }

    // -
    else if(Operator == 2)
        {
        if(iOutputChannel == 1)
          vPosition.x -= nInput;
        else if(iOutputChannel == 2)
          vPosition.y -= nInput;
        else if(iOutputChannel == 3)
          vPosition.z -= nInput;
        else if(iOutputChannel == 4)
          vRotation.x -= nInput;
        else if(iOutputChannel == 5)
          vRotation.y -= nInput;
        else if(iOutputChannel == 6)
          vRotation.z -= nInput;
        else if(iOutputChannel == 7)
          vScaling.x -= nInput;
        else if(iOutputChannel == 8)
          vScaling.y -= nInput;
        else if(iOutputChannel == 9)
          vScaling.z -= nInput;
        }

    // Abs
    else if(iOperator == 3)
        if(nMultiplier >= 0)
            {
            if(iOutputChannel == 1)
              vPosition.x += abs(nInput);
            else if(iOutputChannel == 2)
              vPosition.y += abs(nInput);
            else if(iOutputChannel == 3)
              vPosition.z += abs(nInput);
            else if(iOutputChannel == 4)
              vRotation.x += abs(nInput);
            else if(iOutputChannel == 5)
              vRotation.y += abs(nInput);
            else if(iOutputChannel == 6)
              vRotation.z += abs(nInput);
            else if(iOutputChannel == 7)
              vScaling.x += abs(nInput);
            else if(iOutputChannel == 8)
              vScaling.y += abs(nInput);
            else if(iOutputChannel == 9)
              vScaling.z += abs(nInput);
            }
        else
            {
            if(iOutputChannel == 1)
              vPosition.x -= abs(nInput);
            else if(iOutputChannel == 2)
              vPosition.y -= abs(nInput);
            else if(iOutputChannel == 3)
              vPosition.z -= abs(nInput);
            else if(iOutputChannel == 4)
              vRotation.x -= abs(nInput);
            else if(iOutputChannel == 5)
              vRotation.y -= abs(nInput);
            else if(iOutputChannel == 6)
              vRotation.z -= abs(nInput);
            else if(iOutputChannel == 7)
              vScaling.x -= abs(nInput);
            else if(iOutputChannel == 8)
              vScaling.y -= abs(nInput);
            else if(iOutputChannel == 9)
              vScaling.z -= abs(nInput);
            }

// ma

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

}

load: what,io
{
    if(what == SCENEMODE)   // processing an ASCII scene file
    {
        ChannelItemName = io.read().asStr();
        iInputChannel = io.read().asInt();
        iOutputChannel = io.read().asInt();
        iOperator = io.read().asInt();
        nMultiplier = io.read().asNum();
    }
}

save: what,io
{
    if(what == SCENEMODE)
    {

        if(ChannelItem != nil)
            {
            io.writeln(string(ChannelItem.name));
            }
        else
            {
            io.writeln("nil");
            }    

        io.writeln(iInputChannel);
        io.writeln(iOutputChannel);
        io.writeln(iOperator);
        io.writeln(nMultiplier);

    }
}

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

    ctrl_c0 = ctlmeshitems("Channel Item",ChannelItem);
    ctrl_c1 = ctlchoice("Input Channel",iInputChannel,@"X","Y","Z","H","P","B","SX","SY","SZ"@);
    ctrl_c2 = ctlchoice("Output Channel",iOutputChannel,@"X","Y","Z","H","P","B","SX","SY","SZ"@);
    ctrl_c3 = ctlchoice("Operator",iOperator,@"+","-","Abs"@);
    ctrl_c4 = ctlnumber("Multiplier",nMultiplier);

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

    return if !reqpost();

    ChannelItem = getvalue(ctrl_c0);    
    iInputChannel = getvalue(ctrl_c1);
    iOutputChannel = getvalue(ctrl_c2);
    iOperator = getvalue(ctrl_c3);
    nMultiplier = getvalue(ctrl_c4);

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

No comments:

Post a Comment