Chaos Corona Forum

Chaos Corona for 3ds Max => [Max] Corona Goodies - User Contributions => Topic started by: racoonart on 2014-02-14, 23:16:07

Title: Autofocus
Post by: racoonart on 2014-02-14, 23:16:07
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 ;) )

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! :) )
https://forum.corona-renderer.com/index.php?topic=2703.msg118309#msg118309 (https://forum.corona-renderer.com/index.php?topic=2703.msg118309#msg118309)
Title: Re: CoronaCameraMod - Autofocus
Post by: kahein on 2014-02-18, 11:43:02
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 
Title: Re: CoronaCameraMod - Autofocus
Post by: kahein on 2014-02-18, 11:50:25
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
Title: Re: CoronaCameraMod - Autofocus
Post by: racoonart on 2014-02-18, 12:00:03
could it be possible to automatically add a CoronaCamMod on the selected camera when click on the script
Done, will update the file soon.

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
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?
Title: Re: CoronaCameraMod - Autofocus
Post by: Tanakov on 2014-02-18, 21:18:56
Did you reset xform?
Title: Re: CoronaCameraMod - Autofocus
Post by: ukajali on 2014-02-19, 17:12:00
sweet tool :) works like a charm! thx very much
Title: Re: CoronaCameraMod - Autofocus
Post by: gekygoly on 2014-02-20, 00:29:40
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
Title: Re: CoronaCameraMod - Autofocus
Post by: racoonart on 2014-02-20, 16:15:42
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.
I've no idea which script you're running but mine does not (yet!) open any dialogs ;)
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.
Title: Re: CoronaCameraMod - Autofocus
Post by: johan belmans on 2014-02-20, 16:25:15
Hi Martin

could it be the script is not working with A5?
I always receive the following error message (see attachment)
Title: Re: CoronaCameraMod - Autofocus
Post by: racoonart on 2014-02-20, 16:28:02
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 :-/
Title: Re: CoronaCameraMod - Autofocus
Post by: johan belmans on 2014-02-20, 16:39:55
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 ;-)
Title: Re: CoronaCameraMod - Autofocus
Post by: Stan_But on 2014-04-24, 01:10:20
Hi DeadClown!
Thank you for very usable scripts!
If it maybe to do that the script works with camera target?
Title: Re: CoronaCameraMod - Autofocus
Post by: Stan_But on 2014-09-07, 14:51:33
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 (;
Title: Re: CoronaCameraMod - Autofocus
Post by: racoonart on 2014-09-07, 15:16:44
If it maybe to do that the script works with camera target?
Sorry, missed that one. Shouldn't be a problem but I'm currently a bit busy, will make a note for it :)

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(
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 =/
Title: Re: CoronaCameraMod - Autofocus
Post by: Stan_But on 2014-09-07, 16:56:09
If it maybe to do that the script works with camera target?
Sorry, missed that one. Shouldn't be a problem but I'm currently a bit busy, will make a note for it :)

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

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(
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 =/

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 (;
Title: Re: CoronaCameraMod - Autofocus
Post by: racoonart on 2014-09-09, 10:11:40
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 =/
Title: Re: CoronaCameraMod - Autofocus
Post by: Stan_But on 2014-09-09, 23:29:50
It's very sad((
Thanks for your try! (;
Title: Re: CoronaCameraMod - Autofocus
Post by: Stan_But on 2014-09-25, 20:37:51
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
Title: Re: CoronaCameraMod - Autofocus
Post by: racoonart on 2014-09-25, 21:37:52
If it maybe to do that the script works with camera target?
Done

Can you do in the perspective view will work autofocus too?
I mean to use "Perspective view focus distance"
...aaaand done :)

[UPDATE] Updated Script version v.03:
The Script has 3 modes now:
- CoronaCameraModifier
- Camera target
- Render settings: Perspective view focus distance
Title: Re: CoronaCameraMod - Autofocus
Post by: Stan_But on 2014-09-25, 21:42:41
Awesome!
Great Great Great thanks!!!)
Title: Re: Autofocus
Post by: kahein on 2014-09-30, 14:45:17
Great Job.
Work perfectly !
Title: Re: Autofocus
Post by: form on 2014-12-12, 18:44:24
very handy script, thanks a lot. Unfortunately stopped working with latest DB. Your probably on top of it. Cheers
Title: Re: Autofocus
Post by: racoonart on 2014-12-12, 18:55:00
Ah, yes. I've updated the maxscript commands but forgot to upload it.
New version is attached to the first post :)
Title: Re: Autofocus
Post by: form on 2014-12-17, 16:33:55
Thanks DeadClown, it's really useful!
Title: Re: Autofocus
Post by: Frood on 2016-08-11, 16:07:29
Never tried this handy script before but at least with DB16-08-05 I get a "...got undefined" in "addmodifier theCamera(CoronaCamMod())" when there is none present.

Any chance to support physical cams?

Good Luck

Title: Re: Autofocus
Post by: dubcat on 2016-08-11, 17:23:08
Here is my little mod with Physical Camera support, should do the trick until an official update. No reason to keep it to myself.
Title: Re: Autofocus
Post by: Frood on 2016-08-11, 17:34:52
Damn. Meanwhile I also modded it to support Physical and fixed the CameraMod name. But I´d still like to use the "official" by Martin so maybe he has some time to extend it.

Good Luck

Edit: I see you added a new mode, I simplified it to "CameraMod", "Camera settings" and "Render settings". In case of Camera it set´s target distance (standard target cam and physical cam) and in case of physical cam additionally focus distance. This may be unwanted in some very rare cases but I´d like to have it simple. (physical cam target get set only if activated anyway).

Good Luck


Title: Re: Autofocus
Post by: Frood on 2018-01-15, 12:05:21
(...) so maybe he has some time to extend it.

Nope :)

Due to this sad fact I changed it again,  here is a new version (v0.06):



Good Luck



Title: Re: Autofocus
Post by: iacdxb on 2018-01-17, 05:19:18
Hi,
Is it for C4D also....?

Thanks.
Title: Re: Autofocus
Post by: Frood on 2018-01-17, 08:45:00
Sorry no, it's maxscript.


Good Luck


Title: Re: Autofocus
Post by: Jpjapers on 2018-01-24, 10:50:12
I wonder if something like this will be implemented in v2 onwards like in the Vray frame buffer where you can click to change focus.
Title: Re: Autofocus
Post by: NicolasC on 2018-01-24, 11:02:45
I wonder if something like this will be implemented in v2 onwards like in the Vray frame buffer where you can click to change focus.
Oh yes !!! like with VFB+ ...
However, AFAIR, with VRay it's only implemented with VRayRT for now.
Title: Re: Autofocus
Post by: Jpjapers on 2018-01-25, 16:39:47

SNIP

Oh yes !!! like with VFB+ ...
However, AFAIR, with VRay it's only implemented with VRayRT for now.

Yeah in IR it would be great, Would be even better if that change in focal length could be reflected in the camera settings
Title: Re: Autofocus
Post by: Hozkr Mejia on 2018-03-30, 07:03:09
Thank you very much for sharing, I'll try it soon :)