Blender V5.0
camera_delegate.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2025 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#include "camera_delegate.hh"
6
7#include "DNA_ID.h"
8#include "DNA_camera_types.h"
9#include "DNA_scene_types.h"
10
11#include "BKE_idprop.hh"
12
13#include <pxr/imaging/hd/camera.h>
14
16
17static pxr::VtValue vt_value(const IDProperty *prop)
18{
19 switch (prop->type) {
20 case IDP_INT:
21 return pxr::VtValue{IDP_int_get(prop)};
22 case IDP_FLOAT:
23 return pxr::VtValue{IDP_float_get(prop)};
24 case IDP_DOUBLE:
25 return pxr::VtValue{IDP_double_get(prop)};
26 case IDP_BOOLEAN:
27 return pxr::VtValue{bool(IDP_bool_get(prop))};
28 }
29 return pxr::VtValue{};
30}
31
32CameraDelegate::CameraDelegate(pxr::HdRenderIndex *render_index, pxr::SdfPath const &delegate_id)
33 : pxr::HdxFreeCameraSceneDelegate{render_index, delegate_id}
34{
35}
36
37void CameraDelegate::sync(const Scene *scene)
38{
39 if (!scene || !scene->camera) {
40 return;
41 }
42
43 const Camera *camera = static_cast<const Camera *>(scene->camera->data);
44 if (camera_ == camera) {
45 return;
46 }
47
48 camera_ = camera;
49 GetRenderIndex().GetChangeTracker().MarkSprimDirty(GetCameraId(), pxr::HdCamera::DirtyParams);
50}
51
52void CameraDelegate::update(const ID *camera)
53{
54 if (&camera_->id == camera) {
55 GetRenderIndex().GetChangeTracker().MarkSprimDirty(GetCameraId(), pxr::HdCamera::DirtyParams);
56 }
57}
58
59pxr::VtValue CameraDelegate::GetCameraParamValue(pxr::SdfPath const &id, pxr::TfToken const &key)
60{
61 if (camera_ && camera_->id.properties) {
62 const IDProperty *prop = IDP_GetPropertyFromGroup(camera_->id.properties, key.GetText());
63 if (prop) {
64 return vt_value(prop);
65 }
66 }
67 return pxr::HdxFreeCameraSceneDelegate::GetCameraParamValue(id, key);
68}
69
70} // namespace blender::io::hydra
#define IDP_float_get(prop)
IDProperty * IDP_GetPropertyFromGroup(const IDProperty *prop, blender::StringRef name) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition idprop.cc:747
#define IDP_int_get(prop)
#define IDP_double_get(prop)
#define IDP_bool_get(prop)
ID and Library types, which are fundamental for SDNA.
@ IDP_DOUBLE
@ IDP_FLOAT
@ IDP_BOOLEAN
@ IDP_INT
CameraDelegate(pxr::HdRenderIndex *render_index, pxr::SdfPath const &delegate_id)
pxr::VtValue GetCameraParamValue(pxr::SdfPath const &id, pxr::TfToken const &key) override
static pxr::VtValue vt_value(const IDProperty *prop)
char type
Definition DNA_ID.h:156
Definition DNA_ID.h:414
struct Object * camera