(2020-01-02, 23:37)Walt White Wrote: Appreciate the help. I'll try to figure out the 8860 code by looking at the "actors" and hopefully my example will have only three actors and each will have a simple motion to describe.
The trick for me will be to recognize the main "story" components out of the 1100 lines of code in 8860.
Both 8860(and your model have only one actor. Actors are used to describe the bone structure of the things moving. This way you won't have to worry about recursion of stuff attached to other stuff.
As it has been a couple of years for me using this stuff myself I went and made the mechanical part of the animation (as far I understand it).
It needs a better story (not just infinite rotation at the starting gear)
But it should get you going a whole lot faster as there is next to nothing documentation wise
Code:
genTools=require('genTools')
aniTools=require('aniTools')
function mainActor()
local mainSf=ldc.subfile()
local result=aniTools.actor()
--Joints and aniElms
result.inputGearsAngle=result:addAniElm(aniTools.aniElm(0))
result:addJoint(aniTools.angleJoint(mainSf:getRef('InputGears.ldr'), result.inputGearsAngle, ldc.vector(0,1,0)))
result.knobPairAngle=result:addAniElm(aniTools.aniElm(0))
result:addJoint(aniTools.angleJoint(mainSf:getRef('KnobPair.ldr'), result.knobPairAngle, ldc.vector(0,0,1)))
result.endGearsAngle=result:addAniElm(aniTools.aniElm(0))
result:addJoint(aniTools.angleJoint(mainSf:getRef('EndGears.ldr'), result.endGearsAngle, ldc.vector(0,1,0)))
result.pivotDriverAngle=result:addAniElm(aniTools.aniElm(0))
result:addJoint(aniTools.angleJoint(mainSf:getRef('PivotDriver.ldr'), result.pivotDriverAngle, ldc.vector(0,1,0)))
result.pivotArmAngle=result:addAniElm(aniTools.aniElm(0))
local arm=result:addJoint(aniTools.angleJoint(mainSf:getRef('PivotArm.ldr'), result.pivotArmAngle, ldc.vector(0,1,0)))
--Attach the hor arm axle to the arm joint instead of the actor itself.
result.pivotHorizontalsAngle=result:addAniElm(aniTools.aniElm(0))
arm:addJoint(aniTools.angleJoint(mainSf:getRef('PivotHorizontals.ldr'), result.pivotHorizontalsAngle, ldc.vector(0,0,1)))
--Create a state tracking table for the pivot angle as everyhing behind it depends on the current mode.
result.modeStateInfo=result:addStateInfo(aniTools.numberDepStateInfo(result.pivotDriverAngle, {mode=0}))
return result
end
function modeDepAction(actor)
--Custom state dependend action, to handle all possible dependency chains based on a current mode variable.
local result=aniTools.stateInfoDepAction(actor.modeStateInfo, 0, nil)
result.actor=actor
result.initTotals=function(self)
self.totPivotArmAngle=0
self.totPivotHorizontalsAngle=0
end
result.processState=function(self, state)
local mode=state.value.mode
local mainAngle=state.elmValueDiff --don't access pivotDriverAngle directly as that gives it's current ABS angle. We want the one relative to the start of this state segment.
local armAngle=0
local horAngle=0
if mode==0 then
--only arm moves
armAngle=mainAngle
elseif mode==1 then
--block arm
horAngle=-mainAngle
else
--block hor
armAngle=mainAngle
horAngle=-armAngle
end
self.totPivotArmAngle=self.totPivotArmAngle+armAngle
self.totPivotHorizontalsAngle=self.totPivotHorizontalsAngle+horAngle
end
result.applyTotals=function(self)
self.actor.pivotArmAngle:setValue(self.totPivotArmAngle)
self.actor.pivotHorizontalsAngle:setValue(self.totPivotHorizontalsAngle)
end
return result
end
function onStart()
story=aniTools.story()
local actor=story:addActor(mainActor())
local seq=story:addSequence(aniTools.sequence())
--==actions==--
--base gears run forever
seq:addAction(aniTools.speedAction(actor.inputGearsAngle, 0, nil, 45))
seq:addAction(aniTools.ratioDepAction(actor.knobPairAngle, 0, nil, actor.inputGearsAngle, -1))
seq:addAction(aniTools.ratioDepAction(actor.endGearsAngle, 0, nil, actor.knobPairAngle, -1))
seq:addAction(aniTools.ratioDepAction(actor.pivotDriverAngle, 0, nil, actor.endGearsAngle, -1))
--Setup state dep actions
seq:addAction(modeDepAction(actor)) --custom action
seq:addAction(aniTools.stateChangeAction(actor.modeStateInfo, 2, {mode=1}))
seq:addAction(aniTools.stateChangeAction(actor.modeStateInfo, 4, {mode=2}))
--==All done==--
story:prep()
end
function onFrame()
story:apply(ldc.animation():getFrameTime())
end
function register()
local ani=ldc.animation('My animation')
ani:setLength(10)
ani:setEvent('start', 'onStart')
ani:setEvent('frame', 'onFrame')
end
register()
Let me know if you need more comments.