Render: allow to select an entire collection to set the focal point in the Depth of Field settings in the Camera properties #119869
|
@ -135,8 +135,9 @@ static void blender_camera_init(BlenderCamera *bcam, BL::RenderSettings &b_rende
|
|||
bcam->full_height = bcam->render_height;
|
||||
}
|
||||
|
||||
static void sum_obj_positions(float3 &pos, int &count, BL::Collection &coll){
|
||||
for (BL::Object obj : coll.objects){
|
||||
static void sum_obj_positions(float3 &pos, int &count, BL::Collection &coll)
|
||||
{
|
||||
for (BL::Object obj : coll.objects) {
|
||||
Transform dofmat = get_transform(obj.matrix_world());
|
||||
float3 curr = transform_get_column(&dofmat, 3);
|
||||
pos.x += curr.x;
|
||||
|
@ -144,8 +145,8 @@ static void sum_obj_positions(float3 &pos, int &count, BL::Collection &coll){
|
|||
pos.z += curr.z;
|
||||
count += 1;
|
||||
}
|
||||
for (BL::Collection child : coll.children){
|
||||
sum_obj_positions(pos,count,child);
|
||||
for (BL::Collection child : coll.children) {
|
||||
sum_obj_positions(pos, count, child);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -161,10 +162,10 @@ static float blender_camera_focal_distance(BL::RenderEngine &b_engine,
|
|||
return b_camera.dof().focus_distance();
|
||||
}
|
||||
|
||||
if(b_dof_collection){
|
||||
if (b_dof_collection) {
|
||||
int count = 0;
|
||||
float3 pos = {};
|
||||
sum_obj_positions(pos,count,b_dof_collection);
|
||||
sum_obj_positions(pos, count, b_dof_collection);
|
||||
float den = static_cast<float>(count);
|
||||
pos.x /= den;
|
||||
pos.y /= den;
|
||||
|
|
|
@ -15,12 +15,12 @@
|
|||
|
||||
#include "DNA_ID.h"
|
||||
#include "DNA_camera_types.h"
|
||||
#include "DNA_collection_types.h"
|
||||
#include "DNA_defaults.h"
|
||||
#include "DNA_light_types.h"
|
||||
#include "DNA_object_types.h"
|
||||
#include "DNA_scene_types.h"
|
||||
#include "DNA_view3d_types.h"
|
||||
#include "DNA_collection_types.h"
|
||||
|
||||
#include "BLI_listbase.h"
|
||||
#include "BLI_math_geom.h"
|
||||
|
@ -278,19 +278,27 @@ void *BKE_camera_add(Main *bmain, const char *name)
|
|||
return cam;
|
||||
}
|
||||
|
||||
static void sum_obj_positions(float pos[3], int *count, Collection *c){
|
||||
static void sum_obj_positions(float pos[3], int *count, Collection *c)
|
||||
{
|
||||
ListBase *gobject = &(c->gobject);
|
||||
ListBase *children = &(c->children);
|
||||
*count += BLI_listbase_count(gobject);
|
||||
LISTBASE_FOREACH(LinkData*,current,gobject){
|
||||
Object* o =static_cast<Object*>(current->data);
|
||||
LISTBASE_FOREACH (LinkData *, current, gobject) {
|
||||
Object *o = static_cast<Object *>(current->data);
|
||||
const blender::float3 &cpos = o->object_to_world().location();
|
||||
add_v3_v3v3(pos,pos,cpos);
|
||||
printf("Name: %s, Pos: %f, %f, %f, Total: %f, %f, %f\n",o->id.name,cpos.x,cpos.y,cpos.z,pos[0],pos[1],pos[2]); //DEBUG
|
||||
add_v3_v3v3(pos, pos, cpos);
|
||||
printf("Name: %s, Pos: %f, %f, %f, Total: %f, %f, %f\n",
|
||||
o->id.name,
|
||||
cpos.x,
|
||||
cpos.y,
|
||||
cpos.z,
|
||||
pos[0],
|
||||
pos[1],
|
||||
pos[2]); // DEBUG
|
||||
}
|
||||
LISTBASE_FOREACH(LinkData*,current,children){
|
||||
Collection *child = static_cast<Collection*>(current->data);
|
||||
sum_obj_positions(pos,count,child);
|
||||
LISTBASE_FOREACH (LinkData *, current, children) {
|
||||
Collection *child = static_cast<Collection *>(current->data);
|
||||
sum_obj_positions(pos, count, child);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -300,20 +308,18 @@ float BKE_camera_object_dof_distance(const Object *ob)
|
|||
if (ob->type != OB_CAMERA) {
|
||||
return 0.0f;
|
||||
}
|
||||
if (cam->dof.focus_collection){
|
||||
if (cam->dof.focus_collection) {
|
||||
float view_dir[3], dof_dir[3];
|
||||
normalize_v3_v3(view_dir, ob->object_to_world().ptr()[2]);
|
||||
|
||||
float pos[3] = {0.0f,0.0f,0.0f};
|
||||
float pos[3] = {0.0f, 0.0f, 0.0f};
|
||||
int count = 0;
|
||||
sum_obj_positions(pos,&count,cam->dof.focus_collection);
|
||||
sum_obj_positions(pos, &count, cam->dof.focus_collection);
|
||||
float scale = 1.0f / static_cast<float>(count);
|
||||
mul_v3_fl(pos,scale);
|
||||
printf("Nobjects: %d, AVG Pos: %f, %f, %f\n",count,pos[0],pos[1],pos[2]); // DEBUG
|
||||
mul_v3_fl(pos, scale);
|
||||
printf("Nobjects: %d, AVG Pos: %f, %f, %f\n", count, pos[0], pos[1], pos[2]); // DEBUG
|
||||
|
||||
sub_v3_v3v3(dof_dir,
|
||||
ob->object_to_world().location(),
|
||||
pos);
|
||||
sub_v3_v3v3(dof_dir, ob->object_to_world().location(), pos);
|
||||
return fabsf(dot_v3v3(view_dir, dof_dir));
|
||||
}
|
||||
if (cam->dof.focus_object) {
|
||||
|
|
|
@ -1875,7 +1875,7 @@ void DepsgraphNodeBuilder::build_camera(Camera *camera)
|
|||
build_object(-1, camera->dof.focus_object, DEG_ID_LINKED_INDIRECTLY, false);
|
||||
}
|
||||
if (camera->dof.focus_collection != nullptr) {
|
||||
build_collection(nullptr,camera->dof.focus_collection);
|
||||
build_collection(nullptr, camera->dof.focus_collection);
|
||||
mod_moder marked this conversation as resolved
Outdated
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Hi, can you run
make format
in root folder of your blender fork?Ok done, thank you. Now the format should be ok