diff options
author | Jacques Lucke <jacques@blender.org> | 2021-01-25 18:20:10 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2021-01-25 18:25:27 +0300 |
commit | 8a77019474c1a4d05fb74bb86031ff75c116f751 (patch) | |
tree | eadbdb78821f1aedb8d2829d583243dd1114bc4f | |
parent | 04f91bce53bd50fc492130ada8869f97ae205f9a (diff) |
Cycles: modernize usage of rna iterators
Using rna iterators in range-based for loops is possible since {rBc4286ddb095d32714c9d5f10751a14f5871b3844}.
This patch only updates the places that are easy to update
without more changes in surrounding code.
Differential Revision: https://developer.blender.org/D10195
-rw-r--r-- | intern/cycles/blender/blender_curves.cpp | 44 | ||||
-rw-r--r-- | intern/cycles/blender/blender_device.cpp | 8 | ||||
-rw-r--r-- | intern/cycles/blender/blender_geometry.cpp | 5 | ||||
-rw-r--r-- | intern/cycles/blender/blender_mesh.cpp | 122 | ||||
-rw-r--r-- | intern/cycles/blender/blender_object.cpp | 7 | ||||
-rw-r--r-- | intern/cycles/blender/blender_python.cpp | 15 | ||||
-rw-r--r-- | intern/cycles/blender/blender_session.cpp | 11 | ||||
-rw-r--r-- | intern/cycles/blender/blender_shader.cpp | 153 | ||||
-rw-r--r-- | intern/cycles/blender/blender_sync.cpp | 34 | ||||
-rw-r--r-- | intern/cycles/blender/blender_util.h | 16 | ||||
-rw-r--r-- | intern/cycles/blender/blender_volume.cpp | 8 |
11 files changed, 179 insertions, 244 deletions
diff --git a/intern/cycles/blender/blender_curves.cpp b/intern/cycles/blender/blender_curves.cpp index 1764b5b635d..4fb5c7f57d1 100644 --- a/intern/cycles/blender/blender_curves.cpp +++ b/intern/cycles/blender/blender_curves.cpp @@ -67,11 +67,10 @@ static bool ObtainCacheParticleData( Transform tfm = get_transform(b_ob->matrix_world()); Transform itfm = transform_quick_inverse(tfm); - BL::Object::modifiers_iterator b_mod; - for (b_ob->modifiers.begin(b_mod); b_mod != b_ob->modifiers.end(); ++b_mod) { - if ((b_mod->type() == b_mod->type_PARTICLE_SYSTEM) && - (background ? b_mod->show_render() : b_mod->show_viewport())) { - BL::ParticleSystemModifier psmd((const PointerRNA)b_mod->ptr); + for (BL::Modifier &b_mod : b_ob->modifiers) { + if ((b_mod.type() == b_mod.type_PARTICLE_SYSTEM) && + (background ? b_mod.show_render() : b_mod.show_viewport())) { + BL::ParticleSystemModifier psmd((const PointerRNA)b_mod.ptr); BL::ParticleSystem b_psys((const PointerRNA)psmd.particle_system().ptr); BL::ParticleSettings b_part((const PointerRNA)b_psys.settings().ptr); @@ -163,11 +162,10 @@ static bool ObtainCacheParticleUV(Hair *hair, CData->curve_uv.clear(); - BL::Object::modifiers_iterator b_mod; - for (b_ob->modifiers.begin(b_mod); b_mod != b_ob->modifiers.end(); ++b_mod) { - if ((b_mod->type() == b_mod->type_PARTICLE_SYSTEM) && - (background ? b_mod->show_render() : b_mod->show_viewport())) { - BL::ParticleSystemModifier psmd((const PointerRNA)b_mod->ptr); + for (BL::Modifier &b_mod : b_ob->modifiers) { + if ((b_mod.type() == b_mod.type_PARTICLE_SYSTEM) && + (background ? b_mod.show_render() : b_mod.show_viewport())) { + BL::ParticleSystemModifier psmd((const PointerRNA)b_mod.ptr); BL::ParticleSystem b_psys((const PointerRNA)psmd.particle_system().ptr); BL::ParticleSettings b_part((const PointerRNA)b_psys.settings().ptr); @@ -226,11 +224,10 @@ static bool ObtainCacheParticleVcol(Hair *hair, CData->curve_vcol.clear(); - BL::Object::modifiers_iterator b_mod; - for (b_ob->modifiers.begin(b_mod); b_mod != b_ob->modifiers.end(); ++b_mod) { - if ((b_mod->type() == b_mod->type_PARTICLE_SYSTEM) && - (background ? b_mod->show_render() : b_mod->show_viewport())) { - BL::ParticleSystemModifier psmd((const PointerRNA)b_mod->ptr); + for (BL::Modifier &b_mod : b_ob->modifiers) { + if ((b_mod.type() == b_mod.type_PARTICLE_SYSTEM) && + (background ? b_mod.show_render() : b_mod.show_viewport())) { + BL::ParticleSystemModifier psmd((const PointerRNA)b_mod.ptr); BL::ParticleSystem b_psys((const PointerRNA)psmd.particle_system().ptr); BL::ParticleSettings b_part((const PointerRNA)b_psys.settings().ptr); @@ -510,11 +507,10 @@ static void ExportCurveSegmentsMotion(Hair *hair, ParticleCurveData *CData, int bool BlenderSync::object_has_particle_hair(BL::Object b_ob) { /* Test if the object has a particle modifier with hair. */ - BL::Object::modifiers_iterator b_mod; - for (b_ob.modifiers.begin(b_mod); b_mod != b_ob.modifiers.end(); ++b_mod) { - if ((b_mod->type() == b_mod->type_PARTICLE_SYSTEM) && - (preview ? b_mod->show_viewport() : b_mod->show_render())) { - BL::ParticleSystemModifier psmd((const PointerRNA)b_mod->ptr); + for (BL::Modifier &b_mod : b_ob.modifiers) { + if ((b_mod.type() == b_mod.type_PARTICLE_SYSTEM) && + (preview ? b_mod.show_viewport() : b_mod.show_render())) { + BL::ParticleSystemModifier psmd((const PointerRNA)b_mod.ptr); BL::ParticleSystem b_psys((const PointerRNA)psmd.particle_system().ptr); BL::ParticleSettings b_part((const PointerRNA)b_psys.settings().ptr); @@ -678,9 +674,7 @@ static void export_hair_curves(Scene *scene, Hair *hair, BL::Hair b_hair) /* Export curves and points. */ vector<float> points_length; - BL::Hair::curves_iterator b_curve_iter; - for (b_hair.curves.begin(b_curve_iter); b_curve_iter != b_hair.curves.end(); ++b_curve_iter) { - BL::HairCurve b_curve = *b_curve_iter; + for (BL::HairCurve &b_curve : b_hair.curves) { const int first_point_index = b_curve.first_point_index(); const int num_points = b_curve.num_points(); @@ -748,9 +742,7 @@ static void export_hair_curves_motion(Hair *hair, BL::Hair b_hair, int motion_st int num_motion_keys = 0; int curve_index = 0; - BL::Hair::curves_iterator b_curve_iter; - for (b_hair.curves.begin(b_curve_iter); b_curve_iter != b_hair.curves.end(); ++b_curve_iter) { - BL::HairCurve b_curve = *b_curve_iter; + for (BL::HairCurve &b_curve : b_hair.curves) { const int first_point_index = b_curve.first_point_index(); const int num_points = b_curve.num_points(); diff --git a/intern/cycles/blender/blender_device.cpp b/intern/cycles/blender/blender_device.cpp index 3ec77719bea..d51b31de638 100644 --- a/intern/cycles/blender/blender_device.cpp +++ b/intern/cycles/blender/blender_device.cpp @@ -47,11 +47,9 @@ DeviceInfo blender_device_info(BL::Preferences &b_preferences, BL::Scene &b_scen /* Find cycles preferences. */ PointerRNA cpreferences; - BL::Preferences::addons_iterator b_addon_iter; - for (b_preferences.addons.begin(b_addon_iter); b_addon_iter != b_preferences.addons.end(); - ++b_addon_iter) { - if (b_addon_iter->module() == "cycles") { - cpreferences = b_addon_iter->preferences().ptr; + for (BL::Addon &b_addon : b_preferences.addons) { + if (b_addon.module() == "cycles") { + cpreferences = b_addon.preferences().ptr; break; } } diff --git a/intern/cycles/blender/blender_geometry.cpp b/intern/cycles/blender/blender_geometry.cpp index 53557e0fe38..a009018f357 100644 --- a/intern/cycles/blender/blender_geometry.cpp +++ b/intern/cycles/blender/blender_geometry.cpp @@ -50,13 +50,12 @@ array<Node *> BlenderSync::find_used_shaders(BL::Object &b_ob) array<Node *> used_shaders; - BL::Object::material_slots_iterator slot; - for (b_ob.material_slots.begin(slot); slot != b_ob.material_slots.end(); ++slot) { + for (BL::MaterialSlot &b_slot : b_ob.material_slots) { if (material_override) { find_shader(material_override, used_shaders, default_shader); } else { - BL::ID b_material(slot->material()); + BL::ID b_material(b_slot.material()); find_shader(b_material, used_shaders, default_shader); } } diff --git a/intern/cycles/blender/blender_mesh.cpp b/intern/cycles/blender/blender_mesh.cpp index b334da38372..7edf797e096 100644 --- a/intern/cycles/blender/blender_mesh.cpp +++ b/intern/cycles/blender/blender_mesh.cpp @@ -285,12 +285,10 @@ static void attr_create_sculpt_vertex_color(Scene *scene, BL::Mesh &b_mesh, bool subdivision) { - BL::Mesh::sculpt_vertex_colors_iterator l; - - for (b_mesh.sculpt_vertex_colors.begin(l); l != b_mesh.sculpt_vertex_colors.end(); ++l) { - const bool active_render = l->active_render(); + for (BL::MeshVertColorLayer &l : b_mesh.sculpt_vertex_colors) { + const bool active_render = l.active_render(); AttributeStandard vcol_std = (active_render) ? ATTR_STD_VERTEX_COLOR : ATTR_STD_NONE; - ustring vcol_name = ustring(l->name().c_str()); + ustring vcol_name = ustring(l.name().c_str()); const bool need_vcol = mesh->need_attribute(scene, vcol_name) || mesh->need_attribute(scene, vcol_std); @@ -307,7 +305,7 @@ static void attr_create_sculpt_vertex_color(Scene *scene, int numverts = b_mesh.vertices.length(); for (int i = 0; i < numverts; i++) { - *(cdata++) = get_float4(l->data[i].color()); + *(cdata++) = get_float4(l.data[i].color()); } } } @@ -315,12 +313,10 @@ static void attr_create_sculpt_vertex_color(Scene *scene, /* Create vertex color attributes. */ static void attr_create_vertex_color(Scene *scene, Mesh *mesh, BL::Mesh &b_mesh, bool subdivision) { - BL::Mesh::vertex_colors_iterator l; - - for (b_mesh.vertex_colors.begin(l); l != b_mesh.vertex_colors.end(); ++l) { - const bool active_render = l->active_render(); + for (BL::MeshLoopColorLayer &l : b_mesh.vertex_colors) { + const bool active_render = l.active_render(); AttributeStandard vcol_std = (active_render) ? ATTR_STD_VERTEX_COLOR : ATTR_STD_NONE; - ustring vcol_name = ustring(l->name().c_str()); + ustring vcol_name = ustring(l.name().c_str()); const bool need_vcol = mesh->need_attribute(scene, vcol_name) || mesh->need_attribute(scene, vcol_std); @@ -339,13 +335,12 @@ static void attr_create_vertex_color(Scene *scene, Mesh *mesh, BL::Mesh &b_mesh, vcol_attr = mesh->subd_attributes.add(vcol_name, TypeRGBA, ATTR_ELEMENT_CORNER_BYTE); } - BL::Mesh::polygons_iterator p; uchar4 *cdata = vcol_attr->data_uchar4(); - for (b_mesh.polygons.begin(p); p != b_mesh.polygons.end(); ++p) { - int n = p->loop_total(); + for (BL::MeshPolygon &p : b_mesh.polygons) { + int n = p.loop_total(); for (int i = 0; i < n; i++) { - float4 color = get_float4(l->data[p->loop_start() + i].color()); + float4 color = get_float4(l.data[p.loop_start() + i].color()); /* Compress/encode vertex color using the sRGB curve. */ *(cdata++) = color_float4_to_uchar4(color); } @@ -359,14 +354,13 @@ static void attr_create_vertex_color(Scene *scene, Mesh *mesh, BL::Mesh &b_mesh, vcol_attr = mesh->attributes.add(vcol_name, TypeRGBA, ATTR_ELEMENT_CORNER_BYTE); } - BL::Mesh::loop_triangles_iterator t; uchar4 *cdata = vcol_attr->data_uchar4(); - for (b_mesh.loop_triangles.begin(t); t != b_mesh.loop_triangles.end(); ++t) { - int3 li = get_int3(t->loops()); - float4 c1 = get_float4(l->data[li[0]].color()); - float4 c2 = get_float4(l->data[li[1]].color()); - float4 c3 = get_float4(l->data[li[2]].color()); + for (BL::MeshLoopTriangle &t : b_mesh.loop_triangles) { + int3 li = get_int3(t.loops()); + float4 c1 = get_float4(l.data[li[0]].color()); + float4 c2 = get_float4(l.data[li[1]].color()); + float4 c3 = get_float4(l.data[li[2]].color()); /* Compress/encode vertex color using the sRGB curve. */ cdata[0] = color_float4_to_uchar4(c1); @@ -383,14 +377,12 @@ static void attr_create_vertex_color(Scene *scene, Mesh *mesh, BL::Mesh &b_mesh, static void attr_create_uv_map(Scene *scene, Mesh *mesh, BL::Mesh &b_mesh) { if (b_mesh.uv_layers.length() != 0) { - BL::Mesh::uv_layers_iterator l; - - for (b_mesh.uv_layers.begin(l); l != b_mesh.uv_layers.end(); ++l) { - const bool active_render = l->active_render(); + for (BL::MeshUVLoopLayer &l : b_mesh.uv_layers) { + const bool active_render = l.active_render(); AttributeStandard uv_std = (active_render) ? ATTR_STD_UV : ATTR_STD_NONE; - ustring uv_name = ustring(l->name().c_str()); + ustring uv_name = ustring(l.name().c_str()); AttributeStandard tangent_std = (active_render) ? ATTR_STD_UV_TANGENT : ATTR_STD_NONE; - ustring tangent_name = ustring((string(l->name().c_str()) + ".tangent").c_str()); + ustring tangent_name = ustring((string(l.name().c_str()) + ".tangent").c_str()); /* Denotes whether UV map was requested directly. */ const bool need_uv = mesh->need_attribute(scene, uv_name) || @@ -412,14 +404,13 @@ static void attr_create_uv_map(Scene *scene, Mesh *mesh, BL::Mesh &b_mesh) uv_attr = mesh->attributes.add(uv_name, TypeFloat2, ATTR_ELEMENT_CORNER); } - BL::Mesh::loop_triangles_iterator t; float2 *fdata = uv_attr->data_float2(); - for (b_mesh.loop_triangles.begin(t); t != b_mesh.loop_triangles.end(); ++t) { - int3 li = get_int3(t->loops()); - fdata[0] = get_float2(l->data[li[0]].uv()); - fdata[1] = get_float2(l->data[li[1]].uv()); - fdata[2] = get_float2(l->data[li[2]].uv()); + for (BL::MeshLoopTriangle &t : b_mesh.loop_triangles) { + int3 li = get_int3(t.loops()); + fdata[0] = get_float2(l.data[li[0]].uv()); + fdata[1] = get_float2(l.data[li[1]].uv()); + fdata[2] = get_float2(l.data[li[2]].uv()); fdata += 3; } } @@ -427,10 +418,10 @@ static void attr_create_uv_map(Scene *scene, Mesh *mesh, BL::Mesh &b_mesh) /* UV tangent */ if (need_tangent) { AttributeStandard sign_std = (active_render) ? ATTR_STD_UV_TANGENT_SIGN : ATTR_STD_NONE; - ustring sign_name = ustring((string(l->name().c_str()) + ".tangent_sign").c_str()); + ustring sign_name = ustring((string(l.name().c_str()) + ".tangent_sign").c_str()); bool need_sign = (mesh->need_attribute(scene, sign_name) || mesh->need_attribute(scene, sign_std)); - mikk_compute_tangents(b_mesh, l->name().c_str(), mesh, need_sign, active_render); + mikk_compute_tangents(b_mesh, l.name().c_str(), mesh, need_sign, active_render); } /* Remove temporarily created UV attribute. */ if (!need_uv && uv_attr != NULL) { @@ -480,13 +471,12 @@ static void attr_create_subd_uv_map(Scene *scene, Mesh *mesh, BL::Mesh &b_mesh, uv_attr->flags |= ATTR_SUBDIVIDED; } - BL::Mesh::polygons_iterator p; float2 *fdata = uv_attr->data_float2(); - for (b_mesh.polygons.begin(p); p != b_mesh.polygons.end(); ++p) { - int n = p->loop_total(); + for (BL::MeshPolygon &p : b_mesh.polygons) { + int n = p.loop_total(); for (int j = 0; j < n; j++) { - *(fdata++) = get_float2(l->data[p->loop_start() + j].uv()); + *(fdata++) = get_float2(l->data[p.loop_start() + j].uv()); } } } @@ -706,9 +696,8 @@ static void attr_create_random_per_island(Scene *scene, DisjointSet vertices_sets(number_of_vertices); - BL::Mesh::edges_iterator e; - for (b_mesh.edges.begin(e); e != b_mesh.edges.end(); ++e) { - vertices_sets.join(e->vertices()[0], e->vertices()[1]); + for (BL::MeshEdge &e : b_mesh.edges) { + vertices_sets.join(e.vertices()[0], e.vertices()[1]); } AttributeSet &attributes = (subdivision) ? mesh->subd_attributes : mesh->attributes; @@ -716,15 +705,13 @@ static void attr_create_random_per_island(Scene *scene, float *data = attribute->data_float(); if (!subdivision) { - BL::Mesh::loop_triangles_iterator t; - for (b_mesh.loop_triangles.begin(t); t != b_mesh.loop_triangles.end(); ++t) { - data[t->index()] = hash_uint_to_float(vertices_sets.find(t->vertices()[0])); + for (BL::MeshLoopTriangle &t : b_mesh.loop_triangles) { + data[t.index()] = hash_uint_to_float(vertices_sets.find(t.vertices()[0])); } } else { - BL::Mesh::polygons_iterator p; - for (b_mesh.polygons.begin(p); p != b_mesh.polygons.end(); ++p) { - data[p->index()] = hash_uint_to_float(vertices_sets.find(p->vertices()[0])); + for (BL::MeshPolygon &p : b_mesh.polygons) { + data[p.index()] = hash_uint_to_float(vertices_sets.find(p.vertices()[0])); } } } @@ -756,10 +743,9 @@ static void create_mesh(Scene *scene, numtris = numfaces; } else { - BL::Mesh::polygons_iterator p; - for (b_mesh.polygons.begin(p); p != b_mesh.polygons.end(); ++p) { - numngons += (p->loop_total() == 4) ? 0 : 1; - numcorners += p->loop_total(); + for (BL::MeshPolygon &p : b_mesh.polygons) { + numngons += (p.loop_total() == 4) ? 0 : 1; + numcorners += p.loop_total(); } } @@ -803,17 +789,15 @@ static void create_mesh(Scene *scene, /* create faces */ if (!subdivision) { - BL::Mesh::loop_triangles_iterator t; - - for (b_mesh.loop_triangles.begin(t); t != b_mesh.loop_triangles.end(); ++t) { - BL::MeshPolygon p = b_mesh.polygons[t->polygon_index()]; - int3 vi = get_int3(t->vertices()); + for (BL::MeshLoopTriangle &t : b_mesh.loop_triangles) { + BL::MeshPolygon p = b_mesh.polygons[t.polygon_index()]; + int3 vi = get_int3(t.vertices()); int shader = clamp(p.material_index(), 0, used_shaders.size() - 1); bool smooth = p.use_smooth() || use_loop_normals; if (use_loop_normals) { - BL::Array<float, 9> loop_normals = t->split_normals(); + BL::Array<float, 9> loop_normals = t.split_normals(); for (int i = 0; i < 3; i++) { N[vi[i]] = make_float3( loop_normals[i * 3], loop_normals[i * 3 + 1], loop_normals[i * 3 + 2]); @@ -828,18 +812,17 @@ static void create_mesh(Scene *scene, } } else { - BL::Mesh::polygons_iterator p; vector<int> vi; - for (b_mesh.polygons.begin(p); p != b_mesh.polygons.end(); ++p) { - int n = p->loop_total(); - int shader = clamp(p->material_index(), 0, used_shaders.size() - 1); - bool smooth = p->use_smooth() || use_loop_normals; + for (BL::MeshPolygon &p : b_mesh.polygons) { + int n = p.loop_total(); + int shader = clamp(p.material_index(), 0, used_shaders.size() - 1); + bool smooth = p.use_smooth() || use_loop_normals; vi.resize(n); for (int i = 0; i < n; i++) { /* NOTE: Autosmooth is already taken care about. */ - vi[i] = b_mesh.loops[p->loop_start() + i].vertex_index(); + vi[i] = b_mesh.loops[p.loop_start() + i].vertex_index(); } /* create subd faces */ @@ -891,19 +874,18 @@ static void create_subd_mesh(Scene *scene, /* export creases */ size_t num_creases = 0; - BL::Mesh::edges_iterator e; - for (b_mesh.edges.begin(e); e != b_mesh.edges.end(); ++e) { - if (e->crease() != 0.0f) { + for (BL::MeshEdge &e : b_mesh.edges) { + if (e.crease() != 0.0f) { num_creases++; } } mesh->reserve_subd_creases(num_creases); - for (b_mesh.edges.begin(e); e != b_mesh.edges.end(); ++e) { - if (e->crease() != 0.0f) { - mesh->add_crease(e->vertices()[0], e->vertices()[1], e->crease()); + for (BL::MeshEdge &e : b_mesh.edges) { + if (e.crease() != 0.0f) { + mesh->add_crease(e.vertices()[0], e.vertices()[1], e.crease()); } } diff --git a/intern/cycles/blender/blender_object.cpp b/intern/cycles/blender/blender_object.cpp index 8daaaea6978..f0460b129c2 100644 --- a/intern/cycles/blender/blender_object.cpp +++ b/intern/cycles/blender/blender_object.cpp @@ -51,10 +51,11 @@ bool BlenderSync::BKE_object_is_modified(BL::Object &b_ob) } else { /* object level material links */ - BL::Object::material_slots_iterator slot; - for (b_ob.material_slots.begin(slot); slot != b_ob.material_slots.end(); ++slot) - if (slot->link() == BL::MaterialSlot::link_OBJECT) + for (BL::MaterialSlot &b_slot : b_ob.material_slots) { + if (b_slot.link() == BL::MaterialSlot::link_OBJECT) { return true; + } + } } return false; diff --git a/intern/cycles/blender/blender_python.cpp b/intern/cycles/blender/blender_python.cpp index 525525e1047..5646bd5b2eb 100644 --- a/intern/cycles/blender/blender_python.cpp +++ b/intern/cycles/blender/blender_python.cpp @@ -597,22 +597,19 @@ static PyObject *osl_update_node_func(PyObject * /*self*/, PyObject *args) bool removed; do { - BL::Node::inputs_iterator b_input; - BL::Node::outputs_iterator b_output; - removed = false; - for (b_node.inputs.begin(b_input); b_input != b_node.inputs.end(); ++b_input) { - if (used_sockets.find(b_input->ptr.data) == used_sockets.end()) { - b_node.inputs.remove(b_data, *b_input); + for (BL::NodeSocket &b_input : b_node.inputs) { + if (used_sockets.find(b_input.ptr.data) == used_sockets.end()) { + b_node.inputs.remove(b_data, b_input); removed = true; break; } } - for (b_node.outputs.begin(b_output); b_output != b_node.outputs.end(); ++b_output) { - if (used_sockets.find(b_output->ptr.data) == used_sockets.end()) { - b_node.outputs.remove(b_data, *b_output); + for (BL::NodeSocket &b_output : b_node.outputs) { + if (used_sockets.find(b_output.ptr.data) == used_sockets.end()) { + b_node.outputs.remove(b_data, b_output); removed = true; break; } diff --git a/intern/cycles/blender/blender_session.cpp b/intern/cycles/blender/blender_session.cpp index 2ec76be4ee8..ae13310789e 100644 --- a/intern/cycles/blender/blender_session.cpp +++ b/intern/cycles/blender/blender_session.cpp @@ -358,11 +358,7 @@ void BlenderSession::do_write_update_render_tile(RenderTile &rtile, if (do_read_only) { /* copy each pass */ - BL::RenderLayer::passes_iterator b_iter; - - for (b_rlay.passes.begin(b_iter); b_iter != b_rlay.passes.end(); ++b_iter) { - BL::RenderPass b_pass(*b_iter); - + for (BL::RenderPass &b_pass : b_rlay.passes) { /* find matching pass type */ PassType pass_type = BlenderSync::get_pass_type(b_pass); int components = b_pass.channels(); @@ -735,10 +731,7 @@ void BlenderSession::do_write_update_render_result(BL::RenderLayer &b_rlay, if (!do_update_only) { /* copy each pass */ - BL::RenderLayer::passes_iterator b_iter; - - for (b_rlay.passes.begin(b_iter); b_iter != b_rlay.passes.end(); ++b_iter) { - BL::RenderPass b_pass(*b_iter); + for (BL::RenderPass &b_pass : b_rlay.passes) { int components = b_pass.channels(); /* Copy pixels from regular render passes. */ diff --git a/intern/cycles/blender/blender_shader.cpp b/intern/cycles/blender/blender_shader.cpp index f3f46a1b108..64e2b172451 100644 --- a/intern/cycles/blender/blender_shader.cpp +++ b/intern/cycles/blender/blender_shader.cpp @@ -148,15 +148,13 @@ BlenderAttributeType blender_attribute_name_split_type(ustring name, string *r_r static BL::NodeSocket get_node_output(BL::Node &b_node, const string &name) { - BL::Node::outputs_iterator b_out; - - for (b_node.outputs.begin(b_out); b_out != b_node.outputs.end(); ++b_out) - if (b_out->name() == name) - return *b_out; - + for (BL::NodeSocket &b_out : b_node.outputs) { + if (b_out.name() == name) { + return b_out; + } + } assert(0); - - return *b_out; + return *b_node.outputs.begin(); } static float3 get_node_output_rgba(BL::Node &b_node, const string &name) @@ -723,9 +721,8 @@ static ShaderNode *add_node(Scene *scene, image->set_alpha_type(get_image_alpha_type(b_image)); array<int> tiles; - BL::Image::tiles_iterator b_iter; - for (b_image.tiles.begin(b_iter); b_iter != b_image.tiles.end(); ++b_iter) { - tiles.push_back_slow(b_iter->number()); + for (BL::UDIMTile &b_tile : b_image.tiles) { + tiles.push_back_slow(b_tile.number()); } image->set_tiles(tiles); @@ -1012,18 +1009,18 @@ static ShaderInput *node_find_input_by_name(ShaderNode *node, string name = b_socket.name(); if (node_use_modified_socket_name(node)) { - BL::Node::inputs_iterator b_input; bool found = false; int counter = 0, total = 0; - for (b_node.inputs.begin(b_input); b_input != b_node.inputs.end(); ++b_input) { - if (b_input->name() == name) { - if (!found) + for (BL::NodeSocket &b_input : b_node.inputs) { + if (b_input.name() == name) { + if (!found) { counter++; + } total++; } - if (b_input->ptr.data == b_socket.ptr.data) + if (b_input.ptr.data == b_socket.ptr.data) found = true; } @@ -1045,19 +1042,20 @@ static ShaderOutput *node_find_output_by_name(ShaderNode *node, string name = b_socket.name(); if (node_use_modified_socket_name(node)) { - BL::Node::outputs_iterator b_output; bool found = false; int counter = 0, total = 0; - for (b_node.outputs.begin(b_output); b_output != b_node.outputs.end(); ++b_output) { - if (b_output->name() == name) { - if (!found) + for (BL::NodeSocket &b_output : b_node.outputs) { + if (b_output.name() == name) { + if (!found) { counter++; + } total++; } - if (b_output->ptr.data == b_socket.ptr.data) + if (b_output.ptr.data == b_socket.ptr.data) { found = true; + } } /* rename if needed */ @@ -1082,25 +1080,19 @@ static void add_nodes(Scene *scene, const ProxyMap &proxy_output_map) { /* add nodes */ - BL::ShaderNodeTree::nodes_iterator b_node; PtrInputMap input_map; PtrOutputMap output_map; - BL::Node::inputs_iterator b_input; - BL::Node::outputs_iterator b_output; - /* find the node to use for output if there are multiple */ BL::ShaderNode output_node = b_ntree.get_output_node( BL::ShaderNodeOutputMaterial::target_CYCLES); /* add nodes */ - for (b_ntree.nodes.begin(b_node); b_node != b_ntree.nodes.end(); ++b_node) { - if (b_node->mute() || b_node->is_a(&RNA_NodeReroute)) { + for (BL::Node &b_node : b_ntree.nodes) { + if (b_node.mute() || b_node.is_a(&RNA_NodeReroute)) { /* replace muted node with internal links */ - BL::Node::internal_links_iterator b_link; - for (b_node->internal_links.begin(b_link); b_link != b_node->internal_links.end(); - ++b_link) { - BL::NodeSocket to_socket(b_link->to_socket()); + for (BL::NodeLink &b_link : b_node.internal_links) { + BL::NodeSocket to_socket(b_link.to_socket()); SocketType::Type to_socket_type = convert_socket_type(to_socket); if (to_socket_type == SocketType::UNDEFINED) { continue; @@ -1108,22 +1100,22 @@ static void add_nodes(Scene *scene, ConvertNode *proxy = graph->create_node<ConvertNode>(to_socket_type, to_socket_type, true); - input_map[b_link->from_socket().ptr.data] = proxy->inputs[0]; - output_map[b_link->to_socket().ptr.data] = proxy->outputs[0]; + input_map[b_link.from_socket().ptr.data] = proxy->inputs[0]; + output_map[b_link.to_socket().ptr.data] = proxy->outputs[0]; graph->add(proxy); } } - else if (b_node->is_a(&RNA_ShaderNodeGroup) || b_node->is_a(&RNA_NodeCustomGroup) || - b_node->is_a(&RNA_ShaderNodeCustomGroup)) { + else if (b_node.is_a(&RNA_ShaderNodeGroup) || b_node.is_a(&RNA_NodeCustomGroup) || + b_node.is_a(&RNA_ShaderNodeCustomGroup)) { BL::ShaderNodeTree b_group_ntree(PointerRNA_NULL); - if (b_node->is_a(&RNA_ShaderNodeGroup)) - b_group_ntree = BL::ShaderNodeTree(((BL::NodeGroup)(*b_node)).node_tree()); - else if (b_node->is_a(&RNA_NodeCustomGroup)) - b_group_ntree = BL::ShaderNodeTree(((BL::NodeCustomGroup)(*b_node)).node_tree()); + if (b_node.is_a(&RNA_ShaderNodeGroup)) + b_group_ntree = BL::ShaderNodeTree(((BL::NodeGroup)(b_node)).node_tree()); + else if (b_node.is_a(&RNA_NodeCustomGroup)) + b_group_ntree = BL::ShaderNodeTree(((BL::NodeCustomGroup)(b_node)).node_tree()); else - b_group_ntree = BL::ShaderNodeTree(((BL::ShaderNodeCustomGroup)(*b_node)).node_tree()); + b_group_ntree = BL::ShaderNodeTree(((BL::ShaderNodeCustomGroup)(b_node)).node_tree()); ProxyMap group_proxy_input_map, group_proxy_output_map; @@ -1131,8 +1123,8 @@ static void add_nodes(Scene *scene, * Do this even if the node group has no internal tree, * so that links have something to connect to and assert won't fail. */ - for (b_node->inputs.begin(b_input); b_input != b_node->inputs.end(); ++b_input) { - SocketType::Type input_type = convert_socket_type(*b_input); + for (BL::NodeSocket &b_input : b_node.inputs) { + SocketType::Type input_type = convert_socket_type(b_input); if (input_type == SocketType::UNDEFINED) { continue; } @@ -1141,14 +1133,14 @@ static void add_nodes(Scene *scene, graph->add(proxy); /* register the proxy node for internal binding */ - group_proxy_input_map[b_input->identifier()] = proxy; + group_proxy_input_map[b_input.identifier()] = proxy; - input_map[b_input->ptr.data] = proxy->inputs[0]; + input_map[b_input.ptr.data] = proxy->inputs[0]; - set_default_value(proxy->inputs[0], *b_input, b_data, b_ntree); + set_default_value(proxy->inputs[0], b_input, b_data, b_ntree); } - for (b_node->outputs.begin(b_output); b_output != b_node->outputs.end(); ++b_output) { - SocketType::Type output_type = convert_socket_type(*b_output); + for (BL::NodeSocket &b_output : b_node.outputs) { + SocketType::Type output_type = convert_socket_type(b_output); if (output_type == SocketType::UNDEFINED) { continue; } @@ -1157,9 +1149,9 @@ static void add_nodes(Scene *scene, graph->add(proxy); /* register the proxy node for internal binding */ - group_proxy_output_map[b_output->identifier()] = proxy; + group_proxy_output_map[b_output.identifier()] = proxy; - output_map[b_output->ptr.data] = proxy->outputs[0]; + output_map[b_output.ptr.data] = proxy->outputs[0]; } if (b_group_ntree) { @@ -1174,30 +1166,30 @@ static void add_nodes(Scene *scene, group_proxy_output_map); } } - else if (b_node->is_a(&RNA_NodeGroupInput)) { + else if (b_node.is_a(&RNA_NodeGroupInput)) { /* map each socket to a proxy node */ - for (b_node->outputs.begin(b_output); b_output != b_node->outputs.end(); ++b_output) { - ProxyMap::const_iterator proxy_it = proxy_input_map.find(b_output->identifier()); + for (BL::NodeSocket &b_output : b_node.outputs) { + ProxyMap::const_iterator proxy_it = proxy_input_map.find(b_output.identifier()); if (proxy_it != proxy_input_map.end()) { ConvertNode *proxy = proxy_it->second; - output_map[b_output->ptr.data] = proxy->outputs[0]; + output_map[b_output.ptr.data] = proxy->outputs[0]; } } } - else if (b_node->is_a(&RNA_NodeGroupOutput)) { - BL::NodeGroupOutput b_output_node(*b_node); + else if (b_node.is_a(&RNA_NodeGroupOutput)) { + BL::NodeGroupOutput b_output_node(b_node); /* only the active group output is used */ if (b_output_node.is_active_output()) { /* map each socket to a proxy node */ - for (b_node->inputs.begin(b_input); b_input != b_node->inputs.end(); ++b_input) { - ProxyMap::const_iterator proxy_it = proxy_output_map.find(b_input->identifier()); + for (BL::NodeSocket &b_input : b_node.inputs) { + ProxyMap::const_iterator proxy_it = proxy_output_map.find(b_input.identifier()); if (proxy_it != proxy_output_map.end()) { ConvertNode *proxy = proxy_it->second; - input_map[b_input->ptr.data] = proxy->inputs[0]; + input_map[b_input.ptr.data] = proxy->inputs[0]; - set_default_value(proxy->inputs[0], *b_input, b_data, b_ntree); + set_default_value(proxy->inputs[0], b_input, b_data, b_ntree); } } } @@ -1205,52 +1197,49 @@ static void add_nodes(Scene *scene, else { ShaderNode *node = NULL; - if (b_node->ptr.data == output_node.ptr.data) { + if (b_node.ptr.data == output_node.ptr.data) { node = graph->output(); } else { - BL::ShaderNode b_shader_node(*b_node); + BL::ShaderNode b_shader_node(b_node); node = add_node( scene, b_engine, b_data, b_depsgraph, b_scene, graph, b_ntree, b_shader_node); } if (node) { /* map node sockets for linking */ - for (b_node->inputs.begin(b_input); b_input != b_node->inputs.end(); ++b_input) { - ShaderInput *input = node_find_input_by_name(node, *b_node, *b_input); + for (BL::NodeSocket &b_input : b_node.inputs) { + ShaderInput *input = node_find_input_by_name(node, b_node, b_input); if (!input) { /* XXX should not happen, report error? */ continue; } - input_map[b_input->ptr.data] = input; + input_map[b_input.ptr.data] = input; - set_default_value(input, *b_input, b_data, b_ntree); + set_default_value(input, b_input, b_data, b_ntree); } - for (b_node->outputs.begin(b_output); b_output != b_node->outputs.end(); ++b_output) { - ShaderOutput *output = node_find_output_by_name(node, *b_node, *b_output); + for (BL::NodeSocket &b_output : b_node.outputs) { + ShaderOutput *output = node_find_output_by_name(node, b_node, b_output); if (!output) { /* XXX should not happen, report error? */ continue; } - output_map[b_output->ptr.data] = output; + output_map[b_output.ptr.data] = output; } } } } /* connect nodes */ - BL::NodeTree::links_iterator b_link; - - for (b_ntree.links.begin(b_link); b_link != b_ntree.links.end(); ++b_link) { + for (BL::NodeLink &b_link : b_ntree.links) { /* Ignore invalid links to avoid unwanted cycles created in graph. * Also ignore links with unavailable sockets. */ - if (!(b_link->is_valid() && b_link->from_socket().enabled() && - b_link->to_socket().enabled())) { + if (!(b_link.is_valid() && b_link.from_socket().enabled() && b_link.to_socket().enabled())) { continue; } /* get blender link data */ - BL::NodeSocket b_from_sock = b_link->from_socket(); - BL::NodeSocket b_to_sock = b_link->to_socket(); + BL::NodeSocket b_from_sock = b_link.from_socket(); + BL::NodeSocket b_to_sock = b_link.to_socket(); ShaderOutput *output = 0; ShaderInput *input = 0; @@ -1298,13 +1287,12 @@ void BlenderSync::sync_materials(BL::Depsgraph &b_depsgraph, bool update_all) TaskPool pool; set<Shader *> updated_shaders; - BL::Depsgraph::ids_iterator b_id; - for (b_depsgraph.ids.begin(b_id); b_id != b_depsgraph.ids.end(); ++b_id) { - if (!b_id->is_a(&RNA_Material)) { + for (BL::ID &b_id : b_depsgraph.ids) { + if (!b_id.is_a(&RNA_Material)) { continue; } - BL::Material b_mat(*b_id); + BL::Material b_mat(b_id); Shader *shader; /* test if we need to sync */ @@ -1525,13 +1513,12 @@ void BlenderSync::sync_lights(BL::Depsgraph &b_depsgraph, bool update_all) { shader_map.set_default(scene->default_light); - BL::Depsgraph::ids_iterator b_id; - for (b_depsgraph.ids.begin(b_id); b_id != b_depsgraph.ids.end(); ++b_id) { - if (!b_id->is_a(&RNA_Light)) { + for (BL::ID &b_id : b_depsgraph.ids) { + if (!b_id.is_a(&RNA_Light)) { continue; } - BL::Light b_light(*b_id); + BL::Light b_light(b_id); Shader *shader; /* test if we need to sync */ diff --git a/intern/cycles/blender/blender_sync.cpp b/intern/cycles/blender/blender_sync.cpp index a8319960b96..4bcadab35a1 100644 --- a/intern/cycles/blender/blender_sync.cpp +++ b/intern/cycles/blender/blender_sync.cpp @@ -132,9 +132,8 @@ void BlenderSync::sync_recalc(BL::Depsgraph &b_depsgraph, BL::SpaceView3D &b_v3d } /* Iterate over all IDs in this depsgraph. */ - BL::Depsgraph::updates_iterator b_update; - for (b_depsgraph.updates.begin(b_update); b_update != b_depsgraph.updates.end(); ++b_update) { - BL::ID b_id(b_update->id()); + for (BL::DepsgraphUpdate &b_update : b_depsgraph.updates) { + BL::ID b_id(b_update.id()); /* Material */ if (b_id.is_a(&RNA_Material)) { @@ -152,17 +151,17 @@ void BlenderSync::sync_recalc(BL::Depsgraph &b_depsgraph, BL::SpaceView3D &b_v3d const bool is_geometry = object_is_geometry(b_ob); const bool is_light = !is_geometry && object_is_light(b_ob); - if (b_ob.is_instancer() && b_update->is_updated_shading()) { + if (b_ob.is_instancer() && b_update.is_updated_shading()) { /* Needed for e.g. object color updates on instancer. */ object_map.set_recalc(b_ob); } if (is_geometry || is_light) { - const bool updated_geometry = b_update->is_updated_geometry(); + const bool updated_geometry = b_update.is_updated_geometry(); /* Geometry (mesh, hair, volume). */ if (is_geometry) { - if (b_update->is_updated_transform() || b_update->is_updated_shading()) { + if (b_update.is_updated_transform() || b_update.is_updated_shading()) { object_map.set_recalc(b_ob); } @@ -182,7 +181,7 @@ void BlenderSync::sync_recalc(BL::Depsgraph &b_depsgraph, BL::SpaceView3D &b_v3d } /* Light */ else if (is_light) { - if (b_update->is_updated_transform() || b_update->is_updated_shading()) { + if (b_update.is_updated_transform() || b_update.is_updated_shading()) { object_map.set_recalc(b_ob); light_map.set_recalc(b_ob); } @@ -467,16 +466,15 @@ void BlenderSync::sync_images() return; } /* Free buffers used by images which are not needed for render. */ - BL::BlendData::images_iterator b_image; - for (b_data.images.begin(b_image); b_image != b_data.images.end(); ++b_image) { + for (BL::Image &b_image : b_data.images) { /* TODO(sergey): Consider making it an utility function to check * whether image is considered builtin. */ - const bool is_builtin = b_image->packed_file() || - b_image->source() == BL::Image::source_GENERATED || - b_image->source() == BL::Image::source_MOVIE || b_engine.is_preview(); + const bool is_builtin = b_image.packed_file() || + b_image.source() == BL::Image::source_GENERATED || + b_image.source() == BL::Image::source_MOVIE || b_engine.is_preview(); if (is_builtin == false) { - b_image->buffers_free(); + b_image.buffers_free(); } /* TODO(sergey): Free builtin images not used by any shader. */ } @@ -577,10 +575,7 @@ vector<Pass> BlenderSync::sync_render_passes(BL::RenderLayer &b_rlay, vector<Pass> passes; /* loop over passes */ - BL::RenderLayer::passes_iterator b_pass_iter; - - for (b_rlay.passes.begin(b_pass_iter); b_pass_iter != b_rlay.passes.end(); ++b_pass_iter) { - BL::RenderPass b_pass(*b_pass_iter); + for (BL::RenderPass &b_pass : b_rlay.passes) { PassType pass_type = get_pass_type(b_pass); if (pass_type == PASS_MOTION && scene->integrator->get_motion_blur()) @@ -748,9 +743,8 @@ void BlenderSync::free_data_after_sync(BL::Depsgraph &b_depsgraph) /* TODO(sergey): We can actually remove the whole dependency graph, * but that will need some API support first. */ - BL::Depsgraph::objects_iterator b_ob; - for (b_depsgraph.objects.begin(b_ob); b_ob != b_depsgraph.objects.end(); ++b_ob) { - b_ob->cache_release(); + for (BL::Object &b_ob : b_depsgraph.objects) { + b_ob.cache_release(); } } diff --git a/intern/cycles/blender/blender_util.h b/intern/cycles/blender/blender_util.h index 5185ebae789..43dbb4105df 100644 --- a/intern/cycles/blender/blender_util.h +++ b/intern/cycles/blender/blender_util.h @@ -538,11 +538,9 @@ static inline bool object_use_deform_motion(BL::Object &b_parent, BL::Object &b_ static inline BL::FluidDomainSettings object_fluid_liquid_domain_find(BL::Object &b_ob) { - BL::Object::modifiers_iterator b_mod; - - for (b_ob.modifiers.begin(b_mod); b_mod != b_ob.modifiers.end(); ++b_mod) { - if (b_mod->is_a(&RNA_FluidModifier)) { - BL::FluidModifier b_mmd(*b_mod); + for (BL::Modifier &b_mod : b_ob.modifiers) { + if (b_mod.is_a(&RNA_FluidModifier)) { + BL::FluidModifier b_mmd(b_mod); if (b_mmd.fluid_type() == BL::FluidModifier::fluid_type_DOMAIN && b_mmd.domain_settings().domain_type() == BL::FluidDomainSettings::domain_type_LIQUID) { @@ -556,11 +554,9 @@ static inline BL::FluidDomainSettings object_fluid_liquid_domain_find(BL::Object static inline BL::FluidDomainSettings object_fluid_gas_domain_find(BL::Object &b_ob) { - BL::Object::modifiers_iterator b_mod; - - for (b_ob.modifiers.begin(b_mod); b_mod != b_ob.modifiers.end(); ++b_mod) { - if (b_mod->is_a(&RNA_FluidModifier)) { - BL::FluidModifier b_mmd(*b_mod); + for (BL::Modifier &b_mod : b_ob.modifiers) { + if (b_mod.is_a(&RNA_FluidModifier)) { + BL::FluidModifier b_mmd(b_mod); if (b_mmd.fluid_type() == BL::FluidModifier::fluid_type_DOMAIN && b_mmd.domain_settings().domain_type() == BL::FluidDomainSettings::domain_type_GAS) { diff --git a/intern/cycles/blender/blender_volume.cpp b/intern/cycles/blender/blender_volume.cpp index 094d4bbc08c..410f7a72cf5 100644 --- a/intern/cycles/blender/blender_volume.cpp +++ b/intern/cycles/blender/blender_volume.cpp @@ -222,9 +222,7 @@ class BlenderVolumeLoader : public VDBImageLoader { b_volume.grids.load(b_data.ptr.data); #ifdef WITH_OPENVDB - BL::Volume::grids_iterator b_grid_iter; - for (b_volume.grids.begin(b_grid_iter); b_grid_iter != b_volume.grids.end(); ++b_grid_iter) { - BL::VolumeGrid b_volume_grid(*b_grid_iter); + for (BL::VolumeGrid &b_volume_grid : b_volume.grids) { if (b_volume_grid.name() == grid_name) { const bool unload = !b_volume_grid.is_loaded(); @@ -260,9 +258,7 @@ static void sync_volume_object(BL::BlendData &b_data, volume->set_object_space((b_render.space() == BL::VolumeRender::space_OBJECT)); /* Find grid with matching name. */ - BL::Volume::grids_iterator b_grid_iter; - for (b_volume.grids.begin(b_grid_iter); b_grid_iter != b_volume.grids.end(); ++b_grid_iter) { - BL::VolumeGrid b_grid = *b_grid_iter; + for (BL::VolumeGrid &b_grid : b_volume.grids) { ustring name = ustring(b_grid.name()); AttributeStandard std = ATTR_STD_NONE; |