LDraw.org Discussion Forums
Thoughts on animation scripting language - Printable Version

+- LDraw.org Discussion Forums (https://forums.ldraw.org)
+-- Forum: LDraw Programs (https://forums.ldraw.org/forum-7.html)
+--- Forum: LDraw Editors and Viewers (https://forums.ldraw.org/forum-11.html)
+--- Thread: Thoughts on animation scripting language (/thread-12368.html)

Pages: 1 2 3 4


Re: Some progress (was re: Thoughts on ani...) - Michael Horvath - 2014-07-08

Can the animations be exported to POV-Ray? What are your plans in this regard?


Re: Some progress (was re: Thoughts on ani...) - Roland Melkert - 2014-07-08

The upcoming version will probably only have OpenGL export (to bmp's) in the final version.

But I do plan to add Povray export at some point (probably version 1.5). This because I want to establish the basics first, so I won't have to write/adjust the export code multiple times.


Relative movement framework (was re: Thoughts on ani...) - Roland Melkert - 2014-07-19

Hi all,

I've been playing around with lua, and it's even more dynamic than I hoped. So I'm glad I choose it over an own scripting language based on the comments above.

It's so powerful it allows for setting up a generic extremely flexible basic connection system. Something I first considered doing using api functions. But the below script completly handles it using only the (matrix,vector,ref,subfile) LDCad interaction objects.

Given the below script and the demo clip I was hoping to get some feedback suggestions on the current state of the language/api.

Some questions I have are:
  • Is it (somewhat) understandable or do people prefer some more hardcoded solutions for these kinds of animations?
  • Do you think this frame work is good enough for animation you would like to create
  • What kind of lowlevel functions would you like to see for use in custom animations?

Any feedback is welcome.

Youtube clip of relative movement demo

And here's the script used in the youtube clip:

Code:
function register()

  local myAni=ldc.animation('Rel move test');
  myAni:setLength(10); --seconds
  myAni:setFPS(25);
  myAni:setEvent('play', 'preCalcRelMoveDeps');
  myAni:setEvent('frameChange', 'calcRelMoveFrame');
end

function calcRelPos(cur, parent)

  --convert ref's abs pos to it's relative position 'inside' it's parent.
  if cur.ref~=nil then
  
    local pp
  
    if parent.ref~=nil then
      pp=parent.ref:getPos()
    else
      pp=ldc.vector()
    end
    
    cur.relPos=cur.ref:getPos()-pp
  end
  
  --Handle child connections recursively
  if cur.con~=nil then
    for _,con in ipairs(cur.con) do
      calcRelPos(con, cur)
    end
  end

end

function calcCon(cur, parentPosOri)

  --Calculate posOri for this connection
  local posOri=ldc.matrix()
  if cur.calc~=nil then

    --calc placement
    cur.calc(cur, posOri)
    posOri:mulAB(parentPosOri)

    --incl orgOri only in set to compensate for the refereced model's base orientation
    cur.ref:setPosOri(cur.orgOri*posOri)
  end
  
  --Handle child connections recursively
  if cur.con~=nil then
    for _,con in ipairs(cur.con) do
      calcCon(con, posOri)
    end
  end

end

basicAngleCalcFunc=function(cur, posOri)

    --Basic relative single axis placement
    posOri:setRotate(cur.angle, cur.rotAxis)
    posOri:mulTranslateAB(cur.relPos)

end

colorRotateFunc=function(cur, posOri)

    --Basic relative single axis placement
    posOri:setRotate(cur.angle, cur.rotAxis)
    posOri:mulTranslateAB(cur.relPos)
    
    --play with the ref's color
    cur.ref:setColor(math.abs(cur.angle/45))
end

function preCalcRelMoveDeps()

  --link refs
  local sfMain=ldc.subfile();
  arm1=sfMain:getRef(1)
  arm2=sfMain:getRef(2)
  arm3=sfMain:getRef(3)
  arm4=sfMain:getRef(4)

  --Connection blocks
  root={
    con={}
  }
  
  conArm1={
    ref=arm1,
    relPos=ldc.vector(),
    orgOri=arm1:getOri(),
    angle=0,
    rotAxis=ldc.vector(0,0,1),
    calc=basicAngleCalcFunc,
    con={}
  }
  
  conArm2={
    ref=arm2,
    relPos=ldc.vector(),
    orgOri=arm2:getOri(),
    angle=0,
    rotAxis=ldc.vector(0,0,1),
    calc=basicAngleCalcFunc,
    con={}
  }

   conArm3={
    ref=arm3,
    relPos=ldc.vector(),
    orgOri=arm3:getOri(),
    angle=0,
    rotAxis=ldc.vector(0,0,1),
    calc=basicAngleCalcFunc,
    con={}
  }
  
  conArm4={
    ref=arm4,
    relPos=ldc.vector(),
    orgOri=arm4:getOri(),
    angle=0,
    rotAxis=ldc.vector(0,0,1),
    calc=basicAngleCalcFunc,
    con={}
  }  
  
  --Connection tree
  root.con={conArm1}
  conArm1.con={conArm2, conArm4}
  conArm2.con={conArm3}  
    
  --Caluclate rel positions
  calcRelPos(root)
end

function calcRelMoveFrame()

  local curAni=ldc.animation.getCurrent();
  local totTime=curAni:getLength()
  local curTime=totTime*curAni:getFrameNr()/curAni:getFrameCnt()
  
  --calc connection angles for the current frame
  if curTime<3 then
    conArm1.angle=45*curTime/3
  else
    conArm1.angle=45
  end
  
  if curTime>3 then
    if curTime>6 then
      conArm2.angle=-30
    else
      conArm2.angle=-30*(curTime-3)/3
    end
  else
      conArm2.angle=0
  end

  if curTime>6 then
    conArm3.angle=-60*(curTime-6)/4
  else
    conArm3.angle=0
  end
  
  conArm4.angle=curTime/totTime*360*2

  --apply angles
  calcCon(root)
end

register();



Preview of LDCad 1.4 animation scripting api (was re: Thoughts on ani...) - Roland Melkert - 2014-09-17

Hi all,

I just finished the API for the upcoming 1.4 version of my LDCad based on the stuff discussed in this thread.

During testing I wrote a basic reference page for the scripting functions and objects (technically lua tables).

I decided to put it online ahead of the actual 1.4 version in the hopes somebody might notice something weird or has additional feedback which I then still could apply to 1.4 beta 1.

The page is at www.melkert.net/LDCad/docs/scriptAPI

I also wrote an (even shorter more basic) page show casing some bare minimum examples, namely:

The page is at www.melkert.net/LDCad/docs/scriptExamples

Any feedback (and or spelling/grammar corrections) are welcome.


Re: Preview of LDCad 1.4 animation scripting api (was re: Thoughts on ani...) - Michael Heidemann - 2014-09-20

I just had a quick look at the lua language documentation.
As I am not familar with java or c language it would help a lot to have a sample line for each function/method. Also some results of functions are unclear to me. For example:
Code:
get
Get returns x,y and z in one go.
This function has no additional parameters.
How is the notation of functions that returns something?
In this special case: what is returned? - a string - a vector??

Maybe i am stupid. Hopefully these are good questions Smile


Re: Preview of LDCad 1.4 animation scripting api (was re: Thoughts on ani...) - Roland Melkert - 2014-09-20

The lua reference documentation isn't the best of it's kind imho (nor is mine probably Smile ), so I totally understand things can be a bit confusing.

A fun thing in lua is functions can return multiple values, I make use of that in the mentioned get function so you can fetch the vector object's internal variables in one statement like so:

Code:
local x, y, z=myVec:get()

You can then use the three normal number variables to do some manual (vector) math.

Hope that makes sense, I'll try to add some statement examples to the more off beat functions.

Thanks for the suggestion.


Re: Preview of LDCad 1.4 animation scripting api (was re: Thoughts on ani...) - Michael Heidemann - 2014-09-20

Ok, that function makes great sense!

But I think you can imagine that my main concern is the description and help for each function I hope.

The old school description and help files of visual basic I liked a lot. Today you often only get samples, but in most cases there is plenty of room for misunderstanding the underlying logic.