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
9 changed files with 45 additions and 59 deletions
Showing only changes of commit f10d8de5c9 - Show all commits

View File

@ -32,11 +32,11 @@ pxr::GfMatrix4d BlenderSceneDelegate::GetTransform(pxr::SdfPath const &id)
CLOG_INFO(LOG_BSD, 3, "%s", id.GetText());
ObjectData *obj_data = object_data(id);
if (obj_data) {
return obj_data->transform();
return obj_data->transform;
}
if (id == world_prim_id()) {
return world_data_->transform();
return world_data_->transform;
}
return pxr::GfMatrix4d();
@ -147,7 +147,7 @@ pxr::GfMatrix4d BlenderSceneDelegate::GetInstancerTransform(pxr::SdfPath const &
{
CLOG_INFO(LOG_BSD, 3, "%s", instancer_id.GetText());
InstancerData *i_data = instancer_data(instancer_id);
return i_data->transform();
return i_data->transform;
}
void BlenderSceneDelegate::populate(Depsgraph *deps, bContext *cont)

View File

@ -96,11 +96,6 @@ pxr::VtValue InstancerData::get_data(pxr::TfToken const &key) const
return ret;
}
pxr::GfMatrix4d InstancerData::transform()
{
return pxr::GfMatrix4d(1.0);
}
bool InstancerData::update_visibility()
{
bool ret = ObjectData::update_visibility();
@ -211,21 +206,22 @@ void InstancerData::set_instances()
}
int index = 0;
Instance *inst;
pxr::SdfPath path;
pxr::SdfPath p_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);
p_id = object_prim_id(dupli->ob);
auto it = instances_.find(p_id);
if (it == instances_.end()) {
inst = &instances_[path];
inst = &instances_[p_id];
if (!is_supported(dupli->ob)) {
continue;
}
inst->obj_data = std::make_unique<InstanceMeshData>(scene_delegate_, dupli->ob, path);
inst->obj_data->init();
inst->obj_data->insert();
inst->obj_data = ObjectData::create(scene_delegate_, dupli->ob, p_id);
/* Instance's transform should be identity */
inst->obj_data->transform = pxr::GfMatrix4d(1.0);
}
else {
inst = &it->second;
@ -248,16 +244,4 @@ void InstancerData::set_instances()
}
}
InstanceMeshData::InstanceMeshData(BlenderSceneDelegate *scene_delegate,
Object *object,
pxr::SdfPath const &prim_id)
: MeshData(scene_delegate, object, prim_id)
{
}
pxr::GfMatrix4d InstanceMeshData::transform()
{
return pxr::GfMatrix4d(1.0);
}
} // namespace blender::render::hydra

View File

@ -29,7 +29,6 @@ class InstancerData : public ObjectData {
void update() override;
pxr::VtValue get_data(pxr::TfToken const &key) const override;
pxr::GfMatrix4d transform() override;
bool update_visibility() override;
pxr::HdPrimvarDescriptorVector primvar_descriptors(pxr::HdInterpolation interpolation) const;
@ -51,12 +50,4 @@ class InstancerData : public ObjectData {
using InstancerDataMap =
pxr::TfHashMap<pxr::SdfPath, std::unique_ptr<InstancerData>, pxr::SdfPath::Hash>;
class InstanceMeshData : public MeshData {
public:
InstanceMeshData(BlenderSceneDelegate *scene_delegate,
Object *object,
pxr::SdfPath const &prim_id);
pxr::GfMatrix4d transform() override;
};
} // namespace blender::render::hydra

View File

@ -84,6 +84,8 @@ void LightData::init()
/* TODO: temporary value, it should be delivered through Python UI */
data_[pxr::HdLightTokens->exposure] = 1.0f;
set_transform_to_object();
}
void LightData::insert()
@ -116,6 +118,7 @@ void LightData::update()
bits = pxr::HdLight::AllDirty;
}
else if (id->recalc & ID_RECALC_TRANSFORM) {
set_transform_to_object();
bits = pxr::HdLight::DirtyTransform;
}
scene_delegate_->GetRenderIndex().GetChangeTracker().MarkSprimDirty(prim_id, bits);

View File

