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
10 changed files with 82 additions and 82 deletions
Showing only changes of commit 724409e318 - Show all commits

View File

@ -123,7 +123,7 @@ pxr::SdfPath BlenderSceneDelegate::GetInstancerId(pxr::SdfPath const &prim_id)
CLOG_INFO(LOG_BSD, 3, "%s", prim_id.GetText());
InstancerData *i_data = instancer_data(prim_id.GetParentPath());
if (i_data) {
return i_data->p_id_;
return i_data->prim_id;
}
return pxr::SdfPath();
}
@ -152,12 +152,12 @@ pxr::GfMatrix4d BlenderSceneDelegate::GetInstancerTransform(pxr::SdfPath const &
void BlenderSceneDelegate::populate(Depsgraph * deps, bContext * cont)
{
bool is_populated = depsgraph_ != nullptr;
bool is_populated = depsgraph != nullptr;
depsgraph_ = deps;
context_ = cont;
scene_ = DEG_get_input_scene(depsgraph_);
view3d_ = CTX_wm_view3d(context_);
depsgraph = deps;
context = cont;
scene = DEG_get_input_scene(depsgraph);
view3d = CTX_wm_view3d(context);
if (is_populated) {
check_updates();
@ -267,7 +267,7 @@ void BlenderSceneDelegate::update_objects(Object *object)
obj_data->update();
return;
}
if (view3d_ && !BKE_object_is_visible_in_viewport(view3d_, object)) {
if (view3d && !BKE_object_is_visible_in_viewport(view3d, object)) {
return;
}
objects_[id] = ObjectData::create(this, object, id);
@ -297,7 +297,7 @@ void BlenderSceneDelegate::update_instancers(Object *object)
if ((object->transflag & OB_DUPLI) == 0) {
return;
}
if (view3d_ && !BKE_object_is_visible_in_viewport(view3d_, object)) {
if (view3d && !BKE_object_is_visible_in_viewport(view3d, object)) {
return;
}
instancers_[id] = InstancerData::create(this, object, id);
@ -307,7 +307,7 @@ void BlenderSceneDelegate::update_instancers(Object *object)
void BlenderSceneDelegate::update_world()
{
World *world = scene_->world;
World *world = scene->world;
if (!world_data_) {
if (world) {
world_data_ = WorldData::create(this, world, world_prim_id());
@ -331,13 +331,13 @@ void BlenderSceneDelegate::check_updates()
bool do_update_visibility = false;
bool do_update_world = false;
unsigned int scene_recalc = scene_->id.recalc;
unsigned int scene_recalc = scene->id.recalc;
if (scene_recalc) {
/* Checking scene updates */
CLOG_INFO(LOG_BSD,
2,
"Update: %s [%s]",
((ID *)scene_)->name,
((ID *)scene)->name,
std::bitset<32>(scene_recalc).to_string().c_str());
if (scene_recalc & ID_RECALC_BASE_FLAGS) {
@ -347,7 +347,7 @@ void BlenderSceneDelegate::check_updates()
do_update_collection = true;
}
if (scene_recalc & ID_RECALC_AUDIO_VOLUME) {
if ((scene_->world && !world_data_) || (!scene_->world && world_data_)) {
if ((scene->world && !world_data_) || (!scene->world && world_data_)) {
do_update_world = true;
}
}
@ -355,7 +355,7 @@ void BlenderSceneDelegate::check_updates()
/* Checking other objects updates */
DEGIDIterData data = {0};
data.graph = depsgraph_;
data.graph = depsgraph;
data.only_updated = true;
ITER_BEGIN (
DEG_iterator_ids_begin, DEG_iterator_ids_next, DEG_iterator_ids_end, &data, ID *, id) {
@ -403,7 +403,7 @@ void BlenderSceneDelegate::check_updates()
void BlenderSceneDelegate::add_new_objects()
{
DEGObjectIterSettings settings = {0};
settings.depsgraph = depsgraph_;
settings.depsgraph = depsgraph;
settings.flags = DEG_ITER_OBJECT_FLAG_LINKED_DIRECTLY | DEG_ITER_OBJECT_FLAG_VISIBLE |
DEG_ITER_OBJECT_FLAG_LINKED_VIA_SET;
DEGObjectIterData data = {0};
@ -433,7 +433,7 @@ void BlenderSceneDelegate::remove_unused_objects()
std::set<std::string> available_objects;
DEGObjectIterSettings settings = {0};
settings.depsgraph = depsgraph_;
settings.depsgraph = depsgraph;
settings.flags = DEG_ITER_OBJECT_FLAG_LINKED_DIRECTLY | DEG_ITER_OBJECT_FLAG_LINKED_VIA_SET;
DEGObjectIterData data = {0};
data.settings = &settings;
@ -511,7 +511,7 @@ void BlenderSceneDelegate::update_visibility()
/* Add objects which were invisible before and not added yet */
DEGObjectIterSettings settings = {0};
settings.depsgraph = depsgraph_;
settings.depsgraph = depsgraph;
settings.flags = DEG_ITER_OBJECT_FLAG_LINKED_DIRECTLY | DEG_ITER_OBJECT_FLAG_VISIBLE |
DEG_ITER_OBJECT_FLAG_LINKED_VIA_SET;
DEGObjectIterData data = {0};

View File

@ -51,10 +51,10 @@ class BlenderSceneDelegate : public pxr::HdSceneDelegate {
void clear();
EngineType engine_type;
Depsgraph *depsgraph_ = nullptr;
bContext *context_ = nullptr;
View3D *view3d_ = nullptr;
Scene *scene_ = nullptr;
Depsgraph *depsgraph = nullptr;
bContext *context = nullptr;
View3D *view3d = nullptr;
Scene *scene = nullptr;
private:
pxr::SdfPath prim_id(ID *id, const char *prefix) const;

View File

@ -9,7 +9,7 @@
namespace blender::render::hydra {
IdData::IdData(BlenderSceneDelegate *scene_delegate, ID *id, pxr::SdfPath const &prim_id)
: id_(id), p_id_(prim_id), scene_delegate_(scene_delegate)
: id(id), prim_id(prim_id), scene_delegate_(scene_delegate)
{
}

View File

@ -26,8 +26,8 @@ class IdData {
virtual pxr::VtValue get_data(pxr::TfToken const &key) const;
template<class T> const T get_data(pxr::TfToken const &key) const;
ID *id_;
pxr::SdfPath p_id_;
ID *id;
pxr::SdfPath prim_id;
protected:
BlenderSceneDelegate *scene_delegate_;
@ -39,6 +39,6 @@ template<class T> const T IdData::get_data(pxr::TfToken const &key) const
}
#define ID_LOG(level, msg, ...) \
CLOG_INFO(LOG_BSD, level, "%s (%s): " msg, p_id_.GetText(), id_->name, __VA_ARGS__);
CLOG_INFO(LOG_BSD, level, "%s (%s): " msg, prim_id.GetText(), id->name, __VA_ARGS__);
} // namespace blender::render::hydra

View File

@ -51,7 +51,7 @@ void InstancerData::init()
void InstancerData::insert()
{
ID_LOG(2, "");
scene_delegate_->GetRenderIndex().InsertInstancer(scene_delegate_, p_id_);
scene_delegate_->GetRenderIndex().InsertInstancer(scene_delegate_, prim_id);
for (auto &it : instances_) {
it.second.obj_data->insert();
}
@ -59,11 +59,11 @@ void InstancerData::insert()
void InstancerData::remove()
{
CLOG_INFO(LOG_BSD, 2, "%s", p_id_.GetText());
CLOG_INFO(LOG_BSD, 2, "%s", prim_id.GetText());
for (auto &it : instances_) {
it.second.obj_data->remove();
}
scene_delegate_->GetRenderIndex().RemoveInstancer(p_id_);
scene_delegate_->GetRenderIndex().RemoveInstancer(prim_id);
}
void InstancerData::update()
@ -72,17 +72,17 @@ void InstancerData::update()
pxr::HdDirtyBits bits = pxr::HdChangeTracker::Clean;
Object *object = (Object *)id_;
if ((id_->recalc & ID_RECALC_GEOMETRY) || (((ID *)object->data)->recalc & ID_RECALC_GEOMETRY)) {
Object *object = (Object *)id;
if ((id->recalc & ID_RECALC_GEOMETRY) || (((ID *)object->data)->recalc & ID_RECALC_GEOMETRY)) {
set_instances();
bits |= pxr::HdChangeTracker::AllDirty;
}
else if (id_->recalc & ID_RECALC_TRANSFORM) {
else if (id->recalc & ID_RECALC_TRANSFORM) {
set_instances();
bits |= pxr::HdChangeTracker::DirtyTransform;
}
if (bits != pxr::HdChangeTracker::Clean) {
scene_delegate_->GetRenderIndex().GetChangeTracker().MarkInstancerDirty(p_id_, bits);
scene_delegate_->GetRenderIndex().GetChangeTracker().MarkInstancerDirty(prim_id, bits);
}
}
@ -106,11 +106,11 @@ bool InstancerData::update_visibility()
bool ret = ObjectData::update_visibility();
if (ret) {
scene_delegate_->GetRenderIndex().GetChangeTracker().MarkInstancerDirty(
p_id_, pxr::HdChangeTracker::DirtyVisibility);
prim_id, pxr::HdChangeTracker::DirtyVisibility);
for (auto &it : instances_) {
it.second.obj_data->visible = visible;
scene_delegate_->GetRenderIndex().GetChangeTracker().MarkRprimDirty(
it.second.obj_data->p_id_, pxr::HdChangeTracker::DirtyVisibility);
it.second.obj_data->prim_id, pxr::HdChangeTracker::DirtyVisibility);
}
}
return ret;
@ -161,7 +161,7 @@ void InstancerData::check_update(Object *object)
bits |= pxr::HdChangeTracker::DirtyTransform;
}
if (bits != pxr::HdChangeTracker::Clean) {
scene_delegate_->GetRenderIndex().GetChangeTracker().MarkInstancerDirty(p_id_, bits);
scene_delegate_->GetRenderIndex().GetChangeTracker().MarkInstancerDirty(prim_id, bits);
}
}
@ -179,7 +179,7 @@ void InstancerData::check_remove(std::set<std::string> &available_objects)
}
if (ret) {
set_instances();
scene_delegate_->GetRenderIndex().GetChangeTracker().MarkInstancerDirty(p_id_,
scene_delegate_->GetRenderIndex().GetChangeTracker().MarkInstancerDirty(prim_id,
pxr::HdChangeTracker::AllDirty);
}
}
@ -199,7 +199,7 @@ 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);
return prim_id.AppendElementString(str);
}
void InstancerData::set_instances()
@ -212,7 +212,7 @@ void InstancerData::set_instances()
Instance *inst;
pxr::SdfPath path;
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) {
path = object_prim_id(dupli->ob);
auto it = instances_.find(path);
@ -230,7 +230,7 @@ void InstancerData::set_instances()
}
transforms_.push_back(gf_matrix_from_transform(dupli->mat));
inst->indices.push_back(index);
ID_LOG(2, "%s %d", inst->obj_data->id_->name, index);
ID_LOG(2, "%s %d", inst->obj_data->id->name, index);
++index;
}
free_object_duplilist(lb);

View File

@ -25,7 +25,7 @@ void LightData::init()
{
ID_LOG(2, "");
Light *light = (Light *)((Object *)id_)->data;
Light *light = (Light *)((Object *)id)->data;
data_.clear();
float intensity = light->energy;
@ -89,20 +89,20 @@ void LightData::init()
void LightData::insert()
{
ID_LOG(2, "");
scene_delegate_->GetRenderIndex().InsertSprim(p_type_, scene_delegate_, p_id_);
scene_delegate_->GetRenderIndex().InsertSprim(p_type_, scene_delegate_, prim_id);
}
void LightData::remove()
{
CLOG_INFO(LOG_BSD, 2, "%s", id_->name);
scene_delegate_->GetRenderIndex().RemoveSprim(p_type_, p_id_);
CLOG_INFO(LOG_BSD, 2, "%s", id->name);
scene_delegate_->GetRenderIndex().RemoveSprim(p_type_, prim_id);
}
void LightData::update()
{
ID_LOG(2, "");
Light *light = (Light *)((Object *)id_)->data;
Light *light = (Light *)((Object *)id)->data;
if (prim_type(light) != p_type_) {
remove();
init();
@ -111,14 +111,14 @@ void LightData::update()
}
pxr::HdDirtyBits bits = pxr::HdLight::Clean;
if (id_->recalc & ID_RECALC_GEOMETRY) {
if (id->recalc & ID_RECALC_GEOMETRY) {
init();
bits = pxr::HdLight::AllDirty;
}
else if (id_->recalc & ID_RECALC_TRANSFORM) {
else if (id->recalc & ID_RECALC_TRANSFORM) {
bits = pxr::HdLight::DirtyTransform;
}
scene_delegate_->GetRenderIndex().GetChangeTracker().MarkSprimDirty(p_id_, bits);
scene_delegate_->GetRenderIndex().GetChangeTracker().MarkSprimDirty(prim_id, bits);
}
pxr::VtValue LightData::get_data(pxr::TfToken const &key) const
@ -146,7 +146,7 @@ bool LightData::update_visibility()
{
bool ret = ObjectData::update_visibility();
if (ret) {
scene_delegate_->GetRenderIndex().GetChangeTracker().MarkSprimDirty(p_id_,
scene_delegate_->GetRenderIndex().GetChangeTracker().MarkSprimDirty(prim_id,
pxr::HdLight::DirtyParams);
}
return ret;

View File

@ -54,7 +54,7 @@ void MaterialData::init()
func = PyDict_GetItemString(dict, "export_mtlx");
PointerRNA materialptr;
RNA_pointer_create(NULL, &RNA_Material, id_, &materialptr);
RNA_pointer_create(NULL, &RNA_Material, id, &materialptr);
PyObject *material = pyrna_struct_CreatePyObject(&materialptr);
result = PyObject_CallFunction(func, "O", material);
@ -68,7 +68,7 @@ void MaterialData::init()
Py_DECREF(result);
}
else {
CLOG_ERROR(LOG_BSD, "Export error for %s", id_->name);
CLOG_ERROR(LOG_BSD, "Export error for %s", id->name);
PyErr_Print();
}
Py_DECREF(module);
@ -81,22 +81,22 @@ void MaterialData::init()
void MaterialData::insert()
{
CLOG_INFO(LOG_BSD, 2, "%s", id_->name);
CLOG_INFO(LOG_BSD, 2, "%s", id->name);
scene_delegate_->GetRenderIndex().InsertSprim(
pxr::HdPrimTypeTokens->material, scene_delegate_, p_id_);
pxr::HdPrimTypeTokens->material, scene_delegate_, prim_id);
}
void MaterialData::remove()
{
CLOG_INFO(LOG_BSD, 2, "%s", id_->name);
scene_delegate_->GetRenderIndex().RemoveSprim(pxr::HdPrimTypeTokens->material, p_id_);
CLOG_INFO(LOG_BSD, 2, "%s", id->name);
scene_delegate_->GetRenderIndex().RemoveSprim(pxr::HdPrimTypeTokens->material, prim_id);
}
void MaterialData::update()
{
CLOG_INFO(LOG_BSD, 2, "%s", id_->name);
CLOG_INFO(LOG_BSD, 2, "%s", id->name);
init();
scene_delegate_->GetRenderIndex().GetChangeTracker().MarkSprimDirty(p_id_,
scene_delegate_->GetRenderIndex().GetChangeTracker().MarkSprimDirty(prim_id,
pxr::HdMaterial::AllDirty);
}

View File

@ -26,7 +26,7 @@ void MeshData::init()
{
ID_LOG(2, "");
Object *object = (Object *)id_;
Object *object = (Object *)id;
if (object->type == OB_MESH && object->mode == OB_MODE_OBJECT &&
BLI_listbase_is_empty(&object->modifiers)) {
write_mesh((Mesh *)object->data);
@ -48,35 +48,35 @@ void MeshData::insert()
return;
}
CLOG_INFO(LOG_BSD, 2, "%s", id_->name);
CLOG_INFO(LOG_BSD, 2, "%s", id->name);
scene_delegate_->GetRenderIndex().InsertRprim(
pxr::HdPrimTypeTokens->mesh, scene_delegate_, p_id_);
pxr::HdPrimTypeTokens->mesh, scene_delegate_, prim_id);
}
void MeshData::remove()
{
if (!scene_delegate_->GetRenderIndex().HasRprim(p_id_)) {
if (!scene_delegate_->GetRenderIndex().HasRprim(prim_id)) {
return;
}
CLOG_INFO(LOG_BSD, 2, "%s", id_->name);
scene_delegate_->GetRenderIndex().RemoveRprim(p_id_);
CLOG_INFO(LOG_BSD, 2, "%s", id->name);
scene_delegate_->GetRenderIndex().RemoveRprim(prim_id);
}
void MeshData::update()
{
pxr::HdDirtyBits bits = pxr::HdChangeTracker::Clean;
Object *object = (Object *)id_;
if ((id_->recalc & ID_RECALC_GEOMETRY) || (((ID *)object->data)->recalc & ID_RECALC_GEOMETRY)) {
Object *object = (Object *)id;
if ((id->recalc & ID_RECALC_GEOMETRY) || (((ID *)object->data)->recalc & ID_RECALC_GEOMETRY)) {
init();
bits = pxr::HdChangeTracker::AllDirty;
}
else {
if (id_->recalc & ID_RECALC_SHADING) {
if (id->recalc & ID_RECALC_SHADING) {
write_material();
bits |= pxr::HdChangeTracker::DirtyMaterialId;
}
if (id_->recalc & ID_RECALC_TRANSFORM) {
if (id->recalc & ID_RECALC_TRANSFORM) {
bits |= pxr::HdChangeTracker::DirtyTransform;
}
}
@ -85,7 +85,7 @@ void MeshData::update()
return;
}
if (!scene_delegate_->GetRenderIndex().HasRprim(p_id_)) {
if (!scene_delegate_->GetRenderIndex().HasRprim(prim_id)) {
insert();
return;
}
@ -95,8 +95,8 @@ void MeshData::update()
remove();
return;
}
CLOG_INFO(LOG_BSD, 2, "%s", id_->name);
scene_delegate_->GetRenderIndex().GetChangeTracker().MarkRprimDirty(p_id_, bits);
CLOG_INFO(LOG_BSD, 2, "%s", id->name);
scene_delegate_->GetRenderIndex().GetChangeTracker().MarkRprimDirty(prim_id, bits);
}
pxr::VtValue MeshData::get_data(pxr::TfToken const &key) const
@ -122,7 +122,7 @@ bool MeshData::update_visibility()
bool ret = ObjectData::update_visibility();
if (ret) {
scene_delegate_->GetRenderIndex().GetChangeTracker().MarkRprimDirty(
p_id_, pxr::HdChangeTracker::DirtyVisibility);
prim_id, pxr::HdChangeTracker::DirtyVisibility);
}
return ret;
}
@ -162,7 +162,7 @@ pxr::SdfPath MeshData::material_id()
if (!mat_data_) {
return pxr::SdfPath();
}
return mat_data_->p_id_;
return mat_data_->prim_id;
}
void MeshData::write_mesh(Mesh *mesh)
@ -206,7 +206,7 @@ void MeshData::write_mesh(Mesh *mesh)
void MeshData::write_material()
{
Object *object = (Object *)id_;
Object *object = (Object *)id;
Material *mat = nullptr;
if (BKE_object_material_count_eval(object) > 0) {
mat = BKE_object_material_get_eval(object, object->actcol);

View File

@ -66,17 +66,17 @@ bool ObjectData::is_supported(Object *object)
pxr::GfMatrix4d ObjectData::transform()
{
return gf_matrix_from_transform(((Object *)id_)->object_to_world);
return gf_matrix_from_transform(((Object *)id)->object_to_world);
}
bool ObjectData::update_visibility()
{
if (!scene_delegate_->view3d_) {
if (!scene_delegate_->view3d) {
return false;
}
bool prev_visible = visible;
visible = BKE_object_is_visible_in_viewport(scene_delegate_->view3d_, (Object *)id_);
visible = BKE_object_is_visible_in_viewport(scene_delegate_->view3d, (Object *)id);
bool ret = visible != prev_visible;
if (ret) {
ID_LOG(2, "");

View File

@ -49,7 +49,7 @@ void WorldData::init()
{
ID_LOG(2, "");
World *world = (World *)id_;
World *world = (World *)id;
data_.clear();
data_[pxr::UsdLuxTokens->orientToStageUpAxis] = true;
@ -96,8 +96,8 @@ void WorldData::init()
Image *image = (Image *)color_input_node->id;
if (image) {
Main *bmain = CTX_data_main(scene_delegate_->context_);
Scene *scene = scene_delegate_->scene_;
Main *bmain = CTX_data_main(scene_delegate_->context);
Scene *scene = scene_delegate_->scene;
ReportList reports;
ImageSaveOptions opts;
@ -122,26 +122,26 @@ void WorldData::insert()
{
ID_LOG(2, "");
scene_delegate_->GetRenderIndex().InsertSprim(
pxr::HdPrimTypeTokens->domeLight, scene_delegate_, p_id_);
pxr::HdPrimTypeTokens->domeLight, scene_delegate_, prim_id);
}
void WorldData::remove()
{
CLOG_INFO(LOG_BSD, 2, "%s", id_->name);
scene_delegate_->GetRenderIndex().RemoveSprim(pxr::HdPrimTypeTokens->domeLight, p_id_);
CLOG_INFO(LOG_BSD, 2, "%s", id->name);
scene_delegate_->GetRenderIndex().RemoveSprim(pxr::HdPrimTypeTokens->domeLight, prim_id);
}
void WorldData::update()
{
ID_LOG(2, "");
init();
scene_delegate_->GetRenderIndex().GetChangeTracker().MarkSprimDirty(p_id_,
scene_delegate_->GetRenderIndex().GetChangeTracker().MarkSprimDirty(prim_id,
pxr::HdLight::AllDirty);
}
void WorldData::update(World *world)
{
id_ = (ID *)world;
id = (ID *)world;
update();
}