BLEN-299: Export instances #11

Merged
Bogdan Nagirniak merged 7 commits from BLEN-299 into hydra-render 2023-03-05 09:37:12 +01:00
4 changed files with 35 additions and 16 deletions
Showing only changes of commit c8c0b781f5 - Show all commits

View File

@ -78,41 +78,48 @@ bool BlenderSceneDelegate::GetVisible(SdfPath const &id)
return object_data(id)->visible; return object_data(id)->visible;
} }
pxr::GfRange3d BlenderSceneDelegate::GetExtent(pxr::SdfPath const &id) GfRange3d BlenderSceneDelegate::GetExtent(SdfPath const &id)
{ {
LOG(INFO) << "GetExtent: " << id.GetString(); LOG(INFO) << "GetExtent: " << id.GetString();
return pxr::GfRange3d(); return GfRange3d();
} }
bool BlenderSceneDelegate::GetDoubleSided(pxr::SdfPath const &id) bool BlenderSceneDelegate::GetDoubleSided(SdfPath const &id)
{ {
LOG(INFO) << "GetDoubleSided: " << id.GetString(); LOG(INFO) << "GetDoubleSided: " << id.GetString();
return false; return false;
} }
pxr::HdCullStyle BlenderSceneDelegate::GetCullStyle(pxr::SdfPath const &id) HdCullStyle BlenderSceneDelegate::GetCullStyle(SdfPath const &id)
{ {
LOG(INFO) << "GetCullStyle: " << id.GetString(); LOG(INFO) << "GetCullStyle: " << id.GetString();
return pxr::HdCullStyle(); return HdCullStyle();
} }
pxr::SdfPath BlenderSceneDelegate::GetInstancerId(pxr::SdfPath const &primId) SdfPath BlenderSceneDelegate::GetInstancerId(SdfPath const &primId)
{ {
LOG(INFO) << "GetInstancerId: " << primId.GetString(); ObjectData *obj_data = object_data(primId);
return pxr::SdfPath(); LOG(INFO) << "GetInstancerId: " << primId.GetAsString();
if (obj_data && obj_data->name() == "Cube") {
return GetDelegateID().AppendElementString("Instancer");
}
return SdfPath();
} }
pxr::SdfPathVector BlenderSceneDelegate::GetInstancerPrototypes(pxr::SdfPath const &instancerId) SdfPathVector BlenderSceneDelegate::GetInstancerPrototypes(SdfPath const &instancerId)
{ {
LOG(INFO) << "GetInstancerPrototypes: " << instancerId.GetString(); LOG(INFO) << "GetInstancerPrototypes: " << instancerId.GetString();
return pxr::SdfPathVector(); SdfPathVector paths;
paths.push_back(GetDelegateID().AppendElementString("Inst1"));
paths.push_back(GetDelegateID().AppendElementString("Inst2"));
return paths;
} }
pxr::VtIntArray BlenderSceneDelegate::GetInstanceIndices(pxr::SdfPath const &instancerId, VtIntArray BlenderSceneDelegate::GetInstanceIndices(SdfPath const &instancerId,
pxr::SdfPath const &prototypeId) SdfPath const &prototypeId)
{ {
LOG(INFO) << "GetInstanceIndices: " << instancerId.GetString() << " " << prototypeId.GetString(); LOG(INFO) << "GetInstanceIndices: " << instancerId.GetString() << " " << prototypeId.GetString();
return pxr::VtIntArray(); return VtIntArray();
} }
void BlenderSceneDelegate::update_collection(bool remove, bool visibility) void BlenderSceneDelegate::update_collection(bool remove, bool visibility)
@ -294,6 +301,7 @@ void BlenderSceneDelegate::populate(Depsgraph *deps, bContext *cont)
/* Export initial objects */ /* Export initial objects */
update_collection(false, false); update_collection(false, false);
update_world(); update_world();
GetRenderIndex().InsertInstancer(this, GetDelegateID().AppendElementString("Instancer"));
return; return;
} }
@ -374,12 +382,14 @@ void BlenderSceneDelegate::populate(Depsgraph *deps, bContext *cont)
HdMeshTopology BlenderSceneDelegate::GetMeshTopology(SdfPath const& id) HdMeshTopology BlenderSceneDelegate::GetMeshTopology(SdfPath const& id)
{ {
LOG(INFO) << "GetMeshTopology: " << id.GetString();
MeshData *m_data = mesh_data(id); MeshData *m_data = mesh_data(id);
return m_data->mesh_topology(); return m_data->mesh_topology();
} }
VtValue BlenderSceneDelegate::Get(SdfPath const& id, TfToken const& key) VtValue BlenderSceneDelegate::Get(SdfPath const& id, TfToken const& key)
{ {
LOG(INFO) << "Get: " << id.GetString() << " " << key.GetString();
ObjectData *obj_data = object_data(id); ObjectData *obj_data = object_data(id);
if (obj_data) { if (obj_data) {
return obj_data->get_data(key); return obj_data->get_data(key);
@ -394,7 +404,12 @@ VtValue BlenderSceneDelegate::Get(SdfPath const& id, TfToken const& key)
HdPrimvarDescriptorVector BlenderSceneDelegate::GetPrimvarDescriptors(SdfPath const& id, HdInterpolation interpolation) HdPrimvarDescriptorVector BlenderSceneDelegate::GetPrimvarDescriptors(SdfPath const& id, HdInterpolation interpolation)
{ {
LOG(INFO) << "GetPrimvarDescriptors: " << id.GetString() << " " << interpolation;
if (mesh_data(id)) {
return mesh_data(id)->primvar_descriptors(interpolation); return mesh_data(id)->primvar_descriptors(interpolation);
}
HdPrimvarDescriptorVector primvars;
return primvars;
} }
SdfPath BlenderSceneDelegate::GetMaterialId(SdfPath const & rprimId) SdfPath BlenderSceneDelegate::GetMaterialId(SdfPath const & rprimId)
@ -413,6 +428,7 @@ VtValue BlenderSceneDelegate::GetMaterialResource(SdfPath const& id)
GfMatrix4d BlenderSceneDelegate::GetTransform(SdfPath const& id) GfMatrix4d BlenderSceneDelegate::GetTransform(SdfPath const& id)
{ {
LOG(INFO) << "GetTransform: " << id.GetString();
ObjectData *obj_data = object_data(id); ObjectData *obj_data = object_data(id);
if (obj_data) { if (obj_data) {
return obj_data->transform(); return obj_data->transform();

View File

@ -28,7 +28,8 @@ pxr::SdfPath MaterialData::prim_id(pxr::HdSceneDelegate *scene_delegate, Materia
* Example: M_000002074e812088 */ * Example: M_000002074e812088 */
char str[32]; char str[32];
snprintf(str, 32, "M_%016llx", (uint64_t)material); snprintf(str, 32, "M_%016llx", (uint64_t)material);
return scene_delegate->GetDelegateID().AppendElementString(str); //return scene_delegate->GetDelegateID().AppendElementString(str);
return scene_delegate->GetDelegateID().AppendElementString(((ID *)material)->name);
} }
MaterialData::MaterialData(pxr::HdSceneDelegate *scene_delegate, Material *material) MaterialData::MaterialData(pxr::HdSceneDelegate *scene_delegate, Material *material)

View File

@ -25,6 +25,7 @@ public:
pxr::HdPrimvarDescriptorVector primvar_descriptors(pxr::HdInterpolation interpolation); pxr::HdPrimvarDescriptorVector primvar_descriptors(pxr::HdInterpolation interpolation);
pxr::SdfPath material_id; pxr::SdfPath material_id;
pxr::SdfPath instancer_id;
private: private:
void set_mesh(Mesh *mesh); void set_mesh(Mesh *mesh);

View File

@ -56,7 +56,8 @@ pxr::SdfPath ObjectData::prim_id(pxr::HdSceneDelegate *scene_delegate, Object *o
* O_000002073e369608 */ * O_000002073e369608 */
char str[32]; char str[32];
snprintf(str, 32, "O_%016llx", (uint64_t)object); snprintf(str, 32, "O_%016llx", (uint64_t)object);
return scene_delegate->GetDelegateID().AppendElementString(str); //return scene_delegate->GetDelegateID().AppendElementString(str);
return scene_delegate->GetDelegateID().AppendElementString(((ID *)object)->name);
} }
ObjectData::ObjectData(pxr::HdSceneDelegate *scene_delegate, Object *object) ObjectData::ObjectData(pxr::HdSceneDelegate *scene_delegate, Object *object)