forked from blender/blender
Code improvements and fixes #26
@ -116,7 +116,7 @@ bool InstancerData::update_visibility()
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
pxr::HdPrimvarDescriptorVector InstancerData::primvar_descriptors(pxr::HdInterpolation interpolation)
|
pxr::HdPrimvarDescriptorVector InstancerData::primvar_descriptors(pxr::HdInterpolation interpolation) const
|
||||||
{
|
{
|
||||||
pxr::HdPrimvarDescriptorVector primvars;
|
pxr::HdPrimvarDescriptorVector primvars;
|
||||||
if (interpolation == pxr::HdInterpolationInstance) {
|
if (interpolation == pxr::HdInterpolationInstance) {
|
||||||
@ -126,17 +126,17 @@ pxr::HdPrimvarDescriptorVector InstancerData::primvar_descriptors(pxr::HdInterpo
|
|||||||
return primvars;
|
return primvars;
|
||||||
}
|
}
|
||||||
|
|
||||||
pxr::VtIntArray InstancerData::indices(pxr::SdfPath const &id)
|
pxr::VtIntArray InstancerData::indices(pxr::SdfPath const &id) const
|
||||||
{
|
{
|
||||||
return instances_[id].indices;
|
return instances_.find(id)->second.indices;
|
||||||
}
|
}
|
||||||
|
|
||||||
ObjectData *InstancerData::object_data(pxr::SdfPath const &id)
|
ObjectData *InstancerData::object_data(pxr::SdfPath const &id) const
|
||||||
{
|
{
|
||||||
return instances_[id].obj_data.get();
|
return instances_.find(id)->second.obj_data.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
pxr::SdfPathVector InstancerData::prototypes()
|
pxr::SdfPathVector InstancerData::prototypes() const
|
||||||
{
|
{
|
||||||
pxr::SdfPathVector paths;
|
pxr::SdfPathVector paths;
|
||||||
for (auto &it : instances_) {
|
for (auto &it : instances_) {
|
||||||
@ -184,7 +184,7 @@ void InstancerData::check_remove(std::set<std::string> &available_objects)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void InstancerData::available_materials(std::set<pxr::SdfPath> &paths)
|
void InstancerData::available_materials(std::set<pxr::SdfPath> &paths) const
|
||||||
{
|
{
|
||||||
for (auto &it : instances_) {
|
for (auto &it : instances_) {
|
||||||
pxr::SdfPath mat_id = ((MeshData *)it.second.obj_data.get())->material_id();
|
pxr::SdfPath mat_id = ((MeshData *)it.second.obj_data.get())->material_id();
|
||||||
|
@ -32,13 +32,13 @@ class InstancerData : public ObjectData {
|
|||||||
pxr::GfMatrix4d transform() override;
|
pxr::GfMatrix4d transform() override;
|
||||||
bool update_visibility() override;
|
bool update_visibility() override;
|
||||||
|
|
||||||
pxr::HdPrimvarDescriptorVector primvar_descriptors(pxr::HdInterpolation interpolation);
|
pxr::HdPrimvarDescriptorVector primvar_descriptors(pxr::HdInterpolation interpolation) const;
|
||||||
pxr::VtIntArray indices(pxr::SdfPath const &id);
|
pxr::VtIntArray indices(pxr::SdfPath const &id) const;
|
||||||
ObjectData *object_data(pxr::SdfPath const &id);
|
ObjectData *object_data(pxr::SdfPath const &id) const;
|
||||||
pxr::SdfPathVector prototypes();
|
pxr::SdfPathVector prototypes() const;
|
||||||
void check_update(Object *object);
|
void check_update(Object *object);
|
||||||
void check_remove(std::set<std::string> &available_objects);
|
void check_remove(std::set<std::string> &available_objects);
|
||||||
void available_materials(std::set<pxr::SdfPath> &paths);
|
void available_materials(std::set<pxr::SdfPath> &paths) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
pxr::SdfPath object_prim_id(Object *object) const;
|
pxr::SdfPath object_prim_id(Object *object) const;
|
||||||
|
@ -94,7 +94,7 @@ void LightData::insert()
|
|||||||
|
|
||||||
void LightData::remove()
|
void LightData::remove()
|
||||||
{
|
{
|
||||||
CLOG_INFO(LOG_BSD, 2, "%s", id->name);
|
CLOG_INFO(LOG_BSD, 2, "%s", prim_id.GetText());
|
||||||
scene_delegate_->GetRenderIndex().RemoveSprim(p_type_, prim_id);
|
scene_delegate_->GetRenderIndex().RemoveSprim(p_type_, prim_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,24 +77,39 @@ void MaterialData::init()
|
|||||||
|
|
||||||
mtlx_path_ = pxr::SdfAssetPath(path, path);
|
mtlx_path_ = pxr::SdfAssetPath(path, path);
|
||||||
ID_LOG(2, "mtlx=%s", mtlx_path_.GetResolvedPath().c_str());
|
ID_LOG(2, "mtlx=%s", mtlx_path_.GetResolvedPath().c_str());
|
||||||
|
|
||||||
|
/* Calculate material network map */
|
||||||
|
if (!path.empty()) {
|
||||||
|
pxr::HdRenderDelegate *render_delegate = scene_delegate_->GetRenderIndex().GetRenderDelegate();
|
||||||
|
pxr::TfTokenVector shader_source_types = render_delegate->GetShaderSourceTypes();
|
||||||
|
pxr::TfTokenVector render_contexts = render_delegate->GetMaterialRenderContexts();
|
||||||
|
|
||||||
|
pxr::HdMaterialNetworkMap network_map;
|
||||||
|
hdmtlx_convert_to_materialnetworkmap(path, shader_source_types, render_contexts, &network_map);
|
||||||
|
|
||||||
|
material_network_map_ = network_map;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
material_network_map_ = pxr::VtValue();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MaterialData::insert()
|
void MaterialData::insert()
|
||||||
{
|
{
|
||||||
CLOG_INFO(LOG_BSD, 2, "%s", id->name);
|
ID_LOG(2, "");
|
||||||
scene_delegate_->GetRenderIndex().InsertSprim(
|
scene_delegate_->GetRenderIndex().InsertSprim(
|
||||||
pxr::HdPrimTypeTokens->material, scene_delegate_, prim_id);
|
pxr::HdPrimTypeTokens->material, scene_delegate_, prim_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MaterialData::remove()
|
void MaterialData::remove()
|
||||||
{
|
{
|
||||||
CLOG_INFO(LOG_BSD, 2, "%s", id->name);
|
CLOG_INFO(LOG_BSD, 2, "%s", prim_id.GetText());
|
||||||
scene_delegate_->GetRenderIndex().RemoveSprim(pxr::HdPrimTypeTokens->material, prim_id);
|
scene_delegate_->GetRenderIndex().RemoveSprim(pxr::HdPrimTypeTokens->material, prim_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MaterialData::update()
|
void MaterialData::update()
|
||||||
{
|
{
|
||||||
CLOG_INFO(LOG_BSD, 2, "%s", id->name);
|
ID_LOG(2, "");
|
||||||
init();
|
init();
|
||||||
scene_delegate_->GetRenderIndex().GetChangeTracker().MarkSprimDirty(prim_id,
|
scene_delegate_->GetRenderIndex().GetChangeTracker().MarkSprimDirty(prim_id,
|
||||||
pxr::HdMaterial::AllDirty);
|
pxr::HdMaterial::AllDirty);
|
||||||
@ -112,23 +127,8 @@ pxr::VtValue MaterialData::get_data(pxr::TfToken const &key) const
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
pxr::VtValue MaterialData::get_material_resource()
|
pxr::VtValue MaterialData::get_material_resource() const
|
||||||
{
|
{
|
||||||
if (material_network_map_.IsEmpty()) {
|
|
||||||
const std::string &path = mtlx_path_.GetResolvedPath();
|
|
||||||
if (!path.empty()) {
|
|
||||||
pxr::HdRenderDelegate *render_delegate =
|
|
||||||
scene_delegate_->GetRenderIndex().GetRenderDelegate();
|
|
||||||
pxr::TfTokenVector shader_source_types = render_delegate->GetShaderSourceTypes();
|
|
||||||
pxr::TfTokenVector render_contexts = render_delegate->GetMaterialRenderContexts();
|
|
||||||
|
|
||||||
pxr::HdMaterialNetworkMap network_map;
|
|
||||||
hdmtlx_convert_to_materialnetworkmap(
|
|
||||||
path, shader_source_types, render_contexts, &network_map);
|
|
||||||
|
|
||||||
material_network_map_ = network_map;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return material_network_map_;
|
return material_network_map_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ class MaterialData : public IdData {
|
|||||||
void update() override;
|
void update() override;
|
||||||
|
|
||||||
pxr::VtValue get_data(pxr::TfToken const &key) const override;
|
pxr::VtValue get_data(pxr::TfToken const &key) const override;
|
||||||
pxr::VtValue get_material_resource();
|
pxr::VtValue get_material_resource() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
pxr::SdfAssetPath mtlx_path_;
|
pxr::SdfAssetPath mtlx_path_;
|
||||||
|
@ -48,7 +48,7 @@ void MeshData::insert()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
CLOG_INFO(LOG_BSD, 2, "%s", id->name);
|
ID_LOG(2, "");
|
||||||
scene_delegate_->GetRenderIndex().InsertRprim(
|
scene_delegate_->GetRenderIndex().InsertRprim(
|
||||||
pxr::HdPrimTypeTokens->mesh, scene_delegate_, prim_id);
|
pxr::HdPrimTypeTokens->mesh, scene_delegate_, prim_id);
|
||||||
}
|
}
|
||||||
@ -59,7 +59,7 @@ void MeshData::remove()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
CLOG_INFO(LOG_BSD, 2, "%s", id->name);
|
CLOG_INFO(LOG_BSD, 2, "%s", prim_id.GetText());
|
||||||
scene_delegate_->GetRenderIndex().RemoveRprim(prim_id);
|
scene_delegate_->GetRenderIndex().RemoveRprim(prim_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,7 +95,7 @@ void MeshData::update()
|
|||||||
remove();
|
remove();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
CLOG_INFO(LOG_BSD, 2, "%s", id->name);
|
ID_LOG(2, "");
|
||||||
scene_delegate_->GetRenderIndex().GetChangeTracker().MarkRprimDirty(prim_id, bits);
|
scene_delegate_->GetRenderIndex().GetChangeTracker().MarkRprimDirty(prim_id, bits);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -127,7 +127,7 @@ bool MeshData::update_visibility()
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
pxr::HdMeshTopology MeshData::mesh_topology()
|
pxr::HdMeshTopology MeshData::mesh_topology() const
|
||||||
{
|
{
|
||||||
return pxr::HdMeshTopology(pxr::PxOsdOpenSubdivTokens->none,
|
return pxr::HdMeshTopology(pxr::PxOsdOpenSubdivTokens->none,
|
||||||
pxr::HdTokens->rightHanded,
|
pxr::HdTokens->rightHanded,
|
||||||
@ -135,7 +135,7 @@ pxr::HdMeshTopology MeshData::mesh_topology()
|
|||||||
face_vertex_indices_);
|
face_vertex_indices_);
|
||||||
}
|
}
|
||||||
|
|
||||||
pxr::HdPrimvarDescriptorVector MeshData::primvar_descriptors(pxr::HdInterpolation interpolation)
|
pxr::HdPrimvarDescriptorVector MeshData::primvar_descriptors(pxr::HdInterpolation interpolation) const
|
||||||
{
|
{
|
||||||
pxr::HdPrimvarDescriptorVector primvars;
|
pxr::HdPrimvarDescriptorVector primvars;
|
||||||
if (interpolation == pxr::HdInterpolationVertex) {
|
if (interpolation == pxr::HdInterpolationVertex) {
|
||||||
@ -157,7 +157,7 @@ pxr::HdPrimvarDescriptorVector MeshData::primvar_descriptors(pxr::HdInterpolatio
|
|||||||
return primvars;
|
return primvars;
|
||||||
}
|
}
|
||||||
|
|
||||||
pxr::SdfPath MeshData::material_id()
|
pxr::SdfPath MeshData::material_id() const
|
||||||
{
|
{
|
||||||
if (!mat_data_) {
|
if (!mat_data_) {
|
||||||
return pxr::SdfPath();
|
return pxr::SdfPath();
|
||||||
@ -216,11 +216,11 @@ void MeshData::write_material()
|
|||||||
mat_data_ = nullptr;
|
mat_data_ = nullptr;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
pxr::SdfPath id = scene_delegate_->material_prim_id(mat);
|
pxr::SdfPath p_id = scene_delegate_->material_prim_id(mat);
|
||||||
mat_data_ = scene_delegate_->material_data(id);
|
mat_data_ = scene_delegate_->material_data(p_id);
|
||||||
if (!mat_data_) {
|
if (!mat_data_) {
|
||||||
scene_delegate_->materials_[id] = MaterialData::create(scene_delegate_, mat, id);
|
scene_delegate_->materials_[p_id] = MaterialData::create(scene_delegate_, mat, p_id);
|
||||||
mat_data_ = scene_delegate_->material_data(id);
|
mat_data_ = scene_delegate_->material_data(p_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,9 +25,9 @@ class MeshData : public ObjectData {
|
|||||||
pxr::VtValue get_data(pxr::TfToken const &key) const override;
|
pxr::VtValue get_data(pxr::TfToken const &key) const override;
|
||||||
bool update_visibility() override;
|
bool update_visibility() override;
|
||||||
|
|
||||||
pxr::HdMeshTopology mesh_topology();
|
pxr::HdMeshTopology mesh_topology() const;
|
||||||
pxr::HdPrimvarDescriptorVector primvar_descriptors(pxr::HdInterpolation interpolation);
|
pxr::HdPrimvarDescriptorVector primvar_descriptors(pxr::HdInterpolation interpolation) const;
|
||||||
pxr::SdfPath material_id();
|
pxr::SdfPath material_id() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void write_mesh(Mesh *mesh);
|
void write_mesh(Mesh *mesh);
|
||||||
|
@ -127,7 +127,7 @@ void WorldData::insert()
|
|||||||
|
|
||||||
void WorldData::remove()
|
void WorldData::remove()
|
||||||
{
|
{
|
||||||
CLOG_INFO(LOG_BSD, 2, "%s", id->name);
|
CLOG_INFO(LOG_BSD, 2, "%s", prim_id.GetText());
|
||||||
scene_delegate_->GetRenderIndex().RemoveSprim(pxr::HdPrimTypeTokens->domeLight, prim_id);
|
scene_delegate_->GetRenderIndex().RemoveSprim(pxr::HdPrimTypeTokens->domeLight, prim_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user