@ -40,6 +40,7 @@ void MeshData::init()
}
write_material();
set_transform_to_object();
}
void MeshData::insert()
@ -77,6 +78,7 @@ void MeshData::update()
bits |= pxr::HdChangeTracker::DirtyMaterialId;
}
if (id->recalc & ID_RECALC_TRANSFORM) {
set_transform_to_object();
bits |= pxr::HdChangeTracker::DirtyTransform;
}
}

View File

@ -14,7 +14,7 @@ namespace blender::render::hydra {
ObjectData::ObjectData(BlenderSceneDelegate *scene_delegate,
Object *object,
pxr::SdfPath const &prim_id)
: IdData(scene_delegate, (ID *)object, prim_id), visible(true)
: IdData(scene_delegate, (ID *)object, prim_id), transform(pxr::GfMatrix4d(1.0)), visible(true)
{
}
@ -64,11 +64,6 @@ bool ObjectData::is_supported(Object *object)
return false;
}
pxr::GfMatrix4d ObjectData::transform()
{
return gf_matrix_from_transform(((Object *)id)->object_to_world);
}
bool ObjectData::update_visibility()
{
if (!scene_delegate_->view3d) {
@ -84,4 +79,9 @@ bool ObjectData::update_visibility()
return ret;
}
void ObjectData::set_transform_to_object()
{
transform = gf_matrix_from_transform(((Object *)id)->object_to_world);
}
} // namespace blender::render::hydra

View File

@ -23,10 +23,13 @@ class ObjectData : public IdData {
pxr::SdfPath const &prim_id);
static bool is_supported(Object *object);
virtual pxr::GfMatrix4d transform();
virtual bool update_visibility();
pxr::GfMatrix4d transform;
bool visible;
protected:
void set_transform_to_object();
};
using ObjectDataMap =

View File

@ -49,6 +49,8 @@ void WorldData::init()
{
ID_LOG(2, "");
set_transform();
World *world = (World *)id;
data_.clear();
@ -145,21 +147,6 @@ void WorldData::update(World *world)
update();
}
pxr::GfMatrix4d WorldData::transform()
{
pxr::GfMatrix4d transform = pxr::GfMatrix4d(pxr::GfRotation(pxr::GfVec3d(1.0, 0.0, 0.0), -90),
pxr::GfVec3d());
/* TODO : do this check via RenderSettings*/
if (scene_delegate_->GetRenderIndex().GetRenderDelegate()->GetRendererDisplayName() == "RPR") {
transform *= pxr::GfMatrix4d(pxr::GfRotation(pxr::GfVec3d(1.0, 0.0, 0.0), -180),
pxr::GfVec3d());
transform *= pxr::GfMatrix4d(pxr::GfRotation(pxr::GfVec3d(0.0, 0.0, 1.0), 90.0),
pxr::GfVec3d());
}
return transform;
}
pxr::VtValue WorldData::get_data(pxr::TfToken const &key) const
{
pxr::VtValue ret;
@ -170,4 +157,17 @@ pxr::VtValue WorldData::get_data(pxr::TfToken const &key) const
return ret;
}
void WorldData::set_transform()
{
transform = pxr::GfMatrix4d(pxr::GfRotation(pxr::GfVec3d(1.0, 0.0, 0.0), -90), pxr::GfVec3d());
/* TODO : do this check via RenderSettings*/
if (scene_delegate_->GetRenderIndex().GetRenderDelegate()->GetRendererDisplayName() == "RPR") {
transform *= pxr::GfMatrix4d(pxr::GfRotation(pxr::GfVec3d(1.0, 0.0, 0.0), -180),
pxr::GfVec3d());
transform *= pxr::GfMatrix4d(pxr::GfRotation(pxr::GfVec3d(0.0, 0.0, 1.0), 90.0),
pxr::GfVec3d());
}
}
} // namespace blender::render::hydra

View File

@ -32,10 +32,13 @@ class WorldData : public IdData {
void update() override;
void update(World *world);
pxr::GfMatrix4d transform();
pxr::VtValue get_data(pxr::TfToken const &key) const override;
pxr::GfMatrix4d transform;
private:
void set_transform();
std::map<pxr::TfToken, pxr::VtValue> data_;
};