BLEN-359: Implement updates for instances in viewport #20

Merged
Bogdan Nagirniak merged 20 commits from BLEN-359_1 into hydra-render 2023-04-05 11:47:37 +02:00
10 changed files with 47 additions and 55 deletions
Showing only changes of commit b4e44a88e6 - Show all commits

View File

@ -11,14 +11,6 @@ namespace blender::render::hydra {
IdData::IdData(BlenderSceneDelegate *scene_delegate, ID *id)
: scene_delegate(scene_delegate), id(id)
{
//p_id = prim_id();
//init();
//insert();
}
IdData::~IdData()
{
//remove();
}
std::string IdData::name() const

View File

@ -16,10 +16,9 @@ class BlenderSceneDelegate;
class IdData {
public:
IdData(BlenderSceneDelegate *scene_delegate, ID *id);
virtual ~IdData();
virtual ~IdData() = default;
enum class DirtyBits { DIRTY_TRANSFORM = 1, DIRTY_VISIBILITY, DIRTY_MATERIAL, ALL_DIRTY };
virtual pxr::SdfPath prim_id() const = 0;
virtual void init() = 0;
virtual void insert() = 0;
virtual void remove() = 0;
@ -28,7 +27,6 @@ class IdData {
virtual pxr::VtValue get_data(pxr::TfToken const &key) const;
template<class T> const T get_data(pxr::TfToken const &key) const;
std::string name() const;
protected:

View File

@ -18,6 +18,12 @@ namespace blender::render::hydra {
LightData::LightData(BlenderSceneDelegate *scene_delegate, Object *object)
: ObjectData(scene_delegate, object)
{
}
void LightData::init()
{
CLOG_INFO(LOG_BSD, 2, "%s", id->name);
Light *light = (Light *)((Object *)id)->data;
data[pxr::HdLightTokens->intensity] = scene_delegate->engine_type ==
@ -133,10 +139,6 @@ pxr::VtValue LightData::get_data(pxr::TfToken const &key) const
return ret;
}
void LightData::init()
{
}
void LightData::insert()
{
scene_delegate->GetRenderIndex().InsertSprim(prim_type(), scene_delegate, p_id);

View File

@ -23,7 +23,9 @@ namespace blender::render::hydra {
std::unique_ptr<MaterialData> MaterialData::create(BlenderSceneDelegate *scene_delegate,
Material *material)
{
return std::make_unique<MaterialData>(scene_delegate, material);
auto data = std::make_unique<MaterialData>(scene_delegate, material);
data->init();
return data;
}
pxr::SdfPath MaterialData::prim_id(BlenderSceneDelegate *scene_delegate, Material *material)
@ -41,13 +43,9 @@ MaterialData::MaterialData(BlenderSceneDelegate *scene_delegate, Material *mater
p_id = prim_id(scene_delegate, material);
}
pxr::SdfPath MaterialData::prim_id() const
{
return pxr::SdfPath();
}
void MaterialData::init()
{
CLOG_INFO(LOG_BSD, 2, "%s", id->name);
}
pxr::VtValue MaterialData::get_data(pxr::TfToken const &key) const

View File

@ -21,7 +21,6 @@ class MaterialData : IdData {
MaterialData(BlenderSceneDelegate *scene_delegate, Material *material);
pxr::SdfPath prim_id() const override;
void init() override;
void insert() override;
void remove() override;

View File

@ -18,17 +18,6 @@ namespace blender::render::hydra {
MeshData::MeshData(BlenderSceneDelegate *scene_delegate, Object *object)
: ObjectData(scene_delegate, object)
{
if (object->type == OB_MESH && object->mode == OB_MODE_OBJECT &&
BLI_listbase_is_empty(&object->modifiers)) {
set_mesh((Mesh *)object->data);
}
else {
Mesh *mesh = BKE_object_to_mesh(nullptr, object, false);
if (mesh) {
set_mesh(mesh);
}
BKE_object_to_mesh_clear(object);
}
}
pxr::VtValue MeshData::get_data(pxr::TfToken const &key) const
@ -202,6 +191,20 @@ void MeshData::set_mesh(Mesh *mesh)
void MeshData::init()
{
CLOG_INFO(LOG_BSD, 2, "%s", id->name);
Object *object = (Object *)id;
if (object->type == OB_MESH && object->mode == OB_MODE_OBJECT &&
BLI_listbase_is_empty(&object->modifiers)) {
set_mesh((Mesh *)object->data);
}
else {
Mesh *mesh = BKE_object_to_mesh(nullptr, object, false);
if (mesh) {
set_mesh(mesh);
}
BKE_object_to_mesh_clear(object);
}
}
void MeshData::insert()

View File

@ -30,6 +30,8 @@ bool ObjectData::supported(Object *object)
std::unique_ptr<ObjectData> ObjectData::create(BlenderSceneDelegate *scene_delegate, Object *object)
{
std::unique_ptr<ObjectData> data;
switch (object->type) {
case OB_MESH:
case OB_SURF:
@ -37,15 +39,20 @@ std::unique_ptr<ObjectData> ObjectData::create(BlenderSceneDelegate *scene_deleg
case OB_CURVES:
case OB_CURVES_LEGACY:
case OB_MBALL:
return std::make_unique<MeshData>(scene_delegate, object);
data = std::make_unique<MeshData>(scene_delegate, object);
break;
case OB_LAMP:
return std::make_unique<LightData>(scene_delegate, object);
data = std::make_unique<LightData>(scene_delegate, object);
break;
default:
break;
}
return nullptr;
if (data) {
data->init();
}
return data;
}
pxr::SdfPath ObjectData::prim_id(BlenderSceneDelegate *scene_delegate, Object *object)
@ -63,11 +70,6 @@ ObjectData::ObjectData(BlenderSceneDelegate *scene_delegate, Object *object)
p_id = prim_id(scene_delegate, object);
}
pxr::SdfPath ObjectData::prim_id() const
{
return pxr::SdfPath();
}
int ObjectData::type()
{
return ((Object *)id)->type;

View File

@ -22,8 +22,6 @@ class ObjectData : public IdData {
ObjectData(BlenderSceneDelegate *scene_delegate, Object *object);
pxr::SdfPath prim_id() const override;
int type();
pxr::GfMatrix4d transform();
bool update_visibility(View3D *view3d);

View File

@ -32,7 +32,9 @@ std::unique_ptr<WorldData> WorldData::create(BlenderSceneDelegate *scene_delegat
World *world,
bContext *context)
{
return std::make_unique<WorldData>(scene_delegate, world, context);
auto data = std::make_unique<WorldData>(scene_delegate, world, context);
data->init();
return data;
}
pxr::SdfPath WorldData::prim_id(BlenderSceneDelegate *scene_delegate)
@ -41,9 +43,16 @@ pxr::SdfPath WorldData::prim_id(BlenderSceneDelegate *scene_delegate)
}
WorldData::WorldData(BlenderSceneDelegate *scene_delegate, World *world, bContext *context)
: IdData(scene_delegate, (ID *)world)
: IdData(scene_delegate, (ID *)world), context(context)
{
p_id = prim_id(scene_delegate);
}
void WorldData::init()
{
CLOG_INFO(LOG_BSD, 2, "%s", id->name);
World *world = (World *)id;
data[pxr::UsdLuxTokens->orientToStageUpAxis] = true;
@ -100,15 +109,6 @@ WorldData::WorldData(BlenderSceneDelegate *scene_delegate, World *world, bContex
}
}
pxr::SdfPath WorldData::prim_id() const
{
return pxr::SdfPath();
}
void WorldData::init()
{
}
pxr::GfMatrix4d WorldData::transform()
{
pxr::GfMatrix4d transform = pxr::GfMatrix4d(pxr::GfRotation(pxr::GfVec3d(1.0, 0.0, 0.0), -90),

View File

@ -27,7 +27,6 @@ class WorldData : public IdData {
WorldData(BlenderSceneDelegate *scene_delegate, World *world, bContext *context);
pxr::SdfPath prim_id() const override;
void init() override;
void insert() override;
void remove() override;
@ -39,6 +38,7 @@ class WorldData : public IdData {
private:
std::map<pxr::TfToken, pxr::VtValue> data;
bContext *context;
};
} // namespace blender::render::hydra