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