Thoughts on animation scripting language

Some progress (was re: Thoughts on ani...)
Hi all,

I've been playing around with the scripting functionality this weekend after having taken a break for some time.

So I wanted to show the progress as I'm still open to suggestions on the api / core functions available to to end user.

Short clip of a test animation

This animation uses the new direct LDraw ref line access. This makes it possible to do some mass mutating fun stuff e.g. effecting every brick in a model.

The lua source code for this information is shown at the end of the clip (has clearer highlighting), but I'll give it here too:

function limit(v, min, max)

  if v<min then
  if v>max then
  return v;

function register()

  --global defs
  rcktTime=0;  --timespan (seconds) for rocket to get to target
  exTime=3;    --timespan for explosion (seconds)
  --create/link animation obj
  local myAni=ldc.animation('Weapons test');
  myAni:setLength(totTime); --seconds
  myAni:setFPS(25); --low fps for screencap
  myAni:setEvent('play', 'preCalcDeps');
  myAni:setEvent('frameChange', 'calcFrame');

function preCalcDeps()

  --Link submodels and their main refs
  local sfMain=ldc.subfile();
  local refShack=sfMain:getRef('shack.ldr');
  local refDude=sfMain:getRef('dude.ldr');
  local sfDude=refDude:getSubfile();
  local refWeapon=sfDude:getRef('rocketLauncher.ldr');
  --Link needed groups'rocket');  
  local'Group 1'); --helper grp so user can drag target around

  --get floor from first tree ref

  local impCen=ldc.vector(grpTarget:getPos());
  grpTarget:setVisible(false); --hide helper part(s)
  --point dude to target
  -- todo
  local ori=ldc.matrix();
  local angle=45;
  ori:setRotate(angle, 0, -1, 0);
  --Prep the pos and direction vectors for all refs in the shack model
  for i=1, refCnt do
    local tmp=ldc.vector(refPos[i]);

function calcFrame()

  local curAni=ldc.animation.getCurrent();

  local curTime=curAni:getFrameNr()/curAni:getFrameCnt()*totTime;
  if curTime<rcktTime then
    --Rocket animation
    --explode the shack
    for i=1, refCnt do
      local dx, dy, dz=refDir[i]:get();
      local x, y, z=refPos[i]:get();
      x=x + curTime*exSpeed*dx;
      y=y + curTime*exSpeed*dy + 0.5*grav*curTime*curTime;;
      z=z + curTime*exSpeed*dz;
      --x=limit(x, -500, 500);
      y=limit(y, -10000, floor);
      --z=limit(z, -500, 500);

      local ref=sfShack:getRef(i);
      ref:setPos(x, y, z);

« Next Oldest | Next Newest »

Messages In This Thread
Some progress (was re: Thoughts on ani...) - by Roland Melkert - 2014-07-07, 2:24

Forum Jump:

Users browsing this thread: 1 Guest(s)