forked from blender/blender
BLEN-359: Implement updates for instances in viewport #20
@ -56,7 +56,7 @@ bool BlenderSceneDelegate::GetVisible(pxr::SdfPath const &id)
|
|||||||
pxr::SdfPath BlenderSceneDelegate::GetInstancerId(pxr::SdfPath const &prim_id)
|
pxr::SdfPath BlenderSceneDelegate::GetInstancerId(pxr::SdfPath const &prim_id)
|
||||||
{
|
{
|
||||||
CLOG_INFO(LOG_BSD, 3, "%s", prim_id.GetText());
|
CLOG_INFO(LOG_BSD, 3, "%s", prim_id.GetText());
|
||||||
InstancerData *i_data = dynamic_cast<InstancerData *>(mesh_data(prim_id));
|
InstancerData *i_data = instancer_data(prim_id, true);
|
||||||
if (i_data) {
|
if (i_data) {
|
||||||
return i_data->instancer_id;
|
return i_data->instancer_id;
|
||||||
}
|
}
|
||||||
@ -86,19 +86,6 @@ pxr::GfMatrix4d BlenderSceneDelegate::GetInstancerTransform(pxr::SdfPath const &
|
|||||||
return i_data->transform();
|
return i_data->transform();
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t BlenderSceneDelegate::SamplePrimvar(pxr::SdfPath const &id,
|
|
||||||
pxr::TfToken const &key,
|
|
||||||
size_t max_sample_count,
|
|
||||||
float *sample_times,
|
|
||||||
pxr::VtValue *sample_values)
|
|
||||||
{
|
|
||||||
InstancerData *i_data = instancer_data(id);
|
|
||||||
if (i_data) {
|
|
||||||
return i_data->sample_instancer_primvar(key, max_sample_count, sample_times, sample_values);
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void BlenderSceneDelegate::update_collection(bool remove, bool visibility)
|
void BlenderSceneDelegate::update_collection(bool remove, bool visibility)
|
||||||
{
|
{
|
||||||
if (visibility) {
|
if (visibility) {
|
||||||
@ -241,9 +228,9 @@ MaterialData *BlenderSceneDelegate::material_data(pxr::SdfPath const &id)
|
|||||||
return it->second.get();
|
return it->second.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
InstancerData *BlenderSceneDelegate::instancer_data(pxr::SdfPath const &id, bool base_mesh)
|
InstancerData *BlenderSceneDelegate::instancer_data(pxr::SdfPath const &id, bool base_prim)
|
||||||
{
|
{
|
||||||
if (base_mesh) {
|
if (base_prim) {
|
||||||
return dynamic_cast<InstancerData *>(object_data(id));
|
return dynamic_cast<InstancerData *>(object_data(id));
|
||||||
}
|
}
|
||||||
return dynamic_cast<InstancerData *>(object_data(id.GetParentPath()));
|
return dynamic_cast<InstancerData *>(object_data(id.GetParentPath()));
|
||||||
@ -403,15 +390,16 @@ pxr::GfMatrix4d BlenderSceneDelegate::GetTransform(pxr::SdfPath const &id)
|
|||||||
if (obj_data) {
|
if (obj_data) {
|
||||||
return obj_data->transform();
|
return obj_data->transform();
|
||||||
}
|
}
|
||||||
// TODO: add a separate object for instancer for cleaner handling code
|
|
||||||
else if (id.GetName() == "Instancer") {
|
|
||||||
if (MeshData *mesh = mesh_data(id.GetParentPath())) {
|
|
||||||
return mesh->transform().GetInverse();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (id == WorldData::prim_id(this)) {
|
if (id == WorldData::prim_id(this)) {
|
||||||
return world_data->transform();
|
return world_data->transform();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
InstancerData *i_data = instancer_data(id);
|
||||||
|
if (i_data) {
|
||||||
|
return i_data->transform();
|
||||||
|
}
|
||||||
|
|
||||||
return pxr::GfMatrix4d();
|
return pxr::GfMatrix4d();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,11 +48,6 @@ class BlenderSceneDelegate : public pxr::HdSceneDelegate {
|
|||||||
pxr::VtIntArray GetInstanceIndices(pxr::SdfPath const &instancer_id,
|
pxr::VtIntArray GetInstanceIndices(pxr::SdfPath const &instancer_id,
|
||||||
pxr::SdfPath const &prototype_id) override;
|
pxr::SdfPath const &prototype_id) override;
|
||||||
pxr::GfMatrix4d GetInstancerTransform(pxr::SdfPath const &instancer_id) override;
|
pxr::GfMatrix4d GetInstancerTransform(pxr::SdfPath const &instancer_id) override;
|
||||||
size_t SamplePrimvar(pxr::SdfPath const &id,
|
|
||||||
pxr::TfToken const &key,
|
|
||||||
size_t max_sample_count,
|
|
||||||
float *sample_times,
|
|
||||||
pxr::VtValue *sample_values) override;
|
|
||||||
|
|
||||||
EngineType engine_type;
|
EngineType engine_type;
|
||||||
|
|
||||||
@ -61,7 +56,7 @@ class BlenderSceneDelegate : public pxr::HdSceneDelegate {
|
|||||||
MeshData *mesh_data(pxr::SdfPath const &id);
|
MeshData *mesh_data(pxr::SdfPath const &id);
|
||||||
LightData *light_data(pxr::SdfPath const &id);
|
LightData *light_data(pxr::SdfPath const &id);
|
||||||
MaterialData *material_data(pxr::SdfPath const &id);
|
MaterialData *material_data(pxr::SdfPath const &id);
|
||||||
InstancerData *instancer_data(pxr::SdfPath const &id, bool base_mesh=false);
|
InstancerData *instancer_data(pxr::SdfPath const &id, bool base_prim=false);
|
||||||
|
|
||||||
void add_update_object(Object *object);
|
void add_update_object(Object *object);
|
||||||
void add_update_instancer(DupliObject *dupli);
|
void add_update_instancer(DupliObject *dupli);
|
||||||
|
@ -62,8 +62,9 @@ void InstancerData::init()
|
|||||||
|
|
||||||
GfMatrix4d InstancerData::transform()
|
GfMatrix4d InstancerData::transform()
|
||||||
{
|
{
|
||||||
|
return pxr::GfMatrix4d(1.0);
|
||||||
/* transform of the first instance */
|
/* transform of the first instance */
|
||||||
return transforms[0];
|
//return transforms[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
bool InstancerData::update_visibility(View3D *view3d)
|
bool InstancerData::update_visibility(View3D *view3d)
|
||||||
@ -87,16 +88,11 @@ VtValue InstancerData::get_data(TfToken const &key) const
|
|||||||
CLOG_INFO(LOG_BSD, 3, "%s [%s]", id->name, key.GetText());
|
CLOG_INFO(LOG_BSD, 3, "%s [%s]", id->name, key.GetText());
|
||||||
|
|
||||||
if (key == HdInstancerTokens->instanceTransform) {
|
if (key == HdInstancerTokens->instanceTransform) {
|
||||||
return VtValue(calc_instance_transforms());
|
return VtValue(transforms);
|
||||||
}
|
}
|
||||||
return MeshData::get_data(key);
|
return MeshData::get_data(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
pxr::GfMatrix4d InstancerData::instancer_transform()
|
|
||||||
{
|
|
||||||
return pxr::GfMatrix4d(1.0);
|
|
||||||
}
|
|
||||||
|
|
||||||
HdPrimvarDescriptorVector InstancerData::instancer_primvar_descriptors(
|
HdPrimvarDescriptorVector InstancerData::instancer_primvar_descriptors(
|
||||||
HdInterpolation interpolation)
|
HdInterpolation interpolation)
|
||||||
{
|
{
|
||||||
@ -117,22 +113,6 @@ VtIntArray InstancerData::instance_indices()
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t InstancerData::sample_instancer_primvar(TfToken const &key,
|
|
||||||
size_t maxSampleCount,
|
|
||||||
float *sampleTimes,
|
|
||||||
VtValue *sampleValues)
|
|
||||||
{
|
|
||||||
CLOG_INFO(LOG_BSD, 3, "%s [%s]", id->name, key.GetText());
|
|
||||||
if (key == HdInstancerTokens->instanceTransform) {
|
|
||||||
if (maxSampleCount > 0) {
|
|
||||||
sampleTimes[0] = 0.0f;
|
|
||||||
sampleValues[0] = transforms;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void InstancerData::add_instance(DupliObject *dupli)
|
void InstancerData::add_instance(DupliObject *dupli)
|
||||||
{
|
{
|
||||||
CLOG_INFO(LOG_BSD, 2, "%s [%d]", id->name, dupli->random_id);
|
CLOG_INFO(LOG_BSD, 2, "%s [%d]", id->name, dupli->random_id);
|
||||||
@ -168,16 +148,4 @@ void InstancerData::update()
|
|||||||
MeshData::update();
|
MeshData::update();
|
||||||
}
|
}
|
||||||
|
|
||||||
pxr::VtMatrix4dArray InstancerData::calc_instance_transforms() const
|
|
||||||
{
|
|
||||||
pxr::VtMatrix4dArray ret;
|
|
||||||
/* USD hides the prototype mesh when instancing in contrary to the Blender,
|
|
||||||
so we must add it back implicitly */
|
|
||||||
ret.push_back(pxr::GfMatrix4d(1.0));
|
|
||||||
for (size_t i = 1; i < transforms.size(); ++i) {
|
|
||||||
ret.push_back(transforms[0].GetInverse() * transforms[i]);
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace blender::render::hydra
|
} // namespace blender::render::hydra
|
||||||
|
@ -25,20 +25,14 @@ public:
|
|||||||
pxr::GfMatrix4d transform() override;
|
pxr::GfMatrix4d transform() override;
|
||||||
bool update_visibility(View3D *view3d) override;
|
bool update_visibility(View3D *view3d) override;
|
||||||
|
|
||||||
pxr::GfMatrix4d instancer_transform();
|
|
||||||
pxr::HdPrimvarDescriptorVector instancer_primvar_descriptors(pxr::HdInterpolation interpolation);
|
pxr::HdPrimvarDescriptorVector instancer_primvar_descriptors(pxr::HdInterpolation interpolation);
|
||||||
pxr::VtIntArray instance_indices();
|
pxr::VtIntArray instance_indices();
|
||||||
size_t sample_instancer_primvar(pxr::TfToken const &key,
|
|
||||||
size_t maxSampleCount,
|
|
||||||
float *sampleTimes,
|
|
||||||
pxr::VtValue *sampleValues);
|
|
||||||
|
|
||||||
void add_instance(DupliObject *dupli);
|
void add_instance(DupliObject *dupli);
|
||||||
|
|
||||||
pxr::SdfPath instancer_id;
|
pxr::SdfPath instancer_id;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
pxr::VtMatrix4dArray calc_instance_transforms() const;
|
|
||||||
pxr::VtMatrix4dArray transforms;
|
pxr::VtMatrix4dArray transforms;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user