Blender V4.3
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
6
7#include "curves.hh"
9#include "light.hh"
10#include "mesh.hh"
11#include "object.hh"
12#include "volume.hh"
13
14namespace blender::io::hydra {
15
17 const Object *object,
18 pxr::SdfPath const &prim_id)
19 : IdData(scene_delegate, &object->id, prim_id), transform(pxr::GfMatrix4d(1.0))
20{
21}
22
23std::unique_ptr<ObjectData> ObjectData::create(HydraSceneDelegate *scene_delegate,
24 const Object *object,
25 pxr::SdfPath const &prim_id)
26{
27 std::unique_ptr<ObjectData> obj_data;
28 switch (object->type) {
29 case OB_MESH:
30 case OB_SURF:
31 case OB_FONT:
33 case OB_MBALL:
35 obj_data = std::make_unique<VolumeModifierData>(scene_delegate, object, prim_id);
36 break;
37 }
38 obj_data = std::make_unique<MeshData>(scene_delegate, object, prim_id);
39 break;
40 case OB_CURVES:
41 obj_data = std::make_unique<CurvesData>(scene_delegate, object, prim_id);
42 break;
43 case OB_LAMP:
44 obj_data = std::make_unique<LightData>(scene_delegate, object, prim_id);
45 break;
46 case OB_VOLUME:
47 obj_data = std::make_unique<VolumeData>(scene_delegate, object, prim_id);
48 break;
49 default:
51 break;
52 }
53 obj_data->init();
54 return obj_data;
55}
56
58{
59 switch (object->type) {
60 case OB_MESH:
61 case OB_SURF:
62 case OB_FONT:
63 case OB_CURVES:
65 case OB_MBALL:
66 case OB_LAMP:
67 case OB_VOLUME:
68 return true;
69
70 default:
71 break;
72 }
73 return false;
74}
75
76bool ObjectData::is_mesh(const Object *object)
77{
78 switch (object->type) {
79 case OB_MESH:
80 case OB_SURF:
81 case OB_FONT:
83 case OB_MBALL:
85 return false;
86 }
87 return true;
88 default:
89 break;
90 }
91 return false;
92}
93
94bool ObjectData::is_visible(HydraSceneDelegate *scene_delegate, const Object *object, int mode)
95{
96 eEvaluationMode deg_mode = DEG_get_mode(scene_delegate->depsgraph);
97 bool ret = BKE_object_visibility(object, deg_mode) & mode;
98 if (deg_mode == DAG_EVAL_VIEWPORT) {
99 ret &= BKE_object_is_visible_in_viewport(scene_delegate->view3d, object);
100 }
101 /* NOTE: visibility for final render we are taking from depsgraph */
102 return ret;
103}
104
105pxr::VtValue ObjectData::get_data(pxr::SdfPath const & /*id*/, pxr::TfToken const &key) const
106{
107 return get_data(key);
108}
109
110pxr::SdfPath ObjectData::material_id() const
111{
112 return pxr::SdfPath();
113}
114
115pxr::SdfPath ObjectData::material_id(pxr::SdfPath const & /*id*/) const
116{
117 return material_id();
118}
119
121
123{
124 transform = gf_matrix_from_transform(((const Object *)id)->object_to_world().ptr());
125}
126
128
130{
131 if (!mat) {
132 return nullptr;
133 }
134
135 pxr::SdfPath p_id = scene_delegate_->material_prim_id(mat);
136 MaterialData *mat_data = scene_delegate_->material_data(p_id);
137 if (!mat_data) {
138 scene_delegate_->materials_.add_new(
139 p_id, std::make_unique<MaterialData>(scene_delegate_, mat, p_id));
140 mat_data = scene_delegate_->material_data(p_id);
141 mat_data->init();
142 mat_data->insert();
143 }
144 return mat_data;
145}
146
147pxr::GfMatrix4d gf_matrix_from_transform(const float m[4][4])
148{
149 pxr::GfMatrix4d ret;
150 for (int i = 0; i < 4; i++) {
151 for (int j = 0; j < 4; j++) {
152 ret[i][j] = m[i][j];
153 }
154 }
155 return ret;
156}
157
158} // 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:97
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
void add_new(const Key &key, const Value &value)
Definition BLI_map.hh:241
pxr::SdfPath prim_id
Definition id.hh:36
HydraSceneDelegate * scene_delegate_
Definition id.hh:39
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
PointerRNA * ptr
Definition wm_files.cc:4126