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.
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.