forked from blender/blender
BLEN-359: Implement updates for instances in viewport #20
@ -107,7 +107,6 @@ static PyObject *engine_create_func(PyObject * /*self*/, PyObject *args)
|
|||||||
|
|
||||||
RenderEngine *bl_engine = (RenderEngine *)PyLong_AsVoidPtr(pyengine);
|
RenderEngine *bl_engine = (RenderEngine *)PyLong_AsVoidPtr(pyengine);
|
||||||
|
|
||||||
|
|
||||||
Engine *engine;
|
Engine *engine;
|
||||||
if (STREQ(engine_type, "VIEWPORT")) {
|
if (STREQ(engine_type, "VIEWPORT")) {
|
||||||
engine = new ViewportEngine(bl_engine, render_delegate_id);
|
engine = new ViewportEngine(bl_engine, render_delegate_id);
|
||||||
@ -136,7 +135,7 @@ static PyObject *engine_free_func(PyObject * /*self*/, PyObject *args)
|
|||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
Engine *engine = (Engine *) PyLong_AsVoidPtr(pyengine);
|
Engine *engine = (Engine *)PyLong_AsVoidPtr(pyengine);
|
||||||
delete engine;
|
delete engine;
|
||||||
|
|
||||||
CLOG_INFO(LOG_EN, 2, "Engine %016llx", engine);
|
CLOG_INFO(LOG_EN, 2, "Engine %016llx", engine);
|
||||||
|
@ -26,7 +26,6 @@ BlenderSceneDelegate::BlenderSceneDelegate(pxr::HdRenderIndex *parent_index,
|
|||||||
|
|
||||||
void BlenderSceneDelegate::update_world()
|
void BlenderSceneDelegate::update_world()
|
||||||
{
|
{
|
||||||
Scene *scene = DEG_get_input_scene(depsgraph);
|
|
||||||
World *world = scene->world;
|
World *world = scene->world;
|
||||||
if (!world_data) {
|
if (!world_data) {
|
||||||
if (world) {
|
if (world) {
|
||||||
@ -104,7 +103,7 @@ void BlenderSceneDelegate::update_collection(bool remove, bool visibility)
|
|||||||
DEGObjectIterSettings settings = {0};
|
DEGObjectIterSettings settings = {0};
|
||||||
settings.depsgraph = depsgraph;
|
settings.depsgraph = depsgraph;
|
||||||
settings.flags = DEG_ITER_OBJECT_FLAG_LINKED_DIRECTLY | DEG_ITER_OBJECT_FLAG_VISIBLE |
|
settings.flags = DEG_ITER_OBJECT_FLAG_LINKED_DIRECTLY | DEG_ITER_OBJECT_FLAG_VISIBLE |
|
||||||
DEG_ITER_OBJECT_FLAG_LINKED_VIA_SET | DEG_ITER_OBJECT_FLAG_DUPLI;
|
DEG_ITER_OBJECT_FLAG_LINKED_VIA_SET;
|
||||||
DEGObjectIterData data = {0};
|
DEGObjectIterData data = {0};
|
||||||
data.settings = &settings;
|
data.settings = &settings;
|
||||||
data.graph = settings.depsgraph;
|
data.graph = settings.depsgraph;
|
||||||
@ -116,16 +115,12 @@ void BlenderSceneDelegate::update_collection(bool remove, bool visibility)
|
|||||||
Object *,
|
Object *,
|
||||||
object) {
|
object) {
|
||||||
|
|
||||||
|
CLOG_INFO(LOG_BSD, 2, "Add %s", ((ID *)object)->name);
|
||||||
if (!ObjectData::supported(object)) {
|
if (!ObjectData::supported(object)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if ((object->transflag & OB_DUPLI) && InstancerData::supported(object)) {
|
||||||
if (data.dupli_object_current != nullptr) {
|
add_update_instancer(object);
|
||||||
if (!InstancerData::supported(data.dupli_object_current->ob)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
add_update_instancer(data.dupli_object_current);
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
id = ObjectData::prim_id(this, object);
|
id = ObjectData::prim_id(this, object);
|
||||||
@ -177,27 +172,24 @@ void BlenderSceneDelegate::add_update_object(Object *object)
|
|||||||
{
|
{
|
||||||
pxr::SdfPath id = ObjectData::prim_id(this, object);
|
pxr::SdfPath id = ObjectData::prim_id(this, object);
|
||||||
ObjectData *obj_data = object_data(id);
|
ObjectData *obj_data = object_data(id);
|
||||||
if (!obj_data) {
|
if (obj_data) {
|
||||||
|
obj_data->update();
|
||||||
|
}
|
||||||
objects[id] = ObjectData::create(this, object);
|
objects[id] = ObjectData::create(this, object);
|
||||||
obj_data = object_data(id);
|
obj_data = object_data(id);
|
||||||
obj_data->update_visibility(view3d);
|
obj_data->update_visibility(view3d);
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
obj_data->update();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void BlenderSceneDelegate::add_update_instancer(DupliObject *dupli)
|
void BlenderSceneDelegate::add_update_instancer(Object *object)
|
||||||
{
|
{
|
||||||
pxr::SdfPath id = InstancerData::prim_id(this, dupli->ob);
|
pxr::SdfPath id = InstancerData::prim_id(this, object);
|
||||||
InstancerData *i_data = instancer_data(id, true);
|
InstancerData *i_data = instancer_data(id, true);
|
||||||
if (!i_data) {
|
if (i_data) {
|
||||||
objects[id] = InstancerData::create(this, dupli->ob);
|
i_data->update();
|
||||||
|
}
|
||||||
|
objects[id] = InstancerData::create(this, object);
|
||||||
i_data = instancer_data(id, true);
|
i_data = instancer_data(id, true);
|
||||||
i_data->update_visibility(view3d);
|
i_data->update_visibility(view3d);
|
||||||
}
|
|
||||||
|
|
||||||
i_data->add_instance(dupli);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ObjectData *BlenderSceneDelegate::object_data(pxr::SdfPath const &id)
|
ObjectData *BlenderSceneDelegate::object_data(pxr::SdfPath const &id)
|
||||||
@ -242,6 +234,7 @@ void BlenderSceneDelegate::populate(Depsgraph *deps, bContext *cont)
|
|||||||
|
|
||||||
depsgraph = deps;
|
depsgraph = deps;
|
||||||
context = cont;
|
context = cont;
|
||||||
|
scene = DEG_get_input_scene(depsgraph);
|
||||||
view3d = CTX_wm_view3d(context);
|
view3d = CTX_wm_view3d(context);
|
||||||
|
|
||||||
if (!is_populated) {
|
if (!is_populated) {
|
||||||
@ -263,7 +256,8 @@ void BlenderSceneDelegate::populate(Depsgraph *deps, bContext *cont)
|
|||||||
ITER_BEGIN (
|
ITER_BEGIN (
|
||||||
DEG_iterator_ids_begin, DEG_iterator_ids_next, DEG_iterator_ids_end, &data, ID *, id) {
|
DEG_iterator_ids_begin, DEG_iterator_ids_next, DEG_iterator_ids_end, &data, ID *, id) {
|
||||||
|
|
||||||
CLOG_INFO(LOG_BSD, 2, "Update: %s [%s]", id->name, std::bitset<32>(id->recalc).to_string().c_str());
|
CLOG_INFO(
|
||||||
|
LOG_BSD, 2, "Update: %s [%s]", id->name, std::bitset<32>(id->recalc).to_string().c_str());
|
||||||
|
|
||||||
switch (GS(id->name)) {
|
switch (GS(id->name)) {
|
||||||
case ID_OB: {
|
case ID_OB: {
|
||||||
@ -281,7 +275,7 @@ void BlenderSceneDelegate::populate(Depsgraph *deps, bContext *cont)
|
|||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
//case ID_GR:
|
// case ID_GR:
|
||||||
// if (id->recalc & (ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY)) {
|
// if (id->recalc & (ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY)) {
|
||||||
// do_update_collection = true;
|
// do_update_collection = true;
|
||||||
// }
|
// }
|
||||||
|
@ -10,11 +10,11 @@
|
|||||||
|
|
||||||
#include "CLG_log.h"
|
#include "CLG_log.h"
|
||||||
|
|
||||||
|
#include "instancer.h"
|
||||||
#include "light.h"
|
#include "light.h"
|
||||||
#include "mesh.h"
|
#include "mesh.h"
|
||||||
#include "object.h"
|
#include "object.h"
|
||||||
#include "world.h"
|
#include "world.h"
|
||||||
#include "instancer.h"
|
|
||||||
|
|
||||||
namespace blender::render::hydra {
|
namespace blender::render::hydra {
|
||||||
|
|
||||||
@ -22,6 +22,7 @@ extern struct CLG_LogRef *LOG_BSD; /* BSD - Blender Scene Delegate */
|
|||||||
|
|
||||||
class BlenderSceneDelegate : public pxr::HdSceneDelegate {
|
class BlenderSceneDelegate : public pxr::HdSceneDelegate {
|
||||||
friend MeshData;
|
friend MeshData;
|
||||||
|
friend InstancerData;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum class EngineType { VIEWPORT = 1, FINAL, PREVIEW };
|
enum class EngineType { VIEWPORT = 1, FINAL, PREVIEW };
|
||||||
@ -56,16 +57,17 @@ 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_prim=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(Object *object);
|
||||||
void update_world();
|
void update_world();
|
||||||
void update_collection(bool remove, bool visibility);
|
void update_collection(bool remove, bool visibility);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Depsgraph *depsgraph;
|
Depsgraph *depsgraph;
|
||||||
bContext *context;
|
bContext *context;
|
||||||
|
Scene *scene;
|
||||||
View3D *view3d;
|
View3D *view3d;
|
||||||
|
|
||||||
ObjectDataMap objects;
|
ObjectDataMap objects;
|
||||||
|
@ -3,9 +3,9 @@
|
|||||||
|
|
||||||
#include <pxr/base/gf/vec2f.h>
|
#include <pxr/base/gf/vec2f.h>
|
||||||
|
|
||||||
|
#include "../utils.h"
|
||||||
#include "blender_scene_delegate.h"
|
#include "blender_scene_delegate.h"
|
||||||
#include "instancer.h"
|
#include "instancer.h"
|
||||||
#include "../utils.h"
|
|
||||||
|
|
||||||
using namespace pxr;
|
using namespace pxr;
|
||||||
|
|
||||||
@ -27,7 +27,8 @@ bool InstancerData::supported(Object *object)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<InstancerData> InstancerData::create(BlenderSceneDelegate *scene_delegate, Object *object)
|
std::unique_ptr<InstancerData> InstancerData::create(BlenderSceneDelegate *scene_delegate,
|
||||||
|
Object *object)
|
||||||
{
|
{
|
||||||
auto data = std::make_unique<InstancerData>(scene_delegate, object);
|
auto data = std::make_unique<InstancerData>(scene_delegate, object);
|
||||||
data->init();
|
data->init();
|
||||||
@ -45,26 +46,36 @@ 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)
|
: MeshData(scene_delegate, object), parent_obj(object)
|
||||||
{
|
{
|
||||||
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->name, instancer_id.GetText());
|
||||||
|
id = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void InstancerData::init()
|
void InstancerData::init()
|
||||||
{
|
{
|
||||||
CLOG_INFO(LOG_BSD, 2, "%s", id->name);
|
CLOG_INFO(LOG_BSD, 2, "%s", ((ID *)parent_obj)->name);
|
||||||
MeshData::init();
|
|
||||||
|
|
||||||
|
id = nullptr;
|
||||||
transforms.clear();
|
transforms.clear();
|
||||||
|
ListBase *lb = object_duplilist(scene_delegate->depsgraph, scene_delegate->scene, parent_obj);
|
||||||
|
LISTBASE_FOREACH (DupliObject *, dupli, lb) {
|
||||||
|
if (!id) {
|
||||||
|
id = (ID *)dupli->ob;
|
||||||
|
}
|
||||||
|
transforms.push_back(gf_matrix_from_transform(dupli->mat));
|
||||||
|
CLOG_INFO(LOG_BSD, 2, "Instance %s %d", id->name, dupli->random_id);
|
||||||
|
}
|
||||||
|
free_object_duplilist(lb);
|
||||||
|
|
||||||
|
MeshData::init();
|
||||||
}
|
}
|
||||||
|
|
||||||
GfMatrix4d InstancerData::transform()
|
GfMatrix4d InstancerData::transform()
|
||||||
{
|
{
|
||||||
return pxr::GfMatrix4d(1.0);
|
return pxr::GfMatrix4d(1.0);
|
||||||
/* transform of the first instance */
|
|
||||||
//return transforms[0];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool InstancerData::update_visibility(View3D *view3d)
|
bool InstancerData::update_visibility(View3D *view3d)
|
||||||
@ -73,13 +84,8 @@ bool InstancerData::update_visibility(View3D *view3d)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Object *obj = (Object *)id;
|
|
||||||
if (!obj->parent) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool prev_visible = visible;
|
bool prev_visible = visible;
|
||||||
visible = BKE_object_is_visible_in_viewport(view3d, obj->parent);
|
visible = BKE_object_is_visible_in_viewport(view3d, parent_obj);
|
||||||
return visible != prev_visible;
|
return visible != prev_visible;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,12 +119,6 @@ VtIntArray InstancerData::instance_indices()
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void InstancerData::add_instance(DupliObject *dupli)
|
|
||||||
{
|
|
||||||
CLOG_INFO(LOG_BSD, 2, "%s [%d]", id->name, dupli->random_id);
|
|
||||||
transforms.push_back(gf_matrix_from_transform(dupli->mat));
|
|
||||||
}
|
|
||||||
|
|
||||||
void InstancerData::insert()
|
void InstancerData::insert()
|
||||||
{
|
{
|
||||||
CLOG_INFO(LOG_BSD, 2, "%s", id->name);
|
CLOG_INFO(LOG_BSD, 2, "%s", id->name);
|
||||||
|
@ -9,10 +9,11 @@
|
|||||||
|
|
||||||
namespace blender::render::hydra {
|
namespace blender::render::hydra {
|
||||||
|
|
||||||
class InstancerData: public MeshData {
|
class InstancerData : public MeshData {
|
||||||
public:
|
public:
|
||||||
static bool supported(Object *object);
|
static bool supported(Object *object);
|
||||||
static std::unique_ptr<InstancerData> create(BlenderSceneDelegate *scene_delegate, Object *object);
|
static std::unique_ptr<InstancerData> create(BlenderSceneDelegate *scene_delegate,
|
||||||
|
Object *object);
|
||||||
static pxr::SdfPath prim_id(BlenderSceneDelegate *scene_delegate, Object *object);
|
static pxr::SdfPath prim_id(BlenderSceneDelegate *scene_delegate, Object *object);
|
||||||
|
|
||||||
InstancerData(BlenderSceneDelegate *scene_delegate, Object *object);
|
InstancerData(BlenderSceneDelegate *scene_delegate, Object *object);
|
||||||
@ -28,11 +29,10 @@ public:
|
|||||||
pxr::HdPrimvarDescriptorVector instancer_primvar_descriptors(pxr::HdInterpolation interpolation);
|
pxr::HdPrimvarDescriptorVector instancer_primvar_descriptors(pxr::HdInterpolation interpolation);
|
||||||
pxr::VtIntArray instance_indices();
|
pxr::VtIntArray instance_indices();
|
||||||
|
|
||||||
void add_instance(DupliObject *dupli);
|
|
||||||
|
|
||||||
pxr::SdfPath instancer_id;
|
pxr::SdfPath instancer_id;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Object *parent_obj;
|
||||||
pxr::VtMatrix4dArray transforms;
|
pxr::VtMatrix4dArray transforms;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -104,7 +104,8 @@ pxr::VtValue MaterialData::material_resource()
|
|||||||
if (material_network_map.IsEmpty()) {
|
if (material_network_map.IsEmpty()) {
|
||||||
const std::string &path = mtlx_path.GetResolvedPath();
|
const std::string &path = mtlx_path.GetResolvedPath();
|
||||||
if (!path.empty()) {
|
if (!path.empty()) {
|
||||||
pxr::HdRenderDelegate *render_delegate = scene_delegate->GetRenderIndex().GetRenderDelegate();
|
pxr::HdRenderDelegate *render_delegate =
|
||||||
|
scene_delegate->GetRenderIndex().GetRenderDelegate();
|
||||||
pxr::TfTokenVector shader_source_types = render_delegate->GetShaderSourceTypes();
|
pxr::TfTokenVector shader_source_types = render_delegate->GetShaderSourceTypes();
|
||||||
pxr::TfTokenVector render_contexts = render_delegate->GetMaterialRenderContexts();
|
pxr::TfTokenVector render_contexts = render_delegate->GetMaterialRenderContexts();
|
||||||
|
|
||||||
@ -134,7 +135,8 @@ void MaterialData::update()
|
|||||||
{
|
{
|
||||||
CLOG_INFO(LOG_BSD, 2, "%s", id->name);
|
CLOG_INFO(LOG_BSD, 2, "%s", id->name);
|
||||||
init();
|
init();
|
||||||
scene_delegate->GetRenderIndex().GetChangeTracker().MarkSprimDirty(p_id, pxr::HdMaterial::AllDirty);
|
scene_delegate->GetRenderIndex().GetChangeTracker().MarkSprimDirty(p_id,
|
||||||
|
pxr::HdMaterial::AllDirty);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace blender::render::hydra
|
} // namespace blender::render::hydra
|
||||||
|
@ -8,8 +8,8 @@
|
|||||||
|
|
||||||
#include "BKE_duplilist.h"
|
#include "BKE_duplilist.h"
|
||||||
|
|
||||||
#include "object.h"
|
|
||||||
#include "material.h"
|
#include "material.h"
|
||||||
|
#include "object.h"
|
||||||
|
|
||||||
namespace blender::render::hydra {
|
namespace blender::render::hydra {
|
||||||
|
|
||||||
|
@ -28,7 +28,8 @@ bool ObjectData::supported(Object *object)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<ObjectData> ObjectData::create(BlenderSceneDelegate *scene_delegate, Object *object)
|
std::unique_ptr<ObjectData> ObjectData::create(BlenderSceneDelegate *scene_delegate,
|
||||||
|
Object *object)
|
||||||
{
|
{
|
||||||
std::unique_ptr<ObjectData> data;
|
std::unique_ptr<ObjectData> data;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user