Thoughts on animation scripting language


Re: Thoughts on animation scripting language
#25
I've been playing around with lua for a couple of weeks now, and managed to set up a decent basic interface with the LDCad internals.

The below lua script is my current test script, everything in it actually works (compile/runtime wise) and I was wondering if it is somewhat 'understandable'. Or do people think it's to lowlevel?

Code:
--Initialization----
function register()

  local myAni=ldc.animation('Test animation 1');
  myAni:setFPS(25);
  myAni:setLength(2); --seconds
  myAni:setEvent('frameChange', 'frameChange');
  myAni:setEvent('play', 'play');

  myAni=ldc.animation('Test animation 2');
  myAni:setFPS(25);
  myAni:setLength(10); --seconds
  myAni:setEvent('frameChange', 'frameChange');
  myAni:setEvent('play', 'play');
end

--ldc.setPrint2Log(true);
--ldc.setPrint2Console(true);
print('apiVersion: ',ldc.getApiVersion());
register();



--Animation functions-----
function play()

  doAltTest=false; --in order to test the matrix class wrapper
  totRotCnt=2; --nr of rotations within the animation length

  --try to bind upto 3 groups
  grp1=ldc.group('Group 1');
  grp2=ldc.group('Group 2');
  grp3=ldc.group('Group 3');

  local ani=ldc.animation.getCurrent();
  print('fps: ', ani:getFPS(), ', frameCnt: ',ani:getFrameCnt());
end

function frameChange()

  local ani=ldc.animation.getCurrent();
  local angle1=ani:getFrameNr()/ani:getFrameCnt()*totRotCnt*360;

  if (grp2:isLinked() and grp3:isLinked()) then

    --full gear rotation test
    local angle2=-0.5*angle1+(360/16/2);
    local angle3=-0.2*angle2+(360/40/2);

    print('frame: ',ani:getFrameNr(),', angle1: ',angle1, ', angle2: ', angle2, ', angle3: ', angle3);

    local ori=ldc.matrix();
    ori:mulRotateAB(angle1, 0, 0, 1);
    grp1:setOri(ori);

    ori:setRotate(angle2, 0, 0, 1);
    grp2:setOri(ori);

    if doAltTest then

      --rel rotation test (excuse to play more with matrix and vector userdata)
      pos=ldc.vector(90, 40, 70);
      mat=ldc.matrix();
      mat:mulTranslateAB(pos);
      mat:mulAB(ori);
      pos:scale(-1);
      mat:mulTranslateAB(pos);
      grp3:setPosOri(mat);
    else
      ori:setRotate(angle3, 0, 0, 1);
      grp3:setOri(ori);
    end

  else

    --single rotating group test
    local ori=ldc.matrix();
    ori:mulRotateAB(angle1, 1, 0, 0);
    grp1:setOri(ori);

  end

end

I'm also thinking to add a matrixstack object, so you could use that similar to the OpenGL intermediate mode.

Anyhow if anyone has additional suggestions for api functions/functionality I'm open to suggestions.
Reply
« Next Oldest | Next Newest »



Messages In This Thread
Re: Thoughts on animation scripting language - by Roland Melkert - 2014-03-08, 18:27

Forum Jump:


Users browsing this thread: 6 Guest(s)