kaanguyr

[Software] LUA - Animation for LDcad

Recommended Posts

Hi there.

I'm a one-year LDcad user and now a newbie with LUA and animation. I use LDcad v1.5 on Ubuntu 16.4 LTS. I have reproduced the example in the Roland Merkel Youtube, simplified it and, after some time to struggle, I have an error "Active refline link needed" in the line reading ax1:setOri(ori). I consulted the Message error script console ldcad1.5 topic in the LDraw forum, but this is not the case, and there is no information about LUA in the Internet.  I send the animation2.mpd and the .lua files for examination. All seems to be in order, but nothing happens.

Any suggestion? Thanks in advance for your help.

=========== animation2.mpd ===========================

0 FILE main.ldr
0 Author: Conrad G.-Anleo
0 !LDCAD SCRIPT [source=animation2.lua]
1 16 0 0 0 1 0 0 0 1 0 0 0 1 axel1.ldr
0 FILE axel1.ldr
0 Author: Conrad G.-Anleo
1 7 0 0 0 0 1 0 0 0 -1 -1 0 0 32073.dat
1 14 0 0 0 1 0 0 0 1 0 0 0 1 32072.dat

========== animation2.lua =================

--[[
     animation2.lua
     (c) Conrad G.-Anleo
]]

function register()

  local ani=ldc.animation('demo')
  ani:setLength(20)
  ani:setEvent('frame', 'onFrame')
end

function onFrame()

  local ani=ldc.animation('demo')
  local mainSf=ldc.subfile()
  local ori=ldc.matrix()
  local angle=-4*360*ani:getFrameTime()/ani:getLength()

  local ax1=mainSf:getRef('axle1')
  ori:setRotate(angle, 1, 0, 0)
  ax1:setOri(ori)
end

register()

============= END ==============================

 

Share this post


Link to post
Share on other sites

The setOri fails because the ax1 variable isn't set as 'axle1' is not found.

 

You must use

local ax1=mainSf:getRef('axel1.ldr')

Also to rotate the gear axle you'll need to rotate around the z axis: setRotate(angle, 0, 0, 1)

Hope this gets you back on track :)

 

Share this post


Link to post
Share on other sites

Ooooops!

I feel so stupid! So many times I reread the script without realizing the typing error: 'axel1' instead of 'axle1'. I corrected the mistyping and here you are: Same Error. There must be a 'newbie' error, I know, but I'm lost. That's the reason I reduced the example to your variables set, and to only one axe: simplicity.

Don't mind the matrix. I forget always which set of zeroes goes with a specific axle. I always solve it by 'try & error' (an a reread of your notes about LDCad) :classic:

Thanks for your patience and quick answer,

The script is unchanged, The modet now is:

0 FILE main.ldr
0 Author: Conrad G.-Anleo
0 !LDCAD SCRIPT [source=animation2.lua]
1 16 0 0 0 1 0 0 0 1 0 0 0 1 axle1.ldr
0 FILE axle1.ldr
0 Author: Conrad G.-Anleo
1 7 0 0 0 0 1 0 0 0 -1 -1 0 0 32073.dat
1 14 0 0 0 1 0 0 0 1 0 0 0 1 32072.dat

 

 

 

 

Share this post


Link to post
Share on other sites
42 minutes ago, kaanguyr said:

 typing error: 'axel1' instead of 'axle1'. I corrected the mistyping and here you are: Same Error. There must be a 'newbie' error, I know, but I'm lost.

Don't forget to include '.ldr' in the getRef line.

The getRef function needs the literal name of the (Nth) used part you want to link to, the easiest way to get that name is by copying it from the properties window (like i do in the second animation tutorial youtube clip.)

If that link fails (part not found) it will cause the mentioned error on the first usage attempt (setOri in this case).

Edited by roland

Share this post


Link to post
Share on other sites

Yeah!!!,

You got it!. It was the.ldr in the GetRef line. I presumed it was the block name, not the filename. Thank you. I owe you a postcard. :classic:

Share this post


Link to post
Share on other sites

Hello Roland. It's me again.

As you can see I'm learning LUA applied to LDCad in an intensive manner. It's something like "LUA - From Dummy to Expert in One Week" :wink:

Now, there is a new question: What Does the following error message mean? Playback is to slow for 25 fps at an avg frame time of 45.77ms. I got it just viewing one of your examples without changing anything, [5580.mpd and the corresponding .lua] and others. Playing a little with my files I get the same error (time (ms) changes, offcourse), specially with more "complex" models.  i.e.: Nothing to note with very simple models (a few parts), but error with the 42039.mpd trying to open the doors or the rear.

I've read all the documentation before writing this post, I promise.

Thanks to you in advance, as usual.

Share this post


Link to post
Share on other sites

I can answer on this one... this means that your model is too complex and/or your computer hardware is not powerful enough to provide real time rendering at this frame rate. You'll have to lower required frame rate, either in default settings (prefs->animation), or using setFPS meta, or using the animation panel. Note that you can still generate a high fps video (but not real time) using the export function (view ->editing views -> openGL animation export)

Share this post


Link to post
Share on other sites

Slow playback is usually because of the rendering being to slow as the lua script execution itself is rarely above 1ms.

Also I did make some optimizations in 1.6 regarding the fps timing as 1.5 sometimes has false timings on that front.

Has the 5580 model a decent render time (e.g. <20ms reported in left bottom corner) during editing?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.