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_Shift


LScript (Layout) to shift channels by another objects or parent motion. It is a easier way to setup offsets for shifted pivot setups where an object parented to another can shift its pivot back to place to allow its parent pivot to move freely.

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

    Motion_Shift.ls

*/

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

    // Title
    sTitle = "*Shift";

    // Version
    sVersion = "v1.0";

    // Item
    ControlItem = nil;
    ControlItemName = "nil";

    // Variable
    nMultiplierX = 0.0;
    nMultiplierY = 0.0;
    nMultiplierZ = 0.0;
    nMultiplierH = 0.0;
    nMultiplierP = 0.0;
    nMultiplierB = 0.0;
    nMultiplierSX = 0.0;
    nMultiplierSY = 0.0;
    nMultiplierSZ = 0.0;

create
{
    setdesc(sTitle + " - Parent");

    info("Shift - Parent used unless Item is selected");
}

destroy
{
}

process: ma, frame, time
{     
    // Variables

    vPosition = ma.get(POSITION,time);
    vRotation = ma.get(ROTATION,time);
    vScale = ma.get(SCALING,time);
    vControlItemPosition = <0,0,0>;
    vControlItemRotation = <0,0,0>;
    vControlItemScale = <0,0,0>;

    if(ControlItemName != "nil") {ControlItem = Mesh(ControlItemName); ControlItemName = "nil";}
    if(ControlItem)
        {
        setdesc(sTitle + " - " + ControlItem.name); 
        vControlItemPosition = ControlItem.getPosition(time);
        vControlItemRotation = ControlItem.getRotation(time);
        vControlItemScale = ControlItem.getScaling(time);
        }
    else
        {
        Item = ma.objID;
        ItemParent = Item.parent;
        if(ItemParent)
            {
            setdesc(sTitle + " - Parent");
            vControlItemPosition = ItemParent.getPosition(time);
            vControlItemRotation = ItemParent.getRotation(time);
            vControlItemScale = ItemParent.getScaling(time);
            }
        }
       
    // Position / Rotation / Scale
    vPosition.x += (vControlItemPosition.x * nMultiplierX);
    vPosition.y += (vControlItemPosition.y * nMultiplierY);
    vPosition.z += (vControlItemPosition.z * nMultiplierZ);
    vRotation.x += (vControlItemRotation.x * nMultiplierH);
    vRotation.y += (vControlItemRotation.y * nMultiplierP);
    vRotation.z += (vControlItemRotation.z * nMultiplierB);
    vScale.x += (vControlItemScale.x * nMultiplierSX);
    vScale.y += (vControlItemScale.y * nMultiplierSY);
    vScale.z += (vControlItemScale.z * nMultiplierSZ);

// ma

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

}

load: what,io
{
    if(what == SCENEMODE)   // processing an ASCII scene file
    {
        ControlItemName = io.read().asStr();
        nMultiplierX = io.read().asNum();
        nMultiplierY = io.read().asNum();
        nMultiplierZ = io.read().asNum();
        nMultiplierH = io.read().asNum();
        nMultiplierP = io.read().asNum();
        nMultiplierB = io.read().asNum();
        nMultiplierSX = io.read().asNum();
        nMultiplierSY = io.read().asNum();
        nMultiplierSZ = io.read().asNum();

    }
}

save: what,io
{
    if(what == SCENEMODE)
    {
        if(ControlItem != nil)
            {
            io.writeln(string(ControlItem.name));
            }
        else
            {
            io.writeln("nil");
            }    

        io.writeln(nMultiplierX);
        io.writeln(nMultiplierY);
        io.writeln(nMultiplierZ);
        io.writeln(nMultiplierH);
        io.writeln(nMultiplierP);
        io.writeln(nMultiplierB);
        io.writeln(nMultiplierSX);
        io.writeln(nMultiplierSY);
        io.writeln(nMultiplierSZ);
    }
}

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

    ctrl_c0 = ctlmeshitems("Control Item",ControlItem);
    ctrl_c1 = ctlnumber("Position Multiplier X",nMultiplierX);
    ctrl_c2 = ctlnumber("Position Multiplier Y",nMultiplierY);
    ctrl_c3 = ctlnumber("Position Multiplier Z",nMultiplierZ);
    ctrl_c4 = ctlnumber("Rotation Multiplier H",nMultiplierH);
    ctrl_c5 = ctlnumber("Rotation Multiplier P",nMultiplierP);
    ctrl_c6 = ctlnumber("Rotation Multiplier B",nMultiplierB);
    ctrl_c7 = ctlnumber("Scale Multiplier X",nMultiplierSX);
    ctrl_c8 = ctlnumber("Scale Multiplier Y",nMultiplierSY);
    ctrl_c9 = ctlnumber("Scale Multiplier Z",nMultiplierSZ);

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

    return if !reqpost();

    ControlItem = getvalue(ctrl_c0);
    nMultiplierX = getvalue(ctrl_c1);
    nMultiplierY = getvalue(ctrl_c2);
    nMultiplierZ = getvalue(ctrl_c3);
    nMultiplierH = getvalue(ctrl_c4);
    nMultiplierP = getvalue(ctrl_c5);
    nMultiplierB = getvalue(ctrl_c6);
    nMultiplierSX = getvalue(ctrl_c7);
    nMultiplierSY = getvalue(ctrl_c8);
    nMultiplierSZ = getvalue(ctrl_c9);

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

No comments:

Post a comment