forked from blender/blender
Refactor code after PR #57 #67
@ -470,7 +470,6 @@ void BlenderSceneDelegate::update_collection()
|
||||
}
|
||||
else {
|
||||
obj_data = objects_.lookup_or_add(id, ObjectData::create(this, object, id)).get();
|
||||
obj_data->init();
|
||||
obj_data->insert();
|
||||
}
|
||||
}
|
||||
|
@ -28,10 +28,7 @@ extern struct CLG_LogRef *LOG_RENDER_HYDRA_SCENE;
|
||||
class Engine;
|
||||
|
||||
class BlenderSceneDelegate : public pxr::HdSceneDelegate {
|
||||
friend ObjectData; /* has access to instances */
|
||||
friend CurvesData; /* has access to materials */
|
||||
friend VolumeData; /* has access to materials */
|
||||
friend MeshData; /* has access to materials */
|
||||
friend ObjectData; /* has access to materials */
|
||||
friend MaterialData; /* has access to objects and instancers */
|
||||
|
||||
public:
|
||||
|
@ -134,20 +134,7 @@ void CurvesData::write_materials()
|
||||
if (BKE_object_material_count_eval(object) > 0) {
|
||||
mat = BKE_object_material_get_eval(object, 0);
|
||||
}
|
||||
|
||||
if (!mat) {
|
||||
mat_data_ = nullptr;
|
||||
return;
|
||||
}
|
||||
pxr::SdfPath p_id = scene_delegate_->material_prim_id(mat);
|
||||
mat_data_ = scene_delegate_->material_data(p_id);
|
||||
if (!mat_data_) {
|
||||
scene_delegate_->materials_.add_new(
|
||||
p_id, std::make_unique<MaterialData>(scene_delegate_, mat, p_id));
|
||||
mat_data_ = scene_delegate_->material_data(p_id);
|
||||
mat_data_->init();
|
||||
mat_data_->insert();
|
||||
}
|
||||
mat_data_ = get_or_create_material(mat);
|
||||
}
|
||||
|
||||
void CurvesData::write_curves(Curves *curves)
|
||||
|
@ -195,21 +195,7 @@ void MeshData::write_materials()
|
||||
for (int i = 0; i < submeshes_.size(); ++i) {
|
||||
SubMesh &m = submeshes_[i];
|
||||
Material *mat = BKE_object_material_get_eval(object, m.mat_index + 1);
|
||||
if (!mat) {
|
||||
m.mat_data = nullptr;
|
||||
continue;
|
||||
}
|
||||
|
||||
pxr::SdfPath p_id = scene_delegate_->material_prim_id(mat);
|
||||
m.mat_data = scene_delegate_->material_data(p_id);
|
||||
if (!m.mat_data) {
|
||||
m.mat_data = scene_delegate_->materials_
|
||||
.lookup_or_add(p_id,
|
||||
std::make_unique<MaterialData>(scene_delegate_, mat, p_id))
|
||||
.get();
|
||||
m.mat_data->init();
|
||||
m.mat_data->insert();
|
||||
}
|
||||
m.mat_data = get_or_create_material(mat);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -23,7 +23,7 @@ std::unique_ptr<ObjectData> ObjectData::create(BlenderSceneDelegate *scene_deleg
|
||||
Object *object,
|
||||
pxr::SdfPath const &prim_id)
|
||||
{
|
||||
std::unique_ptr<ObjectData> data;
|
||||
std::unique_ptr<ObjectData> obj_data;
|
||||
|
||||
switch (object->type) {
|
||||
case OB_MESH:
|
||||
@ -31,22 +31,23 @@ std::unique_ptr<ObjectData> ObjectData::create(BlenderSceneDelegate *scene_deleg
|
||||
case OB_FONT:
|
||||
case OB_CURVES_LEGACY:
|
||||
case OB_MBALL:
|
||||
data = std::make_unique<MeshData>(scene_delegate, object, prim_id);
|
||||
obj_data = std::make_unique<MeshData>(scene_delegate, object, prim_id);
|
||||
break;
|
||||
case OB_CURVES:
|
||||
data = std::make_unique<CurvesData>(scene_delegate, object, prim_id);
|
||||
obj_data = std::make_unique<CurvesData>(scene_delegate, object, prim_id);
|
||||
break;
|
||||
case OB_LAMP:
|
||||
data = std::make_unique<LightData>(scene_delegate, object, prim_id);
|
||||
obj_data = std::make_unique<LightData>(scene_delegate, object, prim_id);
|
||||
break;
|
||||
case OB_VOLUME:
|
||||
data = std::make_unique<VolumeData>(scene_delegate, object, prim_id);
|
||||
obj_data = std::make_unique<VolumeData>(scene_delegate, object, prim_id);
|
||||
break;
|
||||
default:
|
||||
BLI_assert_unreachable();
|
||||
break;
|
||||
}
|
||||
return data;
|
||||
obj_data->init();
|
||||
return obj_data;
|
||||
}
|
||||
|
||||
bool ObjectData::is_supported(Object *object)
|
||||
@ -103,6 +104,24 @@ void ObjectData::write_transform()
|
||||
|
||||
void ObjectData::write_materials() {}
|
||||
|
||||
MaterialData *ObjectData::get_or_create_material(Material *mat)
|
||||
{
|
||||
if (!mat) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
pxr::SdfPath p_id = scene_delegate_->material_prim_id(mat);
|
||||
MaterialData *mat_data = scene_delegate_->material_data(p_id);
|
||||
if (!mat_data) {
|
||||
scene_delegate_->materials_.add_new(
|
||||
p_id, std::make_unique<MaterialData>(scene_delegate_, mat, p_id));
|
||||
mat_data = scene_delegate_->material_data(p_id);
|
||||
mat_data->init();
|
||||
mat_data->insert();
|
||||
}
|
||||
return mat_data;
|
||||
}
|
||||
|
||||
pxr::GfMatrix4d gf_matrix_from_transform(float m[4][4])
|
||||
{
|
||||
pxr::GfMatrix4d ret;
|
||||
|
@ -41,6 +41,7 @@ class ObjectData : public IdData {
|
||||
protected:
|
||||
virtual void write_transform();
|
||||
virtual void write_materials();
|
||||
MaterialData *get_or_create_material(Material *mat);
|
||||
};
|
||||
|
||||
using ObjectDataMap = Map<pxr::SdfPath, std::unique_ptr<ObjectData>>;
|
||||
|
@ -149,20 +149,7 @@ void VolumeData::write_materials()
|
||||
if (BKE_object_material_count_eval(object) > 0) {
|
||||
mat = BKE_object_material_get_eval(object, 0);
|
||||
}
|
||||
|
||||
if (!mat) {
|
||||
mat_data_ = nullptr;
|
||||
return;
|
||||
}
|
||||
pxr::SdfPath p_id = scene_delegate_->material_prim_id(mat);
|
||||
mat_data_ = scene_delegate_->material_data(p_id);
|
||||
if (!mat_data_) {
|
||||
scene_delegate_->materials_.add_new(
|
||||
p_id, std::make_unique<MaterialData>(scene_delegate_, mat, p_id));
|
||||
mat_data_ = scene_delegate_->material_data(p_id);
|
||||
mat_data_->init();
|
||||
mat_data_->insert();
|
||||
}
|
||||
mat_data_ = get_or_create_material(mat);
|
||||
}
|
||||
|
||||
} // namespace blender::render::hydra
|
||||
|
Loading…
Reference in New Issue
Block a user