Hydra render engine #104712
|
@ -94,8 +94,6 @@ static PyObject *free_func(PyObject * /*self*/, PyObject *args)
|
|||
|
||||
static PyObject *sync_func(PyObject * /*self*/, PyObject *args)
|
||||
{
|
||||
LOG(INFO) << "sync_func";
|
||||
|
||||
PyObject *pyengine, *pydepsgraph, *pycontext, *pysettings;
|
||||
if (!PyArg_ParseTuple(args, "OOOO", &pyengine, &pydepsgraph, &pycontext, &pysettings)) {
|
||||
Py_RETURN_NONE;
|
||||
|
@ -138,8 +136,6 @@ static PyObject *sync_func(PyObject * /*self*/, PyObject *args)
|
|||
|
||||
static PyObject *render_func(PyObject * /*self*/, PyObject *args)
|
||||
{
|
||||
LOG(INFO) << "render_func";
|
||||
|
||||
PyObject *pyengine, *pydepsgraph;
|
||||
if (!PyArg_ParseTuple(args, "OO", &pyengine, &pydepsgraph)) {
|
||||
Py_RETURN_NONE;
|
||||
|
@ -161,8 +157,6 @@ static PyObject *render_func(PyObject * /*self*/, PyObject *args)
|
|||
|
||||
static PyObject *view_draw_func(PyObject * /*self*/, PyObject *args)
|
||||
{
|
||||
LOG(INFO) << "view_draw_func";
|
||||
|
||||
PyObject *pyengine, *pydepsgraph, *pycontext;
|
||||
if (!PyArg_ParseTuple(args, "OOO", &pyengine, &pydepsgraph, &pycontext)) {
|
||||
Py_RETURN_NONE;
|
||||
|
|
|
@ -11,15 +11,15 @@ namespace usdhydra {
|
|||
BlenderSceneDelegate::BlenderSceneDelegate(HdRenderIndex* parentIndex, SdfPath const& delegateID, BL::Depsgraph &b_depsgraph)
|
||||
: HdSceneDelegate(parentIndex, delegateID)
|
||||
, b_depsgraph(b_depsgraph)
|
||||
, _isPopulated(false)
|
||||
, isPopulated(false)
|
||||
{
|
||||
}
|
||||
|
||||
std::unique_ptr<ObjectExport> BlenderSceneDelegate::objectExport(SdfPath const & id)
|
||||
{
|
||||
std::string name = id.GetName();
|
||||
std::string name = objects[id];
|
||||
for (BL::Object &obj : b_depsgraph.objects) {
|
||||
if (obj.name() == name) {
|
||||
if (obj.name_full() == name) {
|
||||
return std::make_unique<ObjectExport>(obj, b_depsgraph);
|
||||
}
|
||||
}
|
||||
|
@ -28,18 +28,82 @@ std::unique_ptr<ObjectExport> BlenderSceneDelegate::objectExport(SdfPath const &
|
|||
|
||||
void BlenderSceneDelegate::Populate()
|
||||
{
|
||||
LOG(INFO) << "Populate " << _isPopulated;
|
||||
LOG(INFO) << "Populate " << isPopulated;
|
||||
|
||||
if (_isPopulated) {
|
||||
// TODO: check depsgraph updates
|
||||
|
||||
//GetRenderIndex().GetChangeTracker().MarkRprimDirty(objId,
|
||||
// HdChangeTracker::DirtyPoints | HdChangeTracker::DirtyNormals | HdChangeTracker::AllDirty);
|
||||
if (isPopulated) {
|
||||
for (auto &update : b_depsgraph.updates) {
|
||||
BL::ID id = update.id();
|
||||
LOG(INFO) << "Update: " << id.name_full() << " " << update.is_updated_transform() << update.is_updated_geometry() << update.is_updated_shading();
|
||||
|
||||
if (id.is_a(&RNA_Object)) {
|
||||
BL::Object &obj = (BL::Object &)id;
|
||||
std::string objName = obj.name_full();
|
||||
SdfPath objId = GetDelegateID().AppendElementString(TfMakeValidIdentifier(objName));
|
||||
|
||||
if (objects.find(objId) == objects.end()) {
|
||||
LOG(INFO) << "Add mesh object: " << objId;
|
||||
GetRenderIndex().InsertRprim(HdPrimTypeTokens->mesh, this, objId);
|
||||
objects[objId] = objName;
|
||||
continue;
|
||||
}
|
||||
if (update.is_updated_geometry()) {
|
||||
LOG(INFO) << "Full updated: " << objId;
|
||||
GetRenderIndex().GetChangeTracker().MarkRprimDirty(objId, HdChangeTracker::AllDirty);
|
||||
continue;
|
||||
}
|
||||
if (update.is_updated_transform()) {
|
||||
LOG(INFO) << "Transform updated: " << objId;
|
||||
GetRenderIndex().GetChangeTracker().MarkRprimDirty(objId, HdChangeTracker::DirtyTransform);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (id.is_a(&RNA_Collection)) {
|
||||
BL::Collection &col = (BL::Collection &)id;
|
||||
//std::cout << "Collection: " << col.name() << "\n";
|
||||
if (update.is_updated_transform() && update.is_updated_geometry()) {
|
||||
//available objects from depsgraph
|
||||
std::set<std::string> depsObjects;
|
||||
for (auto &inst : b_depsgraph.object_instances) {
|
||||
if (inst.is_instance()) {
|
||||
continue;
|
||||
}
|
||||
BL::Object obj = inst.object();
|
||||
if (obj.type() == BL::Object::type_MESH) {
|
||||
depsObjects.insert(obj.name_full());
|
||||
}
|
||||
}
|
||||
|
||||
auto it = objects.begin();
|
||||
while (it != objects.end()) {
|
||||
if (depsObjects.find(it->second) == depsObjects.end()) {
|
||||
LOG(INFO) << "Removed: " << it->first;
|
||||
GetRenderIndex().RemoveRprim(it->first);
|
||||
objects.erase(it);
|
||||
it = objects.begin();
|
||||
}
|
||||
else {
|
||||
++it;
|
||||
}
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
//if (id.is_a(&RNA_Scene)) {
|
||||
// BL::Scene &scene = (BL::Scene &)id;
|
||||
// std::cout << "Scene: " << scene.name() << "\n";
|
||||
|
||||
//}
|
||||
//else {
|
||||
// std::cout << "Other: " << id.name() << "\n";
|
||||
//}
|
||||
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
auto &instances = b_depsgraph.object_instances;
|
||||
for (auto& inst : instances) {
|
||||
for (auto &inst : b_depsgraph.object_instances) {
|
||||
if (inst.is_instance()) {
|
||||
continue;
|
||||
}
|
||||
|
@ -48,7 +112,10 @@ void BlenderSceneDelegate::Populate()
|
|||
SdfPath objId = GetDelegateID().AppendElementString(obj.name_full());
|
||||
|
||||
if (obj.type() == BL::Object::type_MESH) {
|
||||
LOG(INFO) << "Add mesh object: " << objId;
|
||||
|
||||
GetRenderIndex().InsertRprim(HdPrimTypeTokens->mesh, this, objId);
|
||||
objects[objId] = obj.name_full();
|
||||
continue;
|
||||
}
|
||||
if (obj.type() == BL::Object::type_LIGHT) {
|
||||
|
@ -56,7 +123,7 @@ void BlenderSceneDelegate::Populate()
|
|||
continue;
|
||||
}
|
||||
}
|
||||
_isPopulated = true;
|
||||
isPopulated = true;
|
||||
}
|
||||
|
||||
HdMeshTopology BlenderSceneDelegate::GetMeshTopology(SdfPath const& id)
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
|
||||
#include <pxr/pxr.h>
|
||||
#include <pxr/imaging/hd/camera.h>
|
||||
#include <pxr/imaging/hd/sceneDelegate.h>
|
||||
|
@ -35,9 +37,11 @@ public:
|
|||
|
||||
private:
|
||||
BL::Depsgraph b_depsgraph;
|
||||
bool _isPopulated;
|
||||
bool isPopulated;
|
||||
|
||||
std::unique_ptr<ObjectExport> objectExport(SdfPath const& id);
|
||||
|
||||
std::map<SdfPath, std::string> objects;
|
||||
};
|
||||
|
||||
} // namespace usdhydra
|
||||
|
|
Loading…
Reference in New Issue