forked from blender/blender
BLEN-359: Implement updates for instances in viewport #20
@ -200,10 +200,10 @@ void BlenderSceneDelegate::add_update_object(Object *object)
|
||||
void BlenderSceneDelegate::add_update_instancer(DupliObject *dupli)
|
||||
{
|
||||
pxr::SdfPath id = InstancerData::prim_id(this, dupli->ob);
|
||||
InstancerData *i_data = (InstancerData *)mesh_data(id);
|
||||
InstancerData *i_data = instancer_data(id, true);
|
||||
if (!i_data) {
|
||||
objects[id] = InstancerData::create(this, dupli->ob);
|
||||
i_data = (InstancerData *)mesh_data(id);
|
||||
i_data = instancer_data(id, true);
|
||||
// i_data->update_visibility(view3d);
|
||||
}
|
||||
|
||||
@ -238,8 +238,11 @@ MaterialData *BlenderSceneDelegate::material_data(pxr::SdfPath const &id)
|
||||
return it->second.get();
|
||||
}
|
||||
|
||||
InstancerData *BlenderSceneDelegate::instancer_data(pxr::SdfPath const &id)
|
||||
InstancerData *BlenderSceneDelegate::instancer_data(pxr::SdfPath const &id, bool base_mesh)
|
||||
{
|
||||
if (base_mesh) {
|
||||
return dynamic_cast<InstancerData *>(object_data(id));
|
||||
}
|
||||
return dynamic_cast<InstancerData *>(object_data(id.GetParentPath()));
|
||||
}
|
||||
|
||||
|
@ -61,7 +61,7 @@ class BlenderSceneDelegate : public pxr::HdSceneDelegate {
|
||||
MeshData *mesh_data(pxr::SdfPath const &id);
|
||||
LightData *light_data(pxr::SdfPath const &id);
|
||||
MaterialData *material_data(pxr::SdfPath const &id);
|
||||
InstancerData *instancer_data(pxr::SdfPath const &id);
|
||||
InstancerData *instancer_data(pxr::SdfPath const &id, bool base_mesh=false);
|
||||
|
||||
void add_update_object(Object *object);
|
||||
void add_update_instancer(DupliObject *dupli);
|
||||
|
@ -57,26 +57,36 @@ void InstancerData::init()
|
||||
CLOG_INFO(LOG_BSD, 2, "%s", id->name);
|
||||
MeshData::init();
|
||||
|
||||
/* USD hides the prototype mesh when instancing in contrary to the Blender,
|
||||
so we must add it back implicitly */
|
||||
transforms.clear();
|
||||
transforms.push_back(GfMatrix4d(1.0));
|
||||
}
|
||||
|
||||
GfMatrix4d InstancerData::transform()
|
||||
{
|
||||
return GfMatrix4d(1.0);
|
||||
/* transform of the first instance */
|
||||
return transforms[0];
|
||||
}
|
||||
|
||||
VtValue InstancerData::get_data(TfToken const &key) const
|
||||
{
|
||||
CLOG_INFO(LOG_BSD, 3, "%s [%s]", id->name, key.GetText());
|
||||
|
||||
if (key == HdInstancerTokens->instanceTransform) {
|
||||
pxr::VtMatrix4dArray t = transforms;
|
||||
/* USD hides the prototype mesh when instancing in contrary to the Blender,
|
||||
so we must add it back implicitly */
|
||||
t[0] = pxr::GfMatrix4d(1.0);
|
||||
return VtValue(transforms);
|
||||
}
|
||||
return MeshData::get_data(key);
|
||||
}
|
||||
|
||||
HdPrimvarDescriptorVector InstancerData::instancer_primvar_descriptors(HdInterpolation interpolation)
|
||||
pxr::GfMatrix4d InstancerData::instancer_transform()
|
||||
{
|
||||
return pxr::GfMatrix4d(1.0);
|
||||
}
|
||||
|
||||
HdPrimvarDescriptorVector InstancerData::instancer_primvar_descriptors(
|
||||
HdInterpolation interpolation)
|
||||
{
|
||||
HdPrimvarDescriptorVector primvars;
|
||||
if (interpolation == HdInterpolationInstance) {
|
||||
@ -114,7 +124,7 @@ size_t InstancerData::sample_instancer_primvar(TfToken const &key,
|
||||
void InstancerData::add_instance(DupliObject *dupli)
|
||||
{
|
||||
CLOG_INFO(LOG_BSD, 2, "%s [%d]", id->name, dupli->random_id);
|
||||
transforms.push_back(transform().GetInverse() * gf_matrix_from_transform(dupli->mat));
|
||||
transforms.push_back(/*ObjectData::transform().GetInverse() **/ gf_matrix_from_transform(dupli->mat));
|
||||
}
|
||||
|
||||
void InstancerData::insert()
|
||||
|
@ -24,6 +24,7 @@ public:
|
||||
pxr::VtValue get_data(pxr::TfToken const &key) const override;
|
||||
pxr::GfMatrix4d transform() override;
|
||||
|
||||
pxr::GfMatrix4d instancer_transform();
|
||||
pxr::HdPrimvarDescriptorVector instancer_primvar_descriptors(pxr::HdInterpolation interpolation);
|
||||
pxr::VtIntArray instance_indices();
|
||||
size_t sample_instancer_primvar(pxr::TfToken const &key,
|
||||
|
Loading…
Reference in New Issue
Block a user