Hydra: add support for legacy hair particles #114197
|
@ -153,20 +153,6 @@ void InstancerData::update_instance(DupliObject *dupli)
|
|||
ID_LOG(2, "Mesh %s %d", m_inst->data->id->name, int(mesh_transforms_.size()));
|
||||
m_inst->indices.push_back(mesh_transforms_.size());
|
||||
mesh_transforms_.push_back(gf_matrix_from_transform(dupli->mat));
|
||||
|
||||
LISTBASE_FOREACH (ParticleSystem *, psys, &object->particlesystem) {
|
||||
if (HairData::is_supported(psys) && HairData::is_visible(scene_delegate_, object, psys)) {
|
||||
pxr::SdfPath h_id = hair_prim_id(p_id, psys);
|
||||
NonmeshInstance *nm_inst = nonmesh_instance(h_id);
|
||||
if (!nm_inst) {
|
||||
nm_inst = &nonmesh_instances_.lookup_or_add_default(h_id);
|
||||
nm_inst->data = std::make_unique<HairData>(scene_delegate_, object, h_id, psys);
|
||||
nm_inst->data->init();
|
||||
}
|
||||
ID_LOG(2, "Nonmesh %s %d", nm_inst->data->id->name, int(nm_inst->transforms.size()));
|
||||
nm_inst->transforms.push_back(gf_matrix_from_transform(dupli->mat));
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
NonmeshInstance *nm_inst = nonmesh_instance(p_id);
|
||||
|
@ -174,9 +160,25 @@ void InstancerData::update_instance(DupliObject *dupli)
|
|||
nm_inst = &nonmesh_instances_.lookup_or_add_default(p_id);
|
||||
nm_inst->data = ObjectData::create(scene_delegate_, object, p_id);
|
||||
}
|
||||
ID_LOG(2, "Light %s %d", nm_inst->data->id->name, int(nm_inst->transforms.size()));
|
||||
ID_LOG(2, "Nonmesh %s %d", nm_inst->data->id->name, int(nm_inst->transforms.size()));
|
||||
nm_inst->transforms.push_back(gf_matrix_from_transform(dupli->mat));
|
||||
}
|
||||
|
||||
LISTBASE_FOREACH (ParticleSystem *, psys, &object->particlesystem) {
|
||||
if (HairData::is_supported(psys) && HairData::is_visible(scene_delegate_, object, psys)) {
|
||||
pxr::SdfPath h_id = hair_prim_id(p_id, psys);
|
||||
NonmeshInstance *nm_inst = nonmesh_instance(h_id);
|
||||
if (!nm_inst) {
|
||||
nm_inst = &nonmesh_instances_.lookup_or_add_default(h_id);
|
||||
nm_inst->data = std::make_unique<HairData>(scene_delegate_, object, h_id, psys);
|
||||
nm_inst->data->init();
|
||||
}
|
||||
ID_LOG(2, "Nonmesh %s %d", nm_inst->data->id->name, int(nm_inst->transforms.size()));
|
||||
auto trans = gf_matrix_from_transform(dupli->mat).ExtractTranslation();
|
||||
nm_inst->transforms.push_back(gf_matrix_from_transform(psys->imat) *
|
||||
gf_matrix_from_transform(dupli->mat));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void InstancerData::post_update()
|
||||
|
@ -230,7 +232,7 @@ pxr::SdfPath InstancerData::hair_prim_id(const pxr::SdfPath parent_obj,
|
|||
{
|
||||
/* Making id of object in form like <prefix>_<pointer in 16 hex digits format> */
|
||||
char name[32];
|
||||
SNPRINTF(name, "PS_%p", psys);
|
||||
SNPRINTF(name, "H_%p", psys);
|
||||
return prim_id.AppendElementString(name);
|
||||
}
|
||||
|
||||
|
@ -254,17 +256,17 @@ void InstancerData::update_nonmesh_instance(NonmeshInstance &nm_inst)
|
|||
pxr::SdfPath prev_id = nm_inst.data->prim_id;
|
||||
int i;
|
||||
|
||||
/* Remove old light instances */
|
||||
/* Remove old Nonmesh instances */
|
||||
while (nm_inst.count > nm_inst.transforms.size()) {
|
||||
--nm_inst.count;
|
||||
obj_data->prim_id = nonmesh_prim_id(prev_id, nm_inst.count);
|
||||
obj_data->remove();
|
||||
}
|
||||
|
||||
/* Update current light instances */
|
||||
/* NOTE: Special case: recreate instances when prim_type was changed.
|
||||
* Doing only update for other Nonmesh objects. */
|
||||
LightData *l_data = dynamic_cast<LightData *>(obj_data);
|
||||
if (l_data && l_data->prim_type((Light *)((Object *)l_data->id)->data) != l_data->prim_type_) {
|
||||
/* Special case: recreate instances when prim_type was changed */
|
||||
for (i = 0; i < nm_inst.count; ++i) {
|
||||
obj_data->prim_id = nonmesh_prim_id(prev_id, i);
|
||||
obj_data->remove();
|
||||
|
@ -282,7 +284,7 @@ void InstancerData::update_nonmesh_instance(NonmeshInstance &nm_inst)
|
|||
}
|
||||
}
|
||||
|
||||
/* Add new light instances */
|
||||
/* Add new Nonmesh instances */
|
||||
while (nm_inst.count < nm_inst.transforms.size()) {
|
||||
obj_data->prim_id = nonmesh_prim_id(prev_id, nm_inst.count);
|
||||
obj_data->insert();
|
||||
|
|
Loading…
Reference in New Issue