macroScript Benzie_DrawAnimation category:"Benzie" InternalCategory:"Benzie" buttonText:"DrawAnimation" toolTip:"Draw animation in realtime while the viewport is playing" (--MACRO START struct c_drawAnim( precision, lastLMB = false, LMBDrag = false, lastTime = animationrange.start.frame, newTime, thePoint = undefined, intersectObj = undefined, lastMousePos = undefined, thePoint = undefined, thePointsArr = #(), LMBDrag = false, fn drawAnimation =( local newMousePos = mouse.pos if lastMousePos == undefined then( lastMousePos = newMousePos ) if length(newMousePos - lastMousePos) >= precision then( local thePos = undefined if intersectObj != undefined then( local hitRay = intersectRay intersectObj (mapScreenToWorldRay newMousePos) if hitRay != undefined do( thePos = hitRay.pos ) )else( local hitArr = intersectRayScene (mapScreenToWorldRay newMousePos) if hitArr[1] != undefined do( thePos = hitarr[1][2].pos ) ) with animate on( at time newTime ( if thePos != undefined do( thePoint.pos = thePos ) ) ) ) lastMousePos = newMousePos ), fn cleanUpPoint =( if thePoint.pos.controller.keys[1] != undefined then( deleteKey thePoint.pos.controller 1 --print "deleting key" ) ), fn createAnimPoint =( thePoint = \ Point \ name:"trailPoint" \ wirecolor:(color 255 0 0) \ size:4 \ centermarker:off \ axisTripod:off \ cross:off \ Box:on \ constantScreenSize:on \ drawOnTop:off append thePointsArr thePoint ), fn testMouse =( local thisLMB = mouse.buttonStates[1] local LMBDown = false local LMBUp = false if lastLMB == false and thisLMB == true then( --print "LMB Down" LMBDown = true LMBDrag = true createAnimPoint() )else if lastLMB == true and thisLMB == false then( --print "LMB Up" LMBUp = true LMBDrag = false cleanUpPoint() ) if LMBDrag do( --print "Creating animation" drawAnimation() ) lastLMB = thisLMB ), fn frameIncrementCallback =( newTime = floor currentTime.frame if lastTime > newTime then( --print "End Frame" lastTime = animationRange.start.frame )else( if ( newTime - lastTime) >= 1 then( --format "theIncrementTimeIs: %\n" newTime lastTime = newTime testMouse() ) ) )--end fn )--end struct --## ROLLOUT ##-- rollout drawAnimRoll "Draw Animation" width:160 height:105 ( local drawAnimOps spinner precisionSpin "Precision (pixels)" \ range:[1,200,5] \ type:#integer pos:[8,8] \ width:144 height:25 pickbutton nodePick "Pick Intersect Object" \ pos:[8,32] width:144 height:25 checkbutton startChkButt "Start/Stop" \ pos:[8,57] width:144 height:40 on drawAnimRoll open do( print "DrawAnimation Opened" sliderTime = animationRange.start drawAnimOps = c_drawAnim() drawAnimOps.precision = precisionSpin.value ) on precisionSpin changed val do( drawAnimOps.precision = val ) on nodePick picked obj do( theObj = obj nodePick.text = obj.name ) on startChkButt changed args do( if args then( registerTimeCallback drawAnimOps.frameIncrementCallback tool foo ( on mousePoint clickno do( if clickno == 2 do( --on LMB up playanimation immediatereturn:true ) ) ) starttool foo )else( stopAnimation() unregisterTimeCallback drawAnimOps.frameIncrementCallback select drawAnimOps.thePointsArr ) ) on drawAnimRoll close do( unRegisterTimeCallback drawAnimOps.frameIncrementCallback drawAnimOps = undefined ) )--end rollout on execute do( print "Draw Animation Started" try(destroydialog drawanimroll)catch(print "No dialog to destroy") createDialog drawAnimRoll pos:(mouse.screenpos - [40, 20]) )--end execute )--MACRO END