Refactor code after PR #57 #67

Merged
Bogdan Nagirniak merged 9 commits from hydra-object_data-refactor into hydra-render 2023-07-20 22:34:34 +02:00
2 changed files with 14 additions and 9 deletions
Showing only changes of commit 18930cf5a9 - Show all commits

View File

@ -42,15 +42,15 @@ void MeshData::init()
void MeshData::insert() void MeshData::insert()
{ {
/* Empty, because insertion of rprims happen in write_submeshes() */ ID_LOGN(1, "");
update_prims();
} }
void MeshData::remove() void MeshData::remove()
{ {
for (int i = 0; i < submeshes_.size(); ++i) { ID_LOG(1, "");
scene_delegate_->GetRenderIndex().RemoveRprim(submesh_prim_id(i)); submeshes_.clear();
ID_LOG(1, "%d", i); update_prims();
}
} }
void MeshData::update() void MeshData::update()
@ -58,6 +58,7 @@ void MeshData::update()
Object *object = (Object *)id; Object *object = (Object *)id;
if ((id->recalc & ID_RECALC_GEOMETRY) || (((ID *)object->data)->recalc & ID_RECALC_GEOMETRY)) { if ((id->recalc & ID_RECALC_GEOMETRY) || (((ID *)object->data)->recalc & ID_RECALC_GEOMETRY)) {
init(); init();
update_prims();
return; return;
} }
@ -228,7 +229,6 @@ const MeshData::SubMesh &MeshData::submesh(pxr::SdfPath const &id) const
void MeshData::write_submeshes(Mesh *mesh) void MeshData::write_submeshes(Mesh *mesh)
{ {
int sub_meshes_prev_count = submeshes_.size();
submeshes_.clear(); submeshes_.clear();
vertices_.clear(); vertices_.clear();
@ -291,13 +291,15 @@ void MeshData::write_submeshes(Mesh *mesh)
vertices_.push_back(pxr::GfVec3f(v.x, v.y, v.z)); vertices_.push_back(pxr::GfVec3f(v.x, v.y, v.z));
} }
} }
}
/* Update prims in render index */ void MeshData::update_prims()
{
auto &render_index = scene_delegate_->GetRenderIndex(); auto &render_index = scene_delegate_->GetRenderIndex();
int i; int i;
for (i = 0; i < submeshes_.size(); ++i) { for (i = 0; i < submeshes_.size(); ++i) {
pxr::SdfPath p = submesh_prim_id(i); pxr::SdfPath p = submesh_prim_id(i);
if (i < sub_meshes_prev_count) { if (i < submeshes_count_) {
render_index.GetChangeTracker().MarkRprimDirty(p, pxr::HdChangeTracker::AllDirty); render_index.GetChangeTracker().MarkRprimDirty(p, pxr::HdChangeTracker::AllDirty);
ID_LOGN(1, "Update %d", i); ID_LOGN(1, "Update %d", i);
} }
@ -306,10 +308,11 @@ void MeshData::write_submeshes(Mesh *mesh)
ID_LOGN(1, "Insert %d", i); ID_LOGN(1, "Insert %d", i);
} }
} }
for (; i < sub_meshes_prev_count; ++i) { for (; i < submeshes_count_; ++i) {
render_index.RemoveRprim(submesh_prim_id(i)); render_index.RemoveRprim(submesh_prim_id(i));
ID_LOG(1, "Remove %d", i); ID_LOG(1, "Remove %d", i);
} }
submeshes_count_ = submeshes_.size();
} }
} // namespace blender::render::hydra } // namespace blender::render::hydra

View File

@ -51,9 +51,11 @@ class MeshData : public ObjectData {
pxr::SdfPath submesh_prim_id(int index) const; pxr::SdfPath submesh_prim_id(int index) const;
const SubMesh &submesh(pxr::SdfPath const &id) const; const SubMesh &submesh(pxr::SdfPath const &id) const;
void write_submeshes(Mesh *mesh); void write_submeshes(Mesh *mesh);
void update_prims();
pxr::VtVec3fArray vertices_; pxr::VtVec3fArray vertices_;
std::vector<SubMesh> submeshes_; std::vector<SubMesh> submeshes_;
int submeshes_count_ = 0;
}; };
} // namespace blender::render::hydra } // namespace blender::render::hydra