2011-11-05 13:00:39 +00:00
|
|
|
/*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
|
|
|
* All rights reserved.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** \file blender/blenkernel/intern/camera.c
|
|
|
|
* \ingroup bke
|
|
|
|
*/
|
|
|
|
|
2011-11-05 13:11:49 +00:00
|
|
|
#include <stdlib.h>
|
2015-04-06 10:40:12 -03:00
|
|
|
#include <stddef.h>
|
2011-11-05 13:11:49 +00:00
|
|
|
|
2011-11-05 13:00:39 +00:00
|
|
|
#include "DNA_camera_types.h"
|
|
|
|
#include "DNA_lamp_types.h"
|
|
|
|
#include "DNA_object_types.h"
|
|
|
|
#include "DNA_scene_types.h"
|
2011-11-18 21:19:03 +00:00
|
|
|
#include "DNA_view3d_types.h"
|
2015-04-06 10:40:12 -03:00
|
|
|
#include "DNA_ID.h"
|
2011-11-05 13:00:39 +00:00
|
|
|
|
|
|
|
#include "BLI_math.h"
|
2017-10-26 21:40:37 +11:00
|
|
|
#include "BLI_listbase.h"
|
2015-01-03 12:05:16 +01:00
|
|
|
#include "BLI_rect.h"
|
2015-04-06 10:40:12 -03:00
|
|
|
#include "BLI_string.h"
|
|
|
|
#include "BLI_utildefines.h"
|
2011-11-05 13:00:39 +00:00
|
|
|
|
|
|
|
#include "BKE_animsys.h"
|
|
|
|
#include "BKE_camera.h"
|
2011-11-14 03:54:23 +00:00
|
|
|
#include "BKE_object.h"
|
2017-11-08 12:16:49 -02:00
|
|
|
#include "BKE_layer.h"
|
2011-11-05 13:00:39 +00:00
|
|
|
#include "BKE_library.h"
|
|
|
|
#include "BKE_main.h"
|
2015-04-06 10:40:12 -03:00
|
|
|
#include "BKE_scene.h"
|
2011-11-18 21:19:03 +00:00
|
|
|
#include "BKE_screen.h"
|
2011-11-05 13:00:39 +00:00
|
|
|
|
2018-01-18 15:58:02 +01:00
|
|
|
#include "DEG_depsgraph_query.h"
|
|
|
|
|
2017-10-26 21:40:37 +11:00
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
2011-11-18 15:52:00 +00:00
|
|
|
/****************************** Camera Datablock *****************************/
|
|
|
|
|
First step to handle missing libs/datablocks when reading a file.
Idea is, instead of ignoring completely missing linked datablocks, to
create void placeholders for them.
That way, you can work on your file, save it, and find again your missing data once
lib becomes available again. Or you can edit missing lib's path (in Outliner),
save and reload the file, and you are done.
Also, Outliner now shows broken libraries (and placeholders) with a 'broken lib' icon.
Future plans are also to be able to relocate missing libs and reload them at runtime.
Code notes:
- Placeholder ID is just a regular datablock of same type as expected linked one,
with 'default' data, and a LIB_MISSING bitflag set.
- To allow creation of such datablocks, creation of datablocks in BKE was split in two step:
+ Allocation of memory itself.
+ Setting of all internal data to default values.
See also the design task (T43351).
Reviewed by @campbellbarton, thanks a bunch!
Differential Revision: https://developer.blender.org/D1394
2015-10-20 14:44:57 +02:00
|
|
|
void BKE_camera_init(Camera *cam)
|
2011-11-05 13:00:39 +00:00
|
|
|
{
|
First step to handle missing libs/datablocks when reading a file.
Idea is, instead of ignoring completely missing linked datablocks, to
create void placeholders for them.
That way, you can work on your file, save it, and find again your missing data once
lib becomes available again. Or you can edit missing lib's path (in Outliner),
save and reload the file, and you are done.
Also, Outliner now shows broken libraries (and placeholders) with a 'broken lib' icon.
Future plans are also to be able to relocate missing libs and reload them at runtime.
Code notes:
- Placeholder ID is just a regular datablock of same type as expected linked one,
with 'default' data, and a LIB_MISSING bitflag set.
- To allow creation of such datablocks, creation of datablocks in BKE was split in two step:
+ Allocation of memory itself.
+ Setting of all internal data to default values.
See also the design task (T43351).
Reviewed by @campbellbarton, thanks a bunch!
Differential Revision: https://developer.blender.org/D1394
2015-10-20 14:44:57 +02:00
|
|
|
BLI_assert(MEMCMP_STRUCT_OFS_IS_ZERO(cam, id));
|
2012-05-06 15:15:33 +00:00
|
|
|
|
2018-05-15 14:40:01 +02:00
|
|
|
cam->lens = 50.0f;
|
2012-08-09 15:59:32 +00:00
|
|
|
cam->sensor_x = DEFAULT_SENSOR_WIDTH;
|
|
|
|
cam->sensor_y = DEFAULT_SENSOR_HEIGHT;
|
2012-05-06 15:15:33 +00:00
|
|
|
cam->clipsta = 0.1f;
|
2018-07-26 12:29:16 +02:00
|
|
|
cam->clipend = 1000.0f;
|
2018-12-11 14:30:24 +11:00
|
|
|
cam->drawsize = 1.0f;
|
2012-05-06 15:15:33 +00:00
|
|
|
cam->ortho_scale = 6.0;
|
2011-11-05 13:00:39 +00:00
|
|
|
cam->flag |= CAM_SHOWPASSEPARTOUT;
|
|
|
|
cam->passepartalpha = 0.5f;
|
2015-02-12 18:54:41 +01:00
|
|
|
|
2018-07-24 17:57:24 +02:00
|
|
|
cam->gpu_dof.fstop = 128.0f;
|
|
|
|
cam->gpu_dof.ratio = 1.0f;
|
|
|
|
|
2015-04-06 10:40:12 -03:00
|
|
|
/* stereoscopy 3d */
|
|
|
|
cam->stereo.interocular_distance = 0.065f;
|
|
|
|
cam->stereo.convergence_distance = 30.f * 0.065f;
|
2016-07-22 04:05:38 +10:00
|
|
|
cam->stereo.pole_merge_angle_from = DEG2RADF(60.0f);
|
|
|
|
cam->stereo.pole_merge_angle_to = DEG2RADF(75.0f);
|
First step to handle missing libs/datablocks when reading a file.
Idea is, instead of ignoring completely missing linked datablocks, to
create void placeholders for them.
That way, you can work on your file, save it, and find again your missing data once
lib becomes available again. Or you can edit missing lib's path (in Outliner),
save and reload the file, and you are done.
Also, Outliner now shows broken libraries (and placeholders) with a 'broken lib' icon.
Future plans are also to be able to relocate missing libs and reload them at runtime.
Code notes:
- Placeholder ID is just a regular datablock of same type as expected linked one,
with 'default' data, and a LIB_MISSING bitflag set.
- To allow creation of such datablocks, creation of datablocks in BKE was split in two step:
+ Allocation of memory itself.
+ Setting of all internal data to default values.
See also the design task (T43351).
Reviewed by @campbellbarton, thanks a bunch!
Differential Revision: https://developer.blender.org/D1394
2015-10-20 14:44:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void *BKE_camera_add(Main *bmain, const char *name)
|
|
|
|
{
|
|
|
|
Camera *cam;
|
|
|
|
|
Refactor ID copying (and to some extent, ID freeing).
This will allow much finer controll over how we copy data-blocks, from
full copy in Main database, to "lighter" ones (out of Main, inside an
already allocated datablock, etc.).
This commit also transfers a llot of what was previously handled by
per-ID-type custom code to generic ID handling code in BKE_library.
Hopefully will avoid in future inconsistencies and missing bits we had
all over the codebase in the past.
It also adds missing copying handling for a few types, most notably
Scene (which where using a fully customized handling previously).
Note that the type of allocation used during copying (regular in Main,
allocated but outside of Main, or not allocated by ID handling code at
all) is stored in ID's, which allows to handle them correctly when
freeing. This needs to be taken care of with caution when doing 'weird'
unusual things with ID copying and/or allocation!
As a final note, while rather noisy, this commit will hopefully not
break too much existing branches, old 'API' has been kept for the main
part, as a wrapper around new code. Cleaning it up will happen later.
Design task : T51804
Phab Diff: D2714
2017-08-07 16:39:55 +02:00
|
|
|
cam = BKE_libblock_alloc(bmain, ID_CA, name, 0);
|
First step to handle missing libs/datablocks when reading a file.
Idea is, instead of ignoring completely missing linked datablocks, to
create void placeholders for them.
That way, you can work on your file, save it, and find again your missing data once
lib becomes available again. Or you can edit missing lib's path (in Outliner),
save and reload the file, and you are done.
Also, Outliner now shows broken libraries (and placeholders) with a 'broken lib' icon.
Future plans are also to be able to relocate missing libs and reload them at runtime.
Code notes:
- Placeholder ID is just a regular datablock of same type as expected linked one,
with 'default' data, and a LIB_MISSING bitflag set.
- To allow creation of such datablocks, creation of datablocks in BKE was split in two step:
+ Allocation of memory itself.
+ Setting of all internal data to default values.
See also the design task (T43351).
Reviewed by @campbellbarton, thanks a bunch!
Differential Revision: https://developer.blender.org/D1394
2015-10-20 14:44:57 +02:00
|
|
|
|
|
|
|
BKE_camera_init(cam);
|
2015-04-06 10:40:12 -03:00
|
|
|
|
2011-11-05 13:00:39 +00:00
|
|
|
return cam;
|
|
|
|
}
|
|
|
|
|
Refactor ID copying (and to some extent, ID freeing).
This will allow much finer controll over how we copy data-blocks, from
full copy in Main database, to "lighter" ones (out of Main, inside an
already allocated datablock, etc.).
This commit also transfers a llot of what was previously handled by
per-ID-type custom code to generic ID handling code in BKE_library.
Hopefully will avoid in future inconsistencies and missing bits we had
all over the codebase in the past.
It also adds missing copying handling for a few types, most notably
Scene (which where using a fully customized handling previously).
Note that the type of allocation used during copying (regular in Main,
allocated but outside of Main, or not allocated by ID handling code at
all) is stored in ID's, which allows to handle them correctly when
freeing. This needs to be taken care of with caution when doing 'weird'
unusual things with ID copying and/or allocation!
As a final note, while rather noisy, this commit will hopefully not
break too much existing branches, old 'API' has been kept for the main
part, as a wrapper around new code. Cleaning it up will happen later.
Design task : T51804
Phab Diff: D2714
2017-08-07 16:39:55 +02:00
|
|
|
/**
|
|
|
|
* Only copy internal data of Camera ID from source to already allocated/initialized destination.
|
|
|
|
* You probably nerver want to use that directly, use id_copy or BKE_id_copy_ex for typical needs.
|
|
|
|
*
|
|
|
|
* WARNING! This function will not handle ID user count!
|
|
|
|
*
|
2018-12-12 12:50:58 +11:00
|
|
|
* \param flag: Copying options (see BKE_library.h's LIB_ID_COPY_... flags for more).
|
Refactor ID copying (and to some extent, ID freeing).
This will allow much finer controll over how we copy data-blocks, from
full copy in Main database, to "lighter" ones (out of Main, inside an
already allocated datablock, etc.).
This commit also transfers a llot of what was previously handled by
per-ID-type custom code to generic ID handling code in BKE_library.
Hopefully will avoid in future inconsistencies and missing bits we had
all over the codebase in the past.
It also adds missing copying handling for a few types, most notably
Scene (which where using a fully customized handling previously).
Note that the type of allocation used during copying (regular in Main,
allocated but outside of Main, or not allocated by ID handling code at
all) is stored in ID's, which allows to handle them correctly when
freeing. This needs to be taken care of with caution when doing 'weird'
unusual things with ID copying and/or allocation!
As a final note, while rather noisy, this commit will hopefully not
break too much existing branches, old 'API' has been kept for the main
part, as a wrapper around new code. Cleaning it up will happen later.
Design task : T51804
Phab Diff: D2714
2017-08-07 16:39:55 +02:00
|
|
|
*/
|
2018-08-08 11:57:35 +02:00
|
|
|
void BKE_camera_copy_data(Main *UNUSED(bmain), Camera *cam_dst, const Camera *cam_src, const int UNUSED(flag))
|
2011-11-05 13:00:39 +00:00
|
|
|
{
|
2017-10-26 21:40:37 +11:00
|
|
|
BLI_duplicatelist(&cam_dst->bg_images, &cam_src->bg_images);
|
Refactor ID copying (and to some extent, ID freeing).
This will allow much finer controll over how we copy data-blocks, from
full copy in Main database, to "lighter" ones (out of Main, inside an
already allocated datablock, etc.).
This commit also transfers a llot of what was previously handled by
per-ID-type custom code to generic ID handling code in BKE_library.
Hopefully will avoid in future inconsistencies and missing bits we had
all over the codebase in the past.
It also adds missing copying handling for a few types, most notably
Scene (which where using a fully customized handling previously).
Note that the type of allocation used during copying (regular in Main,
allocated but outside of Main, or not allocated by ID handling code at
all) is stored in ID's, which allows to handle them correctly when
freeing. This needs to be taken care of with caution when doing 'weird'
unusual things with ID copying and/or allocation!
As a final note, while rather noisy, this commit will hopefully not
break too much existing branches, old 'API' has been kept for the main
part, as a wrapper around new code. Cleaning it up will happen later.
Design task : T51804
Phab Diff: D2714
2017-08-07 16:39:55 +02:00
|
|
|
}
|
2015-01-09 09:52:51 +01:00
|
|
|
|
Refactor ID copying (and to some extent, ID freeing).
This will allow much finer controll over how we copy data-blocks, from
full copy in Main database, to "lighter" ones (out of Main, inside an
already allocated datablock, etc.).
This commit also transfers a llot of what was previously handled by
per-ID-type custom code to generic ID handling code in BKE_library.
Hopefully will avoid in future inconsistencies and missing bits we had
all over the codebase in the past.
It also adds missing copying handling for a few types, most notably
Scene (which where using a fully customized handling previously).
Note that the type of allocation used during copying (regular in Main,
allocated but outside of Main, or not allocated by ID handling code at
all) is stored in ID's, which allows to handle them correctly when
freeing. This needs to be taken care of with caution when doing 'weird'
unusual things with ID copying and/or allocation!
As a final note, while rather noisy, this commit will hopefully not
break too much existing branches, old 'API' has been kept for the main
part, as a wrapper around new code. Cleaning it up will happen later.
Design task : T51804
Phab Diff: D2714
2017-08-07 16:39:55 +02:00
|
|
|
Camera *BKE_camera_copy(Main *bmain, const Camera *cam)
|
|
|
|
{
|
|
|
|
Camera *cam_copy;
|
2019-02-04 15:34:31 +01:00
|
|
|
BKE_id_copy_ex(bmain, &cam->id, (ID **)&cam_copy, 0);
|
Refactor ID copying (and to some extent, ID freeing).
This will allow much finer controll over how we copy data-blocks, from
full copy in Main database, to "lighter" ones (out of Main, inside an
already allocated datablock, etc.).
This commit also transfers a llot of what was previously handled by
per-ID-type custom code to generic ID handling code in BKE_library.
Hopefully will avoid in future inconsistencies and missing bits we had
all over the codebase in the past.
It also adds missing copying handling for a few types, most notably
Scene (which where using a fully customized handling previously).
Note that the type of allocation used during copying (regular in Main,
allocated but outside of Main, or not allocated by ID handling code at
all) is stored in ID's, which allows to handle them correctly when
freeing. This needs to be taken care of with caution when doing 'weird'
unusual things with ID copying and/or allocation!
As a final note, while rather noisy, this commit will hopefully not
break too much existing branches, old 'API' has been kept for the main
part, as a wrapper around new code. Cleaning it up will happen later.
Design task : T51804
Phab Diff: D2714
2017-08-07 16:39:55 +02:00
|
|
|
return cam_copy;
|
2011-11-05 13:00:39 +00:00
|
|
|
}
|
|
|
|
|
2016-07-20 19:49:45 +02:00
|
|
|
void BKE_camera_make_local(Main *bmain, Camera *cam, const bool lib_local)
|
2011-11-05 13:00:39 +00:00
|
|
|
{
|
2016-07-20 19:49:45 +02:00
|
|
|
BKE_id_make_local_generic(bmain, &cam->id, true, lib_local);
|
2011-11-05 13:00:39 +00:00
|
|
|
}
|
|
|
|
|
ID-Remap - Step one: core work (cleanup and rework of generic ID datablock handling).
This commit changes a lot of how IDs are handled internally, especially the unlinking/freeing
processes. So far, this was very fuzy, to summarize cleanly deleting or replacing a datablock
was pretty much impossible, except for a few special cases.
Also, unlinking was handled by each datatype, in a rather messy and prone-to-errors way (quite
a few ID usages were missed or wrongly handled that way).
One of the main goal of id-remap branch was to cleanup this, and fatorize ID links handling
by using library_query utils to allow generic handling of those, which is now the case
(now, generic ID links handling is only "knwon" from readfile.c and library_query.c).
This commit also adds backends to allow live replacement and deletion of datablocks in Blender
(so-called 'remapping' process, where we replace all usages of a given ID pointer by a new one,
or NULL one in case of unlinking).
This will allow nice new features, like ability to easily reload or relocate libraries, real immediate
deletion of datablocks in blender, replacement of one datablock by another, etc.
Some of those are for next commits.
A word of warning: this commit is highly risky, because it affects potentially a lot in Blender core.
Though it was tested rather deeply, being totally impossible to check all possible ID usage cases,
it's likely there are some remaining issues and bugs in new code... Please report them! ;)
Review task: D2027 (https://developer.blender.org/D2027).
Reviewed by campbellbarton, thanks a bunch.
2016-06-22 17:29:38 +02:00
|
|
|
/** Free (or release) any data used by this camera (does not free the camera itself). */
|
2012-05-05 00:58:22 +00:00
|
|
|
void BKE_camera_free(Camera *ca)
|
2011-11-18 15:52:00 +00:00
|
|
|
{
|
2017-10-26 21:40:37 +11:00
|
|
|
BLI_freelistN(&ca->bg_images);
|
|
|
|
|
ID-Remap - Step one: core work (cleanup and rework of generic ID datablock handling).
This commit changes a lot of how IDs are handled internally, especially the unlinking/freeing
processes. So far, this was very fuzy, to summarize cleanly deleting or replacing a datablock
was pretty much impossible, except for a few special cases.
Also, unlinking was handled by each datatype, in a rather messy and prone-to-errors way (quite
a few ID usages were missed or wrongly handled that way).
One of the main goal of id-remap branch was to cleanup this, and fatorize ID links handling
by using library_query utils to allow generic handling of those, which is now the case
(now, generic ID links handling is only "knwon" from readfile.c and library_query.c).
This commit also adds backends to allow live replacement and deletion of datablocks in Blender
(so-called 'remapping' process, where we replace all usages of a given ID pointer by a new one,
or NULL one in case of unlinking).
This will allow nice new features, like ability to easily reload or relocate libraries, real immediate
deletion of datablocks in blender, replacement of one datablock by another, etc.
Some of those are for next commits.
A word of warning: this commit is highly risky, because it affects potentially a lot in Blender core.
Though it was tested rather deeply, being totally impossible to check all possible ID usage cases,
it's likely there are some remaining issues and bugs in new code... Please report them! ;)
Review task: D2027 (https://developer.blender.org/D2027).
Reviewed by campbellbarton, thanks a bunch.
2016-06-22 17:29:38 +02:00
|
|
|
BKE_animdata_free((ID *)ca, false);
|
2011-11-18 15:52:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************** Camera Usage *******************************/
|
|
|
|
|
2011-11-05 13:00:39 +00:00
|
|
|
/* get the camera's dof value, takes the dof object into account */
|
2012-05-05 00:58:22 +00:00
|
|
|
float BKE_camera_object_dof_distance(Object *ob)
|
2011-11-05 13:00:39 +00:00
|
|
|
{
|
2018-06-17 17:05:51 +02:00
|
|
|
Camera *cam = (Camera *)ob->data;
|
2011-11-05 13:00:39 +00:00
|
|
|
if (ob->type != OB_CAMERA)
|
|
|
|
return 0.0f;
|
2012-10-21 05:46:41 +00:00
|
|
|
if (cam->dof_ob) {
|
2015-09-07 02:32:34 +10:00
|
|
|
float view_dir[3], dof_dir[3];
|
|
|
|
normalize_v3_v3(view_dir, ob->obmat[2]);
|
|
|
|
sub_v3_v3v3(dof_dir, ob->obmat[3], cam->dof_ob->obmat[3]);
|
|
|
|
return fabsf(dot_v3v3(view_dir, dof_dir));
|
2011-11-05 13:00:39 +00:00
|
|
|
}
|
|
|
|
return cam->YF_dofdist;
|
|
|
|
}
|
|
|
|
|
2012-05-05 00:58:22 +00:00
|
|
|
float BKE_camera_sensor_size(int sensor_fit, float sensor_x, float sensor_y)
|
2011-11-18 21:19:03 +00:00
|
|
|
{
|
|
|
|
/* sensor size used to fit to. for auto, sensor_x is both x and y. */
|
2012-03-24 06:18:31 +00:00
|
|
|
if (sensor_fit == CAMERA_SENSOR_FIT_VERT)
|
2011-11-18 21:19:03 +00:00
|
|
|
return sensor_y;
|
2011-11-18 15:52:00 +00:00
|
|
|
|
2011-11-18 21:19:03 +00:00
|
|
|
return sensor_x;
|
|
|
|
}
|
|
|
|
|
2012-05-05 00:58:22 +00:00
|
|
|
int BKE_camera_sensor_fit(int sensor_fit, float sizex, float sizey)
|
2011-11-05 13:00:39 +00:00
|
|
|
{
|
2012-03-24 06:18:31 +00:00
|
|
|
if (sensor_fit == CAMERA_SENSOR_FIT_AUTO) {
|
|
|
|
if (sizex >= sizey)
|
2011-11-18 15:52:00 +00:00
|
|
|
return CAMERA_SENSOR_FIT_HOR;
|
|
|
|
else
|
|
|
|
return CAMERA_SENSOR_FIT_VERT;
|
|
|
|
}
|
|
|
|
|
|
|
|
return sensor_fit;
|
2011-11-05 13:00:39 +00:00
|
|
|
}
|
|
|
|
|
2011-11-18 21:19:03 +00:00
|
|
|
/******************************** Camera Params *******************************/
|
|
|
|
|
2012-05-05 00:58:22 +00:00
|
|
|
void BKE_camera_params_init(CameraParams *params)
|
2011-11-05 13:00:39 +00:00
|
|
|
{
|
2011-11-18 15:52:00 +00:00
|
|
|
memset(params, 0, sizeof(CameraParams));
|
|
|
|
|
|
|
|
/* defaults */
|
2012-05-06 15:15:33 +00:00
|
|
|
params->sensor_x = DEFAULT_SENSOR_WIDTH;
|
|
|
|
params->sensor_y = DEFAULT_SENSOR_HEIGHT;
|
|
|
|
params->sensor_fit = CAMERA_SENSOR_FIT_AUTO;
|
2011-11-18 21:19:03 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
params->zoom = 1.0f;
|
2014-03-01 21:41:07 +11:00
|
|
|
|
|
|
|
/* fallback for non camera objects */
|
|
|
|
params->clipsta = 0.1f;
|
2014-08-11 14:11:15 +06:00
|
|
|
params->clipend = 100.0f;
|
2011-11-05 13:00:39 +00:00
|
|
|
}
|
|
|
|
|
2015-03-21 22:34:20 +11:00
|
|
|
void BKE_camera_params_from_object(CameraParams *params, const Object *ob)
|
2011-11-05 13:00:39 +00:00
|
|
|
{
|
2012-03-24 06:18:31 +00:00
|
|
|
if (!ob)
|
2011-11-18 15:52:00 +00:00
|
|
|
return;
|
2011-11-05 13:00:39 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
if (ob->type == OB_CAMERA) {
|
2011-11-18 15:52:00 +00:00
|
|
|
/* camera object */
|
2012-05-06 15:15:33 +00:00
|
|
|
Camera *cam = ob->data;
|
2011-11-05 13:00:39 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (cam->type == CAM_ORTHO)
|
2014-04-01 11:34:00 +11:00
|
|
|
params->is_ortho = true;
|
2012-05-06 15:15:33 +00:00
|
|
|
params->lens = cam->lens;
|
|
|
|
params->ortho_scale = cam->ortho_scale;
|
2011-11-05 13:00:39 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
params->shiftx = cam->shiftx;
|
|
|
|
params->shifty = cam->shifty;
|
2011-11-05 13:00:39 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
params->sensor_x = cam->sensor_x;
|
|
|
|
params->sensor_y = cam->sensor_y;
|
|
|
|
params->sensor_fit = cam->sensor_fit;
|
2011-11-05 13:00:39 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
params->clipsta = cam->clipsta;
|
|
|
|
params->clipend = cam->clipend;
|
2011-11-05 13:00:39 +00:00
|
|
|
}
|
2012-05-06 15:15:33 +00:00
|
|
|
else if (ob->type == OB_LAMP) {
|
2011-11-18 15:52:00 +00:00
|
|
|
/* lamp object */
|
2012-05-06 15:15:33 +00:00
|
|
|
Lamp *la = ob->data;
|
2019-01-17 16:28:43 +01:00
|
|
|
params->lens = 16.0f / tanf(la->spotsize * 0.5f);
|
2012-05-06 15:15:33 +00:00
|
|
|
if (params->lens == 0.0f)
|
|
|
|
params->lens = 35.0f;
|
2011-11-05 13:00:39 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
params->clipsta = la->clipsta;
|
|
|
|
params->clipend = la->clipend;
|
2011-11-05 13:00:39 +00:00
|
|
|
}
|
2013-01-17 08:46:46 +00:00
|
|
|
else {
|
|
|
|
params->lens = 35.0f;
|
|
|
|
}
|
2011-11-05 13:00:39 +00:00
|
|
|
}
|
|
|
|
|
2018-04-06 12:07:27 +02:00
|
|
|
void BKE_camera_params_from_view3d(CameraParams *params, Depsgraph *depsgraph, const View3D *v3d, const RegionView3D *rv3d)
|
2011-11-18 21:19:03 +00:00
|
|
|
{
|
2011-11-19 18:35:42 +00:00
|
|
|
/* common */
|
2012-05-06 15:15:33 +00:00
|
|
|
params->lens = v3d->lens;
|
|
|
|
params->clipsta = v3d->near;
|
|
|
|
params->clipend = v3d->far;
|
2011-11-18 21:19:03 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
if (rv3d->persp == RV3D_CAMOB) {
|
2011-11-18 21:19:03 +00:00
|
|
|
/* camera view */
|
2018-05-25 11:05:51 +02:00
|
|
|
const Object *ob_camera_eval = DEG_get_evaluated_object(depsgraph, v3d->camera);
|
2018-05-22 07:48:12 +02:00
|
|
|
BKE_camera_params_from_object(params, ob_camera_eval);
|
2011-11-18 21:19:03 +00:00
|
|
|
|
2015-03-02 11:00:22 +11:00
|
|
|
params->zoom = BKE_screen_view3d_zoom_to_fac(rv3d->camzoom);
|
2011-11-19 18:35:42 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
params->offsetx = 2.0f * rv3d->camdx * params->zoom;
|
|
|
|
params->offsety = 2.0f * rv3d->camdy * params->zoom;
|
2011-11-18 21:19:03 +00:00
|
|
|
|
2011-11-19 18:35:42 +00:00
|
|
|
params->shiftx *= params->zoom;
|
|
|
|
params->shifty *= params->zoom;
|
2011-11-18 21:19:03 +00:00
|
|
|
|
2015-03-21 15:11:19 +11:00
|
|
|
params->zoom = CAMERA_PARAM_ZOOM_INIT_CAMOB / params->zoom;
|
2011-11-18 21:19:03 +00:00
|
|
|
}
|
2012-05-06 15:15:33 +00:00
|
|
|
else if (rv3d->persp == RV3D_ORTHO) {
|
2011-11-18 21:19:03 +00:00
|
|
|
/* orthographic view */
|
2016-11-28 17:29:27 +11:00
|
|
|
float sensor_size = BKE_camera_sensor_size(params->sensor_fit, params->sensor_x, params->sensor_y);
|
2012-05-06 15:15:33 +00:00
|
|
|
params->clipend *= 0.5f; // otherwise too extreme low zbuffer quality
|
|
|
|
params->clipsta = -params->clipend;
|
2011-11-18 21:19:03 +00:00
|
|
|
|
2014-04-01 11:34:00 +11:00
|
|
|
params->is_ortho = true;
|
2015-03-21 15:11:30 +11:00
|
|
|
/* make sure any changes to this match ED_view3d_radius_to_dist_ortho() */
|
2012-10-24 16:15:46 +00:00
|
|
|
params->ortho_scale = rv3d->dist * sensor_size / v3d->lens;
|
2015-03-21 15:11:19 +11:00
|
|
|
params->zoom = CAMERA_PARAM_ZOOM_INIT_PERSP;
|
2011-11-19 18:35:42 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* perspective view */
|
2015-03-21 15:11:19 +11:00
|
|
|
params->zoom = CAMERA_PARAM_ZOOM_INIT_PERSP;
|
2011-11-18 21:19:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-05 00:58:22 +00:00
|
|
|
void BKE_camera_params_compute_viewplane(CameraParams *params, int winx, int winy, float xasp, float yasp)
|
2011-11-05 13:00:39 +00:00
|
|
|
{
|
2011-11-18 15:52:00 +00:00
|
|
|
rctf viewplane;
|
2011-11-18 21:19:03 +00:00
|
|
|
float pixsize, viewfac, sensor_size, dx, dy;
|
2011-11-18 15:52:00 +00:00
|
|
|
int sensor_fit;
|
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
params->ycor = yasp / xasp;
|
2011-11-18 15:52:00 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (params->is_ortho) {
|
2011-11-18 21:19:03 +00:00
|
|
|
/* orthographic camera */
|
|
|
|
/* scale == 1.0 means exact 1 to 1 mapping */
|
2012-05-06 15:15:33 +00:00
|
|
|
pixsize = params->ortho_scale;
|
2011-11-05 13:00:39 +00:00
|
|
|
}
|
|
|
|
else {
|
2011-11-18 15:52:00 +00:00
|
|
|
/* perspective camera */
|
2012-05-06 15:15:33 +00:00
|
|
|
sensor_size = BKE_camera_sensor_size(params->sensor_fit, params->sensor_x, params->sensor_y);
|
|
|
|
pixsize = (sensor_size * params->clipsta) / params->lens;
|
2011-11-18 21:19:03 +00:00
|
|
|
}
|
2011-11-18 15:52:00 +00:00
|
|
|
|
2011-11-18 21:19:03 +00:00
|
|
|
/* determine sensor fit */
|
2012-05-06 15:15:33 +00:00
|
|
|
sensor_fit = BKE_camera_sensor_fit(params->sensor_fit, xasp * winx, yasp * winy);
|
2011-11-05 13:00:39 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
if (sensor_fit == CAMERA_SENSOR_FIT_HOR)
|
|
|
|
viewfac = winx;
|
2011-11-18 21:19:03 +00:00
|
|
|
else
|
2012-05-06 15:15:33 +00:00
|
|
|
viewfac = params->ycor * winy;
|
2011-11-18 21:19:03 +00:00
|
|
|
|
|
|
|
pixsize /= viewfac;
|
|
|
|
|
|
|
|
/* extra zoom factor */
|
|
|
|
pixsize *= params->zoom;
|
2011-11-05 13:00:39 +00:00
|
|
|
|
2011-11-18 15:52:00 +00:00
|
|
|
/* compute view plane:
|
|
|
|
* fully centered, zbuffer fills in jittered between -.5 and +.5 */
|
2012-05-06 15:15:33 +00:00
|
|
|
viewplane.xmin = -0.5f * (float)winx;
|
|
|
|
viewplane.ymin = -0.5f * params->ycor * (float)winy;
|
|
|
|
viewplane.xmax = 0.5f * (float)winx;
|
|
|
|
viewplane.ymax = 0.5f * params->ycor * (float)winy;
|
2011-11-05 13:00:39 +00:00
|
|
|
|
2011-11-18 21:19:03 +00:00
|
|
|
/* lens shift and offset */
|
2012-05-06 15:15:33 +00:00
|
|
|
dx = params->shiftx * viewfac + winx * params->offsetx;
|
|
|
|
dy = params->shifty * viewfac + winy * params->offsety;
|
2011-11-05 13:00:39 +00:00
|
|
|
|
2011-11-18 21:19:03 +00:00
|
|
|
viewplane.xmin += dx;
|
|
|
|
viewplane.ymin += dy;
|
|
|
|
viewplane.xmax += dx;
|
|
|
|
viewplane.ymax += dy;
|
|
|
|
|
2011-11-05 13:00:39 +00:00
|
|
|
/* the window matrix is used for clipping, and not changed during OSA steps */
|
|
|
|
/* using an offset of +0.5 here would give clip errors on edges */
|
2011-11-18 15:52:00 +00:00
|
|
|
viewplane.xmin *= pixsize;
|
|
|
|
viewplane.xmax *= pixsize;
|
|
|
|
viewplane.ymin *= pixsize;
|
|
|
|
viewplane.ymax *= pixsize;
|
2011-11-05 13:00:39 +00:00
|
|
|
|
2016-11-29 13:12:26 +11:00
|
|
|
/* Used for rendering (offset by near-clip with perspective views), passed to RE_SetPixelSize.
|
|
|
|
* For viewport drawing 'RegionView3D.pixsize'. */
|
2012-05-06 15:15:33 +00:00
|
|
|
params->viewdx = pixsize;
|
|
|
|
params->viewdy = params->ycor * pixsize;
|
|
|
|
params->viewplane = viewplane;
|
2011-11-19 18:35:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* viewplane is assumed to be already computed */
|
2012-05-05 00:58:22 +00:00
|
|
|
void BKE_camera_params_compute_matrix(CameraParams *params)
|
2011-11-19 18:35:42 +00:00
|
|
|
{
|
2012-05-05 00:58:22 +00:00
|
|
|
rctf viewplane = params->viewplane;
|
2011-11-05 13:00:39 +00:00
|
|
|
|
2011-11-18 21:19:03 +00:00
|
|
|
/* compute projection matrix */
|
2012-03-24 06:18:31 +00:00
|
|
|
if (params->is_ortho)
|
2011-11-18 15:52:00 +00:00
|
|
|
orthographic_m4(params->winmat, viewplane.xmin, viewplane.xmax,
|
2012-05-05 00:58:22 +00:00
|
|
|
viewplane.ymin, viewplane.ymax, params->clipsta, params->clipend);
|
2011-11-05 13:00:39 +00:00
|
|
|
else
|
2011-11-18 15:52:00 +00:00
|
|
|
perspective_m4(params->winmat, viewplane.xmin, viewplane.xmax,
|
2012-05-05 00:58:22 +00:00
|
|
|
viewplane.ymin, viewplane.ymax, params->clipsta, params->clipend);
|
2011-11-05 13:00:39 +00:00
|
|
|
}
|
|
|
|
|
2011-11-18 15:52:00 +00:00
|
|
|
/***************************** Camera View Frame *****************************/
|
|
|
|
|
2015-03-21 22:34:20 +11:00
|
|
|
void BKE_camera_view_frame_ex(
|
|
|
|
const Scene *scene, const Camera *camera,
|
|
|
|
const float drawsize, const bool do_clip, const float scale[3],
|
|
|
|
float r_asp[2], float r_shift[2], float *r_drawsize, float r_vec[4][3])
|
2011-11-05 13:00:39 +00:00
|
|
|
{
|
|
|
|
float facx, facy;
|
|
|
|
float depth;
|
|
|
|
|
|
|
|
/* aspect correcton */
|
|
|
|
if (scene) {
|
2012-05-06 15:15:33 +00:00
|
|
|
float aspx = (float) scene->r.xsch * scene->r.xasp;
|
|
|
|
float aspy = (float) scene->r.ysch * scene->r.yasp;
|
|
|
|
int sensor_fit = BKE_camera_sensor_fit(camera->sensor_fit, aspx, aspy);
|
2011-11-05 13:00:39 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
if (sensor_fit == CAMERA_SENSOR_FIT_HOR) {
|
|
|
|
r_asp[0] = 1.0;
|
|
|
|
r_asp[1] = aspy / aspx;
|
2011-11-05 13:00:39 +00:00
|
|
|
}
|
2011-11-18 23:15:11 +00:00
|
|
|
else {
|
2012-05-06 15:15:33 +00:00
|
|
|
r_asp[0] = aspx / aspy;
|
|
|
|
r_asp[1] = 1.0;
|
2011-11-05 13:00:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2012-05-06 15:15:33 +00:00
|
|
|
r_asp[0] = 1.0f;
|
|
|
|
r_asp[1] = 1.0f;
|
2011-11-05 13:00:39 +00:00
|
|
|
}
|
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
if (camera->type == CAM_ORTHO) {
|
|
|
|
facx = 0.5f * camera->ortho_scale * r_asp[0] * scale[0];
|
|
|
|
facy = 0.5f * camera->ortho_scale * r_asp[1] * scale[1];
|
|
|
|
r_shift[0] = camera->shiftx * camera->ortho_scale * scale[0];
|
|
|
|
r_shift[1] = camera->shifty * camera->ortho_scale * scale[1];
|
2018-12-11 14:30:24 +11:00
|
|
|
depth = do_clip ? -((camera->clipsta * scale[2]) + 0.1f) : -drawsize * scale[2];
|
2011-11-05 13:00:39 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
*r_drawsize = 0.5f * camera->ortho_scale;
|
2011-11-05 13:00:39 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* that way it's always visible - clipsta+0.1 */
|
2013-07-26 05:08:24 +00:00
|
|
|
float fac, scale_x, scale_y;
|
|
|
|
float half_sensor = 0.5f * ((camera->sensor_fit == CAMERA_SENSOR_FIT_VERT) ?
|
|
|
|
(camera->sensor_y) : (camera->sensor_x));
|
2011-11-05 13:00:39 +00:00
|
|
|
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (do_clip) {
|
2011-11-05 13:00:39 +00:00
|
|
|
/* fixed depth, variable size (avoids exceeding clipping range) */
|
2013-07-26 05:08:24 +00:00
|
|
|
/* r_drawsize shouldn't be used in this case, set to dummy value */
|
|
|
|
*r_drawsize = 1.0f;
|
|
|
|
depth = -(camera->clipsta + 0.1f) * scale[2];
|
|
|
|
fac = depth / (camera->lens / (-half_sensor));
|
2015-08-28 12:10:21 +10:00
|
|
|
scale_x = scale[0] / scale[2];
|
|
|
|
scale_y = scale[1] / scale[2];
|
2011-11-05 13:00:39 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* fixed size, variable depth (stays a reasonable size in the 3D view) */
|
2018-12-11 14:30:24 +11:00
|
|
|
*r_drawsize = (drawsize / 2.0f) / ((scale[0] + scale[1] + scale[2]) / 3.0f);
|
2012-05-06 15:15:33 +00:00
|
|
|
depth = *r_drawsize * camera->lens / (-half_sensor) * scale[2];
|
|
|
|
fac = *r_drawsize;
|
2013-07-26 05:08:24 +00:00
|
|
|
scale_x = scale[0];
|
|
|
|
scale_y = scale[1];
|
2011-11-05 13:00:39 +00:00
|
|
|
}
|
|
|
|
|
2013-07-26 05:08:24 +00:00
|
|
|
facx = fac * r_asp[0] * scale_x;
|
|
|
|
facy = fac * r_asp[1] * scale_y;
|
|
|
|
r_shift[0] = camera->shiftx * fac * 2.0f * scale_x;
|
|
|
|
r_shift[1] = camera->shifty * fac * 2.0f * scale_y;
|
2011-11-05 13:00:39 +00:00
|
|
|
}
|
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
r_vec[0][0] = r_shift[0] + facx; r_vec[0][1] = r_shift[1] + facy; r_vec[0][2] = depth;
|
|
|
|
r_vec[1][0] = r_shift[0] + facx; r_vec[1][1] = r_shift[1] - facy; r_vec[1][2] = depth;
|
|
|
|
r_vec[2][0] = r_shift[0] - facx; r_vec[2][1] = r_shift[1] - facy; r_vec[2][2] = depth;
|
|
|
|
r_vec[3][0] = r_shift[0] - facx; r_vec[3][1] = r_shift[1] + facy; r_vec[3][2] = depth;
|
2011-11-05 13:00:39 +00:00
|
|
|
}
|
|
|
|
|
2015-03-21 22:34:20 +11:00
|
|
|
void BKE_camera_view_frame(const Scene *scene, const Camera *camera, float r_vec[4][3])
|
2011-11-05 13:00:39 +00:00
|
|
|
{
|
|
|
|
float dummy_asp[2];
|
|
|
|
float dummy_shift[2];
|
|
|
|
float dummy_drawsize;
|
2012-05-06 15:15:33 +00:00
|
|
|
const float dummy_scale[3] = {1.0f, 1.0f, 1.0f};
|
2011-11-05 13:00:39 +00:00
|
|
|
|
2014-12-19 10:15:10 +01:00
|
|
|
BKE_camera_view_frame_ex(scene, camera, 0.0, true, dummy_scale,
|
2012-05-06 15:15:33 +00:00
|
|
|
dummy_asp, dummy_shift, &dummy_drawsize, r_vec);
|
2011-11-05 13:00:39 +00:00
|
|
|
}
|
|
|
|
|
2015-01-03 12:05:16 +01:00
|
|
|
#define CAMERA_VIEWFRAME_NUM_PLANES 4
|
2011-11-14 03:54:23 +00:00
|
|
|
|
|
|
|
typedef struct CameraViewFrameData {
|
2015-01-03 12:05:16 +01:00
|
|
|
float plane_tx[CAMERA_VIEWFRAME_NUM_PLANES][4]; /* 4 planes */
|
|
|
|
float normal_tx[CAMERA_VIEWFRAME_NUM_PLANES][3];
|
|
|
|
float dist_vals_sq[CAMERA_VIEWFRAME_NUM_PLANES]; /* distance squared (signed) */
|
2011-11-14 03:54:23 +00:00
|
|
|
unsigned int tot;
|
2015-01-03 12:05:16 +01:00
|
|
|
|
|
|
|
/* Ortho camera only. */
|
|
|
|
bool is_ortho;
|
|
|
|
float camera_no[3];
|
|
|
|
float dist_to_cam;
|
|
|
|
|
|
|
|
/* Not used by callbacks... */
|
|
|
|
float camera_rotmat[3][3];
|
2011-11-14 03:54:23 +00:00
|
|
|
} CameraViewFrameData;
|
|
|
|
|
2013-08-13 04:35:14 +00:00
|
|
|
static void camera_to_frame_view_cb(const float co[3], void *user_data)
|
2011-11-14 03:54:23 +00:00
|
|
|
{
|
2012-05-06 15:15:33 +00:00
|
|
|
CameraViewFrameData *data = (CameraViewFrameData *)user_data;
|
2011-11-14 03:54:23 +00:00
|
|
|
unsigned int i;
|
|
|
|
|
2015-01-03 12:05:16 +01:00
|
|
|
for (i = 0; i < CAMERA_VIEWFRAME_NUM_PLANES; i++) {
|
|
|
|
const float nd = dist_signed_squared_to_plane_v3(co, data->plane_tx[i]);
|
|
|
|
CLAMP_MAX(data->dist_vals_sq[i], nd);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (data->is_ortho) {
|
|
|
|
const float d = dot_v3v3(data->camera_no, co);
|
|
|
|
CLAMP_MAX(data->dist_to_cam, d);
|
2011-11-14 03:54:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
data->tot++;
|
|
|
|
}
|
|
|
|
|
2015-03-21 22:34:20 +11:00
|
|
|
static void camera_frame_fit_data_init(
|
|
|
|
const Scene *scene, const Object *ob,
|
|
|
|
CameraParams *params, CameraViewFrameData *data)
|
2011-11-14 03:54:23 +00:00
|
|
|
{
|
2015-01-03 12:05:16 +01:00
|
|
|
float camera_rotmat_transposed_inversed[4][4];
|
2011-11-14 03:54:23 +00:00
|
|
|
unsigned int i;
|
|
|
|
|
2015-01-03 12:05:16 +01:00
|
|
|
/* setup parameters */
|
|
|
|
BKE_camera_params_init(params);
|
|
|
|
BKE_camera_params_from_object(params, ob);
|
2011-11-14 03:54:23 +00:00
|
|
|
|
2015-01-03 12:05:16 +01:00
|
|
|
/* compute matrix, viewplane, .. */
|
|
|
|
if (scene) {
|
|
|
|
BKE_camera_params_compute_viewplane(params, scene->r.xsch, scene->r.ysch, scene->r.xasp, scene->r.yasp);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
BKE_camera_params_compute_viewplane(params, 1, 1, 1.0f, 1.0f);
|
2011-11-14 08:43:09 +00:00
|
|
|
}
|
2015-01-03 12:05:16 +01:00
|
|
|
BKE_camera_params_compute_matrix(params);
|
2011-11-14 08:43:09 +00:00
|
|
|
|
2015-01-03 12:05:16 +01:00
|
|
|
/* initialize callback data */
|
2015-03-21 22:34:20 +11:00
|
|
|
copy_m3_m4(data->camera_rotmat, (float (*)[4])ob->obmat);
|
2015-01-03 12:05:16 +01:00
|
|
|
normalize_m3(data->camera_rotmat);
|
|
|
|
/* To transform a plane which is in its homogeneous representation (4d vector),
|
|
|
|
* we need the inverse of the transpose of the transform matrix... */
|
|
|
|
copy_m4_m3(camera_rotmat_transposed_inversed, data->camera_rotmat);
|
|
|
|
transpose_m4(camera_rotmat_transposed_inversed);
|
|
|
|
invert_m4(camera_rotmat_transposed_inversed);
|
|
|
|
|
|
|
|
/* Extract frustum planes from projection matrix. */
|
|
|
|
planes_from_projmat(params->winmat,
|
|
|
|
/* left right top bottom near far */
|
|
|
|
data->plane_tx[2], data->plane_tx[0], data->plane_tx[3], data->plane_tx[1], NULL, NULL);
|
|
|
|
|
|
|
|
/* Rotate planes and get normals from them */
|
|
|
|
for (i = 0; i < CAMERA_VIEWFRAME_NUM_PLANES; i++) {
|
|
|
|
mul_m4_v4(camera_rotmat_transposed_inversed, data->plane_tx[i]);
|
|
|
|
normalize_v3_v3(data->normal_tx[i], data->plane_tx[i]);
|
2011-11-14 03:54:23 +00:00
|
|
|
}
|
|
|
|
|
2015-01-03 12:05:16 +01:00
|
|
|
copy_v4_fl(data->dist_vals_sq, FLT_MAX);
|
|
|
|
data->tot = 0;
|
|
|
|
data->is_ortho = params->is_ortho;
|
|
|
|
if (params->is_ortho) {
|
|
|
|
/* we want (0, 0, -1) transformed by camera_rotmat, this is a quicker shortcut. */
|
|
|
|
negate_v3_v3(data->camera_no, data->camera_rotmat[2]);
|
|
|
|
data->dist_to_cam = FLT_MAX;
|
2011-11-14 03:54:23 +00:00
|
|
|
}
|
2015-01-03 12:05:16 +01:00
|
|
|
}
|
2011-11-14 03:54:23 +00:00
|
|
|
|
2015-01-03 12:05:16 +01:00
|
|
|
static bool camera_frame_fit_calc_from_data(
|
|
|
|
CameraParams *params, CameraViewFrameData *data, float r_co[3], float *r_scale)
|
|
|
|
{
|
2015-09-04 22:04:54 +10:00
|
|
|
float plane_tx[CAMERA_VIEWFRAME_NUM_PLANES][4];
|
2015-01-03 12:05:16 +01:00
|
|
|
unsigned int i;
|
2011-11-14 03:54:23 +00:00
|
|
|
|
2015-01-03 12:05:16 +01:00
|
|
|
if (data->tot <= 1) {
|
2013-12-29 12:51:27 +11:00
|
|
|
return false;
|
2011-11-14 03:54:23 +00:00
|
|
|
}
|
2015-01-03 12:05:16 +01:00
|
|
|
|
|
|
|
if (params->is_ortho) {
|
|
|
|
const float *cam_axis_x = data->camera_rotmat[0];
|
|
|
|
const float *cam_axis_y = data->camera_rotmat[1];
|
|
|
|
const float *cam_axis_z = data->camera_rotmat[2];
|
|
|
|
float dists[CAMERA_VIEWFRAME_NUM_PLANES];
|
|
|
|
float scale_diff;
|
|
|
|
|
|
|
|
/* apply the dist-from-plane's to the transformed plane points */
|
|
|
|
for (i = 0; i < CAMERA_VIEWFRAME_NUM_PLANES; i++) {
|
|
|
|
dists[i] = sqrtf_signed(data->dist_vals_sq[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((dists[0] + dists[2]) > (dists[1] + dists[3])) {
|
|
|
|
scale_diff = (dists[1] + dists[3]) *
|
|
|
|
(BLI_rctf_size_x(¶ms->viewplane) / BLI_rctf_size_y(¶ms->viewplane));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
scale_diff = (dists[0] + dists[2]) *
|
|
|
|
(BLI_rctf_size_y(¶ms->viewplane) / BLI_rctf_size_x(¶ms->viewplane));
|
|
|
|
}
|
|
|
|
*r_scale = params->ortho_scale - scale_diff;
|
|
|
|
|
|
|
|
zero_v3(r_co);
|
|
|
|
madd_v3_v3fl(r_co, cam_axis_x, (dists[2] - dists[0]) * 0.5f + params->shiftx * scale_diff);
|
|
|
|
madd_v3_v3fl(r_co, cam_axis_y, (dists[1] - dists[3]) * 0.5f + params->shifty * scale_diff);
|
|
|
|
madd_v3_v3fl(r_co, cam_axis_z, -(data->dist_to_cam - 1.0f - params->clipsta));
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2011-11-14 03:54:23 +00:00
|
|
|
else {
|
2011-11-14 08:43:09 +00:00
|
|
|
float plane_isect_1[3], plane_isect_1_no[3], plane_isect_1_other[3];
|
|
|
|
float plane_isect_2[3], plane_isect_2_no[3], plane_isect_2_other[3];
|
2011-11-14 03:54:23 +00:00
|
|
|
|
|
|
|
float plane_isect_pt_1[3], plane_isect_pt_2[3];
|
|
|
|
|
|
|
|
/* apply the dist-from-plane's to the transformed plane points */
|
2015-01-03 12:05:16 +01:00
|
|
|
for (i = 0; i < CAMERA_VIEWFRAME_NUM_PLANES; i++) {
|
2015-09-04 22:04:54 +10:00
|
|
|
float co[3];
|
|
|
|
mul_v3_v3fl(co, data->normal_tx[i], sqrtf_signed(data->dist_vals_sq[i]));
|
|
|
|
plane_from_point_normal_v3(plane_tx[i], co, data->normal_tx[i]);
|
2011-11-14 03:54:23 +00:00
|
|
|
}
|
|
|
|
|
2015-09-04 22:04:54 +10:00
|
|
|
if ((!isect_plane_plane_v3(plane_tx[0], plane_tx[2], plane_isect_1, plane_isect_1_no)) ||
|
|
|
|
(!isect_plane_plane_v3(plane_tx[1], plane_tx[3], plane_isect_2, plane_isect_2_no)))
|
2013-12-29 12:51:27 +11:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2011-11-20 05:56:21 +00:00
|
|
|
|
|
|
|
add_v3_v3v3(plane_isect_1_other, plane_isect_1, plane_isect_1_no);
|
|
|
|
add_v3_v3v3(plane_isect_2_other, plane_isect_2, plane_isect_2_no);
|
|
|
|
|
|
|
|
if (isect_line_line_v3(plane_isect_1, plane_isect_1_other,
|
|
|
|
plane_isect_2, plane_isect_2_other,
|
2015-01-03 12:05:16 +01:00
|
|
|
plane_isect_pt_1, plane_isect_pt_2) != 0)
|
2011-11-14 03:54:23 +00:00
|
|
|
{
|
2015-01-03 12:05:16 +01:00
|
|
|
float cam_plane_no[3];
|
2011-11-20 05:56:21 +00:00
|
|
|
float plane_isect_delta[3];
|
|
|
|
float plane_isect_delta_len;
|
2011-11-14 03:54:23 +00:00
|
|
|
|
2015-01-03 12:05:16 +01:00
|
|
|
float shift_fac = BKE_camera_sensor_size(params->sensor_fit, params->sensor_x, params->sensor_y) /
|
|
|
|
params->lens;
|
|
|
|
|
|
|
|
/* we want (0, 0, -1) transformed by camera_rotmat, this is a quicker shortcut. */
|
|
|
|
negate_v3_v3(cam_plane_no, data->camera_rotmat[2]);
|
2011-11-14 03:54:23 +00:00
|
|
|
|
2011-11-20 05:56:21 +00:00
|
|
|
sub_v3_v3v3(plane_isect_delta, plane_isect_pt_2, plane_isect_pt_1);
|
2012-05-06 15:15:33 +00:00
|
|
|
plane_isect_delta_len = len_v3(plane_isect_delta);
|
2011-11-14 08:43:09 +00:00
|
|
|
|
2011-11-20 05:56:21 +00:00
|
|
|
if (dot_v3v3(plane_isect_delta, cam_plane_no) > 0.0f) {
|
|
|
|
copy_v3_v3(r_co, plane_isect_pt_1);
|
2011-11-14 08:43:09 +00:00
|
|
|
|
2011-11-20 05:56:21 +00:00
|
|
|
/* offset shift */
|
|
|
|
normalize_v3(plane_isect_1_no);
|
2015-01-03 12:05:16 +01:00
|
|
|
madd_v3_v3fl(r_co, plane_isect_1_no, params->shifty * plane_isect_delta_len * shift_fac);
|
2011-11-20 05:56:21 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
copy_v3_v3(r_co, plane_isect_pt_2);
|
2011-11-14 08:43:09 +00:00
|
|
|
|
2011-11-20 05:56:21 +00:00
|
|
|
/* offset shift */
|
|
|
|
normalize_v3(plane_isect_2_no);
|
2015-01-03 12:05:16 +01:00
|
|
|
madd_v3_v3fl(r_co, plane_isect_2_no, params->shiftx * plane_isect_delta_len * shift_fac);
|
2011-11-20 05:56:21 +00:00
|
|
|
}
|
2011-11-14 08:43:09 +00:00
|
|
|
|
2013-12-29 12:51:27 +11:00
|
|
|
return true;
|
2011-11-14 03:54:23 +00:00
|
|
|
}
|
|
|
|
}
|
2015-01-03 12:05:16 +01:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* don't move the camera, just yield the fit location */
|
|
|
|
/* r_scale only valid/useful for ortho cameras */
|
|
|
|
bool BKE_camera_view_frame_fit_to_scene(
|
2018-06-22 07:54:55 +02:00
|
|
|
Depsgraph *depsgraph, Scene *scene, Object *camera_ob, float r_co[3], float *r_scale)
|
2015-01-03 12:05:16 +01:00
|
|
|
{
|
|
|
|
CameraParams params;
|
|
|
|
CameraViewFrameData data_cb;
|
|
|
|
|
|
|
|
/* just in case */
|
|
|
|
*r_scale = 1.0f;
|
|
|
|
|
|
|
|
camera_frame_fit_data_init(scene, camera_ob, ¶ms, &data_cb);
|
|
|
|
|
|
|
|
/* run callback on all visible points */
|
2018-06-22 07:54:55 +02:00
|
|
|
BKE_scene_foreach_display_point(depsgraph, camera_to_frame_view_cb, &data_cb);
|
2015-01-03 12:05:16 +01:00
|
|
|
|
|
|
|
return camera_frame_fit_calc_from_data(¶ms, &data_cb, r_co, r_scale);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool BKE_camera_view_frame_fit_to_coords(
|
2018-05-25 11:05:51 +02:00
|
|
|
const Depsgraph *depsgraph, const float (*cos)[3], int num_cos, Object *camera_ob,
|
2015-03-21 22:34:20 +11:00
|
|
|
float r_co[3], float *r_scale)
|
2015-01-03 12:05:16 +01:00
|
|
|
{
|
2018-05-25 11:05:51 +02:00
|
|
|
Scene *scene_eval = DEG_get_evaluated_scene(depsgraph);
|
|
|
|
Object *camera_ob_eval = DEG_get_evaluated_object(depsgraph, camera_ob);
|
2015-01-03 12:05:16 +01:00
|
|
|
CameraParams params;
|
|
|
|
CameraViewFrameData data_cb;
|
|
|
|
|
|
|
|
/* just in case */
|
|
|
|
*r_scale = 1.0f;
|
|
|
|
|
2018-05-25 11:05:51 +02:00
|
|
|
camera_frame_fit_data_init(scene_eval, camera_ob_eval, ¶ms, &data_cb);
|
2015-01-03 12:05:16 +01:00
|
|
|
|
|
|
|
/* run callback on all given coordinates */
|
|
|
|
while (num_cos--) {
|
|
|
|
camera_to_frame_view_cb(cos[num_cos], &data_cb);
|
|
|
|
}
|
|
|
|
|
|
|
|
return camera_frame_fit_calc_from_data(¶ms, &data_cb, r_co, r_scale);
|
2011-11-14 03:54:23 +00:00
|
|
|
}
|
2015-01-03 12:05:16 +01:00
|
|
|
|
2015-04-06 10:40:12 -03:00
|
|
|
/******************* multiview matrix functions ***********************/
|
|
|
|
|
2018-05-25 11:05:51 +02:00
|
|
|
static void camera_model_matrix(const Object *camera, float r_modelmat[4][4])
|
2015-04-06 10:40:12 -03:00
|
|
|
{
|
|
|
|
copy_m4_m4(r_modelmat, camera->obmat);
|
|
|
|
}
|
|
|
|
|
2018-05-25 11:05:51 +02:00
|
|
|
static void camera_stereo3d_model_matrix(const Object *camera, const bool is_left, float r_modelmat[4][4])
|
2015-04-06 10:40:12 -03:00
|
|
|
{
|
|
|
|
Camera *data = (Camera *)camera->data;
|
|
|
|
float interocular_distance, convergence_distance;
|
|
|
|
short convergence_mode, pivot;
|
|
|
|
float sizemat[4][4];
|
|
|
|
|
|
|
|
float fac = 1.0f;
|
|
|
|
float fac_signed;
|
|
|
|
|
|
|
|
interocular_distance = data->stereo.interocular_distance;
|
|
|
|
convergence_distance = data->stereo.convergence_distance;
|
|
|
|
convergence_mode = data->stereo.convergence_mode;
|
|
|
|
pivot = data->stereo.pivot;
|
|
|
|
|
|
|
|
if (((pivot == CAM_S3D_PIVOT_LEFT) && is_left) ||
|
|
|
|
((pivot == CAM_S3D_PIVOT_RIGHT) && !is_left))
|
|
|
|
{
|
2015-04-19 22:03:42 +10:00
|
|
|
camera_model_matrix(camera, r_modelmat);
|
|
|
|
return;
|
2015-04-06 10:40:12 -03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
float size[3];
|
|
|
|
mat4_to_size(size, camera->obmat);
|
|
|
|
size_to_mat4(sizemat, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pivot == CAM_S3D_PIVOT_CENTER)
|
|
|
|
fac = 0.5f;
|
|
|
|
|
|
|
|
fac_signed = is_left ? fac : -fac;
|
|
|
|
|
|
|
|
/* rotation */
|
|
|
|
if (convergence_mode == CAM_S3D_TOE) {
|
|
|
|
float angle;
|
|
|
|
float angle_sin, angle_cos;
|
|
|
|
float toeinmat[4][4];
|
|
|
|
float rotmat[4][4];
|
|
|
|
|
|
|
|
unit_m4(rotmat);
|
|
|
|
|
|
|
|
if (pivot == CAM_S3D_PIVOT_CENTER) {
|
|
|
|
fac = -fac;
|
|
|
|
fac_signed = -fac_signed;
|
|
|
|
}
|
|
|
|
|
|
|
|
angle = atanf((interocular_distance * 0.5f) / convergence_distance) / fac;
|
|
|
|
|
|
|
|
angle_cos = cosf(angle * fac_signed);
|
|
|
|
angle_sin = sinf(angle * fac_signed);
|
|
|
|
|
|
|
|
rotmat[0][0] = angle_cos;
|
|
|
|
rotmat[2][0] = -angle_sin;
|
|
|
|
rotmat[0][2] = angle_sin;
|
|
|
|
rotmat[2][2] = angle_cos;
|
|
|
|
|
|
|
|
if (pivot == CAM_S3D_PIVOT_CENTER) {
|
|
|
|
/* set the rotation */
|
|
|
|
copy_m4_m4(toeinmat, rotmat);
|
|
|
|
/* set the translation */
|
|
|
|
toeinmat[3][0] = interocular_distance * fac_signed;
|
|
|
|
|
|
|
|
/* transform */
|
|
|
|
normalize_m4_m4(r_modelmat, camera->obmat);
|
|
|
|
mul_m4_m4m4(r_modelmat, r_modelmat, toeinmat);
|
|
|
|
|
|
|
|
/* scale back to the original size */
|
|
|
|
mul_m4_m4m4(r_modelmat, r_modelmat, sizemat);
|
|
|
|
}
|
|
|
|
else { /* CAM_S3D_PIVOT_LEFT, CAM_S3D_PIVOT_RIGHT */
|
|
|
|
/* rotate perpendicular to the interocular line */
|
|
|
|
normalize_m4_m4(r_modelmat, camera->obmat);
|
|
|
|
mul_m4_m4m4(r_modelmat, r_modelmat, rotmat);
|
|
|
|
|
|
|
|
/* translate along the interocular line */
|
|
|
|
unit_m4(toeinmat);
|
|
|
|
toeinmat[3][0] = -interocular_distance * fac_signed;
|
|
|
|
mul_m4_m4m4(r_modelmat, r_modelmat, toeinmat);
|
|
|
|
|
|
|
|
/* rotate to toe-in angle */
|
|
|
|
mul_m4_m4m4(r_modelmat, r_modelmat, rotmat);
|
|
|
|
|
|
|
|
/* scale back to the original size */
|
|
|
|
mul_m4_m4m4(r_modelmat, r_modelmat, sizemat);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
normalize_m4_m4(r_modelmat, camera->obmat);
|
|
|
|
|
|
|
|
/* translate - no rotation in CAM_S3D_OFFAXIS, CAM_S3D_PARALLEL */
|
|
|
|
translate_m4(r_modelmat, -interocular_distance * fac_signed, 0.0f, 0.0f);
|
|
|
|
|
|
|
|
/* scale back to the original size */
|
|
|
|
mul_m4_m4m4(r_modelmat, r_modelmat, sizemat);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* the view matrix is used by the viewport drawing, it is basically the inverted model matrix */
|
2018-05-25 11:05:51 +02:00
|
|
|
void BKE_camera_multiview_view_matrix(RenderData *rd, const Object *camera, const bool is_left, float r_viewmat[4][4])
|
2015-04-06 10:40:12 -03:00
|
|
|
{
|
|
|
|
BKE_camera_multiview_model_matrix(rd, camera, is_left ? STEREO_LEFT_NAME : STEREO_RIGHT_NAME, r_viewmat);
|
|
|
|
invert_m4(r_viewmat);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* left is the default */
|
|
|
|
static bool camera_is_left(const char *viewname)
|
|
|
|
{
|
|
|
|
if (viewname && viewname[0] != '\0') {
|
|
|
|
return !STREQ(viewname, STEREO_RIGHT_NAME);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-05-25 11:05:51 +02:00
|
|
|
void BKE_camera_multiview_model_matrix(RenderData *rd, const Object *camera, const char *viewname, float r_modelmat[4][4])
|
2019-01-11 18:58:09 -02:00
|
|
|
{
|
|
|
|
BKE_camera_multiview_model_matrix_scaled(rd, camera, viewname, r_modelmat);
|
|
|
|
normalize_m4(r_modelmat);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BKE_camera_multiview_model_matrix_scaled(RenderData *rd, const Object *camera, const char *viewname, float r_modelmat[4][4])
|
2015-04-06 10:40:12 -03:00
|
|
|
{
|
|
|
|
const bool is_multiview = (rd && rd->scemode & R_MULTIVIEW) != 0;
|
|
|
|
|
|
|
|
if (!is_multiview) {
|
|
|
|
camera_model_matrix(camera, r_modelmat);
|
|
|
|
}
|
|
|
|
else if (rd->views_format == SCE_VIEWS_FORMAT_MULTIVIEW) {
|
|
|
|
camera_model_matrix(camera, r_modelmat);
|
|
|
|
}
|
|
|
|
else { /* SCE_VIEWS_SETUP_BASIC */
|
|
|
|
const bool is_left = camera_is_left(viewname);
|
|
|
|
camera_stereo3d_model_matrix(camera, is_left, r_modelmat);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-11 13:38:18 -02:00
|
|
|
void BKE_camera_multiview_window_matrix(RenderData *rd, const Object *camera, const char *viewname, float r_winmat[4][4])
|
|
|
|
{
|
|
|
|
CameraParams params;
|
|
|
|
|
|
|
|
/* Setup parameters */
|
|
|
|
BKE_camera_params_init(¶ms);
|
|
|
|
BKE_camera_params_from_object(¶ms, camera);
|
|
|
|
BKE_camera_multiview_params(rd, ¶ms, camera, viewname);
|
|
|
|
|
|
|
|
/* Compute matrix, viewplane, .. */
|
|
|
|
BKE_camera_params_compute_viewplane(¶ms, rd->xsch, rd->ysch, rd->xasp, rd->yasp);
|
|
|
|
BKE_camera_params_compute_matrix(¶ms);
|
|
|
|
|
|
|
|
copy_m4_m4(r_winmat, params.winmat);
|
|
|
|
}
|
|
|
|
|
2018-05-25 11:05:51 +02:00
|
|
|
bool BKE_camera_multiview_spherical_stereo(RenderData *rd, const Object *camera)
|
Multi-View: Cycles - Spherical Stereo support (VR Panoramas)
This is a new option for panorama cameras to render
stereo that can be used in virtual reality devices
The option is available under the camera panel when Multi-View is enabled (Views option in the Render Layers panel)
Known limitations:
------------------
* Parallel convergence is not supported (you need to set a convergence distance really high to simulate this effect).
* Pivot was not supposed to affect the render but it does, this has to be looked at, but for now set it to CENTER
* Derivatives in perspective camera need to be pre-computed or we shuld get rid of kcam->dx/dy (Sergey words, I don't fully grasp the implication shere)
* This works in perspective mode and in panorama mode. However, for fully benefit from this effect in perspective mode you need to render a cube map. (there is an addon for this, developed separately, perhaps we could include it in master).
* We have no support for "neck distance" at the moment. This is supposed to help with objects at short distances.
* We have no support to rotate the "Up Axis" of the stereo plane. Meaning, we hardcode 0,0,1 as UP, and create the stereo pair related to that. (although we could take the camera local UP when rendering panoramas, this wouldn't work for perspective cameras.
* We have no support for interocular distance attenuation based on the proximity of the poles (which helps to reduce the pole rotation effect/artifact).
THIS NEEDS DOCS - both in 2.78 release log and the Blender manual.
Meanwhile you can read about it here: http://code.blender.org/2015/03/1451
This patch specifically dates from March 2015, as you can see in the code.blender.org post. Many thanks to all the reviewers, testers and minor sponsors who helped me maintain spherical-stereo for 1 year.
All that said, have fun with this. This feature was what got me started with Multi-View development (at the time what I was looking for was Fulldome stereo support, but the implementation is the same). In order to make this into Blender I had to make it aiming at a less-specic user-case Thus Multi-View started. (this was December 2012, during Siggraph Asia and a chat I had with Paul Bourke during the conference). I don't have the original patch anymore, but you can find a re-based version of it from March 2013, right before I start with the Multi-View project https://developer.blender.org/P332
Reviewers: sergey, dingto
Subscribers: #cycles
Differential Revision: https://developer.blender.org/D1223
2016-03-10 09:28:29 -03:00
|
|
|
{
|
|
|
|
Camera *cam;
|
|
|
|
const bool is_multiview = (rd && rd->scemode & R_MULTIVIEW) != 0;
|
|
|
|
|
|
|
|
if (!is_multiview)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (camera->type != OB_CAMERA)
|
|
|
|
return false;
|
|
|
|
else
|
|
|
|
cam = camera->data;
|
|
|
|
|
|
|
|
if ((rd->views_format == SCE_VIEWS_FORMAT_STEREO_3D) &&
|
|
|
|
ELEM(cam->type, CAM_PANO, CAM_PERSP) &&
|
|
|
|
((cam->stereo.flag & CAM_S3D_SPHERICAL) != 0))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-04-06 10:40:12 -03:00
|
|
|
static Object *camera_multiview_advanced(Scene *scene, Object *camera, const char *suffix)
|
|
|
|
{
|
|
|
|
SceneRenderView *srv;
|
|
|
|
char name[MAX_NAME];
|
|
|
|
const char *camera_name = camera->id.name + 2;
|
|
|
|
const int len_name = strlen(camera_name);
|
2015-08-19 03:37:58 -03:00
|
|
|
int len_suffix_max = -1;
|
2015-04-06 10:40:12 -03:00
|
|
|
|
|
|
|
name[0] = '\0';
|
|
|
|
|
2015-08-19 03:37:58 -03:00
|
|
|
/* we need to take the better match, thus the len_suffix_max test */
|
2015-04-06 10:40:12 -03:00
|
|
|
for (srv = scene->r.views.first; srv; srv = srv->next) {
|
|
|
|
const int len_suffix = strlen(srv->suffix);
|
|
|
|
|
2015-08-19 03:37:58 -03:00
|
|
|
if ((len_suffix < len_suffix_max) || (len_name < len_suffix))
|
2015-04-06 10:40:12 -03:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if (STREQ(camera_name + (len_name - len_suffix), srv->suffix)) {
|
|
|
|
BLI_snprintf(name, sizeof(name), "%.*s%s", (len_name - len_suffix), camera_name, suffix);
|
2015-08-19 03:37:58 -03:00
|
|
|
len_suffix_max = len_suffix;
|
2015-04-06 10:40:12 -03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (name[0] != '\0') {
|
2017-11-08 12:16:49 -02:00
|
|
|
Object *ob = BKE_scene_object_find_by_name(scene, name);
|
|
|
|
if (ob != NULL) {
|
|
|
|
return ob;
|
2015-04-06 10:40:12 -03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return camera;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* returns the camera to be used for render */
|
|
|
|
Object *BKE_camera_multiview_render(Scene *scene, Object *camera, const char *viewname)
|
|
|
|
{
|
2016-05-06 21:41:56 +02:00
|
|
|
const bool is_multiview = (camera != NULL) && (scene->r.scemode & R_MULTIVIEW) != 0;
|
2015-04-06 10:40:12 -03:00
|
|
|
|
|
|
|
if (!is_multiview) {
|
|
|
|
return camera;
|
|
|
|
}
|
|
|
|
else if (scene->r.views_format == SCE_VIEWS_FORMAT_STEREO_3D) {
|
|
|
|
return camera;
|
|
|
|
}
|
|
|
|
else { /* SCE_VIEWS_FORMAT_MULTIVIEW */
|
|
|
|
const char *suffix = BKE_scene_multiview_view_suffix_get(&scene->r, viewname);
|
|
|
|
return camera_multiview_advanced(scene, camera, suffix);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-25 11:05:51 +02:00
|
|
|
static float camera_stereo3d_shift_x(const Object *camera, const char *viewname)
|
2015-04-06 10:40:12 -03:00
|
|
|
{
|
|
|
|
Camera *data = camera->data;
|
|
|
|
float shift = data->shiftx;
|
|
|
|
float interocular_distance, convergence_distance;
|
|
|
|
short convergence_mode, pivot;
|
|
|
|
bool is_left = true;
|
|
|
|
|
|
|
|
float fac = 1.0f;
|
|
|
|
float fac_signed;
|
|
|
|
|
|
|
|
if (viewname && viewname[0]) {
|
|
|
|
is_left = STREQ(viewname, STEREO_LEFT_NAME);
|
|
|
|
}
|
|
|
|
|
|
|
|
interocular_distance = data->stereo.interocular_distance;
|
|
|
|
convergence_distance = data->stereo.convergence_distance;
|
|
|
|
convergence_mode = data->stereo.convergence_mode;
|
|
|
|
pivot = data->stereo.pivot;
|
|
|
|
|
2015-06-29 10:24:25 -03:00
|
|
|
if (convergence_mode != CAM_S3D_OFFAXIS)
|
|
|
|
return shift;
|
|
|
|
|
2015-04-06 10:40:12 -03:00
|
|
|
if (((pivot == CAM_S3D_PIVOT_LEFT) && is_left) ||
|
|
|
|
((pivot == CAM_S3D_PIVOT_RIGHT) && !is_left))
|
|
|
|
{
|
|
|
|
return shift;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pivot == CAM_S3D_PIVOT_CENTER)
|
|
|
|
fac = 0.5f;
|
|
|
|
|
|
|
|
fac_signed = is_left ? fac : -fac;
|
2015-06-29 10:24:25 -03:00
|
|
|
shift += ((interocular_distance / data->sensor_x) * (data->lens / convergence_distance)) * fac_signed;
|
2015-04-06 10:40:12 -03:00
|
|
|
|
|
|
|
return shift;
|
|
|
|
}
|
|
|
|
|
2018-05-25 11:05:51 +02:00
|
|
|
float BKE_camera_multiview_shift_x(RenderData *rd, const Object *camera, const char *viewname)
|
2015-04-06 10:40:12 -03:00
|
|
|
{
|
|
|
|
const bool is_multiview = (rd && rd->scemode & R_MULTIVIEW) != 0;
|
|
|
|
Camera *data = camera->data;
|
|
|
|
|
2015-04-14 00:59:28 +10:00
|
|
|
BLI_assert(camera->type == OB_CAMERA);
|
|
|
|
|
2015-04-06 10:40:12 -03:00
|
|
|
if (!is_multiview) {
|
|
|
|
return data->shiftx;
|
|
|
|
}
|
|
|
|
else if (rd->views_format == SCE_VIEWS_FORMAT_MULTIVIEW) {
|
|
|
|
return data->shiftx;
|
|
|
|
}
|
|
|
|
else { /* SCE_VIEWS_SETUP_BASIC */
|
|
|
|
return camera_stereo3d_shift_x(camera, viewname);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-25 11:05:51 +02:00
|
|
|
void BKE_camera_multiview_params(RenderData *rd, CameraParams *params, const Object *camera, const char *viewname)
|
2015-04-06 10:40:12 -03:00
|
|
|
{
|
2015-04-14 00:59:28 +10:00
|
|
|
if (camera->type == OB_CAMERA) {
|
|
|
|
params->shiftx = BKE_camera_multiview_shift_x(rd, camera, viewname);
|
|
|
|
}
|
2015-04-06 10:40:12 -03:00
|
|
|
}
|
|
|
|
|
2015-02-12 18:54:41 +01:00
|
|
|
void BKE_camera_to_gpu_dof(struct Object *camera, struct GPUFXSettings *r_fx_settings)
|
|
|
|
{
|
|
|
|
if (camera->type == OB_CAMERA) {
|
|
|
|
Camera *cam = camera->data;
|
|
|
|
r_fx_settings->dof = &cam->gpu_dof;
|
|
|
|
r_fx_settings->dof->focal_length = cam->lens;
|
|
|
|
r_fx_settings->dof->sensor = BKE_camera_sensor_size(cam->sensor_fit, cam->sensor_x, cam->sensor_y);
|
2015-09-07 02:32:34 +10:00
|
|
|
r_fx_settings->dof->focus_distance = BKE_camera_object_dof_distance(camera);
|
2015-02-12 18:54:41 +01:00
|
|
|
}
|
|
|
|
}
|
2017-10-26 21:40:37 +11:00
|
|
|
|
|
|
|
CameraBGImage *BKE_camera_background_image_new(Camera *cam)
|
|
|
|
{
|
|
|
|
CameraBGImage *bgpic = MEM_callocN(sizeof(CameraBGImage), "Background Image");
|
|
|
|
|
|
|
|
bgpic->scale = 1.0f;
|
|
|
|
bgpic->alpha = 0.5f;
|
|
|
|
bgpic->iuser.ok = 1;
|
2018-05-24 21:19:38 +02:00
|
|
|
bgpic->iuser.flag |= IMA_ANIM_ALWAYS;
|
2017-10-26 21:40:37 +11:00
|
|
|
bgpic->flag |= CAM_BGIMG_FLAG_EXPANDED;
|
|
|
|
|
|
|
|
BLI_addtail(&cam->bg_images, bgpic);
|
|
|
|
|
|
|
|
return bgpic;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BKE_camera_background_image_remove(Camera *cam, CameraBGImage *bgpic)
|
|
|
|
{
|
|
|
|
BLI_remlink(&cam->bg_images, bgpic);
|
|
|
|
|
|
|
|
MEM_freeN(bgpic);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BKE_camera_background_image_clear(Camera *cam)
|
|
|
|
{
|
|
|
|
CameraBGImage *bgpic = cam->bg_images.first;
|
|
|
|
|
|
|
|
while (bgpic) {
|
|
|
|
CameraBGImage *next_bgpic = bgpic->next;
|
|
|
|
|
|
|
|
BKE_camera_background_image_remove(cam, bgpic);
|
|
|
|
|
|
|
|
bgpic = next_bgpic;
|
|
|
|
}
|
2017-11-08 12:16:49 -02:00
|
|
|
}
|