Autofocus

This little Script will help setting the camera focus very precisely. Just run the script and click in the viewport where you want the focus point to be. A little red helper will flash up for a short moment to show the exact position of your focus point (at least if your current active layer is not hidden :wink: )

If you want to use this script as a macroscript you just need to uncomment the first 2 lines (remove the “–”)
P.S. If you use this script in scenes with several thousand objects it may get slow (~4 seconds in a scene with 15k objects) since the intersectRayScene maxscript function I need to use is unfortunately quite slow.

Updated Script version v.04:
Updated the maxscript commands to work with the daily builds post-A7 and Corona 1.0

UPDATE BY FROOD
Please download an updated version by frood here (thanks frood! :smiley: )
[https://forum.corona-renderer.com/ Autofocus #msg118309](https://forum.corona-renderer.com/ Autofocus #msg118309)
CoronaAutofocus_v0.03.ms (4.04 KB)
CoronaAutofocus_v0.04.ms (4.1 KB)

it work really well.
Thanks for sharing.
maybe a suggestion.
could it be possible to automatically add a CoronaCamMod on the selected camera when click on the script

i have just a little unit size bug.
ex a box at 1.5m (the correct distance) in the override focus field it put 0.15m

Done, will update the file soon.

That’s weird, it’s working in world units, it shouldn’t matter what you have for system and display units. I tested it here and it worked either for inches + meters or centimeters + meters etc. Which configuration did you use?

Did you reset xform?

sweet tool :smiley: works like a charm! thx very much

Hi guys, can you please provide detailed instructions of all process to make this work?

Here’s my problem: I’ve a camera with coronacameramod modifier applied on it(NOT coronacmameramodAdv), I have the DoF in corona settings TURNED ON(with wrong focus), I run the script in the correct viewprt and camera selected, put the focus on the object I want(a little dialog windows tells me the right name of the object too), I click ok to the window in which the scripts tells me that targetdist setting is overridden, and I click render. But focus doesn’t change.
Tell me where I’m wrong please!!

Thanks a lot in advance
Jack

I’ve no idea which script you’re running but mine does not (yet!) open any dialogs :wink:
If there is some window opening it’s either not from my script or it’s a maxscript error message - which would explain why the focus does not change at all. You can post the error message here with a description of what you did exactly.

To make it more clear: Your active viewport must have a camera assigned, not perspective, and this camera must have a CoronaCameraMod modifier. If that’s true you just need to run the script and click somewhere in this viewport - a little red helper will pop up indicating where your focus is.

Hi Martin

could it be the script is not working with A5?
I always receive the following error message (see attachment)

Oooooh, yes, right. I totally forgot that the cameraMod did not have as much features in A5 as it has now. Thanks for reporting! Sorry, that means you will have to wait for A6 or use the daily builds :-/

I first have to figured out how this is working

" have a separate external folder containing different builds with all plugin and dll files (A5, dailies, important steps etc). One of these subfolders is referenced in all the plugin inis over the network (or more precisely: they all include another ini which targets the plugin folder, easier to maintain that way). The important thing is to include the path where the dlls lie into the path environment variable on every machine - without that max will fail loading and complain about missing dlls.
So this way I don’t need to have the files in my max folder and can just rename the build’s folders which then load different files on each max start."

before I start with the Daily Builds :wink:

Hi DeadClown!
Thank you for very usable scripts!
If it maybe to do that the script works with camera target?

Hello, Martin!
Looks like autofocus doesn’t work correctly through the cropped geometry((
It focuses the camera to the cropped geometry but not to the needed geometry(
I will try fix it myself but i not so good know the maxscript (;

Sorry, missed that one. Shouldn’t be a problem but I’m currently a bit busy, will make a note for it :smiley:

What is cropped geometry? If you mean “viewport clipping” then I doubt I can do anything about it. I’m using the exposed raycasting methods from maxscript, that limits my possibilities in that sense =/

When it may be done it would be more clearly to see where the focus
I will be waiting (;

Oh. I’m sorry(
I mean the clipped geometry with the camera clipping planes.
Camera don’t shows the clipped but script sees and focuses at this mesh
One more time sorry for mistake (;

Sorry, I fear I can’t do anything about it =/

It’s very sad((
Thanks for your try! (;

here i’m again (;
Hi, Martin!
Can you do in the perspective view will work autofocus too?
I mean to use “Perspective view focus distance”
Very comfortable for the tweaking

Done

…aaaand done :smiley:

Updated Script version v.03:
The Script has 3 modes now:

  • CoronaCameraModifier
  • Camera target
  • Render settings: Perspective view focus distance

Awesome!
Great Great Great thanks!!!)