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
4 changed files with 28 additions and 21 deletions
Showing only changes of commit 857c4f0160 - Show all commits

View File

@ -170,10 +170,10 @@ void BlenderSceneDelegate::add_update_object(Object *object)
if ((object->transflag & OB_DUPLI) && InstancerData::supported(object)) {
add_update_instancer(object);
}
InstancerData *i_data = instancer_data(object);
if (i_data) {
i_data->update();
}
//InstancerData *i_data = instancer_data(object);
//if (i_data) {
// i_data->update();
//}
pxr::SdfPath id = ObjectData::prim_id(this, object);
ObjectData *obj_data = object_data(id);
@ -197,7 +197,7 @@ void BlenderSceneDelegate::add_update_instancer(Object *object)
i_data->update();
return;
}
objects[id] = InstancerData::create(this, object);
instancers[id] = InstancerData::create(this, object);
i_data = instancer_data(id);
i_data->update_visibility(view3d);
}
@ -208,9 +208,8 @@ ObjectData *BlenderSceneDelegate::object_data(pxr::SdfPath const &id)
if (it != objects.end()) {
return it->second.get();
}
it = objects.find(id.GetParentPath());
if (it != objects.end()) {
InstancerData *i_data = (InstancerData *)it->second.get();
InstancerData *i_data = instancer_data(id.GetParentPath());
if (i_data) {
return i_data->object_data(id);
}
return nullptr;
@ -237,18 +236,10 @@ MaterialData *BlenderSceneDelegate::material_data(pxr::SdfPath const &id)
InstancerData *BlenderSceneDelegate::instancer_data(pxr::SdfPath const &id)
{
return dynamic_cast<InstancerData *>(object_data(id));
}
InstancerData *BlenderSceneDelegate::instancer_data(Object *object)
{
//InstancerData *i_data;
//for (auto &it : objects) {
// i_data = dynamic_cast<InstancerData *>(it.second.get());
// if (i_data && i_data->is_base(object)) {
// return i_data;
// }
//}
auto it = instancers.find(id);
if (it != instancers.end()) {
return it->second.get();
}
return nullptr;
}

View File

@ -59,7 +59,6 @@ class BlenderSceneDelegate : public pxr::HdSceneDelegate {
LightData *light_data(pxr::SdfPath const &id);
MaterialData *material_data(pxr::SdfPath const &id);
InstancerData *instancer_data(pxr::SdfPath const &id);
InstancerData *instancer_data(Object *object);
void add_update_object(Object *object);
void add_update_instancer(Object *object);
@ -74,6 +73,7 @@ class BlenderSceneDelegate : public pxr::HdSceneDelegate {
ObjectDataMap objects;
MaterialDataMap materials;
InstancerDataMap instancers;
std::unique_ptr<WorldData> world_data;
};

View File

@ -114,6 +114,18 @@ pxr::SdfPathVector InstancerData::prototypes()
return paths;
}
void InstancerData::update(Object *object)
{
pxr::SdfPath path = ObjectData::prim_id(scene_delegate, object);
path = p_id.AppendElementString(path.GetName());
auto it = instances.find(path);
if (it == instances.end()) {
return;
}
ObjectData *obj_data = it->second.obj_data.get();
obj_data->update();
}
void InstancerData::set_instances()
{
transforms.clear();

View File

@ -35,6 +35,7 @@ class InstancerData : public ObjectData {
pxr::VtIntArray indices(pxr::SdfPath const &id);
ObjectData *object_data(pxr::SdfPath const &id);
pxr::SdfPathVector prototypes();
void update(Object *object);
private:
void set_instances();
@ -43,6 +44,9 @@ class InstancerData : public ObjectData {
pxr::VtMatrix4dArray transforms;
};
using InstancerDataMap =
pxr::TfHashMap<pxr::SdfPath, std::unique_ptr<InstancerData>, pxr::SdfPath::Hash>;
class InstanceMeshData : public MeshData {
public:
InstanceMeshData(BlenderSceneDelegate *scene_delegate, Object *object, pxr::SdfPath const &p_id);