Blender V5.0
io/usd/hydra/object.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2011-2022 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#include "BKE_layer.hh"
6
8
9#include "curves.hh"
11#include "light.hh"
12#include "mesh.hh"
13#include "object.hh"
14#include "volume.hh"
15#include "volume_modifier.hh"
16
17namespace blender::io::hydra {
18
20 const Object *object,
21 pxr::SdfPath const &prim_id)
22 : IdData(scene_delegate, (object) ? &object->id : nullptr, prim_id),
23 transform(pxr::GfMatrix4d(1.0))
24{
25}
26
27std::unique_ptr<ObjectData> ObjectData::create(HydraSceneDelegate *scene_delegate,
28 const Object *object,
29 pxr::SdfPath const &prim_id)
30{
31 std::unique_ptr<ObjectData> obj_data;
32 switch (object->type) {
33 case OB_MESH:
34 case OB_SURF:
35 case OB_FONT:
37 case OB_MBALL:
39 obj_data = std::make_unique<VolumeModifierData>(scene_delegate, object, prim_id);
40 break;
41 }
42 obj_data = std::make_unique<MeshData>(scene_delegate, object, prim_id);
43 break;
44 case OB_CURVES:
45 obj_data = std::make_unique<CurvesData>(scene_delegate, object, prim_id);
46 break;
47 case OB_LAMP:
48 obj_data = std::make_unique<LightData>(scene_delegate, object, prim_id);
49 break;
50 case OB_VOLUME:
51 obj_data = std::make_unique<VolumeData>(scene_delegate, object, prim_id);
52 break;
53 default:
55 break;
56 }
57 obj_data->init();
58 return obj_data;
59}
60
62{
63 switch (object->type) {
64 case OB_MESH:
65 case OB_SURF:
66 case OB_FONT:
67 case OB_CURVES:
69 case OB_MBALL:
70 case OB_LAMP:
71 case OB_VOLUME:
72 return true;
73
74 default:
75 break;
76 }
77 return false;
78}
79
80bool ObjectData::is_mesh(const Object *object)
81{
82 switch (object->type) {
83 case OB_MESH:
84 case OB_SURF:
85 case OB_FONT:
87 case OB_MBALL:
89 return false;
90 }
91 return true;
92 default:
93 break;
94 }
95 return false;
96}
97
98bool ObjectData::is_visible(HydraSceneDelegate *scene_delegate, const Object *object, int mode)
99{
100 eEvaluationMode deg_mode = DEG_get_mode(scene_delegate->depsgraph);
101 bool ret = BKE_object_visibility(object, deg_mode) & mode;
102 if (deg_mode == DAG_EVAL_VIEWPORT) {
103 ret &= BKE_object_is_visible_in_viewport(scene_delegate->view3d, object);
104 }
105 /* NOTE: visibility for final render we are taking from depsgraph */
106 return ret;
107}
108
109pxr::VtValue ObjectData::get_data(pxr::SdfPath const & /*id*/, pxr::TfToken const &key) const
110{
111 return get_data(key);
112}
113
114pxr::SdfPath ObjectData::material_id() const
115{
116 return pxr::SdfPath();
117}
118
119pxr::SdfPath ObjectData::material_id(pxr::SdfPath const & /*id*/) const
120{
121 return material_id();
122}
123
125
127{
128 transform = gf_matrix_from_transform(((const Object *)id)->object_to_world().ptr());
129}
130
132
134{
135 if (!mat) {
136 return nullptr;
137 }
138
139 pxr::SdfPath p_id = scene_delegate_->material_prim_id(mat);
140 MaterialData *mat_data = scene_delegate_->material_data(p_id);
141 if (!mat_data) {
142 scene_delegate_->materials_.add_new(
143 p_id, std::make_unique<MaterialData>(scene_delegate_, mat, p_id));
144 mat_data = scene_delegate_->material_data(p_id);
145 mat_data->init();
146 mat_data->insert();
147 }
148 return mat_data;
149}
150
151pxr::GfMatrix4d gf_matrix_from_transform(const float m[4][4])
152{
153 pxr::GfMatrix4d ret;
154 for (int i = 0; i < 4; i++) {
155 for (int j = 0; j < 4; j++) {
156 ret[i][j] = m[i][j];
157 }
158 }
159 return ret;
160}
161
162} // namespace blender::io::hydra
bool BKE_object_is_visible_in_viewport(const View3D *v3d, const Object *ob)
int BKE_object_visibility(const Object *ob, int dag_eval_mode)
#define BLI_assert_unreachable()
Definition BLI_assert.h:93
eEvaluationMode
@ DAG_EVAL_VIEWPORT
eEvaluationMode DEG_get_mode(const Depsgraph *graph)
@ OB_MBALL
@ OB_SURF
@ OB_FONT
@ OB_LAMP
@ OB_MESH
@ OB_VOLUME
@ OB_CURVES_LEGACY
@ OB_CURVES
IdData(HydraSceneDelegate *scene_delegate, const ID *id, pxr::SdfPath const &prim_id)
Definition id.cc:9
pxr::SdfPath prim_id
Definition id.hh:36
HydraSceneDelegate * scene_delegate_
Definition id.hh:39
pxr::GfMatrix4d transform
Definition object.hh:24
virtual void available_materials(Set< pxr::SdfPath > &paths) const
virtual pxr::SdfPath material_id() const
static bool is_mesh(const Object *object)
MaterialData * get_or_create_material(const Material *mat)
static bool is_visible(HydraSceneDelegate *scene_delegate, const Object *object, int mode=OB_VISIBLE_SELF)
static std::unique_ptr< ObjectData > create(HydraSceneDelegate *scene_delegate, const Object *object, pxr::SdfPath const &prim_id)
static bool is_supported(const Object *object)
virtual pxr::VtValue get_data(pxr::SdfPath const &id, pxr::TfToken const &key) const
ObjectData(HydraSceneDelegate *scene_delegate, const Object *object, pxr::SdfPath const &prim_id)
static bool is_volume_modifier(const Object *object)
pxr::GfMatrix4d gf_matrix_from_transform(const float m[4][4])
return ret
i
Definition text_draw.cc:230
PointerRNA * ptr
Definition wm_files.cc:4238