Page MenuHome

Add camera DOF bone property
Needs ReviewPublic

Authored by Damien Picard (pioverfour) on Mar 3 2020, 5:31 PM.



This diff allows using an Armature’s bone as a DOF target for a camera. This is useful when using an armature as a camera rig, to avoid creating and targetting an Empty object.

Diff Detail

Event Timeline

you didn't specify any reviewers here?

you didn't specify any reviewers here?

I wanted to investigate a bit more whether I could implement Cycles support, but I really couldn’t. I’ll assign it to the developers who wrote the code surrounding the modifications now.

This revision is now accepted and ready to land.Thu, Mar 12, 12:13 AM
Campbell Barton (campbellbarton) requested changes to this revision.EditedThu, Mar 12, 12:18 AM

Accepting functionality, there are some missing relationship updates though.

  • ED_armature_bone_rename should be updated.
  • source/blender/depsgraph/intern/builder/ needs to know about this relationship too.

Anything against the name focus_subtarget? matching constraints, allowing for non-bone sub-targets in the future.

This revision now requires changes to proceed.Thu, Mar 12, 12:18 AM

For Cycles it would be something like this (untested):

diff --git a/intern/cycles/blender/blender_camera.cpp b/intern/cycles/blender/blender_camera.cpp
index 40a1a2c2edc..4beef2ffa9d 100644
--- a/intern/cycles/blender/blender_camera.cpp
+++ b/intern/cycles/blender/blender_camera.cpp
@@ -140,11 +140,20 @@ static float blender_camera_focal_distance(BL::RenderEngine &b_engine,
   if (!b_dof_object)
     return b_camera.dof().focus_distance();

+  Transform dofmat = get_transform(b_dof_object.matrix_world());
+  string focus_bone = b_camera.dof().focus_bone();
+  if (b_dof_object.pose() && !focus_bone.empty()) {
+    BL::PoseBone b_bone = b_dof_object.pose().bones[focus_bone];
+    if (b_bone) {
+      dofmat = dofmat * get_transform(b_bone.matrix());
+    }
+  }
   /* for dof object, return distance along camera Z direction */
   BL::Array<float, 16> b_ob_matrix;
   b_engine.camera_model_matrix(b_ob, bcam->use_spherical_stereo, b_ob_matrix);
   Transform obmat = transform_clear_scale(get_transform(b_ob_matrix));
-  Transform dofmat = get_transform(b_dof_object.matrix_world());
   float3 view_dir = normalize(transform_get_column(&obmat, 2));
   float3 dof_dir = transform_get_column(&obmat, 3) - transform_get_column(&dofmat, 3);
   return fabsf(dot(view_dir, dof_dir));
Damien Picard (pioverfour) edited the summary of this revision. (Show Details)
  • Rename focus_bone to focus_subtarget
  • Use Brecht’s code for Cycles
  • Expose the property in Cycles’ UI
    • Side note: the focus_object property does not display the same name in Cycles’ (Focus Object) and Eevee’s UIs (Focus on Object). I named the subtarget property accordingly (Focus Bone, Focus on Bone), but perhaps they should be unified.
  • Update source/blender/editors/armature/armature_naming.c and source/blender/depsgraph/intern/builder/
    • I don’t properly understand the depsgraph’s logic so I may have got it wrong:
    • the code in doesn’t appear to have any effect
    • in armature_naming.c I call DEG_id_tag_update() on the camera data, which isn’t done elsewhere in this file.
Damien Picard (pioverfour) marked an inline comment as done.Fri, Mar 20, 3:39 PM
Jeroen Bakker (jbakker) resigned from this revision.Thu, Mar 26, 9:42 AM