Support several instancers on one object #24

Merged
Bogdan Nagirniak merged 16 commits from BLEN-383 into hydra-render 2023-04-19 02:46:24 +02:00
3 changed files with 28 additions and 4 deletions
Showing only changes of commit c57651f9bb - Show all commits

View File

@ -9,7 +9,7 @@
namespace blender::render::hydra { namespace blender::render::hydra {
IdData::IdData(BlenderSceneDelegate *scene_delegate, ID *id) IdData::IdData(BlenderSceneDelegate *scene_delegate, ID *id)
: scene_delegate(scene_delegate), id(id) : id(id), scene_delegate(scene_delegate)
{ {
} }

View File

@ -54,6 +54,9 @@ void InstancerData::init()
{ {
ID_LOG(2, ""); ID_LOG(2, "");
set_instances(); set_instances();
for (auto &it : instances) {
it.second.obj_data->init();
}
} }
pxr::GfMatrix4d InstancerData::transform() pxr::GfMatrix4d InstancerData::transform()
@ -131,8 +134,10 @@ void InstancerData::set_instances()
auto it = instances.find(path); auto it = instances.find(path);
if (it == instances.end()) { if (it == instances.end()) {
inst = &instances[path]; inst = &instances[path];
inst->obj_data = ObjectData::create(scene_delegate, dupli->ob); if (!supported(dupli->ob)) {
inst->obj_data->p_id = path; continue;
}
inst->obj_data = std::make_unique<InstanceMeshData>(scene_delegate, dupli->ob, path);
} }
else { else {
inst = &it->second; inst = &it->second;
@ -183,4 +188,17 @@ void InstancerData::update()
} }
} }
InstanceMeshData::InstanceMeshData(BlenderSceneDelegate *scene_delegate,
Object *object,
pxr::SdfPath const &p_id)
: MeshData(scene_delegate, object)
{
this->p_id = p_id;
}
pxr::GfMatrix4d InstanceMeshData::transform()
{
return pxr::GfMatrix4d(1.0);
}
} // namespace blender::render::hydra } // namespace blender::render::hydra

View File

@ -5,7 +5,7 @@
#include "BKE_duplilist.h" #include "BKE_duplilist.h"
#include "object.h" #include "mesh.h"
namespace blender::render::hydra { namespace blender::render::hydra {
@ -43,4 +43,10 @@ class InstancerData : public ObjectData {
pxr::VtMatrix4dArray transforms; pxr::VtMatrix4dArray transforms;
}; };
class InstanceMeshData : public MeshData {
public:
InstanceMeshData(BlenderSceneDelegate *scene_delegate, Object *object, pxr::SdfPath const &p_id);
pxr::GfMatrix4d transform() override;
};
} // namespace blender::render::hydra } // namespace blender::render::hydra