Code improvements and fixes #26

Merged
Bogdan Nagirniak merged 8 commits from code_improvements_fixes into hydra-render 2023-04-21 07:48:50 +02:00
16 changed files with 176 additions and 161 deletions
Showing only changes of commit e3e8db3ace - Show all commits

View File

@ -35,7 +35,7 @@ pxr::GfMatrix4d BlenderSceneDelegate::GetTransform(pxr::SdfPath const &id)
return obj_data->transform(); return obj_data->transform();
} }
if (id == WorldData::prim_id(this)) { if (id == world_prim_id()) {
return world_data_->transform(); return world_data_->transform();
} }
@ -71,7 +71,7 @@ pxr::VtValue BlenderSceneDelegate::GetLightParamValue(pxr::SdfPath const &id,
if (l_data) { if (l_data) {
return l_data->get_data(key); return l_data->get_data(key);
} }
if (id == WorldData::prim_id(this)) { if (id == world_prim_id()) {
return world_data_->get_data(key); return world_data_->get_data(key);
} }
return pxr::VtValue(); return pxr::VtValue();
@ -111,7 +111,7 @@ pxr::VtValue BlenderSceneDelegate::GetMaterialResource(pxr::SdfPath const &id)
bool BlenderSceneDelegate::GetVisible(pxr::SdfPath const &id) bool BlenderSceneDelegate::GetVisible(pxr::SdfPath const &id)
{ {
if (id == WorldData::prim_id(this)) { if (id == world_prim_id()) {
return true; return true;
} }
@ -187,7 +187,35 @@ void BlenderSceneDelegate::clear()
materials_.clear(); materials_.clear();
} }
ObjectData *BlenderSceneDelegate::object_data(pxr::SdfPath const &id) pxr::SdfPath BlenderSceneDelegate::prim_id(ID *id, const char *prefix) const
{
/* Making id of object in form like <prefix>_<pointer in 16 hex digits format> */
char str[32];
snprintf(str, 32, "%s_%016llx", prefix, (uint64_t)id);
return GetDelegateID().AppendElementString(str);
}
pxr::SdfPath BlenderSceneDelegate::object_prim_id(Object *object) const
{
return prim_id((ID *)object, "O");
}
pxr::SdfPath BlenderSceneDelegate::material_prim_id(Material *mat) const
{
return prim_id((ID *)mat, "M");
}
pxr::SdfPath BlenderSceneDelegate::instancer_prim_id(Object *object) const
{
return prim_id((ID *)object, "I");
}
pxr::SdfPath BlenderSceneDelegate::world_prim_id() const
{
return GetDelegateID().AppendElementString("World");
}
ObjectData *BlenderSceneDelegate::object_data(pxr::SdfPath const &id) const
{ {
auto it = objects_.find(id); auto it = objects_.find(id);
if (it != objects_.end()) { if (it != objects_.end()) {
@ -200,17 +228,17 @@ ObjectData *BlenderSceneDelegate::object_data(pxr::SdfPath const &id)
return nullptr; return nullptr;
} }
MeshData *BlenderSceneDelegate::mesh_data(pxr::SdfPath const &id) MeshData *BlenderSceneDelegate::mesh_data(pxr::SdfPath const &id) const
{ {
return dynamic_cast<MeshData *>(object_data(id)); return dynamic_cast<MeshData *>(object_data(id));
} }
LightData *BlenderSceneDelegate::light_data(pxr::SdfPath const &id) LightData *BlenderSceneDelegate::light_data(pxr::SdfPath const &id) const
{ {
return dynamic_cast<LightData *>(object_data(id)); return dynamic_cast<LightData *>(object_data(id));
} }
MaterialData *BlenderSceneDelegate::material_data(pxr::SdfPath const &id) MaterialData *BlenderSceneDelegate::material_data(pxr::SdfPath const &id) const
{ {
auto it = materials_.find(id); auto it = materials_.find(id);
if (it == materials_.end()) { if (it == materials_.end()) {
@ -219,7 +247,7 @@ MaterialData *BlenderSceneDelegate::material_data(pxr::SdfPath const &id)
return it->second.get(); return it->second.get();
} }
InstancerData *BlenderSceneDelegate::instancer_data(pxr::SdfPath const &id) InstancerData *BlenderSceneDelegate::instancer_data(pxr::SdfPath const &id) const
{ {
auto it = instancers_.find(id); auto it = instancers_.find(id);
if (it != instancers_.end()) { if (it != instancers_.end()) {
@ -233,7 +261,7 @@ void BlenderSceneDelegate::update_objects(Object *object)
if (!ObjectData::is_supported(object)) { if (!ObjectData::is_supported(object)) {
return; return;
} }
pxr::SdfPath id = ObjectData::prim_id(this, object); pxr::SdfPath id = object_prim_id(object);
ObjectData *obj_data = object_data(id); ObjectData *obj_data = object_data(id);
if (obj_data) { if (obj_data) {
obj_data->update(); obj_data->update();
@ -242,7 +270,7 @@ void BlenderSceneDelegate::update_objects(Object *object)
if (view3d_ && !BKE_object_is_visible_in_viewport(view3d_, object)) { if (view3d_ && !BKE_object_is_visible_in_viewport(view3d_, object)) {
return; return;
} }
objects_[id] = ObjectData::create(this, object); objects_[id] = ObjectData::create(this, object, id);
obj_data = object_data(id); obj_data = object_data(id);
obj_data->update_visibility(view3d_); obj_data->update_visibility(view3d_);
} }
@ -254,7 +282,7 @@ void BlenderSceneDelegate::update_instancers(Object *object)
it.second->check_update(object); it.second->check_update(object);
} }
pxr::SdfPath id = InstancerData::prim_id(this, object); pxr::SdfPath id = instancer_prim_id(object);
InstancerData *i_data = instancer_data(id); InstancerData *i_data = instancer_data(id);
if (i_data) { if (i_data) {
if (object->transflag & OB_DUPLI) { if (object->transflag & OB_DUPLI) {
@ -272,7 +300,7 @@ void BlenderSceneDelegate::update_instancers(Object *object)
if (view3d_ && !BKE_object_is_visible_in_viewport(view3d_, object)) { if (view3d_ && !BKE_object_is_visible_in_viewport(view3d_, object)) {
return; return;
} }
instancers_[id] = InstancerData::create(this, object); instancers_[id] = InstancerData::create(this, object, id);
i_data = instancer_data(id); i_data = instancer_data(id);
i_data->update_visibility(view3d_); i_data->update_visibility(view3d_);
} }
@ -282,7 +310,7 @@ void BlenderSceneDelegate::update_world()
World *world = scene_->world; World *world = scene_->world;
if (!world_data_) { if (!world_data_) {
if (world) { if (world) {
world_data_ = WorldData::create(this, world, context_); world_data_ = WorldData::create(this, world, world_prim_id());
} }
} }
else { else {
@ -343,7 +371,7 @@ void BlenderSceneDelegate::check_updates()
} break; } break;
case ID_MA: { case ID_MA: {
MaterialData *mat_data = material_data(MaterialData::prim_id(this, (Material *)id)); MaterialData *mat_data = material_data(material_prim_id((Material *)id));
if (mat_data) { if (mat_data) {
mat_data->update(); mat_data->update();
} }
@ -420,8 +448,8 @@ void BlenderSceneDelegate::remove_unused_objects()
if (!ObjectData::is_supported(object)) { if (!ObjectData::is_supported(object)) {
continue; continue;
} }
available_objects.insert(ObjectData::prim_id(this, object).GetName()); available_objects.insert(object_prim_id(object).GetName());
available_objects.insert(InstancerData::prim_id(this, object).GetName()); available_objects.insert(instancer_prim_id(object).GetName());
} }
ITER_END; ITER_END;
@ -501,10 +529,10 @@ void BlenderSceneDelegate::update_visibility()
continue; continue;
} }
if (!object_data(ObjectData::prim_id(this, object))) { if (!object_data(object_prim_id(object))) {
update_objects(object); update_objects(object);
} }
if (!instancer_data(InstancerData::prim_id(this, object))) { if (!instancer_data(instancer_prim_id(object))) {
update_instancers(object); update_instancers(object);
} }
} }

View File

@ -52,13 +52,23 @@ class BlenderSceneDelegate : public pxr::HdSceneDelegate {
void clear(); void clear();
EngineType engine_type; EngineType engine_type;
Depsgraph *depsgraph_ = nullptr;
bContext *context_ = nullptr;
View3D *view3d_ = nullptr;
Scene *scene_ = nullptr;
private: private:
ObjectData *object_data(pxr::SdfPath const &id); pxr::SdfPath prim_id(ID *id, const char *prefix) const;
MeshData *mesh_data(pxr::SdfPath const &id); pxr::SdfPath object_prim_id(Object *object) const;
LightData *light_data(pxr::SdfPath const &id); pxr::SdfPath material_prim_id(Material *mat) const;
MaterialData *material_data(pxr::SdfPath const &id); pxr::SdfPath instancer_prim_id(Object *object) const;
InstancerData *instancer_data(pxr::SdfPath const &id); pxr::SdfPath world_prim_id() const;
ObjectData *object_data(pxr::SdfPath const &id) const;
MeshData *mesh_data(pxr::SdfPath const &id) const;
LightData *light_data(pxr::SdfPath const &id) const;
MaterialData *material_data(pxr::SdfPath const &id) const;
InstancerData *instancer_data(pxr::SdfPath const &id) const;
void update_objects(Object *object); void update_objects(Object *object);
void update_instancers(Object *object); void update_instancers(Object *object);
@ -68,11 +78,6 @@ class BlenderSceneDelegate : public pxr::HdSceneDelegate {
void remove_unused_objects(); void remove_unused_objects();
void update_visibility(); void update_visibility();
Depsgraph *depsgraph_ = nullptr;
bContext *context_ = nullptr;
View3D *view3d_ = nullptr;
Scene *scene_ = nullptr;
ObjectDataMap objects_; ObjectDataMap objects_;
MaterialDataMap materials_; MaterialDataMap materials_;
InstancerDataMap instancers_; InstancerDataMap instancers_;

View File

@ -3,13 +3,13 @@
#include "BKE_lib_id.h" #include "BKE_lib_id.h"
#include "blender_scene_delegate.h" //#include "blender_scene_delegate.h"
#include "id.h" #include "id.h"
namespace blender::render::hydra { namespace blender::render::hydra {
IdData::IdData(BlenderSceneDelegate *scene_delegate, ID *id) IdData::IdData(BlenderSceneDelegate *scene_delegate, ID *id, pxr::SdfPath const &prim_id)
: scene_delegate_(scene_delegate), id_(id) : id_(id), p_id_(prim_id), scene_delegate_(scene_delegate)
{ {
} }

View File

@ -18,7 +18,7 @@ class IdData {
friend InstancerData; friend InstancerData;
public: public:
IdData(BlenderSceneDelegate *scene_delegate, ID *id); IdData(BlenderSceneDelegate *scene_delegate, ID *id, pxr::SdfPath const &prim_id);
virtual ~IdData() = default; virtual ~IdData() = default;
virtual void init() = 0; virtual void init() = 0;
@ -29,10 +29,11 @@ class IdData {
virtual pxr::VtValue get_data(pxr::TfToken const &key) const; virtual pxr::VtValue get_data(pxr::TfToken const &key) const;
template<class T> const T get_data(pxr::TfToken const &key) const; template<class T> const T get_data(pxr::TfToken const &key) const;
protected:
BlenderSceneDelegate *scene_delegate_;
ID *id_; ID *id_;
pxr::SdfPath p_id_; pxr::SdfPath p_id_;
protected:
BlenderSceneDelegate *scene_delegate_;
}; };
template<class T> const T IdData::get_data(pxr::TfToken const &key) const template<class T> const T IdData::get_data(pxr::TfToken const &key) const

View File

@ -9,11 +9,21 @@
namespace blender::render::hydra { namespace blender::render::hydra {
InstancerData::InstancerData(BlenderSceneDelegate *scene_delegate, Object *object) InstancerData::InstancerData(BlenderSceneDelegate *scene_delegate,
: ObjectData(scene_delegate, object) Object *object,
pxr::SdfPath const &prim_id)
: ObjectData(scene_delegate, object, prim_id)
{ {
p_id_ = prim_id(scene_delegate, object); }
ID_LOG(2, "");
std::unique_ptr<InstancerData> InstancerData::create(BlenderSceneDelegate *scene_delegate,
Object *object,
pxr::SdfPath const &prim_id)
{
auto data = std::make_unique<InstancerData>(scene_delegate, object, prim_id);
data->init();
data->insert();
return data;
} }
bool InstancerData::is_supported(Object *object) bool InstancerData::is_supported(Object *object)
@ -32,24 +42,6 @@ bool InstancerData::is_supported(Object *object)
return false; return false;
} }
std::unique_ptr<InstancerData> InstancerData::create(BlenderSceneDelegate *scene_delegate,
Object *object)
{
auto data = std::make_unique<InstancerData>(scene_delegate, object);
data->init();
data->insert();
return data;
}
pxr::SdfPath InstancerData::prim_id(BlenderSceneDelegate *scene_delegate, Object *object)
{
/* Making id of instancer in form like I_<pointer in 16 hex digits format>. Example:
* I_000002073e369608 */
char str[32];
snprintf(str, 32, "I_%016llx", (uint64_t)object);
return scene_delegate->GetDelegateID().AppendElementString(str);
}
void InstancerData::init() void InstancerData::init()
{ {
ID_LOG(2, ""); ID_LOG(2, "");
@ -159,8 +151,7 @@ pxr::SdfPathVector InstancerData::prototypes()
void InstancerData::check_update(Object *object) void InstancerData::check_update(Object *object)
{ {
pxr::SdfPath path = ObjectData::prim_id(scene_delegate_, object); pxr::SdfPath path = object_prim_id(object);
path = p_id_.AppendElementString(path.GetName());
auto it = instances_.find(path); auto it = instances_.find(path);
if (it == instances_.end()) { if (it == instances_.end()) {
return; return;
@ -207,6 +198,14 @@ void InstancerData::available_materials(std::set<pxr::SdfPath> &paths)
} }
} }
pxr::SdfPath InstancerData::object_prim_id(Object *object) const
{
/* Making id of object in form like <prefix>_<pointer in 16 hex digits format> */
char str[32];
snprintf(str, 32, "O_%016llx", (uint64_t)object);
return p_id_.AppendElementString(str);
}
void InstancerData::set_instances() void InstancerData::set_instances()
{ {
transforms_.clear(); transforms_.clear();
@ -219,8 +218,7 @@ void InstancerData::set_instances()
ListBase *lb = object_duplilist(scene_delegate_->depsgraph_, scene_delegate_->scene_, (Object *)id_); ListBase *lb = object_duplilist(scene_delegate_->depsgraph_, scene_delegate_->scene_, (Object *)id_);
LISTBASE_FOREACH (DupliObject *, dupli, lb) { LISTBASE_FOREACH (DupliObject *, dupli, lb) {
path = ObjectData::prim_id(scene_delegate_, dupli->ob); path = object_prim_id(dupli->ob);
path = p_id_.AppendElementString(path.GetName());
auto it = instances_.find(path); auto it = instances_.find(path);
if (it == instances_.end()) { if (it == instances_.end()) {
inst = &instances_[path]; inst = &instances_[path];
@ -236,7 +234,7 @@ void InstancerData::set_instances()
} }
transforms_.push_back(gf_matrix_from_transform(dupli->mat)); transforms_.push_back(gf_matrix_from_transform(dupli->mat));
inst->indices.push_back(index); inst->indices.push_back(index);
ID_LOG(2, "Instance %s %d", inst->obj_data->id_->name, index); ID_LOG(2, "%s %d", inst->obj_data->id_->name, index);
++index; ++index;
} }
free_object_duplilist(lb); free_object_duplilist(lb);
@ -254,10 +252,9 @@ void InstancerData::set_instances()
InstanceMeshData::InstanceMeshData(BlenderSceneDelegate *scene_delegate, InstanceMeshData::InstanceMeshData(BlenderSceneDelegate *scene_delegate,
Object *object, Object *object,
pxr::SdfPath const &p_id) pxr::SdfPath const &prim_id)
: MeshData(scene_delegate, object) : MeshData(scene_delegate, object, prim_id)
{ {
this->p_id_ = p_id;
} }
pxr::GfMatrix4d InstanceMeshData::transform() pxr::GfMatrix4d InstanceMeshData::transform()

View File

@ -18,12 +18,12 @@ class InstancerData : public ObjectData {
}; };
public: public:
InstancerData(BlenderSceneDelegate *scene_delegate, Object *object); InstancerData(BlenderSceneDelegate *scene_delegate, Object *object, pxr::SdfPath const &prim_id);
static bool is_supported(Object *object);
static std::unique_ptr<InstancerData> create(BlenderSceneDelegate *scene_delegate, static std::unique_ptr<InstancerData> create(BlenderSceneDelegate *scene_delegate,
Object *object); Object *object,
static pxr::SdfPath prim_id(BlenderSceneDelegate *scene_delegate, Object *object); pxr::SdfPath const &prim_id);
static bool is_supported(Object *object);
void init() override; void init() override;
void insert() override; void insert() override;
@ -43,6 +43,7 @@ class InstancerData : public ObjectData {
void available_materials(std::set<pxr::SdfPath> &paths); void available_materials(std::set<pxr::SdfPath> &paths);
private: private:
pxr::SdfPath object_prim_id(Object *object) const;
void set_instances(); void set_instances();
pxr::TfHashMap<pxr::SdfPath, Instance, pxr::SdfPath::Hash> instances_; pxr::TfHashMap<pxr::SdfPath, Instance, pxr::SdfPath::Hash> instances_;
@ -54,7 +55,7 @@ using InstancerDataMap =
class InstanceMeshData : public MeshData { class InstanceMeshData : public MeshData {
public: public:
InstanceMeshData(BlenderSceneDelegate *scene_delegate, Object *object, pxr::SdfPath const &p_id); InstanceMeshData(BlenderSceneDelegate *scene_delegate, Object *object, pxr::SdfPath const &prim_id);
pxr::GfMatrix4d transform() override; pxr::GfMatrix4d transform() override;
}; };

View File

@ -14,10 +14,11 @@
namespace blender::render::hydra { namespace blender::render::hydra {
LightData::LightData(BlenderSceneDelegate *scene_delegate, Object *object) LightData::LightData(BlenderSceneDelegate *scene_delegate,
: ObjectData(scene_delegate, object) Object *object,
pxr::SdfPath const &prim_id)
: ObjectData(scene_delegate, object, prim_id)
{ {
ID_LOG(2, "");
} }
void LightData::init() void LightData::init()
@ -87,7 +88,7 @@ void LightData::init()
void LightData::insert() void LightData::insert()
{ {
CLOG_INFO(LOG_BSD, 2, "%s", id_->name); ID_LOG(2, "");
scene_delegate_->GetRenderIndex().InsertSprim(p_type_, scene_delegate_, p_id_); scene_delegate_->GetRenderIndex().InsertSprim(p_type_, scene_delegate_, p_id_);
} }
@ -99,7 +100,7 @@ void LightData::remove()
void LightData::update() void LightData::update()
{ {
CLOG_INFO(LOG_BSD, 2, "%s", id_->name); ID_LOG(2, "");
Light *light = (Light *)((Object *)id_)->data; Light *light = (Light *)((Object *)id_)->data;
if (prim_type(light) != p_type_) { if (prim_type(light) != p_type_) {

View File

@ -15,7 +15,7 @@ namespace blender::render::hydra {
class LightData : public ObjectData { class LightData : public ObjectData {
public: public:
LightData(BlenderSceneDelegate *scene_delegate, Object *object); LightData(BlenderSceneDelegate *scene_delegate, Object *object, pxr::SdfPath const &prim_id);
void init() override; void init() override;
void insert() override; void insert() override;

View File

@ -20,31 +20,23 @@
namespace blender::render::hydra { namespace blender::render::hydra {
MaterialData::MaterialData(BlenderSceneDelegate *scene_delegate, Material *material) MaterialData::MaterialData(BlenderSceneDelegate *scene_delegate,
: IdData(scene_delegate, (ID *)material) Material *material,
pxr::SdfPath const &prim_id)
: IdData(scene_delegate, (ID *)material, prim_id)
{ {
p_id_ = prim_id(scene_delegate, material);
ID_LOG(2, "");
} }
std::unique_ptr<MaterialData> MaterialData::create(BlenderSceneDelegate *scene_delegate, std::unique_ptr<MaterialData> MaterialData::create(BlenderSceneDelegate *scene_delegate,
Material *material) Material *material,
pxr::SdfPath const &prim_id)
{ {
auto data = std::make_unique<MaterialData>(scene_delegate, material); auto data = std::make_unique<MaterialData>(scene_delegate, material, prim_id);
data->init(); data->init();
data->insert(); data->insert();
return data; return data;
} }
pxr::SdfPath MaterialData::prim_id(BlenderSceneDelegate *scene_delegate, Material *material)
{
/* Making id of material in form like M_<pointer in 16 hex digits format>.
* Example: M_000002074e812088 */
char str[32];
snprintf(str, 32, "M_%016llx", (uint64_t)material);
return scene_delegate->GetDelegateID().AppendElementString(str);
}
void MaterialData::init() void MaterialData::init()
{ {
ID_LOG(2, ""); ID_LOG(2, "");

View File

@ -19,11 +19,13 @@ class MaterialData : IdData {
friend MeshData; friend MeshData;
public: public:
MaterialData(BlenderSceneDelegate *scene_delegate, Material *material); MaterialData(BlenderSceneDelegate *scene_delegate,
Material *material,
pxr::SdfPath const &prim_id);
static std::unique_ptr<MaterialData> create(BlenderSceneDelegate *scene_delegate, static std::unique_ptr<MaterialData> create(BlenderSceneDelegate *scene_delegate,
Material *material); Material *material,
static pxr::SdfPath prim_id(BlenderSceneDelegate *scene_delegate, Material *material); pxr::SdfPath const &prim_id);
void init() override; void init() override;
void insert() override; void insert() override;

View File

@ -15,15 +15,16 @@
namespace blender::render::hydra { namespace blender::render::hydra {
MeshData::MeshData(BlenderSceneDelegate *scene_delegate, Object *object) MeshData::MeshData(BlenderSceneDelegate *scene_delegate,
: ObjectData(scene_delegate, object), mat_data_(nullptr) Object *object,
pxr::SdfPath const &prim_id)
: ObjectData(scene_delegate, object, prim_id)
{ {
ID_LOG(2, "");
} }
void MeshData::init() void MeshData::init()
{ {
CLOG_INFO(LOG_BSD, 2, "%s", id_->name); ID_LOG(2, "");
Object *object = (Object *)id_; Object *object = (Object *)id_;
if (object->type == OB_MESH && object->mode == OB_MODE_OBJECT && if (object->type == OB_MESH && object->mode == OB_MODE_OBJECT &&
@ -215,10 +216,10 @@ void MeshData::write_material()
mat_data_ = nullptr; mat_data_ = nullptr;
return; return;
} }
pxr::SdfPath id = MaterialData::prim_id(scene_delegate_, mat); pxr::SdfPath id = scene_delegate_->material_prim_id(mat);
mat_data_ = scene_delegate_->material_data(id); mat_data_ = scene_delegate_->material_data(id);
if (!mat_data_) { if (!mat_data_) {
scene_delegate_->materials_[id] = MaterialData::create(scene_delegate_, mat); scene_delegate_->materials_[id] = MaterialData::create(scene_delegate_, mat, id);
mat_data_ = scene_delegate_->material_data(id); mat_data_ = scene_delegate_->material_data(id);
} }
} }

View File

@ -15,7 +15,7 @@ namespace blender::render::hydra {
class MeshData : public ObjectData { class MeshData : public ObjectData {
public: public:
MeshData(BlenderSceneDelegate *scene_delegate, Object *object); MeshData(BlenderSceneDelegate *scene_delegate, Object *object, pxr::SdfPath const &prim_id);
void init() override; void init() override;
void insert() override; void insert() override;
@ -42,7 +42,7 @@ class MeshData : public ObjectData {
pxr::VtVec3fArray normals_; pxr::VtVec3fArray normals_;
pxr::VtMatrix4dArray instances_; pxr::VtMatrix4dArray instances_;
MaterialData *mat_data_; MaterialData *mat_data_ = nullptr;
}; };
} // namespace blender::render::hydra } // namespace blender::render::hydra

View File

@ -11,10 +11,40 @@
namespace blender::render::hydra { namespace blender::render::hydra {
ObjectData::ObjectData(BlenderSceneDelegate *scene_delegate, Object *object) ObjectData::ObjectData(BlenderSceneDelegate *scene_delegate,
: IdData(scene_delegate, (ID *)object), visible(true) Object *object,
pxr::SdfPath const &prim_id)
: IdData(scene_delegate, (ID *)object, prim_id), visible(true)
{ {
p_id_ = prim_id(scene_delegate, object); }
std::unique_ptr<ObjectData> ObjectData::create(BlenderSceneDelegate *scene_delegate,
Object *object,
pxr::SdfPath const &prim_id)
{
std::unique_ptr<ObjectData> data;
switch (object->type) {
case OB_MESH:
case OB_SURF:
case OB_FONT:
case OB_CURVES_LEGACY:
case OB_MBALL:
data = std::make_unique<MeshData>(scene_delegate, object, prim_id);
break;
case OB_LAMP:
data = std::make_unique<LightData>(scene_delegate, object, prim_id);
break;
default:
break;
}
if (data) {
data->init();
data->insert();
}
return data;
} }
bool ObjectData::is_supported(Object *object) bool ObjectData::is_supported(Object *object)
@ -34,43 +64,6 @@ bool ObjectData::is_supported(Object *object)
return false; return false;
} }
std::unique_ptr<ObjectData> ObjectData::create(BlenderSceneDelegate *scene_delegate,
Object *object)
{
std::unique_ptr<ObjectData> data;
switch (object->type) {
case OB_MESH:
case OB_SURF:
case OB_FONT:
case OB_CURVES_LEGACY:
case OB_MBALL:
data = std::make_unique<MeshData>(scene_delegate, object);
break;
case OB_LAMP:
data = std::make_unique<LightData>(scene_delegate, object);
break;
default:
break;
}
if (data) {
data->init();
data->insert();
}
return data;
}
pxr::SdfPath ObjectData::prim_id(BlenderSceneDelegate *scene_delegate, Object *object)
{
/* Making id of object in form like O_<pointer in 16 hex digits format>. Example:
* O_000002073e369608 */
char str[32];
snprintf(str, 32, "O_%016llx", (uint64_t)object);
return scene_delegate->GetDelegateID().AppendElementString(str);
}
pxr::GfMatrix4d ObjectData::transform() pxr::GfMatrix4d ObjectData::transform()
{ {
return gf_matrix_from_transform(((Object *)id_)->object_to_world); return gf_matrix_from_transform(((Object *)id_)->object_to_world);

View File

@ -16,11 +16,12 @@ namespace blender::render::hydra {
class ObjectData : public IdData { class ObjectData : public IdData {
public: public:
ObjectData(BlenderSceneDelegate *scene_delegate, Object *object); ObjectData(BlenderSceneDelegate *scene_delegate, Object *object, pxr::SdfPath const &prim_id);
static std::unique_ptr<ObjectData> create(BlenderSceneDelegate *scene_delegate,
Object *object,
pxr::SdfPath const &prim_id);
static bool is_supported(Object *object); static bool is_supported(Object *object);
static std::unique_ptr<ObjectData> create(BlenderSceneDelegate *scene_delegate, Object *object);
static pxr::SdfPath prim_id(BlenderSceneDelegate *scene_delegate, Object *object);
virtual pxr::GfMatrix4d transform(); virtual pxr::GfMatrix4d transform();
virtual bool update_visibility(View3D *view3d); virtual bool update_visibility(View3D *view3d);

View File

@ -28,28 +28,23 @@
namespace blender::render::hydra { namespace blender::render::hydra {
WorldData::WorldData(BlenderSceneDelegate *scene_delegate, World *world, bContext *context) WorldData::WorldData(BlenderSceneDelegate *scene_delegate,
: IdData(scene_delegate, (ID *)world), context_(context) World *world,
pxr::SdfPath const &prim_id)
: IdData(scene_delegate, (ID *)world, prim_id)
{ {
p_id_ = prim_id(scene_delegate);
ID_LOG(2, "");
} }
std::unique_ptr<WorldData> WorldData::create(BlenderSceneDelegate *scene_delegate, std::unique_ptr<WorldData> WorldData::create(BlenderSceneDelegate *scene_delegate,
World *world, World *world,
bContext *context) pxr::SdfPath const &prim_id)
{ {
auto data = std::make_unique<WorldData>(scene_delegate, world, context); auto data = std::make_unique<WorldData>(scene_delegate, world, prim_id);
data->init(); data->init();
data->insert(); data->insert();
return data; return data;
} }
pxr::SdfPath WorldData::prim_id(BlenderSceneDelegate *scene_delegate)
{
return scene_delegate->GetDelegateID().AppendElementString("World");
}
void WorldData::init() void WorldData::init()
{ {
ID_LOG(2, ""); ID_LOG(2, "");
@ -101,8 +96,8 @@ void WorldData::init()
Image *image = (Image *)color_input_node->id; Image *image = (Image *)color_input_node->id;
if (image) { if (image) {
Main *bmain = CTX_data_main(context_); Main *bmain = CTX_data_main(scene_delegate_->context_);
Scene *scene = CTX_data_scene(context_); Scene *scene = scene_delegate_->scene_;
ReportList reports; ReportList reports;
ImageSaveOptions opts; ImageSaveOptions opts;

View File

@ -20,12 +20,11 @@ namespace blender::render::hydra {
class WorldData : public IdData { class WorldData : public IdData {
public: public:
WorldData(BlenderSceneDelegate *scene_delegate, World *world, bContext *context); WorldData(BlenderSceneDelegate *scene_delegate, World *world, pxr::SdfPath const &prim_id);
static std::unique_ptr<WorldData> create(BlenderSceneDelegate *scene_delegate, static std::unique_ptr<WorldData> create(BlenderSceneDelegate *scene_delegate,
World *world, World *world,
bContext *context); pxr::SdfPath const &prim_id);
static pxr::SdfPath prim_id(BlenderSceneDelegate *scene_delegate);
void init() override; void init() override;
void insert() override; void insert() override;
@ -38,7 +37,6 @@ class WorldData : public IdData {
private: private:
std::map<pxr::TfToken, pxr::VtValue> data_; std::map<pxr::TfToken, pxr::VtValue> data_;
bContext *context_;
}; };
} // namespace blender::render::hydra } // namespace blender::render::hydra