forked from blender/blender
Code improvements and fixes #26
@ -35,7 +35,7 @@ pxr::GfMatrix4d BlenderSceneDelegate::GetTransform(pxr::SdfPath const &id)
|
||||
return obj_data->transform();
|
||||
}
|
||||
|
||||
if (id == WorldData::prim_id(this)) {
|
||||
if (id == world_prim_id()) {
|
||||
return world_data_->transform();
|
||||
}
|
||||
|
||||
@ -71,7 +71,7 @@ pxr::VtValue BlenderSceneDelegate::GetLightParamValue(pxr::SdfPath const &id,
|
||||
if (l_data) {
|
||||
return l_data->get_data(key);
|
||||
}
|
||||
if (id == WorldData::prim_id(this)) {
|
||||
if (id == world_prim_id()) {
|
||||
return world_data_->get_data(key);
|
||||
}
|
||||
return pxr::VtValue();
|
||||
@ -111,7 +111,7 @@ pxr::VtValue BlenderSceneDelegate::GetMaterialResource(pxr::SdfPath const &id)
|
||||
|
||||
bool BlenderSceneDelegate::GetVisible(pxr::SdfPath const &id)
|
||||
{
|
||||
if (id == WorldData::prim_id(this)) {
|
||||
if (id == world_prim_id()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -187,7 +187,35 @@ void BlenderSceneDelegate::clear()
|
||||
materials_.clear();
|
||||
}
|
||||
|
||||
ObjectData *BlenderSceneDelegate::object_data(pxr::SdfPath const &id)
|
||||
pxr::SdfPath BlenderSceneDelegate::prim_id(ID *id, const char *prefix) const
|
||||
{
|
||||
/* Making id of object in form like <prefix>_<pointer in 16 hex digits format> */
|
||||
char str[32];
|
||||
snprintf(str, 32, "%s_%016llx", prefix, (uint64_t)id);
|
||||
return GetDelegateID().AppendElementString(str);
|
||||
}
|
||||
|
||||
pxr::SdfPath BlenderSceneDelegate::object_prim_id(Object *object) const
|
||||
{
|
||||
return prim_id((ID *)object, "O");
|
||||
}
|
||||
|
||||
pxr::SdfPath BlenderSceneDelegate::material_prim_id(Material *mat) const
|
||||
{
|
||||
return prim_id((ID *)mat, "M");
|
||||
}
|
||||
|
||||
pxr::SdfPath BlenderSceneDelegate::instancer_prim_id(Object *object) const
|
||||
{
|
||||
return prim_id((ID *)object, "I");
|
||||
}
|
||||
|
||||
pxr::SdfPath BlenderSceneDelegate::world_prim_id() const
|
||||
{
|
||||
return GetDelegateID().AppendElementString("World");
|
||||
}
|
||||
|
||||
ObjectData *BlenderSceneDelegate::object_data(pxr::SdfPath const &id) const
|
||||
{
|
||||
auto it = objects_.find(id);
|
||||
if (it != objects_.end()) {
|
||||
@ -200,17 +228,17 @@ ObjectData *BlenderSceneDelegate::object_data(pxr::SdfPath const &id)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
MeshData *BlenderSceneDelegate::mesh_data(pxr::SdfPath const &id)
|
||||
MeshData *BlenderSceneDelegate::mesh_data(pxr::SdfPath const &id) const
|
||||
{
|
||||
return dynamic_cast<MeshData *>(object_data(id));
|
||||
}
|
||||
|
||||
LightData *BlenderSceneDelegate::light_data(pxr::SdfPath const &id)
|
||||
LightData *BlenderSceneDelegate::light_data(pxr::SdfPath const &id) const
|
||||
{
|
||||
return dynamic_cast<LightData *>(object_data(id));
|
||||
}
|
||||
|
||||
MaterialData *BlenderSceneDelegate::material_data(pxr::SdfPath const &id)
|
||||
MaterialData *BlenderSceneDelegate::material_data(pxr::SdfPath const &id) const
|
||||
{
|
||||
auto it = materials_.find(id);
|
||||
if (it == materials_.end()) {
|
||||
@ -219,7 +247,7 @@ MaterialData *BlenderSceneDelegate::material_data(pxr::SdfPath const &id)
|
||||
return it->second.get();
|
||||
}
|
||||
|
||||
InstancerData *BlenderSceneDelegate::instancer_data(pxr::SdfPath const &id)
|
||||
InstancerData *BlenderSceneDelegate::instancer_data(pxr::SdfPath const &id) const
|
||||
{
|
||||
auto it = instancers_.find(id);
|
||||
if (it != instancers_.end()) {
|
||||
@ -233,7 +261,7 @@ void BlenderSceneDelegate::update_objects(Object *object)
|
||||
if (!ObjectData::is_supported(object)) {
|
||||
return;
|
||||
}
|
||||
pxr::SdfPath id = ObjectData::prim_id(this, object);
|
||||
pxr::SdfPath id = object_prim_id(object);
|
||||
ObjectData *obj_data = object_data(id);
|
||||
if (obj_data) {
|
||||
obj_data->update();
|
||||
@ -242,7 +270,7 @@ void BlenderSceneDelegate::update_objects(Object *object)
|
||||
if (view3d_ && !BKE_object_is_visible_in_viewport(view3d_, object)) {
|
||||
return;
|
||||
}
|
||||
objects_[id] = ObjectData::create(this, object);
|
||||
objects_[id] = ObjectData::create(this, object, id);
|
||||
obj_data = object_data(id);
|
||||
obj_data->update_visibility(view3d_);
|
||||
}
|
||||
@ -254,7 +282,7 @@ void BlenderSceneDelegate::update_instancers(Object *object)
|
||||
it.second->check_update(object);
|
||||
}
|
||||
|
||||
pxr::SdfPath id = InstancerData::prim_id(this, object);
|
||||
pxr::SdfPath id = instancer_prim_id(object);
|
||||
InstancerData *i_data = instancer_data(id);
|
||||
if (i_data) {
|
||||
if (object->transflag & OB_DUPLI) {
|
||||
@ -272,7 +300,7 @@ void BlenderSceneDelegate::update_instancers(Object *object)
|
||||
if (view3d_ && !BKE_object_is_visible_in_viewport(view3d_, object)) {
|
||||
return;
|
||||
}
|
||||
instancers_[id] = InstancerData::create(this, object);
|
||||
instancers_[id] = InstancerData::create(this, object, id);
|
||||
i_data = instancer_data(id);
|
||||
i_data->update_visibility(view3d_);
|
||||
}
|
||||
@ -282,7 +310,7 @@ void BlenderSceneDelegate::update_world()
|
||||
World *world = scene_->world;
|
||||
if (!world_data_) {
|
||||
if (world) {
|
||||
world_data_ = WorldData::create(this, world, context_);
|
||||
world_data_ = WorldData::create(this, world, world_prim_id());
|
||||
}
|
||||
}
|
||||
else {
|
||||
@ -343,7 +371,7 @@ void BlenderSceneDelegate::check_updates()
|
||||
} break;
|
||||
|
||||
case ID_MA: {
|
||||
MaterialData *mat_data = material_data(MaterialData::prim_id(this, (Material *)id));
|
||||
MaterialData *mat_data = material_data(material_prim_id((Material *)id));
|
||||
if (mat_data) {
|
||||
mat_data->update();
|
||||
}
|
||||
@ -420,8 +448,8 @@ void BlenderSceneDelegate::remove_unused_objects()
|
||||
if (!ObjectData::is_supported(object)) {
|
||||
continue;
|
||||
}
|
||||
available_objects.insert(ObjectData::prim_id(this, object).GetName());
|
||||
available_objects.insert(InstancerData::prim_id(this, object).GetName());
|
||||
available_objects.insert(object_prim_id(object).GetName());
|
||||
available_objects.insert(instancer_prim_id(object).GetName());
|
||||
}
|
||||
ITER_END;
|
||||
|
||||
@ -501,10 +529,10 @@ void BlenderSceneDelegate::update_visibility()
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!object_data(ObjectData::prim_id(this, object))) {
|
||||
if (!object_data(object_prim_id(object))) {
|
||||
update_objects(object);
|
||||
}
|
||||
if (!instancer_data(InstancerData::prim_id(this, object))) {
|
||||
if (!instancer_data(instancer_prim_id(object))) {
|
||||
update_instancers(object);
|
||||
}
|
||||
}
|
||||
|
@ -52,13 +52,23 @@ class BlenderSceneDelegate : public pxr::HdSceneDelegate {
|
||||
void clear();
|
||||
|
||||
EngineType engine_type;
|
||||
Depsgraph *depsgraph_ = nullptr;
|
||||
bContext *context_ = nullptr;
|
||||
View3D *view3d_ = nullptr;
|
||||
Scene *scene_ = nullptr;
|
||||
|
||||
private:
|
||||
ObjectData *object_data(pxr::SdfPath const &id);
|
||||
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);
|
||||
pxr::SdfPath prim_id(ID *id, const char *prefix) const;
|
||||
pxr::SdfPath object_prim_id(Object *object) const;
|
||||
pxr::SdfPath material_prim_id(Material *mat) const;
|
||||
pxr::SdfPath instancer_prim_id(Object *object) const;
|
||||
pxr::SdfPath world_prim_id() const;
|
||||
|
||||
ObjectData *object_data(pxr::SdfPath const &id) const;
|
||||
MeshData *mesh_data(pxr::SdfPath const &id) const;
|
||||
LightData *light_data(pxr::SdfPath const &id) const;
|
||||
MaterialData *material_data(pxr::SdfPath const &id) const;
|
||||
InstancerData *instancer_data(pxr::SdfPath const &id) const;
|
||||
|
||||
void update_objects(Object *object);
|
||||
void update_instancers(Object *object);
|
||||
@ -68,11 +78,6 @@ class BlenderSceneDelegate : public pxr::HdSceneDelegate {
|
||||
void remove_unused_objects();
|
||||
void update_visibility();
|
||||
|
||||
Depsgraph *depsgraph_ = nullptr;
|
||||
bContext *context_ = nullptr;
|
||||
View3D *view3d_ = nullptr;
|
||||
Scene *scene_ = nullptr;
|
||||
|
||||
ObjectDataMap objects_;
|
||||
MaterialDataMap materials_;
|
||||
InstancerDataMap instancers_;
|
||||
|
@ -3,13 +3,13 @@
|
||||
|
||||
#include "BKE_lib_id.h"
|
||||
|
||||
#include "blender_scene_delegate.h"
|
||||
//#include "blender_scene_delegate.h"
|
||||
#include "id.h"
|
||||
|
||||
namespace blender::render::hydra {
|
||||
|
||||
IdData::IdData(BlenderSceneDelegate *scene_delegate, ID *id)
|
||||
: scene_delegate_(scene_delegate), id_(id)
|
||||
IdData::IdData(BlenderSceneDelegate *scene_delegate, ID *id, pxr::SdfPath const &prim_id)
|
||||
: id_(id), p_id_(prim_id), scene_delegate_(scene_delegate)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -18,7 +18,7 @@ class IdData {
|
||||
friend InstancerData;
|
||||
|
||||
public:
|
||||
IdData(BlenderSceneDelegate *scene_delegate, ID *id);
|
||||
IdData(BlenderSceneDelegate *scene_delegate, ID *id, pxr::SdfPath const &prim_id);
|
||||
virtual ~IdData() = default;
|
||||
|
||||
virtual void init() = 0;
|
||||
@ -29,10 +29,11 @@ class IdData {
|
||||
virtual pxr::VtValue get_data(pxr::TfToken const &key) const;
|
||||
template<class T> const T get_data(pxr::TfToken const &key) const;
|
||||
|
||||
protected:
|
||||
BlenderSceneDelegate *scene_delegate_;
|
||||
ID *id_;
|
||||
pxr::SdfPath p_id_;
|
||||
|
||||
protected:
|
||||
BlenderSceneDelegate *scene_delegate_;
|
||||
};
|
||||
|
||||
template<class T> const T IdData::get_data(pxr::TfToken const &key) const
|
||||
|
@ -9,11 +9,21 @@
|
||||
|
||||
namespace blender::render::hydra {
|
||||
|
||||
InstancerData::InstancerData(BlenderSceneDelegate *scene_delegate, Object *object)
|
||||
: ObjectData(scene_delegate, object)
|
||||
InstancerData::InstancerData(BlenderSceneDelegate *scene_delegate,
|
||||
Object *object,
|
||||
pxr::SdfPath const &prim_id)
|
||||
: ObjectData(scene_delegate, object, prim_id)
|
||||
{
|
||||
p_id_ = prim_id(scene_delegate, object);
|
||||
ID_LOG(2, "");
|
||||
}
|
||||
|
||||
std::unique_ptr<InstancerData> InstancerData::create(BlenderSceneDelegate *scene_delegate,
|
||||
Object *object,
|
||||
pxr::SdfPath const &prim_id)
|
||||
{
|
||||
auto data = std::make_unique<InstancerData>(scene_delegate, object, prim_id);
|
||||
data->init();
|
||||
data->insert();
|
||||
return data;
|
||||
}
|
||||
|
||||
bool InstancerData::is_supported(Object *object)
|
||||
@ -32,24 +42,6 @@ bool InstancerData::is_supported(Object *object)
|
||||
return false;
|
||||
}
|
||||
|
||||
std::unique_ptr<InstancerData> InstancerData::create(BlenderSceneDelegate *scene_delegate,
|
||||
Object *object)
|
||||
{
|
||||
auto data = std::make_unique<InstancerData>(scene_delegate, object);
|
||||
data->init();
|
||||
data->insert();
|
||||
return data;
|
||||
}
|
||||
|
||||
pxr::SdfPath InstancerData::prim_id(BlenderSceneDelegate *scene_delegate, Object *object)
|
||||
{
|
||||
/* Making id of instancer in form like I_<pointer in 16 hex digits format>. Example:
|
||||
* I_000002073e369608 */
|
||||
char str[32];
|
||||
snprintf(str, 32, "I_%016llx", (uint64_t)object);
|
||||
return scene_delegate->GetDelegateID().AppendElementString(str);
|
||||
}
|
||||
|
||||
void InstancerData::init()
|
||||
{
|
||||
ID_LOG(2, "");
|
||||
@ -159,8 +151,7 @@ pxr::SdfPathVector InstancerData::prototypes()
|
||||
|
||||
void InstancerData::check_update(Object *object)
|
||||
{
|
||||
pxr::SdfPath path = ObjectData::prim_id(scene_delegate_, object);
|
||||
path = p_id_.AppendElementString(path.GetName());
|
||||
pxr::SdfPath path = object_prim_id(object);
|
||||
auto it = instances_.find(path);
|
||||
if (it == instances_.end()) {
|
||||
return;
|
||||
@ -207,6 +198,14 @@ void InstancerData::available_materials(std::set<pxr::SdfPath> &paths)
|
||||
}
|
||||
}
|
||||
|
||||
pxr::SdfPath InstancerData::object_prim_id(Object *object) const
|
||||
{
|
||||
/* Making id of object in form like <prefix>_<pointer in 16 hex digits format> */
|
||||
char str[32];
|
||||
snprintf(str, 32, "O_%016llx", (uint64_t)object);
|
||||
return p_id_.AppendElementString(str);
|
||||
}
|
||||
|
||||
void InstancerData::set_instances()
|
||||
{
|
||||
transforms_.clear();
|
||||
@ -219,8 +218,7 @@ void InstancerData::set_instances()
|
||||
|
||||
ListBase *lb = object_duplilist(scene_delegate_->depsgraph_, scene_delegate_->scene_, (Object *)id_);
|
||||
LISTBASE_FOREACH (DupliObject *, dupli, lb) {
|
||||
path = ObjectData::prim_id(scene_delegate_, dupli->ob);
|
||||
path = p_id_.AppendElementString(path.GetName());
|
||||
path = object_prim_id(dupli->ob);
|
||||
auto it = instances_.find(path);
|
||||
if (it == instances_.end()) {
|
||||
inst = &instances_[path];
|
||||
@ -236,7 +234,7 @@ void InstancerData::set_instances()
|
||||
}
|
||||
transforms_.push_back(gf_matrix_from_transform(dupli->mat));
|
||||
inst->indices.push_back(index);
|
||||
ID_LOG(2, "Instance %s %d", inst->obj_data->id_->name, index);
|
||||
ID_LOG(2, "%s %d", inst->obj_data->id_->name, index);
|
||||
++index;
|
||||
}
|
||||
free_object_duplilist(lb);
|
||||
@ -254,10 +252,9 @@ void InstancerData::set_instances()
|
||||
|
||||
InstanceMeshData::InstanceMeshData(BlenderSceneDelegate *scene_delegate,
|
||||
Object *object,
|
||||
pxr::SdfPath const &p_id)
|
||||
: MeshData(scene_delegate, object)
|
||||
pxr::SdfPath const &prim_id)
|
||||
: MeshData(scene_delegate, object, prim_id)
|
||||
{
|
||||
this->p_id_ = p_id;
|
||||
}
|
||||
|
||||
pxr::GfMatrix4d InstanceMeshData::transform()
|
||||
|
@ -18,12 +18,12 @@ class InstancerData : public ObjectData {
|
||||
};
|
||||
|
||||
public:
|
||||
InstancerData(BlenderSceneDelegate *scene_delegate, Object *object);
|
||||
InstancerData(BlenderSceneDelegate *scene_delegate, Object *object, pxr::SdfPath const &prim_id);
|
||||
|
||||
static bool is_supported(Object *object);
|
||||
static std::unique_ptr<InstancerData> create(BlenderSceneDelegate *scene_delegate,
|
||||
Object *object);
|
||||
static pxr::SdfPath prim_id(BlenderSceneDelegate *scene_delegate, Object *object);
|
||||
Object *object,
|
||||
pxr::SdfPath const &prim_id);
|
||||
static bool is_supported(Object *object);
|
||||
|
||||
void init() override;
|
||||
void insert() override;
|
||||
@ -43,6 +43,7 @@ class InstancerData : public ObjectData {
|
||||
void available_materials(std::set<pxr::SdfPath> &paths);
|
||||
|
||||
private:
|
||||
pxr::SdfPath object_prim_id(Object *object) const;
|
||||
void set_instances();
|
||||
|
||||
pxr::TfHashMap<pxr::SdfPath, Instance, pxr::SdfPath::Hash> instances_;
|
||||
@ -54,7 +55,7 @@ using InstancerDataMap =
|
||||
|
||||
class InstanceMeshData : public MeshData {
|
||||
public:
|
||||
InstanceMeshData(BlenderSceneDelegate *scene_delegate, Object *object, pxr::SdfPath const &p_id);
|
||||
InstanceMeshData(BlenderSceneDelegate *scene_delegate, Object *object, pxr::SdfPath const &prim_id);
|
||||
pxr::GfMatrix4d transform() override;
|
||||
};
|
||||
|
||||
|
@ -14,10 +14,11 @@
|
||||
|
||||
namespace blender::render::hydra {
|
||||
|
||||
LightData::LightData(BlenderSceneDelegate *scene_delegate, Object *object)
|
||||
: ObjectData(scene_delegate, object)
|
||||
LightData::LightData(BlenderSceneDelegate *scene_delegate,
|
||||
Object *object,
|
||||
pxr::SdfPath const &prim_id)
|
||||
: ObjectData(scene_delegate, object, prim_id)
|
||||
{
|
||||
ID_LOG(2, "");
|
||||
}
|
||||
|
||||
void LightData::init()
|
||||
@ -87,7 +88,7 @@ void LightData::init()
|
||||
|
||||
void LightData::insert()
|
||||
{
|
||||
CLOG_INFO(LOG_BSD, 2, "%s", id_->name);
|
||||
ID_LOG(2, "");
|
||||
scene_delegate_->GetRenderIndex().InsertSprim(p_type_, scene_delegate_, p_id_);
|
||||
}
|
||||
|
||||
@ -99,7 +100,7 @@ void LightData::remove()
|
||||
|
||||
void LightData::update()
|
||||
{
|
||||
CLOG_INFO(LOG_BSD, 2, "%s", id_->name);
|
||||
ID_LOG(2, "");
|
||||
|
||||
Light *light = (Light *)((Object *)id_)->data;
|
||||
if (prim_type(light) != p_type_) {
|
||||
|
@ -15,7 +15,7 @@ namespace blender::render::hydra {
|
||||
|
||||
class LightData : public ObjectData {
|
||||
public:
|
||||
LightData(BlenderSceneDelegate *scene_delegate, Object *object);
|
||||
LightData(BlenderSceneDelegate *scene_delegate, Object *object, pxr::SdfPath const &prim_id);
|
||||
|
||||
void init() override;
|
||||
void insert() override;
|
||||
|
@ -20,31 +20,23 @@
|
||||
|
||||
namespace blender::render::hydra {
|
||||
|
||||
MaterialData::MaterialData(BlenderSceneDelegate *scene_delegate, Material *material)
|
||||
: IdData(scene_delegate, (ID *)material)
|
||||
MaterialData::MaterialData(BlenderSceneDelegate *scene_delegate,
|
||||
Material *material,
|
||||
pxr::SdfPath const &prim_id)
|
||||
: IdData(scene_delegate, (ID *)material, prim_id)
|
||||
{
|
||||
p_id_ = prim_id(scene_delegate, material);
|
||||
ID_LOG(2, "");
|
||||
}
|
||||
|
||||
std::unique_ptr<MaterialData> MaterialData::create(BlenderSceneDelegate *scene_delegate,
|
||||
Material *material)
|
||||
Material *material,
|
||||
pxr::SdfPath const &prim_id)
|
||||
{
|
||||
auto data = std::make_unique<MaterialData>(scene_delegate, material);
|
||||
auto data = std::make_unique<MaterialData>(scene_delegate, material, prim_id);
|
||||
data->init();
|
||||
data->insert();
|
||||
return data;
|
||||
}
|
||||
|
||||
pxr::SdfPath MaterialData::prim_id(BlenderSceneDelegate *scene_delegate, Material *material)
|
||||
{
|
||||
/* Making id of material in form like M_<pointer in 16 hex digits format>.
|
||||
* Example: M_000002074e812088 */
|
||||
char str[32];
|
||||
snprintf(str, 32, "M_%016llx", (uint64_t)material);
|
||||
return scene_delegate->GetDelegateID().AppendElementString(str);
|
||||
}
|
||||
|
||||
void MaterialData::init()
|
||||
{
|
||||
ID_LOG(2, "");
|
||||
|
@ -19,11 +19,13 @@ class MaterialData : IdData {
|
||||
friend MeshData;
|
||||
|
||||
public:
|
||||
MaterialData(BlenderSceneDelegate *scene_delegate, Material *material);
|
||||
MaterialData(BlenderSceneDelegate *scene_delegate,
|
||||
Material *material,
|
||||
pxr::SdfPath const &prim_id);
|
||||
|
||||
static std::unique_ptr<MaterialData> create(BlenderSceneDelegate *scene_delegate,
|
||||
Material *material);
|
||||
static pxr::SdfPath prim_id(BlenderSceneDelegate *scene_delegate, Material *material);
|
||||
Material *material,
|
||||
pxr::SdfPath const &prim_id);
|
||||
|
||||
void init() override;
|
||||
void insert() override;
|
||||
|
@ -15,15 +15,16 @@
|
||||
|
||||
namespace blender::render::hydra {
|
||||
|
||||
MeshData::MeshData(BlenderSceneDelegate *scene_delegate, Object *object)
|
||||
: ObjectData(scene_delegate, object), mat_data_(nullptr)
|
||||
MeshData::MeshData(BlenderSceneDelegate *scene_delegate,
|
||||
Object *object,
|
||||
pxr::SdfPath const &prim_id)
|
||||
: ObjectData(scene_delegate, object, prim_id)
|
||||
{
|
||||
ID_LOG(2, "");
|
||||
}
|
||||
|
||||
void MeshData::init()
|
||||
{
|
||||
CLOG_INFO(LOG_BSD, 2, "%s", id_->name);
|
||||
ID_LOG(2, "");
|
||||
|
||||
Object *object = (Object *)id_;
|
||||
if (object->type == OB_MESH && object->mode == OB_MODE_OBJECT &&
|
||||
@ -215,10 +216,10 @@ void MeshData::write_material()
|
||||
mat_data_ = nullptr;
|
||||
return;
|
||||
}
|
||||
pxr::SdfPath id = MaterialData::prim_id(scene_delegate_, mat);
|
||||
pxr::SdfPath id = scene_delegate_->material_prim_id(mat);
|
||||
mat_data_ = scene_delegate_->material_data(id);
|
||||
if (!mat_data_) {
|
||||
scene_delegate_->materials_[id] = MaterialData::create(scene_delegate_, mat);
|
||||
scene_delegate_->materials_[id] = MaterialData::create(scene_delegate_, mat, id);
|
||||
mat_data_ = scene_delegate_->material_data(id);
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ namespace blender::render::hydra {
|
||||
|
||||
class MeshData : public ObjectData {
|
||||
public:
|
||||
MeshData(BlenderSceneDelegate *scene_delegate, Object *object);
|
||||
MeshData(BlenderSceneDelegate *scene_delegate, Object *object, pxr::SdfPath const &prim_id);
|
||||
|
||||
void init() override;
|
||||
void insert() override;
|
||||
@ -42,7 +42,7 @@ class MeshData : public ObjectData {
|
||||
pxr::VtVec3fArray normals_;
|
||||
pxr::VtMatrix4dArray instances_;
|
||||
|
||||
MaterialData *mat_data_;
|
||||
MaterialData *mat_data_ = nullptr;
|
||||
};
|
||||
|
||||
} // namespace blender::render::hydra
|
||||
|
@ -11,10 +11,40 @@
|
||||
|
||||
namespace blender::render::hydra {
|
||||
|
||||
ObjectData::ObjectData(BlenderSceneDelegate *scene_delegate, Object *object)
|
||||
: IdData(scene_delegate, (ID *)object), visible(true)
|
||||
ObjectData::ObjectData(BlenderSceneDelegate *scene_delegate,
|
||||
Object *object,
|
||||
pxr::SdfPath const &prim_id)
|
||||
: IdData(scene_delegate, (ID *)object, prim_id), visible(true)
|
||||
{
|
||||
p_id_ = prim_id(scene_delegate, object);
|
||||
}
|
||||
|
||||
std::unique_ptr<ObjectData> ObjectData::create(BlenderSceneDelegate *scene_delegate,
|
||||
Object *object,
|
||||
pxr::SdfPath const &prim_id)
|
||||
{
|
||||
std::unique_ptr<ObjectData> data;
|
||||
|
||||
switch (object->type) {
|
||||
case OB_MESH:
|
||||
case OB_SURF:
|
||||
case OB_FONT:
|
||||
case OB_CURVES_LEGACY:
|
||||
case OB_MBALL:
|
||||
data = std::make_unique<MeshData>(scene_delegate, object, prim_id);
|
||||
break;
|
||||
|
||||
case OB_LAMP:
|
||||
data = std::make_unique<LightData>(scene_delegate, object, prim_id);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (data) {
|
||||
data->init();
|
||||
data->insert();
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
bool ObjectData::is_supported(Object *object)
|
||||
@ -34,43 +64,6 @@ bool ObjectData::is_supported(Object *object)
|
||||
return false;
|
||||
}
|
||||
|
||||
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:
|
||||
case OB_FONT:
|
||||
case OB_CURVES_LEGACY:
|
||||
case OB_MBALL:
|
||||
data = std::make_unique<MeshData>(scene_delegate, object);
|
||||
break;
|
||||
|
||||
case OB_LAMP:
|
||||
data = std::make_unique<LightData>(scene_delegate, object);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (data) {
|
||||
data->init();
|
||||
data->insert();
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
pxr::SdfPath ObjectData::prim_id(BlenderSceneDelegate *scene_delegate, Object *object)
|
||||
{
|
||||
/* Making id of object in form like O_<pointer in 16 hex digits format>. Example:
|
||||
* O_000002073e369608 */
|
||||
char str[32];
|
||||
snprintf(str, 32, "O_%016llx", (uint64_t)object);
|
||||
return scene_delegate->GetDelegateID().AppendElementString(str);
|
||||
}
|
||||
|
||||
pxr::GfMatrix4d ObjectData::transform()
|
||||
{
|
||||
return gf_matrix_from_transform(((Object *)id_)->object_to_world);
|
||||
|
@ -16,11 +16,12 @@ namespace blender::render::hydra {
|
||||
|
||||
class ObjectData : public IdData {
|
||||
public:
|
||||
ObjectData(BlenderSceneDelegate *scene_delegate, Object *object);
|
||||
ObjectData(BlenderSceneDelegate *scene_delegate, Object *object, pxr::SdfPath const &prim_id);
|
||||
|
||||
static std::unique_ptr<ObjectData> create(BlenderSceneDelegate *scene_delegate,
|
||||
Object *object,
|
||||
pxr::SdfPath const &prim_id);
|
||||
static bool is_supported(Object *object);
|
||||
static std::unique_ptr<ObjectData> create(BlenderSceneDelegate *scene_delegate, Object *object);
|
||||
static pxr::SdfPath prim_id(BlenderSceneDelegate *scene_delegate, Object *object);
|
||||
|
||||
virtual pxr::GfMatrix4d transform();
|
||||
virtual bool update_visibility(View3D *view3d);
|
||||
|
@ -28,28 +28,23 @@
|
||||
|
||||
namespace blender::render::hydra {
|
||||
|
||||
WorldData::WorldData(BlenderSceneDelegate *scene_delegate, World *world, bContext *context)
|
||||
: IdData(scene_delegate, (ID *)world), context_(context)
|
||||
WorldData::WorldData(BlenderSceneDelegate *scene_delegate,
|
||||
World *world,
|
||||
pxr::SdfPath const &prim_id)
|
||||
: IdData(scene_delegate, (ID *)world, prim_id)
|
||||
{
|
||||
p_id_ = prim_id(scene_delegate);
|
||||
ID_LOG(2, "");
|
||||
}
|
||||
|
||||
std::unique_ptr<WorldData> WorldData::create(BlenderSceneDelegate *scene_delegate,
|
||||
World *world,
|
||||
bContext *context)
|
||||
pxr::SdfPath const &prim_id)
|
||||
{
|
||||
auto data = std::make_unique<WorldData>(scene_delegate, world, context);
|
||||
auto data = std::make_unique<WorldData>(scene_delegate, world, prim_id);
|
||||
data->init();
|
||||
data->insert();
|
||||
return data;
|
||||
}
|
||||
|
||||
pxr::SdfPath WorldData::prim_id(BlenderSceneDelegate *scene_delegate)
|
||||
{
|
||||
return scene_delegate->GetDelegateID().AppendElementString("World");
|
||||
}
|
||||
|
||||
void WorldData::init()
|
||||
{
|
||||
ID_LOG(2, "");
|
||||
@ -101,8 +96,8 @@ void WorldData::init()
|
||||
Image *image = (Image *)color_input_node->id;
|
||||
|
||||
if (image) {
|
||||
Main *bmain = CTX_data_main(context_);
|
||||
Scene *scene = CTX_data_scene(context_);
|
||||
Main *bmain = CTX_data_main(scene_delegate_->context_);
|
||||
Scene *scene = scene_delegate_->scene_;
|
||||
|
||||
ReportList reports;
|
||||
ImageSaveOptions opts;
|
||||
|
@ -20,12 +20,11 @@ namespace blender::render::hydra {
|
||||
|
||||
class WorldData : public IdData {
|
||||
public:
|
||||
WorldData(BlenderSceneDelegate *scene_delegate, World *world, bContext *context);
|
||||
WorldData(BlenderSceneDelegate *scene_delegate, World *world, pxr::SdfPath const &prim_id);
|
||||
|
||||
static std::unique_ptr<WorldData> create(BlenderSceneDelegate *scene_delegate,
|
||||
World *world,
|
||||
bContext *context);
|
||||
static pxr::SdfPath prim_id(BlenderSceneDelegate *scene_delegate);
|
||||
pxr::SdfPath const &prim_id);
|
||||
|
||||
void init() override;
|
||||
void insert() override;
|
||||
@ -38,7 +37,6 @@ class WorldData : public IdData {
|
||||
|
||||
private:
|
||||
std::map<pxr::TfToken, pxr::VtValue> data_;
|
||||
bContext *context_;
|
||||
};
|
||||
|
||||
} // namespace blender::render::hydra
|
||||
|
Loading…
Reference in New Issue
Block a user