/*DESCRIPTION Pick the focal point in the scene for cameras or render settings */ --macroScript CoronaCamAutofocus --category: "Corona Renderer" ( /* v.04 Copyright (C) 2014 Martin Geupel http://www.racoon-artworks.de */ try(DestroyDialog ::AutoFocusRoll)catch() AutoFocus_iso_x = getinisetting "$plugcfg\\RacoonScripts.ini" "AutoFocus" "pos_x" as integer AutoFocus_iso_y = getinisetting "$plugcfg\\RacoonScripts.ini" "AutoFocus" "pos_y" as integer AutoFocus_iso_x = if AutoFocus_iso_x == 0 then 640 else AutoFocus_iso_x AutoFocus_iso_y = if AutoFocus_iso_y == 0 then 480 else AutoFocus_iso_y theCamera = undefined AFmode = 1 fn compareFN v1 v2 =( local d = (distance theCamera.pos v1[2].pos)-(distance theCamera.pos v2[2].pos) case of( (d < 0.): -1 (d > 0.): 1 default: 0 ) ) tool SetCoronaCamFocus ( on mousePoint clickno do( if clickno == 1 then( hits = intersectRayScene (mapScreenToWorldRay mouse.pos) hits = for elem in hits where not elem[1].ishidden collect elem -- exclude hidden scene objects qsort hits compareFN try(thePos= hits[1][2].pos) catch(thePos=undefined) if thePos != undefined then( thePointH = point wirecolor:red centermarker:false axistripod:false cross:true Box:false constantscreensize:true size:20 thePointH.pos = thePos redrawViews() sleep 0.3 delete thePointH coordSysTM = Inverse(getViewTM()) viewDir = -coordSysTM.row3 viewPt = coordSysTM.row4 theAngle = acos(dot (normalize (thePos - viewPt)) (normalize viewDir)) dist = ((length (thePos - viewPt)) * sin(90.0-theAngle)) case AFmode of( 1:( thecamera.modifiers[#CoronaCameraMod].useOverrideFocus = true theCamera.modifiers[#CoronaCameraMod].overrideFocusDistance = dist ) 2:( thecamera.targetDistance = dist ) 3:( try(renderers.current.dof_focalDistance = dist)catch(messageBox "Error occured, is Corona set as render engine?") ) 4:( thecamera.targetDistance = dist ) ) ) else() ) else #stop ) ) rollout AutoFocusRoll "Autofocus" ( radiobuttons rdoAFmode "Mode: " labels:#("CoronaCameraMod", "Camera target", "Settings: view focus dist", "Physical Camera") button btnPick "Start focus picking" width:140 height:30 fn CoronaCamMod_AFmode =( try(stopTool SetCoronaCamFocus)catch() if theCamera != undefined AND superclassof theCamera == camera then( if theCamera.modifiers[#CoronaCameraMod] != undefined then( startTool SetCoronaCamFocus prompt:"SetCoronaCamFocus" ) else( if queryBox "No CoronaCameraMod modifier found on the camera, do you want to assign a new one?" then( addmodifier theCamera (CoronaCameraMod()) startTool SetCoronaCamFocus prompt:"SetCoronaCamFocus" ) ) ) else messagebox "No valid Camera set in active viewport or CoronaCameraMod modifier missing" ) fn CamTarget_AFmode =( try(stopTool SetCoronaCamFocus)catch() if theCamera != undefined AND superclassof theCamera == camera then( if classof theCamera == Targetcamera then( startTool SetCoronaCamFocus prompt:"SetCoronaCamFocus" ) else messagebox "Active viewport Camera is not a target camera!" ) else messagebox "No valid Camera set in active viewport" ) fn RS_ViewDist_AFmode =( try(stopTool SetCoronaCamFocus)catch() theCamera = getViewTM() startTool SetCoronaCamFocus prompt:"SetCoronaCamFocus" ) fn CamPhys_AFmode =( try(stopTool SetCoronaCamFocus)catch() if theCamera != undefined AND superclassof theCamera == camera then( if classof theCamera == Physical_Camera then( startTool SetCoronaCamFocus prompt:"SetCoronaCamFocus" ) else messagebox "Active viewport Camera is not a Phys camera!" ) else messagebox "No valid Camera set in active viewport" ) on rdoAFmode changed state do( AFmode = state ) on btnPick pressed do( theCamera = Viewport.GetCamera() case AFmode of( 1: CoronaCamMod_AFmode() 2: CamTarget_AFmode() 3: RS_ViewDist_AFmode() 4: CamPhys_AFmode() ) ) on AutoFocusRoll close do( setinisetting "$plugcfg\\RacoonScripts.ini" "AutoFocus" "pos_x" ((GetDialogPos AutoFocusRoll).x as string) setinisetting "$plugcfg\\RacoonScripts.ini" "AutoFocus" "pos_y" ((GetDialogPos AutoFocusRoll).y as string) ) ) CreateDialog AutoFocusRoll pos:[AutoFocus_iso_x, AutoFocus_iso_y] )