-- Free to Target -- v1.04 -- -- by James Coulter -- http://www.jamescoulter.com --1/7/2013 vray camera support added by: Miles Majefski macroScript jec_Free_to_Target category:"James Coulter" internalcategory:"Camera Utilities" tooltip:"Free to Target v1.04" buttontext:"Free to Target" Icon:#("Cameras",1) ( global SourceCam = undefined fn jecCamFilt obj = superClassOf obj == camera rollout thisRoll "Free to Target" width:270 height:280 ( -- DECLARATIONS -- local TargetDist = 100.0 local CopyStart = ((animationRange.start as float) / (4800.0/framerate)) local CopyEnd = ((animationRange.end as float) / (4800.0/framerate)) local DeltaRoll = 0 local rolloutPos = undefined -- DIALOG LAYOUT -- label L1 "This utility creates a Target Camera that matches" align:#left label L2 "an existing Free Camera." align:#left offset:[1,-3] GroupBox grpTimeRange "Time Range" pos:[10,40] width:250 height:64 radiobuttons rdoRange labels:#("Active Time Segment", "Custom -->") columns:1 align:#left offset:[5,-50] spinner spnInTime "In Time:" range:[-10000,10000,CopyStart] type:#integer fieldWidth:40 offset:[-4,-34] enabled:false spinner spnOutTime "Out Time:" range:[-10000,10000,Copyend] type:#integer fieldWidth:40 offset:[-4,0] enabled:false GroupBox grpCamData "Camera Properties" pos:[10,110] width:250 height:64 label L4 "Source Camera:" align:#left offset:[5,-50] pickbutton btnSourceCam "Pick Source Camera" width:150 filter:jecCamFilt select:false align:#left offset:[90,-22] checkbox chkTargOR "Override Target Distance -->" checked:false offset:[5,0] spinner spnTargetDist range:[0.001,10000.0,100.0] type:#worldunits fieldWidth:40 offset:[-4,-20] enabled:false button btnCreateCam "Create Camera" align:#center offset:[0,16] enabled:false button btnCancel "Close" align:#right offset:[3,-26] label L5 "Free to Target v1.04" align:#right offset:[0,14] label L6 "by James Coulter" align:#right offset:[0,-3] label L7 "http://www.jamescoulter.com" align:#right offset:[0,-3] -- EVENT HANDLERS -- on btnCancel pressed do DestroyDialog thisRoll on rdoRange changed rdoRangeVal do ( if rdoRangeVal == 1 then ( spnInTime.value = ((animationRange.start as float) / (4800.0/framerate)) CopyStart = (animationRange.start as float) / (4800.0/framerate) as integer spnOutTime.value = ((animationRange.end as float) / (4800.0/framerate)) CopyEnd = (animationRange.end as float) / (4800.0/framerate) as integer spnInTime.enabled = false spnOutTime.enabled = false ) else ( spnInTime.enabled = true spnOutTime.enabled = true ) ) on spnInTime changed spnInTimeVal do CopyStart = spnInTime.value as integer on spnOutTime changed spnOutTimeVal do CopyEnd = spnOutTime.value as integer on btnSourceCam picked thisObj do ( SourceCam = thisObj btnSourceCam.text = SourceCam.name btnCreateCam.enabled = true ) on chkTargOR changed chkTargORVal do spnTargetDist.enabled = chkTargORVal on btnCreateCam pressed do ( NewCam = Copy SourceCam if classof newcam == vrayphysicalcamera then NewCam.targeted = true else NewCam.type = #target NewCam.position.controller = Bezier_Position() NewCam.target.position.controller = Bezier_Position() if chkTargOR.state == True then ( TargetDist = spnTargetDist.value ) else ( TargetDist = NewCam.targetDistance ) For ThisFrame = CopyStart to CopyEnd do ( ThisPos = at time ThisFrame SourceCam.position ThisDir = at time ThisFrame SourceCam.dir TargetPos = (-ThisDir * TargetDist) + ThisPos DestCamPosKey = addNewKey NewCam.position.controller ThisFrame DestCamPosKey.value = ThisPos DestTargPosKey = addNewKey NewCam.target.position.controller ThisFrame DestTargPosKey.value = TargetPos SourceVect = at time ThisFrame SourceCam.transform.row2 TargetVect = at time ThisFrame NewCam.transform.row2 DeltaRoll = acos ( dot (normalize TargetVect) (normalize SourceVect)) CrossNorm = cross TargetVect SourceVect SignumAngle = acos (dot (normalize ThisDir) (normalize CrossNorm)) If SignumAngle > 90.0 then DeltaRoll *= -1.0 DestRollKey = addNewKey NewCam.transform.controller.roll_angle.controller ThisFrame DestRollKey.value += DeltaRoll ) ) on thisRoll moved newPos do ( rolloutPos = newPos ) on thisRoll close do ( if rolloutPos != undefined then ( FreeToTargetINI = (GetDir #plugcfg) + "\\FreeToTarget.ini" setINISetting FreeToTargetINI "Window" "PositionX" (rolloutPos.x as string) setINISetting FreeToTargetINI "Window" "PositionY" (rolloutPos.y as string) ) ) ) -- Position History -- FreeToTargetINI = (GetDir #plugcfg) + "\\FreeToTarget.ini" TempRolloutPosX = (getINISetting FreeToTargetINI "Window" "PositionX") as float TempRolloutPosY = (getINISetting FreeToTargetINI "Window" "PositionY") as float if ((TempRolloutPosX != 0.0) or (TempRolloutPosY != 0.0)) then ( CreateDialog thisRoll modal:false pos:[TempRolloutPosX, TempRolloutPosY] ) else ( CreateDialog thisRoll modal:false ) )