forked from blender/blender
Refactor code after PR #57 #67
@ -45,7 +45,7 @@ pxr::HdBasisCurvesTopology BlenderSceneDelegate::GetBasisCurvesTopology(pxr::Sdf
|
||||
{
|
||||
CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 3, "%s", id.GetText());
|
||||
CurvesData *c_data = curves_data(id);
|
||||
return c_data->curves_topology(id);
|
||||
return c_data->topology();
|
||||
};
|
||||
|
||||
pxr::GfMatrix4d BlenderSceneDelegate::GetTransform(pxr::SdfPath const &id)
|
||||
@ -72,14 +72,6 @@ pxr::VtValue BlenderSceneDelegate::Get(pxr::SdfPath const &id, pxr::TfToken cons
|
||||
if (m_data) {
|
||||
return m_data->get_data(id, key);
|
||||
}
|
||||
CurvesData *c_data = curves_data(id);
|
||||
if (c_data) {
|
||||
return c_data->get_data(id, key);
|
||||
}
|
||||
VolumeData *v_data = volume_data(id);
|
||||
if (v_data) {
|
||||
return v_data->get_data(id, key);
|
||||
}
|
||||
ObjectData *obj_data = object_data(id);
|
||||
if (obj_data) {
|
||||
return obj_data->get_data(key);
|
||||
|
@ -22,7 +22,6 @@ void CurvesData::init()
|
||||
{
|
||||
ID_LOG(1, "");
|
||||
|
||||
Object *object = (Object *)id;
|
||||
write_curves((Curves *)object->data);
|
||||
write_transform();
|
||||
write_materials();
|
||||
@ -43,17 +42,18 @@ void CurvesData::remove()
|
||||
|
||||
void CurvesData::update()
|
||||
{
|
||||
Object *object = (Object *)id;
|
||||
pxr::HdDirtyBits bits = pxr::HdChangeTracker::Clean;
|
||||
if ((id->recalc & ID_RECALC_GEOMETRY) || (((ID *)object->data)->recalc & ID_RECALC_GEOMETRY)) {
|
||||
if ((object->id.recalc & ID_RECALC_GEOMETRY) ||
|
||||
(((ID *)object->data)->recalc & ID_RECALC_GEOMETRY))
|
||||
{
|
||||
init();
|
||||
bits = pxr::HdChangeTracker::AllDirty;
|
||||
}
|
||||
if (id->recalc & ID_RECALC_SHADING) {
|
||||
if (object->id.recalc & ID_RECALC_SHADING) {
|
||||
write_materials();
|
||||
bits |= pxr::HdChangeTracker::DirtyMaterialId | pxr::HdChangeTracker::DirtyDoubleSided;
|
||||
}
|
||||
if (id->recalc & ID_RECALC_TRANSFORM) {
|
||||
if (object->id.recalc & ID_RECALC_TRANSFORM) {
|
||||
write_transform();
|
||||
bits |= pxr::HdChangeTracker::DirtyTransform;
|
||||
}
|
||||
@ -66,7 +66,7 @@ void CurvesData::update()
|
||||
ID_LOG(1, "");
|
||||
}
|
||||
|
||||
pxr::VtValue CurvesData::get_data(pxr::SdfPath const & /* id */, pxr::TfToken const &key) const
|
||||
pxr::VtValue CurvesData::get_data(pxr::TfToken const &key) const
|
||||
{
|
||||
if (key == pxr::HdTokens->points) {
|
||||
return pxr::VtValue(vertices_);
|
||||
@ -80,18 +80,7 @@ pxr::VtValue CurvesData::get_data(pxr::SdfPath const & /* id */, pxr::TfToken co
|
||||
return pxr::VtValue();
|
||||
}
|
||||
|
||||
bool CurvesData::update_visibility()
|
||||
{
|
||||
bool ret = ObjectData::update_visibility();
|
||||
if (ret) {
|
||||
scene_delegate_->GetRenderIndex().GetChangeTracker().MarkRprimDirty(
|
||||
prim_id, pxr::HdChangeTracker::DirtyVisibility);
|
||||
ID_LOG(1, "");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
pxr::HdBasisCurvesTopology CurvesData::curves_topology(pxr::SdfPath const & /* id */) const
|
||||
pxr::HdBasisCurvesTopology CurvesData::topology() const
|
||||
{
|
||||
return pxr::HdBasisCurvesTopology(pxr::HdTokens->linear,
|
||||
pxr::TfToken(),
|
||||
@ -180,7 +169,6 @@ void CurvesData::write_uv_maps(Curves *curves)
|
||||
|
||||
void CurvesData::write_materials()
|
||||
{
|
||||
Object *object = (Object *)id;
|
||||
Material *mat = nullptr;
|
||||
/* TODO: Using only first material. Add support for multimaterial. */
|
||||
if (BKE_object_material_count_eval(object) > 0) {
|
||||
|
@ -24,13 +24,12 @@ class CurvesData : public ObjectData {
|
||||
void remove() override;
|
||||
void update() override;
|
||||
|
||||
pxr::VtValue get_data(pxr::SdfPath const &id, pxr::TfToken const &key) const;
|
||||
bool update_visibility() override;
|
||||
pxr::VtValue get_data(pxr::TfToken const &key) const override;
|
||||
|
||||
pxr::HdBasisCurvesTopology curves_topology(pxr::SdfPath const &id) const;
|
||||
pxr::HdBasisCurvesTopology topology() const;
|
||||
pxr::HdPrimvarDescriptorVector primvar_descriptors(pxr::HdInterpolation interpolation) const;
|
||||
pxr::SdfPath material_id() const;
|
||||
void available_materials(Set<pxr::SdfPath> &paths) const;
|
||||
void available_materials(Set<pxr::SdfPath> &paths) const override;
|
||||
|
||||
private:
|
||||
void write_curves(Curves *curves);
|
||||
|
@ -7,14 +7,9 @@
|
||||
|
||||
namespace blender::render::hydra {
|
||||
|
||||
IdData::IdData(BlenderSceneDelegate *scene_delegate, ID *id, pxr::SdfPath const &prim_id)
|
||||
: id(id), prim_id(prim_id), scene_delegate_(scene_delegate)
|
||||
IdData::IdData(BlenderSceneDelegate *scene_delegate, pxr::SdfPath const &prim_id)
|
||||
: prim_id(prim_id), scene_delegate_(scene_delegate)
|
||||
{
|
||||
}
|
||||
|
||||
pxr::VtValue IdData::get_data(pxr::TfToken const & /*key*/) const
|
||||
{
|
||||
return pxr::VtValue();
|
||||
}
|
||||
|
||||
} // namespace blender::render::hydra
|
||||
|
@ -13,14 +13,14 @@
|
||||
template<> struct blender::DefaultHash<pxr::SdfPath> {
|
||||
uint64_t operator()(const pxr::SdfPath &value) const
|
||||
{
|
||||
return pxr::SdfPath::Hash()(value);
|
||||
return (uint64_t)value.GetHash();
|
||||
}
|
||||
};
|
||||
|
||||
template<> struct blender::DefaultHash<pxr::TfToken> {
|
||||
uint64_t operator()(const pxr::TfToken &value) const
|
||||
{
|
||||
return pxr::TfHash()(value);
|
||||
return (uint64_t)value.Hash();
|
||||
}
|
||||
};
|
||||
|
||||
@ -30,7 +30,7 @@ class BlenderSceneDelegate;
|
||||
|
||||
class IdData {
|
||||
public:
|
||||
IdData(BlenderSceneDelegate *scene_delegate, ID *id, pxr::SdfPath const &prim_id);
|
||||
IdData(BlenderSceneDelegate *scene_delegate, pxr::SdfPath const &prim_id);
|
||||
virtual ~IdData() = default;
|
||||
|
||||
virtual void init() = 0;
|
||||
@ -38,27 +38,15 @@ class IdData {
|
||||
virtual void remove() = 0;
|
||||
virtual void update() = 0;
|
||||
|
||||
virtual pxr::VtValue get_data(pxr::TfToken const &key) const;
|
||||
template<class T> const T get_data(pxr::TfToken const &key) const;
|
||||
virtual pxr::VtValue get_data(pxr::TfToken const &key) const = 0;
|
||||
|
||||
ID *id;
|
||||
pxr::SdfPath prim_id;
|
||||
|
||||
protected:
|
||||
BlenderSceneDelegate *scene_delegate_;
|
||||
};
|
||||
|
||||
template<class T> const T IdData::get_data(pxr::TfToken const &key) const
|
||||
{
|
||||
return get_data(key).Get<T>();
|
||||
}
|
||||
|
||||
#define ID_LOG(level, msg, ...) \
|
||||
CLOG_INFO(LOG_RENDER_HYDRA_SCENE, \
|
||||
level, \
|
||||
"%s (%s): " msg, \
|
||||
prim_id.GetText(), \
|
||||
id ? id->name : "", \
|
||||
##__VA_ARGS__);
|
||||
CLOG_INFO(LOG_RENDER_HYDRA_SCENE, level, "%s: " msg, prim_id.GetText(), ##__VA_ARGS__);
|
||||
|
||||
} // namespace blender::render::hydra
|
||||
|
@ -12,7 +12,7 @@
|
||||
namespace blender::render::hydra {
|
||||
|
||||
InstancerData::InstancerData(BlenderSceneDelegate *scene_delegate, pxr::SdfPath const &prim_id)
|
||||
: IdData(scene_delegate, nullptr, prim_id)
|
||||
: IdData(scene_delegate, prim_id)
|
||||
{
|
||||
}
|
||||
|
||||
@ -163,7 +163,7 @@ void InstancerData::update_instance(Object *parent_ob, DupliObject *dupli)
|
||||
inst->data = std::make_unique<LightData>(scene_delegate_, ob, p_id);
|
||||
inst->data->init();
|
||||
}
|
||||
ID_LOG(2, "Light %s %d", inst->data->id->name, (int)inst->transforms.size());
|
||||
ID_LOG(2, "Light %s %d", inst->data->object->id.name, (int)inst->transforms.size());
|
||||
inst->transforms.push_back(gf_matrix_from_transform(dupli->mat));
|
||||
}
|
||||
else {
|
||||
@ -177,7 +177,7 @@ void InstancerData::update_instance(Object *parent_ob, DupliObject *dupli)
|
||||
else {
|
||||
inst->data->update();
|
||||
}
|
||||
ID_LOG(2, "Mesh %s %d", inst->data->id->name, (int)mesh_transforms_.size());
|
||||
ID_LOG(2, "Mesh %s %d", inst->data->object->id.name, (int)mesh_transforms_.size());
|
||||
inst->indices.push_back(mesh_transforms_.size());
|
||||
mesh_transforms_.push_back(gf_matrix_from_transform(dupli->mat));
|
||||
}
|
||||
@ -260,7 +260,7 @@ void InstancerData::update_light_instance(LightInstance &inst)
|
||||
}
|
||||
|
||||
/* Update current light instances */
|
||||
if (inst.data->prim_type((Light *)((Object *)l_data.id)->data) != l_data.prim_type_) {
|
||||
if (inst.data->prim_type((Light *)l_data.object->data) != l_data.prim_type_) {
|
||||
/* Recreate instances when prim_type was changed */
|
||||
for (i = 0; i < inst.count; ++i) {
|
||||
p = light_prim_id(inst, i);
|
||||
@ -271,13 +271,13 @@ void InstancerData::update_light_instance(LightInstance &inst)
|
||||
for (i = 0; i < inst.count; ++i) {
|
||||
p = light_prim_id(inst, i);
|
||||
render_index.InsertSprim(l_data.prim_type_, scene_delegate_, p);
|
||||
ID_LOG(2, "Insert %s (%s)", p.GetText(), l_data.id->name);
|
||||
ID_LOG(2, "Insert %s (%s)", p.GetText(), l_data.object->id.name);
|
||||
}
|
||||
}
|
||||
else {
|
||||
/* Update light instances*/
|
||||
pxr::HdDirtyBits bits = pxr::HdLight::DirtyTransform;
|
||||
Object *obj = (Object *)inst.data->id;
|
||||
Object *obj = inst.data->object;
|
||||
if (obj->id.recalc & ID_RECALC_GEOMETRY || ((ID *)obj->data)->recalc & ID_RECALC_GEOMETRY) {
|
||||
l_data.init();
|
||||
bits = pxr::HdLight::AllDirty;
|
||||
@ -285,7 +285,7 @@ void InstancerData::update_light_instance(LightInstance &inst)
|
||||
for (i = 0; i < inst.count; ++i) {
|
||||
p = light_prim_id(inst, i);
|
||||
render_index.GetChangeTracker().MarkSprimDirty(p, bits);
|
||||
ID_LOG(2, "Update %s (%s)", p.GetText(), l_data.id->name);
|
||||
ID_LOG(2, "Update %s (%s)", p.GetText(), l_data.object->id.name);
|
||||
}
|
||||
}
|
||||
|
||||
@ -293,7 +293,7 @@ void InstancerData::update_light_instance(LightInstance &inst)
|
||||
while (inst.count < inst.transforms.size()) {
|
||||
p = light_prim_id(inst, inst.count);
|
||||
render_index.InsertSprim(l_data.prim_type_, scene_delegate_, p);
|
||||
ID_LOG(2, "Insert %s (%s)", p.GetText(), l_data.id->name);
|
||||
ID_LOG(2, "Insert %s (%s)", p.GetText(), l_data.object->id.name);
|
||||
++inst.count;
|
||||
}
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ void LightData::init()
|
||||
{
|
||||
ID_LOG(1, "");
|
||||
|
||||
Light *light = (Light *)((Object *)id)->data;
|
||||
Light *light = (Light *)object->data;
|
||||
data_.clear();
|
||||
|
||||
switch (light->type) {
|
||||
@ -109,10 +109,9 @@ void LightData::remove()
|
||||
|
||||
void LightData::update()
|
||||
{
|
||||
Object *object = (Object *)id;
|
||||
Light *light = (Light *)object->data;
|
||||
pxr::HdDirtyBits bits = pxr::HdLight::Clean;
|
||||
if (id->recalc & ID_RECALC_GEOMETRY || light->id.recalc & ID_RECALC_GEOMETRY) {
|
||||
if (object->id.recalc & ID_RECALC_GEOMETRY || light->id.recalc & ID_RECALC_GEOMETRY) {
|
||||
if (prim_type(light) != prim_type_) {
|
||||
remove();
|
||||
init();
|
||||
@ -122,7 +121,7 @@ void LightData::update()
|
||||
init();
|
||||
bits = pxr::HdLight::AllDirty;
|
||||
}
|
||||
else if (id->recalc & ID_RECALC_TRANSFORM) {
|
||||
else if (object->id.recalc & ID_RECALC_TRANSFORM) {
|
||||
write_transform();
|
||||
bits = pxr::HdLight::DirtyTransform;
|
||||
}
|
||||
@ -148,17 +147,6 @@ pxr::VtValue LightData::get_data(pxr::TfToken const &key) const
|
||||
return pxr::VtValue();
|
||||
}
|
||||
|
||||
bool LightData::update_visibility()
|
||||
{
|
||||
bool ret = ObjectData::update_visibility();
|
||||
if (ret) {
|
||||
scene_delegate_->GetRenderIndex().GetChangeTracker().MarkSprimDirty(prim_id,
|
||||
pxr::HdLight::DirtyParams);
|
||||
ID_LOG(1, "");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
pxr::TfToken LightData::prim_type(Light *light)
|
||||
{
|
||||
switch (light->type) {
|
||||
|
@ -27,7 +27,6 @@ class LightData : public ObjectData {
|
||||
void update() override;
|
||||
|
||||
pxr::VtValue get_data(pxr::TfToken const &key) const override;
|
||||
bool update_visibility() override;
|
||||
|
||||
private:
|
||||
pxr::TfToken prim_type(Light *light);
|
||||
|
@ -25,14 +25,14 @@ namespace blender::render::hydra {
|
||||
MaterialData::MaterialData(BlenderSceneDelegate *scene_delegate,
|
||||
Material *material,
|
||||
pxr::SdfPath const &prim_id)
|
||||
: IdData(scene_delegate, (ID *)material, prim_id)
|
||||
: IdData(scene_delegate, prim_id), material(material)
|
||||
{
|
||||
}
|
||||
|
||||
void MaterialData::init()
|
||||
{
|
||||
ID_LOG(1, "");
|
||||
double_sided = (((Material *)id)->blend_flag & MA_BL_CULL_BACKFACE) == 0;
|
||||
double_sided = (material->blend_flag & MA_BL_CULL_BACKFACE) == 0;
|
||||
|
||||
export_mtlx();
|
||||
if (scene_delegate_->settings.mx_filename_key.IsEmpty()) {
|
||||
@ -105,12 +105,12 @@ void MaterialData::export_mtlx()
|
||||
func = PyDict_GetItemString(dict, "export_mtlx");
|
||||
|
||||
PointerRNA materialptr;
|
||||
RNA_pointer_create(NULL, &RNA_Material, id, &materialptr);
|
||||
PyObject *material = pyrna_struct_CreatePyObject(&materialptr);
|
||||
RNA_pointer_create(NULL, &RNA_Material, material, &materialptr);
|
||||
PyObject *pymaterial = pyrna_struct_CreatePyObject(&materialptr);
|
||||
|
||||
result = PyObject_CallFunction(func, "O", material);
|
||||
result = PyObject_CallFunction(func, "O", pymaterial);
|
||||
|
||||
Py_DECREF(material);
|
||||
Py_DECREF(pymaterial);
|
||||
|
||||
std::string path;
|
||||
|
||||
@ -135,7 +135,7 @@ void MaterialData::export_mtlx()
|
||||
CLOG_ERROR(LOG_RENDER_HYDRA_SCENE,
|
||||
"Export error for %s (%s): %s",
|
||||
prim_id.GetText(),
|
||||
id->name,
|
||||
material->id.name,
|
||||
err_str.c_str());
|
||||
if (traceback) {
|
||||
PyTraceBack_Print(traceback, PySys_GetObject("stderr"));
|
||||
|
@ -29,6 +29,7 @@ class MaterialData : public IdData {
|
||||
pxr::VtValue get_material_resource() const;
|
||||
pxr::HdCullStyle cull_style() const;
|
||||
|
||||
Material *material;
|
||||
bool double_sided = true;
|
||||
|
||||
private:
|
||||
|
@ -29,7 +29,6 @@ void MeshData::init()
|
||||
{
|
||||
ID_LOG(1, "");
|
||||
|
||||
Object *object = (Object *)id;
|
||||
Mesh *mesh = BKE_object_to_mesh(nullptr, object, false);
|
||||
if (mesh) {
|
||||
write_submeshes(mesh);
|
||||
@ -55,18 +54,19 @@ void MeshData::remove()
|
||||
|
||||
void MeshData::update()
|
||||
{
|
||||
Object *object = (Object *)id;
|
||||
if ((id->recalc & ID_RECALC_GEOMETRY) || (((ID *)object->data)->recalc & ID_RECALC_GEOMETRY)) {
|
||||
if ((object->id.recalc & ID_RECALC_GEOMETRY) ||
|
||||
(((ID *)object->data)->recalc & ID_RECALC_GEOMETRY))
|
||||
{
|
||||
init();
|
||||
return;
|
||||
}
|
||||
|
||||
pxr::HdDirtyBits bits = pxr::HdChangeTracker::Clean;
|
||||
if (id->recalc & ID_RECALC_SHADING) {
|
||||
if (object->id.recalc & ID_RECALC_SHADING) {
|
||||
write_materials();
|
||||
bits |= pxr::HdChangeTracker::DirtyMaterialId | pxr::HdChangeTracker::DirtyDoubleSided;
|
||||
}
|
||||
if (id->recalc & ID_RECALC_TRANSFORM) {
|
||||
if (object->id.recalc & ID_RECALC_TRANSFORM) {
|
||||
write_transform();
|
||||
bits |= pxr::HdChangeTracker::DirtyTransform;
|
||||
}
|
||||
@ -81,31 +81,23 @@ void MeshData::update()
|
||||
}
|
||||
}
|
||||
|
||||
pxr::VtValue MeshData::get_data(pxr::SdfPath const &id, pxr::TfToken const &key) const
|
||||
pxr::VtValue MeshData::get_data(pxr::TfToken const &key) const
|
||||
{
|
||||
if (key == pxr::HdTokens->points) {
|
||||
return pxr::VtValue(vertices_);
|
||||
}
|
||||
else if (key == pxr::HdTokens->normals) {
|
||||
return pxr::VtValue();
|
||||
}
|
||||
|
||||
pxr::VtValue MeshData::get_data(pxr::SdfPath const &id, pxr::TfToken const &key) const
|
||||
{
|
||||
if (key == pxr::HdTokens->normals) {
|
||||
return pxr::VtValue(submesh(id).normals);
|
||||
}
|
||||
else if (key == pxr::_tokens->st) {
|
||||
return pxr::VtValue(submesh(id).uvs);
|
||||
}
|
||||
return pxr::VtValue();
|
||||
}
|
||||
|
||||
bool MeshData::update_visibility()
|
||||
{
|
||||
bool ret = ObjectData::update_visibility();
|
||||
if (ret) {
|
||||
for (int i = 0; i < submeshes_.size(); ++i) {
|
||||
scene_delegate_->GetRenderIndex().GetChangeTracker().MarkRprimDirty(
|
||||
submesh_prim_id(i), pxr::HdChangeTracker::DirtyVisibility);
|
||||
ID_LOG(1, "%d", i);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
return get_data(key);
|
||||
}
|
||||
|
||||
pxr::HdMeshTopology MeshData::mesh_topology(pxr::SdfPath const &id) const
|
||||
@ -217,7 +209,7 @@ void MeshData::write_submeshes(Mesh *mesh)
|
||||
vertices_.clear();
|
||||
|
||||
/* Insert base submeshes */
|
||||
int mat_count = BKE_object_material_count_eval((Object *)id);
|
||||
int mat_count = BKE_object_material_count_eval(object);
|
||||
for (int i = 0; i < std::max(mat_count, 1); ++i) {
|
||||
SubMesh sm;
|
||||
sm.mat_index = i;
|
||||
@ -298,7 +290,6 @@ void MeshData::write_submeshes(Mesh *mesh)
|
||||
|
||||
void MeshData::write_materials()
|
||||
{
|
||||
Object *object = (Object *)id;
|
||||
for (int i = 0; i < submeshes_.size(); ++i) {
|
||||
SubMesh &m = submeshes_[i];
|
||||
Material *mat = BKE_object_material_get_eval(object, m.mat_index + 1);
|
||||
|
@ -32,8 +32,8 @@ class MeshData : public ObjectData {
|
||||
void remove() override;
|
||||
void update() override;
|
||||
|
||||
pxr::VtValue get_data(pxr::SdfPath const &id, pxr::TfToken const &key) const;
|
||||
bool update_visibility() override;
|
||||
pxr::VtValue get_data(pxr::TfToken const &key) const override;
|
||||
pxr::VtValue get_data(pxr::SdfPath const &id, pxr::TfToken const &key) const override;
|
||||
|
||||
pxr::HdMeshTopology mesh_topology(pxr::SdfPath const &id) const;
|
||||
pxr::HdPrimvarDescriptorVector primvar_descriptors(pxr::HdInterpolation interpolation) const;
|
||||
|
@ -15,7 +15,7 @@ namespace blender::render::hydra {
|
||||
ObjectData::ObjectData(BlenderSceneDelegate *scene_delegate,
|
||||
Object *object,
|
||||
pxr::SdfPath const &prim_id)
|
||||
: IdData(scene_delegate, (ID *)object, prim_id), transform(pxr::GfMatrix4d(1.0))
|
||||
: IdData(scene_delegate, prim_id), object(object), transform(pxr::GfMatrix4d(1.0))
|
||||
{
|
||||
}
|
||||
|
||||
@ -43,6 +43,7 @@ std::unique_ptr<ObjectData> ObjectData::create(BlenderSceneDelegate *scene_deleg
|
||||
data = std::make_unique<VolumeData>(scene_delegate, object, prim_id);
|
||||
break;
|
||||
default:
|
||||
BLI_assert_unreachable();
|
||||
break;
|
||||
}
|
||||
return data;
|
||||
@ -78,18 +79,20 @@ bool ObjectData::is_visible(BlenderSceneDelegate *scene_delegate, Object *object
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool ObjectData::update_visibility()
|
||||
pxr::VtValue ObjectData::get_data(pxr::SdfPath const &id, pxr::TfToken const &key) const
|
||||
{
|
||||
bool prev_visible = visible;
|
||||
visible = is_visible(scene_delegate_, (Object *)id);
|
||||
return visible != prev_visible;
|
||||
return get_data(key);
|
||||
}
|
||||
|
||||
void ObjectData::available_materials(Set<pxr::SdfPath> &paths) const {}
|
||||
|
||||
void ObjectData::write_transform()
|
||||
{
|
||||
transform = gf_matrix_from_transform(((Object *)id)->object_to_world);
|
||||
transform = gf_matrix_from_transform(object->object_to_world);
|
||||
}
|
||||
|
||||
void ObjectData::write_materials() {}
|
||||
|
||||
pxr::GfMatrix4d gf_matrix_from_transform(float m[4][4])
|
||||
{
|
||||
pxr::GfMatrix4d ret;
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include "BKE_layer.h"
|
||||
#include "BKE_object.h"
|
||||
#include "BLI_map.hh"
|
||||
#include "BLI_set.hh"
|
||||
#include "DNA_object_types.h"
|
||||
|
||||
#include "id.h"
|
||||
@ -28,13 +29,17 @@ class ObjectData : public IdData {
|
||||
Object *object,
|
||||
int mode = OB_VISIBLE_SELF);
|
||||
|
||||
virtual bool update_visibility();
|
||||
using IdData::get_data;
|
||||
virtual pxr::VtValue get_data(pxr::SdfPath const &id, pxr::TfToken const &key) const;
|
||||
virtual void available_materials(Set<pxr::SdfPath> &paths) const;
|
||||
|
||||
Object *object;
|
||||
pxr::GfMatrix4d transform;
|
||||
bool visible = true;
|
||||
|
||||
protected:
|
||||
void write_transform();
|
||||
virtual void write_transform();
|
||||
virtual void write_materials();
|
||||
};
|
||||
|
||||
using ObjectDataMap = Map<pxr::SdfPath, std::unique_ptr<ObjectData>>;
|
||||
|
@ -28,7 +28,7 @@ VolumeData::VolumeData(BlenderSceneDelegate *scene_delegate,
|
||||
void VolumeData::init()
|
||||
{
|
||||
ID_LOG(1, "");
|
||||
Volume *volume = (Volume *)((Object *)this->id)->data;
|
||||
Volume *volume = (Volume *)object->data;
|
||||
Main *main = CTX_data_main(scene_delegate_->context);
|
||||
if (!BKE_volume_load(volume, main)) {
|
||||
return;
|
||||
@ -80,17 +80,18 @@ void VolumeData::remove()
|
||||
|
||||
void VolumeData::update()
|
||||
{
|
||||
Object *object = (Object *)id;
|
||||
pxr::HdDirtyBits bits = pxr::HdChangeTracker::Clean;
|
||||
if ((id->recalc & ID_RECALC_GEOMETRY) || (((ID *)object->data)->recalc & ID_RECALC_GEOMETRY)) {
|
||||
if ((object->id.recalc & ID_RECALC_GEOMETRY) ||
|
||||
(((ID *)object->data)->recalc & ID_RECALC_GEOMETRY))
|
||||
{
|
||||
init();
|
||||
bits = pxr::HdChangeTracker::AllDirty;
|
||||
}
|
||||
if (id->recalc & ID_RECALC_SHADING) {
|
||||
if (object->id.recalc & ID_RECALC_SHADING) {
|
||||
write_materials();
|
||||
bits |= pxr::HdChangeTracker::DirtyMaterialId | pxr::HdChangeTracker::DirtyDoubleSided;
|
||||
}
|
||||
if (id->recalc & ID_RECALC_TRANSFORM) {
|
||||
if (object->id.recalc & ID_RECALC_TRANSFORM) {
|
||||
write_transform();
|
||||
bits |= pxr::HdChangeTracker::DirtyTransform;
|
||||
}
|
||||
@ -103,13 +104,13 @@ void VolumeData::update()
|
||||
ID_LOG(1, "");
|
||||
}
|
||||
|
||||
BogdanNagirniak marked this conversation as resolved
|
||||
pxr::VtValue VolumeData::get_data(pxr::SdfPath const &id, pxr::TfToken const &key) const
|
||||
pxr::VtValue VolumeData::get_data(pxr::TfToken const &key) const
|
||||
{
|
||||
if (key == pxr::HdVolumeFieldSchemaTokens->filePath) {
|
||||
return pxr::VtValue(pxr::SdfAssetPath(filepath_, filepath_));
|
||||
}
|
||||
if (key == pxr::HdVolumeFieldSchemaTokens->fieldName) {
|
||||
std::string name = id.GetName();
|
||||
std::string name = prim_id.GetName();
|
||||
return pxr::VtValue(pxr::TfToken(name.substr(name.find("VF_") + 3)));
|
||||
}
|
||||
if (key == pxr::HdVolumeFieldSchemaTokens->fieldIndex) {
|
||||
@ -121,17 +122,6 @@ pxr::VtValue VolumeData::get_data(pxr::SdfPath const &id, pxr::TfToken const &ke
|
||||
return pxr::VtValue();
|
||||
}
|
||||
|
||||
bool VolumeData::update_visibility()
|
||||
{
|
||||
bool ret = ObjectData::update_visibility();
|
||||
if (ret) {
|
||||
scene_delegate_->GetRenderIndex().GetChangeTracker().MarkRprimDirty(
|
||||
prim_id, pxr::HdChangeTracker::DirtyVisibility);
|
||||
ID_LOG(1, "");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
pxr::HdVolumeFieldDescriptorVector VolumeData::field_descriptors() const
|
||||
{
|
||||
return field_descriptors_;
|
||||
@ -154,7 +144,6 @@ void VolumeData::available_materials(Set<pxr::SdfPath> &paths) const
|
||||
|
||||
void VolumeData::write_materials()
|
||||
{
|
||||
Object *object = (Object *)id;
|
||||
Material *mat = nullptr;
|
||||
/* TODO: Using only first material. Add support for multimaterial. */
|
||||
if (BKE_object_material_count_eval(object) > 0) {
|
||||
|
@ -19,12 +19,11 @@ class VolumeData : public ObjectData {
|
||||
void remove() override;
|
||||
void update() override;
|
||||
|
||||
pxr::VtValue get_data(pxr::SdfPath const &id, pxr::TfToken const &key) const;
|
||||
bool update_visibility() override;
|
||||
pxr::VtValue get_data(pxr::TfToken const &key) const override;
|
||||
|
||||
pxr::HdVolumeFieldDescriptorVector field_descriptors() const;
|
||||
pxr::SdfPath material_id() const;
|
||||
void available_materials(Set<pxr::SdfPath> &paths) const;
|
||||
void available_materials(Set<pxr::SdfPath> &paths) const override;
|
||||
|
||||
private:
|
||||
void write_materials();
|
||||
|
@ -33,7 +33,7 @@
|
||||
namespace blender::render::hydra {
|
||||
|
||||
WorldData::WorldData(BlenderSceneDelegate *scene_delegate, pxr::SdfPath const &prim_id)
|
||||
: IdData(scene_delegate, nullptr, prim_id)
|
||||
: IdData(scene_delegate, prim_id)
|
||||
{
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user
Must be
get_data(pxr::SdfPath const &id, pxr::TfToken const &key) const
sinceid
here is field name.Also change back
prim_id.GetName();
->id.GetName();
No,
VolumeData::get_data(pxr::TfToken const &key)
should be here. By defaultYes, you are right. Fixed.