forked from blender/blender
Implement instancing for light objects #35
@ -56,7 +56,7 @@ void InstancerData::insert()
|
|||||||
void InstancerData::remove()
|
void InstancerData::remove()
|
||||||
{
|
{
|
||||||
CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 2, "%s", prim_id.GetText());
|
CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 2, "%s", prim_id.GetText());
|
||||||
for (auto &it : instances_) {
|
for (auto &it : mesh_instances_) {
|
||||||
it.second.obj_data->remove();
|
it.second.obj_data->remove();
|
||||||
}
|
}
|
||||||
scene_delegate_->GetRenderIndex().RemoveInstancer(prim_id);
|
scene_delegate_->GetRenderIndex().RemoveInstancer(prim_id);
|
||||||
@ -87,7 +87,7 @@ pxr::VtValue InstancerData::get_data(pxr::TfToken const &key) const
|
|||||||
ID_LOG(3, "%s", key.GetText());
|
ID_LOG(3, "%s", key.GetText());
|
||||||
pxr::VtValue ret;
|
pxr::VtValue ret;
|
||||||
if (key == pxr::HdInstancerTokens->instanceTransform) {
|
if (key == pxr::HdInstancerTokens->instanceTransform) {
|
||||||
ret = transforms_;
|
ret = mesh_transforms_;
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -98,7 +98,7 @@ bool InstancerData::update_visibility()
|
|||||||
if (ret) {
|
if (ret) {
|
||||||
scene_delegate_->GetRenderIndex().GetChangeTracker().MarkInstancerDirty(
|
scene_delegate_->GetRenderIndex().GetChangeTracker().MarkInstancerDirty(
|
||||||
prim_id, pxr::HdChangeTracker::DirtyVisibility);
|
prim_id, pxr::HdChangeTracker::DirtyVisibility);
|
||||||
for (auto &it : instances_) {
|
for (auto &it : mesh_instances_) {
|
||||||
it.second.obj_data->visible = visible;
|
it.second.obj_data->visible = visible;
|
||||||
scene_delegate_->GetRenderIndex().GetChangeTracker().MarkRprimDirty(
|
scene_delegate_->GetRenderIndex().GetChangeTracker().MarkRprimDirty(
|
||||||
it.second.obj_data->prim_id, pxr::HdChangeTracker::DirtyVisibility);
|
it.second.obj_data->prim_id, pxr::HdChangeTracker::DirtyVisibility);
|
||||||
@ -120,18 +120,18 @@ pxr::HdPrimvarDescriptorVector InstancerData::primvar_descriptors(
|
|||||||
|
|
||||||
pxr::VtIntArray InstancerData::indices(pxr::SdfPath const &id) const
|
pxr::VtIntArray InstancerData::indices(pxr::SdfPath const &id) const
|
||||||
{
|
{
|
||||||
return instances_.find(id)->second.indices;
|
return mesh_instances_.find(id)->second.indices;
|
||||||
}
|
}
|
||||||
|
|
||||||
ObjectData *InstancerData::object_data(pxr::SdfPath const &id) const
|
ObjectData *InstancerData::object_data(pxr::SdfPath const &id) const
|
||||||
{
|
{
|
||||||
return instances_.find(id)->second.obj_data.get();
|
return mesh_instances_.find(id)->second.obj_data.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
pxr::SdfPathVector InstancerData::prototypes() const
|
pxr::SdfPathVector InstancerData::prototypes() const
|
||||||
{
|
{
|
||||||
pxr::SdfPathVector paths;
|
pxr::SdfPathVector paths;
|
||||||
for (auto &it : instances_) {
|
for (auto &it : mesh_instances_) {
|
||||||
paths.push_back(it.first);
|
paths.push_back(it.first);
|
||||||
}
|
}
|
||||||
return paths;
|
return paths;
|
||||||
@ -140,8 +140,8 @@ pxr::SdfPathVector InstancerData::prototypes() const
|
|||||||
void InstancerData::check_update(Object *object)
|
void InstancerData::check_update(Object *object)
|
||||||
{
|
{
|
||||||
pxr::SdfPath path = object_prim_id(object);
|
pxr::SdfPath path = object_prim_id(object);
|
||||||
auto it = instances_.find(path);
|
auto it = mesh_instances_.find(path);
|
||||||
if (it == instances_.end()) {
|
if (it == mesh_instances_.end()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ObjectData *obj_data = it->second.obj_data.get();
|
ObjectData *obj_data = it->second.obj_data.get();
|
||||||
@ -161,13 +161,13 @@ void InstancerData::check_update(Object *object)
|
|||||||
void InstancerData::check_remove(std::set<std::string> &available_objects)
|
void InstancerData::check_remove(std::set<std::string> &available_objects)
|
||||||
{
|
{
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
for (auto it = instances_.begin(); it != instances_.end(); ++it) {
|
for (auto it = mesh_instances_.begin(); it != mesh_instances_.end(); ++it) {
|
||||||
if (available_objects.find(it->first.GetName()) != available_objects.end()) {
|
if (available_objects.find(it->first.GetName()) != available_objects.end()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
it->second.obj_data->remove();
|
it->second.obj_data->remove();
|
||||||
instances_.erase(it);
|
mesh_instances_.erase(it);
|
||||||
it = instances_.begin();
|
it = mesh_instances_.begin();
|
||||||
ret = true;
|
ret = true;
|
||||||
}
|
}
|
||||||
if (ret) {
|
if (ret) {
|
||||||
@ -179,7 +179,7 @@ void InstancerData::check_remove(std::set<std::string> &available_objects)
|
|||||||
|
|
||||||
void InstancerData::available_materials(std::set<pxr::SdfPath> &paths) const
|
void InstancerData::available_materials(std::set<pxr::SdfPath> &paths) const
|
||||||
{
|
{
|
||||||
for (auto &it : instances_) {
|
for (auto &it : mesh_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();
|
||||||
if (!mat_id.IsEmpty()) {
|
if (!mat_id.IsEmpty()) {
|
||||||
paths.insert(mat_id);
|
paths.insert(mat_id);
|
||||||
@ -204,8 +204,8 @@ pxr::SdfPath InstancerData::object_prim_id(Object *object) const
|
|||||||
|
|
||||||
void InstancerData::set_instances()
|
void InstancerData::set_instances()
|
||||||
{
|
{
|
||||||
transforms_.clear();
|
mesh_transforms_.clear();
|
||||||
for (auto &it : instances_) {
|
for (auto &it : mesh_instances_) {
|
||||||
it.second.indices.clear();
|
it.second.indices.clear();
|
||||||
}
|
}
|
||||||
int index = 0;
|
int index = 0;
|
||||||
@ -216,9 +216,9 @@ void InstancerData::set_instances()
|
|||||||
scene_delegate_->depsgraph, scene_delegate_->scene, (Object *)id);
|
scene_delegate_->depsgraph, scene_delegate_->scene, (Object *)id);
|
||||||
LISTBASE_FOREACH (DupliObject *, dupli, lb) {
|
LISTBASE_FOREACH (DupliObject *, dupli, lb) {
|
||||||
p_id = object_prim_id(dupli->ob);
|
p_id = object_prim_id(dupli->ob);
|
||||||
auto it = instances_.find(p_id);
|
auto it = mesh_instances_.find(p_id);
|
||||||
if (it == instances_.end()) {
|
if (it == mesh_instances_.end()) {
|
||||||
inst = &instances_[p_id];
|
inst = &mesh_instances_[p_id];
|
||||||
if (!is_supported(dupli->ob)) {
|
if (!is_supported(dupli->ob)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -230,7 +230,7 @@ void InstancerData::set_instances()
|
|||||||
else {
|
else {
|
||||||
inst = &it->second;
|
inst = &it->second;
|
||||||
}
|
}
|
||||||
transforms_.push_back(gf_matrix_from_transform(dupli->mat));
|
mesh_transforms_.push_back(gf_matrix_from_transform(dupli->mat));
|
||||||
inst->indices.push_back(index);
|
inst->indices.push_back(index);
|
||||||
ID_LOG(2, "%s %d", inst->obj_data->id->name, index);
|
ID_LOG(2, "%s %d", inst->obj_data->id->name, index);
|
||||||
++index;
|
++index;
|
||||||
@ -238,13 +238,13 @@ void InstancerData::set_instances()
|
|||||||
free_object_duplilist(lb);
|
free_object_duplilist(lb);
|
||||||
|
|
||||||
/* Remove intances without indices */
|
/* Remove intances without indices */
|
||||||
for (auto it = instances_.begin(); it != instances_.end(); ++it) {
|
for (auto it = mesh_instances_.begin(); it != mesh_instances_.end(); ++it) {
|
||||||
if (!it->second.indices.empty()) {
|
if (!it->second.indices.empty()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
it->second.obj_data->remove();
|
it->second.obj_data->remove();
|
||||||
instances_.erase(it);
|
mesh_instances_.erase(it);
|
||||||
it = instances_.begin();
|
it = mesh_instances_.begin();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,8 +44,10 @@ class InstancerData : public ObjectData {
|
|||||||
pxr::SdfPath object_prim_id(Object *object) const;
|
pxr::SdfPath object_prim_id(Object *object) const;
|
||||||
void set_instances();
|
void set_instances();
|
||||||
|
|
||||||
pxr::TfHashMap<pxr::SdfPath, Instance, pxr::SdfPath::Hash> instances_;
|
pxr::TfHashMap<pxr::SdfPath, Instance, pxr::SdfPath::Hash> mesh_instances_;
|
||||||
pxr::VtMatrix4dArray transforms_;
|
pxr::TfHashMap<pxr::SdfPath, Instance, pxr::SdfPath::Hash> light_instances_;
|
||||||
|
pxr::VtMatrix4dArray mesh_transforms_;
|
||||||
|
pxr::VtMatrix4dArray light_transforms_;
|
||||||
};
|
};
|
||||||
|
|
||||||
using InstancerDataMap =
|
using InstancerDataMap =
|
||||||
|
@ -126,9 +126,6 @@ pxr::VtValue MeshData::get_data(pxr::TfToken const &key) const
|
|||||||
else if (key == pxr::HdPrimvarRoleTokens->textureCoordinate) {
|
else if (key == pxr::HdPrimvarRoleTokens->textureCoordinate) {
|
||||||
ret = uvs_;
|
ret = uvs_;
|
||||||
}
|
}
|
||||||
else if (key == pxr::HdInstancerTokens->instanceTransform) {
|
|
||||||
ret = instances_;
|
|
||||||
}
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,7 +40,6 @@ class MeshData : public ObjectData {
|
|||||||
pxr::VtVec3fArray vertices_;
|
pxr::VtVec3fArray vertices_;
|
||||||
pxr::VtVec2fArray uvs_;
|
pxr::VtVec2fArray uvs_;
|
||||||
pxr::VtVec3fArray normals_;
|
pxr::VtVec3fArray normals_;
|
||||||
pxr::VtMatrix4dArray instances_;
|
|
||||||
|
|
||||||
MaterialData *mat_data_ = nullptr;
|
MaterialData *mat_data_ = nullptr;
|
||||||
Object *parent_;
|
Object *parent_;
|
||||||
|
Loading…
Reference in New Issue
Block a user