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);
|
||||
|
||||
|
||||
Engine *engine;
|
||||
if (STREQ(engine_type, "VIEWPORT")) {
|
||||
engine = new ViewportEngine(bl_engine, render_delegate_id);
|
||||
@ -136,7 +135,7 @@ static PyObject *engine_free_func(PyObject * /*self*/, PyObject *args)
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
Engine *engine = (Engine *) PyLong_AsVoidPtr(pyengine);
|
||||
Engine *engine = (Engine *)PyLong_AsVoidPtr(pyengine);
|
||||
delete engine;
|
||||
|
||||
CLOG_INFO(LOG_EN, 2, "Engine %016llx", engine);
|
||||
|
@ -26,7 +26,6 @@ BlenderSceneDelegate::BlenderSceneDelegate(pxr::HdRenderIndex *parent_index,
|
||||
|
||||
void BlenderSceneDelegate::update_world()
|
||||
{
|
||||
Scene *scene = DEG_get_input_scene(depsgraph);
|
||||
World *world = scene->world;
|
||||
if (!world_data) {
|
||||
if (world) {
|
||||
@ -104,7 +103,7 @@ void BlenderSceneDelegate::update_collection(bool remove, bool visibility)
|
||||
DEGObjectIterSettings settings = {0};
|
||||
settings.depsgraph = depsgraph;
|
||||
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};
|
||||
data.settings = &settings;
|
||||
data.graph = settings.depsgraph;
|
||||
@ -116,16 +115,12 @@ void BlenderSceneDelegate::update_collection(bool remove, bool visibility)
|
||||
Object *,
|
||||
object) {
|
||||
|
||||
CLOG_INFO(LOG_BSD, 2, "Add %s", ((ID *)object)->name);
|
||||
if (!ObjectData::supported(object)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (data.dupli_object_current != nullptr) {
|
||||
if (!InstancerData::supported(data.dupli_object_current->ob)) {
|
||||
continue;
|
||||
}
|
||||
add_update_instancer(data.dupli_object_current);
|
||||
continue;
|
||||
if ((object->transflag & OB_DUPLI) && InstancerData::supported(object)) {
|
||||
add_update_instancer(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);
|
||||
ObjectData *obj_data = object_data(id);
|
||||
if (!obj_data) {
|
||||
objects[id] = ObjectData::create(this, object);
|
||||
obj_data = object_data(id);
|
||||
obj_data->update_visibility(view3d);
|
||||
return;
|
||||
if (obj_data) {
|
||||
obj_data->update();
|
||||
}
|
||||
|
||||
obj_data->update();
|
||||
objects[id] = ObjectData::create(this, object);
|
||||
obj_data = object_data(id);
|
||||
obj_data->update_visibility(view3d);
|
||||
}
|
||||
|
||||
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);
|
||||
if (!i_data) {
|
||||
objects[id] = InstancerData::create(this, dupli->ob);
|
||||
i_data = instancer_data(id, true);
|
||||
i_data->update_visibility(view3d);
|
||||
if (i_data) {
|
||||
i_data->update();
|
||||
}
|
||||
|
||||
i_data->add_instance(dupli);
|
||||
objects[id] = InstancerData::create(this, object);
|
||||
i_data = instancer_data(id, true);
|
||||
i_data->update_visibility(view3d);
|
||||
}
|
||||
|
||||
ObjectData *BlenderSceneDelegate::object_data(pxr::SdfPath const &id)
|
||||
@ -242,6 +234,7 @@ void BlenderSceneDelegate::populate(Depsgraph *deps, bContext *cont)
|
||||
|
||||
depsgraph = deps;
|
||||
context = cont;
|
||||
scene = DEG_get_input_scene(depsgraph);
|
||||
view3d = CTX_wm_view3d(context);
|
||||
|
||||
if (!is_populated) {
|
||||
@ -263,7 +256,8 @@ void BlenderSceneDelegate::populate(Depsgraph *deps, bContext *cont)
|
||||
ITER_BEGIN (
|
||||
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)) {
|
||||
case ID_OB: {
|
||||
@ -281,11 +275,11 @@ void BlenderSceneDelegate::populate(Depsgraph *deps, bContext *cont)
|
||||
}
|
||||
} break;
|
||||
|
||||
//case ID_GR:
|
||||
// if (id->recalc & (ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY)) {
|
||||
// do_update_collection = true;
|
||||
// }
|
||||
// break;
|
||||
// case ID_GR:
|
||||
// if (id->recalc & (ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY)) {
|
||||
// do_update_collection = true;
|
||||
// }
|
||||
// break;
|
||||
|
||||
case ID_SCE: {
|
||||
if (id->recalc & ID_RECALC_BASE_FLAGS) {
|
||||
|
@ -10,18 +10,19 @@
|
||||
|
||||
#include "CLG_log.h"
|
||||
|
||||
#include "instancer.h"
|
||||
#include "light.h"
|
||||
#include "mesh.h"
|
||||
#include "object.h"
|
||||
#include "world.h"
|
||||
#include "instancer.h"
|
||||
|
||||
namespace blender::render::hydra {
|
||||
|
||||
extern struct CLG_LogRef *LOG_BSD; /* BSD - Blender Scene Delegate */
|
||||
extern struct CLG_LogRef *LOG_BSD; /* BSD - Blender Scene Delegate */
|
||||
|
||||
class BlenderSceneDelegate : public pxr::HdSceneDelegate {
|
||||
friend MeshData;
|
||||
friend InstancerData;
|
||||
|
||||
public:
|
||||
enum class EngineType { VIEWPORT = 1, FINAL, PREVIEW };
|
||||
@ -56,16 +57,17 @@ 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, bool base_prim=false);
|
||||
InstancerData *instancer_data(pxr::SdfPath const &id, bool base_prim = false);
|
||||
|
||||
void add_update_object(Object *object);
|
||||
void add_update_instancer(DupliObject *dupli);
|
||||
void add_update_instancer(Object *object);
|
||||
void update_world();
|
||||
void update_collection(bool remove, bool visibility);
|
||||
|
||||
private:
|
||||
Depsgraph *depsgraph;
|
||||
bContext *context;
|
||||
Scene *scene;
|
||||
View3D *view3d;
|
||||
|
||||
ObjectDataMap objects;
|
||||
|
@ -3,9 +3,9 @@
|
||||
|
||||
#include <pxr/base/gf/vec2f.h>
|
||||
|
||||
#include "../utils.h"
|
||||
#include "blender_scene_delegate.h"
|
||||
#include "instancer.h"
|
||||
#include "../utils.h"
|
||||
|
||||
using namespace pxr;
|
||||
|
||||
@ -27,7 +27,8 @@ bool InstancerData::supported(Object *object)
|
||||
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);
|
||||
data->init();
|
||||
@ -45,26 +46,36 @@ SdfPath InstancerData::prim_id(BlenderSceneDelegate *scene_delegate, Object *obj
|
||||
}
|
||||
|
||||
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);
|
||||
instancer_id = p_id.AppendElementString("Instancer");
|
||||
CLOG_INFO(LOG_BSD, 2, "%s, instancer_id=%s", id->name, instancer_id.GetText());
|
||||
id = nullptr;
|
||||
}
|
||||
|
||||
void InstancerData::init()
|
||||
{
|
||||
CLOG_INFO(LOG_BSD, 2, "%s", id->name);
|
||||
MeshData::init();
|
||||
CLOG_INFO(LOG_BSD, 2, "%s", ((ID *)parent_obj)->name);
|
||||
|
||||
id = nullptr;
|
||||
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()
|
||||
{
|
||||
return pxr::GfMatrix4d(1.0);
|
||||
/* transform of the first instance */
|
||||
//return transforms[0];
|
||||
}
|
||||
|
||||
bool InstancerData::update_visibility(View3D *view3d)
|
||||
@ -73,13 +84,8 @@ bool InstancerData::update_visibility(View3D *view3d)
|
||||
return false;
|
||||
}
|
||||
|
||||
Object *obj = (Object *)id;
|
||||
if (!obj->parent) {
|
||||
return false;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@ -113,12 +119,6 @@ VtIntArray InstancerData::instance_indices()
|
||||
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()
|
||||
{
|
||||
CLOG_INFO(LOG_BSD, 2, "%s", id->name);
|
||||
|
@ -9,10 +9,11 @@
|
||||
|
||||
namespace blender::render::hydra {
|
||||
|
||||
class InstancerData: public MeshData {
|
||||
public:
|
||||
class InstancerData : public MeshData {
|
||||
public:
|
||||
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);
|
||||
|
||||
InstancerData(BlenderSceneDelegate *scene_delegate, Object *object);
|
||||
@ -28,12 +29,11 @@ public:
|
||||
pxr::HdPrimvarDescriptorVector instancer_primvar_descriptors(pxr::HdInterpolation interpolation);
|
||||
pxr::VtIntArray instance_indices();
|
||||
|
||||
void add_instance(DupliObject *dupli);
|
||||
|
||||
pxr::SdfPath instancer_id;
|
||||
|
||||
private:
|
||||
Object *parent_obj;
|
||||
pxr::VtMatrix4dArray transforms;
|
||||
};
|
||||
|
||||
} // namespace blender::render::hydra
|
||||
} // namespace blender::render::hydra
|
||||
|
@ -147,7 +147,7 @@ bool LightData::update_visibility(View3D *view3d)
|
||||
bool ret = ObjectData::update_visibility(view3d);
|
||||
if (ret) {
|
||||
scene_delegate->GetRenderIndex().GetChangeTracker().MarkSprimDirty(p_id,
|
||||
pxr::HdLight::DirtyParams);
|
||||
pxr::HdLight::DirtyParams);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
@ -21,7 +21,7 @@
|
||||
namespace blender::render::hydra {
|
||||
|
||||
std::unique_ptr<MaterialData> MaterialData::create(BlenderSceneDelegate *scene_delegate,
|
||||
Material *material)
|
||||
Material *material)
|
||||
{
|
||||
auto data = std::make_unique<MaterialData>(scene_delegate, material);
|
||||
data->init();
|
||||
@ -104,7 +104,8 @@ pxr::VtValue MaterialData::material_resource()
|
||||
if (material_network_map.IsEmpty()) {
|
||||
const std::string &path = mtlx_path.GetResolvedPath();
|
||||
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 render_contexts = render_delegate->GetMaterialRenderContexts();
|
||||
|
||||
@ -134,7 +135,8 @@ void MaterialData::update()
|
||||
{
|
||||
CLOG_INFO(LOG_BSD, 2, "%s", id->name);
|
||||
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
|
||||
|
@ -20,7 +20,7 @@ class MaterialData : IdData {
|
||||
|
||||
public:
|
||||
static std::unique_ptr<MaterialData> create(BlenderSceneDelegate *scene_delegate,
|
||||
Material *material);
|
||||
Material *material);
|
||||
static pxr::SdfPath prim_id(BlenderSceneDelegate *scene_delegate, Material *material);
|
||||
|
||||
MaterialData(BlenderSceneDelegate *scene_delegate, Material *material);
|
||||
|
@ -8,8 +8,8 @@
|
||||
|
||||
#include "BKE_duplilist.h"
|
||||
|
||||
#include "object.h"
|
||||
#include "material.h"
|
||||
#include "object.h"
|
||||
|
||||
namespace blender::render::hydra {
|
||||
|
||||
|
@ -28,7 +28,8 @@ bool ObjectData::supported(Object *object)
|
||||
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;
|
||||
|
||||
|
@ -29,8 +29,8 @@
|
||||
namespace blender::render::hydra {
|
||||
|
||||
std::unique_ptr<WorldData> WorldData::create(BlenderSceneDelegate *scene_delegate,
|
||||
World *world,
|
||||
bContext *context)
|
||||
World *world,
|
||||
bContext *context)
|
||||
{
|
||||
auto data = std::make_unique<WorldData>(scene_delegate, world, context);
|
||||
data->init();
|
||||
|
@ -21,8 +21,8 @@ namespace blender::render::hydra {
|
||||
class WorldData : public IdData {
|
||||
public:
|
||||
static std::unique_ptr<WorldData> create(BlenderSceneDelegate *scene_delegate,
|
||||
World *world,
|
||||
bContext *context);
|
||||
World *world,
|
||||
bContext *context);
|
||||
static pxr::SdfPath prim_id(BlenderSceneDelegate *scene_delegate);
|
||||
|
||||
WorldData(BlenderSceneDelegate *scene_delegate, World *world, bContext *context);
|
||||
|
Loading…
Reference in New Issue
Block a user