forked from blender/blender
BLEN-359: Implement updates for instances in viewport #20
@ -48,30 +48,17 @@ SdfPath InstancerData::prim_id(BlenderSceneDelegate *scene_delegate, Object *obj
|
|||||||
InstancerData::InstancerData(BlenderSceneDelegate *scene_delegate, Object *object)
|
InstancerData::InstancerData(BlenderSceneDelegate *scene_delegate, Object *object)
|
||||||
: MeshData(scene_delegate, object), parent_obj(object)
|
: MeshData(scene_delegate, object), parent_obj(object)
|
||||||
{
|
{
|
||||||
|
id = nullptr;
|
||||||
p_id = prim_id(scene_delegate, object);
|
p_id = prim_id(scene_delegate, object);
|
||||||
instancer_id = p_id.AppendElementString("Instancer");
|
instancer_id = p_id.AppendElementString("Instancer");
|
||||||
CLOG_INFO(LOG_BSD, 2, "%s, instancer_id=%s", id->name, instancer_id.GetText());
|
CLOG_INFO(LOG_BSD, 2, "%s, instancer_id=%s", ((ID *)parent_obj)->name, instancer_id.GetText());
|
||||||
id = nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void InstancerData::init()
|
void InstancerData::init()
|
||||||
{
|
{
|
||||||
CLOG_INFO(LOG_BSD, 2, "%s", ((ID *)parent_obj)->name);
|
CLOG_INFO(LOG_BSD, 2, "%s", ((ID *)parent_obj)->name);
|
||||||
|
|
||||||
id = nullptr;
|
set_instances();
|
||||||
transforms.clear();
|
|
||||||
ListBase *lb = object_duplilist(scene_delegate->depsgraph, scene_delegate->scene, parent_obj);
|
|
||||||
LISTBASE_FOREACH (DupliObject *, dupli, lb) {
|
|
||||||
if (!id) {
|
|
||||||
/* TODO: We create instances only for object in first dupli.
|
|
||||||
Instances should be created for all objects */
|
|
||||||
id = (ID *)dupli->ob;
|
|
||||||
}
|
|
||||||
transforms.push_back(gf_matrix_from_transform(dupli->mat));
|
|
||||||
CLOG_INFO(LOG_BSD, 2, "Instance %s (%s) %d", id->name, ((ID *)dupli->ob)->name, dupli->random_id);
|
|
||||||
}
|
|
||||||
free_object_duplilist(lb);
|
|
||||||
|
|
||||||
MeshData::init();
|
MeshData::init();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,6 +113,27 @@ bool InstancerData::is_base(Object *object) const
|
|||||||
return (ID *)object == id;
|
return (ID *)object == id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool InstancerData::set_instances()
|
||||||
|
{
|
||||||
|
ID *prev_id = id;
|
||||||
|
id = nullptr;
|
||||||
|
transforms.clear();
|
||||||
|
ListBase *lb = object_duplilist(scene_delegate->depsgraph, scene_delegate->scene, parent_obj);
|
||||||
|
LISTBASE_FOREACH (DupliObject *, dupli, lb) {
|
||||||
|
if (!id) {
|
||||||
|
/* TODO: We create instances only for object in first dupli.
|
||||||
|
Instances should be created for all objects */
|
||||||
|
id = (ID *)dupli->ob;
|
||||||
|
}
|
||||||
|
transforms.push_back(gf_matrix_from_transform(dupli->mat));
|
||||||
|
CLOG_INFO(
|
||||||
|
LOG_BSD, 2, "Instance %s (%s) %d", id->name, ((ID *)dupli->ob)->name, dupli->random_id);
|
||||||
|
}
|
||||||
|
free_object_duplilist(lb);
|
||||||
|
|
||||||
|
return id != prev_id;
|
||||||
|
}
|
||||||
|
|
||||||
void InstancerData::insert()
|
void InstancerData::insert()
|
||||||
{
|
{
|
||||||
CLOG_INFO(LOG_BSD, 2, "%s", ((ID *)parent_obj)->name);
|
CLOG_INFO(LOG_BSD, 2, "%s", ((ID *)parent_obj)->name);
|
||||||
@ -166,16 +174,10 @@ void InstancerData::update()
|
|||||||
|
|
||||||
if ((recalc & ID_RECALC_GEOMETRY) || (((ID *)parent_obj->data)->recalc & ID_RECALC_GEOMETRY)) {
|
if ((recalc & ID_RECALC_GEOMETRY) || (((ID *)parent_obj->data)->recalc & ID_RECALC_GEOMETRY)) {
|
||||||
init();
|
init();
|
||||||
bits = pxr::HdChangeTracker::AllDirty;
|
bits |= pxr::HdChangeTracker::AllDirty;
|
||||||
}
|
}
|
||||||
else if (recalc & ID_RECALC_TRANSFORM) {
|
else if (recalc & ID_RECALC_TRANSFORM || id->recalc & ID_RECALC_TRANSFORM) {
|
||||||
transforms.clear();
|
set_instances();
|
||||||
ListBase *lb = object_duplilist(scene_delegate->depsgraph, scene_delegate->scene, parent_obj);
|
|
||||||
LISTBASE_FOREACH (DupliObject *, dupli, lb) {
|
|
||||||
transforms.push_back(gf_matrix_from_transform(dupli->mat));
|
|
||||||
}
|
|
||||||
free_object_duplilist(lb);
|
|
||||||
|
|
||||||
bits |= pxr::HdChangeTracker::DirtyTransform;
|
bits |= pxr::HdChangeTracker::DirtyTransform;
|
||||||
}
|
}
|
||||||
if (bits != pxr::HdChangeTracker::Clean) {
|
if (bits != pxr::HdChangeTracker::Clean) {
|
||||||
|
@ -35,6 +35,8 @@ class InstancerData : public MeshData {
|
|||||||
private:
|
private:
|
||||||
Object *parent_obj;
|
Object *parent_obj;
|
||||||
pxr::VtMatrix4dArray transforms;
|
pxr::VtMatrix4dArray transforms;
|
||||||
|
|
||||||
|
bool set_instances();
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace blender::render::hydra
|
} // namespace blender::render::hydra
|
||||||
|
Loading…
Reference in New Issue
Block a user