Fix: USD & Alembic importers might not initialize material indices
f1c0249f34
incorrectly assumed that the importer functions that
assigned material indices set all of the values, but that isn't true
for all files.
This commit is contained in:
parent
bd1ff201b1
commit
97f4e076c7
Notes:
blender-bot
2023-04-04 07:45:26 +02:00
Referenced by issue #101886, adding a second material to an imported usdc animation causes immediate crash of blender.
|
@ -763,7 +763,7 @@ Mesh *AbcMeshReader::read_mesh(Mesh *existing_mesh,
|
|||
std::map<std::string, int> mat_map;
|
||||
bke::MutableAttributeAccessor attributes = new_mesh->attributes_for_write();
|
||||
bke::SpanAttributeWriter<int> material_indices =
|
||||
attributes.lookup_or_add_for_write_only_span<int>("material_index", ATTR_DOMAIN_FACE);
|
||||
attributes.lookup_or_add_for_write_span<int>("material_index", ATTR_DOMAIN_FACE);
|
||||
assign_facesets_to_material_indices(sample_sel, material_indices.span, mat_map);
|
||||
material_indices.finish();
|
||||
}
|
||||
|
@ -823,8 +823,8 @@ void AbcMeshReader::readFaceSetsSample(Main *bmain, Mesh *mesh, const ISampleSel
|
|||
{
|
||||
std::map<std::string, int> mat_map;
|
||||
bke::MutableAttributeAccessor attributes = mesh->attributes_for_write();
|
||||
bke::SpanAttributeWriter<int> material_indices =
|
||||
attributes.lookup_or_add_for_write_only_span<int>("material_index", ATTR_DOMAIN_FACE);
|
||||
bke::SpanAttributeWriter<int> material_indices = attributes.lookup_or_add_for_write_span<int>(
|
||||
"material_index", ATTR_DOMAIN_FACE);
|
||||
assign_facesets_to_material_indices(sample_sel, material_indices.span, mat_map);
|
||||
material_indices.finish();
|
||||
utils::assign_materials(bmain, m_object, mat_map);
|
||||
|
|
|
@ -804,8 +804,8 @@ void USDMeshReader::readFaceSetsSample(Main *bmain, Mesh *mesh, const double mot
|
|||
std::map<pxr::SdfPath, int> mat_map;
|
||||
|
||||
bke::MutableAttributeAccessor attributes = mesh->attributes_for_write();
|
||||
bke::SpanAttributeWriter<int> material_indices =
|
||||
attributes.lookup_or_add_for_write_only_span<int>("material_index", ATTR_DOMAIN_FACE);
|
||||
bke::SpanAttributeWriter<int> material_indices = attributes.lookup_or_add_for_write_span<int>(
|
||||
"material_index", ATTR_DOMAIN_FACE);
|
||||
this->assign_facesets_to_material_indices(motionSampleTime, material_indices.span, &mat_map);
|
||||
material_indices.finish();
|
||||
/* Build material name map if it's not built yet. */
|
||||
|
@ -914,7 +914,7 @@ Mesh *USDMeshReader::read_mesh(Mesh *existing_mesh,
|
|||
std::map<pxr::SdfPath, int> mat_map;
|
||||
bke::MutableAttributeAccessor attributes = active_mesh->attributes_for_write();
|
||||
bke::SpanAttributeWriter<int> material_indices =
|
||||
attributes.lookup_or_add_for_write_only_span<int>("material_index", ATTR_DOMAIN_FACE);
|
||||
attributes.lookup_or_add_for_write_span<int>("material_index", ATTR_DOMAIN_FACE);
|
||||
assign_facesets_to_material_indices(motionSampleTime, material_indices.span, &mat_map);
|
||||
material_indices.finish();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue