forked from blender/blender
Code improvements and fixes #26
@ -32,11 +32,11 @@ pxr::GfMatrix4d BlenderSceneDelegate::GetTransform(pxr::SdfPath const &id)
|
|||||||
CLOG_INFO(LOG_BSD, 3, "%s", id.GetText());
|
CLOG_INFO(LOG_BSD, 3, "%s", id.GetText());
|
||||||
ObjectData *obj_data = object_data(id);
|
ObjectData *obj_data = object_data(id);
|
||||||
if (obj_data) {
|
if (obj_data) {
|
||||||
return obj_data->transform();
|
return obj_data->transform;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (id == world_prim_id()) {
|
if (id == world_prim_id()) {
|
||||||
return world_data_->transform();
|
return world_data_->transform;
|
||||||
}
|
}
|
||||||
|
|
||||||
return pxr::GfMatrix4d();
|
return pxr::GfMatrix4d();
|
||||||
@ -147,7 +147,7 @@ pxr::GfMatrix4d BlenderSceneDelegate::GetInstancerTransform(pxr::SdfPath const &
|
|||||||
{
|
{
|
||||||
CLOG_INFO(LOG_BSD, 3, "%s", instancer_id.GetText());
|
CLOG_INFO(LOG_BSD, 3, "%s", instancer_id.GetText());
|
||||||
InstancerData *i_data = instancer_data(instancer_id);
|
InstancerData *i_data = instancer_data(instancer_id);
|
||||||
return i_data->transform();
|
return i_data->transform;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BlenderSceneDelegate::populate(Depsgraph *deps, bContext *cont)
|
void BlenderSceneDelegate::populate(Depsgraph *deps, bContext *cont)
|
||||||
|
@ -96,11 +96,6 @@ pxr::VtValue InstancerData::get_data(pxr::TfToken const &key) const
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
pxr::GfMatrix4d InstancerData::transform()
|
|
||||||
{
|
|
||||||
return pxr::GfMatrix4d(1.0);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool InstancerData::update_visibility()
|
bool InstancerData::update_visibility()
|
||||||
{
|
{
|
||||||
bool ret = ObjectData::update_visibility();
|
bool ret = ObjectData::update_visibility();
|
||||||
@ -211,21 +206,22 @@ void InstancerData::set_instances()
|
|||||||
}
|
}
|
||||||
int index = 0;
|
int index = 0;
|
||||||
Instance *inst;
|
Instance *inst;
|
||||||
pxr::SdfPath path;
|
pxr::SdfPath p_id;
|
||||||
|
|
||||||
ListBase *lb = object_duplilist(
|
ListBase *lb = object_duplilist(
|
||||||
scene_delegate_->depsgraph, scene_delegate_->scene, (Object *)id);
|
scene_delegate_->depsgraph, scene_delegate_->scene, (Object *)id);
|
||||||
LISTBASE_FOREACH (DupliObject *, dupli, lb) {
|
LISTBASE_FOREACH (DupliObject *, dupli, lb) {
|
||||||
path = object_prim_id(dupli->ob);
|
p_id = object_prim_id(dupli->ob);
|
||||||
auto it = instances_.find(path);
|
auto it = instances_.find(p_id);
|
||||||
if (it == instances_.end()) {
|
if (it == instances_.end()) {
|
||||||
inst = &instances_[path];
|
inst = &instances_[p_id];
|
||||||
if (!is_supported(dupli->ob)) {
|
if (!is_supported(dupli->ob)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
inst->obj_data = std::make_unique<InstanceMeshData>(scene_delegate_, dupli->ob, path);
|
inst->obj_data = ObjectData::create(scene_delegate_, dupli->ob, p_id);
|
||||||
inst->obj_data->init();
|
|
||||||
inst->obj_data->insert();
|
/* Instance's transform should be identity */
|
||||||
|
inst->obj_data->transform = pxr::GfMatrix4d(1.0);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
inst = &it->second;
|
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
|
} // namespace blender::render::hydra
|
||||||
|
@ -29,7 +29,6 @@ class InstancerData : public ObjectData {
|
|||||||
void update() override;
|
void update() override;
|
||||||
|
|
||||||
pxr::VtValue get_data(pxr::TfToken const &key) const override;
|
pxr::VtValue get_data(pxr::TfToken const &key) const override;
|
||||||
pxr::GfMatrix4d transform() override;
|
|
||||||
bool update_visibility() override;
|
bool update_visibility() override;
|
||||||
|
|
||||||
pxr::HdPrimvarDescriptorVector primvar_descriptors(pxr::HdInterpolation interpolation) const;
|
pxr::HdPrimvarDescriptorVector primvar_descriptors(pxr::HdInterpolation interpolation) const;
|
||||||
@ -51,12 +50,4 @@ class InstancerData : public ObjectData {
|
|||||||
using InstancerDataMap =
|
using InstancerDataMap =
|
||||||
pxr::TfHashMap<pxr::SdfPath, std::unique_ptr<InstancerData>, pxr::SdfPath::Hash>;
|
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
|
} // namespace blender::render::hydra
|
||||||
|
@ -84,6 +84,8 @@ void LightData::init()
|
|||||||
|
|
||||||
/* TODO: temporary value, it should be delivered through Python UI */
|
/* TODO: temporary value, it should be delivered through Python UI */
|
||||||
data_[pxr::HdLightTokens->exposure] = 1.0f;
|
data_[pxr::HdLightTokens->exposure] = 1.0f;
|
||||||
|
|
||||||
|
set_transform_to_object();
|
||||||
}
|
}
|
||||||
|
|
||||||
void LightData::insert()
|
void LightData::insert()
|
||||||
@ -116,6 +118,7 @@ void LightData::update()
|
|||||||
bits = pxr::HdLight::AllDirty;
|
bits = pxr::HdLight::AllDirty;
|
||||||
}
|
}
|
||||||
else if (id->recalc & ID_RECALC_TRANSFORM) {
|
else if (id->recalc & ID_RECALC_TRANSFORM) {
|
||||||
|
set_transform_to_object();
|
||||||
bits = pxr::HdLight::DirtyTransform;
|
bits = pxr::HdLight::DirtyTransform;
|
||||||
}
|
}
|
||||||
scene_delegate_->GetRenderIndex().GetChangeTracker().MarkSprimDirty(prim_id, bits);
|
scene_delegate_->GetRenderIndex().GetChangeTracker().MarkSprimDirty(prim_id, bits);
|
||||||
|
@ -40,6 +40,7 @@ void MeshData::init()
|
|||||||
}
|
}
|
||||||
|
|
||||||
write_material();
|
write_material();
|
||||||
|
set_transform_to_object();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MeshData::insert()
|
void MeshData::insert()
|
||||||
@ -77,6 +78,7 @@ void MeshData::update()
|
|||||||
bits |= pxr::HdChangeTracker::DirtyMaterialId;
|
bits |= pxr::HdChangeTracker::DirtyMaterialId;
|
||||||
}
|
}
|
||||||
if (id->recalc & ID_RECALC_TRANSFORM) {
|
if (id->recalc & ID_RECALC_TRANSFORM) {
|
||||||
|
set_transform_to_object();
|
||||||
bits |= pxr::HdChangeTracker::DirtyTransform;
|
bits |= pxr::HdChangeTracker::DirtyTransform;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@ namespace blender::render::hydra {
|
|||||||
ObjectData::ObjectData(BlenderSceneDelegate *scene_delegate,
|
ObjectData::ObjectData(BlenderSceneDelegate *scene_delegate,
|
||||||
Object *object,
|
Object *object,
|
||||||
pxr::SdfPath const &prim_id)
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
pxr::GfMatrix4d ObjectData::transform()
|
|
||||||
{
|
|
||||||
return gf_matrix_from_transform(((Object *)id)->object_to_world);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ObjectData::update_visibility()
|
bool ObjectData::update_visibility()
|
||||||
{
|
{
|
||||||
if (!scene_delegate_->view3d) {
|
if (!scene_delegate_->view3d) {
|
||||||
@ -84,4 +79,9 @@ bool ObjectData::update_visibility()
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ObjectData::set_transform_to_object()
|
||||||
|
{
|
||||||
|
transform = gf_matrix_from_transform(((Object *)id)->object_to_world);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace blender::render::hydra
|
} // namespace blender::render::hydra
|
||||||
|
@ -23,10 +23,13 @@ class ObjectData : public IdData {
|
|||||||
pxr::SdfPath const &prim_id);
|
pxr::SdfPath const &prim_id);
|
||||||
static bool is_supported(Object *object);
|
static bool is_supported(Object *object);
|
||||||
|
|
||||||
virtual pxr::GfMatrix4d transform();
|
|
||||||
virtual bool update_visibility();
|
virtual bool update_visibility();
|
||||||
|
|
||||||
|
pxr::GfMatrix4d transform;
|
||||||
bool visible;
|
bool visible;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void set_transform_to_object();
|
||||||
};
|
};
|
||||||
|
|
||||||
using ObjectDataMap =
|
using ObjectDataMap =
|
||||||
|
@ -49,6 +49,8 @@ void WorldData::init()
|
|||||||
{
|
{
|
||||||
ID_LOG(2, "");
|
ID_LOG(2, "");
|
||||||
|
|
||||||
|
set_transform();
|
||||||
|
|
||||||
World *world = (World *)id;
|
World *world = (World *)id;
|
||||||
data_.clear();
|
data_.clear();
|
||||||
|
|
||||||
@ -145,21 +147,6 @@ void WorldData::update(World *world)
|
|||||||
update();
|
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 WorldData::get_data(pxr::TfToken const &key) const
|
||||||
{
|
{
|
||||||
pxr::VtValue ret;
|
pxr::VtValue ret;
|
||||||
@ -170,4 +157,17 @@ pxr::VtValue WorldData::get_data(pxr::TfToken const &key) const
|
|||||||
return ret;
|
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
|
} // namespace blender::render::hydra
|
||||||
|
@ -32,10 +32,13 @@ class WorldData : public IdData {
|
|||||||
void update() override;
|
void update() override;
|
||||||
void update(World *world);
|
void update(World *world);
|
||||||
|
|
||||||
pxr::GfMatrix4d transform();
|
|
||||||
pxr::VtValue get_data(pxr::TfToken const &key) const override;
|
pxr::VtValue get_data(pxr::TfToken const &key) const override;
|
||||||
|
|
||||||
|
pxr::GfMatrix4d transform;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void set_transform();
|
||||||
|
|
||||||
std::map<pxr::TfToken, pxr::VtValue> data_;
|
std::map<pxr::TfToken, pxr::VtValue> data_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user