From da4e2fe7fe8fb006ce4574d1a642c9129eaa549a Mon Sep 17 00:00:00 2001 From: Aras Pranckevicius Date: Mon, 2 Jan 2023 16:14:51 +0200 Subject: [PATCH] OBJ: in exporter faces loop, move material index accessor outside of the loop While the cost of creating AttributeAccessor and finding the "material_index" attribute is not large, there's really no need to do that for each polygon. Move the access outside of the per-polygon loop. --- .../io/wavefront_obj/exporter/obj_export_file_writer.cc | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/source/blender/io/wavefront_obj/exporter/obj_export_file_writer.cc b/source/blender/io/wavefront_obj/exporter/obj_export_file_writer.cc index ec09a145f1b..6957e07dadd 100644 --- a/source/blender/io/wavefront_obj/exporter/obj_export_file_writer.cc +++ b/source/blender/io/wavefront_obj/exporter/obj_export_file_writer.cc @@ -337,6 +337,9 @@ void OBJWriter::write_poly_elements(FormatHandler &fh, const int tot_polygons = obj_mesh_data.tot_polygons(); const int tot_deform_groups = obj_mesh_data.tot_deform_groups(); threading::EnumerableThreadSpecific> group_weights; + const bke::AttributeAccessor attributes = obj_mesh_data.get_mesh()->attributes(); + const VArray material_indices = attributes.lookup_or_default( + "material_index", ATTR_DOMAIN_FACE, 0); obj_parallel_chunked_output(fh, tot_polygons, [&](FormatHandler &buf, int idx) { /* Polygon order for writing into the file is not necessarily the same @@ -372,10 +375,6 @@ void OBJWriter::write_poly_elements(FormatHandler &fh, } } - const bke::AttributeAccessor attributes = obj_mesh_data.get_mesh()->attributes(); - const VArray material_indices = attributes.lookup_or_default( - "material_index", ATTR_DOMAIN_FACE, 0); - /* Write material name and material group if different from previous. */ if (export_params_.export_materials && obj_mesh_data.tot_materials() > 0) { const int16_t prev_mat = idx == 0 ? NEGATIVE_INIT : std::max(0, material_indices[prev_i]);