LDCad Animation puzzle


Animation puzzle
#1

.ldr   animationDemo.ldr (Size: 1.35 KB / Downloads: 1)
I'm using LDCad 1.6d, working on an animation, and have a baffling problem.  I can recreate the problem using Roland's original basic animation demo on YouTube:

I create the model and copy his LUA script. See aniDemoModel.png

As soon as I launch the LUA script, the Axle1 sub-model jumps to a new position on the first frame.  It also loses the 13° rotation that allowed its 14 tooth gear to mesh correctly with the Axle2 gear.  See aniDemoMove.png

Then using Roland's setRotate(angle, 1, 0, 0) the sub-model rotates around the wrong axis.  See aniDemoWrongAxis.png

Changing setRotate() to "angle, 0, 0, 1" fixes the wrong axis problem so the sub-model rotates around the correct axis, but I can't find any way to keep the sub-model from jumping to the new position and losing its 13° adjustment.

I've done other animations (which still work) and have never seen this problem.  Now it's happening to every new model I make!


Model:
[Image: aniDemoModel.png]

Move:
[Image: aniDemoMove.png]

Wrong axis:
[Image: aniDemoWrongAxis.png]

LDR file:
Code:
0 FILE main.ldr
0 Name: animationDemo
0 Author: LDCad
0 !LDCAD SCRIPT [source=animationDemo.lua]
1 14 0 0 0 1 0 0 0 1 0 0 0 1 3702.dat
1 14 50 0 -30 0 0 1 0 1 0 -1 0 0 3700.dat
1 14 -70 0 -30 0 0 1 0 1 0 -1 0 0 3700.dat
1 14 -10 0 -30 0 0 1 0 1 0 -1 0 0 3700.dat
1 14 0 0 -60 1 0 0 0 1 0 0 0 1 3702.dat
1 14 -70 -8 -30 0 0 1 0 1 0 -1 0 0 3710.dat
1 14 -10 -8 -30 0 0 1 0 1 0 -1 0 0 3710.dat
1 14 50 -8 -30 0 0 1 0 1 0 -1 0 0 3710.dat
1 14 50 24 -30 0 0 1 0 1 0 -1 0 0 3710.dat
1 14 -10 24 -30 0 0 1 0 1 0 -1 0 0 3710.dat
1 14 -70 24 -30 0 0 1 0 1 0 -1 0 0 3710.dat
1 16 -23 10 -30 0 0 1 0 1 0 -1 0 0 Axle2.ldr
1 14 50 -16 -30 0 0 1 0 1 0 -1 0 0 3023.dat
1 14 50 -40 -30 0 0 1 0 1 0 -1 0 0 3700.dat
1 16 60 -30 -30 1 0 0 0 0.99 0.139 0 -0.139 0.99 Axle3.ldr
1 16 -40 10 -80 -0.974 -0.225 0 -0.225 0.974 0 0 0 -1 Axle1.ldr
0 FILE Axle1.ldr
0 Author: LDraw
1 71 0 0 0 1 0 0 0 1 0 0 0 1 3736.dat
1 0 0 0 -50 0 0 -1 0 1 0 1 0 0 3706.dat
1 71 0 0 -67 -1 0 0 0 1 0 0 0 -1 4143.dat
1 71 0 0 -99.997 1 0.001 0 -0.001 1 0 0 0 1 3713.dat
1 71 -30 0 12 0 0.139 -0.99 0 0.99 0.139 1 0 0 3749.dat
0 FILE Axle2.ldr
0 Author: LDraw
1 71 0 0 0 1 0 0 0 1 0 0 0 1 4143.dat
1 0 0 0 53 0 0 1 0 1 0 -1 0 0 3706.dat
1 71 0 0 93 1 0 0 0 1 0 0 0 1 3647.dat
0 FILE Axle3.ldr
0 Author: LDraw
1 71 0 0 0 1 0 0 0 1 0 0 0 1 3749.dat
1 71 10 0 0 0 0 1 0 1 0 -1 0 0 3648.dat

LUA code:
Code:
function register()
  local ani=ldc.animation('animationDemo')
  ani:setLength(20)
  ani:setEvent('frame', 'onFrame')
end

function onFrame()
  local ani=ldc.animation.getCurrent()
  local mainSf=ldc.subfile()
  local ori=ldc.matrix()

  local angle=720*ani:getFrameTime()/ani:getLength()

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

register()
Reply
RE: Animation puzzle
#2
(2021-03-15, 0:15)Walt White Wrote: As soon as I launch the LUA script, the Axle1 sub-model jumps to a new position on the first frame.  It also loses the 13° rotation that allowed its 14 tooth gear to mesh correctly with the Axle2 gear.
This is how it supposed to work Big Grin

The setRotation function constructs a new rotation matrix (stored in the ori variable).

You then assign this matrix to the type 1 reference line of 'Axle1.ldr' by doing this you will overwrite any existing rotation.

If you want to keep the initial orientation you will need to buffer it in the start event and then multiply it with the one before assigning it to the reference.

But it is much more practical to make sure the reference is orientated correctly while using the 1 0 0 0 1 0 0 0 1 rotation matrix.

You can do that by rotating the parts in the submodel them selves.

You can see this is also the case in my second animation demo video at 2:45

Hope this clears things up.
Reply
« Next Oldest | Next Newest »



Forum Jump:


Users browsing this thread: 2 Guest(s)