From 54643a8bad89a04dffcce6f8380a1ac573921fab Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Wed, 12 Apr 2023 15:08:36 +0300 Subject: [PATCH 01/13] renamings and rearrangings under scene_delegate/ --- .../scene_delegate/blender_scene_delegate.cc | 106 +++++++++--------- .../scene_delegate/blender_scene_delegate.h | 13 ++- .../render/hydra/scene_delegate/instancer.cc | 12 +- .../render/hydra/scene_delegate/instancer.h | 11 +- .../render/hydra/scene_delegate/light.cc | 6 +- .../render/hydra/scene_delegate/light.h | 5 +- .../render/hydra/scene_delegate/material.cc | 8 +- .../render/hydra/scene_delegate/material.h | 7 +- .../render/hydra/scene_delegate/mesh.cc | 75 +++++++------ .../render/hydra/scene_delegate/mesh.h | 17 +-- .../scene_delegate/mtlx_hydra_adapter.cc | 2 +- .../hydra/scene_delegate/mtlx_hydra_adapter.h | 8 +- .../render/hydra/scene_delegate/object.cc | 8 +- .../render/hydra/scene_delegate/object.h | 7 +- .../render/hydra/scene_delegate/world.cc | 6 +- .../render/hydra/scene_delegate/world.h | 5 +- 16 files changed, 156 insertions(+), 140 deletions(-) diff --git a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc index 38346736b41e..c89b55353ed0 100644 --- a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc +++ b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc @@ -45,17 +45,17 @@ void BlenderSceneDelegate::update_world() bool BlenderSceneDelegate::GetVisible(pxr::SdfPath const &id) { - if (id == WorldData::prim_id(this)) { + if (id == WorldData::get_prim_id(this)) { return true; } - return object_data(id)->visible; + return get_object_data(id)->visible; } 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, true); + InstancerData *i_data = get_instancer_data(prim_id, true); if (i_data) { return i_data->instancer_id; } @@ -74,15 +74,15 @@ pxr::VtIntArray BlenderSceneDelegate::GetInstanceIndices(pxr::SdfPath const &ins pxr::SdfPath const &prototype_id) { CLOG_INFO(LOG_BSD, 3, "%s, %s", instancer_id.GetText(), prototype_id.GetText()); - InstancerData *i_data = instancer_data(instancer_id); - return i_data->instance_indices(); + InstancerData *i_data = get_instancer_data(instancer_id); + return i_data->get_instance_indices(); } pxr::GfMatrix4d BlenderSceneDelegate::GetInstancerTransform(pxr::SdfPath const &instancer_id) { CLOG_INFO(LOG_BSD, 3, "%s", instancer_id.GetText()); - InstancerData *i_data = instancer_data(instancer_id); - return i_data->transform(); + InstancerData *i_data = get_instancer_data(instancer_id); + return i_data->get_transform(); } void BlenderSceneDelegate::update_collection(bool remove, bool visibility) @@ -114,19 +114,19 @@ void BlenderSceneDelegate::update_collection(bool remove, bool visibility) object) { CLOG_INFO(LOG_BSD, 2, "Add %s", ((ID *)object)->name); - if (!ObjectData::supported(object)) { + if (!ObjectData::is_supported(object)) { continue; } - id = ObjectData::prim_id(this, object); + id = ObjectData::get_prim_id(this, object); if (remove) { available_objects.insert(id); - if ((object->transflag & OB_DUPLI) && InstancerData::supported(object)) { - available_objects.insert(InstancerData::prim_id(this, object)); + if ((object->transflag & OB_DUPLI) && InstancerData::is_supported(object)) { + available_objects.insert(InstancerData::get_prim_id(this, object)); } } - if (!object_data(id)) { + if (!get_object_data(id)) { add_update_object(object); } } @@ -150,7 +150,7 @@ void BlenderSceneDelegate::update_collection(bool remove, bool visibility) if (!m_data) { continue; } - pxr::SdfPath mat_id = m_data->material_id(); + pxr::SdfPath mat_id = m_data->get_material_id(); if (!mat_id.IsEmpty()) { available_materials.insert(mat_id); } @@ -168,16 +168,16 @@ void BlenderSceneDelegate::update_collection(bool remove, bool visibility) void BlenderSceneDelegate::add_update_object(Object *object) { - if ((object->transflag & OB_DUPLI) && InstancerData::supported(object)) { + if ((object->transflag & OB_DUPLI) && InstancerData::is_supported(object)) { add_update_instancer(object); } - InstancerData *i_data = instancer_data(object); + InstancerData *i_data = get_instancer_data(object); if (i_data) { i_data->update(); } - pxr::SdfPath id = ObjectData::prim_id(this, object); - ObjectData *obj_data = object_data(id); + pxr::SdfPath id = ObjectData::get_prim_id(this, object); + ObjectData *obj_data = get_object_data(id); if (obj_data) { obj_data->update(); return; @@ -186,24 +186,24 @@ void BlenderSceneDelegate::add_update_object(Object *object) return; } objects[id] = ObjectData::create(this, object); - obj_data = object_data(id); + obj_data = get_object_data(id); obj_data->update_visibility(view3d); } void BlenderSceneDelegate::add_update_instancer(Object *object) { - pxr::SdfPath id = InstancerData::prim_id(this, object); - InstancerData *i_data = instancer_data(id, true); + pxr::SdfPath id = InstancerData::get_prim_id(this, object); + InstancerData *i_data = get_instancer_data(id, true); if (i_data) { i_data->update(); return; } objects[id] = InstancerData::create(this, object); - i_data = instancer_data(id, true); + i_data = get_instancer_data(id, true); i_data->update_visibility(view3d); } -ObjectData *BlenderSceneDelegate::object_data(pxr::SdfPath const &id) +ObjectData *BlenderSceneDelegate::get_object_data(pxr::SdfPath const &id) { auto it = objects.find(id); if (it == objects.end()) { @@ -212,17 +212,17 @@ ObjectData *BlenderSceneDelegate::object_data(pxr::SdfPath const &id) return it->second.get(); } -MeshData *BlenderSceneDelegate::mesh_data(pxr::SdfPath const &id) +MeshData *BlenderSceneDelegate::get_mesh_data(pxr::SdfPath const &id) { - return dynamic_cast(object_data(id)); + return dynamic_cast(get_object_data(id)); } -LightData *BlenderSceneDelegate::light_data(pxr::SdfPath const &id) +LightData *BlenderSceneDelegate::get_light_data(pxr::SdfPath const &id) { - return dynamic_cast(object_data(id)); + return dynamic_cast(get_object_data(id)); } -MaterialData *BlenderSceneDelegate::material_data(pxr::SdfPath const &id) +MaterialData *BlenderSceneDelegate::get_material_data(pxr::SdfPath const &id) { auto it = materials.find(id); if (it == materials.end()) { @@ -231,15 +231,15 @@ MaterialData *BlenderSceneDelegate::material_data(pxr::SdfPath const &id) return it->second.get(); } -InstancerData *BlenderSceneDelegate::instancer_data(pxr::SdfPath const &id, bool base_prim) +InstancerData *BlenderSceneDelegate::get_instancer_data(pxr::SdfPath const &id, bool base_prim) { if (base_prim) { - return dynamic_cast(object_data(id)); + return dynamic_cast(get_object_data(id)); } - return dynamic_cast(object_data(id.GetParentPath())); + return dynamic_cast(get_object_data(id.GetParentPath())); } -InstancerData *BlenderSceneDelegate::instancer_data(Object *object) +InstancerData *BlenderSceneDelegate::get_instancer_data(Object *object) { InstancerData *i_data; for (auto &it : objects) { @@ -310,14 +310,14 @@ void BlenderSceneDelegate::populate(Depsgraph *deps, bContext *cont) switch (GS(id->name)) { case ID_OB: { Object *object = (Object *)id; - if (!ObjectData::supported(object)) { + if (!ObjectData::is_supported(object)) { break; } add_update_object(object); } break; case ID_MA: { - MaterialData *mat_data = material_data(MaterialData::prim_id(this, (Material *)id)); + MaterialData *mat_data = get_material_data(MaterialData::get_prim_id(this, (Material *)id)); if (mat_data) { mat_data->update(); } @@ -343,25 +343,25 @@ void BlenderSceneDelegate::populate(Depsgraph *deps, bContext *cont) pxr::HdMeshTopology BlenderSceneDelegate::GetMeshTopology(pxr::SdfPath const &id) { CLOG_INFO(LOG_BSD, 3, "%s", id.GetText()); - MeshData *m_data = mesh_data(id); - return m_data->mesh_topology(); + MeshData *m_data = get_mesh_data(id); + return m_data->get_mesh_topology(); } pxr::VtValue BlenderSceneDelegate::Get(pxr::SdfPath const &id, pxr::TfToken const &key) { CLOG_INFO(LOG_BSD, 3, "%s, %s", id.GetText(), key.GetText()); - ObjectData *obj_data = object_data(id); + ObjectData *obj_data = get_object_data(id); if (obj_data) { return obj_data->get_data(key); } - MaterialData *mat_data = material_data(id); + MaterialData *mat_data = get_material_data(id); if (mat_data) { return mat_data->get_data(key); } - InstancerData *i_data = instancer_data(id); + InstancerData *i_data = get_instancer_data(id); if (i_data) { return i_data->get_data(key); } @@ -374,14 +374,14 @@ pxr::HdPrimvarDescriptorVector BlenderSceneDelegate::GetPrimvarDescriptors( { CLOG_INFO(LOG_BSD, 3, "%s, %d", id.GetText(), interpolation); - MeshData *m_data = mesh_data(id); + MeshData *m_data = get_mesh_data(id); if (m_data) { - return m_data->primvar_descriptors(interpolation); + return m_data->get_primvar_descriptors(interpolation); } - InstancerData *i_data = instancer_data(id); + InstancerData *i_data = get_instancer_data(id); if (i_data) { - return i_data->instancer_primvar_descriptors(interpolation); + return i_data->get_instancer_primvar_descriptors(interpolation); } return pxr::HdPrimvarDescriptorVector(); @@ -389,14 +389,14 @@ pxr::HdPrimvarDescriptorVector BlenderSceneDelegate::GetPrimvarDescriptors( pxr::SdfPath BlenderSceneDelegate::GetMaterialId(pxr::SdfPath const &rprim_id) { - return mesh_data(rprim_id)->material_id(); + return get_mesh_data(rprim_id)->get_material_id(); } pxr::VtValue BlenderSceneDelegate::GetMaterialResource(pxr::SdfPath const &id) { - MaterialData *mat_data = material_data(id); + MaterialData *mat_data = get_material_data(id); if (mat_data) { - return mat_data->material_resource(); + return mat_data->get_material_resource(); } return pxr::VtValue(); } @@ -404,18 +404,18 @@ pxr::VtValue BlenderSceneDelegate::GetMaterialResource(pxr::SdfPath const &id) pxr::GfMatrix4d BlenderSceneDelegate::GetTransform(pxr::SdfPath const &id) { CLOG_INFO(LOG_BSD, 3, "%s", id.GetText()); - ObjectData *obj_data = object_data(id); + ObjectData *obj_data = get_object_data(id); if (obj_data) { - return obj_data->transform(); + return obj_data->get_transform(); } - if (id == WorldData::prim_id(this)) { - return world_data->transform(); + if (id == WorldData::get_prim_id(this)) { + return world_data->get_transform(); } - InstancerData *i_data = instancer_data(id); + InstancerData *i_data = get_instancer_data(id); if (i_data) { - return i_data->transform(); + return i_data->get_transform(); } return pxr::GfMatrix4d(); @@ -424,11 +424,11 @@ pxr::GfMatrix4d BlenderSceneDelegate::GetTransform(pxr::SdfPath const &id) pxr::VtValue BlenderSceneDelegate::GetLightParamValue(pxr::SdfPath const &id, pxr::TfToken const &key) { - LightData *l_data = light_data(id); + LightData *l_data = get_light_data(id); if (l_data) { return l_data->get_data(key); } - if (id == WorldData::prim_id(this)) { + if (id == WorldData::get_prim_id(this)) { return world_data->get_data(key); } return pxr::VtValue(); diff --git a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.h b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.h index 0ee8bb3d0f21..6e2d1e2dfee2 100644 --- a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.h +++ b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.h @@ -51,15 +51,16 @@ class BlenderSceneDelegate : public pxr::HdSceneDelegate { pxr::SdfPath const &prototype_id) override; pxr::GfMatrix4d GetInstancerTransform(pxr::SdfPath const &instancer_id) override; + public: EngineType engine_type; private: - ObjectData *object_data(pxr::SdfPath const &id); - MeshData *mesh_data(pxr::SdfPath const &id); - LightData *light_data(pxr::SdfPath const &id); - MaterialData *material_data(pxr::SdfPath const &id); - InstancerData *instancer_data(pxr::SdfPath const &id, bool base_prim = false); - InstancerData *instancer_data(Object *object); + ObjectData *get_object_data(pxr::SdfPath const &id); + MeshData *get_mesh_data(pxr::SdfPath const &id); + LightData *get_light_data(pxr::SdfPath const &id); + MaterialData *get_material_data(pxr::SdfPath const &id); + InstancerData *get_instancer_data(pxr::SdfPath const &id, bool base_prim = false); + InstancerData *get_instancer_data(Object *object); void add_update_object(Object *object); void add_update_instancer(Object *object); diff --git a/source/blender/render/hydra/scene_delegate/instancer.cc b/source/blender/render/hydra/scene_delegate/instancer.cc index 8c5cd75e72e8..3925cf4950ed 100644 --- a/source/blender/render/hydra/scene_delegate/instancer.cc +++ b/source/blender/render/hydra/scene_delegate/instancer.cc @@ -9,7 +9,7 @@ namespace blender::render::hydra { -bool InstancerData::supported(Object *object) +bool InstancerData::is_supported(Object *object) { switch (object->type) { case OB_MESH: @@ -34,7 +34,7 @@ std::unique_ptr InstancerData::create(BlenderSceneDelegate *scene return data; } -pxr::SdfPath InstancerData::prim_id(BlenderSceneDelegate *scene_delegate, Object *object) +pxr::SdfPath InstancerData::get_prim_id(BlenderSceneDelegate *scene_delegate, Object *object) { /* Making id of instancer in form like I_. Example: * I_000002073e369608 */ @@ -47,7 +47,7 @@ InstancerData::InstancerData(BlenderSceneDelegate *scene_delegate, Object *objec : MeshData(scene_delegate, object), parent_obj(object) { id = nullptr; - p_id = prim_id(scene_delegate, object); + p_id = get_prim_id(scene_delegate, object); instancer_id = p_id.AppendElementString("Instancer"); CLOG_INFO(LOG_BSD, 2, "%s, instancer_id=%s", ((ID *)parent_obj)->name, instancer_id.GetText()); } @@ -60,7 +60,7 @@ void InstancerData::init() MeshData::init(); } -pxr::GfMatrix4d InstancerData::transform() +pxr::GfMatrix4d InstancerData::get_transform() { return pxr::GfMatrix4d(1.0); } @@ -91,7 +91,7 @@ pxr::VtValue InstancerData::get_data(pxr::TfToken const &key) const return MeshData::get_data(key); } -pxr::HdPrimvarDescriptorVector InstancerData::instancer_primvar_descriptors( +pxr::HdPrimvarDescriptorVector InstancerData::get_instancer_primvar_descriptors( pxr::HdInterpolation interpolation) { pxr::HdPrimvarDescriptorVector primvars; @@ -102,7 +102,7 @@ pxr::HdPrimvarDescriptorVector InstancerData::instancer_primvar_descriptors( return primvars; } -pxr::VtIntArray InstancerData::instance_indices() +pxr::VtIntArray InstancerData::get_instance_indices() { pxr::VtIntArray ret(transforms.size()); for (size_t i = 0; i < ret.size(); ++i) { diff --git a/source/blender/render/hydra/scene_delegate/instancer.h b/source/blender/render/hydra/scene_delegate/instancer.h index 0e33f1ac017a..e80d40001ab6 100644 --- a/source/blender/render/hydra/scene_delegate/instancer.h +++ b/source/blender/render/hydra/scene_delegate/instancer.h @@ -11,10 +11,10 @@ namespace blender::render::hydra { class InstancerData : public MeshData { public: - static bool supported(Object *object); + static bool is_supported(Object *object); static std::unique_ptr create(BlenderSceneDelegate *scene_delegate, Object *object); - static pxr::SdfPath prim_id(BlenderSceneDelegate *scene_delegate, Object *object); + static pxr::SdfPath get_prim_id(BlenderSceneDelegate *scene_delegate, Object *object); InstancerData(BlenderSceneDelegate *scene_delegate, Object *object); @@ -22,12 +22,13 @@ class InstancerData : public MeshData { void insert() override; void remove() override; void update() override; + pxr::VtValue get_data(pxr::TfToken const &key) const override; - pxr::GfMatrix4d transform() override; + pxr::GfMatrix4d get_transform() override; bool update_visibility(View3D *view3d) override; - pxr::HdPrimvarDescriptorVector instancer_primvar_descriptors(pxr::HdInterpolation interpolation); - pxr::VtIntArray instance_indices(); + pxr::HdPrimvarDescriptorVector get_instancer_primvar_descriptors(pxr::HdInterpolation interpolation); + pxr::VtIntArray get_instance_indices(); bool is_base(Object *object) const; pxr::SdfPath instancer_id; diff --git a/source/blender/render/hydra/scene_delegate/light.cc b/source/blender/render/hydra/scene_delegate/light.cc index 3b104e7f11e1..2e9c3085df10 100644 --- a/source/blender/render/hydra/scene_delegate/light.cc +++ b/source/blender/render/hydra/scene_delegate/light.cc @@ -79,13 +79,13 @@ void LightData::init() break; } - p_type = prim_type(light); + p_type = get_prim_type(light); /* TODO: temporary value, it should be delivered through Python UI */ data[pxr::HdLightTokens->exposure] = 1.0f; } -pxr::TfToken LightData::prim_type(Light *light) +pxr::TfToken LightData::get_prim_type(Light *light) { pxr::TfToken ret; switch (light->type) { @@ -169,7 +169,7 @@ void LightData::update() CLOG_INFO(LOG_BSD, 2, "%s", id->name); Light *light = (Light *)((Object *)id)->data; - if (prim_type(light) != p_type) { + if (get_prim_type(light) != p_type) { remove(); init(); insert(); diff --git a/source/blender/render/hydra/scene_delegate/light.h b/source/blender/render/hydra/scene_delegate/light.h index f351450c084b..9d78415046d1 100644 --- a/source/blender/render/hydra/scene_delegate/light.h +++ b/source/blender/render/hydra/scene_delegate/light.h @@ -21,13 +21,16 @@ class LightData : public ObjectData { void insert() override; void remove() override; void update() override; + pxr::VtValue get_data(pxr::TfToken const &key) const override; bool update_visibility(View3D *view3d) override; + private: + pxr::TfToken get_prim_type(Light *light); + private: std::map data; pxr::TfToken p_type; - pxr::TfToken prim_type(Light *light); }; } // namespace blender::render::hydra diff --git a/source/blender/render/hydra/scene_delegate/material.cc b/source/blender/render/hydra/scene_delegate/material.cc index 3e20c74ef966..37cefe982593 100644 --- a/source/blender/render/hydra/scene_delegate/material.cc +++ b/source/blender/render/hydra/scene_delegate/material.cc @@ -29,7 +29,7 @@ std::unique_ptr MaterialData::create(BlenderSceneDelegate *scene_d return data; } -pxr::SdfPath MaterialData::prim_id(BlenderSceneDelegate *scene_delegate, Material *material) +pxr::SdfPath MaterialData::get_prim_id(BlenderSceneDelegate *scene_delegate, Material *material) { /* Making id of material in form like M_. * Example: M_000002074e812088 */ @@ -41,7 +41,7 @@ pxr::SdfPath MaterialData::prim_id(BlenderSceneDelegate *scene_delegate, Materia MaterialData::MaterialData(BlenderSceneDelegate *scene_delegate, Material *material) : IdData(scene_delegate, (ID *)material) { - p_id = prim_id(scene_delegate, material); + p_id = get_prim_id(scene_delegate, material); CLOG_INFO(LOG_BSD, 2, "%s, id=%s", id->name, p_id.GetText()); } @@ -99,7 +99,7 @@ pxr::VtValue MaterialData::get_data(pxr::TfToken const &key) const return ret; } -pxr::VtValue MaterialData::material_resource() +pxr::VtValue MaterialData::get_material_resource() { if (material_network_map.IsEmpty()) { const std::string &path = mtlx_path.GetResolvedPath(); @@ -110,7 +110,7 @@ pxr::VtValue MaterialData::material_resource() pxr::TfTokenVector render_contexts = render_delegate->GetMaterialRenderContexts(); pxr::HdMaterialNetworkMap network_map; - HdMtlxConvertToMaterialNetworkMap(path, shader_source_types, render_contexts, &network_map); + hdmtlx_convert_to_materialnetworkmap(path, shader_source_types, render_contexts, &network_map); material_network_map = network_map; } diff --git a/source/blender/render/hydra/scene_delegate/material.h b/source/blender/render/hydra/scene_delegate/material.h index 7d7e6dfc92df..0f7b0545f078 100644 --- a/source/blender/render/hydra/scene_delegate/material.h +++ b/source/blender/render/hydra/scene_delegate/material.h @@ -21,7 +21,7 @@ class MaterialData : IdData { public: static std::unique_ptr create(BlenderSceneDelegate *scene_delegate, Material *material); - static pxr::SdfPath prim_id(BlenderSceneDelegate *scene_delegate, Material *material); + static pxr::SdfPath get_prim_id(BlenderSceneDelegate *scene_delegate, Material *material); MaterialData(BlenderSceneDelegate *scene_delegate, Material *material); @@ -29,10 +29,9 @@ class MaterialData : IdData { void insert() override; void remove() override; void update() override; - pxr::VtValue get_data(pxr::TfToken const &key) const override; - pxr::VtValue material_resource(); - void export_mtlx(); + pxr::VtValue get_data(pxr::TfToken const &key) const override; + pxr::VtValue get_material_resource(); private: pxr::SdfAssetPath mtlx_path; diff --git a/source/blender/render/hydra/scene_delegate/mesh.cc b/source/blender/render/hydra/scene_delegate/mesh.cc index e2d44c017174..eed4b3e5af7a 100644 --- a/source/blender/render/hydra/scene_delegate/mesh.cc +++ b/source/blender/render/hydra/scene_delegate/mesh.cc @@ -49,7 +49,7 @@ bool MeshData::update_visibility(View3D *view3d) return ret; } -pxr::HdMeshTopology MeshData::mesh_topology() +pxr::HdMeshTopology MeshData::get_mesh_topology() { return pxr::HdMeshTopology(pxr::PxOsdOpenSubdivTokens->none, pxr::HdTokens->rightHanded, @@ -57,7 +57,7 @@ pxr::HdMeshTopology MeshData::mesh_topology() face_vertex_indices); } -pxr::HdPrimvarDescriptorVector MeshData::primvar_descriptors(pxr::HdInterpolation interpolation) +pxr::HdPrimvarDescriptorVector MeshData::get_primvar_descriptors(pxr::HdInterpolation interpolation) { pxr::HdPrimvarDescriptorVector primvars; if (interpolation == pxr::HdInterpolationVertex) { @@ -79,7 +79,7 @@ pxr::HdPrimvarDescriptorVector MeshData::primvar_descriptors(pxr::HdInterpolatio return primvars; } -pxr::SdfPath MeshData::material_id() +pxr::SdfPath MeshData::get_material_id() { if (!mat_data) { return pxr::SdfPath(); @@ -87,7 +87,7 @@ pxr::SdfPath MeshData::material_id() return mat_data->p_id; } -void MeshData::set_mesh(Mesh *mesh) +void MeshData::write_mesh(Mesh *mesh) { face_vertex_counts.clear(); face_vertex_indices.clear(); @@ -122,30 +122,11 @@ void MeshData::set_mesh(Mesh *mesh) vertices.push_back(pxr::GfVec3f(v.x, v.y, v.z)); } - /* normals */ - const float(*lnors)[3] = (float(*)[3])CustomData_get_layer(&mesh->ldata, CD_NORMAL); - if (lnors) { - normals.reserve(loopTris.size() * 3); - for (MLoopTri lt : loopTris) { - normals.push_back(pxr::GfVec3f(lnors[lt.tri[0]])); - normals.push_back(pxr::GfVec3f(lnors[lt.tri[1]])); - normals.push_back(pxr::GfVec3f(lnors[lt.tri[2]])); - } - } - - /* uvs*/ - const float(*luvs)[2] = (float(*)[2])CustomData_get_layer(&mesh->ldata, CD_PROP_FLOAT2); - if (luvs) { - uvs.reserve(loopTris.size() * 3); - for (MLoopTri lt : loopTris) { - uvs.push_back(pxr::GfVec2f(luvs[lt.tri[0]])); - uvs.push_back(pxr::GfVec2f(luvs[lt.tri[1]])); - uvs.push_back(pxr::GfVec2f(luvs[lt.tri[2]])); - } - } + write_normals(mesh); + write_uv_maps(mesh); } -void MeshData::set_material() +void MeshData::write_material() { Object *object = (Object *)id; Material *mat = nullptr; @@ -157,11 +138,39 @@ void MeshData::set_material() mat_data = nullptr; return; } - pxr::SdfPath id = MaterialData::prim_id(scene_delegate, mat); - mat_data = scene_delegate->material_data(id); + pxr::SdfPath id = MaterialData::get_prim_id(scene_delegate, mat); + mat_data = scene_delegate->get_material_data(id); if (!mat_data) { scene_delegate->materials[id] = MaterialData::create(scene_delegate, mat); - mat_data = scene_delegate->material_data(id); + mat_data = scene_delegate->get_material_data(id); + } +} + +void MeshData::write_uv_maps(Mesh *mesh) +{ + blender::Span loopTris = mesh->looptris(); + const float(*luvs)[2] = (float(*)[2])CustomData_get_layer(&mesh->ldata, CD_PROP_FLOAT2); + if (luvs) { + uvs.reserve(loopTris.size() * 3); + for (MLoopTri lt : loopTris) { + uvs.push_back(pxr::GfVec2f(luvs[lt.tri[0]])); + uvs.push_back(pxr::GfVec2f(luvs[lt.tri[1]])); + uvs.push_back(pxr::GfVec2f(luvs[lt.tri[2]])); + } + } +} + +void MeshData::write_normals(Mesh *mesh) +{ + blender::Span loopTris = mesh->looptris(); + const float(*lnors)[3] = (float(*)[3])CustomData_get_layer(&mesh->ldata, CD_NORMAL); + if (lnors) { + normals.reserve(loopTris.size() * 3); + for (MLoopTri lt : loopTris) { + normals.push_back(pxr::GfVec3f(lnors[lt.tri[0]])); + normals.push_back(pxr::GfVec3f(lnors[lt.tri[1]])); + normals.push_back(pxr::GfVec3f(lnors[lt.tri[2]])); + } } } @@ -172,17 +181,17 @@ void MeshData::init() Object *object = (Object *)id; if (object->type == OB_MESH && object->mode == OB_MODE_OBJECT && BLI_listbase_is_empty(&object->modifiers)) { - set_mesh((Mesh *)object->data); + write_mesh((Mesh *)object->data); } else { Mesh *mesh = BKE_object_to_mesh(nullptr, object, false); if (mesh) { - set_mesh(mesh); + write_mesh(mesh); } BKE_object_to_mesh_clear(object); } - set_material(); + write_material(); } void MeshData::insert() @@ -215,7 +224,7 @@ void MeshData::update() } else { if (id->recalc & ID_RECALC_SHADING) { - set_material(); + write_material(); bits |= pxr::HdChangeTracker::DirtyMaterialId; } if (id->recalc & ID_RECALC_TRANSFORM) { diff --git a/source/blender/render/hydra/scene_delegate/mesh.h b/source/blender/render/hydra/scene_delegate/mesh.h index 1a2869362a78..a02380eb0523 100644 --- a/source/blender/render/hydra/scene_delegate/mesh.h +++ b/source/blender/render/hydra/scene_delegate/mesh.h @@ -21,23 +21,26 @@ class MeshData : public ObjectData { void insert() override; void remove() override; void update() override; + pxr::VtValue get_data(pxr::TfToken const &key) const override; bool update_visibility(View3D *view3d) override; - pxr::HdMeshTopology mesh_topology(); - pxr::HdPrimvarDescriptorVector primvar_descriptors(pxr::HdInterpolation interpolation); - pxr::SdfPath material_id(); + pxr::HdMeshTopology get_mesh_topology(); + pxr::HdPrimvarDescriptorVector get_primvar_descriptors(pxr::HdInterpolation interpolation); + pxr::SdfPath get_material_id(); protected: - void set_mesh(Mesh *mesh); - void set_material(); + void write_mesh(Mesh *mesh); + void write_material(); + void write_uv_maps(Mesh *mesh); + void write_normals(Mesh *mesh); + protected: pxr::VtIntArray face_vertex_counts; pxr::VtIntArray face_vertex_indices; pxr::VtVec3fArray vertices; - pxr::VtVec3fArray normals; pxr::VtVec2fArray uvs; - + pxr::VtVec3fArray normals; pxr::VtMatrix4dArray instances; MaterialData *mat_data; diff --git a/source/blender/render/hydra/scene_delegate/mtlx_hydra_adapter.cc b/source/blender/render/hydra/scene_delegate/mtlx_hydra_adapter.cc index 2a7d1e717098..36686d89690a 100644 --- a/source/blender/render/hydra/scene_delegate/mtlx_hydra_adapter.cc +++ b/source/blender/render/hydra/scene_delegate/mtlx_hydra_adapter.cc @@ -22,7 +22,7 @@ namespace mx = MaterialX; -void HdMtlxConvertToMaterialNetworkMap(std::string const &mtlx_path, +void hdmtlx_convert_to_materialnetworkmap(std::string const &mtlx_path, pxr::TfTokenVector const &shader_source_types, pxr::TfTokenVector const &render_contexts, pxr::HdMaterialNetworkMap *out) diff --git a/source/blender/render/hydra/scene_delegate/mtlx_hydra_adapter.h b/source/blender/render/hydra/scene_delegate/mtlx_hydra_adapter.h index 9ffd92895c2b..741f288ffb66 100644 --- a/source/blender/render/hydra/scene_delegate/mtlx_hydra_adapter.h +++ b/source/blender/render/hydra/scene_delegate/mtlx_hydra_adapter.h @@ -10,7 +10,7 @@ struct pxr::HdMaterialNetworkMap; -void HdMtlxConvertToMaterialNetworkMap(std::string const &mtlx_path, - pxr::TfTokenVector const &shader_source_types, - pxr::TfTokenVector const &render_contexts, - pxr::HdMaterialNetworkMap *out); +void hdmtlx_convert_to_materialnetworkmap(std::string const &mtlx_path, + pxr::TfTokenVector const &shader_source_types, + pxr::TfTokenVector const &render_contexts, + pxr::HdMaterialNetworkMap *out); diff --git a/source/blender/render/hydra/scene_delegate/object.cc b/source/blender/render/hydra/scene_delegate/object.cc index 6a120734296d..feb910551f4b 100644 --- a/source/blender/render/hydra/scene_delegate/object.cc +++ b/source/blender/render/hydra/scene_delegate/object.cc @@ -11,7 +11,7 @@ namespace blender::render::hydra { -bool ObjectData::supported(Object *object) +bool ObjectData::is_supported(Object *object) { switch (object->type) { case OB_MESH: @@ -56,7 +56,7 @@ std::unique_ptr ObjectData::create(BlenderSceneDelegate *scene_deleg return data; } -pxr::SdfPath ObjectData::prim_id(BlenderSceneDelegate *scene_delegate, Object *object) +pxr::SdfPath ObjectData::get_prim_id(BlenderSceneDelegate *scene_delegate, Object *object) { /* Making id of object in form like O_. Example: * O_000002073e369608 */ @@ -68,10 +68,10 @@ pxr::SdfPath ObjectData::prim_id(BlenderSceneDelegate *scene_delegate, Object *o ObjectData::ObjectData(BlenderSceneDelegate *scene_delegate, Object *object) : IdData(scene_delegate, (ID *)object), visible(true) { - p_id = prim_id(scene_delegate, object); + p_id = get_prim_id(scene_delegate, object); } -pxr::GfMatrix4d ObjectData::transform() +pxr::GfMatrix4d ObjectData::get_transform() { return gf_matrix_from_transform(((Object *)id)->object_to_world); } diff --git a/source/blender/render/hydra/scene_delegate/object.h b/source/blender/render/hydra/scene_delegate/object.h index bdc17566ec43..9ce8210ed771 100644 --- a/source/blender/render/hydra/scene_delegate/object.h +++ b/source/blender/render/hydra/scene_delegate/object.h @@ -16,15 +16,16 @@ namespace blender::render::hydra { class ObjectData : public IdData { public: - static bool supported(Object *object); + static bool is_supported(Object *object); static std::unique_ptr create(BlenderSceneDelegate *scene_delegate, Object *object); - static pxr::SdfPath prim_id(BlenderSceneDelegate *scene_delegate, Object *object); + static pxr::SdfPath get_prim_id(BlenderSceneDelegate *scene_delegate, Object *object); ObjectData(BlenderSceneDelegate *scene_delegate, Object *object); - virtual pxr::GfMatrix4d transform(); + virtual pxr::GfMatrix4d get_transform(); virtual bool update_visibility(View3D *view3d); + public: bool visible; }; diff --git a/source/blender/render/hydra/scene_delegate/world.cc b/source/blender/render/hydra/scene_delegate/world.cc index 993574853c7f..9d66487385d4 100644 --- a/source/blender/render/hydra/scene_delegate/world.cc +++ b/source/blender/render/hydra/scene_delegate/world.cc @@ -38,7 +38,7 @@ std::unique_ptr WorldData::create(BlenderSceneDelegate *scene_delegat return data; } -pxr::SdfPath WorldData::prim_id(BlenderSceneDelegate *scene_delegate) +pxr::SdfPath WorldData::get_prim_id(BlenderSceneDelegate *scene_delegate) { return scene_delegate->GetDelegateID().AppendElementString("World"); } @@ -46,7 +46,7 @@ pxr::SdfPath WorldData::prim_id(BlenderSceneDelegate *scene_delegate) WorldData::WorldData(BlenderSceneDelegate *scene_delegate, World *world, bContext *context) : IdData(scene_delegate, (ID *)world), context(context) { - p_id = prim_id(scene_delegate); + p_id = get_prim_id(scene_delegate); CLOG_INFO(LOG_BSD, 2, "%s, id=%s", id->name, p_id.GetText()); } @@ -123,7 +123,7 @@ void WorldData::init() } } -pxr::GfMatrix4d WorldData::transform() +pxr::GfMatrix4d WorldData::get_transform() { pxr::GfMatrix4d transform = pxr::GfMatrix4d(pxr::GfRotation(pxr::GfVec3d(1.0, 0.0, 0.0), -90), pxr::GfVec3d()); diff --git a/source/blender/render/hydra/scene_delegate/world.h b/source/blender/render/hydra/scene_delegate/world.h index 36ef231894f4..648a55607d24 100644 --- a/source/blender/render/hydra/scene_delegate/world.h +++ b/source/blender/render/hydra/scene_delegate/world.h @@ -23,7 +23,7 @@ class WorldData : public IdData { static std::unique_ptr create(BlenderSceneDelegate *scene_delegate, World *world, bContext *context); - static pxr::SdfPath prim_id(BlenderSceneDelegate *scene_delegate); + static pxr::SdfPath get_prim_id(BlenderSceneDelegate *scene_delegate); WorldData(BlenderSceneDelegate *scene_delegate, World *world, bContext *context); @@ -33,8 +33,7 @@ class WorldData : public IdData { void update() override; void update(World *world); - pxr::GfMatrix4d transform(); - + pxr::GfMatrix4d get_transform(); pxr::VtValue get_data(pxr::TfToken const &key) const override; private: -- 2.30.2 From d04fc816106feb8ad4a297da3f956a802fcbaeb7 Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Thu, 13 Apr 2023 14:39:53 +0300 Subject: [PATCH 02/13] renamings and rearrangings --- source/blender/render/hydra/engine.cc | 2 +- source/blender/render/hydra/engine.h | 3 +- source/blender/render/hydra/final_engine.cc | 4 +- source/blender/render/hydra/preview_engine.cc | 8 +- .../scene_delegate/blender_scene_delegate.cc | 615 +++++++++--------- .../scene_delegate/blender_scene_delegate.h | 20 +- .../blender/render/hydra/scene_delegate/id.cc | 2 +- .../blender/render/hydra/scene_delegate/id.h | 6 +- .../render/hydra/scene_delegate/instancer.cc | 172 ++--- .../render/hydra/scene_delegate/instancer.h | 12 +- .../render/hydra/scene_delegate/light.cc | 174 ++--- .../render/hydra/scene_delegate/light.h | 5 +- .../render/hydra/scene_delegate/material.cc | 82 +-- .../render/hydra/scene_delegate/material.h | 8 +- .../render/hydra/scene_delegate/mesh.cc | 343 +++++----- .../render/hydra/scene_delegate/mesh.h | 15 +- .../render/hydra/scene_delegate/object.cc | 16 +- .../render/hydra/scene_delegate/object.h | 5 +- .../render/hydra/scene_delegate/world.cc | 99 +-- .../render/hydra/scene_delegate/world.h | 8 +- .../blender/render/hydra/viewport_engine.cc | 6 +- 21 files changed, 801 insertions(+), 804 deletions(-) diff --git a/source/blender/render/hydra/engine.cc b/source/blender/render/hydra/engine.cc index 6452e1ddf866..c58c1d4b3ec7 100644 --- a/source/blender/render/hydra/engine.cc +++ b/source/blender/render/hydra/engine.cc @@ -46,7 +46,7 @@ Engine::Engine(RenderEngine *bl_engine, const std::string &delegate_id) : bl_eng Engine::~Engine() { - scene_delegate = nullptr; + scene_delegate_ = nullptr; render_task_delegate = nullptr; free_camera_delegate = nullptr; simple_light_task_delegate = nullptr; diff --git a/source/blender/render/hydra/engine.h b/source/blender/render/hydra/engine.h index 3e6a5ad95056..6bcec61cbecf 100644 --- a/source/blender/render/hydra/engine.h +++ b/source/blender/render/hydra/engine.h @@ -38,12 +38,11 @@ class Engine { protected: float renderer_percent_done(); - protected: RenderEngine *bl_engine; pxr::HdPluginRenderDelegateUniqueHandle render_delegate; std::unique_ptr render_index; - std::unique_ptr scene_delegate; + std::unique_ptr scene_delegate_; std::unique_ptr render_task_delegate; std::unique_ptr free_camera_delegate; std::unique_ptr simple_light_task_delegate; diff --git a/source/blender/render/hydra/final_engine.cc b/source/blender/render/hydra/final_engine.cc index 54e55fbbfa0f..281c68cb6376 100644 --- a/source/blender/render/hydra/final_engine.cc +++ b/source/blender/render/hydra/final_engine.cc @@ -16,11 +16,11 @@ void FinalEngine::sync(Depsgraph *depsgraph, bContext *context, pxr::HdRenderSettingsMap &render_settings) { - scene_delegate = std::make_unique( + scene_delegate_ = std::make_unique( render_index.get(), pxr::SdfPath::AbsoluteRootPath().AppendElementString("scene"), BlenderSceneDelegate::EngineType::FINAL); - scene_delegate->populate(depsgraph, context); + scene_delegate_->populate(depsgraph, context); for (auto const &setting : render_settings) { render_delegate->SetRenderSetting(setting.first, setting.second); diff --git a/source/blender/render/hydra/preview_engine.cc b/source/blender/render/hydra/preview_engine.cc index ffb9891952e2..e69189411aa7 100644 --- a/source/blender/render/hydra/preview_engine.cc +++ b/source/blender/render/hydra/preview_engine.cc @@ -56,14 +56,14 @@ void PreviewEngine::sync(Depsgraph *depsgraph, bContext *context, pxr::HdRenderSettingsMap &render_settings) { - if (!scene_delegate) { - scene_delegate = std::make_unique( + if (!scene_delegate_) { + scene_delegate_ = std::make_unique( render_index.get(), pxr::SdfPath::AbsoluteRootPath().AppendElementString("scene"), BlenderSceneDelegate::EngineType::PREVIEW); } - scene_delegate->clear(); - scene_delegate->populate(depsgraph, context); + scene_delegate_->clear(); + scene_delegate_->populate(depsgraph, context); for (auto const &setting : render_settings) { render_delegate->SetRenderSetting(setting.first, setting.second); diff --git a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc index c89b55353ed0..f5481b6736f0 100644 --- a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc +++ b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc @@ -18,29 +18,208 @@ BlenderSceneDelegate::BlenderSceneDelegate(pxr::HdRenderIndex *parent_index, BlenderSceneDelegate::EngineType engine_type) : HdSceneDelegate(parent_index, delegate_id), engine_type(engine_type), - depsgraph(nullptr), - context(nullptr), - view3d(nullptr) + depsgraph_(nullptr), + context_(nullptr), + view3d_(nullptr) { } -void BlenderSceneDelegate::update_world() +void BlenderSceneDelegate::populate(Depsgraph *deps, bContext *cont) { - World *world = scene->world; - if (!world_data) { - if (world) { - world_data = WorldData::create(this, world, context); + bool is_populated = depsgraph_ != nullptr; + + depsgraph_ = deps; + context_ = cont; + scene_ = DEG_get_input_scene(depsgraph_); + view3d_ = CTX_wm_view3d(context_); + + if (!is_populated) { + /* Export initial objects */ + update_collection(false, false); + update_world(); + return; + } + + /* Working with updates */ + bool do_update_collection = false; + bool do_update_visibility = false; + bool do_update_world = false; + + unsigned int scene_recalc = ((ID *)scene_)->recalc; + if (scene_recalc) { + /* Checking scene updates */ + CLOG_INFO(LOG_BSD, + 2, + "Update: %s [%s]", + ((ID *)scene_)->name, + std::bitset<32>(scene_recalc).to_string().c_str()); + + if (scene_recalc & ID_RECALC_BASE_FLAGS) { + do_update_visibility = true; + } + if (scene_recalc & (ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY)) { + do_update_collection = true; + } + if (scene_recalc & ID_RECALC_AUDIO_VOLUME) { + if ((scene_->world && !world_data_) || (!scene_->world && world_data_)) { + do_update_world = true; + } + } + if (do_update_collection || do_update_visibility) { + update_collection(do_update_collection, do_update_visibility); } } - else { - if (world) { - world_data->update(world); - } - else { - world_data->remove(); - world_data = nullptr; + + /* Checking other objects updates */ + DEGIDIterData data = {0}; + data.graph = depsgraph_; + data.only_updated = true; + ITER_BEGIN ( + DEG_iterator_ids_begin, DEG_iterator_ids_next, DEG_iterator_ids_end, &data, ID *, id) { + + CLOG_INFO( + LOG_BSD, 2, "Update: %s [%s]", id->name, std::bitset<32>(id->recalc).to_string().c_str()); + + switch (GS(id->name)) { + case ID_OB: { + Object *object = (Object *)id; + if (!ObjectData::is_supported(object)) { + break; + } + add_update_object(object); + } break; + + case ID_MA: { + MaterialData *mat_data = get_material_data( + MaterialData::get_prim_id(this, (Material *)id)); + if (mat_data) { + mat_data->update(); + } + } break; + + case ID_WO: { + if (id->recalc & ID_RECALC_SHADING) { + do_update_world = true; + } + } break; + + default: + break; } } + ITER_END; + + if (do_update_world) { + update_world(); + } +} + +void BlenderSceneDelegate::clear() +{ + for (auto &it : materials_) { + it.second->remove(); + } + + for (auto &it : objects_) { + it.second->remove(); + } + + materials_.clear(); + objects_.clear(); +} + +pxr::HdMeshTopology BlenderSceneDelegate::GetMeshTopology(pxr::SdfPath const &id) +{ + CLOG_INFO(LOG_BSD, 3, "%s", id.GetText()); + MeshData *m_data = get_mesh_data(id); + return m_data->get_mesh_topology(); +} + +pxr::GfMatrix4d BlenderSceneDelegate::GetTransform(pxr::SdfPath const &id) +{ + CLOG_INFO(LOG_BSD, 3, "%s", id.GetText()); + ObjectData *obj_data = get_object_data(id); + if (obj_data) { + return obj_data->get_transform(); + } + + if (id == WorldData::get_prim_id(this)) { + return world_data_->get_transform(); + } + + InstancerData *i_data = get_instancer_data(id); + if (i_data) { + return i_data->get_transform(); + } + + return pxr::GfMatrix4d(); +} + +pxr::VtValue BlenderSceneDelegate::Get(pxr::SdfPath const &id, pxr::TfToken const &key) +{ + CLOG_INFO(LOG_BSD, 3, "%s, %s", id.GetText(), key.GetText()); + + ObjectData *obj_data = get_object_data(id); + if (obj_data) { + return obj_data->get_data(key); + } + + MaterialData *mat_data = get_material_data(id); + if (mat_data) { + return mat_data->get_data(key); + } + + InstancerData *i_data = get_instancer_data(id); + if (i_data) { + return i_data->get_data(key); + } + + return pxr::VtValue(); +} + +pxr::VtValue BlenderSceneDelegate::GetLightParamValue(pxr::SdfPath const &id, + pxr::TfToken const &key) +{ + LightData *l_data = get_light_data(id); + if (l_data) { + return l_data->get_data(key); + } + if (id == WorldData::get_prim_id(this)) { + return world_data_->get_data(key); + } + return pxr::VtValue(); +} + +pxr::HdPrimvarDescriptorVector BlenderSceneDelegate::GetPrimvarDescriptors( + pxr::SdfPath const &id, pxr::HdInterpolation interpolation) +{ + CLOG_INFO(LOG_BSD, 3, "%s, %d", id.GetText(), interpolation); + + MeshData *m_data = get_mesh_data(id); + if (m_data) { + return m_data->get_primvar_descriptors(interpolation); + } + + InstancerData *i_data = get_instancer_data(id); + if (i_data) { + return i_data->get_instancer_primvar_descriptors(interpolation); + } + + return pxr::HdPrimvarDescriptorVector(); +} + +pxr::SdfPath BlenderSceneDelegate::GetMaterialId(pxr::SdfPath const &rprim_id) +{ + return get_mesh_data(rprim_id)->get_material_id(); +} + +pxr::VtValue BlenderSceneDelegate::GetMaterialResource(pxr::SdfPath const &id) +{ + MaterialData *mat_data = get_material_data(id); + if (mat_data) { + return mat_data->get_material_resource(); + } + return pxr::VtValue(); } bool BlenderSceneDelegate::GetVisible(pxr::SdfPath const &id) @@ -85,12 +264,116 @@ pxr::GfMatrix4d BlenderSceneDelegate::GetInstancerTransform(pxr::SdfPath const & return i_data->get_transform(); } +ObjectData *BlenderSceneDelegate::get_object_data(pxr::SdfPath const &id) +{ + auto it = objects_.find(id); + if (it == objects_.end()) { + return nullptr; + } + return it->second.get(); +} + +MeshData *BlenderSceneDelegate::get_mesh_data(pxr::SdfPath const &id) +{ + return dynamic_cast(get_object_data(id)); +} + +LightData *BlenderSceneDelegate::get_light_data(pxr::SdfPath const &id) +{ + return dynamic_cast(get_object_data(id)); +} + +MaterialData *BlenderSceneDelegate::get_material_data(pxr::SdfPath const &id) +{ + auto it = materials_.find(id); + if (it == materials_.end()) { + return nullptr; + } + return it->second.get(); +} + +InstancerData *BlenderSceneDelegate::get_instancer_data(pxr::SdfPath const &id, bool base_prim) +{ + if (base_prim) { + return dynamic_cast(get_object_data(id)); + } + return dynamic_cast(get_object_data(id.GetParentPath())); +} + +InstancerData *BlenderSceneDelegate::get_instancer_data(Object *object) +{ + InstancerData *i_data; + for (auto &it : objects_) { + i_data = dynamic_cast(it.second.get()); + if (i_data && i_data->is_base(object)) { + return i_data; + } + } + return nullptr; +} + +void BlenderSceneDelegate::add_update_object(Object *object) +{ + if ((object->transflag & OB_DUPLI) && InstancerData::is_supported(object)) { + add_update_instancer(object); + } + InstancerData *i_data = get_instancer_data(object); + if (i_data) { + i_data->update(); + } + + pxr::SdfPath id = ObjectData::get_prim_id(this, object); + ObjectData *obj_data = get_object_data(id); + if (obj_data) { + obj_data->update(); + return; + } + if (view3d_ && !BKE_object_is_visible_in_viewport(view3d_, object)) { + return; + } + objects_[id] = ObjectData::create(this, object); + obj_data = get_object_data(id); + obj_data->update_visibility(view3d_); +} + +void BlenderSceneDelegate::add_update_instancer(Object *object) +{ + pxr::SdfPath id = InstancerData::get_prim_id(this, object); + InstancerData *i_data = get_instancer_data(id, true); + if (i_data) { + i_data->update(); + return; + } + objects_[id] = InstancerData::create(this, object); + i_data = get_instancer_data(id, true); + i_data->update_visibility(view3d_); +} + +void BlenderSceneDelegate::update_world() +{ + World *world = scene_->world; + if (!world_data_) { + if (world) { + world_data_ = WorldData::create(this, world, context_); + } + } + else { + if (world) { + world_data_->update(world); + } + else { + world_data_->remove(); + world_data_ = nullptr; + } + } +} + void BlenderSceneDelegate::update_collection(bool remove, bool visibility) { if (visibility) { /* Check and update visibility */ - for (auto &obj : objects) { - obj.second->update_visibility(view3d); + for (auto &obj : objects_) { + obj.second->update_visibility(view3d_); } } @@ -99,7 +382,7 @@ void BlenderSceneDelegate::update_collection(bool remove, bool visibility) pxr::SdfPath id; 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}; @@ -134,18 +417,18 @@ void BlenderSceneDelegate::update_collection(bool remove, bool visibility) if (remove) { /* remove unused objects */ - for (auto it = objects.begin(); it != objects.end(); ++it) { + for (auto it = objects_.begin(); it != objects_.end(); ++it) { if (available_objects.find(it->first) != available_objects.end()) { continue; } it->second->remove(); - objects.erase(it); - it = objects.begin(); + objects_.erase(it); + it = objects_.begin(); } /* remove unused materials */ std::set available_materials; - for (auto &obj : objects) { + for (auto &obj : objects_) { MeshData *m_data = dynamic_cast(obj.second.get()); if (!m_data) { continue; @@ -155,297 +438,15 @@ void BlenderSceneDelegate::update_collection(bool remove, bool visibility) available_materials.insert(mat_id); } } - for (auto it = materials.begin(); it != materials.end(); ++it) { + for (auto it = materials_.begin(); it != materials_.end(); ++it) { if (available_materials.find(it->first) != available_materials.end()) { continue; } it->second->remove(); - materials.erase(it); - it = materials.begin(); + materials_.erase(it); + it = materials_.begin(); } } } -void BlenderSceneDelegate::add_update_object(Object *object) -{ - if ((object->transflag & OB_DUPLI) && InstancerData::is_supported(object)) { - add_update_instancer(object); - } - InstancerData *i_data = get_instancer_data(object); - if (i_data) { - i_data->update(); - } - - pxr::SdfPath id = ObjectData::get_prim_id(this, object); - ObjectData *obj_data = get_object_data(id); - if (obj_data) { - obj_data->update(); - return; - } - if (view3d && !BKE_object_is_visible_in_viewport(view3d, object)) { - return; - } - objects[id] = ObjectData::create(this, object); - obj_data = get_object_data(id); - obj_data->update_visibility(view3d); -} - -void BlenderSceneDelegate::add_update_instancer(Object *object) -{ - pxr::SdfPath id = InstancerData::get_prim_id(this, object); - InstancerData *i_data = get_instancer_data(id, true); - if (i_data) { - i_data->update(); - return; - } - objects[id] = InstancerData::create(this, object); - i_data = get_instancer_data(id, true); - i_data->update_visibility(view3d); -} - -ObjectData *BlenderSceneDelegate::get_object_data(pxr::SdfPath const &id) -{ - auto it = objects.find(id); - if (it == objects.end()) { - return nullptr; - } - return it->second.get(); -} - -MeshData *BlenderSceneDelegate::get_mesh_data(pxr::SdfPath const &id) -{ - return dynamic_cast(get_object_data(id)); -} - -LightData *BlenderSceneDelegate::get_light_data(pxr::SdfPath const &id) -{ - return dynamic_cast(get_object_data(id)); -} - -MaterialData *BlenderSceneDelegate::get_material_data(pxr::SdfPath const &id) -{ - auto it = materials.find(id); - if (it == materials.end()) { - return nullptr; - } - return it->second.get(); -} - -InstancerData *BlenderSceneDelegate::get_instancer_data(pxr::SdfPath const &id, bool base_prim) -{ - if (base_prim) { - return dynamic_cast(get_object_data(id)); - } - return dynamic_cast(get_object_data(id.GetParentPath())); -} - -InstancerData *BlenderSceneDelegate::get_instancer_data(Object *object) -{ - InstancerData *i_data; - for (auto &it : objects) { - i_data = dynamic_cast(it.second.get()); - if (i_data && i_data->is_base(object)) { - return i_data; - } - } - return nullptr; -} - -void BlenderSceneDelegate::populate(Depsgraph *deps, bContext *cont) -{ - bool is_populated = depsgraph != nullptr; - - depsgraph = deps; - context = cont; - scene = DEG_get_input_scene(depsgraph); - view3d = CTX_wm_view3d(context); - - if (!is_populated) { - /* Export initial objects */ - update_collection(false, false); - update_world(); - return; - } - - /* Working with updates */ - bool do_update_collection = false; - bool do_update_visibility = false; - bool do_update_world = false; - - unsigned int scene_recalc = ((ID *)scene)->recalc; - if (scene_recalc) { - /* Checking scene updates */ - CLOG_INFO(LOG_BSD, - 2, - "Update: %s [%s]", - ((ID *)scene)->name, - std::bitset<32>(scene_recalc).to_string().c_str()); - - if (scene_recalc & ID_RECALC_BASE_FLAGS) { - do_update_visibility = true; - } - if (scene_recalc & (ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY)) { - do_update_collection = true; - } - if (scene_recalc & ID_RECALC_AUDIO_VOLUME) { - if ((scene->world && !world_data) || (!scene->world && world_data)) { - do_update_world = true; - } - } - if (do_update_collection || do_update_visibility) { - update_collection(do_update_collection, do_update_visibility); - } - } - - /* Checking other objects updates */ - DEGIDIterData data = {0}; - data.graph = depsgraph; - data.only_updated = true; - ITER_BEGIN ( - DEG_iterator_ids_begin, DEG_iterator_ids_next, DEG_iterator_ids_end, &data, ID *, id) { - - CLOG_INFO( - LOG_BSD, 2, "Update: %s [%s]", id->name, std::bitset<32>(id->recalc).to_string().c_str()); - - switch (GS(id->name)) { - case ID_OB: { - Object *object = (Object *)id; - if (!ObjectData::is_supported(object)) { - break; - } - add_update_object(object); - } break; - - case ID_MA: { - MaterialData *mat_data = get_material_data(MaterialData::get_prim_id(this, (Material *)id)); - if (mat_data) { - mat_data->update(); - } - } break; - - case ID_WO: { - if (id->recalc & ID_RECALC_SHADING) { - do_update_world = true; - } - } break; - - default: - break; - } - } - ITER_END; - - if (do_update_world) { - update_world(); - } -} - -pxr::HdMeshTopology BlenderSceneDelegate::GetMeshTopology(pxr::SdfPath const &id) -{ - CLOG_INFO(LOG_BSD, 3, "%s", id.GetText()); - MeshData *m_data = get_mesh_data(id); - return m_data->get_mesh_topology(); -} - -pxr::VtValue BlenderSceneDelegate::Get(pxr::SdfPath const &id, pxr::TfToken const &key) -{ - CLOG_INFO(LOG_BSD, 3, "%s, %s", id.GetText(), key.GetText()); - - ObjectData *obj_data = get_object_data(id); - if (obj_data) { - return obj_data->get_data(key); - } - - MaterialData *mat_data = get_material_data(id); - if (mat_data) { - return mat_data->get_data(key); - } - - InstancerData *i_data = get_instancer_data(id); - if (i_data) { - return i_data->get_data(key); - } - - return pxr::VtValue(); -} - -pxr::HdPrimvarDescriptorVector BlenderSceneDelegate::GetPrimvarDescriptors( - pxr::SdfPath const &id, pxr::HdInterpolation interpolation) -{ - CLOG_INFO(LOG_BSD, 3, "%s, %d", id.GetText(), interpolation); - - MeshData *m_data = get_mesh_data(id); - if (m_data) { - return m_data->get_primvar_descriptors(interpolation); - } - - InstancerData *i_data = get_instancer_data(id); - if (i_data) { - return i_data->get_instancer_primvar_descriptors(interpolation); - } - - return pxr::HdPrimvarDescriptorVector(); -} - -pxr::SdfPath BlenderSceneDelegate::GetMaterialId(pxr::SdfPath const &rprim_id) -{ - return get_mesh_data(rprim_id)->get_material_id(); -} - -pxr::VtValue BlenderSceneDelegate::GetMaterialResource(pxr::SdfPath const &id) -{ - MaterialData *mat_data = get_material_data(id); - if (mat_data) { - return mat_data->get_material_resource(); - } - return pxr::VtValue(); -} - -pxr::GfMatrix4d BlenderSceneDelegate::GetTransform(pxr::SdfPath const &id) -{ - CLOG_INFO(LOG_BSD, 3, "%s", id.GetText()); - ObjectData *obj_data = get_object_data(id); - if (obj_data) { - return obj_data->get_transform(); - } - - if (id == WorldData::get_prim_id(this)) { - return world_data->get_transform(); - } - - InstancerData *i_data = get_instancer_data(id); - if (i_data) { - return i_data->get_transform(); - } - - return pxr::GfMatrix4d(); -} - -pxr::VtValue BlenderSceneDelegate::GetLightParamValue(pxr::SdfPath const &id, - pxr::TfToken const &key) -{ - LightData *l_data = get_light_data(id); - if (l_data) { - return l_data->get_data(key); - } - if (id == WorldData::get_prim_id(this)) { - return world_data->get_data(key); - } - return pxr::VtValue(); -} - -void BlenderSceneDelegate::clear() -{ - for (auto &it : materials) { - it.second->remove(); - } - - for (auto &it : objects) { - it.second->remove(); - } - - materials.clear(); - objects.clear(); -} - } // namespace blender::render::hydra diff --git a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.h b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.h index 6e2d1e2dfee2..7684ca95b308 100644 --- a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.h +++ b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.h @@ -27,7 +27,7 @@ class BlenderSceneDelegate : public pxr::HdSceneDelegate { public: enum class EngineType { VIEWPORT = 1, FINAL, PREVIEW }; - BlenderSceneDelegate(pxr::HdRenderIndex *render_index, + BlenderSceneDelegate(pxr::HdRenderIndex *parent_index, pxr::SdfPath const &delegate_id, BlenderSceneDelegate::EngineType engine_type); ~BlenderSceneDelegate() override = default; @@ -35,7 +35,7 @@ class BlenderSceneDelegate : public pxr::HdSceneDelegate { void populate(Depsgraph *depsgraph, bContext *context); void clear(); - // delegate methods + /* Delegate methods */ pxr::HdMeshTopology GetMeshTopology(pxr::SdfPath const &id) override; pxr::GfMatrix4d GetTransform(pxr::SdfPath const &id) override; pxr::VtValue Get(pxr::SdfPath const &id, pxr::TfToken const &key) override; @@ -51,7 +51,6 @@ class BlenderSceneDelegate : public pxr::HdSceneDelegate { pxr::SdfPath const &prototype_id) override; pxr::GfMatrix4d GetInstancerTransform(pxr::SdfPath const &instancer_id) override; - public: EngineType engine_type; private: @@ -67,15 +66,14 @@ class BlenderSceneDelegate : public pxr::HdSceneDelegate { void update_world(); void update_collection(bool remove, bool visibility); - private: - Depsgraph *depsgraph; - bContext *context; - Scene *scene; - View3D *view3d; + Depsgraph *depsgraph_; + bContext *context_; + Scene *scene_; + View3D *view3d_; - ObjectDataMap objects; - MaterialDataMap materials; - std::unique_ptr world_data; + ObjectDataMap objects_; + MaterialDataMap materials_; + std::unique_ptr world_data_; }; } // namespace blender::render::hydra diff --git a/source/blender/render/hydra/scene_delegate/id.cc b/source/blender/render/hydra/scene_delegate/id.cc index 7c0a28be9de2..c2f048d796e0 100644 --- a/source/blender/render/hydra/scene_delegate/id.cc +++ b/source/blender/render/hydra/scene_delegate/id.cc @@ -9,7 +9,7 @@ namespace blender::render::hydra { IdData::IdData(BlenderSceneDelegate *scene_delegate, ID *id) - : scene_delegate(scene_delegate), id(id) + : scene_delegate_(scene_delegate), id_(id) { } diff --git a/source/blender/render/hydra/scene_delegate/id.h b/source/blender/render/hydra/scene_delegate/id.h index 8d36f8e2d3c1..5ece38101c9b 100644 --- a/source/blender/render/hydra/scene_delegate/id.h +++ b/source/blender/render/hydra/scene_delegate/id.h @@ -27,9 +27,9 @@ class IdData { template const T get_data(pxr::TfToken const &key) const; protected: - BlenderSceneDelegate *scene_delegate; - ID *id; - pxr::SdfPath p_id; + BlenderSceneDelegate *scene_delegate_; + ID *id_; + pxr::SdfPath p_id_; }; template const T IdData::get_data(pxr::TfToken const &key) const diff --git a/source/blender/render/hydra/scene_delegate/instancer.cc b/source/blender/render/hydra/scene_delegate/instancer.cc index 3925cf4950ed..5f5f3774a3ea 100644 --- a/source/blender/render/hydra/scene_delegate/instancer.cc +++ b/source/blender/render/hydra/scene_delegate/instancer.cc @@ -9,6 +9,15 @@ namespace blender::render::hydra { +InstancerData::InstancerData(BlenderSceneDelegate *scene_delegate, Object *object) + : MeshData(scene_delegate, object), parent_obj_(object) +{ + id_ = nullptr; + p_id_ = get_prim_id(scene_delegate, object); + instancer_id = p_id_.AppendElementString("Instancer"); + CLOG_INFO(LOG_BSD, 2, "%s, instancer_id=%s", ((ID *)parent_obj_)->name, instancer_id.GetText()); +} + bool InstancerData::is_supported(Object *object) { switch (object->type) { @@ -43,23 +52,75 @@ pxr::SdfPath InstancerData::get_prim_id(BlenderSceneDelegate *scene_delegate, Ob return scene_delegate->GetDelegateID().AppendElementString(str); } -InstancerData::InstancerData(BlenderSceneDelegate *scene_delegate, Object *object) - : MeshData(scene_delegate, object), parent_obj(object) -{ - id = nullptr; - p_id = get_prim_id(scene_delegate, object); - instancer_id = p_id.AppendElementString("Instancer"); - CLOG_INFO(LOG_BSD, 2, "%s, instancer_id=%s", ((ID *)parent_obj)->name, instancer_id.GetText()); -} - void InstancerData::init() { - CLOG_INFO(LOG_BSD, 2, "%s", ((ID *)parent_obj)->name); + CLOG_INFO(LOG_BSD, 2, "%s", ((ID *)parent_obj_)->name); set_instances(); MeshData::init(); } +void InstancerData::insert() +{ + CLOG_INFO(LOG_BSD, 2, "%s", ((ID *)parent_obj_)->name); + MeshData::insert(); + + if (face_vertex_counts_.empty()) { + return; + } + scene_delegate_->GetRenderIndex().InsertInstancer(scene_delegate_, instancer_id); +} + +void InstancerData::remove() +{ + CLOG_INFO(LOG_BSD, 2, "%s", ((ID *)parent_obj_)->name); + + if (!scene_delegate_->GetRenderIndex().HasInstancer(instancer_id)) { + return; + } + scene_delegate_->GetRenderIndex().RemoveInstancer(instancer_id); + + MeshData::remove(); +} + +void InstancerData::update() +{ + CLOG_INFO(LOG_BSD, 2, "%s", ((ID *)parent_obj_)->name); + + pxr::HdDirtyBits bits = pxr::HdChangeTracker::Clean; + unsigned int recalc = ((ID *)parent_obj_)->recalc; + + Object *object = (Object *)id_; + if ((id_->recalc & ID_RECALC_GEOMETRY) || (((ID *)object->data)->recalc & ID_RECALC_GEOMETRY)) { + init(); + scene_delegate_->GetRenderIndex().GetChangeTracker().MarkRprimDirty( + p_id_, pxr::HdChangeTracker::AllDirty); + return; + } + + if ((recalc & ID_RECALC_GEOMETRY) || (((ID *)parent_obj_->data)->recalc & ID_RECALC_GEOMETRY)) { + init(); + bits |= pxr::HdChangeTracker::AllDirty; + } + else if (recalc & ID_RECALC_TRANSFORM || id_->recalc & ID_RECALC_TRANSFORM) { + set_instances(); + bits |= pxr::HdChangeTracker::DirtyTransform; + } + if (bits != pxr::HdChangeTracker::Clean) { + scene_delegate_->GetRenderIndex().GetChangeTracker().MarkInstancerDirty(instancer_id, bits); + } +} + +pxr::VtValue InstancerData::get_data(pxr::TfToken const &key) const +{ + CLOG_INFO(LOG_BSD, 3, "%s [%s]", id_->name, key.GetText()); + + if (key == pxr::HdInstancerTokens->instanceTransform) { + return pxr::VtValue(transforms_); + } + return MeshData::get_data(key); +} + pxr::GfMatrix4d InstancerData::get_transform() { return pxr::GfMatrix4d(1.0); @@ -72,25 +133,15 @@ bool InstancerData::update_visibility(View3D *view3d) } bool prev_visible = visible; - visible = BKE_object_is_visible_in_viewport(view3d, parent_obj); + visible = BKE_object_is_visible_in_viewport(view3d, parent_obj_); bool ret = visible != prev_visible; if (ret) { - scene_delegate->GetRenderIndex().GetChangeTracker().MarkRprimDirty( - p_id, pxr::HdChangeTracker::DirtyVisibility); + scene_delegate_->GetRenderIndex().GetChangeTracker().MarkRprimDirty( + p_id_, pxr::HdChangeTracker::DirtyVisibility); } return ret; } -pxr::VtValue InstancerData::get_data(pxr::TfToken const &key) const -{ - CLOG_INFO(LOG_BSD, 3, "%s [%s]", id->name, key.GetText()); - - if (key == pxr::HdInstancerTokens->instanceTransform) { - return pxr::VtValue(transforms); - } - return MeshData::get_data(key); -} - pxr::HdPrimvarDescriptorVector InstancerData::get_instancer_primvar_descriptors( pxr::HdInterpolation interpolation) { @@ -104,7 +155,7 @@ pxr::HdPrimvarDescriptorVector InstancerData::get_instancer_primvar_descriptors( pxr::VtIntArray InstancerData::get_instance_indices() { - pxr::VtIntArray ret(transforms.size()); + pxr::VtIntArray ret(transforms_.size()); for (size_t i = 0; i < ret.size(); ++i) { ret[i] = i; } @@ -113,82 +164,31 @@ pxr::VtIntArray InstancerData::get_instance_indices() bool InstancerData::is_base(Object *object) const { - return (ID *)object == id; + return (ID *)object == id_; } bool InstancerData::set_instances() { - ID *prev_id = id; - id = nullptr; - transforms.clear(); - ListBase *lb = object_duplilist(scene_delegate->depsgraph, scene_delegate->scene, parent_obj); + ID *prev_id = id_; + id_ = nullptr; + transforms_.clear(); + ListBase *lb = object_duplilist(scene_delegate_->depsgraph_, scene_delegate_->scene_, parent_obj_); LISTBASE_FOREACH (DupliObject *, dupli, lb) { - if (!id) { + if (!id_) { /* TODO: We create instances only for object in first dupli. Instances should be created for all objects */ - id = (ID *)dupli->ob; + id_ = (ID *)dupli->ob; } - if (id != (ID *)dupli->ob) { + if (id_ != (ID *)dupli->ob) { continue; } - transforms.push_back(gf_matrix_from_transform(dupli->mat)); + transforms_.push_back(gf_matrix_from_transform(dupli->mat)); CLOG_INFO( - LOG_BSD, 2, "Instance %s (%s) %d", id->name, ((ID *)dupli->ob)->name, dupli->random_id); + LOG_BSD, 2, "Instance %s (%s) %d", id_->name, ((ID *)dupli->ob)->name, dupli->random_id); } free_object_duplilist(lb); - return id != prev_id; -} - -void InstancerData::insert() -{ - CLOG_INFO(LOG_BSD, 2, "%s", ((ID *)parent_obj)->name); - MeshData::insert(); - - if (face_vertex_counts.empty()) { - return; - } - scene_delegate->GetRenderIndex().InsertInstancer(scene_delegate, instancer_id); -} - -void InstancerData::remove() -{ - CLOG_INFO(LOG_BSD, 2, "%s", ((ID *)parent_obj)->name); - - if (!scene_delegate->GetRenderIndex().HasInstancer(instancer_id)) { - return; - } - scene_delegate->GetRenderIndex().RemoveInstancer(instancer_id); - - MeshData::remove(); -} - -void InstancerData::update() -{ - CLOG_INFO(LOG_BSD, 2, "%s", ((ID *)parent_obj)->name); - - pxr::HdDirtyBits bits = pxr::HdChangeTracker::Clean; - unsigned int recalc = ((ID *)parent_obj)->recalc; - - Object *object = (Object *)id; - if ((id->recalc & ID_RECALC_GEOMETRY) || (((ID *)object->data)->recalc & ID_RECALC_GEOMETRY)) { - init(); - scene_delegate->GetRenderIndex().GetChangeTracker().MarkRprimDirty( - p_id, pxr::HdChangeTracker::AllDirty); - return; - } - - if ((recalc & ID_RECALC_GEOMETRY) || (((ID *)parent_obj->data)->recalc & ID_RECALC_GEOMETRY)) { - init(); - bits |= pxr::HdChangeTracker::AllDirty; - } - else if (recalc & ID_RECALC_TRANSFORM || id->recalc & ID_RECALC_TRANSFORM) { - set_instances(); - bits |= pxr::HdChangeTracker::DirtyTransform; - } - if (bits != pxr::HdChangeTracker::Clean) { - scene_delegate->GetRenderIndex().GetChangeTracker().MarkInstancerDirty(instancer_id, bits); - } + return id_ != prev_id; } } // namespace blender::render::hydra diff --git a/source/blender/render/hydra/scene_delegate/instancer.h b/source/blender/render/hydra/scene_delegate/instancer.h index e80d40001ab6..f057e7c342ee 100644 --- a/source/blender/render/hydra/scene_delegate/instancer.h +++ b/source/blender/render/hydra/scene_delegate/instancer.h @@ -11,13 +11,13 @@ namespace blender::render::hydra { class InstancerData : public MeshData { public: + InstancerData(BlenderSceneDelegate *scene_delegate, Object *object); + static bool is_supported(Object *object); static std::unique_ptr create(BlenderSceneDelegate *scene_delegate, Object *object); static pxr::SdfPath get_prim_id(BlenderSceneDelegate *scene_delegate, Object *object); - InstancerData(BlenderSceneDelegate *scene_delegate, Object *object); - void init() override; void insert() override; void remove() override; @@ -29,15 +29,15 @@ class InstancerData : public MeshData { pxr::HdPrimvarDescriptorVector get_instancer_primvar_descriptors(pxr::HdInterpolation interpolation); pxr::VtIntArray get_instance_indices(); - bool is_base(Object *object) const; + pxr::SdfPath instancer_id; private: - Object *parent_obj; - pxr::VtMatrix4dArray transforms; - bool set_instances(); + + Object *parent_obj_; + pxr::VtMatrix4dArray transforms_; }; } // namespace blender::render::hydra diff --git a/source/blender/render/hydra/scene_delegate/light.cc b/source/blender/render/hydra/scene_delegate/light.cc index 2e9c3085df10..a63d919325d9 100644 --- a/source/blender/render/hydra/scene_delegate/light.cc +++ b/source/blender/render/hydra/scene_delegate/light.cc @@ -17,72 +17,138 @@ namespace blender::render::hydra { LightData::LightData(BlenderSceneDelegate *scene_delegate, Object *object) : ObjectData(scene_delegate, object) { - CLOG_INFO(LOG_BSD, 2, "%s id=%s", id->name, p_id.GetText()); + CLOG_INFO(LOG_BSD, 2, "%s id=%s", id_->name, p_id_.GetText()); } void LightData::init() { - CLOG_INFO(LOG_BSD, 2, "%s", id->name); + CLOG_INFO(LOG_BSD, 2, "%s", id_->name); - Light *light = (Light *)((Object *)id)->data; - data.clear(); + Light *light = (Light *)((Object *)id_)->data; + data_.clear(); float intensity = light->energy; - if (scene_delegate->engine_type == BlenderSceneDelegate::EngineType::PREVIEW) { + if (scene_delegate_->engine_type == BlenderSceneDelegate::EngineType::PREVIEW) { intensity *= 0.001; } - data[pxr::HdLightTokens->intensity] = intensity; + data_[pxr::HdLightTokens->intensity] = intensity; - data[pxr::HdLightTokens->color] = pxr::GfVec3f(light->r, light->g, light->b); + data_[pxr::HdLightTokens->color] = pxr::GfVec3f(light->r, light->g, light->b); switch (light->type) { case LA_LOCAL: - data[pxr::HdLightTokens->radius] = light->area_size / 2; + data_[pxr::HdLightTokens->radius] = light->area_size / 2; break; case LA_SUN: - data[pxr::HdLightTokens->angle] = light->sun_angle * 180.0 / M_PI; + data_[pxr::HdLightTokens->angle] = light->sun_angle * 180.0 / M_PI; break; case LA_SPOT: - data[pxr::HdLightTokens->shapingConeAngle] = light->spotsize / 2; - data[pxr::HdLightTokens->shapingConeSoftness] = light->spotblend; - data[pxr::UsdLuxTokens->treatAsPoint] = true; + data_[pxr::HdLightTokens->shapingConeAngle] = light->spotsize / 2; + data_[pxr::HdLightTokens->shapingConeSoftness] = light->spotblend; + data_[pxr::UsdLuxTokens->treatAsPoint] = true; break; case LA_AREA: switch (light->area_shape) { case LA_AREA_SQUARE: - data[pxr::HdLightTokens->width] = light->area_size; - data[pxr::HdLightTokens->height] = light->area_size; + data_[pxr::HdLightTokens->width] = light->area_size; + data_[pxr::HdLightTokens->height] = light->area_size; break; case LA_AREA_RECT: - data[pxr::HdLightTokens->width] = light->area_size; - data[pxr::HdLightTokens->height] = light->area_sizey; + data_[pxr::HdLightTokens->width] = light->area_size; + data_[pxr::HdLightTokens->height] = light->area_sizey; break; case LA_AREA_DISK: - data[pxr::HdLightTokens->radius] = light->area_size / 2; + data_[pxr::HdLightTokens->radius] = light->area_size / 2; break; case LA_AREA_ELLIPSE: - data[pxr::HdLightTokens->radius] = (light->area_size + light->area_sizey) / 4; + data_[pxr::HdLightTokens->radius] = (light->area_size + light->area_sizey) / 4; break; default: break; } - data[pxr::HdLightTokens->normalize] = true; + data_[pxr::HdLightTokens->normalize] = true; break; default: break; } - p_type = get_prim_type(light); + p_type_ = get_prim_type(light); /* TODO: temporary value, it should be delivered through Python UI */ - data[pxr::HdLightTokens->exposure] = 1.0f; + data_[pxr::HdLightTokens->exposure] = 1.0f; +} + +void LightData::insert() +{ + CLOG_INFO(LOG_BSD, 2, "%s", id_->name); + scene_delegate_->GetRenderIndex().InsertSprim(p_type_, scene_delegate_, p_id_); +} + +void LightData::remove() +{ + CLOG_INFO(LOG_BSD, 2, "%s", id_->name); + scene_delegate_->GetRenderIndex().RemoveSprim(p_type_, p_id_); +} + +void LightData::update() +{ + CLOG_INFO(LOG_BSD, 2, "%s", id_->name); + + Light *light = (Light *)((Object *)id_)->data; + if (get_prim_type(light) != p_type_) { + remove(); + init(); + insert(); + return; + } + + pxr::HdDirtyBits bits = pxr::HdLight::Clean; + if (id_->recalc & ID_RECALC_GEOMETRY) { + init(); + bits = pxr::HdLight::AllDirty; + } + else if (id_->recalc & ID_RECALC_TRANSFORM) { + bits = pxr::HdLight::DirtyTransform; + } + scene_delegate_->GetRenderIndex().GetChangeTracker().MarkSprimDirty(p_id_, bits); +} + +pxr::VtValue LightData::get_data(pxr::TfToken const &key) const +{ + pxr::VtValue ret; + auto it = data_.find(key); + if (it != data_.end()) { + ret = it->second; + } + else { + std::string n = key.GetString(); + if (boost::algorithm::contains(n, "object:visibility:")) { + if (boost::algorithm::ends_with(n, "camera") || boost::algorithm::ends_with(n, "shadow")) { + ret = false; + } + else { + ret = true; + } + } + } + return ret; +} + +bool LightData::update_visibility(View3D *view3d) +{ + bool ret = ObjectData::update_visibility(view3d); + if (ret) { + scene_delegate_->GetRenderIndex().GetChangeTracker().MarkSprimDirty(p_id_, + pxr::HdLight::DirtyParams); + } + return ret; } pxr::TfToken LightData::get_prim_type(Light *light) @@ -121,70 +187,4 @@ pxr::TfToken LightData::get_prim_type(Light *light) return ret; } -pxr::VtValue LightData::get_data(pxr::TfToken const &key) const -{ - pxr::VtValue ret; - auto it = data.find(key); - if (it != data.end()) { - ret = it->second; - } - else { - std::string n = key.GetString(); - if (boost::algorithm::contains(n, "object:visibility:")) { - if (boost::algorithm::ends_with(n, "camera") || boost::algorithm::ends_with(n, "shadow")) { - ret = false; - } - else { - ret = true; - } - } - } - return ret; -} - -bool LightData::update_visibility(View3D *view3d) -{ - bool ret = ObjectData::update_visibility(view3d); - if (ret) { - scene_delegate->GetRenderIndex().GetChangeTracker().MarkSprimDirty(p_id, - pxr::HdLight::DirtyParams); - } - return ret; -} - -void LightData::insert() -{ - CLOG_INFO(LOG_BSD, 2, "%s", id->name); - scene_delegate->GetRenderIndex().InsertSprim(p_type, scene_delegate, p_id); -} - -void LightData::remove() -{ - CLOG_INFO(LOG_BSD, 2, "%s", id->name); - scene_delegate->GetRenderIndex().RemoveSprim(p_type, p_id); -} - -void LightData::update() -{ - CLOG_INFO(LOG_BSD, 2, "%s", id->name); - - Light *light = (Light *)((Object *)id)->data; - if (get_prim_type(light) != p_type) { - remove(); - init(); - insert(); - return; - } - - pxr::HdDirtyBits bits = pxr::HdLight::Clean; - if (id->recalc & ID_RECALC_GEOMETRY) { - init(); - bits = pxr::HdLight::AllDirty; - } - else if (id->recalc & ID_RECALC_TRANSFORM) { - bits = pxr::HdLight::DirtyTransform; - } - scene_delegate->GetRenderIndex().GetChangeTracker().MarkSprimDirty(p_id, bits); -} - } // namespace blender::render::hydra diff --git a/source/blender/render/hydra/scene_delegate/light.h b/source/blender/render/hydra/scene_delegate/light.h index 9d78415046d1..a325c6f0457d 100644 --- a/source/blender/render/hydra/scene_delegate/light.h +++ b/source/blender/render/hydra/scene_delegate/light.h @@ -28,9 +28,8 @@ class LightData : public ObjectData { private: pxr::TfToken get_prim_type(Light *light); - private: - std::map data; - pxr::TfToken p_type; + std::map data_; + pxr::TfToken p_type_; }; } // namespace blender::render::hydra diff --git a/source/blender/render/hydra/scene_delegate/material.cc b/source/blender/render/hydra/scene_delegate/material.cc index 37cefe982593..6e134763bd81 100644 --- a/source/blender/render/hydra/scene_delegate/material.cc +++ b/source/blender/render/hydra/scene_delegate/material.cc @@ -20,6 +20,13 @@ namespace blender::render::hydra { +MaterialData::MaterialData(BlenderSceneDelegate *scene_delegate, Material *material) + : IdData(scene_delegate, (ID *)material) +{ + p_id_ = get_prim_id(scene_delegate, material); + CLOG_INFO(LOG_BSD, 2, "%s, id=%s", id_->name, p_id_.GetText()); +} + std::unique_ptr MaterialData::create(BlenderSceneDelegate *scene_delegate, Material *material) { @@ -38,18 +45,11 @@ pxr::SdfPath MaterialData::get_prim_id(BlenderSceneDelegate *scene_delegate, Mat return scene_delegate->GetDelegateID().AppendElementString(str); } -MaterialData::MaterialData(BlenderSceneDelegate *scene_delegate, Material *material) - : IdData(scene_delegate, (ID *)material) -{ - p_id = get_prim_id(scene_delegate, material); - CLOG_INFO(LOG_BSD, 2, "%s, id=%s", id->name, p_id.GetText()); -} - void MaterialData::init() { - CLOG_INFO(LOG_BSD, 2, "%s", id->name); + CLOG_INFO(LOG_BSD, 2, "%s", id_->name); - material_network_map = pxr::VtValue(); + material_network_map_ = pxr::VtValue(); /* Call of python function hydra.export_mtlx() */ @@ -62,7 +62,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); @@ -76,23 +76,44 @@ 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); PyGILState_Release(gstate); - mtlx_path = pxr::SdfAssetPath(path, path); - CLOG_INFO(LOG_BSD, 2, "Export: %s, mtlx=%s", id->name, mtlx_path.GetResolvedPath().c_str()); + mtlx_path_ = pxr::SdfAssetPath(path, path); + CLOG_INFO(LOG_BSD, 2, "Export: %s, mtlx=%s", id_->name, mtlx_path_.GetResolvedPath().c_str()); +} + +void MaterialData::insert() +{ + CLOG_INFO(LOG_BSD, 2, "%s", id_->name); + scene_delegate_->GetRenderIndex().InsertSprim( + pxr::HdPrimTypeTokens->material, scene_delegate_, p_id_); +} + +void MaterialData::remove() +{ + CLOG_INFO(LOG_BSD, 2, "%s", id_->name); + scene_delegate_->GetRenderIndex().RemoveSprim(pxr::HdPrimTypeTokens->material, p_id_); +} + +void MaterialData::update() +{ + CLOG_INFO(LOG_BSD, 2, "%s", id_->name); + init(); + scene_delegate_->GetRenderIndex().GetChangeTracker().MarkSprimDirty(p_id_, + pxr::HdMaterial::AllDirty); } pxr::VtValue MaterialData::get_data(pxr::TfToken const &key) const { pxr::VtValue ret; if (key.GetString() == "MaterialXFilename") { - if (!mtlx_path.GetResolvedPath().empty()) { - ret = mtlx_path; + if (!mtlx_path_.GetResolvedPath().empty()) { + ret = mtlx_path_; } CLOG_INFO(LOG_BSD, 3, "%s", key.GetText()); } @@ -101,42 +122,21 @@ pxr::VtValue MaterialData::get_data(pxr::TfToken const &key) const pxr::VtValue MaterialData::get_material_resource() { - if (material_network_map.IsEmpty()) { - const std::string &path = mtlx_path.GetResolvedPath(); + if (material_network_map_.IsEmpty()) { + const std::string &path = mtlx_path_.GetResolvedPath(); if (!path.empty()) { pxr::HdRenderDelegate *render_delegate = - scene_delegate->GetRenderIndex().GetRenderDelegate(); + scene_delegate_->GetRenderIndex().GetRenderDelegate(); pxr::TfTokenVector shader_source_types = render_delegate->GetShaderSourceTypes(); pxr::TfTokenVector render_contexts = render_delegate->GetMaterialRenderContexts(); pxr::HdMaterialNetworkMap network_map; hdmtlx_convert_to_materialnetworkmap(path, shader_source_types, render_contexts, &network_map); - material_network_map = network_map; + material_network_map_ = network_map; } } - return material_network_map; -} - -void MaterialData::insert() -{ - CLOG_INFO(LOG_BSD, 2, "%s", id->name); - scene_delegate->GetRenderIndex().InsertSprim( - pxr::HdPrimTypeTokens->material, scene_delegate, p_id); -} - -void MaterialData::remove() -{ - CLOG_INFO(LOG_BSD, 2, "%s", id->name); - scene_delegate->GetRenderIndex().RemoveSprim(pxr::HdPrimTypeTokens->material, p_id); -} - -void MaterialData::update() -{ - CLOG_INFO(LOG_BSD, 2, "%s", id->name); - init(); - scene_delegate->GetRenderIndex().GetChangeTracker().MarkSprimDirty(p_id, - pxr::HdMaterial::AllDirty); + return material_network_map_; } } // namespace blender::render::hydra diff --git a/source/blender/render/hydra/scene_delegate/material.h b/source/blender/render/hydra/scene_delegate/material.h index 0f7b0545f078..2f42f37c2826 100644 --- a/source/blender/render/hydra/scene_delegate/material.h +++ b/source/blender/render/hydra/scene_delegate/material.h @@ -19,12 +19,12 @@ class MaterialData : IdData { friend MeshData; public: + MaterialData(BlenderSceneDelegate *scene_delegate, Material *material); + static std::unique_ptr create(BlenderSceneDelegate *scene_delegate, Material *material); static pxr::SdfPath get_prim_id(BlenderSceneDelegate *scene_delegate, Material *material); - MaterialData(BlenderSceneDelegate *scene_delegate, Material *material); - void init() override; void insert() override; void remove() override; @@ -34,8 +34,8 @@ class MaterialData : IdData { pxr::VtValue get_material_resource(); private: - pxr::SdfAssetPath mtlx_path; - pxr::VtValue material_network_map; + pxr::SdfAssetPath mtlx_path_; + pxr::VtValue material_network_map_; }; using MaterialDataMap = diff --git a/source/blender/render/hydra/scene_delegate/mesh.cc b/source/blender/render/hydra/scene_delegate/mesh.cc index eed4b3e5af7a..76deb7ec9fc7 100644 --- a/source/blender/render/hydra/scene_delegate/mesh.cc +++ b/source/blender/render/hydra/scene_delegate/mesh.cc @@ -16,169 +16,16 @@ namespace blender::render::hydra { MeshData::MeshData(BlenderSceneDelegate *scene_delegate, Object *object) - : ObjectData(scene_delegate, object), mat_data(nullptr) + : ObjectData(scene_delegate, object), mat_data_(nullptr) { - CLOG_INFO(LOG_BSD, 2, "%s, id=%s", id->name, p_id.GetText()); -} - -pxr::VtValue MeshData::get_data(pxr::TfToken const &key) const -{ - pxr::VtValue ret; - if (key == pxr::HdTokens->points) { - ret = vertices; - } - else if (key == pxr::HdTokens->normals) { - ret = normals; - } - else if (key == pxr::HdPrimvarRoleTokens->textureCoordinate) { - ret = uvs; - } - else if (key == pxr::HdInstancerTokens->instanceTransform) { - ret = instances; - } - return ret; -} - -bool MeshData::update_visibility(View3D *view3d) -{ - bool ret = ObjectData::update_visibility(view3d); - if (ret) { - scene_delegate->GetRenderIndex().GetChangeTracker().MarkRprimDirty( - p_id, pxr::HdChangeTracker::DirtyVisibility); - } - return ret; -} - -pxr::HdMeshTopology MeshData::get_mesh_topology() -{ - return pxr::HdMeshTopology(pxr::PxOsdOpenSubdivTokens->none, - pxr::HdTokens->rightHanded, - face_vertex_counts, - face_vertex_indices); -} - -pxr::HdPrimvarDescriptorVector MeshData::get_primvar_descriptors(pxr::HdInterpolation interpolation) -{ - pxr::HdPrimvarDescriptorVector primvars; - if (interpolation == pxr::HdInterpolationVertex) { - if (!vertices.empty()) { - primvars.emplace_back(pxr::HdTokens->points, interpolation, pxr::HdPrimvarRoleTokens->point); - } - } - else if (interpolation == pxr::HdInterpolationFaceVarying) { - if (!normals.empty()) { - primvars.emplace_back( - pxr::HdTokens->normals, interpolation, pxr::HdPrimvarRoleTokens->normal); - } - if (!uvs.empty()) { - primvars.emplace_back(pxr::HdPrimvarRoleTokens->textureCoordinate, - interpolation, - pxr::HdPrimvarRoleTokens->textureCoordinate); - } - } - return primvars; -} - -pxr::SdfPath MeshData::get_material_id() -{ - if (!mat_data) { - return pxr::SdfPath(); - } - return mat_data->p_id; -} - -void MeshData::write_mesh(Mesh *mesh) -{ - face_vertex_counts.clear(); - face_vertex_indices.clear(); - vertices.clear(); - normals.clear(); - uvs.clear(); - - BKE_mesh_calc_normals_split(mesh); - int tris_len = BKE_mesh_runtime_looptri_len(mesh); - if (tris_len == 0) { - return; - } - - blender::Span loopTris = mesh->looptris(); - - /* face_vertex_counts */ - face_vertex_counts = pxr::VtIntArray(tris_len, 3); - - /* face_vertex_indices */ - blender::Span corner_verts = mesh->corner_verts(); - face_vertex_indices.reserve(loopTris.size() * 3); - for (MLoopTri lt : loopTris) { - face_vertex_indices.push_back(corner_verts[lt.tri[0]]); - face_vertex_indices.push_back(corner_verts[lt.tri[1]]); - face_vertex_indices.push_back(corner_verts[lt.tri[2]]); - } - - /* vertices */ - vertices.reserve(mesh->totvert); - blender::Span verts = mesh->vert_positions(); - for (blender::float3 v : verts) { - vertices.push_back(pxr::GfVec3f(v.x, v.y, v.z)); - } - - write_normals(mesh); - write_uv_maps(mesh); -} - -void MeshData::write_material() -{ - Object *object = (Object *)id; - Material *mat = nullptr; - if (BKE_object_material_count_eval(object) > 0) { - mat = BKE_object_material_get_eval(object, object->actcol); - } - - if (!mat) { - mat_data = nullptr; - return; - } - pxr::SdfPath id = MaterialData::get_prim_id(scene_delegate, mat); - mat_data = scene_delegate->get_material_data(id); - if (!mat_data) { - scene_delegate->materials[id] = MaterialData::create(scene_delegate, mat); - mat_data = scene_delegate->get_material_data(id); - } -} - -void MeshData::write_uv_maps(Mesh *mesh) -{ - blender::Span loopTris = mesh->looptris(); - const float(*luvs)[2] = (float(*)[2])CustomData_get_layer(&mesh->ldata, CD_PROP_FLOAT2); - if (luvs) { - uvs.reserve(loopTris.size() * 3); - for (MLoopTri lt : loopTris) { - uvs.push_back(pxr::GfVec2f(luvs[lt.tri[0]])); - uvs.push_back(pxr::GfVec2f(luvs[lt.tri[1]])); - uvs.push_back(pxr::GfVec2f(luvs[lt.tri[2]])); - } - } -} - -void MeshData::write_normals(Mesh *mesh) -{ - blender::Span loopTris = mesh->looptris(); - const float(*lnors)[3] = (float(*)[3])CustomData_get_layer(&mesh->ldata, CD_NORMAL); - if (lnors) { - normals.reserve(loopTris.size() * 3); - for (MLoopTri lt : loopTris) { - normals.push_back(pxr::GfVec3f(lnors[lt.tri[0]])); - normals.push_back(pxr::GfVec3f(lnors[lt.tri[1]])); - normals.push_back(pxr::GfVec3f(lnors[lt.tri[2]])); - } - } + CLOG_INFO(LOG_BSD, 2, "%s, id=%s", id_->name, p_id_.GetText()); } void MeshData::init() { - CLOG_INFO(LOG_BSD, 2, "%s", id->name); + CLOG_INFO(LOG_BSD, 2, "%s", id_->name); - 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); @@ -196,38 +43,39 @@ void MeshData::init() void MeshData::insert() { - if (face_vertex_counts.empty()) { + if (face_vertex_counts_.empty()) { return; } - CLOG_INFO(LOG_BSD, 2, "%s", id->name); - scene_delegate->GetRenderIndex().InsertRprim(pxr::HdPrimTypeTokens->mesh, scene_delegate, p_id); + CLOG_INFO(LOG_BSD, 2, "%s", id_->name); + scene_delegate_->GetRenderIndex().InsertRprim( + pxr::HdPrimTypeTokens->mesh, scene_delegate_, p_id_); } void MeshData::remove() { - if (!scene_delegate->GetRenderIndex().HasRprim(p_id)) { + if (!scene_delegate_->GetRenderIndex().HasRprim(p_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(p_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; } } @@ -236,18 +84,171 @@ void MeshData::update() return; } - if (!scene_delegate->GetRenderIndex().HasRprim(p_id)) { + if (!scene_delegate_->GetRenderIndex().HasRprim(p_id_)) { insert(); return; } - if (face_vertex_counts.empty()) { + if (face_vertex_counts_.empty()) { /* Remove prim without faces */ 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(p_id_, bits); +} + +pxr::VtValue MeshData::get_data(pxr::TfToken const &key) const +{ + pxr::VtValue ret; + if (key == pxr::HdTokens->points) { + ret = vertices_; + } + else if (key == pxr::HdTokens->normals) { + ret = normals_; + } + else if (key == pxr::HdPrimvarRoleTokens->textureCoordinate) { + ret = uvs_; + } + else if (key == pxr::HdInstancerTokens->instanceTransform) { + ret = instances_; + } + return ret; +} + +bool MeshData::update_visibility(View3D *view3d) +{ + bool ret = ObjectData::update_visibility(view3d); + if (ret) { + scene_delegate_->GetRenderIndex().GetChangeTracker().MarkRprimDirty( + p_id_, pxr::HdChangeTracker::DirtyVisibility); + } + return ret; +} + +pxr::HdMeshTopology MeshData::get_mesh_topology() +{ + return pxr::HdMeshTopology(pxr::PxOsdOpenSubdivTokens->none, + pxr::HdTokens->rightHanded, + face_vertex_counts_, + face_vertex_indices_); +} + +pxr::HdPrimvarDescriptorVector MeshData::get_primvar_descriptors(pxr::HdInterpolation interpolation) +{ + pxr::HdPrimvarDescriptorVector primvars; + if (interpolation == pxr::HdInterpolationVertex) { + if (!vertices_.empty()) { + primvars.emplace_back(pxr::HdTokens->points, interpolation, pxr::HdPrimvarRoleTokens->point); + } + } + else if (interpolation == pxr::HdInterpolationFaceVarying) { + if (!normals_.empty()) { + primvars.emplace_back( + pxr::HdTokens->normals, interpolation, pxr::HdPrimvarRoleTokens->normal); + } + if (!uvs_.empty()) { + primvars.emplace_back(pxr::HdPrimvarRoleTokens->textureCoordinate, + interpolation, + pxr::HdPrimvarRoleTokens->textureCoordinate); + } + } + return primvars; +} + +pxr::SdfPath MeshData::get_material_id() +{ + if (!mat_data_) { + return pxr::SdfPath(); + } + return mat_data_->p_id_; +} + +void MeshData::write_mesh(Mesh *mesh) +{ + face_vertex_counts_.clear(); + face_vertex_indices_.clear(); + vertices_.clear(); + normals_.clear(); + uvs_.clear(); + + BKE_mesh_calc_normals_split(mesh); + int tris_len = BKE_mesh_runtime_looptri_len(mesh); + if (tris_len == 0) { + return; + } + + blender::Span loopTris = mesh->looptris(); + + /* face_vertex_counts */ + face_vertex_counts_ = pxr::VtIntArray(tris_len, 3); + + /* face_vertex_indices */ + blender::Span corner_verts = mesh->corner_verts(); + face_vertex_indices_.reserve(loopTris.size() * 3); + for (MLoopTri lt : loopTris) { + face_vertex_indices_.push_back(corner_verts[lt.tri[0]]); + face_vertex_indices_.push_back(corner_verts[lt.tri[1]]); + face_vertex_indices_.push_back(corner_verts[lt.tri[2]]); + } + + /* vertices */ + vertices_.reserve(mesh->totvert); + blender::Span verts = mesh->vert_positions(); + for (blender::float3 v : verts) { + vertices_.push_back(pxr::GfVec3f(v.x, v.y, v.z)); + } + + write_normals(mesh); + write_uv_maps(mesh); +} + +void MeshData::write_material() +{ + Object *object = (Object *)id_; + Material *mat = nullptr; + if (BKE_object_material_count_eval(object) > 0) { + mat = BKE_object_material_get_eval(object, object->actcol); + } + + if (!mat) { + mat_data_ = nullptr; + return; + } + pxr::SdfPath id = MaterialData::get_prim_id(scene_delegate_, mat); + mat_data_ = scene_delegate_->get_material_data(id); + if (!mat_data_) { + scene_delegate_->materials_[id] = MaterialData::create(scene_delegate_, mat); + mat_data_ = scene_delegate_->get_material_data(id); + } +} + +void MeshData::write_uv_maps(Mesh *mesh) +{ + blender::Span loopTris = mesh->looptris(); + const float(*luvs)[2] = (float(*)[2])CustomData_get_layer(&mesh->ldata, CD_PROP_FLOAT2); + if (luvs) { + uvs_.reserve(loopTris.size() * 3); + for (MLoopTri lt : loopTris) { + uvs_.push_back(pxr::GfVec2f(luvs[lt.tri[0]])); + uvs_.push_back(pxr::GfVec2f(luvs[lt.tri[1]])); + uvs_.push_back(pxr::GfVec2f(luvs[lt.tri[2]])); + } + } +} + +void MeshData::write_normals(Mesh *mesh) +{ + blender::Span loopTris = mesh->looptris(); + const float(*lnors)[3] = (float(*)[3])CustomData_get_layer(&mesh->ldata, CD_NORMAL); + if (lnors) { + normals_.reserve(loopTris.size() * 3); + for (MLoopTri lt : loopTris) { + normals_.push_back(pxr::GfVec3f(lnors[lt.tri[0]])); + normals_.push_back(pxr::GfVec3f(lnors[lt.tri[1]])); + normals_.push_back(pxr::GfVec3f(lnors[lt.tri[2]])); + } + } } } // namespace blender::render::hydra diff --git a/source/blender/render/hydra/scene_delegate/mesh.h b/source/blender/render/hydra/scene_delegate/mesh.h index a02380eb0523..0b7247a49507 100644 --- a/source/blender/render/hydra/scene_delegate/mesh.h +++ b/source/blender/render/hydra/scene_delegate/mesh.h @@ -35,15 +35,14 @@ class MeshData : public ObjectData { void write_uv_maps(Mesh *mesh); void write_normals(Mesh *mesh); - protected: - pxr::VtIntArray face_vertex_counts; - pxr::VtIntArray face_vertex_indices; - pxr::VtVec3fArray vertices; - pxr::VtVec2fArray uvs; - pxr::VtVec3fArray normals; - pxr::VtMatrix4dArray instances; + pxr::VtIntArray face_vertex_counts_; + pxr::VtIntArray face_vertex_indices_; + pxr::VtVec3fArray vertices_; + pxr::VtVec2fArray uvs_; + pxr::VtVec3fArray normals_; + pxr::VtMatrix4dArray instances_; - MaterialData *mat_data; + MaterialData *mat_data_; }; } // namespace blender::render::hydra diff --git a/source/blender/render/hydra/scene_delegate/object.cc b/source/blender/render/hydra/scene_delegate/object.cc index feb910551f4b..1f6914e262f8 100644 --- a/source/blender/render/hydra/scene_delegate/object.cc +++ b/source/blender/render/hydra/scene_delegate/object.cc @@ -11,6 +11,12 @@ namespace blender::render::hydra { +ObjectData::ObjectData(BlenderSceneDelegate *scene_delegate, Object *object) + : IdData(scene_delegate, (ID *)object), visible(true) +{ + p_id_ = get_prim_id(scene_delegate, object); +} + bool ObjectData::is_supported(Object *object) { switch (object->type) { @@ -65,15 +71,9 @@ pxr::SdfPath ObjectData::get_prim_id(BlenderSceneDelegate *scene_delegate, Objec return scene_delegate->GetDelegateID().AppendElementString(str); } -ObjectData::ObjectData(BlenderSceneDelegate *scene_delegate, Object *object) - : IdData(scene_delegate, (ID *)object), visible(true) -{ - p_id = get_prim_id(scene_delegate, object); -} - pxr::GfMatrix4d ObjectData::get_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(View3D *view3d) @@ -83,7 +83,7 @@ bool ObjectData::update_visibility(View3D *view3d) } bool prev_visible = visible; - visible = BKE_object_is_visible_in_viewport(view3d, (Object *)id); + visible = BKE_object_is_visible_in_viewport(view3d, (Object *)id_); return visible != prev_visible; } diff --git a/source/blender/render/hydra/scene_delegate/object.h b/source/blender/render/hydra/scene_delegate/object.h index 9ce8210ed771..7778e74dd9e2 100644 --- a/source/blender/render/hydra/scene_delegate/object.h +++ b/source/blender/render/hydra/scene_delegate/object.h @@ -16,16 +16,15 @@ namespace blender::render::hydra { class ObjectData : public IdData { public: + ObjectData(BlenderSceneDelegate *scene_delegate, Object *object); + static bool is_supported(Object *object); static std::unique_ptr create(BlenderSceneDelegate *scene_delegate, Object *object); static pxr::SdfPath get_prim_id(BlenderSceneDelegate *scene_delegate, Object *object); - ObjectData(BlenderSceneDelegate *scene_delegate, Object *object); - virtual pxr::GfMatrix4d get_transform(); virtual bool update_visibility(View3D *view3d); - public: bool visible; }; diff --git a/source/blender/render/hydra/scene_delegate/world.cc b/source/blender/render/hydra/scene_delegate/world.cc index 9d66487385d4..6dc0fbc5c99d 100644 --- a/source/blender/render/hydra/scene_delegate/world.cc +++ b/source/blender/render/hydra/scene_delegate/world.cc @@ -28,6 +28,13 @@ namespace blender::render::hydra { +WorldData::WorldData(BlenderSceneDelegate *scene_delegate, World *world, bContext *context) + : IdData(scene_delegate, (ID *)world), context_(context) +{ + p_id_ = get_prim_id(scene_delegate); + CLOG_INFO(LOG_BSD, 2, "%s, id=%s", id_->name, p_id_.GetText()); +} + std::unique_ptr WorldData::create(BlenderSceneDelegate *scene_delegate, World *world, bContext *context) @@ -43,21 +50,14 @@ pxr::SdfPath WorldData::get_prim_id(BlenderSceneDelegate *scene_delegate) return scene_delegate->GetDelegateID().AppendElementString("World"); } -WorldData::WorldData(BlenderSceneDelegate *scene_delegate, World *world, bContext *context) - : IdData(scene_delegate, (ID *)world), context(context) -{ - p_id = get_prim_id(scene_delegate); - CLOG_INFO(LOG_BSD, 2, "%s, id=%s", id->name, p_id.GetText()); -} - void WorldData::init() { - CLOG_INFO(LOG_BSD, 2, "%s", id->name); + CLOG_INFO(LOG_BSD, 2, "%s", id_->name); - World *world = (World *)id; - data.clear(); + World *world = (World *)id_; + data_.clear(); - data[pxr::UsdLuxTokens->orientToStageUpAxis] = true; + data_[pxr::UsdLuxTokens->orientToStageUpAxis] = true; if (world->use_nodes) { /* TODO: Create nodes parsing system */ @@ -90,9 +90,9 @@ void WorldData::init() float const *strength = strength_input.default_value_typed(); float const *color = color_input.default_value_typed(); - data[pxr::HdLightTokens->intensity] = strength[1]; - data[pxr::HdLightTokens->exposure] = 1.0f; - data[pxr::HdLightTokens->color] = pxr::GfVec3f(color[0], color[1], color[2]); + data_[pxr::HdLightTokens->intensity] = strength[1]; + data_[pxr::HdLightTokens->exposure] = 1.0f; + data_[pxr::HdLightTokens->color] = pxr::GfVec3f(color[0], color[1], color[2]); if (!color_input.directly_linked_links().is_empty()) { bNode *color_input_node = color_input.directly_linked_links()[0]->fromnode; @@ -101,8 +101,8 @@ void WorldData::init() Image *image = (Image *)color_input_node->id; if (image) { - Main *bmain = CTX_data_main(context); - Scene *scene = CTX_data_scene(context); + Main *bmain = CTX_data_main(context_); + Scene *scene = CTX_data_scene(context_); ReportList reports; ImageSaveOptions opts; @@ -110,26 +110,53 @@ void WorldData::init() std::string image_path = cache_image(bmain, scene, image, &tex->iuser, &opts, &reports); if (!image_path.empty()) { - data[pxr::HdLightTokens->textureFile] = pxr::SdfAssetPath(image_path, image_path); + data_[pxr::HdLightTokens->textureFile] = pxr::SdfAssetPath(image_path, image_path); } } } } } else { - data[pxr::HdLightTokens->intensity] = 1.0f; - data[pxr::HdLightTokens->exposure] = world->exposure; - data[pxr::HdLightTokens->color] = pxr::GfVec3f(world->horr, world->horg, world->horb); + data_[pxr::HdLightTokens->intensity] = 1.0f; + data_[pxr::HdLightTokens->exposure] = world->exposure; + data_[pxr::HdLightTokens->color] = pxr::GfVec3f(world->horr, world->horg, world->horb); } } +void WorldData::insert() +{ + CLOG_INFO(LOG_BSD, 2, "%s", id_->name); + scene_delegate_->GetRenderIndex().InsertSprim( + pxr::HdPrimTypeTokens->domeLight, scene_delegate_, p_id_); +} + +void WorldData::remove() +{ + CLOG_INFO(LOG_BSD, 2, "%s", id_->name); + scene_delegate_->GetRenderIndex().RemoveSprim(pxr::HdPrimTypeTokens->domeLight, p_id_); +} + +void WorldData::update() +{ + CLOG_INFO(LOG_BSD, 2, "%s", id_->name); + init(); + scene_delegate_->GetRenderIndex().GetChangeTracker().MarkSprimDirty(p_id_, + pxr::HdLight::AllDirty); +} + +void WorldData::update(World *world) +{ + id_ = (ID *)world; + update(); +} + pxr::GfMatrix4d WorldData::get_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") { + 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), @@ -141,37 +168,11 @@ pxr::GfMatrix4d WorldData::get_transform() pxr::VtValue WorldData::get_data(pxr::TfToken const &key) const { pxr::VtValue ret; - auto it = data.find(key); - if (it != data.end()) { + auto it = data_.find(key); + if (it != data_.end()) { ret = it->second; } return ret; } -void WorldData::insert() -{ - CLOG_INFO(LOG_BSD, 2, "%s", id->name); - scene_delegate->GetRenderIndex().InsertSprim( - pxr::HdPrimTypeTokens->domeLight, scene_delegate, p_id); -} - -void WorldData::remove() -{ - CLOG_INFO(LOG_BSD, 2, "%s", id->name); - scene_delegate->GetRenderIndex().RemoveSprim(pxr::HdPrimTypeTokens->domeLight, p_id); -} - -void WorldData::update() -{ - CLOG_INFO(LOG_BSD, 2, "%s", id->name); - init(); - scene_delegate->GetRenderIndex().GetChangeTracker().MarkSprimDirty(p_id, pxr::HdLight::AllDirty); -} - -void WorldData::update(World *world) -{ - id = (ID *)world; - update(); -} - } // namespace blender::render::hydra diff --git a/source/blender/render/hydra/scene_delegate/world.h b/source/blender/render/hydra/scene_delegate/world.h index 648a55607d24..2d8df7bfc499 100644 --- a/source/blender/render/hydra/scene_delegate/world.h +++ b/source/blender/render/hydra/scene_delegate/world.h @@ -20,13 +20,13 @@ namespace blender::render::hydra { class WorldData : public IdData { public: + WorldData(BlenderSceneDelegate *scene_delegate, World *world, bContext *context); + static std::unique_ptr create(BlenderSceneDelegate *scene_delegate, World *world, bContext *context); static pxr::SdfPath get_prim_id(BlenderSceneDelegate *scene_delegate); - WorldData(BlenderSceneDelegate *scene_delegate, World *world, bContext *context); - void init() override; void insert() override; void remove() override; @@ -37,8 +37,8 @@ class WorldData : public IdData { pxr::VtValue get_data(pxr::TfToken const &key) const override; private: - std::map data; - bContext *context; + std::map data_; + bContext *context_; }; } // namespace blender::render::hydra diff --git a/source/blender/render/hydra/viewport_engine.cc b/source/blender/render/hydra/viewport_engine.cc index 7984ca892a22..2115f5318754 100644 --- a/source/blender/render/hydra/viewport_engine.cc +++ b/source/blender/render/hydra/viewport_engine.cc @@ -217,13 +217,13 @@ void ViewportEngine::sync(Depsgraph *depsgraph, bContext *context, pxr::HdRenderSettingsMap &render_settings) { - if (!scene_delegate) { - scene_delegate = std::make_unique( + if (!scene_delegate_) { + scene_delegate_ = std::make_unique( render_index.get(), pxr::SdfPath::AbsoluteRootPath().AppendElementString("scene"), BlenderSceneDelegate::EngineType::VIEWPORT); } - scene_delegate->populate(depsgraph, context); + scene_delegate_->populate(depsgraph, context); for (auto const &setting : render_settings) { render_delegate->SetRenderSetting(setting.first, setting.second); -- 2.30.2 From b5945ae735be81364bf1ec1580394a338e3a71b6 Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Thu, 13 Apr 2023 17:02:29 +0300 Subject: [PATCH 03/13] continuation --- source/blender/render/hydra/camera.cc | 332 +++++++++--------- source/blender/render/hydra/camera.h | 16 +- source/blender/render/hydra/engine.cc | 46 +-- source/blender/render/hydra/engine.h | 18 +- source/blender/render/hydra/final_engine.cc | 58 +-- source/blender/render/hydra/final_engine.h | 3 +- source/blender/render/hydra/preview_engine.cc | 54 +-- source/blender/render/hydra/preview_engine.h | 15 +- .../render/hydra/render_task_delegate.cc | 26 +- .../render/hydra/render_task_delegate.h | 13 +- .../hydra/simple_light_task_delegate.cc | 4 +- .../render/hydra/simple_light_task_delegate.h | 3 +- .../blender/render/hydra/viewport_engine.cc | 82 ++--- source/blender/render/hydra/viewport_engine.h | 12 +- 14 files changed, 345 insertions(+), 337 deletions(-) diff --git a/source/blender/render/hydra/camera.cc b/source/blender/render/hydra/camera.cc index f2201e53518d..5810be5d000f 100644 --- a/source/blender/render/hydra/camera.cc +++ b/source/blender/render/hydra/camera.cc @@ -9,140 +9,6 @@ namespace blender::render::hydra { -CameraData::CameraData(Object *camera_obj, pxr::GfVec2i res, pxr::GfVec4f tile) -{ - Camera *camera = (Camera *)camera_obj->data; - - float t_pos[2] = {tile[0], tile[1]}; - float t_size[2] = {tile[2], tile[3]}; - transform = gf_matrix_from_transform(camera_obj->object_to_world); - clip_range = pxr::GfRange1f(camera->clip_start, camera->clip_end); - mode = camera->type; - - if (camera->dof.flag & CAM_DOF_ENABLED) { - float focus_distance; - if (!camera->dof.focus_object) { - focus_distance = camera->dof.focus_distance; - } - else { - pxr::GfVec3f obj_pos(camera->dof.focus_object->object_to_world[0][3], - camera->dof.focus_object->object_to_world[1][3], - camera->dof.focus_object->object_to_world[2][3]); - pxr::GfVec3f cam_pos(transform[0][3], transform[1][3], transform[2][3]); - focus_distance = (obj_pos - cam_pos).GetLength(); - } - - dof_data = std::tuple( - std::max(focus_distance, 0.001f), camera->dof.aperture_fstop, camera->dof.aperture_blades); - } - - float ratio = (float)res[0] / res[1]; - - switch (camera->sensor_fit) { - case CAMERA_SENSOR_FIT_VERT: - lens_shift = pxr::GfVec2f(camera->shiftx / ratio, camera->shifty); - break; - case CAMERA_SENSOR_FIT_HOR: - lens_shift = pxr::GfVec2f(camera->shiftx, camera->shifty * ratio); - break; - case CAMERA_SENSOR_FIT_AUTO: - if (ratio > 1.0f) { - lens_shift = pxr::GfVec2f(camera->shiftx, camera->shifty * ratio); - } - else { - lens_shift = pxr::GfVec2f(camera->shiftx / ratio, camera->shifty); - } - break; - default: - lens_shift = pxr::GfVec2f(camera->shiftx, camera->shifty); - break; - } - - lens_shift = pxr::GfVec2f( - lens_shift[0] / t_size[0] + (t_pos[0] + t_size[0] * 0.5 - 0.5) / t_size[0], - lens_shift[1] / t_size[1] + (t_pos[1] + t_size[1] * 0.5 - 0.5) / t_size[1]); - - switch (camera->type) { - case CAM_PERSP: - focal_length = camera->lens; - - switch (camera->sensor_fit) { - case CAMERA_SENSOR_FIT_VERT: - sensor_size = pxr::GfVec2f(camera->sensor_y * ratio, camera->sensor_y); - break; - case CAMERA_SENSOR_FIT_HOR: - sensor_size = pxr::GfVec2f(camera->sensor_x, camera->sensor_x / ratio); - break; - case CAMERA_SENSOR_FIT_AUTO: - if (ratio > 1.0f) { - sensor_size = pxr::GfVec2f(camera->sensor_x, camera->sensor_x / ratio); - } - else { - sensor_size = pxr::GfVec2f(camera->sensor_x * ratio, camera->sensor_x); - } - break; - default: - sensor_size = pxr::GfVec2f(camera->sensor_x, camera->sensor_y); - break; - } - sensor_size = pxr::GfVec2f(sensor_size[0] * t_size[0], sensor_size[1] * t_size[1]); - break; - - case CAM_ORTHO: - focal_length = 0.0f; - switch (camera->sensor_fit) { - case CAMERA_SENSOR_FIT_VERT: - ortho_size = pxr::GfVec2f(camera->ortho_scale * ratio, camera->ortho_scale); - break; - case CAMERA_SENSOR_FIT_HOR: - ortho_size = pxr::GfVec2f(camera->ortho_scale, camera->ortho_scale / ratio); - break; - case CAMERA_SENSOR_FIT_AUTO: - if (ratio > 1.0f) { - ortho_size = pxr::GfVec2f(camera->ortho_scale, camera->ortho_scale / ratio); - } - else { - ortho_size = pxr::GfVec2f(camera->ortho_scale * ratio, camera->ortho_scale); - } - break; - default: - ortho_size = pxr::GfVec2f(camera->ortho_scale, camera->ortho_scale); - break; - } - ortho_size = pxr::GfVec2f(ortho_size[0] * t_size[0], ortho_size[1] * t_size[1]); - break; - - case CAM_PANO: - /* TODO: Recheck parameters for PANO camera */ - focal_length = camera->lens; - - switch (camera->sensor_fit) { - case CAMERA_SENSOR_FIT_VERT: - sensor_size = pxr::GfVec2f(camera->sensor_y * ratio, camera->sensor_y); - break; - case CAMERA_SENSOR_FIT_HOR: - sensor_size = pxr::GfVec2f(camera->sensor_x, camera->sensor_x / ratio); - break; - case CAMERA_SENSOR_FIT_AUTO: - if (ratio > 1.0f) { - sensor_size = pxr::GfVec2f(camera->sensor_x, camera->sensor_x / ratio); - } - else { - sensor_size = pxr::GfVec2f(camera->sensor_x * ratio, camera->sensor_x); - } - break; - default: - sensor_size = pxr::GfVec2f(camera->sensor_x, camera->sensor_y); - break; - } - sensor_size = pxr::GfVec2f(sensor_size[0] * t_size[0], sensor_size[1] * t_size[1]); - - default: - focal_length = camera->lens; - sensor_size = pxr::GfVec2f(camera->sensor_y * ratio, camera->sensor_y); - } -} - CameraData::CameraData(bContext *context) { View3D *view3d = CTX_wm_view3d(context); @@ -155,46 +21,46 @@ CameraData::CameraData(bContext *context) pxr::GfVec2i res(region->winx, region->winy); float ratio = (float)res[0] / res[1]; - transform = gf_matrix_from_transform(region_data->viewmat).GetInverse(); + transform_ = gf_matrix_from_transform(region_data->viewmat).GetInverse(); switch (region_data->persp) { case RV3D_PERSP: { - mode = CAM_PERSP; - clip_range = pxr::GfRange1f(view3d->clip_start, view3d->clip_end); - lens_shift = pxr::GfVec2f(0.0, 0.0); - focal_length = view3d->lens; + mode_ = CAM_PERSP; + clip_range_ = pxr::GfRange1f(view3d->clip_start, view3d->clip_end); + lens_shift_ = pxr::GfVec2f(0.0, 0.0); + focal_length_ = view3d->lens; if (ratio > 1.0) { - sensor_size = pxr::GfVec2f(VIEWPORT_SENSOR_SIZE, VIEWPORT_SENSOR_SIZE / ratio); + sensor_size_ = pxr::GfVec2f(VIEWPORT_SENSOR_SIZE, VIEWPORT_SENSOR_SIZE / ratio); } else { - sensor_size = pxr::GfVec2f(VIEWPORT_SENSOR_SIZE * ratio, VIEWPORT_SENSOR_SIZE); + sensor_size_ = pxr::GfVec2f(VIEWPORT_SENSOR_SIZE * ratio, VIEWPORT_SENSOR_SIZE); } break; } case RV3D_ORTHO: { - mode = CAM_ORTHO; - lens_shift = pxr::GfVec2f(0.0f, 0.0f); + mode_ = CAM_ORTHO; + lens_shift_ = pxr::GfVec2f(0.0f, 0.0f); float o_size = region_data->dist * VIEWPORT_SENSOR_SIZE / view3d->lens; float o_depth = view3d->clip_end; - clip_range = pxr::GfRange1f(-o_depth * 0.5, o_depth * 0.5); + clip_range_ = pxr::GfRange1f(-o_depth * 0.5, o_depth * 0.5); if (ratio > 1.0f) { - ortho_size = pxr::GfVec2f(o_size, o_size / ratio); + ortho_size_ = pxr::GfVec2f(o_size, o_size / ratio); } else { - ortho_size = pxr::GfVec2f(o_size * ratio, o_size); + ortho_size_ = pxr::GfVec2f(o_size * ratio, o_size); } break; } case RV3D_CAMOB: { - pxr::GfMatrix4d mat = transform; + pxr::GfMatrix4d mat = transform_; *this = CameraData(view3d->camera, res, pxr::GfVec4f(0, 0, 1, 1)); - transform = mat; + transform_ = mat; // This formula was taken from previous plugin with corresponded comment // See blender/intern/cycles/blender/blender_camera.cpp:blender_camera_from_view (look @@ -203,14 +69,14 @@ CameraData::CameraData(bContext *context) // Updating l_shift due to viewport zoom and view_camera_offset // view_camera_offset should be multiplied by 2 - lens_shift = pxr::GfVec2f((lens_shift[0] + region_data->camdx * 2) / zoom, - (lens_shift[1] + region_data->camdy * 2) / zoom); + lens_shift_ = pxr::GfVec2f((lens_shift_[0] + region_data->camdx * 2) / zoom, + (lens_shift_[1] + region_data->camdy * 2) / zoom); - if (mode == CAM_ORTHO) { - ortho_size *= zoom; + if (mode_ == CAM_ORTHO) { + ortho_size_ *= zoom; } else { - sensor_size *= zoom; + sensor_size_ *= zoom; } break; } @@ -220,25 +86,164 @@ CameraData::CameraData(bContext *context) } } +CameraData::CameraData(Object *camera_obj, pxr::GfVec2i res, pxr::GfVec4f tile) +{ + Camera *camera = (Camera *)camera_obj->data; + + float t_pos[2] = {tile[0], tile[1]}; + float t_size[2] = {tile[2], tile[3]}; + transform_ = gf_matrix_from_transform(camera_obj->object_to_world); + clip_range_ = pxr::GfRange1f(camera->clip_start, camera->clip_end); + mode_ = camera->type; + + if (camera->dof.flag & CAM_DOF_ENABLED) { + float focus_distance; + if (!camera->dof.focus_object) { + focus_distance = camera->dof.focus_distance; + } + else { + pxr::GfVec3f obj_pos(camera->dof.focus_object->object_to_world[0][3], + camera->dof.focus_object->object_to_world[1][3], + camera->dof.focus_object->object_to_world[2][3]); + pxr::GfVec3f cam_pos(transform_[0][3], transform_[1][3], transform_[2][3]); + focus_distance = (obj_pos - cam_pos).GetLength(); + } + + dof_data_ = std::tuple( + std::max(focus_distance, 0.001f), camera->dof.aperture_fstop, camera->dof.aperture_blades); + } + + float ratio = (float)res[0] / res[1]; + + switch (camera->sensor_fit) { + case CAMERA_SENSOR_FIT_VERT: + lens_shift_ = pxr::GfVec2f(camera->shiftx / ratio, camera->shifty); + break; + case CAMERA_SENSOR_FIT_HOR: + lens_shift_ = pxr::GfVec2f(camera->shiftx, camera->shifty * ratio); + break; + case CAMERA_SENSOR_FIT_AUTO: + if (ratio > 1.0f) { + lens_shift_ = pxr::GfVec2f(camera->shiftx, camera->shifty * ratio); + } + else { + lens_shift_ = pxr::GfVec2f(camera->shiftx / ratio, camera->shifty); + } + break; + default: + lens_shift_ = pxr::GfVec2f(camera->shiftx, camera->shifty); + break; + } + + lens_shift_ = pxr::GfVec2f( + lens_shift_[0] / t_size[0] + (t_pos[0] + t_size[0] * 0.5 - 0.5) / t_size[0], + lens_shift_[1] / t_size[1] + (t_pos[1] + t_size[1] * 0.5 - 0.5) / t_size[1]); + + switch (camera->type) { + case CAM_PERSP: + focal_length_ = camera->lens; + + switch (camera->sensor_fit) { + case CAMERA_SENSOR_FIT_VERT: + sensor_size_ = pxr::GfVec2f(camera->sensor_y * ratio, camera->sensor_y); + break; + case CAMERA_SENSOR_FIT_HOR: + sensor_size_ = pxr::GfVec2f(camera->sensor_x, camera->sensor_x / ratio); + break; + case CAMERA_SENSOR_FIT_AUTO: + if (ratio > 1.0f) { + sensor_size_ = pxr::GfVec2f(camera->sensor_x, camera->sensor_x / ratio); + } + else { + sensor_size_ = pxr::GfVec2f(camera->sensor_x * ratio, camera->sensor_x); + } + break; + default: + sensor_size_ = pxr::GfVec2f(camera->sensor_x, camera->sensor_y); + break; + } + sensor_size_ = pxr::GfVec2f(sensor_size_[0] * t_size[0], sensor_size_[1] * t_size[1]); + break; + + case CAM_ORTHO: + focal_length_ = 0.0f; + switch (camera->sensor_fit) { + case CAMERA_SENSOR_FIT_VERT: + ortho_size_ = pxr::GfVec2f(camera->ortho_scale * ratio, camera->ortho_scale); + break; + case CAMERA_SENSOR_FIT_HOR: + ortho_size_ = pxr::GfVec2f(camera->ortho_scale, camera->ortho_scale / ratio); + break; + case CAMERA_SENSOR_FIT_AUTO: + if (ratio > 1.0f) { + ortho_size_ = pxr::GfVec2f(camera->ortho_scale, camera->ortho_scale / ratio); + } + else { + ortho_size_ = pxr::GfVec2f(camera->ortho_scale * ratio, camera->ortho_scale); + } + break; + default: + ortho_size_ = pxr::GfVec2f(camera->ortho_scale, camera->ortho_scale); + break; + } + ortho_size_ = pxr::GfVec2f(ortho_size_[0] * t_size[0], ortho_size_[1] * t_size[1]); + break; + + case CAM_PANO: + /* TODO: Recheck parameters for PANO camera */ + focal_length_ = camera->lens; + + switch (camera->sensor_fit) { + case CAMERA_SENSOR_FIT_VERT: + sensor_size_ = pxr::GfVec2f(camera->sensor_y * ratio, camera->sensor_y); + break; + case CAMERA_SENSOR_FIT_HOR: + sensor_size_ = pxr::GfVec2f(camera->sensor_x, camera->sensor_x / ratio); + break; + case CAMERA_SENSOR_FIT_AUTO: + if (ratio > 1.0f) { + sensor_size_ = pxr::GfVec2f(camera->sensor_x, camera->sensor_x / ratio); + } + else { + sensor_size_ = pxr::GfVec2f(camera->sensor_x * ratio, camera->sensor_x); + } + break; + default: + sensor_size_ = pxr::GfVec2f(camera->sensor_x, camera->sensor_y); + break; + } + sensor_size_ = pxr::GfVec2f(sensor_size_[0] * t_size[0], sensor_size_[1] * t_size[1]); + + default: + focal_length_ = camera->lens; + sensor_size_ = pxr::GfVec2f(camera->sensor_y * ratio, camera->sensor_y); + } +} + +pxr::GfCamera CameraData::gf_camera() +{ + return gf_camera(pxr::GfVec4f(0, 0, 1, 1)); +} + pxr::GfCamera CameraData::gf_camera(pxr::GfVec4f tile) { float t_pos[2] = {tile[0], tile[1]}, t_size[2] = {tile[2], tile[3]}; pxr::GfCamera gf_camera = pxr::GfCamera(); - gf_camera.SetClippingRange(clip_range); + gf_camera.SetClippingRange(clip_range_); - float l_shift[2] = {(lens_shift[0] + t_pos[0] + t_size[0] * 0.5f - 0.5f) / t_size[0], - (lens_shift[1] + t_pos[1] + t_size[1] * 0.5f - 0.5f) / t_size[1]}; + float l_shift[2] = {(lens_shift_[0] + t_pos[0] + t_size[0] * 0.5f - 0.5f) / t_size[0], + (lens_shift_[1] + t_pos[1] + t_size[1] * 0.5f - 0.5f) / t_size[1]}; - switch (mode) { + switch (mode_) { case CAM_PERSP: case CAM_PANO: { /* TODO: store panoramic camera settings */ gf_camera.SetProjection(pxr::GfCamera::Projection::Perspective); - gf_camera.SetFocalLength(focal_length); + gf_camera.SetFocalLength(focal_length_); - float s_size[2] = {sensor_size[0] * t_size[0], sensor_size[1] * t_size[1]}; + float s_size[2] = {sensor_size_[0] * t_size[0], sensor_size_[1] * t_size[1]}; gf_camera.SetHorizontalAperture(s_size[0]); gf_camera.SetVerticalAperture(s_size[1]); @@ -252,7 +257,7 @@ pxr::GfCamera CameraData::gf_camera(pxr::GfVec4f tile) // Use tenths of a world unit accorging to USD docs // https://graphics.pixar.com/usd/docs/api/class_gf_camera.html - float o_size[2] = {ortho_size[0] * t_size[0] * 10, ortho_size[1] * t_size[1] * 10}; + float o_size[2] = {ortho_size_[0] * t_size[0] * 10, ortho_size_[1] * t_size[1] * 10}; gf_camera.SetHorizontalAperture(o_size[0]); gf_camera.SetVerticalAperture(o_size[1]); @@ -265,13 +270,10 @@ pxr::GfCamera CameraData::gf_camera(pxr::GfVec4f tile) break; } - gf_camera.SetTransform(transform); + gf_camera.SetTransform(transform_); return gf_camera; } -pxr::GfCamera CameraData::gf_camera() -{ - return gf_camera(pxr::GfVec4f(0, 0, 1, 1)); -} + } // namespace blender::render::hydra diff --git a/source/blender/render/hydra/camera.h b/source/blender/render/hydra/camera.h index 9e23146b5a60..6e3a482ae007 100644 --- a/source/blender/render/hydra/camera.h +++ b/source/blender/render/hydra/camera.h @@ -23,14 +23,14 @@ class CameraData { pxr::GfCamera gf_camera(pxr::GfVec4f tile); private: - int mode; - pxr::GfRange1f clip_range; - float focal_length; - pxr::GfVec2f sensor_size; - pxr::GfMatrix4d transform; - pxr::GfVec2f lens_shift; - pxr::GfVec2f ortho_size; - std::tuple dof_data; + int mode_; + pxr::GfRange1f clip_range_; + float focal_length_; + pxr::GfVec2f sensor_size_; + pxr::GfMatrix4d transform_; + pxr::GfVec2f lens_shift_; + pxr::GfVec2f ortho_size_; + std::tuple dof_data_; }; } // namespace blender::render::hydra diff --git a/source/blender/render/hydra/engine.cc b/source/blender/render/hydra/engine.cc index c58c1d4b3ec7..6f048c25a17d 100644 --- a/source/blender/render/hydra/engine.cc +++ b/source/blender/render/hydra/engine.cc @@ -14,51 +14,51 @@ namespace blender::render::hydra { CLG_LOGREF_DECLARE_GLOBAL(LOG_EN, "rhd.en"); -Engine::Engine(RenderEngine *bl_engine, const std::string &delegate_id) : bl_engine(bl_engine) +Engine::Engine(RenderEngine *bl_engine, const std::string &delegate_id) : bl_engine_(bl_engine) { pxr::HdRendererPluginRegistry ®istry = pxr::HdRendererPluginRegistry::GetInstance(); pxr::TF_PY_ALLOW_THREADS_IN_SCOPE(); - render_delegate = registry.CreateRenderDelegate(pxr::TfToken(delegate_id)); + render_delegate_ = registry.CreateRenderDelegate(pxr::TfToken(delegate_id)); pxr::HdDriverVector hd_drivers; if (bl_engine->type->flag & RE_USE_GPU_CONTEXT) { - hgi = pxr::Hgi::CreatePlatformDefaultHgi(); - hgi_driver.name = pxr::HgiTokens->renderDriver; - hgi_driver.driver = pxr::VtValue(hgi.get()); + hgi_ = pxr::Hgi::CreatePlatformDefaultHgi(); + hgi_driver_.name = pxr::HgiTokens->renderDriver; + hgi_driver_.driver = pxr::VtValue(hgi_.get()); - hd_drivers.push_back(&hgi_driver); + hd_drivers.push_back(&hgi_driver_); } - render_index.reset(pxr::HdRenderIndex::New(render_delegate.Get(), hd_drivers)); - free_camera_delegate = std::make_unique( - render_index.get(), pxr::SdfPath::AbsoluteRootPath().AppendElementString("freeCamera")); - render_task_delegate = std::make_unique( - render_index.get(), pxr::SdfPath::AbsoluteRootPath().AppendElementString("renderTask")); - if (render_delegate->GetRendererDisplayName() == "GL") { - simple_light_task_delegate = std::make_unique( - render_index.get(), + render_index_.reset(pxr::HdRenderIndex::New(render_delegate_.Get(), hd_drivers)); + free_camera_delegate_ = std::make_unique( + render_index_.get(), pxr::SdfPath::AbsoluteRootPath().AppendElementString("freeCamera")); + render_task_delegate_ = std::make_unique( + render_index_.get(), pxr::SdfPath::AbsoluteRootPath().AppendElementString("renderTask")); + if (render_delegate_->GetRendererDisplayName() == "GL") { + simple_light_task_delegate_ = std::make_unique( + render_index_.get(), pxr::SdfPath::AbsoluteRootPath().AppendElementString("simpleLightTask")); } - engine = std::make_unique(); + engine_ = std::make_unique(); } Engine::~Engine() { scene_delegate_ = nullptr; - render_task_delegate = nullptr; - free_camera_delegate = nullptr; - simple_light_task_delegate = nullptr; - render_index = nullptr; - render_delegate = nullptr; - engine = nullptr; - hgi = nullptr; + render_task_delegate_ = nullptr; + free_camera_delegate_ = nullptr; + simple_light_task_delegate_ = nullptr; + render_index_ = nullptr; + render_delegate_ = nullptr; + engine_ = nullptr; + hgi_ = nullptr; } float Engine::renderer_percent_done() { - pxr::VtDictionary render_stats = render_delegate->GetRenderStats(); + pxr::VtDictionary render_stats = render_delegate_->GetRenderStats(); auto it = render_stats.find("percentDone"); if (it == render_stats.end()) { return 0.0; diff --git a/source/blender/render/hydra/engine.h b/source/blender/render/hydra/engine.h index 6bcec61cbecf..9e27b98cde35 100644 --- a/source/blender/render/hydra/engine.h +++ b/source/blender/render/hydra/engine.h @@ -38,18 +38,18 @@ class Engine { protected: float renderer_percent_done(); - RenderEngine *bl_engine; + RenderEngine *bl_engine_; - pxr::HdPluginRenderDelegateUniqueHandle render_delegate; - std::unique_ptr render_index; + pxr::HdPluginRenderDelegateUniqueHandle render_delegate_; + std::unique_ptr render_index_; std::unique_ptr scene_delegate_; - std::unique_ptr render_task_delegate; - std::unique_ptr free_camera_delegate; - std::unique_ptr simple_light_task_delegate; - std::unique_ptr engine; + std::unique_ptr render_task_delegate_; + std::unique_ptr free_camera_delegate_; + std::unique_ptr simple_light_task_delegate_; + std::unique_ptr engine_; - pxr::HgiUniquePtr hgi; - pxr::HdDriver hgi_driver; + pxr::HgiUniquePtr hgi_; + pxr::HdDriver hgi_driver_; }; } // namespace blender::render::hydra diff --git a/source/blender/render/hydra/final_engine.cc b/source/blender/render/hydra/final_engine.cc index 281c68cb6376..c943d12d2f4d 100644 --- a/source/blender/render/hydra/final_engine.cc +++ b/source/blender/render/hydra/final_engine.cc @@ -17,13 +17,13 @@ void FinalEngine::sync(Depsgraph *depsgraph, pxr::HdRenderSettingsMap &render_settings) { scene_delegate_ = std::make_unique( - render_index.get(), + render_index_.get(), pxr::SdfPath::AbsoluteRootPath().AppendElementString("scene"), BlenderSceneDelegate::EngineType::FINAL); scene_delegate_->populate(depsgraph, context); for (auto const &setting : render_settings) { - render_delegate->SetRenderSetting(setting.first, setting.second); + render_delegate_->SetRenderSetting(setting.first, setting.second); } } @@ -49,19 +49,19 @@ void FinalEngine::render(Depsgraph *depsgraph) pxr::GfCamera camera = CameraData(scene->camera, image_res, pxr::GfVec4f(0, 0, 1, 1)).gf_camera(border); - free_camera_delegate->SetCamera(camera); - render_task_delegate->set_camera_and_viewport(free_camera_delegate->GetCameraId(), + free_camera_delegate_->SetCamera(camera); + render_task_delegate_->set_camera_and_viewport(free_camera_delegate_->GetCameraId(), pxr::GfVec4d(0, 0, res[0], res[1])); - render_task_delegate->set_renderer_aov(pxr::HdAovTokens->color); - if (simple_light_task_delegate) { - simple_light_task_delegate->set_camera_path(free_camera_delegate->GetCameraId()); + render_task_delegate_->set_renderer_aov(pxr::HdAovTokens->color); + if (simple_light_task_delegate_) { + simple_light_task_delegate_->set_camera_path(free_camera_delegate_->GetCameraId()); } pxr::HdTaskSharedPtrVector tasks; - if (simple_light_task_delegate) { - tasks.push_back(simple_light_task_delegate->get_task()); + if (simple_light_task_delegate_) { + tasks.push_back(simple_light_task_delegate_->get_task()); } - tasks.push_back(render_task_delegate->get_task()); + tasks.push_back(render_task_delegate_->get_task()); std::chrono::time_point time_begin = std::chrono::steady_clock::now(), time_current; @@ -76,11 +76,11 @@ void FinalEngine::render(Depsgraph *depsgraph) { // Release the GIL before calling into hydra, in case any hydra plugins call into python. pxr::TF_PY_ALLOW_THREADS_IN_SCOPE(); - engine->Execute(render_index.get(), &tasks); + engine_->Execute(render_index_.get(), &tasks); } while (true) { - if (RE_engine_test_break(bl_engine)) { + if (RE_engine_test_break(bl_engine_)) { break; } @@ -94,15 +94,15 @@ void FinalEngine::render(Depsgraph *depsgraph) "Render Time: " + format_duration(elapsed_time) + " | Done: " + std::to_string(int(percent_done)) + "%"); - if (render_task_delegate->is_converged()) { + if (render_task_delegate_->is_converged()) { break; } - render_task_delegate->get_renderer_aov_data(pxr::HdAovTokens->color, pixels.data()); + render_task_delegate_->get_renderer_aov_data(pxr::HdAovTokens->color, pixels.data()); update_render_result(render_images, layer_name, res[0], res[1]); } - render_task_delegate->get_renderer_aov_data(pxr::HdAovTokens->color, pixels.data()); + render_task_delegate_->get_renderer_aov_data(pxr::HdAovTokens->color, pixels.data()); update_render_result(render_images, layer_name, res[0], res[1]); } @@ -124,7 +124,7 @@ void FinalEngine::update_render_result(std::map> int height) { RenderResult *result = RE_engine_begin_result( - bl_engine, 0, 0, width, height, layer_name.c_str(), nullptr); + bl_engine_, 0, 0, width, height, layer_name.c_str(), nullptr); /* TODO: only for the first render layer */ RenderLayer *layer = (RenderLayer *)result->layers.first; @@ -138,13 +138,13 @@ void FinalEngine::update_render_result(std::map> sizeof(float) * pass->rectx * pass->recty * pass->channels); } - RE_engine_end_result(bl_engine, result, false, false, false); + RE_engine_end_result(bl_engine_, result, false, false, false); } void FinalEngine::notify_status(float progress, const std::string &title, const std::string &info) { - RE_engine_update_progress(bl_engine, progress); - RE_engine_update_stats(bl_engine, title.c_str(), info.c_str()); + RE_engine_update_progress(bl_engine_, progress); + RE_engine_update_stats(bl_engine_, title.c_str(), info.c_str()); } void FinalEngineGL::render(Depsgraph *depsgraph) @@ -169,21 +169,21 @@ void FinalEngineGL::render(Depsgraph *depsgraph) pxr::GfCamera camera = CameraData(scene->camera, image_res, pxr::GfVec4f(0, 0, 1, 1)).gf_camera(border); - free_camera_delegate->SetCamera(camera); - render_task_delegate->set_camera_and_viewport(free_camera_delegate->GetCameraId(), + free_camera_delegate_->SetCamera(camera); + render_task_delegate_->set_camera_and_viewport(free_camera_delegate_->GetCameraId(), pxr::GfVec4d(0, 0, res[0], res[1])); - if (simple_light_task_delegate) { - simple_light_task_delegate->set_camera_path(free_camera_delegate->GetCameraId()); + if (simple_light_task_delegate_) { + simple_light_task_delegate_->set_camera_path(free_camera_delegate_->GetCameraId()); } pxr::HdTaskSharedPtrVector tasks; - if (simple_light_task_delegate) { + if (simple_light_task_delegate_) { /* TODO: Uncomment this and fix GL error: invalid operation, reported from void __cdecl pxrInternal_v0_22__pxrReserved__::HgiGLResourceBindings::BindResources(void) */ - // tasks.push_back(simple_light_task_delegate->get_task()); + // tasks.push_back(simple_light_task_delegate_->get_task()); } - tasks.push_back(render_task_delegate->get_task()); + tasks.push_back(render_task_delegate_->get_task()); std::chrono::time_point time_begin = std::chrono::steady_clock::now(), time_current; @@ -214,11 +214,11 @@ void FinalEngineGL::render(Depsgraph *depsgraph) { // Release the GIL before calling into hydra, in case any hydra plugins call into python. pxr::TF_PY_ALLOW_THREADS_IN_SCOPE(); - engine->Execute(render_index.get(), &tasks); + engine_->Execute(render_index_.get(), &tasks); } while (true) { - if (RE_engine_test_break(bl_engine)) { + if (RE_engine_test_break(bl_engine_)) { break; } @@ -232,7 +232,7 @@ void FinalEngineGL::render(Depsgraph *depsgraph) "Render Time: " + format_duration(elapsed_time) + " | Done: " + std::to_string(int(percent_done)) + "%"); - if (render_task_delegate->is_converged()) { + if (render_task_delegate_->is_converged()) { break; } diff --git a/source/blender/render/hydra/final_engine.h b/source/blender/render/hydra/final_engine.h index 28c1cf6c7cec..066e00465ad7 100644 --- a/source/blender/render/hydra/final_engine.h +++ b/source/blender/render/hydra/final_engine.h @@ -12,6 +12,7 @@ namespace blender::render::hydra { class FinalEngine : public Engine { public: using Engine::Engine; + virtual void sync(Depsgraph *depsgraph, bContext *context, pxr::HdRenderSettingsMap &render_settings) override; @@ -25,13 +26,13 @@ class FinalEngine : public Engine { int height); void notify_status(float progress, const std::string &title, const std::string &info); - protected: pxr::HdRenderSettingsMap render_settings; }; class FinalEngineGL : public FinalEngine { public: using FinalEngine::FinalEngine; + void render(Depsgraph *depsgraph) override; }; diff --git a/source/blender/render/hydra/preview_engine.cc b/source/blender/render/hydra/preview_engine.cc index e69189411aa7..02cf8063ed74 100644 --- a/source/blender/render/hydra/preview_engine.cc +++ b/source/blender/render/hydra/preview_engine.cc @@ -11,14 +11,14 @@ namespace blender::render::hydra { const double LIFETIME = 180.0; -std::unique_ptr PreviewEngine::instance; +std::unique_ptr PreviewEngine::instance_; void PreviewEngine::schedule_free() { - instance->render_delegate->Stop(); + instance_->render_delegate_->Stop(); /* Register timer for schedule free PreviewEngine instance */ - BLI_timer_register((uintptr_t)instance.get(), + BLI_timer_register((uintptr_t)instance_.get(), free_instance, nullptr, nullptr, @@ -28,27 +28,27 @@ void PreviewEngine::schedule_free() PreviewEngine *PreviewEngine::get_instance(RenderEngine *bl_engine, const std::string &render_delegate_id) { - if (!instance) { - instance = std::make_unique(bl_engine, render_delegate_id); + if (!instance_) { + instance_ = std::make_unique(bl_engine, render_delegate_id); } - if (BLI_timer_is_registered((uintptr_t)instance.get())) { + if (BLI_timer_is_registered((uintptr_t)instance_.get())) { /* Unregister timer while PreviewEngine is working */ - BLI_timer_unregister((uintptr_t)instance.get()); + BLI_timer_unregister((uintptr_t)instance_.get()); } - instance->update(bl_engine, render_delegate_id); + instance_->update(bl_engine, render_delegate_id); - return instance.get(); + return instance_.get(); } double PreviewEngine::free_instance(uintptr_t uuid, void *user_data) { - if (!instance->render_task_delegate->is_converged()) { + if (!instance_->render_task_delegate_->is_converged()) { /* Restart timer if render isn't completed */ return LIFETIME; } CLOG_INFO(LOG_EN, 2, ""); - instance = nullptr; + instance_ = nullptr; return -1; } @@ -58,7 +58,7 @@ void PreviewEngine::sync(Depsgraph *depsgraph, { if (!scene_delegate_) { scene_delegate_ = std::make_unique( - render_index.get(), + render_index_.get(), pxr::SdfPath::AbsoluteRootPath().AppendElementString("scene"), BlenderSceneDelegate::EngineType::PREVIEW); } @@ -66,7 +66,7 @@ void PreviewEngine::sync(Depsgraph *depsgraph, scene_delegate_->populate(depsgraph, context); for (auto const &setting : render_settings) { - render_delegate->SetRenderSetting(setting.first, setting.second); + render_delegate_->SetRenderSetting(setting.first, setting.second); } } @@ -81,45 +81,45 @@ void PreviewEngine::render(Depsgraph *depsgraph) pxr::GfCamera camera = CameraData(scene->camera, res, pxr::GfVec4f(0, 0, 1, 1)).gf_camera(pxr::GfVec4f(0, 0, 1, 1)); - free_camera_delegate->SetCamera(camera); - render_task_delegate->set_camera_and_viewport(free_camera_delegate->GetCameraId(), + free_camera_delegate_->SetCamera(camera); + render_task_delegate_->set_camera_and_viewport(free_camera_delegate_->GetCameraId(), pxr::GfVec4d(0, 0, res[0], res[1])); - render_task_delegate->set_renderer_aov(pxr::HdAovTokens->color); + render_task_delegate_->set_renderer_aov(pxr::HdAovTokens->color); pxr::HdTaskSharedPtrVector tasks; - if (simple_light_task_delegate) { - tasks.push_back(simple_light_task_delegate->get_task()); + if (simple_light_task_delegate_) { + tasks.push_back(simple_light_task_delegate_->get_task()); } - tasks.push_back(render_task_delegate->get_task()); + tasks.push_back(render_task_delegate_->get_task()); std::vector pixels = std::vector(res[0] * res[1] * 4); // 4 - number of channels { // Release the GIL before calling into hydra, in case any hydra plugins call into python. pxr::TF_PY_ALLOW_THREADS_IN_SCOPE(); - engine->Execute(render_index.get(), &tasks); + engine_->Execute(render_index_.get(), &tasks); } while (true) { - if (RE_engine_test_break(bl_engine)) { + if (RE_engine_test_break(bl_engine_)) { break; } - if (render_task_delegate->is_converged()) { + if (render_task_delegate_->is_converged()) { break; } - render_task_delegate->get_renderer_aov_data(pxr::HdAovTokens->color, pixels.data()); + render_task_delegate_->get_renderer_aov_data(pxr::HdAovTokens->color, pixels.data()); update_render_result(layer_name, res[0], res[1], pixels); } - render_task_delegate->get_renderer_aov_data(pxr::HdAovTokens->color, pixels.data()); + render_task_delegate_->get_renderer_aov_data(pxr::HdAovTokens->color, pixels.data()); update_render_result(layer_name, res[0], res[1], pixels); } void PreviewEngine::update(RenderEngine *bl_engine, const std::string &render_delegate_id) { - this->bl_engine = bl_engine; + this->bl_engine_ = bl_engine; /* TODO: recreate render_delegate when render_delegate_id is changed */ } @@ -129,13 +129,13 @@ void PreviewEngine::update_render_result(const std::string &layer_name, std::vector &pixels) { RenderResult *result = RE_engine_begin_result( - bl_engine, 0, 0, width, height, layer_name.c_str(), nullptr); + bl_engine_, 0, 0, width, height, layer_name.c_str(), nullptr); RenderLayer *layer = (RenderLayer *)result->layers.first; RenderPass *pass = (RenderPass *)layer->passes.first; memcpy(pass->rect, pixels.data(), sizeof(float) * pass->rectx * pass->recty * pass->channels); - RE_engine_end_result(bl_engine, result, false, false, false); + RE_engine_end_result(bl_engine_, result, false, false, false); } } // namespace blender::render::hydra diff --git a/source/blender/render/hydra/preview_engine.h b/source/blender/render/hydra/preview_engine.h index 97ee9da93a3e..69c0a58c0451 100644 --- a/source/blender/render/hydra/preview_engine.h +++ b/source/blender/render/hydra/preview_engine.h @@ -8,22 +8,23 @@ namespace blender::render::hydra { class PreviewEngine : public FinalEngine { - private: - /* Singleton class instance */ - static std::unique_ptr instance; - static double free_instance(uintptr_t uuid, void *user_data); - public: - static PreviewEngine *get_instance(RenderEngine *bl_engine, const std::string &render_delegate_id); + using FinalEngine::FinalEngine; + + static PreviewEngine *get_instance(RenderEngine *bl_engine, + const std::string &render_delegate_id); static void schedule_free(); - using FinalEngine::FinalEngine; void sync(Depsgraph *depsgraph, bContext *context, pxr::HdRenderSettingsMap &render_settings) override; void render(Depsgraph *depsgraph) override; private: + /* Singleton class instance */ + static double free_instance(uintptr_t uuid, void *user_data); + static std::unique_ptr instance_; + void update(RenderEngine *bl_engine, const std::string &render_delegate_id); void update_render_result(const std::string &layer_name, int width, diff --git a/source/blender/render/hydra/render_task_delegate.cc b/source/blender/render/hydra/render_task_delegate.cc index 250b86619da8..92b0a4660c4a 100644 --- a/source/blender/render/hydra/render_task_delegate.cc +++ b/source/blender/render/hydra/render_task_delegate.cc @@ -22,8 +22,8 @@ RenderTaskDelegate::RenderTaskDelegate(pxr::HdRenderIndex *parent_index, GetRenderIndex().GetChangeTracker().MarkTaskDirty(render_task_id, pxr::HdChangeTracker::DirtyRenderTags); - task_params.enableLighting = true; - task_params.alphaThreshold = 0.1f; + task_params_.enableLighting = true; + task_params_.alphaThreshold = 0.1f; } pxr::SdfPath RenderTaskDelegate::get_task_id() const @@ -39,7 +39,7 @@ pxr::SdfPath RenderTaskDelegate::get_aov_id(pxr::TfToken const &aov) const pxr::VtValue RenderTaskDelegate::Get(pxr::SdfPath const &id, pxr::TfToken const &key) { if (key == pxr::HdTokens->params) { - return pxr::VtValue(task_params); + return pxr::VtValue(task_params_); } if (key == pxr::HdTokens->collection) { pxr::HdRprimCollection rprim_collection(pxr::HdTokens->geometry, @@ -54,7 +54,7 @@ pxr::VtValue RenderTaskDelegate::Get(pxr::SdfPath const &id, pxr::TfToken const pxr::HdRenderBufferDescriptor RenderTaskDelegate::GetRenderBufferDescriptor(pxr::SdfPath const &id) { - return buffer_descriptors[id]; + return buffer_descriptors_[id]; } pxr::TfTokenVector RenderTaskDelegate::GetTaskRenderTags(pxr::SdfPath const &task_id) @@ -73,14 +73,14 @@ void RenderTaskDelegate::set_renderer_aov(pxr::TfToken const &aov) pxr::HdAovDescriptor aov_desc = GetRenderIndex().GetRenderDelegate()->GetDefaultAovDescriptor( aov); pxr::HdRenderBufferDescriptor desc( - pxr::GfVec3i(task_params.viewport[2], task_params.viewport[3], 1), + pxr::GfVec3i(task_params_.viewport[2], task_params_.viewport[3], 1), aov_desc.format, aov_desc.multiSampled); pxr::SdfPath buffer_id = get_aov_id(aov); - if (buffer_descriptors.find(buffer_id) == buffer_descriptors.end()) { + if (buffer_descriptors_.find(buffer_id) == buffer_descriptors_.end()) { GetRenderIndex().InsertBprim(pxr::HdPrimTypeTokens->renderBuffer, this, buffer_id); - buffer_descriptors[buffer_id] = desc; + buffer_descriptors_[buffer_id] = desc; GetRenderIndex().GetChangeTracker().MarkBprimDirty(buffer_id, pxr::HdRenderBuffer::DirtyDescription); @@ -88,13 +88,13 @@ void RenderTaskDelegate::set_renderer_aov(pxr::TfToken const &aov) binding.aovName = aov; binding.renderBufferId = buffer_id; binding.aovSettings = aov_desc.aovSettings; - task_params.aovBindings.push_back(binding); + task_params_.aovBindings.push_back(binding); GetRenderIndex().GetChangeTracker().MarkTaskDirty(get_task_id(), pxr::HdChangeTracker::DirtyParams); } - else if (buffer_descriptors[buffer_id] != desc) { - buffer_descriptors[buffer_id] = desc; + else if (buffer_descriptors_[buffer_id] != desc) { + buffer_descriptors_[buffer_id] = desc; GetRenderIndex().GetChangeTracker().MarkBprimDirty(buffer_id, pxr::HdRenderBuffer::DirtyDescription); } @@ -124,9 +124,9 @@ pxr::HdTaskSharedPtr RenderTaskDelegate::get_task() void RenderTaskDelegate::set_camera_and_viewport(pxr::SdfPath const &camera_id, pxr::GfVec4d const &viewport) { - if (task_params.viewport != viewport || task_params.camera != camera_id) { - task_params.viewport = viewport; - task_params.camera = camera_id; + if (task_params_.viewport != viewport || task_params_.camera != camera_id) { + task_params_.viewport = viewport; + task_params_.camera = camera_id; GetRenderIndex().GetChangeTracker().MarkTaskDirty(get_task_id(), pxr::HdChangeTracker::DirtyParams); } diff --git a/source/blender/render/hydra/render_task_delegate.h b/source/blender/render/hydra/render_task_delegate.h index f7119fc83e2a..f8a1a956816c 100644 --- a/source/blender/render/hydra/render_task_delegate.h +++ b/source/blender/render/hydra/render_task_delegate.h @@ -16,10 +16,6 @@ class RenderTaskDelegate : public pxr::HdSceneDelegate { pxr::SdfPath get_task_id() const; pxr::SdfPath get_aov_id(pxr::TfToken const &aov) const; - pxr::VtValue Get(pxr::SdfPath const &id, pxr::TfToken const &key) override; - pxr::HdRenderBufferDescriptor GetRenderBufferDescriptor(pxr::SdfPath const &id) override; - pxr::TfTokenVector GetTaskRenderTags(pxr::SdfPath const &taskId) override; - bool is_converged(); void set_renderer_aov(pxr::TfToken const &aovId); pxr::HdRenderBuffer *get_renderer_aov(pxr::TfToken const &id); @@ -28,10 +24,15 @@ class RenderTaskDelegate : public pxr::HdSceneDelegate { pxr::HdTaskSharedPtr get_task(); void set_camera_and_viewport(pxr::SdfPath const &cameraId, pxr::GfVec4d const &viewport); + /* Delegate methods */ + pxr::VtValue Get(pxr::SdfPath const &id, pxr::TfToken const &key) override; + pxr::HdRenderBufferDescriptor GetRenderBufferDescriptor(pxr::SdfPath const &id) override; + pxr::TfTokenVector GetTaskRenderTags(pxr::SdfPath const &taskId) override; + private: - pxr::HdxRenderTaskParams task_params; + pxr::HdxRenderTaskParams task_params_; pxr::TfHashMap - buffer_descriptors; + buffer_descriptors_; }; } // namespace blender::render::hydra diff --git a/source/blender/render/hydra/simple_light_task_delegate.cc b/source/blender/render/hydra/simple_light_task_delegate.cc index 712e3c5e2cca..6bd7fc0cecfc 100644 --- a/source/blender/render/hydra/simple_light_task_delegate.cc +++ b/source/blender/render/hydra/simple_light_task_delegate.cc @@ -27,13 +27,13 @@ pxr::HdTaskSharedPtr SimpleLightTaskDelegate::get_task() void SimpleLightTaskDelegate::set_camera_path(pxr::SdfPath const &camera_path) { - task_params.cameraPath = camera_path; + task_params_.cameraPath = camera_path; } pxr::VtValue SimpleLightTaskDelegate::Get(pxr::SdfPath const &id, pxr::TfToken const &key) { if (key == pxr::HdTokens->params) { - return pxr::VtValue(task_params); + return pxr::VtValue(task_params_); } return pxr::VtValue(); } diff --git a/source/blender/render/hydra/simple_light_task_delegate.h b/source/blender/render/hydra/simple_light_task_delegate.h index 4c8f8ed20b27..376876b7f17b 100644 --- a/source/blender/render/hydra/simple_light_task_delegate.h +++ b/source/blender/render/hydra/simple_light_task_delegate.h @@ -18,10 +18,11 @@ class SimpleLightTaskDelegate : public pxr::HdSceneDelegate { pxr::HdTaskSharedPtr get_task(); void set_camera_path(pxr::SdfPath const &); + /* Delegate methods */ pxr::VtValue Get(pxr::SdfPath const &id, pxr::TfToken const &key) override; private: - pxr::HdxSimpleLightTaskParams task_params; + pxr::HdxSimpleLightTaskParams task_params_; }; } // namespace blender::render::hydra diff --git a/source/blender/render/hydra/viewport_engine.cc b/source/blender/render/hydra/viewport_engine.cc index 2115f5318754..63071cb534e5 100644 --- a/source/blender/render/hydra/viewport_engine.cc +++ b/source/blender/render/hydra/viewport_engine.cc @@ -132,7 +132,7 @@ pxr::GfCamera ViewSettings::gf_camera() (float)border[3] / screen_height)); } -DrawTexture::DrawTexture() : texture(nullptr), width(0), height(0), channels(4) +DrawTexture::DrawTexture() : texture_(nullptr), width_(0), height_(0), channels_(4) { float coords[8] = {0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0}; @@ -144,72 +144,72 @@ DrawTexture::DrawTexture() : texture(nullptr), width(0), height(0), channels(4) GPU_vertbuf_attr_fill(vbo, 0, coords); GPU_vertbuf_attr_fill(vbo, 1, coords); - batch = GPU_batch_create_ex(GPU_PRIM_TRI_FAN, vbo, nullptr, GPU_BATCH_OWNS_VBO); + batch_ = GPU_batch_create_ex(GPU_PRIM_TRI_FAN, vbo, nullptr, GPU_BATCH_OWNS_VBO); } DrawTexture::~DrawTexture() { - if (texture) { + if (texture_) { free(); } - GPU_batch_discard(batch); + GPU_batch_discard(batch_); } void DrawTexture::set_buffer(pxr::HdRenderBuffer *buffer) { - if (!texture) { + if (!texture_) { create(buffer); return; } - if (width != buffer->GetWidth() || height != buffer->GetHeight()) { + if (width_ != buffer->GetWidth() || height_ != buffer->GetHeight()) { free(); create(buffer); return; } void *data = buffer->Map(); - GPU_texture_update(texture, GPU_DATA_FLOAT, data); + GPU_texture_update(texture_, GPU_DATA_FLOAT, data); buffer->Unmap(); } void DrawTexture::create(pxr::HdRenderBuffer *buffer) { - width = buffer->GetWidth(); - height = buffer->GetHeight(); - channels = pxr::HdGetComponentCount(buffer->GetFormat()); + width_ = buffer->GetWidth(); + height_ = buffer->GetHeight(); + channels_ = pxr::HdGetComponentCount(buffer->GetFormat()); void *data = buffer->Map(); - texture = GPU_texture_create_2d("texHydraRenderViewport", - width, - height, + texture_ = GPU_texture_create_2d("texHydraRenderViewport", + width_, + height_, 1, GPU_RGBA16F, GPU_TEXTURE_USAGE_GENERAL, (float *)data); buffer->Unmap(); - GPU_texture_filter_mode(texture, true); - GPU_texture_mipmap_mode(texture, true, true); + GPU_texture_filter_mode(texture_, true); + GPU_texture_mipmap_mode(texture_, true, true); } void DrawTexture::free() { - GPU_texture_free(texture); - texture = nullptr; + GPU_texture_free(texture_); + texture_ = nullptr; } void DrawTexture::draw(GPUShader *shader, float x, float y) { int slot = GPU_shader_get_sampler_binding(shader, "image"); - GPU_texture_bind(texture, slot); + GPU_texture_bind(texture_, slot); GPU_shader_uniform_1i(shader, "image", slot); GPU_matrix_push(); GPU_matrix_translate_2f(x, y); - GPU_matrix_scale_2f(width, height); - GPU_batch_set_shader(batch, shader); - GPU_batch_draw(batch); + GPU_matrix_scale_2f(width_, height_); + GPU_batch_set_shader(batch_, shader); + GPU_batch_draw(batch_); GPU_matrix_pop(); } @@ -219,14 +219,14 @@ void ViewportEngine::sync(Depsgraph *depsgraph, { if (!scene_delegate_) { scene_delegate_ = std::make_unique( - render_index.get(), + render_index_.get(), pxr::SdfPath::AbsoluteRootPath().AppendElementString("scene"), BlenderSceneDelegate::EngineType::VIEWPORT); } scene_delegate_->populate(depsgraph, context); for (auto const &setting : render_settings) { - render_delegate->SetRenderSetting(setting.first, setting.second); + render_delegate_->SetRenderSetting(setting.first, setting.second); } } @@ -238,41 +238,41 @@ void ViewportEngine::render(Depsgraph *depsgraph, bContext *context) }; pxr::GfCamera gf_camera = view_settings.gf_camera(); - free_camera_delegate->SetCamera(gf_camera); - render_task_delegate->set_camera_and_viewport(free_camera_delegate->GetCameraId(), + free_camera_delegate_->SetCamera(gf_camera); + render_task_delegate_->set_camera_and_viewport(free_camera_delegate_->GetCameraId(), pxr::GfVec4d(view_settings.border[0], view_settings.border[1], view_settings.border[2], view_settings.border[3])); - if (simple_light_task_delegate) { - simple_light_task_delegate->set_camera_path(free_camera_delegate->GetCameraId()); + if (simple_light_task_delegate_) { + simple_light_task_delegate_->set_camera_path(free_camera_delegate_->GetCameraId()); } - if ((bl_engine->type->flag & RE_USE_GPU_CONTEXT) == 0) { - render_task_delegate->set_renderer_aov(pxr::HdAovTokens->color); + if ((bl_engine_->type->flag & RE_USE_GPU_CONTEXT) == 0) { + render_task_delegate_->set_renderer_aov(pxr::HdAovTokens->color); } if (renderer_percent_done() == 0.0f) { - time_begin = std::chrono::steady_clock::now(); + time_begin_ = std::chrono::steady_clock::now(); } GPUShader *shader = GPU_shader_get_builtin_shader(GPU_SHADER_3D_IMAGE); GPU_shader_bind(shader); pxr::HdTaskSharedPtrVector tasks; - if (simple_light_task_delegate) { - tasks.push_back(simple_light_task_delegate->get_task()); + if (simple_light_task_delegate_) { + tasks.push_back(simple_light_task_delegate_->get_task()); } - tasks.push_back(render_task_delegate->get_task()); + tasks.push_back(render_task_delegate_->get_task()); { /* Release the GIL before calling into hydra, in case any hydra plugins call into python. */ pxr::TF_PY_ALLOW_THREADS_IN_SCOPE(); - engine->Execute(render_index.get(), &tasks); + engine_->Execute(render_index_.get(), &tasks); - if ((bl_engine->type->flag & RE_USE_GPU_CONTEXT) == 0) { - draw_texture.set_buffer(render_task_delegate->get_renderer_aov(pxr::HdAovTokens->color)); - draw_texture.draw(shader, view_settings.border[0], view_settings.border[1]); + if ((bl_engine_->type->flag & RE_USE_GPU_CONTEXT) == 0) { + draw_texture_.set_buffer(render_task_delegate_->get_renderer_aov(pxr::HdAovTokens->color)); + draw_texture_.draw(shader, view_settings.border[0], view_settings.border[1]); } } @@ -281,15 +281,15 @@ void ViewportEngine::render(Depsgraph *depsgraph, bContext *context) std::chrono::time_point time_current = std::chrono::steady_clock::now(); std::chrono::milliseconds elapsed_time = std::chrono::duration_cast( - time_current - time_begin); + time_current - time_begin_); std::string formatted_time = format_duration(elapsed_time); - if (!render_task_delegate->is_converged()) { + if (!render_task_delegate_->is_converged()) { notify_status("Time: " + formatted_time + " | Done: " + std::to_string(int(renderer_percent_done())) + "%", "Render"); - bl_engine->flag |= RE_ENGINE_DO_DRAW; + bl_engine_->flag |= RE_ENGINE_DO_DRAW; } else { notify_status(("Time: " + formatted_time).c_str(), "Rendering Done"); @@ -303,7 +303,7 @@ void ViewportEngine::render(Depsgraph *depsgraph) void ViewportEngine::notify_status(const std::string &info, const std::string &status) { - RE_engine_update_stats(bl_engine, status.c_str(), info.c_str()); + RE_engine_update_stats(bl_engine_, status.c_str(), info.c_str()); } } // namespace blender::render::hydra diff --git a/source/blender/render/hydra/viewport_engine.h b/source/blender/render/hydra/viewport_engine.h index 154842fc7021..a362cf21bfba 100644 --- a/source/blender/render/hydra/viewport_engine.h +++ b/source/blender/render/hydra/viewport_engine.h @@ -19,6 +19,7 @@ class DrawTexture { public: DrawTexture(); ~DrawTexture(); + void set_buffer(pxr::HdRenderBuffer *buffer); void draw(GPUShader *shader, float x, float y); @@ -26,14 +27,15 @@ class DrawTexture { void create(pxr::HdRenderBuffer *buffer); void free(); - GPUTexture *texture; - GPUBatch *batch; - int width, height, channels; + GPUTexture *texture_; + GPUBatch *batch_; + int width_, height_, channels_; }; class ViewportEngine : public Engine { public: using Engine::Engine; + void sync(Depsgraph *depsgraph, bContext *context, pxr::HdRenderSettingsMap &render_settings) override; @@ -44,9 +46,9 @@ class ViewportEngine : public Engine { void notify_status(const std::string &title, const std::string &info); private: - std::chrono::time_point time_begin; + std::chrono::time_point time_begin_; - DrawTexture draw_texture; + DrawTexture draw_texture_; }; } // namespace blender::render::hydra -- 2.30.2 From 359c2894839f8490c2e5f0e0b81ab655b4bfc7d5 Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Thu, 13 Apr 2023 17:29:36 +0300 Subject: [PATCH 04/13] continuation --- source/blender/render/hydra/final_engine.h | 2 +- source/blender/render/hydra/preview_engine.cc | 38 ++++++-------- source/blender/render/hydra/python.cc | 2 +- .../render/hydra/render_task_delegate.cc | 52 +++++++++---------- .../blender/render/hydra/viewport_engine.cc | 38 +++++++------- 5 files changed, 64 insertions(+), 68 deletions(-) diff --git a/source/blender/render/hydra/final_engine.h b/source/blender/render/hydra/final_engine.h index 066e00465ad7..17473ad5ec74 100644 --- a/source/blender/render/hydra/final_engine.h +++ b/source/blender/render/hydra/final_engine.h @@ -26,7 +26,7 @@ class FinalEngine : public Engine { int height); void notify_status(float progress, const std::string &title, const std::string &info); - pxr::HdRenderSettingsMap render_settings; + pxr::HdRenderSettingsMap render_settings_; }; class FinalEngineGL : public FinalEngine { diff --git a/source/blender/render/hydra/preview_engine.cc b/source/blender/render/hydra/preview_engine.cc index 02cf8063ed74..620d34040ff2 100644 --- a/source/blender/render/hydra/preview_engine.cc +++ b/source/blender/render/hydra/preview_engine.cc @@ -13,19 +13,6 @@ const double LIFETIME = 180.0; std::unique_ptr PreviewEngine::instance_; -void PreviewEngine::schedule_free() -{ - instance_->render_delegate_->Stop(); - - /* Register timer for schedule free PreviewEngine instance */ - BLI_timer_register((uintptr_t)instance_.get(), - free_instance, - nullptr, - nullptr, - LIFETIME, - true); -} - PreviewEngine *PreviewEngine::get_instance(RenderEngine *bl_engine, const std::string &render_delegate_id) { if (!instance_) { @@ -40,16 +27,12 @@ PreviewEngine *PreviewEngine::get_instance(RenderEngine *bl_engine, const std::s return instance_.get(); } -double PreviewEngine::free_instance(uintptr_t uuid, void *user_data) +void PreviewEngine::schedule_free() { - if (!instance_->render_task_delegate_->is_converged()) { - /* Restart timer if render isn't completed */ - return LIFETIME; - } + instance_->render_delegate_->Stop(); - CLOG_INFO(LOG_EN, 2, ""); - instance_ = nullptr; - return -1; + /* Register timer for schedule free PreviewEngine instance */ + BLI_timer_register((uintptr_t)instance_.get(), free_instance, nullptr, nullptr, LIFETIME, true); } void PreviewEngine::sync(Depsgraph *depsgraph, @@ -117,6 +100,19 @@ void PreviewEngine::render(Depsgraph *depsgraph) update_render_result(layer_name, res[0], res[1], pixels); } +double PreviewEngine::free_instance(uintptr_t uuid, void *user_data) +{ + if (!instance_->render_task_delegate_->is_converged()) { + /* Restart timer if render isn't completed */ + return LIFETIME; + } + + CLOG_INFO(LOG_EN, 2, ""); + instance_ = nullptr; + return -1; +} + + void PreviewEngine::update(RenderEngine *bl_engine, const std::string &render_delegate_id) { this->bl_engine_ = bl_engine; diff --git a/source/blender/render/hydra/python.cc b/source/blender/render/hydra/python.cc index b97a31b15555..e445ead763a2 100644 --- a/source/blender/render/hydra/python.cc +++ b/source/blender/render/hydra/python.cc @@ -236,8 +236,8 @@ static PyMethodDef methods[] = { {"engine_create", engine_create_func, METH_VARARGS, ""}, {"engine_free", engine_free_func, METH_VARARGS, ""}, - {"engine_render", engine_render_func, METH_VARARGS, ""}, {"engine_sync", engine_sync_func, METH_VARARGS, ""}, + {"engine_render", engine_render_func, METH_VARARGS, ""}, {"engine_view_draw", engine_view_draw_func, METH_VARARGS, ""}, {NULL, NULL, 0, NULL}, diff --git a/source/blender/render/hydra/render_task_delegate.cc b/source/blender/render/hydra/render_task_delegate.cc index 92b0a4660c4a..d5348aef4d7b 100644 --- a/source/blender/render/hydra/render_task_delegate.cc +++ b/source/blender/render/hydra/render_task_delegate.cc @@ -36,32 +36,6 @@ pxr::SdfPath RenderTaskDelegate::get_aov_id(pxr::TfToken const &aov) const return GetDelegateID().AppendElementString("aov_" + aov.GetString()); } -pxr::VtValue RenderTaskDelegate::Get(pxr::SdfPath const &id, pxr::TfToken const &key) -{ - if (key == pxr::HdTokens->params) { - return pxr::VtValue(task_params_); - } - if (key == pxr::HdTokens->collection) { - pxr::HdRprimCollection rprim_collection(pxr::HdTokens->geometry, - pxr::HdReprSelector(pxr::HdReprTokens->smoothHull), - false, - pxr::TfToken()); - rprim_collection.SetRootPath(pxr::SdfPath::AbsoluteRootPath()); - return pxr::VtValue(rprim_collection); - } - return pxr::VtValue(); -} - -pxr::HdRenderBufferDescriptor RenderTaskDelegate::GetRenderBufferDescriptor(pxr::SdfPath const &id) -{ - return buffer_descriptors_[id]; -} - -pxr::TfTokenVector RenderTaskDelegate::GetTaskRenderTags(pxr::SdfPath const &task_id) -{ - return {pxr::HdRenderTagTokens->geometry}; -} - bool RenderTaskDelegate::is_converged() { pxr::HdTaskSharedPtr renderTask = GetRenderIndex().GetTask(get_task_id()); @@ -132,4 +106,30 @@ void RenderTaskDelegate::set_camera_and_viewport(pxr::SdfPath const &camera_id, } } +pxr::VtValue RenderTaskDelegate::Get(pxr::SdfPath const &id, pxr::TfToken const &key) +{ + if (key == pxr::HdTokens->params) { + return pxr::VtValue(task_params_); + } + if (key == pxr::HdTokens->collection) { + pxr::HdRprimCollection rprim_collection(pxr::HdTokens->geometry, + pxr::HdReprSelector(pxr::HdReprTokens->smoothHull), + false, + pxr::TfToken()); + rprim_collection.SetRootPath(pxr::SdfPath::AbsoluteRootPath()); + return pxr::VtValue(rprim_collection); + } + return pxr::VtValue(); +} + +pxr::HdRenderBufferDescriptor RenderTaskDelegate::GetRenderBufferDescriptor(pxr::SdfPath const &id) +{ + return buffer_descriptors_[id]; +} + +pxr::TfTokenVector RenderTaskDelegate::GetTaskRenderTags(pxr::SdfPath const &task_id) +{ + return {pxr::HdRenderTagTokens->geometry}; +} + } // namespace blender::render::hydra diff --git a/source/blender/render/hydra/viewport_engine.cc b/source/blender/render/hydra/viewport_engine.cc index 63071cb534e5..1946cb277a54 100644 --- a/source/blender/render/hydra/viewport_engine.cc +++ b/source/blender/render/hydra/viewport_engine.cc @@ -173,6 +173,20 @@ void DrawTexture::set_buffer(pxr::HdRenderBuffer *buffer) buffer->Unmap(); } +void DrawTexture::draw(GPUShader *shader, float x, float y) +{ + int slot = GPU_shader_get_sampler_binding(shader, "image"); + GPU_texture_bind(texture_, slot); + GPU_shader_uniform_1i(shader, "image", slot); + + GPU_matrix_push(); + GPU_matrix_translate_2f(x, y); + GPU_matrix_scale_2f(width_, height_); + GPU_batch_set_shader(batch_, shader); + GPU_batch_draw(batch_); + GPU_matrix_pop(); +} + void DrawTexture::create(pxr::HdRenderBuffer *buffer) { width_ = buffer->GetWidth(); @@ -199,20 +213,6 @@ void DrawTexture::free() texture_ = nullptr; } -void DrawTexture::draw(GPUShader *shader, float x, float y) -{ - int slot = GPU_shader_get_sampler_binding(shader, "image"); - GPU_texture_bind(texture_, slot); - GPU_shader_uniform_1i(shader, "image", slot); - - GPU_matrix_push(); - GPU_matrix_translate_2f(x, y); - GPU_matrix_scale_2f(width_, height_); - GPU_batch_set_shader(batch_, shader); - GPU_batch_draw(batch_); - GPU_matrix_pop(); -} - void ViewportEngine::sync(Depsgraph *depsgraph, bContext *context, pxr::HdRenderSettingsMap &render_settings) @@ -230,6 +230,11 @@ void ViewportEngine::sync(Depsgraph *depsgraph, } } +void ViewportEngine::render(Depsgraph *depsgraph) +{ + /* Empty function */ +} + void ViewportEngine::render(Depsgraph *depsgraph, bContext *context) { ViewSettings view_settings(context); @@ -296,11 +301,6 @@ void ViewportEngine::render(Depsgraph *depsgraph, bContext *context) } } -void ViewportEngine::render(Depsgraph *depsgraph) -{ - /* Empty function */ -} - void ViewportEngine::notify_status(const std::string &info, const std::string &status) { RE_engine_update_stats(bl_engine_, status.c_str(), info.c_str()); -- 2.30.2 From 4ff539776010f49ee05ace7f17a6de3298c7e48b Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Thu, 13 Apr 2023 17:39:51 +0300 Subject: [PATCH 05/13] formmating comments --- source/blender/render/hydra/camera.cc | 18 +++++++++--------- source/blender/render/hydra/final_engine.cc | 12 ++++++------ source/blender/render/hydra/preview_engine.cc | 4 ++-- source/blender/render/hydra/viewport_engine.cc | 8 ++++---- 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/source/blender/render/hydra/camera.cc b/source/blender/render/hydra/camera.cc index 5810be5d000f..28bc806e7d8c 100644 --- a/source/blender/render/hydra/camera.cc +++ b/source/blender/render/hydra/camera.cc @@ -15,8 +15,8 @@ CameraData::CameraData(bContext *context) RegionView3D *region_data = (RegionView3D *)CTX_wm_region_data(context); ARegion *region = CTX_wm_region(context); - // this constant was found experimentally, didn't find such option in - // context.view3d or context.region_data + /* This constant was found experimentally, didn't find such option in + * context.view3d or context.region_data. */ float VIEWPORT_SENSOR_SIZE = 72.0; pxr::GfVec2i res(region->winx, region->winy); @@ -62,13 +62,13 @@ CameraData::CameraData(bContext *context) *this = CameraData(view3d->camera, res, pxr::GfVec4f(0, 0, 1, 1)); transform_ = mat; - // This formula was taken from previous plugin with corresponded comment - // See blender/intern/cycles/blender/blender_camera.cpp:blender_camera_from_view (look - // for 1.41421f) + /* This formula was taken from previous plugin with corresponded comment. + * See blender/intern/cycles/blender/blender_camera.cpp:blender_camera_from_view (look + * for 1.41421f). */ float zoom = 4.0 / pow((pow(2.0, 0.5) + region_data->camzoom / 50.0), 2); - // Updating l_shift due to viewport zoom and view_camera_offset - // view_camera_offset should be multiplied by 2 + /* Updating l_shift due to viewport zoom and view_camera_offset + * view_camera_offset should be multiplied by 2. */ lens_shift_ = pxr::GfVec2f((lens_shift_[0] + region_data->camdx * 2) / zoom, (lens_shift_[1] + region_data->camdy * 2) / zoom); @@ -255,8 +255,8 @@ pxr::GfCamera CameraData::gf_camera(pxr::GfVec4f tile) case CAM_ORTHO: { gf_camera.SetProjection(pxr::GfCamera::Projection::Orthographic); - // Use tenths of a world unit accorging to USD docs - // https://graphics.pixar.com/usd/docs/api/class_gf_camera.html + /* Use tenths of a world unit accorging to USD docs + * https://graphics.pixar.com/usd/docs/api/class_gf_camera.html */ float o_size[2] = {ortho_size_[0] * t_size[0] * 10, ortho_size_[1] * t_size[1] * 10}; gf_camera.SetHorizontalAperture(o_size[0]); diff --git a/source/blender/render/hydra/final_engine.cc b/source/blender/render/hydra/final_engine.cc index c943d12d2f4d..e7cd0bf6943d 100644 --- a/source/blender/render/hydra/final_engine.cc +++ b/source/blender/render/hydra/final_engine.cc @@ -70,11 +70,11 @@ void FinalEngine::render(Depsgraph *depsgraph) float percent_done = 0.0; std::map> render_images{ - {"Combined", std::vector(res[0] * res[1] * 4)}}; // 4 - number of channels + {"Combined", std::vector(res[0] * res[1] * 4)}}; /* 4 - number of channels. */ std::vector &pixels = render_images["Combined"]; { - // Release the GIL before calling into hydra, in case any hydra plugins call into python. + /* Release the GIL before calling into hydra, in case any hydra plugins call into python. */ pxr::TF_PY_ALLOW_THREADS_IN_SCOPE(); engine_->Execute(render_index_.get(), &tasks); } @@ -179,8 +179,8 @@ void FinalEngineGL::render(Depsgraph *depsgraph) pxr::HdTaskSharedPtrVector tasks; if (simple_light_task_delegate_) { /* TODO: Uncomment this and fix GL error: - invalid operation, reported from void __cdecl - pxrInternal_v0_22__pxrReserved__::HgiGLResourceBindings::BindResources(void) */ + * invalid operation, reported from void __cdecl + * pxrInternal_v0_22__pxrReserved__::HgiGLResourceBindings::BindResources(void) */ // tasks.push_back(simple_light_task_delegate_->get_task()); } tasks.push_back(render_task_delegate_->get_task()); @@ -192,7 +192,7 @@ void FinalEngineGL::render(Depsgraph *depsgraph) float percent_done = 0.0; std::map> render_images{ - {"Combined", std::vector(res[0] * res[1] * 4)}}; // 4 - number of channels + {"Combined", std::vector(res[0] * res[1] * 4)}}; /* 4 - number of channels. */ std::vector &pixels = render_images["Combined"]; GPUFrameBuffer *framebuffer = GPU_framebuffer_create("fbHydraRenderFinal"); @@ -212,7 +212,7 @@ void FinalEngineGL::render(Depsgraph *depsgraph) GPU_framebuffer_clear_color_depth(framebuffer, clear_color, 1.0); { - // Release the GIL before calling into hydra, in case any hydra plugins call into python. + /* Release the GIL before calling into hydra, in case any hydra plugins call into python. */ pxr::TF_PY_ALLOW_THREADS_IN_SCOPE(); engine_->Execute(render_index_.get(), &tasks); } diff --git a/source/blender/render/hydra/preview_engine.cc b/source/blender/render/hydra/preview_engine.cc index 620d34040ff2..57b2695da241 100644 --- a/source/blender/render/hydra/preview_engine.cc +++ b/source/blender/render/hydra/preview_engine.cc @@ -75,10 +75,10 @@ void PreviewEngine::render(Depsgraph *depsgraph) } tasks.push_back(render_task_delegate_->get_task()); - std::vector pixels = std::vector(res[0] * res[1] * 4); // 4 - number of channels + std::vector pixels = std::vector(res[0] * res[1] * 4); /* 4 - number of channels. */ { - // Release the GIL before calling into hydra, in case any hydra plugins call into python. + /* Release the GIL before calling into hydra, in case any hydra plugins call into python. */ pxr::TF_PY_ALLOW_THREADS_IN_SCOPE(); engine_->Execute(render_index_.get(), &tasks); } diff --git a/source/blender/render/hydra/viewport_engine.cc b/source/blender/render/hydra/viewport_engine.cc index 1946cb277a54..1fe9bf23695f 100644 --- a/source/blender/render/hydra/viewport_engine.cc +++ b/source/blender/render/hydra/viewport_engine.cc @@ -47,7 +47,7 @@ ViewSettings::ViewSettings(bContext *context) : camera_data(context) Scene *scene = CTX_data_scene(context); - // getting render border + /* Getting render border. */ int x1 = 0, y1 = 0; int x2 = screen_width, y2 = screen_height; @@ -73,7 +73,7 @@ ViewSettings::ViewSettings(bContext *context) : camera_data(context) } } - // getting camera view region + /* Getting camera view region. */ float x1_f = std::min( {screen_points[0][0], screen_points[1][0], screen_points[2][0], screen_points[3][0]}); float x2_f = std::max( @@ -83,7 +83,7 @@ ViewSettings::ViewSettings(bContext *context) : camera_data(context) float y2_f = std::max( {screen_points[0][1], screen_points[1][1], screen_points[2][1], screen_points[3][1]}); - // adjusting region to border + /* Adjusting region to border. */ float x = x1_f, y = y1_f; float dx = x2_f - x1_f, dy = y2_f - y1_f; @@ -92,7 +92,7 @@ ViewSettings::ViewSettings(bContext *context) : camera_data(context) y1 = y + scene->r.border.ymin * dy; y2 = y + scene->r.border.ymax * dy; - // adjusting to region screen resolution + /* Adjusting to region screen resolution. */ x1 = std::max(std::min(x1, screen_width), 0); x2 = std::max(std::min(x2, screen_width), 0); y1 = std::max(std::min(y1, screen_height), 0); -- 2.30.2 From 69179066ed0c7eb646d343943fd652b25343cb01 Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Thu, 13 Apr 2023 21:35:42 +0300 Subject: [PATCH 06/13] make format --- source/blender/render/hydra/camera.cc | 4 +--- source/blender/render/hydra/final_engine.cc | 17 ++++++---------- source/blender/render/hydra/preview_engine.cc | 11 +++++----- source/blender/render/hydra/preview_engine.h | 1 - .../render/hydra/scene_delegate/instancer.cc | 3 ++- .../render/hydra/scene_delegate/instancer.h | 3 ++- .../render/hydra/scene_delegate/material.cc | 3 ++- .../render/hydra/scene_delegate/mesh.cc | 3 ++- .../scene_delegate/mtlx_hydra_adapter.cc | 6 +++--- .../blender/render/hydra/viewport_engine.cc | 20 +++++++++---------- 10 files changed, 34 insertions(+), 37 deletions(-) diff --git a/source/blender/render/hydra/camera.cc b/source/blender/render/hydra/camera.cc index 28bc806e7d8c..b9917061fdd6 100644 --- a/source/blender/render/hydra/camera.cc +++ b/source/blender/render/hydra/camera.cc @@ -70,7 +70,7 @@ CameraData::CameraData(bContext *context) /* Updating l_shift due to viewport zoom and view_camera_offset * view_camera_offset should be multiplied by 2. */ lens_shift_ = pxr::GfVec2f((lens_shift_[0] + region_data->camdx * 2) / zoom, - (lens_shift_[1] + region_data->camdy * 2) / zoom); + (lens_shift_[1] + region_data->camdy * 2) / zoom); if (mode_ == CAM_ORTHO) { ortho_size_ *= zoom; @@ -274,6 +274,4 @@ pxr::GfCamera CameraData::gf_camera(pxr::GfVec4f tile) return gf_camera; } - - } // namespace blender::render::hydra diff --git a/source/blender/render/hydra/final_engine.cc b/source/blender/render/hydra/final_engine.cc index e7cd0bf6943d..c019dea58172 100644 --- a/source/blender/render/hydra/final_engine.cc +++ b/source/blender/render/hydra/final_engine.cc @@ -51,7 +51,7 @@ void FinalEngine::render(Depsgraph *depsgraph) free_camera_delegate_->SetCamera(camera); render_task_delegate_->set_camera_and_viewport(free_camera_delegate_->GetCameraId(), - pxr::GfVec4d(0, 0, res[0], res[1])); + pxr::GfVec4d(0, 0, res[0], res[1])); render_task_delegate_->set_renderer_aov(pxr::HdAovTokens->color); if (simple_light_task_delegate_) { simple_light_task_delegate_->set_camera_path(free_camera_delegate_->GetCameraId()); @@ -70,7 +70,7 @@ void FinalEngine::render(Depsgraph *depsgraph) float percent_done = 0.0; std::map> render_images{ - {"Combined", std::vector(res[0] * res[1] * 4)}}; /* 4 - number of channels. */ + {"Combined", std::vector(res[0] * res[1] * 4)}}; /* 4 - number of channels. */ std::vector &pixels = render_images["Combined"]; { @@ -171,7 +171,7 @@ void FinalEngineGL::render(Depsgraph *depsgraph) free_camera_delegate_->SetCamera(camera); render_task_delegate_->set_camera_and_viewport(free_camera_delegate_->GetCameraId(), - pxr::GfVec4d(0, 0, res[0], res[1])); + pxr::GfVec4d(0, 0, res[0], res[1])); if (simple_light_task_delegate_) { simple_light_task_delegate_->set_camera_path(free_camera_delegate_->GetCameraId()); } @@ -192,17 +192,12 @@ void FinalEngineGL::render(Depsgraph *depsgraph) float percent_done = 0.0; std::map> render_images{ - {"Combined", std::vector(res[0] * res[1] * 4)}}; /* 4 - number of channels. */ + {"Combined", std::vector(res[0] * res[1] * 4)}}; /* 4 - number of channels. */ std::vector &pixels = render_images["Combined"]; GPUFrameBuffer *framebuffer = GPU_framebuffer_create("fbHydraRenderFinal"); - GPUTexture *texture = GPU_texture_create_2d("texHydraRenderFinal", - res[0], - res[1], - 1, - GPU_RGBA32F, - GPU_TEXTURE_USAGE_GENERAL, - nullptr); + GPUTexture *texture = GPU_texture_create_2d( + "texHydraRenderFinal", res[0], res[1], 1, GPU_RGBA32F, GPU_TEXTURE_USAGE_GENERAL, nullptr); GPU_texture_filter_mode(texture, true); GPU_texture_mipmap_mode(texture, true, true); GPU_framebuffer_texture_attach(framebuffer, texture, 0, 0); diff --git a/source/blender/render/hydra/preview_engine.cc b/source/blender/render/hydra/preview_engine.cc index 57b2695da241..71301ae71396 100644 --- a/source/blender/render/hydra/preview_engine.cc +++ b/source/blender/render/hydra/preview_engine.cc @@ -3,9 +3,9 @@ #include "DEG_depsgraph_query.h" +#include "BLI_timer.h" #include "camera.h" #include "preview_engine.h" -#include "BLI_timer.h" namespace blender::render::hydra { @@ -13,7 +13,8 @@ const double LIFETIME = 180.0; std::unique_ptr PreviewEngine::instance_; -PreviewEngine *PreviewEngine::get_instance(RenderEngine *bl_engine, const std::string &render_delegate_id) +PreviewEngine *PreviewEngine::get_instance(RenderEngine *bl_engine, + const std::string &render_delegate_id) { if (!instance_) { instance_ = std::make_unique(bl_engine, render_delegate_id); @@ -66,7 +67,7 @@ void PreviewEngine::render(Depsgraph *depsgraph) free_camera_delegate_->SetCamera(camera); render_task_delegate_->set_camera_and_viewport(free_camera_delegate_->GetCameraId(), - pxr::GfVec4d(0, 0, res[0], res[1])); + pxr::GfVec4d(0, 0, res[0], res[1])); render_task_delegate_->set_renderer_aov(pxr::HdAovTokens->color); pxr::HdTaskSharedPtrVector tasks; @@ -75,7 +76,8 @@ void PreviewEngine::render(Depsgraph *depsgraph) } tasks.push_back(render_task_delegate_->get_task()); - std::vector pixels = std::vector(res[0] * res[1] * 4); /* 4 - number of channels. */ + std::vector pixels = std::vector(res[0] * res[1] * + 4); /* 4 - number of channels. */ { /* Release the GIL before calling into hydra, in case any hydra plugins call into python. */ @@ -112,7 +114,6 @@ double PreviewEngine::free_instance(uintptr_t uuid, void *user_data) return -1; } - void PreviewEngine::update(RenderEngine *bl_engine, const std::string &render_delegate_id) { this->bl_engine_ = bl_engine; diff --git a/source/blender/render/hydra/preview_engine.h b/source/blender/render/hydra/preview_engine.h index 69c0a58c0451..64e969eca368 100644 --- a/source/blender/render/hydra/preview_engine.h +++ b/source/blender/render/hydra/preview_engine.h @@ -30,7 +30,6 @@ class PreviewEngine : public FinalEngine { int width, int height, std::vector &pixels); - }; } // namespace blender::render::hydra diff --git a/source/blender/render/hydra/scene_delegate/instancer.cc b/source/blender/render/hydra/scene_delegate/instancer.cc index 5f5f3774a3ea..6123a9331c80 100644 --- a/source/blender/render/hydra/scene_delegate/instancer.cc +++ b/source/blender/render/hydra/scene_delegate/instancer.cc @@ -172,7 +172,8 @@ bool InstancerData::set_instances() ID *prev_id = id_; id_ = nullptr; transforms_.clear(); - ListBase *lb = object_duplilist(scene_delegate_->depsgraph_, scene_delegate_->scene_, parent_obj_); + ListBase *lb = object_duplilist( + scene_delegate_->depsgraph_, scene_delegate_->scene_, parent_obj_); LISTBASE_FOREACH (DupliObject *, dupli, lb) { if (!id_) { /* TODO: We create instances only for object in first dupli. diff --git a/source/blender/render/hydra/scene_delegate/instancer.h b/source/blender/render/hydra/scene_delegate/instancer.h index f057e7c342ee..7989fd701d6f 100644 --- a/source/blender/render/hydra/scene_delegate/instancer.h +++ b/source/blender/render/hydra/scene_delegate/instancer.h @@ -27,7 +27,8 @@ class InstancerData : public MeshData { pxr::GfMatrix4d get_transform() override; bool update_visibility(View3D *view3d) override; - pxr::HdPrimvarDescriptorVector get_instancer_primvar_descriptors(pxr::HdInterpolation interpolation); + pxr::HdPrimvarDescriptorVector get_instancer_primvar_descriptors( + pxr::HdInterpolation interpolation); pxr::VtIntArray get_instance_indices(); bool is_base(Object *object) const; diff --git a/source/blender/render/hydra/scene_delegate/material.cc b/source/blender/render/hydra/scene_delegate/material.cc index 6e134763bd81..1ba1c21f014d 100644 --- a/source/blender/render/hydra/scene_delegate/material.cc +++ b/source/blender/render/hydra/scene_delegate/material.cc @@ -131,7 +131,8 @@ pxr::VtValue MaterialData::get_material_resource() pxr::TfTokenVector render_contexts = render_delegate->GetMaterialRenderContexts(); pxr::HdMaterialNetworkMap network_map; - hdmtlx_convert_to_materialnetworkmap(path, shader_source_types, render_contexts, &network_map); + hdmtlx_convert_to_materialnetworkmap( + path, shader_source_types, render_contexts, &network_map); material_network_map_ = network_map; } diff --git a/source/blender/render/hydra/scene_delegate/mesh.cc b/source/blender/render/hydra/scene_delegate/mesh.cc index 76deb7ec9fc7..e4e21a6e6f23 100644 --- a/source/blender/render/hydra/scene_delegate/mesh.cc +++ b/source/blender/render/hydra/scene_delegate/mesh.cc @@ -134,7 +134,8 @@ pxr::HdMeshTopology MeshData::get_mesh_topology() face_vertex_indices_); } -pxr::HdPrimvarDescriptorVector MeshData::get_primvar_descriptors(pxr::HdInterpolation interpolation) +pxr::HdPrimvarDescriptorVector MeshData::get_primvar_descriptors( + pxr::HdInterpolation interpolation) { pxr::HdPrimvarDescriptorVector primvars; if (interpolation == pxr::HdInterpolationVertex) { diff --git a/source/blender/render/hydra/scene_delegate/mtlx_hydra_adapter.cc b/source/blender/render/hydra/scene_delegate/mtlx_hydra_adapter.cc index 36686d89690a..58836be947cc 100644 --- a/source/blender/render/hydra/scene_delegate/mtlx_hydra_adapter.cc +++ b/source/blender/render/hydra/scene_delegate/mtlx_hydra_adapter.cc @@ -23,9 +23,9 @@ namespace mx = MaterialX; void hdmtlx_convert_to_materialnetworkmap(std::string const &mtlx_path, - pxr::TfTokenVector const &shader_source_types, - pxr::TfTokenVector const &render_contexts, - pxr::HdMaterialNetworkMap *out) + pxr::TfTokenVector const &shader_source_types, + pxr::TfTokenVector const &render_contexts, + pxr::HdMaterialNetworkMap *out) { if (mtlx_path.empty()) { return; diff --git a/source/blender/render/hydra/viewport_engine.cc b/source/blender/render/hydra/viewport_engine.cc index 1fe9bf23695f..aa4b14cde2d5 100644 --- a/source/blender/render/hydra/viewport_engine.cc +++ b/source/blender/render/hydra/viewport_engine.cc @@ -195,12 +195,12 @@ void DrawTexture::create(pxr::HdRenderBuffer *buffer) void *data = buffer->Map(); texture_ = GPU_texture_create_2d("texHydraRenderViewport", - width_, - height_, - 1, - GPU_RGBA16F, - GPU_TEXTURE_USAGE_GENERAL, - (float *)data); + width_, + height_, + 1, + GPU_RGBA16F, + GPU_TEXTURE_USAGE_GENERAL, + (float *)data); buffer->Unmap(); GPU_texture_filter_mode(texture_, true); @@ -245,10 +245,10 @@ void ViewportEngine::render(Depsgraph *depsgraph, bContext *context) pxr::GfCamera gf_camera = view_settings.gf_camera(); free_camera_delegate_->SetCamera(gf_camera); render_task_delegate_->set_camera_and_viewport(free_camera_delegate_->GetCameraId(), - pxr::GfVec4d(view_settings.border[0], - view_settings.border[1], - view_settings.border[2], - view_settings.border[3])); + pxr::GfVec4d(view_settings.border[0], + view_settings.border[1], + view_settings.border[2], + view_settings.border[3])); if (simple_light_task_delegate_) { simple_light_task_delegate_->set_camera_path(free_camera_delegate_->GetCameraId()); } -- 2.30.2 From fa34aadc6844bb942b3cccebbce1500539fc129e Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Fri, 14 Apr 2023 13:32:22 +0300 Subject: [PATCH 07/13] fox review comments --- source/blender/render/hydra/engine.cc | 1 + source/blender/render/hydra/engine.h | 2 -- source/blender/render/hydra/final_engine.cc | 16 ++++++++-------- source/blender/render/hydra/preview_engine.cc | 4 ++-- .../scene_delegate/blender_scene_delegate.cc | 5 +---- .../scene_delegate/blender_scene_delegate.h | 8 ++++---- source/blender/render/hydra/viewport_engine.cc | 8 +++++--- 7 files changed, 21 insertions(+), 23 deletions(-) diff --git a/source/blender/render/hydra/engine.cc b/source/blender/render/hydra/engine.cc index 6f048c25a17d..a36bfd401193 100644 --- a/source/blender/render/hydra/engine.cc +++ b/source/blender/render/hydra/engine.cc @@ -46,6 +46,7 @@ Engine::Engine(RenderEngine *bl_engine, const std::string &delegate_id) : bl_eng Engine::~Engine() { + /* Destructor must exists and keep deletion order */ scene_delegate_ = nullptr; render_task_delegate_ = nullptr; free_camera_delegate_ = nullptr; diff --git a/source/blender/render/hydra/engine.h b/source/blender/render/hydra/engine.h index 9e27b98cde35..ec1c0e17e8af 100644 --- a/source/blender/render/hydra/engine.h +++ b/source/blender/render/hydra/engine.h @@ -5,8 +5,6 @@ #include -#include - #include #include #include diff --git a/source/blender/render/hydra/final_engine.cc b/source/blender/render/hydra/final_engine.cc index c019dea58172..9e077f511b8d 100644 --- a/source/blender/render/hydra/final_engine.cc +++ b/source/blender/render/hydra/final_engine.cc @@ -29,14 +29,14 @@ void FinalEngine::sync(Depsgraph *depsgraph, void FinalEngine::render(Depsgraph *depsgraph) { - Scene *scene = DEG_get_input_scene(depsgraph); - ViewLayer *view_layer = DEG_get_input_view_layer(depsgraph); + const Scene *scene = DEG_get_evaluated_scene(depsgraph); + const ViewLayer *view_layer = DEG_get_evaluated_view_layer(depsgraph); std::string scene_name(MAX_ID_FULL_NAME, 0); BKE_id_full_name_get(scene_name.data(), (ID *)scene, 0); std::string layer_name = view_layer->name; - RenderData &r = scene->r; + const RenderData &r = scene->r; pxr::GfVec4f border(0, 0, 1, 1); if (r.mode & R_BORDER) { border = pxr::GfVec4f(r.border.xmin, @@ -149,14 +149,14 @@ void FinalEngine::notify_status(float progress, const std::string &title, const void FinalEngineGL::render(Depsgraph *depsgraph) { - Scene *scene = DEG_get_input_scene(depsgraph); - ViewLayer *view_layer = DEG_get_input_view_layer(depsgraph); + const Scene *scene = DEG_get_evaluated_scene(depsgraph); + const ViewLayer *view_layer = DEG_get_evaluated_view_layer(depsgraph); std::string scene_name(MAX_ID_FULL_NAME, 0); BKE_id_full_name_get(scene_name.data(), (ID *)scene, 0); std::string layer_name = view_layer->name; - RenderData &r = scene->r; + const RenderData &r = scene->r; pxr::GfVec4f border(0, 0, 1, 1); if (r.mode & R_BORDER) { border = pxr::GfVec4f(r.border.xmin, @@ -195,9 +195,9 @@ void FinalEngineGL::render(Depsgraph *depsgraph) {"Combined", std::vector(res[0] * res[1] * 4)}}; /* 4 - number of channels. */ std::vector &pixels = render_images["Combined"]; - GPUFrameBuffer *framebuffer = GPU_framebuffer_create("fbHydraRenderFinal"); + GPUFrameBuffer *framebuffer = GPU_framebuffer_create("fb_hdyra_render_final"); GPUTexture *texture = GPU_texture_create_2d( - "texHydraRenderFinal", res[0], res[1], 1, GPU_RGBA32F, GPU_TEXTURE_USAGE_GENERAL, nullptr); + "tex_hydra_render_final", res[0], res[1], 1, GPU_RGBA32F, GPU_TEXTURE_USAGE_GENERAL, nullptr); GPU_texture_filter_mode(texture, true); GPU_texture_mipmap_mode(texture, true, true); GPU_framebuffer_texture_attach(framebuffer, texture, 0, 0); diff --git a/source/blender/render/hydra/preview_engine.cc b/source/blender/render/hydra/preview_engine.cc index 71301ae71396..08b1f5b90c7d 100644 --- a/source/blender/render/hydra/preview_engine.cc +++ b/source/blender/render/hydra/preview_engine.cc @@ -56,8 +56,8 @@ void PreviewEngine::sync(Depsgraph *depsgraph, void PreviewEngine::render(Depsgraph *depsgraph) { - Scene *scene = DEG_get_input_scene(depsgraph); - ViewLayer *view_layer = DEG_get_input_view_layer(depsgraph); + const Scene *scene = DEG_get_evaluated_scene(depsgraph); + const ViewLayer *view_layer = DEG_get_evaluated_view_layer(depsgraph); std::string layer_name = view_layer->name; pxr::GfVec2i res(scene->r.xsch, scene->r.ysch); diff --git a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc index f5481b6736f0..9b8e7b2d70a1 100644 --- a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc +++ b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc @@ -17,10 +17,7 @@ BlenderSceneDelegate::BlenderSceneDelegate(pxr::HdRenderIndex *parent_index, pxr::SdfPath const &delegate_id, BlenderSceneDelegate::EngineType engine_type) : HdSceneDelegate(parent_index, delegate_id), - engine_type(engine_type), - depsgraph_(nullptr), - context_(nullptr), - view3d_(nullptr) + engine_type(engine_type) { } diff --git a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.h b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.h index 7684ca95b308..9239beaae642 100644 --- a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.h +++ b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.h @@ -66,11 +66,11 @@ class BlenderSceneDelegate : public pxr::HdSceneDelegate { void update_world(); void update_collection(bool remove, bool visibility); - Depsgraph *depsgraph_; - bContext *context_; + Depsgraph *depsgraph_ = nullptr; + bContext *context_ = nullptr; + View3D *view3d_ = nullptr; Scene *scene_; - View3D *view3d_; - + ObjectDataMap objects_; MaterialDataMap materials_; std::unique_ptr world_data_; diff --git a/source/blender/render/hydra/viewport_engine.cc b/source/blender/render/hydra/viewport_engine.cc index aa4b14cde2d5..f3db317a9a8b 100644 --- a/source/blender/render/hydra/viewport_engine.cc +++ b/source/blender/render/hydra/viewport_engine.cc @@ -5,15 +5,17 @@ #include #include -// clang-format off #include "DNA_camera_types.h" #include "DNA_screen_types.h" #include "DNA_vec_types.h" /* this include must be before BKE_camera.h due to "rctf" type */ + #include "BKE_camera.h" + #include "BLI_math_matrix.h" + #include "DEG_depsgraph_query.h" + #include "GPU_matrix.h" -// clang-format on #include "camera.h" #include "utils.h" @@ -194,7 +196,7 @@ void DrawTexture::create(pxr::HdRenderBuffer *buffer) channels_ = pxr::HdGetComponentCount(buffer->GetFormat()); void *data = buffer->Map(); - texture_ = GPU_texture_create_2d("texHydraRenderViewport", + texture_ = GPU_texture_create_2d("tex_hydra_render_viewport", width_, height_, 1, -- 2.30.2 From 9bea6a6e9450322b5cda7330b74301b9fdf1a1a9 Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Fri, 14 Apr 2023 14:07:35 +0300 Subject: [PATCH 08/13] removed destructor, ordered members --- source/blender/render/hydra/engine.cc | 13 ------------- source/blender/render/hydra/engine.h | 3 ++- 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/source/blender/render/hydra/engine.cc b/source/blender/render/hydra/engine.cc index a36bfd401193..26026dad49ea 100644 --- a/source/blender/render/hydra/engine.cc +++ b/source/blender/render/hydra/engine.cc @@ -44,19 +44,6 @@ Engine::Engine(RenderEngine *bl_engine, const std::string &delegate_id) : bl_eng engine_ = std::make_unique(); } -Engine::~Engine() -{ - /* Destructor must exists and keep deletion order */ - scene_delegate_ = nullptr; - render_task_delegate_ = nullptr; - free_camera_delegate_ = nullptr; - simple_light_task_delegate_ = nullptr; - render_index_ = nullptr; - render_delegate_ = nullptr; - engine_ = nullptr; - hgi_ = nullptr; -} - float Engine::renderer_percent_done() { pxr::VtDictionary render_stats = render_delegate_->GetRenderStats(); diff --git a/source/blender/render/hydra/engine.h b/source/blender/render/hydra/engine.h index ec1c0e17e8af..16a4a42225c1 100644 --- a/source/blender/render/hydra/engine.h +++ b/source/blender/render/hydra/engine.h @@ -26,7 +26,7 @@ extern struct CLG_LogRef *LOG_EN; /* EN - Engine */ class Engine { public: Engine(RenderEngine *bl_engine, const std::string &render_delegate_id); - virtual ~Engine(); + virtual ~Engine() {}; virtual void sync(Depsgraph *depsgraph, bContext *context, @@ -38,6 +38,7 @@ class Engine { RenderEngine *bl_engine_; + /* The order is important due to deletion order */ pxr::HdPluginRenderDelegateUniqueHandle render_delegate_; std::unique_ptr render_index_; std::unique_ptr scene_delegate_; -- 2.30.2 From a935ea75fdfd70cfc72f58b7b03b487f7fceca6b Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Fri, 14 Apr 2023 14:08:09 +0300 Subject: [PATCH 09/13] make format --- source/blender/render/hydra/engine.h | 2 +- source/blender/render/hydra/final_engine.cc | 9 +++++++-- .../hydra/scene_delegate/blender_scene_delegate.cc | 3 +-- .../render/hydra/scene_delegate/blender_scene_delegate.h | 2 +- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/source/blender/render/hydra/engine.h b/source/blender/render/hydra/engine.h index 16a4a42225c1..b0dfa8b859ee 100644 --- a/source/blender/render/hydra/engine.h +++ b/source/blender/render/hydra/engine.h @@ -26,7 +26,7 @@ extern struct CLG_LogRef *LOG_EN; /* EN - Engine */ class Engine { public: Engine(RenderEngine *bl_engine, const std::string &render_delegate_id); - virtual ~Engine() {}; + virtual ~Engine(){}; virtual void sync(Depsgraph *depsgraph, bContext *context, diff --git a/source/blender/render/hydra/final_engine.cc b/source/blender/render/hydra/final_engine.cc index 9e077f511b8d..f2b8286fc04c 100644 --- a/source/blender/render/hydra/final_engine.cc +++ b/source/blender/render/hydra/final_engine.cc @@ -196,8 +196,13 @@ void FinalEngineGL::render(Depsgraph *depsgraph) std::vector &pixels = render_images["Combined"]; GPUFrameBuffer *framebuffer = GPU_framebuffer_create("fb_hdyra_render_final"); - GPUTexture *texture = GPU_texture_create_2d( - "tex_hydra_render_final", res[0], res[1], 1, GPU_RGBA32F, GPU_TEXTURE_USAGE_GENERAL, nullptr); + GPUTexture *texture = GPU_texture_create_2d("tex_hydra_render_final", + res[0], + res[1], + 1, + GPU_RGBA32F, + GPU_TEXTURE_USAGE_GENERAL, + nullptr); GPU_texture_filter_mode(texture, true); GPU_texture_mipmap_mode(texture, true, true); GPU_framebuffer_texture_attach(framebuffer, texture, 0, 0); diff --git a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc index 9b8e7b2d70a1..170ef92cdc61 100644 --- a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc +++ b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc @@ -16,8 +16,7 @@ CLG_LOGREF_DECLARE_GLOBAL(LOG_BSD, "rhd.bsd"); BlenderSceneDelegate::BlenderSceneDelegate(pxr::HdRenderIndex *parent_index, pxr::SdfPath const &delegate_id, BlenderSceneDelegate::EngineType engine_type) - : HdSceneDelegate(parent_index, delegate_id), - engine_type(engine_type) + : HdSceneDelegate(parent_index, delegate_id), engine_type(engine_type) { } diff --git a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.h b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.h index 9239beaae642..0a6933623eac 100644 --- a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.h +++ b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.h @@ -70,7 +70,7 @@ class BlenderSceneDelegate : public pxr::HdSceneDelegate { bContext *context_ = nullptr; View3D *view3d_ = nullptr; Scene *scene_; - + ObjectDataMap objects_; MaterialDataMap materials_; std::unique_ptr world_data_; -- 2.30.2 From f82fb51015d2b5e9da9e5c60853b5240374a4884 Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Fri, 14 Apr 2023 14:44:27 +0300 Subject: [PATCH 10/13] changed destructor --- source/blender/render/hydra/engine.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/blender/render/hydra/engine.h b/source/blender/render/hydra/engine.h index b0dfa8b859ee..4de015e51ee1 100644 --- a/source/blender/render/hydra/engine.h +++ b/source/blender/render/hydra/engine.h @@ -26,7 +26,7 @@ extern struct CLG_LogRef *LOG_EN; /* EN - Engine */ class Engine { public: Engine(RenderEngine *bl_engine, const std::string &render_delegate_id); - virtual ~Engine(){}; + virtual ~Engine() = default; virtual void sync(Depsgraph *depsgraph, bContext *context, -- 2.30.2 From 43493aa7d4298661239d7fe639a7af4de2be94ca Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Fri, 14 Apr 2023 15:52:47 +0300 Subject: [PATCH 11/13] set nullptr to field --- .../render/hydra/scene_delegate/blender_scene_delegate.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.h b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.h index 0a6933623eac..ba008badf877 100644 --- a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.h +++ b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.h @@ -69,7 +69,7 @@ class BlenderSceneDelegate : public pxr::HdSceneDelegate { Depsgraph *depsgraph_ = nullptr; bContext *context_ = nullptr; View3D *view3d_ = nullptr; - Scene *scene_; + Scene *scene_ = nullptr; ObjectDataMap objects_; MaterialDataMap materials_; -- 2.30.2 From 78a399d04c58fe5bfe2f6ea81dec1da7ba110cf8 Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Fri, 14 Apr 2023 18:19:25 +0300 Subject: [PATCH 12/13] fix review comments --- .../scene_delegate/blender_scene_delegate.cc | 98 +++++++++---------- .../scene_delegate/blender_scene_delegate.h | 12 +-- .../render/hydra/scene_delegate/instancer.cc | 10 +- .../render/hydra/scene_delegate/instancer.h | 8 +- .../render/hydra/scene_delegate/light.cc | 6 +- .../render/hydra/scene_delegate/light.h | 2 +- .../render/hydra/scene_delegate/material.cc | 4 +- .../render/hydra/scene_delegate/material.h | 2 +- .../render/hydra/scene_delegate/mesh.cc | 12 +-- .../render/hydra/scene_delegate/mesh.h | 6 +- .../render/hydra/scene_delegate/object.cc | 6 +- .../render/hydra/scene_delegate/object.h | 4 +- .../render/hydra/scene_delegate/world.cc | 6 +- .../render/hydra/scene_delegate/world.h | 4 +- 14 files changed, 90 insertions(+), 90 deletions(-) diff --git a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc index 170ef92cdc61..b2ad611d7ec0 100644 --- a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc +++ b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc @@ -86,8 +86,8 @@ void BlenderSceneDelegate::populate(Depsgraph *deps, bContext *cont) } break; case ID_MA: { - MaterialData *mat_data = get_material_data( - MaterialData::get_prim_id(this, (Material *)id)); + MaterialData *mat_data = material_data( + MaterialData::prim_id(this, (Material *)id)); if (mat_data) { mat_data->update(); } @@ -127,25 +127,25 @@ void BlenderSceneDelegate::clear() pxr::HdMeshTopology BlenderSceneDelegate::GetMeshTopology(pxr::SdfPath const &id) { CLOG_INFO(LOG_BSD, 3, "%s", id.GetText()); - MeshData *m_data = get_mesh_data(id); - return m_data->get_mesh_topology(); + MeshData *m_data = mesh_data(id); + return m_data->mesh_topology(); } pxr::GfMatrix4d BlenderSceneDelegate::GetTransform(pxr::SdfPath const &id) { CLOG_INFO(LOG_BSD, 3, "%s", id.GetText()); - ObjectData *obj_data = get_object_data(id); + ObjectData *obj_data = object_data(id); if (obj_data) { - return obj_data->get_transform(); + return obj_data->transform(); } - if (id == WorldData::get_prim_id(this)) { - return world_data_->get_transform(); + if (id == WorldData::prim_id(this)) { + return world_data_->transform(); } - InstancerData *i_data = get_instancer_data(id); + InstancerData *i_data = instancer_data(id); if (i_data) { - return i_data->get_transform(); + return i_data->transform(); } return pxr::GfMatrix4d(); @@ -155,17 +155,17 @@ pxr::VtValue BlenderSceneDelegate::Get(pxr::SdfPath const &id, pxr::TfToken cons { CLOG_INFO(LOG_BSD, 3, "%s, %s", id.GetText(), key.GetText()); - ObjectData *obj_data = get_object_data(id); + ObjectData *obj_data = object_data(id); if (obj_data) { return obj_data->get_data(key); } - MaterialData *mat_data = get_material_data(id); + MaterialData *mat_data = material_data(id); if (mat_data) { return mat_data->get_data(key); } - InstancerData *i_data = get_instancer_data(id); + InstancerData *i_data = instancer_data(id); if (i_data) { return i_data->get_data(key); } @@ -176,11 +176,11 @@ pxr::VtValue BlenderSceneDelegate::Get(pxr::SdfPath const &id, pxr::TfToken cons pxr::VtValue BlenderSceneDelegate::GetLightParamValue(pxr::SdfPath const &id, pxr::TfToken const &key) { - LightData *l_data = get_light_data(id); + LightData *l_data = light_data(id); if (l_data) { return l_data->get_data(key); } - if (id == WorldData::get_prim_id(this)) { + if (id == WorldData::prim_id(this)) { return world_data_->get_data(key); } return pxr::VtValue(); @@ -191,14 +191,14 @@ pxr::HdPrimvarDescriptorVector BlenderSceneDelegate::GetPrimvarDescriptors( { CLOG_INFO(LOG_BSD, 3, "%s, %d", id.GetText(), interpolation); - MeshData *m_data = get_mesh_data(id); + MeshData *m_data = mesh_data(id); if (m_data) { - return m_data->get_primvar_descriptors(interpolation); + return m_data->primvar_descriptors(interpolation); } - InstancerData *i_data = get_instancer_data(id); + InstancerData *i_data = instancer_data(id); if (i_data) { - return i_data->get_instancer_primvar_descriptors(interpolation); + return i_data->instancer_primvar_descriptors(interpolation); } return pxr::HdPrimvarDescriptorVector(); @@ -206,12 +206,12 @@ pxr::HdPrimvarDescriptorVector BlenderSceneDelegate::GetPrimvarDescriptors( pxr::SdfPath BlenderSceneDelegate::GetMaterialId(pxr::SdfPath const &rprim_id) { - return get_mesh_data(rprim_id)->get_material_id(); + return mesh_data(rprim_id)->material_id(); } pxr::VtValue BlenderSceneDelegate::GetMaterialResource(pxr::SdfPath const &id) { - MaterialData *mat_data = get_material_data(id); + MaterialData *mat_data = material_data(id); if (mat_data) { return mat_data->get_material_resource(); } @@ -220,17 +220,17 @@ pxr::VtValue BlenderSceneDelegate::GetMaterialResource(pxr::SdfPath const &id) bool BlenderSceneDelegate::GetVisible(pxr::SdfPath const &id) { - if (id == WorldData::get_prim_id(this)) { + if (id == WorldData::prim_id(this)) { return true; } - return get_object_data(id)->visible; + return object_data(id)->visible; } pxr::SdfPath BlenderSceneDelegate::GetInstancerId(pxr::SdfPath const &prim_id) { CLOG_INFO(LOG_BSD, 3, "%s", prim_id.GetText()); - InstancerData *i_data = get_instancer_data(prim_id, true); + InstancerData *i_data = instancer_data(prim_id, true); if (i_data) { return i_data->instancer_id; } @@ -249,18 +249,18 @@ pxr::VtIntArray BlenderSceneDelegate::GetInstanceIndices(pxr::SdfPath const &ins pxr::SdfPath const &prototype_id) { CLOG_INFO(LOG_BSD, 3, "%s, %s", instancer_id.GetText(), prototype_id.GetText()); - InstancerData *i_data = get_instancer_data(instancer_id); - return i_data->get_instance_indices(); + InstancerData *i_data = instancer_data(instancer_id); + return i_data->instance_indices(); } pxr::GfMatrix4d BlenderSceneDelegate::GetInstancerTransform(pxr::SdfPath const &instancer_id) { CLOG_INFO(LOG_BSD, 3, "%s", instancer_id.GetText()); - InstancerData *i_data = get_instancer_data(instancer_id); - return i_data->get_transform(); + InstancerData *i_data = instancer_data(instancer_id); + return i_data->transform(); } -ObjectData *BlenderSceneDelegate::get_object_data(pxr::SdfPath const &id) +ObjectData *BlenderSceneDelegate::object_data(pxr::SdfPath const &id) { auto it = objects_.find(id); if (it == objects_.end()) { @@ -269,17 +269,17 @@ ObjectData *BlenderSceneDelegate::get_object_data(pxr::SdfPath const &id) return it->second.get(); } -MeshData *BlenderSceneDelegate::get_mesh_data(pxr::SdfPath const &id) +MeshData *BlenderSceneDelegate::mesh_data(pxr::SdfPath const &id) { - return dynamic_cast(get_object_data(id)); + return dynamic_cast(object_data(id)); } -LightData *BlenderSceneDelegate::get_light_data(pxr::SdfPath const &id) +LightData *BlenderSceneDelegate::light_data(pxr::SdfPath const &id) { - return dynamic_cast(get_object_data(id)); + return dynamic_cast(object_data(id)); } -MaterialData *BlenderSceneDelegate::get_material_data(pxr::SdfPath const &id) +MaterialData *BlenderSceneDelegate::material_data(pxr::SdfPath const &id) { auto it = materials_.find(id); if (it == materials_.end()) { @@ -288,15 +288,15 @@ MaterialData *BlenderSceneDelegate::get_material_data(pxr::SdfPath const &id) return it->second.get(); } -InstancerData *BlenderSceneDelegate::get_instancer_data(pxr::SdfPath const &id, bool base_prim) +InstancerData *BlenderSceneDelegate::instancer_data(pxr::SdfPath const &id, bool base_prim) { if (base_prim) { - return dynamic_cast(get_object_data(id)); + return dynamic_cast(object_data(id)); } - return dynamic_cast(get_object_data(id.GetParentPath())); + return dynamic_cast(object_data(id.GetParentPath())); } -InstancerData *BlenderSceneDelegate::get_instancer_data(Object *object) +InstancerData *BlenderSceneDelegate::instancer_data(Object *object) { InstancerData *i_data; for (auto &it : objects_) { @@ -313,13 +313,13 @@ void BlenderSceneDelegate::add_update_object(Object *object) if ((object->transflag & OB_DUPLI) && InstancerData::is_supported(object)) { add_update_instancer(object); } - InstancerData *i_data = get_instancer_data(object); + InstancerData *i_data = instancer_data(object); if (i_data) { i_data->update(); } - pxr::SdfPath id = ObjectData::get_prim_id(this, object); - ObjectData *obj_data = get_object_data(id); + pxr::SdfPath id = ObjectData::prim_id(this, object); + ObjectData *obj_data = object_data(id); if (obj_data) { obj_data->update(); return; @@ -328,20 +328,20 @@ void BlenderSceneDelegate::add_update_object(Object *object) return; } objects_[id] = ObjectData::create(this, object); - obj_data = get_object_data(id); + obj_data = object_data(id); obj_data->update_visibility(view3d_); } void BlenderSceneDelegate::add_update_instancer(Object *object) { - pxr::SdfPath id = InstancerData::get_prim_id(this, object); - InstancerData *i_data = get_instancer_data(id, true); + pxr::SdfPath id = InstancerData::prim_id(this, object); + InstancerData *i_data = instancer_data(id, true); if (i_data) { i_data->update(); return; } objects_[id] = InstancerData::create(this, object); - i_data = get_instancer_data(id, true); + i_data = instancer_data(id, true); i_data->update_visibility(view3d_); } @@ -397,15 +397,15 @@ void BlenderSceneDelegate::update_collection(bool remove, bool visibility) continue; } - id = ObjectData::get_prim_id(this, object); + id = ObjectData::prim_id(this, object); if (remove) { available_objects.insert(id); if ((object->transflag & OB_DUPLI) && InstancerData::is_supported(object)) { - available_objects.insert(InstancerData::get_prim_id(this, object)); + available_objects.insert(InstancerData::prim_id(this, object)); } } - if (!get_object_data(id)) { + if (!object_data(id)) { add_update_object(object); } } @@ -429,7 +429,7 @@ void BlenderSceneDelegate::update_collection(bool remove, bool visibility) if (!m_data) { continue; } - pxr::SdfPath mat_id = m_data->get_material_id(); + pxr::SdfPath mat_id = m_data->material_id(); if (!mat_id.IsEmpty()) { available_materials.insert(mat_id); } diff --git a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.h b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.h index ba008badf877..48c84e987e14 100644 --- a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.h +++ b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.h @@ -54,12 +54,12 @@ class BlenderSceneDelegate : public pxr::HdSceneDelegate { EngineType engine_type; private: - ObjectData *get_object_data(pxr::SdfPath const &id); - MeshData *get_mesh_data(pxr::SdfPath const &id); - LightData *get_light_data(pxr::SdfPath const &id); - MaterialData *get_material_data(pxr::SdfPath const &id); - InstancerData *get_instancer_data(pxr::SdfPath const &id, bool base_prim = false); - InstancerData *get_instancer_data(Object *object); + ObjectData *object_data(pxr::SdfPath const &id); + MeshData *mesh_data(pxr::SdfPath const &id); + LightData *light_data(pxr::SdfPath const &id); + MaterialData *material_data(pxr::SdfPath const &id); + InstancerData *instancer_data(pxr::SdfPath const &id, bool base_prim = false); + InstancerData *instancer_data(Object *object); void add_update_object(Object *object); void add_update_instancer(Object *object); diff --git a/source/blender/render/hydra/scene_delegate/instancer.cc b/source/blender/render/hydra/scene_delegate/instancer.cc index 6123a9331c80..8e85c641841f 100644 --- a/source/blender/render/hydra/scene_delegate/instancer.cc +++ b/source/blender/render/hydra/scene_delegate/instancer.cc @@ -13,7 +13,7 @@ InstancerData::InstancerData(BlenderSceneDelegate *scene_delegate, Object *objec : MeshData(scene_delegate, object), parent_obj_(object) { id_ = nullptr; - p_id_ = get_prim_id(scene_delegate, object); + p_id_ = prim_id(scene_delegate, object); instancer_id = p_id_.AppendElementString("Instancer"); CLOG_INFO(LOG_BSD, 2, "%s, instancer_id=%s", ((ID *)parent_obj_)->name, instancer_id.GetText()); } @@ -43,7 +43,7 @@ std::unique_ptr InstancerData::create(BlenderSceneDelegate *scene return data; } -pxr::SdfPath InstancerData::get_prim_id(BlenderSceneDelegate *scene_delegate, Object *object) +pxr::SdfPath InstancerData::prim_id(BlenderSceneDelegate *scene_delegate, Object *object) { /* Making id of instancer in form like I_. Example: * I_000002073e369608 */ @@ -121,7 +121,7 @@ pxr::VtValue InstancerData::get_data(pxr::TfToken const &key) const return MeshData::get_data(key); } -pxr::GfMatrix4d InstancerData::get_transform() +pxr::GfMatrix4d InstancerData::transform() { return pxr::GfMatrix4d(1.0); } @@ -142,7 +142,7 @@ bool InstancerData::update_visibility(View3D *view3d) return ret; } -pxr::HdPrimvarDescriptorVector InstancerData::get_instancer_primvar_descriptors( +pxr::HdPrimvarDescriptorVector InstancerData::instancer_primvar_descriptors( pxr::HdInterpolation interpolation) { pxr::HdPrimvarDescriptorVector primvars; @@ -153,7 +153,7 @@ pxr::HdPrimvarDescriptorVector InstancerData::get_instancer_primvar_descriptors( return primvars; } -pxr::VtIntArray InstancerData::get_instance_indices() +pxr::VtIntArray InstancerData::instance_indices() { pxr::VtIntArray ret(transforms_.size()); for (size_t i = 0; i < ret.size(); ++i) { diff --git a/source/blender/render/hydra/scene_delegate/instancer.h b/source/blender/render/hydra/scene_delegate/instancer.h index 7989fd701d6f..5c3a9a4dbfa7 100644 --- a/source/blender/render/hydra/scene_delegate/instancer.h +++ b/source/blender/render/hydra/scene_delegate/instancer.h @@ -16,7 +16,7 @@ class InstancerData : public MeshData { static bool is_supported(Object *object); static std::unique_ptr create(BlenderSceneDelegate *scene_delegate, Object *object); - static pxr::SdfPath get_prim_id(BlenderSceneDelegate *scene_delegate, Object *object); + static pxr::SdfPath prim_id(BlenderSceneDelegate *scene_delegate, Object *object); void init() override; void insert() override; @@ -24,12 +24,12 @@ class InstancerData : public MeshData { void update() override; pxr::VtValue get_data(pxr::TfToken const &key) const override; - pxr::GfMatrix4d get_transform() override; + pxr::GfMatrix4d transform() override; bool update_visibility(View3D *view3d) override; - pxr::HdPrimvarDescriptorVector get_instancer_primvar_descriptors( + pxr::HdPrimvarDescriptorVector instancer_primvar_descriptors( pxr::HdInterpolation interpolation); - pxr::VtIntArray get_instance_indices(); + pxr::VtIntArray instance_indices(); bool is_base(Object *object) const; pxr::SdfPath instancer_id; diff --git a/source/blender/render/hydra/scene_delegate/light.cc b/source/blender/render/hydra/scene_delegate/light.cc index a63d919325d9..ca99694a57de 100644 --- a/source/blender/render/hydra/scene_delegate/light.cc +++ b/source/blender/render/hydra/scene_delegate/light.cc @@ -79,7 +79,7 @@ void LightData::init() break; } - p_type_ = get_prim_type(light); + p_type_ = prim_type(light); /* TODO: temporary value, it should be delivered through Python UI */ data_[pxr::HdLightTokens->exposure] = 1.0f; @@ -102,7 +102,7 @@ void LightData::update() CLOG_INFO(LOG_BSD, 2, "%s", id_->name); Light *light = (Light *)((Object *)id_)->data; - if (get_prim_type(light) != p_type_) { + if (prim_type(light) != p_type_) { remove(); init(); insert(); @@ -151,7 +151,7 @@ bool LightData::update_visibility(View3D *view3d) return ret; } -pxr::TfToken LightData::get_prim_type(Light *light) +pxr::TfToken LightData::prim_type(Light *light) { pxr::TfToken ret; switch (light->type) { diff --git a/source/blender/render/hydra/scene_delegate/light.h b/source/blender/render/hydra/scene_delegate/light.h index a325c6f0457d..4aa91040e761 100644 --- a/source/blender/render/hydra/scene_delegate/light.h +++ b/source/blender/render/hydra/scene_delegate/light.h @@ -26,7 +26,7 @@ class LightData : public ObjectData { bool update_visibility(View3D *view3d) override; private: - pxr::TfToken get_prim_type(Light *light); + pxr::TfToken prim_type(Light *light); std::map data_; pxr::TfToken p_type_; diff --git a/source/blender/render/hydra/scene_delegate/material.cc b/source/blender/render/hydra/scene_delegate/material.cc index 1ba1c21f014d..d13b011e89b3 100644 --- a/source/blender/render/hydra/scene_delegate/material.cc +++ b/source/blender/render/hydra/scene_delegate/material.cc @@ -23,7 +23,7 @@ namespace blender::render::hydra { MaterialData::MaterialData(BlenderSceneDelegate *scene_delegate, Material *material) : IdData(scene_delegate, (ID *)material) { - p_id_ = get_prim_id(scene_delegate, material); + p_id_ = prim_id(scene_delegate, material); CLOG_INFO(LOG_BSD, 2, "%s, id=%s", id_->name, p_id_.GetText()); } @@ -36,7 +36,7 @@ std::unique_ptr MaterialData::create(BlenderSceneDelegate *scene_d return data; } -pxr::SdfPath MaterialData::get_prim_id(BlenderSceneDelegate *scene_delegate, Material *material) +pxr::SdfPath MaterialData::prim_id(BlenderSceneDelegate *scene_delegate, Material *material) { /* Making id of material in form like M_. * Example: M_000002074e812088 */ diff --git a/source/blender/render/hydra/scene_delegate/material.h b/source/blender/render/hydra/scene_delegate/material.h index 2f42f37c2826..1389fec8ade1 100644 --- a/source/blender/render/hydra/scene_delegate/material.h +++ b/source/blender/render/hydra/scene_delegate/material.h @@ -23,7 +23,7 @@ class MaterialData : IdData { static std::unique_ptr create(BlenderSceneDelegate *scene_delegate, Material *material); - static pxr::SdfPath get_prim_id(BlenderSceneDelegate *scene_delegate, Material *material); + static pxr::SdfPath prim_id(BlenderSceneDelegate *scene_delegate, Material *material); void init() override; void insert() override; diff --git a/source/blender/render/hydra/scene_delegate/mesh.cc b/source/blender/render/hydra/scene_delegate/mesh.cc index e4e21a6e6f23..359fa35b4594 100644 --- a/source/blender/render/hydra/scene_delegate/mesh.cc +++ b/source/blender/render/hydra/scene_delegate/mesh.cc @@ -126,7 +126,7 @@ bool MeshData::update_visibility(View3D *view3d) return ret; } -pxr::HdMeshTopology MeshData::get_mesh_topology() +pxr::HdMeshTopology MeshData::mesh_topology() { return pxr::HdMeshTopology(pxr::PxOsdOpenSubdivTokens->none, pxr::HdTokens->rightHanded, @@ -134,7 +134,7 @@ pxr::HdMeshTopology MeshData::get_mesh_topology() face_vertex_indices_); } -pxr::HdPrimvarDescriptorVector MeshData::get_primvar_descriptors( +pxr::HdPrimvarDescriptorVector MeshData::primvar_descriptors( pxr::HdInterpolation interpolation) { pxr::HdPrimvarDescriptorVector primvars; @@ -157,7 +157,7 @@ pxr::HdPrimvarDescriptorVector MeshData::get_primvar_descriptors( return primvars; } -pxr::SdfPath MeshData::get_material_id() +pxr::SdfPath MeshData::material_id() { if (!mat_data_) { return pxr::SdfPath(); @@ -216,11 +216,11 @@ void MeshData::write_material() mat_data_ = nullptr; return; } - pxr::SdfPath id = MaterialData::get_prim_id(scene_delegate_, mat); - mat_data_ = scene_delegate_->get_material_data(id); + pxr::SdfPath id = MaterialData::prim_id(scene_delegate_, mat); + mat_data_ = scene_delegate_->material_data(id); if (!mat_data_) { scene_delegate_->materials_[id] = MaterialData::create(scene_delegate_, mat); - mat_data_ = scene_delegate_->get_material_data(id); + mat_data_ = scene_delegate_->material_data(id); } } diff --git a/source/blender/render/hydra/scene_delegate/mesh.h b/source/blender/render/hydra/scene_delegate/mesh.h index 0b7247a49507..c710c7317e8d 100644 --- a/source/blender/render/hydra/scene_delegate/mesh.h +++ b/source/blender/render/hydra/scene_delegate/mesh.h @@ -25,9 +25,9 @@ class MeshData : public ObjectData { pxr::VtValue get_data(pxr::TfToken const &key) const override; bool update_visibility(View3D *view3d) override; - pxr::HdMeshTopology get_mesh_topology(); - pxr::HdPrimvarDescriptorVector get_primvar_descriptors(pxr::HdInterpolation interpolation); - pxr::SdfPath get_material_id(); + pxr::HdMeshTopology mesh_topology(); + pxr::HdPrimvarDescriptorVector primvar_descriptors(pxr::HdInterpolation interpolation); + pxr::SdfPath material_id(); protected: void write_mesh(Mesh *mesh); diff --git a/source/blender/render/hydra/scene_delegate/object.cc b/source/blender/render/hydra/scene_delegate/object.cc index 1f6914e262f8..241c047d451e 100644 --- a/source/blender/render/hydra/scene_delegate/object.cc +++ b/source/blender/render/hydra/scene_delegate/object.cc @@ -14,7 +14,7 @@ namespace blender::render::hydra { ObjectData::ObjectData(BlenderSceneDelegate *scene_delegate, Object *object) : IdData(scene_delegate, (ID *)object), visible(true) { - p_id_ = get_prim_id(scene_delegate, object); + p_id_ = prim_id(scene_delegate, object); } bool ObjectData::is_supported(Object *object) @@ -62,7 +62,7 @@ std::unique_ptr ObjectData::create(BlenderSceneDelegate *scene_deleg return data; } -pxr::SdfPath ObjectData::get_prim_id(BlenderSceneDelegate *scene_delegate, Object *object) +pxr::SdfPath ObjectData::prim_id(BlenderSceneDelegate *scene_delegate, Object *object) { /* Making id of object in form like O_. Example: * O_000002073e369608 */ @@ -71,7 +71,7 @@ pxr::SdfPath ObjectData::get_prim_id(BlenderSceneDelegate *scene_delegate, Objec return scene_delegate->GetDelegateID().AppendElementString(str); } -pxr::GfMatrix4d ObjectData::get_transform() +pxr::GfMatrix4d ObjectData::transform() { return gf_matrix_from_transform(((Object *)id_)->object_to_world); } diff --git a/source/blender/render/hydra/scene_delegate/object.h b/source/blender/render/hydra/scene_delegate/object.h index 7778e74dd9e2..4a60b5d64c59 100644 --- a/source/blender/render/hydra/scene_delegate/object.h +++ b/source/blender/render/hydra/scene_delegate/object.h @@ -20,9 +20,9 @@ class ObjectData : public IdData { static bool is_supported(Object *object); static std::unique_ptr create(BlenderSceneDelegate *scene_delegate, Object *object); - static pxr::SdfPath get_prim_id(BlenderSceneDelegate *scene_delegate, Object *object); + static pxr::SdfPath prim_id(BlenderSceneDelegate *scene_delegate, Object *object); - virtual pxr::GfMatrix4d get_transform(); + virtual pxr::GfMatrix4d transform(); virtual bool update_visibility(View3D *view3d); bool visible; diff --git a/source/blender/render/hydra/scene_delegate/world.cc b/source/blender/render/hydra/scene_delegate/world.cc index 6dc0fbc5c99d..e712d076c336 100644 --- a/source/blender/render/hydra/scene_delegate/world.cc +++ b/source/blender/render/hydra/scene_delegate/world.cc @@ -31,7 +31,7 @@ namespace blender::render::hydra { WorldData::WorldData(BlenderSceneDelegate *scene_delegate, World *world, bContext *context) : IdData(scene_delegate, (ID *)world), context_(context) { - p_id_ = get_prim_id(scene_delegate); + p_id_ = prim_id(scene_delegate); CLOG_INFO(LOG_BSD, 2, "%s, id=%s", id_->name, p_id_.GetText()); } @@ -45,7 +45,7 @@ std::unique_ptr WorldData::create(BlenderSceneDelegate *scene_delegat return data; } -pxr::SdfPath WorldData::get_prim_id(BlenderSceneDelegate *scene_delegate) +pxr::SdfPath WorldData::prim_id(BlenderSceneDelegate *scene_delegate) { return scene_delegate->GetDelegateID().AppendElementString("World"); } @@ -150,7 +150,7 @@ void WorldData::update(World *world) update(); } -pxr::GfMatrix4d WorldData::get_transform() +pxr::GfMatrix4d WorldData::transform() { pxr::GfMatrix4d transform = pxr::GfMatrix4d(pxr::GfRotation(pxr::GfVec3d(1.0, 0.0, 0.0), -90), pxr::GfVec3d()); diff --git a/source/blender/render/hydra/scene_delegate/world.h b/source/blender/render/hydra/scene_delegate/world.h index 2d8df7bfc499..71924a7862bc 100644 --- a/source/blender/render/hydra/scene_delegate/world.h +++ b/source/blender/render/hydra/scene_delegate/world.h @@ -25,7 +25,7 @@ class WorldData : public IdData { static std::unique_ptr create(BlenderSceneDelegate *scene_delegate, World *world, bContext *context); - static pxr::SdfPath get_prim_id(BlenderSceneDelegate *scene_delegate); + static pxr::SdfPath prim_id(BlenderSceneDelegate *scene_delegate); void init() override; void insert() override; @@ -33,7 +33,7 @@ class WorldData : public IdData { void update() override; void update(World *world); - pxr::GfMatrix4d get_transform(); + pxr::GfMatrix4d transform(); pxr::VtValue get_data(pxr::TfToken const &key) const override; private: -- 2.30.2 From 816f141e7dce570766cc5e2f7e85cd1e252c605f Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Fri, 14 Apr 2023 18:19:53 +0300 Subject: [PATCH 13/13] make format --- .../render/hydra/scene_delegate/blender_scene_delegate.cc | 3 +-- source/blender/render/hydra/scene_delegate/instancer.h | 3 +-- source/blender/render/hydra/scene_delegate/mesh.cc | 3 +-- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc index b2ad611d7ec0..b86bf0ab200b 100644 --- a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc +++ b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc @@ -86,8 +86,7 @@ void BlenderSceneDelegate::populate(Depsgraph *deps, bContext *cont) } break; case ID_MA: { - MaterialData *mat_data = material_data( - MaterialData::prim_id(this, (Material *)id)); + MaterialData *mat_data = material_data(MaterialData::prim_id(this, (Material *)id)); if (mat_data) { mat_data->update(); } diff --git a/source/blender/render/hydra/scene_delegate/instancer.h b/source/blender/render/hydra/scene_delegate/instancer.h index 5c3a9a4dbfa7..cdff32c7b62b 100644 --- a/source/blender/render/hydra/scene_delegate/instancer.h +++ b/source/blender/render/hydra/scene_delegate/instancer.h @@ -27,8 +27,7 @@ class InstancerData : public MeshData { pxr::GfMatrix4d transform() override; bool update_visibility(View3D *view3d) override; - pxr::HdPrimvarDescriptorVector instancer_primvar_descriptors( - pxr::HdInterpolation interpolation); + pxr::HdPrimvarDescriptorVector instancer_primvar_descriptors(pxr::HdInterpolation interpolation); pxr::VtIntArray instance_indices(); bool is_base(Object *object) const; diff --git a/source/blender/render/hydra/scene_delegate/mesh.cc b/source/blender/render/hydra/scene_delegate/mesh.cc index 359fa35b4594..5c3340962277 100644 --- a/source/blender/render/hydra/scene_delegate/mesh.cc +++ b/source/blender/render/hydra/scene_delegate/mesh.cc @@ -134,8 +134,7 @@ pxr::HdMeshTopology MeshData::mesh_topology() face_vertex_indices_); } -pxr::HdPrimvarDescriptorVector MeshData::primvar_descriptors( - pxr::HdInterpolation interpolation) +pxr::HdPrimvarDescriptorVector MeshData::primvar_descriptors(pxr::HdInterpolation interpolation) { pxr::HdPrimvarDescriptorVector primvars; if (interpolation == pxr::HdInterpolationVertex) { -- 2.30.2