Implement instancing for light objects #35

Merged
Bogdan Nagirniak merged 18 commits from BLEN-395 into hydra-render 2023-05-04 15:12:27 +02:00
7 changed files with 33 additions and 24 deletions
Showing only changes of commit 54d3928b1a - Show all commits

View File

@ -280,6 +280,7 @@ void BlenderSceneDelegate::update_objects(Object *object)
pxr::SdfPath id = object_prim_id(object); pxr::SdfPath id = object_prim_id(object);
ObjectData *obj_data = object_data(id); ObjectData *obj_data = object_data(id);
if (obj_data) { if (obj_data) {
obj_data->update_parent();
obj_data->update(); obj_data->update();
return; return;
} }
@ -288,6 +289,9 @@ void BlenderSceneDelegate::update_objects(Object *object)
} }
objects_[id] = ObjectData::create(this, object, id); objects_[id] = ObjectData::create(this, object, id);
obj_data = object_data(id); obj_data = object_data(id);
obj_data->update_parent();
obj_data->init();
obj_data->insert();
obj_data->update_visibility(); obj_data->update_visibility();
} }

View File

@ -21,7 +21,8 @@ namespace blender::render::hydra {
extern struct CLG_LogRef *LOG_RENDER_HYDRA_SCENE; /* BSD - Blender Scene Delegate */ extern struct CLG_LogRef *LOG_RENDER_HYDRA_SCENE; /* BSD - Blender Scene Delegate */
class BlenderSceneDelegate : public pxr::HdSceneDelegate { class BlenderSceneDelegate : public pxr::HdSceneDelegate {
friend MeshData; /* has access to materials and instances */ friend ObjectData; /* has access to instances */
friend MeshData; /* has access to materials */
public: public:
enum class EngineType { VIEWPORT = 1, FINAL, PREVIEW }; enum class EngineType { VIEWPORT = 1, FINAL, PREVIEW };

View File

@ -104,7 +104,8 @@ void LightData::update()
{ {
ID_LOG(2, ""); ID_LOG(2, "");
Light *light = (Light *)((Object *)id)->data; Object *object = (Object *)id;
Light *light = (Light *)object->data;
if (prim_type(light) != prim_type_) { if (prim_type(light) != prim_type_) {
remove(); remove();
init(); init();

View File

@ -17,7 +17,7 @@ namespace blender::render::hydra {
MeshData::MeshData(BlenderSceneDelegate *scene_delegate, MeshData::MeshData(BlenderSceneDelegate *scene_delegate,
Object *object, Object *object,
pxr::SdfPath const &prim_id) pxr::SdfPath const &prim_id)
: ObjectData(scene_delegate, object, prim_id), parent_(object->parent) : ObjectData(scene_delegate, object, prim_id)
{ {
} }
@ -66,20 +66,6 @@ void MeshData::remove()
void MeshData::update() void MeshData::update()
{ {
Object *object = (Object *)id; Object *object = (Object *)id;
if (parent_ != object->parent) {
parent_ = object->parent;
/* Looking for corresponded instancer and update it as parent */
for (Object *ob = parent_; ob != nullptr; ob = ob->parent) {
InstancerData *i_data = scene_delegate_->instancer_data(
scene_delegate_->instancer_prim_id(ob));
if (i_data) {
i_data->update_as_parent();
break;
}
}
}
pxr::HdDirtyBits bits = pxr::HdChangeTracker::Clean; pxr::HdDirtyBits bits = pxr::HdChangeTracker::Clean;
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();

View File

@ -42,7 +42,6 @@ class MeshData : public ObjectData {
pxr::VtVec3fArray normals_; pxr::VtVec3fArray normals_;
MaterialData *mat_data_ = nullptr; MaterialData *mat_data_ = nullptr;
Object *parent_;
}; };
} // namespace blender::render::hydra } // namespace blender::render::hydra

View File

@ -13,7 +13,7 @@ namespace blender::render::hydra {
ObjectData::ObjectData(BlenderSceneDelegate *scene_delegate, ObjectData::ObjectData(BlenderSceneDelegate *scene_delegate,
Object *object, Object *object,
pxr::SdfPath const &prim_id) pxr::SdfPath const &prim_id)
: IdData(scene_delegate, (ID *)object, prim_id), transform(pxr::GfMatrix4d(1.0)), visible(true) : IdData(scene_delegate, (ID *)object, prim_id), transform(pxr::GfMatrix4d(1.0))
{ {
} }
@ -39,10 +39,6 @@ std::unique_ptr<ObjectData> ObjectData::create(BlenderSceneDelegate *scene_deleg
default: default:
break; break;
} }
if (data) {
data->init();
data->insert();
}
return data; return data;
} }
@ -78,6 +74,25 @@ bool ObjectData::update_visibility()
return ret; return ret;
} }
void ObjectData::update_parent()
{
Object *object = (Object *)id;
if (parent_ != object->parent) {
ID_LOG(2, "");
parent_ = object->parent;
/* Looking for corresponded instancer and update it as parent */
for (Object *ob = parent_; ob != nullptr; ob = ob->parent) {
InstancerData *i_data = scene_delegate_->instancer_data(
scene_delegate_->instancer_prim_id(ob));
if (i_data) {
i_data->update_as_parent();
break;
}
}
}
}
void ObjectData::write_transform() void ObjectData::write_transform()
{ {
transform = gf_matrix_from_transform(((Object *)id)->object_to_world); transform = gf_matrix_from_transform(((Object *)id)->object_to_world);

View File

@ -24,12 +24,15 @@ class ObjectData : public IdData {
static bool is_supported(Object *object); static bool is_supported(Object *object);
virtual bool update_visibility(); virtual bool update_visibility();
void update_parent();
pxr::GfMatrix4d transform; pxr::GfMatrix4d transform;
bool visible; bool visible = true;
protected: protected:
void write_transform(); void write_transform();
Object *parent_ = nullptr;
}; };
using ObjectDataMap = using ObjectDataMap =