forked from blender/blender
Implement instancing for light objects #35
@ -280,6 +280,7 @@ void BlenderSceneDelegate::update_objects(Object *object)
|
||||
pxr::SdfPath id = object_prim_id(object);
|
||||
ObjectData *obj_data = object_data(id);
|
||||
if (obj_data) {
|
||||
obj_data->update_parent();
|
||||
obj_data->update();
|
||||
return;
|
||||
}
|
||||
@ -288,6 +289,9 @@ void BlenderSceneDelegate::update_objects(Object *object)
|
||||
}
|
||||
objects_[id] = ObjectData::create(this, object, id);
|
||||
obj_data = object_data(id);
|
||||
obj_data->update_parent();
|
||||
obj_data->init();
|
||||
obj_data->insert();
|
||||
obj_data->update_visibility();
|
||||
}
|
||||
|
||||
|
@ -21,7 +21,8 @@ namespace blender::render::hydra {
|
||||
extern struct CLG_LogRef *LOG_RENDER_HYDRA_SCENE; /* BSD - Blender Scene Delegate */
|
||||
|
||||
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:
|
||||
enum class EngineType { VIEWPORT = 1, FINAL, PREVIEW };
|
||||
|
@ -104,7 +104,8 @@ void LightData::update()
|
||||
{
|
||||
ID_LOG(2, "");
|
||||
|
||||
Light *light = (Light *)((Object *)id)->data;
|
||||
Object *object = (Object *)id;
|
||||
Light *light = (Light *)object->data;
|
||||
if (prim_type(light) != prim_type_) {
|
||||
remove();
|
||||
init();
|
||||
|
@ -17,7 +17,7 @@ namespace blender::render::hydra {
|
||||
MeshData::MeshData(BlenderSceneDelegate *scene_delegate,
|
||||
Object *object,
|
||||
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()
|
||||
{
|
||||
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;
|
||||
if ((id->recalc & ID_RECALC_GEOMETRY) || (((ID *)object->data)->recalc & ID_RECALC_GEOMETRY)) {
|
||||
init();
|
||||
|
@ -42,7 +42,6 @@ class MeshData : public ObjectData {
|
||||
pxr::VtVec3fArray normals_;
|
||||
|
||||
MaterialData *mat_data_ = nullptr;
|
||||
Object *parent_;
|
||||
};
|
||||
|
||||
} // namespace blender::render::hydra
|
||||
|
@ -13,7 +13,7 @@ namespace blender::render::hydra {
|
||||
ObjectData::ObjectData(BlenderSceneDelegate *scene_delegate,
|
||||
Object *object,
|
||||
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:
|
||||
break;
|
||||
}
|
||||
if (data) {
|
||||
data->init();
|
||||
data->insert();
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
@ -78,6 +74,25 @@ bool ObjectData::update_visibility()
|
||||
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()
|
||||
{
|
||||
transform = gf_matrix_from_transform(((Object *)id)->object_to_world);
|
||||
|
@ -24,12 +24,15 @@ class ObjectData : public IdData {
|
||||
static bool is_supported(Object *object);
|
||||
|
||||
virtual bool update_visibility();
|
||||
void update_parent();
|
||||
|
||||
pxr::GfMatrix4d transform;
|
||||
bool visible;
|
||||
bool visible = true;
|
||||
|
||||
protected:
|
||||
void write_transform();
|
||||
|
||||
Object *parent_ = nullptr;
|
||||
};
|
||||
|
||||
using ObjectDataMap =
|
||||
|
Loading…
Reference in New Issue
Block a user