Hi,
I have got a really silly question but I couldnt figure it out yet. I want the camera to stay focused on a specific object, even if the object or the cam is moving. Is there an easy one-klick solution?
Focus on object
17031 16 2-
- Rosko Ron
- Member
- 183 posts
- Joined: March 2015
- Offline
-
- malexander
- Staff
- 4939 posts
- Joined: July 2005
- Offline
-
- Rosko Ron
- Member
- 183 posts
- Joined: March 2015
- Offline
-
- verysame
- Member
- 59 posts
- Joined: May 2015
- Offline
twod
It's not exactly one click, but there's a Look At parameter on the Camera object. Select the object that you want to look at and it'll do the rest. It won't auto-frame the object, though.
What if I want to control the focus but I don't want to change camera's constraint?
In other words, I still want to control cam pos, rot, without pointing at any particular object in the scene, but I do want to control the focus distance (as if I were changing focus on my camera using the lens' focusing ring).
An example for this comes from Blender:

Andrew
Houdini Apprentice
Houdini Apprentice
-
- goldfarb
- Staff
- 3448 posts
- Joined: July 2005
- Offline
on the Sampling Tab of the camera object there is a parameter called Focus Distance
NOTE - this will only work when you have Depth of Field turned ON
if you select the camera and hit Enter in the viewport you'll get the handles for the camera, then use the “z” hotkey
now you'll have a little square thingy and two arrow thingys
move the square thingy to the distance you want to focus and the arrows to narrow the depth of field
I made a little file to show you one way to have more control over the two main parameters you need to adjust to have focus track an object
I built a geometry object and inside I merged in the camera origin and the center point of a null object
I made a poly line with those two points and the measured it's length
I then used a prim() function on the Focus Distance Parameter of cam1
now I can place the null object - called “focus_target” anywhere in the scene and that will drive the focal distance…which doesn't seem all that great…but if you unparent the null from the camera it can now become a child of anything in your scene…and if it's a moving object the focal distance will update as needed.
the other parameter you need to adjust is the F-Stop - large values mean a deep focal distance, small values mean a very tight range that will be in focus.
in the ropnet the mantra node has Enable Depth of Field turned ON.
you can make this way better of course…but it's something to play with
and you should check this out:
https://www.youtube.com/watch?v=01UlqkRRcgQ [youtube.com]
HTH
NOTE - this will only work when you have Depth of Field turned ON
if you select the camera and hit Enter in the viewport you'll get the handles for the camera, then use the “z” hotkey
now you'll have a little square thingy and two arrow thingys
move the square thingy to the distance you want to focus and the arrows to narrow the depth of field
I made a little file to show you one way to have more control over the two main parameters you need to adjust to have focus track an object
I built a geometry object and inside I merged in the camera origin and the center point of a null object
I made a poly line with those two points and the measured it's length
I then used a prim() function on the Focus Distance Parameter of cam1
now I can place the null object - called “focus_target” anywhere in the scene and that will drive the focal distance…which doesn't seem all that great…but if you unparent the null from the camera it can now become a child of anything in your scene…and if it's a moving object the focal distance will update as needed.
the other parameter you need to adjust is the F-Stop - large values mean a deep focal distance, small values mean a very tight range that will be in focus.
in the ropnet the mantra node has Enable Depth of Field turned ON.
you can make this way better of course…but it's something to play with
and you should check this out:
https://www.youtube.com/watch?v=01UlqkRRcgQ [youtube.com]
HTH
-
- Rosko Ron
- Member
- 183 posts
- Joined: March 2015
- Offline
-
- verysame
- Member
- 59 posts
- Joined: May 2015
- Offline
-
- tamte
- Member
- 6510 posts
- Joined: July 2007
- Online
-
- verysame
- Member
- 59 posts
- Joined: May 2015
- Offline
tamte
you can just put following expression to Focus Distance parm without any extra steps
vlength(vtorigin(“.”, “../focus_target”))
it will measure world space distance from camera to focus object (in this case named focus_target in the same level as camera)
Thanks,
that's very handy!
Andrew
Houdini Apprentice
Houdini Apprentice
-
- Rosko Ron
- Member
- 183 posts
- Joined: March 2015
- Offline
-
- Matt Slanchik
- Member
- 1 posts
- Joined: Sept. 2013
- Offline
-
- goldfarb
- Staff
- 3448 posts
- Joined: July 2005
- Offline
Matt Slanchik
So long story short, there is no Maya F type function? You all are going on and on about coding F stops and random stuff but it's really a simple question. Can you focus the camera on something or not?
this thread is about a camera's focus - not what applications refer to as ‘focus’
if you want to snap the camera view to a selected Object - use ‘f’
-
- CYTE
- Member
- 411 posts
- Joined: Feb. 2017
- Offline
-
- chris wells
- Member
- 54 posts
- Joined: Jan. 2015
- Offline
-
- videlam
- Member
- 2 posts
- Joined: July 2017
- Offline
-
- CYTE
- Member
- 411 posts
- Joined: Feb. 2017
- Offline
-
- videlam
- Member
- 2 posts
- Joined: July 2017
- Offline
I made a script to create a null and set the focus on it.
On the shelf, create a new tool and copy/paste the code
On the shelf, create a new tool and copy/paste the code
import toolutils scene_viewer = toolutils.sceneViewer() selected_objects = scene_viewer.selectObjects("Select a camera and press Enter",allowed_types = ["cam"]) object = hou.selectedNodes() netparent = object[0].parent() selectname = str (object[0]) focus_obj = netparent.createNode("null", selectname+'_focus_target') d_focus=('vlength(vtorigin(".", "../'+str(focus_obj)+'"))') hou.parm('/obj/'+selectname+'/focus').setExpression(str(d_focus))
-
- Quick Links