[Bf-blender-cvs] [9565ea07245] master: IO: Harmonize UI for selection of axes in OBJ and Collada
Commit: 9565ea072457e4523146883ad332fbe4766cdea2 Author: Aras Pranckevicius Date: Fri Feb 3 11:14:43 2023 +0200 Branches: master https://developer.blender.org/rB9565ea072457e4523146883ad332fbe4766cdea2 IO: Harmonize UI for selection of axes in OBJ and Collada Implements T103858: in OBJ importer and exporter, and in Collada exporter, present axis choices as a dropdown instead of inline button row. Reviewed By: Bastien Montagne Differential Revision: https://developer.blender.org/D17186 === M source/blender/editors/io/io_collada.c M source/blender/editors/io/io_obj.c === diff --git a/source/blender/editors/io/io_collada.c b/source/blender/editors/io/io_collada.c index 7bc28a0ba89..7fa835b6490 100644 --- a/source/blender/editors/io/io_collada.c +++ b/source/blender/editors/io/io_collada.c @@ -261,17 +261,8 @@ static void uiCollada_exportSettings(uiLayout *layout, PointerRNA *imfptr) uiItemL(row, IFACE_("Global Orientation"), ICON_ORIENTATION_GLOBAL); uiItemR(box, imfptr, "apply_global_orientation", 0, IFACE_("Apply"), ICON_NONE); - -row = uiLayoutRow(box, false); -uiItemR(row, -imfptr, -"export_global_forward_selection", -UI_ITEM_R_EXPAND, -IFACE_("Forward Axis"), -ICON_NONE); -row = uiLayoutRow(box, false); -uiItemR( -row, imfptr, "export_global_up_selection", UI_ITEM_R_EXPAND, IFACE_("Up Axis"), ICON_NONE); +uiItemR(box, imfptr, "export_global_forward_selection", 0, IFACE_("Forward Axis"), ICON_NONE); +uiItemR(box, imfptr, "export_global_up_selection", 0, IFACE_("Up Axis"), ICON_NONE); /* Texture options */ box = uiLayoutBox(layout); diff --git a/source/blender/editors/io/io_obj.c b/source/blender/editors/io/io_obj.c index e1dba4ee954..54124b46ee5 100644 --- a/source/blender/editors/io/io_obj.c +++ b/source/blender/editors/io/io_obj.c @@ -115,7 +115,7 @@ static void ui_obj_export_settings(uiLayout *layout, PointerRNA *imfptr) uiLayoutSetPropSep(layout, true); uiLayoutSetPropDecorate(layout, false); - uiLayout *box, *col, *sub, *row; + uiLayout *box, *col, *sub; /* Object Transform options. */ box = uiLayoutBox(layout); @@ -123,11 +123,8 @@ static void ui_obj_export_settings(uiLayout *layout, PointerRNA *imfptr) sub = uiLayoutColumnWithHeading(col, false, IFACE_("Limit to")); uiItemR(sub, imfptr, "export_selected_objects", 0, IFACE_("Selected Only"), ICON_NONE); uiItemR(sub, imfptr, "global_scale", 0, NULL, ICON_NONE); - - row = uiLayoutRow(box, false); - uiItemR(row, imfptr, "forward_axis", UI_ITEM_R_EXPAND, IFACE_("Forward Axis"), ICON_NONE); - row = uiLayoutRow(box, false); - uiItemR(row, imfptr, "up_axis", UI_ITEM_R_EXPAND, IFACE_("Up Axis"), ICON_NONE); + uiItemR(sub, imfptr, "forward_axis", 0, IFACE_("Forward Axis"), ICON_NONE); + uiItemR(sub, imfptr, "up_axis", 0, IFACE_("Up Axis"), ICON_NONE); col = uiLayoutColumn(box, false); sub = uiLayoutColumn(col, false); @@ -466,10 +463,8 @@ static void ui_obj_import_settings(uiLayout *layout, PointerRNA *imfptr) uiItemR(sub, imfptr, "clamp_size", 0, NULL, ICON_NONE); sub = uiLayoutColumn(col, false); - uiLayout *row = uiLayoutRow(box, false); - uiItemR(row, imfptr, "forward_axis", UI_ITEM_R_EXPAND, IFACE_("Forward Axis"), ICON_NONE); - row = uiLayoutRow(box, false); - uiItemR(row, imfptr, "up_axis", UI_ITEM_R_EXPAND, IFACE_("Up Axis"), ICON_NONE); + uiItemR(sub, imfptr, "forward_axis", 0, IFACE_("Forward Axis"), ICON_NONE); + uiItemR(sub, imfptr, "up_axis", 0, IFACE_("Up Axis"), ICON_NONE); box = uiLayoutBox(layout); uiItemL(box, IFACE_("Options"), ICON_EXPORT); ___ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs
[Bf-blender-cvs] [427b0a0ab2c] blender-v3.3-release: Fix T101850: Cycles DDS oversaturation when alpha is in use
Commit: 427b0a0ab2c6fdbba5fd7285b907e59ac946b4f7 Author: Aras Pranckevicius Date: Mon Oct 17 21:03:17 2022 +0300 Branches: blender-v3.3-release https://developer.blender.org/rB427b0a0ab2c6fdbba5fd7285b907e59ac946b4f7 Fix T101850: Cycles DDS oversaturation when alpha is in use DDS files coming through OIIO needed a similar treatment as TGA in T99565; just for DDS OIIO just never set the "unassociated alpha" attribute. Fixes T101850. Reviewed By: Brecht Van Lommel Differential Revision: https://developer.blender.org/D16270 === M intern/cycles/scene/image_oiio.cpp === diff --git a/intern/cycles/scene/image_oiio.cpp b/intern/cycles/scene/image_oiio.cpp index ea11e4da628..032b787bfba 100644 --- a/intern/cycles/scene/image_oiio.cpp +++ b/intern/cycles/scene/image_oiio.cpp @@ -197,11 +197,16 @@ bool OIIOImageLoader::load_pixels(const ImageMetaData , if (associate_alpha) { do_associate_alpha = spec.get_int_attribute("oiio:UnassociatedAlpha", 0); -/* Workaround OIIO not detecting TGA file alpha the same as Blender (since #3019). - * We want anything not marked as premultiplied alpha to get associated. */ -if (!do_associate_alpha && spec.alpha_channel != -1 && -strcmp(in->format_name(), "targa") == 0) { - do_associate_alpha = spec.get_int_attribute("targa:alpha_type", -1) != 4; +if (!do_associate_alpha && spec.alpha_channel != -1) { + /* Workaround OIIO not detecting TGA file alpha the same as Blender (since #3019). + * We want anything not marked as premultiplied alpha to get associated. */ + if (strcmp(in->format_name(), "targa") == 0) { +do_associate_alpha = spec.get_int_attribute("targa:alpha_type", -1) != 4; + } + /* OIIO DDS reader never sets UnassociatedAlpha attribute. */ + if (strcmp(in->format_name(), "dds") == 0) { +do_associate_alpha = true; + } } } ___ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs
[Bf-blender-cvs] [b599820418f] master: OBJ: add split by objects/groups import options (T103839)
Commit: b599820418fbfa1cbec88572ed5ff8a6dbce9e13 Author: Aras Pranckevicius Date: Thu Jan 12 22:47:39 2023 +0200 Branches: master https://developer.blender.org/rBb599820418fbfa1cbec88572ed5ff8a6dbce9e13 OBJ: add split by objects/groups import options (T103839) The new C++ OBJ importer was missing "split by objects" / "split by groups" import settings of the older Python importer. Implements T103839. Added test coverage for all 4 possible combinations of these two options. === M source/blender/editors/io/io_obj.c M source/blender/io/wavefront_obj/IO_wavefront_obj.h M source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc M source/blender/io/wavefront_obj/importer/obj_import_mesh.cc M source/blender/io/wavefront_obj/tests/obj_importer_tests.cc === diff --git a/source/blender/editors/io/io_obj.c b/source/blender/editors/io/io_obj.c index ce121203972..e1dba4ee954 100644 --- a/source/blender/editors/io/io_obj.c +++ b/source/blender/editors/io/io_obj.c @@ -410,6 +410,8 @@ static int wm_obj_import_exec(bContext *C, wmOperator *op) import_params.clamp_size = RNA_float_get(op->ptr, "clamp_size"); import_params.forward_axis = RNA_enum_get(op->ptr, "forward_axis"); import_params.up_axis = RNA_enum_get(op->ptr, "up_axis"); + import_params.use_split_objects = RNA_boolean_get(op->ptr, "use_split_objects"); + import_params.use_split_groups = RNA_boolean_get(op->ptr, "use_split_groups"); import_params.import_vertex_groups = RNA_boolean_get(op->ptr, "import_vertex_groups"); import_params.validate_meshes = RNA_boolean_get(op->ptr, "validate_meshes"); import_params.relative_paths = ((U.flag & USER_RELPATHS) != 0); @@ -472,6 +474,8 @@ static void ui_obj_import_settings(uiLayout *layout, PointerRNA *imfptr) box = uiLayoutBox(layout); uiItemL(box, IFACE_("Options"), ICON_EXPORT); col = uiLayoutColumn(box, false); + uiItemR(col, imfptr, "use_split_objects", 0, NULL, ICON_NONE); + uiItemR(col, imfptr, "use_split_groups", 0, NULL, ICON_NONE); uiItemR(col, imfptr, "import_vertex_groups", 0, NULL, ICON_NONE); uiItemR(col, imfptr, "validate_meshes", 0, NULL, ICON_NONE); } @@ -531,6 +535,16 @@ void WM_OT_obj_import(struct wmOperatorType *ot) RNA_def_property_update_runtime(prop, (void *)forward_axis_update); prop = RNA_def_enum(ot->srna, "up_axis", io_transform_axis, IO_AXIS_Y, "Up Axis", ""); RNA_def_property_update_runtime(prop, (void *)up_axis_update); + RNA_def_boolean(ot->srna, + "use_split_objects", + true, + "Split By Object", + "Import each OBJ 'o' as a separate object"); + RNA_def_boolean(ot->srna, + "use_split_groups", + false, + "Split By Group", + "Import each OBJ 'g' as a separate object"); RNA_def_boolean(ot->srna, "import_vertex_groups", false, diff --git a/source/blender/io/wavefront_obj/IO_wavefront_obj.h b/source/blender/io/wavefront_obj/IO_wavefront_obj.h index cf6464eeb37..2c039958bee 100644 --- a/source/blender/io/wavefront_obj/IO_wavefront_obj.h +++ b/source/blender/io/wavefront_obj/IO_wavefront_obj.h @@ -68,6 +68,8 @@ struct OBJImportParams { float global_scale; eIOAxis forward_axis; eIOAxis up_axis; + bool use_split_objects; + bool use_split_groups; bool import_vertex_groups; bool validate_meshes; bool relative_paths; diff --git a/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc b/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc index 1a3a333d957..b90a0c99424 100644 --- a/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc +++ b/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc @@ -363,6 +363,24 @@ static void geom_update_smooth_group(const char *p, const char *end, bool _sta r_state_shaded_smooth = smooth != 0; } +static void geom_new_object(const char *p, +const char *end, +bool _state_shaded_smooth, +std::string _state_group_name, +int _state_material_index, +Geometry *_curr_geom, +Vector> _all_geometries) +{ + r_state_shaded_smooth = false; + r_state_group_name = ""; + /* Reset object-local material index that's used in face infos. + * NOTE: do not reset the material name; that has to carry over + * into the next object if needed. */ +
[Bf-blender-cvs] [da4e2fe7fe8] master: OBJ: in exporter faces loop, move material index accessor outside of the loop
Commit: da4e2fe7fe8fb006ce4574d1a642c9129eaa549a Author: Aras Pranckevicius Date: Mon Jan 2 16:14:51 2023 +0200 Branches: master https://developer.blender.org/rBda4e2fe7fe8fb006ce4574d1a642c9129eaa549a 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. === M source/blender/io/wavefront_obj/exporter/obj_export_file_writer.cc === 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 , 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 , int idx) { /* Polygon order for writing into the file is not necessarily the same @@ -372,10 +375,6 @@ void OBJWriter::write_poly_elements(FormatHandler , } } -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]); ___ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs
[Bf-blender-cvs] [eaef8d50bc9] master: Fix T102672: OBJ exporter "material groups" option wrong for objects with >32k faces
Commit: eaef8d50bc9acf35b279a25a93f9756da30a05ae Author: Aras Pranckevicius Date: Mon Jan 2 16:12:17 2023 +0200 Branches: master https://developer.blender.org/rBeaef8d50bc9acf35b279a25a93f9756da30a05ae Fix T102672: OBJ exporter "material groups" option wrong for objects with >32k faces Turns out, using the wrong output buffer (global one, instead of per-thread one) puts the data into the wrong buffer! Fixes T102672 === M source/blender/io/wavefront_obj/exporter/obj_export_file_writer.cc === 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 909c179dda3..ec09a145f1b 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 @@ -392,7 +392,7 @@ void OBJWriter::write_poly_elements(FormatHandler , if (export_params_.export_material_groups) { std::string object_name = obj_mesh_data.get_object_name(); spaces_to_underscores(object_name); -fh.write_obj_group(object_name + "_" + mat_name); +buf.write_obj_group(object_name + "_" + mat_name); } buf.write_obj_usemtl(mat_name); } ___ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs
[Bf-blender-cvs] [3277879085e] master: Fix T103441: make OBJ importer ignore any unrecognized trailing per-face index data.
Commit: 3277879085ed42a4524a7c43110c37dd0d4ebb84 Author: Aras Pranckevicius Date: Sun Jan 1 19:30:20 2023 +0200 Branches: master https://developer.blender.org/rB3277879085ed42a4524a7c43110c37dd0d4ebb84 Fix T103441: make OBJ importer ignore any unrecognized trailing per-face index data. Some files out there (e.g. in T103441) contain face definitions with four indices, which the importer code was not expecting. The OBJ standard spells out up to three indices per face corner; the file in there must be using some sort of non-standard OBJ syntax extension. Now the code simply ignores any trailing per-face-corner data. === M source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc === diff --git a/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc b/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc index a46b3397891..1a3a333d957 100644 --- a/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc +++ b/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc @@ -252,6 +252,8 @@ static void geom_add_polygon(Geometry *geom, geom->face_corners_.append(corner); curr_face.corner_count_++; +/* Some files contain extra stuff per face (e.g. 4 indices); skip any remainder (T103441). */ +p = drop_non_whitespace(p, end); /* Skip whitespace to get to the next face corner. */ p = drop_whitespace(p, end); } ___ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs
[Bf-blender-cvs] [8007f7e74f5] master: Fix T103212: ignore OBJ UV indices if no UVs are present
Commit: 8007f7e74f5085693c5b5f83d3f9f19a173bab75 Author: Aras Pranckevicius Date: Sun Jan 1 19:14:37 2023 +0200 Branches: master https://developer.blender.org/rB8007f7e74f5085693c5b5f83d3f9f19a173bab75 Fix T103212: ignore OBJ UV indices if no UVs are present Similar to T98782 that was about normal indices: some files out there are technically "wrong" since they refer to UV indices, without ever defining any UVs. If the file does not have any UVs, simply ignore UV indices in the OBJ face definitions. Fixes T103212. === M source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc === diff --git a/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc b/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc index 7d5f023af4b..a46b3397891 100644 --- a/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc +++ b/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc @@ -222,7 +222,8 @@ static void geom_add_polygon(Geometry *geom, else { geom->track_vertex_index(corner.vert_index); } -if (got_uv) { +/* Ignore UV index, if the geometry does not have any UVs (T103212). */ +if (got_uv && !global_vertices.uv_vertices.is_empty()) { corner.uv_vert_index += corner.uv_vert_index < 0 ? global_vertices.uv_vertices.size() : -1; if (corner.uv_vert_index < 0 || corner.uv_vert_index >= global_vertices.uv_vertices.size()) { fprintf(stderr, ___ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs
[Bf-blender-cvs] [a47d1ad9d58] blender-v3.4-release: Fix T103031: ViewLayer: Crash in indirect_only_get due to missing null check
Commit: a47d1ad9d58b5596f942b28c03f07b4bded25ea6 Author: Aras Pranckevicius Date: Fri Dec 9 20:20:11 2022 +0200 Branches: blender-v3.4-release https://developer.blender.org/rBa47d1ad9d58b5596f942b28c03f07b4bded25ea6 Fix T103031: ViewLayer: Crash in indirect_only_get due to missing null check Previous fix (rBe00f76c6a8cca) accidentally lost a null check. Fixes T103031. === M source/blender/makesrna/intern/rna_object_api.c === diff --git a/source/blender/makesrna/intern/rna_object_api.c b/source/blender/makesrna/intern/rna_object_api.c index 366a3597ce6..3d4d72cefaf 100644 --- a/source/blender/makesrna/intern/rna_object_api.c +++ b/source/blender/makesrna/intern/rna_object_api.c @@ -205,6 +205,10 @@ static bool rna_Object_holdout_get(Object *ob, bContext *C, PointerRNA *view_lay static bool rna_Object_indirect_only_get(Object *ob, bContext *C, PointerRNA *view_layer_ptr) { Base *base = find_view_layer_base_with_synced_ensure(ob, C, view_layer_ptr, NULL, NULL); + if (!base) { +return false; + } + return ((base->flag & BASE_INDIRECT_ONLY) != 0); } ___ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs
[Bf-blender-cvs] [874319a3443] master: Fix T103031: ViewLayer: Crash in indirect_only_get due to missing null check
Commit: 874319a3443f7150f78b34f5737b1bc159e5262e Author: Aras Pranckevicius Date: Fri Dec 9 20:20:11 2022 +0200 Branches: master https://developer.blender.org/rB874319a3443f7150f78b34f5737b1bc159e5262e Fix T103031: ViewLayer: Crash in indirect_only_get due to missing null check Previous fix (rBe00f76c6a8cca) accidentally lost a null check. Fixes T103031. === M source/blender/makesrna/intern/rna_object_api.c === diff --git a/source/blender/makesrna/intern/rna_object_api.c b/source/blender/makesrna/intern/rna_object_api.c index 366a3597ce6..3d4d72cefaf 100644 --- a/source/blender/makesrna/intern/rna_object_api.c +++ b/source/blender/makesrna/intern/rna_object_api.c @@ -205,6 +205,10 @@ static bool rna_Object_holdout_get(Object *ob, bContext *C, PointerRNA *view_lay static bool rna_Object_indirect_only_get(Object *ob, bContext *C, PointerRNA *view_layer_ptr) { Base *base = find_view_layer_base_with_synced_ensure(ob, C, view_layer_ptr, NULL, NULL); + if (!base) { +return false; + } + return ((base->flag & BASE_INDIRECT_ONLY) != 0); } ___ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs
[Bf-blender-cvs] [e1e9c838899] blender-v3.3-release: Fix T101685: OBJ importer does not assign proper material if "usemtl" is before "o"
Commit: e1e9c838899dd1a8f55a5c67b2d5716a6a5b88a6 Author: Aras Pranckevicius Date: Sun Oct 9 21:21:31 2022 +0300 Branches: blender-v3.3-release https://developer.blender.org/rBe1e9c838899dd1a8f55a5c67b2d5716a6a5b88a6 Fix T101685: OBJ importer does not assign proper material if "usemtl" is before "o" The importer logic was wrongly resetting "current material name" upon encountering a new object ("o" command). However as per OBJ specification, this is incorrect: > Specifies the material name for the element following it. Once a > material is assigned, it cannot be turned off; it can only be > changed. Fixes T101685. Test coverage for this was added in svn tests repo. === M source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc === diff --git a/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc b/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc index 7069e1185e0..78f34eab228 100644 --- a/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc +++ b/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc @@ -507,6 +507,15 @@ void OBJParser::parse(Vector> _all_geometries, } /* Faces. */ else if (parse_keyword(p, end, "f")) { +/* If we don't have a material index assigned yet, get one. + * It means "usemtl" state came from the previous object. */ +if (state_material_index == -1 && !state_material_name.empty() && +curr_geom->material_indices_.is_empty()) { + curr_geom->material_indices_.add_new(state_material_name, 0); + curr_geom->material_order_.append(state_material_name); + state_material_index = 0; +} + geom_add_polygon(curr_geom, p, end, @@ -523,7 +532,10 @@ void OBJParser::parse(Vector> _all_geometries, else if (parse_keyword(p, end, "o")) { state_shaded_smooth = false; state_group_name = ""; -state_material_name = ""; +/* Reset object-local material index that's used in face infos. + * Note: do not reset the material name; that has to carry over + * into the next object if needed. */ +state_material_index = -1; curr_geom = create_geometry( curr_geom, GEOM_MESH, StringRef(p, end).trim(), r_all_geometries); } ___ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs
[Bf-blender-cvs] [603a534f09b] master: Fix T101850: Cycles DDS oversaturation when alpha is in use
Commit: 603a534f09b0f94f599c607240a4934f7c1a2ef6 Author: Aras Pranckevicius Date: Mon Oct 17 21:03:17 2022 +0300 Branches: master https://developer.blender.org/rB603a534f09b0f94f599c607240a4934f7c1a2ef6 Fix T101850: Cycles DDS oversaturation when alpha is in use DDS files coming through OIIO needed a similar treatment as TGA in T99565; just for DDS OIIO just never set the "unassociated alpha" attribute. Fixes T101850. Reviewed By: Brecht Van Lommel Differential Revision: https://developer.blender.org/D16270 === M intern/cycles/scene/image_oiio.cpp === diff --git a/intern/cycles/scene/image_oiio.cpp b/intern/cycles/scene/image_oiio.cpp index d59359970c6..7bcf1ccb073 100644 --- a/intern/cycles/scene/image_oiio.cpp +++ b/intern/cycles/scene/image_oiio.cpp @@ -196,11 +196,16 @@ bool OIIOImageLoader::load_pixels(const ImageMetaData , if (associate_alpha) { do_associate_alpha = spec.get_int_attribute("oiio:UnassociatedAlpha", 0); -/* Workaround OIIO not detecting TGA file alpha the same as Blender (since #3019). - * We want anything not marked as premultiplied alpha to get associated. */ -if (!do_associate_alpha && spec.alpha_channel != -1 && -strcmp(in->format_name(), "targa") == 0) { - do_associate_alpha = spec.get_int_attribute("targa:alpha_type", -1) != 4; +if (!do_associate_alpha && spec.alpha_channel != -1) { + /* Workaround OIIO not detecting TGA file alpha the same as Blender (since #3019). + * We want anything not marked as premultiplied alpha to get associated. */ + if (strcmp(in->format_name(), "targa") == 0) { +do_associate_alpha = spec.get_int_attribute("targa:alpha_type", -1) != 4; + } + /* OIIO DDS reader never sets UnassociatedAlpha attribute. */ + if (strcmp(in->format_name(), "dds") == 0) { +do_associate_alpha = true; + } } } ___ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs
[Bf-blender-cvs] [25b745ae85e] master: IO: support Presets in Alembic, Collada, OBJ, STL, USD importers
Commit: 25b745ae85ea47675508adb0aa46ccb3cb738e21 Author: Aras Pranckevicius Date: Mon Oct 10 16:01:18 2022 +0300 Branches: master https://developer.blender.org/rB25b745ae85ea47675508adb0aa46ccb3cb738e21 IO: support Presets in Alembic, Collada, OBJ, STL, USD importers The exporters already had Preset functionality, but the importers did not. === M source/blender/editors/io/io_alembic.c M source/blender/editors/io/io_collada.c M source/blender/editors/io/io_obj.c M source/blender/editors/io/io_stl_ops.c M source/blender/editors/io/io_usd.c === diff --git a/source/blender/editors/io/io_alembic.c b/source/blender/editors/io/io_alembic.c index d4855f470ff..100d56a6b0d 100644 --- a/source/blender/editors/io/io_alembic.c +++ b/source/blender/editors/io/io_alembic.c @@ -658,7 +658,7 @@ void WM_OT_alembic_import(wmOperatorType *ot) ot->name = "Import Alembic"; ot->description = "Load an Alembic archive"; ot->idname = "WM_OT_alembic_import"; - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_PRESET; ot->invoke = wm_alembic_import_invoke; ot->exec = wm_alembic_import_exec; diff --git a/source/blender/editors/io/io_collada.c b/source/blender/editors/io/io_collada.c index 1048d0eca32..a630f150e0e 100644 --- a/source/blender/editors/io/io_collada.c +++ b/source/blender/editors/io/io_collada.c @@ -770,14 +770,12 @@ void WM_OT_collada_import(wmOperatorType *ot) ot->name = "Import COLLADA"; ot->description = "Load a Collada file"; ot->idname = "WM_OT_collada_import"; - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_PRESET; ot->invoke = WM_operator_filesel; ot->exec = wm_collada_import_exec; ot->poll = WM_operator_winactive; - // ot->flag = OPTYPE_PRESET; - ot->ui = wm_collada_import_draw; WM_operator_properties_filesel(ot, diff --git a/source/blender/editors/io/io_obj.c b/source/blender/editors/io/io_obj.c index 08dbc28d722..7559cd47b27 100644 --- a/source/blender/editors/io/io_obj.c +++ b/source/blender/editors/io/io_obj.c @@ -492,7 +492,7 @@ void WM_OT_obj_import(struct wmOperatorType *ot) ot->name = "Import Wavefront OBJ"; ot->description = "Load a Wavefront OBJ scene"; ot->idname = "WM_OT_obj_import"; - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_PRESET; ot->invoke = wm_obj_import_invoke; ot->exec = wm_obj_import_exec; diff --git a/source/blender/editors/io/io_stl_ops.c b/source/blender/editors/io/io_stl_ops.c index c98e5beaf3b..c27d42a07c0 100644 --- a/source/blender/editors/io/io_stl_ops.c +++ b/source/blender/editors/io/io_stl_ops.c @@ -95,7 +95,7 @@ void WM_OT_stl_import(struct wmOperatorType *ot) ot->exec = wm_stl_import_execute; ot->poll = WM_operator_winactive; ot->check = wm_stl_import_check; - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_PRESET; WM_operator_properties_filesel(ot, FILE_TYPE_FOLDER, diff --git a/source/blender/editors/io/io_usd.c b/source/blender/editors/io/io_usd.c index eb80cabcd7f..c776fbf0dd7 100644 --- a/source/blender/editors/io/io_usd.c +++ b/source/blender/editors/io/io_usd.c @@ -500,7 +500,7 @@ void WM_OT_usd_import(struct wmOperatorType *ot) ot->poll = WM_operator_winactive; ot->ui = wm_usd_import_draw; - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_PRESET; WM_operator_properties_filesel(ot, FILE_TYPE_FOLDER | FILE_TYPE_USD, ___ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs
[Bf-blender-cvs] [499af28a35c] master: IO: remove BKE_layer_collection_resync_forbid & allow
Commit: 499af28a35c48244c1ac58bf7a817f0eeb24c7f5 Author: Aras Pranckevicius Date: Mon Oct 10 14:06:36 2022 +0300 Branches: master https://developer.blender.org/rB499af28a35c48244c1ac58bf7a817f0eeb24c7f5 IO: remove BKE_layer_collection_resync_forbid & allow Part of T101073: after the view layer sync was made lazy (D15885), the BKE_layer_collection_resync_forbid and BKE_layer_collection_resync_allow in Alembic/USD/OBJ importers is no longer needed, as long as they do view layer dependent operations (selecting new objects) in a separate loop after creating all the objects. Verified that this does not regress import times for 26k objects OBJ scene (Blender 3.0 splash) and 250k objects USD scene (Moana). === M source/blender/io/alembic/intern/alembic_capi.cc M source/blender/io/usd/intern/usd_capi_import.cc M source/blender/io/wavefront_obj/importer/obj_importer.cc === diff --git a/source/blender/io/alembic/intern/alembic_capi.cc b/source/blender/io/alembic/intern/alembic_capi.cc index 39595089109..b92ce5b4cfb 100644 --- a/source/blender/io/alembic/intern/alembic_capi.cc +++ b/source/blender/io/alembic/intern/alembic_capi.cc @@ -608,15 +608,11 @@ static void import_endjob(void *user_data) lc = BKE_layer_collection_get_active(view_layer); -/* Add all objects to the collection (don't do sync for each object). */ -BKE_layer_collection_resync_forbid(); for (AbcObjectReader *reader : data->readers) { Object *ob = reader->object(); BKE_collection_object_add(data->bmain, lc->collection, ob); } -/* Sync the collection, and do view layer operations. */ -BKE_layer_collection_resync_allow(); -BKE_main_collection_sync(data->bmain); +/* Sync and do the view layer operations. */ BKE_view_layer_synced_ensure(scene, view_layer); for (AbcObjectReader *reader : data->readers) { Object *ob = reader->object(); diff --git a/source/blender/io/usd/intern/usd_capi_import.cc b/source/blender/io/usd/intern/usd_capi_import.cc index 5808c6bc77a..b8cc43beeb9 100644 --- a/source/blender/io/usd/intern/usd_capi_import.cc +++ b/source/blender/io/usd/intern/usd_capi_import.cc @@ -317,8 +317,7 @@ static void import_endjob(void *customdata) lc = BKE_layer_collection_get_active(view_layer); -/* Add all objects to the collection (don't do sync for each object). */ -BKE_layer_collection_resync_forbid(); +/* Add all objects to the collection. */ for (USDPrimReader *reader : data->archive->readers()) { if (!reader) { continue; @@ -330,9 +329,7 @@ static void import_endjob(void *customdata) BKE_collection_object_add(data->bmain, lc->collection, ob); } -/* Sync the collection, and do view layer operations. */ -BKE_layer_collection_resync_allow(); -BKE_main_collection_sync(data->bmain); +/* Sync and do the view layer operations. */ BKE_view_layer_synced_ensure(scene, view_layer); for (USDPrimReader *reader : data->archive->readers()) { if (!reader) { diff --git a/source/blender/io/wavefront_obj/importer/obj_importer.cc b/source/blender/io/wavefront_obj/importer/obj_importer.cc index ccbcce64d65..a42ec47151d 100644 --- a/source/blender/io/wavefront_obj/importer/obj_importer.cc +++ b/source/blender/io/wavefront_obj/importer/obj_importer.cc @@ -42,9 +42,6 @@ static void geometry_to_blender_objects(Main *bmain, { LayerCollection *lc = BKE_layer_collection_get_active(view_layer); - /* Don't do collection syncs for each object, will do once after the loop. */ - BKE_layer_collection_resync_forbid(); - /* Sort objects by name: creating many objects is much faster if the creation * order is sorted by name. */ blender::parallel_sort( @@ -73,12 +70,8 @@ static void geometry_to_blender_objects(Main *bmain, } } - /* Sync the collection after all objects are created. */ - BKE_layer_collection_resync_allow(); - BKE_main_collection_sync(bmain); + /* Do object selections in a separate loop (allows just one view layer sync). */ BKE_view_layer_synced_ensure(scene, view_layer); - - /* After collection sync, select objects in the view layer and do DEG updates. */ for (Object *obj : objects) { Base *base = BKE_view_layer_base_find(view_layer, obj); BKE_view_layer_base_select_and_set_active(view_layer, base); ___ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs
[Bf-blender-cvs] [42b1a7d4c66] master: OBJ: add global scale factor import setting
Commit: 42b1a7d4c660a4304ae8e6e45abc60824211917a Author: Aras Pranckevicius Date: Mon Oct 10 10:10:33 2022 +0300 Branches: master https://developer.blender.org/rB42b1a7d4c660a4304ae8e6e45abc60824211917a OBJ: add global scale factor import setting Requested in D16095 proposal - also USD & Alembic have import scale option; OBJ has an export scale object but the import scale was not there for some reason. === M source/blender/editors/io/io_obj.c M source/blender/io/wavefront_obj/IO_wavefront_obj.h M source/blender/io/wavefront_obj/exporter/obj_export_file_writer.cc M source/blender/io/wavefront_obj/exporter/obj_export_mesh.cc M source/blender/io/wavefront_obj/exporter/obj_export_mesh.hh M source/blender/io/wavefront_obj/exporter/obj_export_nurbs.cc M source/blender/io/wavefront_obj/exporter/obj_export_nurbs.hh M source/blender/io/wavefront_obj/importer/importer_mesh_utils.cc M source/blender/io/wavefront_obj/tests/obj_exporter_tests.cc M source/blender/io/wavefront_obj/tests/obj_exporter_tests.hh M source/blender/io/wavefront_obj/tests/obj_importer_tests.cc === diff --git a/source/blender/editors/io/io_obj.c b/source/blender/editors/io/io_obj.c index cb8eafeb52d..08dbc28d722 100644 --- a/source/blender/editors/io/io_obj.c +++ b/source/blender/editors/io/io_obj.c @@ -81,7 +81,7 @@ static int wm_obj_export_exec(bContext *C, wmOperator *op) export_params.forward_axis = RNA_enum_get(op->ptr, "forward_axis"); export_params.up_axis = RNA_enum_get(op->ptr, "up_axis"); - export_params.scaling_factor = RNA_float_get(op->ptr, "scaling_factor"); + export_params.global_scale = RNA_float_get(op->ptr, "global_scale"); export_params.apply_modifiers = RNA_boolean_get(op->ptr, "apply_modifiers"); export_params.export_eval_mode = RNA_enum_get(op->ptr, "export_eval_mode"); @@ -122,7 +122,7 @@ static void ui_obj_export_settings(uiLayout *layout, PointerRNA *imfptr) col = uiLayoutColumn(box, false); sub = uiLayoutColumnWithHeading(col, false, IFACE_("Limit to")); uiItemR(sub, imfptr, "export_selected_objects", 0, IFACE_("Selected Only"), ICON_NONE); - uiItemR(sub, imfptr, "scaling_factor", 0, NULL, ICON_NONE); + uiItemR(sub, imfptr, "global_scale", 0, NULL, ICON_NONE); row = uiLayoutRow(box, false); uiItemR(row, imfptr, "forward_axis", UI_ITEM_R_EXPAND, IFACE_("Forward Axis"), ICON_NONE); @@ -301,15 +301,16 @@ void WM_OT_obj_export(struct wmOperatorType *ot) RNA_def_property_update_runtime(prop, (void *)forward_axis_update); prop = RNA_def_enum(ot->srna, "up_axis", io_transform_axis, IO_AXIS_Y, "Up Axis", ""); RNA_def_property_update_runtime(prop, (void *)up_axis_update); - RNA_def_float(ot->srna, -"scaling_factor", -1.0f, -0.001f, -1.0f, -"Scale", -"Upscale the object by this factor", -0.01, -1000.0f); + RNA_def_float( + ot->srna, + "global_scale", + 1.0f, + 0.0001f, + 1.0f, + "Scale", + "Value by which to enlarge or shrink the objects with respect to the world's origin", + 0.0001f, + 1.0f); /* File Writer options. */ RNA_def_boolean( ot->srna, "apply_modifiers", true, "Apply Modifiers", "Apply modifiers to exported meshes"); @@ -405,6 +406,7 @@ static int wm_obj_import_exec(bContext *C, wmOperator *op) { struct OBJImportParams import_params; RNA_string_get(op->ptr, "filepath", import_params.filepath); + import_params.global_scale = RNA_float_get(op->ptr, "global_scale"); import_params.clamp_size = RNA_float_get(op->ptr, "clamp_size"); import_params.forward_axis = RNA_enum_get(op->ptr, "forward_axis"); import_params.up_axis = RNA_enum_get(op->ptr, "up_axis"); @@ -459,6 +461,7 @@ static void ui_obj_import_settings(uiLayout *layout, PointerRNA *imfptr) uiItemL(box, IFACE_("Transform"), ICON_OBJECT_DATA); uiLayout *col = uiLayoutColumn(box, false); uiLayout *sub = uiLayoutColumn(col, false); + uiItemR(sub, imfptr, "global_scale", 0, NULL, ICON_NONE); uiItemR(sub, imfptr, "clamp_size", 0, NULL, ICON_NONE); sub = uiLayoutColumn(col, false); @@ -504,6 +507,16 @@ void WM_OT_obj_import(struct wmOperatorType *ot) WM_FILESEL_DIRECTORY | WM_FILESEL_FILES, FILE_DEFAULTDISPLAY,
[Bf-blender-cvs] [bd2f002e711] master: Fix T101685: OBJ importer does not assign proper material if "usemtl" is before "o"
Commit: bd2f002e711ccff13a41d1eaf37a098c02d13d4a Author: Aras Pranckevicius Date: Sun Oct 9 21:21:31 2022 +0300 Branches: master https://developer.blender.org/rBbd2f002e711ccff13a41d1eaf37a098c02d13d4a Fix T101685: OBJ importer does not assign proper material if "usemtl" is before "o" The importer logic was wrongly resetting "current material name" upon encountering a new object ("o" command). However as per OBJ specification, this is incorrect: > Specifies the material name for the element following it. Once a > material is assigned, it cannot be turned off; it can only be > changed. Fixes T101685. Test coverage for this was added in svn tests repo. === M source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc === diff --git a/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc b/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc index bd1c2d32a12..e5ff6bf837d 100644 --- a/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc +++ b/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc @@ -508,6 +508,15 @@ void OBJParser::parse(Vector> _all_geometries, } /* Faces. */ else if (parse_keyword(p, end, "f")) { +/* If we don't have a material index assigned yet, get one. + * It means "usemtl" state came from the previous object. */ +if (state_material_index == -1 && !state_material_name.empty() && +curr_geom->material_indices_.is_empty()) { + curr_geom->material_indices_.add_new(state_material_name, 0); + curr_geom->material_order_.append(state_material_name); + state_material_index = 0; +} + geom_add_polygon(curr_geom, p, end, @@ -524,7 +533,10 @@ void OBJParser::parse(Vector> _all_geometries, else if (parse_keyword(p, end, "o")) { state_shaded_smooth = false; state_group_name = ""; -state_material_name = ""; +/* Reset object-local material index that's used in face infos. + * Note: do not reset the material name; that has to carry over + * into the next object if needed. */ +state_material_index = -1; curr_geom = create_geometry( curr_geom, GEOM_MESH, StringRef(p, end).trim(), r_all_geometries); } ___ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs
[Bf-blender-cvs] [c2fb85282d9] master: OBJ: extend importer tests to test imported material expectations
Commit: c2fb85282d94eb7231b54b2b9d6bbd33f32c7a2a Author: Aras Pranckevicius Date: Sun Oct 9 20:52:23 2022 +0300 Branches: master https://developer.blender.org/rBc2fb85282d94eb7231b54b2b9d6bbd33f32c7a2a OBJ: extend importer tests to test imported material expectations Previously "which material got assigned to an object in the end" was not covered by tests. This is preparation for fixing T101685. === M source/blender/io/wavefront_obj/tests/obj_importer_tests.cc === diff --git a/source/blender/io/wavefront_obj/tests/obj_importer_tests.cc b/source/blender/io/wavefront_obj/tests/obj_importer_tests.cc index 8d1171097b8..1657bf81dc7 100644 --- a/source/blender/io/wavefront_obj/tests/obj_importer_tests.cc +++ b/source/blender/io/wavefront_obj/tests/obj_importer_tests.cc @@ -8,6 +8,7 @@ #include "BKE_curve.h" #include "BKE_customdata.h" #include "BKE_main.h" +#include "BKE_material.h" #include "BKE_mesh.h" #include "BKE_object.h" #include "BKE_scene.h" @@ -22,6 +23,7 @@ #include "DEG_depsgraph_query.h" #include "DNA_curve_types.h" +#include "DNA_material_types.h" #include "DNA_mesh_types.h" #include "DNA_meshdata_types.h" #include "DNA_scene_types.h" @@ -41,6 +43,7 @@ struct Expectation { float3 normal_first; float2 uv_first; float4 color_first = {-1, -1, -1, -1}; + std::string first_mat; }; class obj_importer_test : public BlendfileLoadingBaseTest { @@ -132,6 +135,10 @@ class obj_importer_test : public BlendfileLoadingBaseTest { // int cyclic = (nurb->flagu & CU_NURB_CYCLIC) ? 1 : 0; // EXPECT_EQ(cyclic, exp.mesh_totloop_or_curve_cyclic); } + if (!exp.first_mat.empty()) { +Material *mat = BKE_object_material_get(object, 1); +ASSERT_STREQ(mat ? mat->id.name : "", exp.first_mat.c_str()); + } ++object_index; } DEG_OBJECT_ITER_END; @@ -309,7 +316,42 @@ TEST_F(obj_importer_test, import_materials) { Expectation expect[] = { {"OBCube", OB_MESH, 8, 12, 6, 24, float3(1, 1, -1), float3(-1, 1, 1)}, - {"OBmaterials", OB_MESH, 8, 12, 6, 24, float3(-1, -1, 1), float3(1, -1, -1)}, + {"OBmaterials", + OB_MESH, + 8, + 12, + 6, + 24, + float3(-1, -1, 1), + float3(1, -1, -1), + float3(0), + float2(0), + float4(-1), + "MAno_textures_red"}, + {"OBObjMtlAfter", + OB_MESH, + 3, + 3, + 1, + 3, + float3(3, 0, 0), + float3(5, 0, 0), + float3(0), + float2(0), + float4(-1), + "MAno_textures_red"}, + {"OBObjMtlBefore", + OB_MESH, + 3, + 3, + 1, + 3, + float3(6, 0, 0), + float3(8, 0, 0), + float3(0), + float2(0), + float4(-1), + "MAClay"}, }; import_and_check("materials.obj", expect, std::size(expect), 4, 8); } @@ -327,7 +369,9 @@ TEST_F(obj_importer_test, import_cubes_with_textures_rel) float3(1, 1, -1), float3(-1, -1, 1), float3(0, 1, 0), - float2(0.9935f, 0.0020f)}, + float2(0.9935f, 0.0020f), + float4(-1), + "MAMat_BaseRoughEmissNormal10"}, {"OBCubeTexMul", OB_MESH, 8, @@ -337,7 +381,9 @@ TEST_F(obj_importer_test, import_cubes_with_textures_rel) float3(4, -2, -1), float3(2, -4, 1), float3(0, 1, 0), - float2(0.9935f, 0.0020f)}, + float2(0.9935f, 0.0020f), + float4(-1), + "MAMat_BaseMul"}, {"OBCubeTiledTex", OB_MESH, 8, @@ -347,7 +393,9 @@ TEST_F(obj_importer_test, import_cubes_with_textures_rel) float3(4, 1, -1), float3(2, -1, 1), float3(0, 1, 0), - float2(0.9935f, 0.0020f)}, + float2(0.9935f, 0.0020f), + float4(-1), + "MAMat_BaseTiled"}, {"OBCubeTiledTexFromAnotherFolder", OB_MESH, 8, @@ -357,7 +405,9 @@ TEST_F(obj_importer_test, import_cubes_with_textures_rel) float3(7, 1, -1), float3(5, -1, 1), float3(0, 1, 0), - float2(0.9935f, 0.0020f)}, + float2(0.9935f, 0.0020f), + float4(-1), + "MAMat_EmissTiledAnotherFolder"}, }; import_and_check("cubes_with_textures_rel.obj", expect, std::size(expect), 4, 4); } @@ -455,7 +505,10 @@ TEST_F(obj_importer_test, import_all_objects) 26, float3(28, 1, -1), float3(26, 1, 1), - float3(-1, 0, 0)}, + float3(-1, 0, 0), + float2(0), + float4(-1), + "MARed"}, {"OBNurbsCircle&q
[Bf-blender-cvs] [3f30c1c042b] blender-v3.3-release: Fix T101487: New OBJ importer handles UVs incorrectly when some faces of an object don't have UVs
Commit: 3f30c1c042b3852882139d7cabe0c223da1e0e14 Author: Aras Pranckevicius Date: Mon Oct 3 11:07:35 2022 +0300 Branches: blender-v3.3-release https://developer.blender.org/rB3f30c1c042b3852882139d7cabe0c223da1e0e14 Fix T101487: New OBJ importer handles UVs incorrectly when some faces of an object don't have UVs The UV data filling logic was incorrectly just skipping over loop entries that don't have a UV coordinate, instead of assigning the default zero UV for them. This was a problem only for meshes where some faces did have UVs, but some other faces did not (T101487). === M source/blender/io/wavefront_obj/importer/obj_import_mesh.cc === diff --git a/source/blender/io/wavefront_obj/importer/obj_import_mesh.cc b/source/blender/io/wavefront_obj/importer/obj_import_mesh.cc index 6b19d6573af..ab6c81f798b 100644 --- a/source/blender/io/wavefront_obj/importer/obj_import_mesh.cc +++ b/source/blender/io/wavefront_obj/importer/obj_import_mesh.cc @@ -268,12 +268,13 @@ void MeshFromGeometry::create_uv_verts(Mesh *mesh) for (const PolyElem _face : mesh_geometry_.face_elements_) { for (int idx = 0; idx < curr_face.corner_count_; ++idx) { const PolyCorner _corner = mesh_geometry_.face_corners_[curr_face.start_index_ + idx]; - if (curr_corner.uv_vert_index >= 0 && - curr_corner.uv_vert_index < global_vertices_.uv_vertices.size()) { -const float2 _src = global_vertices_.uv_vertices[curr_corner.uv_vert_index]; -copy_v2_v2(mluv_dst[tot_loop_idx].uv, mluv_src); -tot_loop_idx++; + const int uv_index = curr_corner.uv_vert_index; + float2 uv(0, 0); + if (uv_index >= 0 && uv_index < global_vertices_.uv_vertices.size()) { +uv = global_vertices_.uv_vertices[uv_index]; } + copy_v2_v2(mluv_dst[tot_loop_idx].uv, uv); + tot_loop_idx++; } } } ___ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs
[Bf-blender-cvs] [7029f11439c] master: Fix T101487: New OBJ importer handles UVs incorrectly when some faces of an object don't have UVs
Commit: 7029f11439c21d64e3d43133209d69eff62026b8 Author: Aras Pranckevicius Date: Mon Oct 3 11:07:35 2022 +0300 Branches: master https://developer.blender.org/rB7029f11439c21d64e3d43133209d69eff62026b8 Fix T101487: New OBJ importer handles UVs incorrectly when some faces of an object don't have UVs The UV data filling logic was incorrectly just skipping over loop entries that don't have a UV coordinate, instead of assigning the default zero UV for them. This was a problem only for meshes where some faces did have UVs, but some other faces did not (T101487). === M source/blender/io/wavefront_obj/importer/obj_import_mesh.cc === diff --git a/source/blender/io/wavefront_obj/importer/obj_import_mesh.cc b/source/blender/io/wavefront_obj/importer/obj_import_mesh.cc index 4a4d1eeadb6..33ece88d3d4 100644 --- a/source/blender/io/wavefront_obj/importer/obj_import_mesh.cc +++ b/source/blender/io/wavefront_obj/importer/obj_import_mesh.cc @@ -275,12 +275,13 @@ void MeshFromGeometry::create_uv_verts(Mesh *mesh) for (const PolyElem _face : mesh_geometry_.face_elements_) { for (int idx = 0; idx < curr_face.corner_count_; ++idx) { const PolyCorner _corner = mesh_geometry_.face_corners_[curr_face.start_index_ + idx]; - if (curr_corner.uv_vert_index >= 0 && - curr_corner.uv_vert_index < global_vertices_.uv_vertices.size()) { -const float2 _src = global_vertices_.uv_vertices[curr_corner.uv_vert_index]; -copy_v2_v2(mluv_dst[tot_loop_idx].uv, mluv_src); -tot_loop_idx++; + const int uv_index = curr_corner.uv_vert_index; + float2 uv(0, 0); + if (uv_index >= 0 && uv_index < global_vertices_.uv_vertices.size()) { +uv = global_vertices_.uv_vertices[uv_index]; } + copy_v2_v2(mluv_dst[tot_loop_idx].uv, uv); + tot_loop_idx++; } } } ___ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs
[Bf-blender-cvs] [07b547ef96f] blender-v3.3-release: Fix T100797: C++ exporters do not remember the path on subsequent exports
Commit: 07b547ef96f1a607e57202e3badb6ffa651e1c41 Author: Aras Pranckevicius Date: Wed Sep 7 11:47:29 2022 +0300 Branches: blender-v3.3-release https://developer.blender.org/rB07b547ef96f1a607e57202e3badb6ffa651e1c41 Fix T100797: C++ exporters do not remember the path on subsequent exports Most/all C++ based IO code had a pattern of doing using RNA_struct_property_is_set to check whether a default path needs to be set. However, it returns false for properties restored from "previous operator settings" (property restoration code sets IDP_FLAG_GHOST flag on them, which "is set" sees and goes "nope, not set"). The fix here is to apply similar logic as 10 years ago in the T32855 fix (rBdb250a4): use RNA_struct_property_is_set_ex instead. Reviewed By: Campbell Barton Differential Revision: https://developer.blender.org/D15904 === M source/blender/editors/io/io_alembic.c M source/blender/editors/io/io_collada.c M source/blender/editors/io/io_gpencil_export.c M source/blender/editors/io/io_gpencil_import.c M source/blender/editors/io/io_obj.c M source/blender/editors/io/io_stl_ops.c M source/blender/editors/io/io_usd.c === diff --git a/source/blender/editors/io/io_alembic.c b/source/blender/editors/io/io_alembic.c index 0068586730f..ff69a94b249 100644 --- a/source/blender/editors/io/io_alembic.c +++ b/source/blender/editors/io/io_alembic.c @@ -75,7 +75,7 @@ static int wm_alembic_export_invoke(bContext *C, wmOperator *op, const wmEvent * RNA_boolean_set(op->ptr, "init_scene_frame_range", true); - if (!RNA_struct_property_is_set(op->ptr, "filepath")) { + if (!RNA_struct_property_is_set_ex(op->ptr, "filepath", false)) { Main *bmain = CTX_data_main(C); char filepath[FILE_MAX]; @@ -99,7 +99,7 @@ static int wm_alembic_export_invoke(bContext *C, wmOperator *op, const wmEvent * static int wm_alembic_export_exec(bContext *C, wmOperator *op) { - if (!RNA_struct_property_is_set(op->ptr, "filepath")) { + if (!RNA_struct_property_is_set_ex(op->ptr, "filepath", false)) { BKE_report(op->reports, RPT_ERROR, "No filename given"); return OPERATOR_CANCELLED; } @@ -619,7 +619,7 @@ static int wm_alembic_import_invoke(bContext *C, wmOperator *op, const wmEvent * static int wm_alembic_import_exec(bContext *C, wmOperator *op) { - if (!RNA_struct_property_is_set(op->ptr, "filepath")) { + if (!RNA_struct_property_is_set_ex(op->ptr, "filepath", false)) { BKE_report(op->reports, RPT_ERROR, "No filename given"); return OPERATOR_CANCELLED; } diff --git a/source/blender/editors/io/io_collada.c b/source/blender/editors/io/io_collada.c index c491e7a5815..5ebf76295d7 100644 --- a/source/blender/editors/io/io_collada.c +++ b/source/blender/editors/io/io_collada.c @@ -38,7 +38,7 @@ static int wm_collada_export_invoke(bContext *C, wmOperator *op, const wmEvent * { Main *bmain = CTX_data_main(C); - if (!RNA_struct_property_is_set(op->ptr, "filepath")) { + if (!RNA_struct_property_is_set_ex(op->ptr, "filepath", false)) { char filepath[FILE_MAX]; const char *blendfile_path = BKE_main_blendfile_path(bmain); @@ -98,7 +98,7 @@ static int wm_collada_export_exec(bContext *C, wmOperator *op) int export_count; int sample_animations; - if (!RNA_struct_property_is_set(op->ptr, "filepath")) { + if (!RNA_struct_property_is_set_ex(op->ptr, "filepath", false)) { BKE_report(op->reports, RPT_ERROR, "No filename given"); return OPERATOR_CANCELLED; } @@ -709,7 +709,7 @@ static int wm_collada_import_exec(bContext *C, wmOperator *op) int keep_bind_info; ImportSettings import_settings; - if (!RNA_struct_property_is_set(op->ptr, "filepath")) { + if (!RNA_struct_property_is_set_ex(op->ptr, "filepath", false)) { BKE_report(op->reports, RPT_ERROR, "No filename given"); return OPERATOR_CANCELLED; } diff --git a/source/blender/editors/io/io_gpencil_export.c b/source/blender/editors/io/io_gpencil_export.c index 6db68a26232..0b59d86db4f 100644 --- a/source/blender/editors/io/io_gpencil_export.c +++ b/source/blender/editors/io/io_gpencil_export.c @@ -74,7 +74,7 @@ static void gpencil_export_common_props_definition(wmOperatorType *ot) static void set_export_filepath(bContext *C, wmOperator *op, const char *extension) { - if (!RNA_struct_property_is_set(op->ptr, "filepath")) { + if (!RNA_struct_property_is_set_ex(op->ptr, "filepath", false)) { Main *bmain = CTX_data_main(C); char filepath[FILE_MAX]; @@ -121,7 +121,7 @@ static int wm_gpencil_export_svg_exec(bContext *C, wmOpera
[Bf-blender-cvs] [dba599c8064] blender-v3.3-release: obj: support importing multiple files at once
Commit: dba599c8064731df4b68b7e983fba1ce2d41c4eb Author: Aras Pranckevicius Date: Thu Aug 11 17:05:54 2022 +0300 Branches: blender-v3.3-release https://developer.blender.org/rBdba599c8064731df4b68b7e983fba1ce2d41c4eb obj: support importing multiple files at once Implemented the same way as STL or GPencil SVG importers: loop over the input files, import one by one. Has been requested by the community for quite a long time (e.g. https://blender.community/c/rightclickselect/Jhbbbc/), as well as 3rd party addons to implement just this (https://github.com/p2or/blender-batch-import-wavefront-obj). === M source/blender/editors/io/io_obj.c M source/blender/io/wavefront_obj/IO_wavefront_obj.cc M source/blender/io/wavefront_obj/IO_wavefront_obj.h M source/blender/io/wavefront_obj/importer/obj_importer.cc M source/blender/io/wavefront_obj/tests/obj_importer_tests.cc === diff --git a/source/blender/editors/io/io_obj.c b/source/blender/editors/io/io_obj.c index c61a34679bc..aec8467ed70 100644 --- a/source/blender/editors/io/io_obj.c +++ b/source/blender/editors/io/io_obj.c @@ -406,11 +406,6 @@ static int wm_obj_import_invoke(bContext *C, wmOperator *op, const wmEvent *UNUS static int wm_obj_import_exec(bContext *C, wmOperator *op) { - if (!RNA_struct_property_is_set(op->ptr, "filepath")) { -BKE_report(op->reports, RPT_ERROR, "No filename given"); -return OPERATOR_CANCELLED; - } - struct OBJImportParams import_params; RNA_string_get(op->ptr, "filepath", import_params.filepath); import_params.clamp_size = RNA_float_get(op->ptr, "clamp_size"); @@ -419,8 +414,35 @@ static int wm_obj_import_exec(bContext *C, wmOperator *op) import_params.import_vertex_groups = RNA_boolean_get(op->ptr, "import_vertex_groups"); import_params.validate_meshes = RNA_boolean_get(op->ptr, "validate_meshes"); import_params.relative_paths = ((U.flag & USER_RELPATHS) != 0); - - OBJ_import(C, _params); + import_params.clear_selection = true; + + int files_len = RNA_collection_length(op->ptr, "files"); + if (files_len) { +/* Importing multiple files: loop over them and import one by one. */ +PointerRNA fileptr; +PropertyRNA *prop; +char dir_only[FILE_MAX], file_only[FILE_MAX]; + +RNA_string_get(op->ptr, "directory", dir_only); +prop = RNA_struct_find_property(op->ptr, "files"); +for (int i = 0; i < files_len; i++) { + RNA_property_collection_lookup_int(op->ptr, prop, i, ); + RNA_string_get(, "name", file_only); + BLI_join_dirfile( + import_params.filepath, sizeof(import_params.filepath), dir_only, file_only); + import_params.clear_selection = (i == 0); + OBJ_import(C, _params); +} + } + else if (RNA_struct_property_is_set(op->ptr, "filepath")) { +/* Importing one file. */ +RNA_string_get(op->ptr, "filepath", import_params.filepath); +OBJ_import(C, _params); + } + else { +BKE_report(op->reports, RPT_ERROR, "No filename given"); +return OPERATOR_CANCELLED; + } Scene *scene = CTX_data_scene(C); WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, scene); @@ -481,7 +503,8 @@ void WM_OT_obj_import(struct wmOperatorType *ot) FILE_TYPE_FOLDER, FILE_BLENDER, FILE_OPENFILE, - WM_FILESEL_FILEPATH | WM_FILESEL_SHOW_PROPS, + WM_FILESEL_FILEPATH | WM_FILESEL_SHOW_PROPS | + WM_FILESEL_DIRECTORY | WM_FILESEL_FILES, FILE_DEFAULTDISPLAY, FILE_SORT_DEFAULT); RNA_def_float( diff --git a/source/blender/io/wavefront_obj/IO_wavefront_obj.cc b/source/blender/io/wavefront_obj/IO_wavefront_obj.cc index fb0b4a1aca9..2fd2973ee73 100644 --- a/source/blender/io/wavefront_obj/IO_wavefront_obj.cc +++ b/source/blender/io/wavefront_obj/IO_wavefront_obj.cc @@ -4,6 +4,7 @@ * \ingroup obj */ +#include "BLI_path_util.h" #include "BLI_timeit.hh" #include "IO_wavefront_obj.h" @@ -11,14 +12,26 @@ #include "obj_exporter.hh" #include "obj_importer.hh" +using namespace blender::timeit; + +static void report_duration(const char *job, const TimePoint _time, const char *path) +{ + Nanoseconds duration = Clock::now() - start_time; + std::cout << "OBJ " << job << " of '" << BLI_path_basename(path) << "' took "; + print_duration(duration); + std::cout << '\n'; +} + void OBJ_export(bContext *C, const OBJExportParams *export_par
[Bf-blender-cvs] [761da576b0a] blender-v3.3-release: Fix T96297: obj: improve layout of UI fields and axis validation
Commit: 761da576b0a9166e8598d3cbf3bbbaca3bc0b315 Author: Aras Pranckevicius Date: Thu Sep 8 11:43:26 2022 +0300 Branches: blender-v3.3-release https://developer.blender.org/rB761da576b0a9166e8598d3cbf3bbbaca3bc0b315 Fix T96297: obj: improve layout of UI fields and axis validation Implement ideas from T96297: - Fix "invalid axis settings" (both forward & up along the same direction) validation: now similar to the Python based code, when invalid axis is applied, the other axis is changed to not conflict. - Make axis enums be expanded inside the row, similar to Collada UI. - Move "selected only" near the top, similar to how it's in Collada, USD, FBX and glTF export UIs. - Move animation export options to the bottom. === M source/blender/editors/io/io_obj.c M source/blender/io/wavefront_obj/IO_wavefront_obj.h === diff --git a/source/blender/editors/io/io_obj.c b/source/blender/editors/io/io_obj.c index 662ff601e29..7c931def2e0 100644 --- a/source/blender/editors/io/io_obj.c +++ b/source/blender/editors/io/io_obj.c @@ -126,28 +126,24 @@ static void ui_obj_export_settings(uiLayout *layout, PointerRNA *imfptr) uiLayoutSetPropSep(layout, true); uiLayoutSetPropDecorate(layout, false); - /* Animation options. */ - uiLayout *box = uiLayoutBox(layout); - uiItemL(box, IFACE_("Animation"), ICON_ANIM); - uiLayout *col = uiLayoutColumn(box, false); - uiLayout *sub = uiLayoutColumn(col, false); - uiItemR(sub, imfptr, "export_animation", 0, NULL, ICON_NONE); - sub = uiLayoutColumn(sub, true); - uiItemR(sub, imfptr, "start_frame", 0, IFACE_("Frame Start"), ICON_NONE); - uiItemR(sub, imfptr, "end_frame", 0, IFACE_("End"), ICON_NONE); - uiLayoutSetEnabled(sub, export_animation); + uiLayout *box, *col, *sub, *row; /* Object Transform options. */ box = uiLayoutBox(layout); uiItemL(box, IFACE_("Object Properties"), ICON_OBJECT_DATA); col = uiLayoutColumn(box, false); - sub = uiLayoutColumn(col, false); - uiItemR(sub, imfptr, "forward_axis", 0, IFACE_("Axis Forward"), ICON_NONE); - uiItemR(sub, imfptr, "up_axis", 0, IFACE_("Up"), ICON_NONE); - sub = uiLayoutColumn(col, false); + sub = uiLayoutColumnWithHeading(col, false, IFACE_("Limit to")); + uiItemR(sub, imfptr, "export_selected_objects", 0, IFACE_("Selected Only"), ICON_NONE); uiItemR(sub, imfptr, "scaling_factor", 0, NULL, ICON_NONE); + + row = uiLayoutRow(box, false); + uiItemR(row, imfptr, "forward_axis", UI_ITEM_R_EXPAND, IFACE_("Foward Axis"), ICON_NONE); + row = uiLayoutRow(box, false); + uiItemR(row, imfptr, "up_axis", UI_ITEM_R_EXPAND, IFACE_("Up Axis"), ICON_NONE); + + col = uiLayoutColumn(box, false); + sub = uiLayoutColumn(col, false); sub = uiLayoutColumnWithHeading(col, false, IFACE_("Objects")); - uiItemR(sub, imfptr, "export_selected_objects", 0, IFACE_("Selected Only"), ICON_NONE); uiItemR(sub, imfptr, "apply_modifiers", 0, IFACE_("Apply Modifiers"), ICON_NONE); uiItemR(sub, imfptr, "export_eval_mode", 0, IFACE_("Properties"), ICON_NONE); sub = uiLayoutColumn(sub, false); @@ -156,7 +152,7 @@ static void ui_obj_export_settings(uiLayout *layout, PointerRNA *imfptr) /* Options for what to write. */ box = uiLayoutBox(layout); - uiItemL(box, IFACE_("Geometry Export"), ICON_EXPORT); + uiItemL(box, IFACE_("Geometry"), ICON_EXPORT); col = uiLayoutColumn(box, false); sub = uiLayoutColumnWithHeading(col, false, IFACE_("Export")); uiItemR(sub, imfptr, "export_uv", 0, IFACE_("UV Coordinates"), ICON_NONE); @@ -178,6 +174,17 @@ static void ui_obj_export_settings(uiLayout *layout, PointerRNA *imfptr) sub = uiLayoutColumn(sub, false); uiLayoutSetEnabled(sub, export_smooth_groups); uiItemR(sub, imfptr, "smooth_group_bitflags", 0, IFACE_("Smooth Group Bitflags"), ICON_NONE); + + /* Animation options. */ + box = uiLayoutBox(layout); + uiItemL(box, IFACE_("Animation"), ICON_ANIM); + col = uiLayoutColumn(box, false); + sub = uiLayoutColumn(col, false); + uiItemR(sub, imfptr, "export_animation", 0, NULL, ICON_NONE); + sub = uiLayoutColumn(sub, true); + uiItemR(sub, imfptr, "start_frame", 0, IFACE_("Frame Start"), ICON_NONE); + uiItemR(sub, imfptr, "end_frame", 0, IFACE_("End"), ICON_NONE); + uiLayoutSetEnabled(sub, export_animation); } static void wm_obj_export_draw(bContext *UNUSED(C), wmOperator *op) @@ -223,15 +230,30 @@ static bool wm_obj_export_check(bContext *C, wmOperator *op) RNA_int_set(op->ptr,
[Bf-blender-cvs] [61334344786] blender-v3.3-release: Fix T100669: OBJ exporter does not properly export image sequence texture names
Commit: 613343447861eae1aef90786802bac28a1adaea6 Author: Aras Pranckevicius Date: Wed Sep 7 17:56:06 2022 +0300 Branches: blender-v3.3-release https://developer.blender.org/rB613343447861eae1aef90786802bac28a1adaea6 Fix T100669: OBJ exporter does not properly export image sequence texture names When exporting OBJ/MTL animation, texture file paths of image sequences were not adjusted to contain the correct frame number. Fixes T100669. Also, the OBJ exporter was wrongly writing to the same .mtl file for each exported frame, which is a regression compared to the legacy Python exporter. === M source/blender/io/wavefront_obj/exporter/obj_export_mtl.cc M source/blender/io/wavefront_obj/exporter/obj_exporter.cc === diff --git a/source/blender/io/wavefront_obj/exporter/obj_export_mtl.cc b/source/blender/io/wavefront_obj/exporter/obj_export_mtl.cc index 4ed148ec64e..2a6311d15db 100644 --- a/source/blender/io/wavefront_obj/exporter/obj_export_mtl.cc +++ b/source/blender/io/wavefront_obj/exporter/obj_export_mtl.cc @@ -111,28 +111,41 @@ static const bNode *get_node_of_type(Span socket return nullptr; } -/** +/* * From a texture image shader node, get the image's filepath. * If packed image is found, only the file "name" is returned. */ -static const char *get_image_filepath(const bNode *tex_node) +static std::string get_image_filepath(const bNode *tex_node) { if (!tex_node) { -return nullptr; +return ""; } Image *tex_image = reinterpret_cast(tex_node->id); if (!tex_image || !BKE_image_has_filepath(tex_image)) { -return nullptr; +return ""; } - const char *path = tex_image->filepath; + if (BKE_image_has_packedfile(tex_image)) { /* Put image in the same directory as the .MTL file. */ -path = BLI_path_slash_rfind(path) + 1; +const char *filename = BLI_path_slash_rfind(tex_image->filepath) + 1; fprintf(stderr, "Packed image found:'%s'. Unpack and place the image in the same " "directory as the .MTL file.\n", -path); +filename); +return filename; } + + char path[FILE_MAX]; + BLI_strncpy(path, tex_image->filepath, FILE_MAX); + + if (tex_image->source == IMA_SRC_SEQUENCE) { +char head[FILE_MAX], tail[FILE_MAX]; +unsigned short numlen; +int framenr = static_cast(tex_node->storage)->iuser.framenr; +BLI_path_sequence_decode(path, head, tail, ); +BLI_path_sequence_encode(path, head, tail, numlen, framenr); + } + return path; } @@ -302,8 +315,8 @@ static void store_image_textures(const nodes::NodeRef *bsdf_node, if (!tex_node) { continue; } -const char *tex_image_filepath = get_image_filepath(tex_node); -if (!tex_image_filepath) { +const std::string tex_image_filepath = get_image_filepath(tex_node); +if (tex_image_filepath.empty()) { continue; } diff --git a/source/blender/io/wavefront_obj/exporter/obj_exporter.cc b/source/blender/io/wavefront_obj/exporter/obj_exporter.cc index 77d4f6268bc..421e814a0a6 100644 --- a/source/blender/io/wavefront_obj/exporter/obj_exporter.cc +++ b/source/blender/io/wavefront_obj/exporter/obj_exporter.cc @@ -268,7 +268,7 @@ void export_frame(Depsgraph *depsgraph, const OBJExportParams _params, co std::unique_ptr mtl_writer = nullptr; if (export_params.export_materials) { try { - mtl_writer = std::make_unique(export_params.filepath); + mtl_writer = std::make_unique(filepath); } catch (const std::system_error ) { print_exception_error(ex); ___ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs
[Bf-blender-cvs] [faccd880385] blender-v3.3-release: Fix T100887: Some C++ importers/exporters (e.g. OBJ) reset file dialog Sort By mode
Commit: faccd880385b5ce61ca6aeacce65964becd469f5 Author: Aras Pranckevicius Date: Thu Sep 8 13:07:31 2022 +0300 Branches: blender-v3.3-release https://developer.blender.org/rBfaccd880385b5ce61ca6aeacce65964becd469f5 Fix T100887: Some C++ importers/exporters (e.g. OBJ) reset file dialog Sort By mode A couple years ago D8598 made it so that C++ operators generally should use "default" sort mode, which remembers previously used sort setting. Back then all the places that needed it got changed to use this "default" one, but since then some more IO code landed, where seemingly by accident it used "sort by file name": - USD importer, - Grease Pencil exporter, - OBJ importer & exporter, - STL importer. Reviewed By: Julian Eisel Differential Revision: https://developer.blender.org/D15906 === M source/blender/editors/io/io_gpencil_export.c M source/blender/editors/io/io_obj.c M source/blender/editors/io/io_stl_ops.c M source/blender/editors/io/io_usd.c === diff --git a/source/blender/editors/io/io_gpencil_export.c b/source/blender/editors/io/io_gpencil_export.c index 3f905dd7de0..6db68a26232 100644 --- a/source/blender/editors/io/io_gpencil_export.c +++ b/source/blender/editors/io/io_gpencil_export.c @@ -233,7 +233,7 @@ void WM_OT_gpencil_export_svg(wmOperatorType *ot) FILE_SAVE, WM_FILESEL_FILEPATH | WM_FILESEL_SHOW_PROPS, FILE_DEFAULTDISPLAY, - FILE_SORT_ALPHA); + FILE_SORT_DEFAULT); gpencil_export_common_props_definition(ot); @@ -391,7 +391,7 @@ void WM_OT_gpencil_export_pdf(wmOperatorType *ot) FILE_SAVE, WM_FILESEL_FILEPATH | WM_FILESEL_SHOW_PROPS, FILE_DEFAULTDISPLAY, - FILE_SORT_ALPHA); + FILE_SORT_DEFAULT); static const EnumPropertyItem gpencil_export_frame_items[] = { {GP_EXPORT_FRAME_ACTIVE, "ACTIVE", 0, "Active", "Include only active frame"}, diff --git a/source/blender/editors/io/io_obj.c b/source/blender/editors/io/io_obj.c index 7c931def2e0..c61a34679bc 100644 --- a/source/blender/editors/io/io_obj.c +++ b/source/blender/editors/io/io_obj.c @@ -278,7 +278,7 @@ void WM_OT_obj_export(struct wmOperatorType *ot) FILE_SAVE, WM_FILESEL_FILEPATH | WM_FILESEL_SHOW_PROPS, FILE_DEFAULTDISPLAY, - FILE_SORT_ALPHA); + FILE_SORT_DEFAULT); /* Animation options. */ RNA_def_boolean(ot->srna, @@ -483,7 +483,7 @@ void WM_OT_obj_import(struct wmOperatorType *ot) FILE_OPENFILE, WM_FILESEL_FILEPATH | WM_FILESEL_SHOW_PROPS, FILE_DEFAULTDISPLAY, - FILE_SORT_ALPHA); + FILE_SORT_DEFAULT); RNA_def_float( ot->srna, "clamp_size", diff --git a/source/blender/editors/io/io_stl_ops.c b/source/blender/editors/io/io_stl_ops.c index 7db32cd6f18..ddf1bde0c1d 100644 --- a/source/blender/editors/io/io_stl_ops.c +++ b/source/blender/editors/io/io_stl_ops.c @@ -104,7 +104,7 @@ void WM_OT_stl_import(struct wmOperatorType *ot) WM_FILESEL_FILEPATH | WM_FILESEL_FILES | WM_FILESEL_DIRECTORY | WM_FILESEL_SHOW_PROPS, FILE_DEFAULTDISPLAY, - FILE_SORT_ALPHA); + FILE_SORT_DEFAULT); RNA_def_float(ot->srna, "global_scale", 1.0f, 1e-6f, 1e6f, "Scale", "", 0.001f, 1000.0f); RNA_def_boolean(ot->srna, diff --git a/source/blender/editors/io/io_usd.c b/source/blender/editors/io/io_usd.c index a59cdf60243..a33bd905a29 100644 --- a/source/blender/editors/io/io_usd.c +++ b/source/blender/editors/io/io_usd.c @@ -500,7 +500,7 @@ void WM_OT_usd_import(struct wmOperatorType *ot) FILE_OPENFILE, WM_FILESEL_FILEPATH | WM_FILESEL_RELPATH | WM_FILESEL_SHOW_PROPS, FILE_DEFAULTDISPLAY, - FILE_SORT_ALPHA); + FILE_SORT_DEFAULT); RNA_def_float( ot->srna, ___ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs
[Bf-blender-cvs] [e00f76c6a8c] master: ViewLayer: fix missing sync in object APIs (fixes T101128, T101204)
Commit: e00f76c6a8ccaafbdd09b069923176ad23e3ce7e Author: Aras Pranckevicius Date: Tue Sep 20 09:45:18 2022 +0300 Branches: master https://developer.blender.org/rBe00f76c6a8ccaafbdd09b069923176ad23e3ce7e ViewLayer: fix missing sync in object APIs (fixes T101128, T101204) Since D15885, most (all?) python based importers are failing with an error like RuntimeError: Error: Object 'Cube' can't be selected because it is not in View Layer, whenever they try to mark just-created objects selected via obj.select_set(True). Happens at least in FBX and (legacy) OBJ importers -- effectively they end up creating just the first imported object before failing with this exception. Looks like BKE_view_layer_synced_ensure calls were missing before BKE_view_layer_base_find in rna_object_api.c. Reviewed By: Campbell Barton Differential Revision: https://developer.blender.org/D16004 === M source/blender/makesrna/intern/rna_object_api.c === diff --git a/source/blender/makesrna/intern/rna_object_api.c b/source/blender/makesrna/intern/rna_object_api.c index 0b8cf601bfd..c99c5fb723d 100644 --- a/source/blender/makesrna/intern/rna_object_api.c +++ b/source/blender/makesrna/intern/rna_object_api.c @@ -77,13 +77,36 @@ static const EnumPropertyItem space_items[] = { # include "MEM_guardedalloc.h" -static void rna_Object_select_set( -Object *ob, bContext *C, ReportList *reports, bool select, ViewLayer *view_layer) +static Base *find_view_layer_base_with_synced_ensure( +Object *ob, bContext *C, PointerRNA *view_layer_ptr, Scene **r_scene, ViewLayer **r_view_layer) { - if (view_layer == NULL) { + Scene *scene; + ViewLayer *view_layer; + if (view_layer_ptr->data) { +scene = (Scene *)view_layer_ptr->owner_id; +view_layer = view_layer_ptr->data; + } + else { +scene = CTX_data_scene(C); view_layer = CTX_data_view_layer(C); } - Base *base = BKE_view_layer_base_find(view_layer, ob); + if (r_scene != NULL) { +*r_scene = scene; + } + if (r_view_layer != NULL) { +*r_view_layer = view_layer; + } + + BKE_view_layer_synced_ensure(scene, view_layer); + return BKE_view_layer_base_find(view_layer, ob); +} + +static void rna_Object_select_set( +Object *ob, bContext *C, ReportList *reports, bool select, PointerRNA *view_layer_ptr) +{ + Scene *scene; + ViewLayer *view_layer; + Base *base = find_view_layer_base_with_synced_ensure(ob, C, view_layer_ptr, , _layer); if (!base) { if (select) { @@ -98,19 +121,14 @@ static void rna_Object_select_set( ED_object_base_select(base, select ? BA_SELECT : BA_DESELECT); - Scene *scene = CTX_data_scene(C); DEG_id_tag_update(>id, ID_RECALC_SELECT); WM_main_add_notifier(NC_SCENE | ND_OB_SELECT, scene); ED_outliner_select_sync_from_object_tag(C); } -static bool rna_Object_select_get(Object *ob, bContext *C, ViewLayer *view_layer) +static bool rna_Object_select_get(Object *ob, bContext *C, PointerRNA *view_layer_ptr) { - if (view_layer == NULL) { -view_layer = CTX_data_view_layer(C); - } - Base *base = BKE_view_layer_base_find(view_layer, ob); - + Base *base = find_view_layer_base_with_synced_ensure(ob, C, view_layer_ptr, NULL, NULL); if (!base) { return false; } @@ -119,13 +137,11 @@ static bool rna_Object_select_get(Object *ob, bContext *C, ViewLayer *view_layer } static void rna_Object_hide_set( -Object *ob, bContext *C, ReportList *reports, bool hide, ViewLayer *view_layer) +Object *ob, bContext *C, ReportList *reports, bool hide, PointerRNA *view_layer_ptr) { - if (view_layer == NULL) { -view_layer = CTX_data_view_layer(C); - } - Base *base = BKE_view_layer_base_find(view_layer, ob); - + Scene *scene; + ViewLayer *view_layer; + Base *base = find_view_layer_base_with_synced_ensure(ob, C, view_layer_ptr, , _layer); if (!base) { if (hide) { BKE_reportf(reports, @@ -144,19 +160,14 @@ static void rna_Object_hide_set( base->flag &= ~BASE_HIDDEN; } - Scene *scene = CTX_data_scene(C); BKE_view_layer_need_resync_tag(view_layer); DEG_id_tag_update(>id, ID_RECALC_BASE_FLAGS); WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, scene); } -static bool rna_Object_hide_get(Object *ob, bContext *C, ViewLayer *view_layer) +static bool rna_Object_hide_get(Object *ob, bContext *C, PointerRNA *view_layer_ptr) { - if (view_layer == NULL) { -view_layer = CTX_data_view_layer(C); - } - Base *base = BKE_view_layer_base_find(view_layer, ob); - + Base *base = find_view_layer_base_with_synced_ensure(ob, C, view_layer_ptr, NULL, NULL); if (!base) { return false; } @@ -164,15 +175,15 @@ static bool rna_Object_hide_get(Object *ob, bContext *C, ViewLayer *view_layer) return ((base->flag & BASE_HIDDEN) != 0); } -static bool rna_Object_visible_get(Object *ob, bCon
[Bf-blender-cvs] [42fe0b6dfcc] master: Attributes: add color_srgb property to FloatColorAttributeValue and ByteColorAttributeValue
Commit: 42fe0b6dfcc276f5db1461add1e24aea55ca1131 Author: Aras Pranckevicius Date: Wed Sep 14 22:50:46 2022 +0300 Branches: master https://developer.blender.org/rB42fe0b6dfcc276f5db1461add1e24aea55ca1131 Attributes: add color_srgb property to FloatColorAttributeValue and ByteColorAttributeValue This patch adds color_srgb property to FloatColorAttributeValue and ByteColorAttributeValue, so Python code can do `layer.data.foreach_get("color_srgb", ...)` to fetch the data efficiently, if it needs it in sRGB color space. Reviewed By: Bastien Montagne Differential Revision: https://developer.blender.org/D15966 === M source/blender/makesrna/intern/rna_attribute.c === diff --git a/source/blender/makesrna/intern/rna_attribute.c b/source/blender/makesrna/intern/rna_attribute.c index 5e17f22ecf5..4bf55bcc701 100644 --- a/source/blender/makesrna/intern/rna_attribute.c +++ b/source/blender/makesrna/intern/rna_attribute.c @@ -321,6 +321,36 @@ static void rna_ByteColorAttributeValue_color_set(PointerRNA *ptr, const float * linearrgb_to_srgb_uchar4(>r, values); } +static void rna_ByteColorAttributeValue_color_srgb_get(PointerRNA *ptr, float *values) +{ + MLoopCol *col = (MLoopCol *)ptr->data; + values[0] = col->r / 255.0f; + values[1] = col->g / 255.0f; + values[2] = col->b / 255.0f; + values[3] = col->a / 255.0f; +} + +static void rna_ByteColorAttributeValue_color_srgb_set(PointerRNA *ptr, const float *values) +{ + MLoopCol *col = (MLoopCol *)ptr->data; + col->r = round_fl_to_uchar_clamp(values[0] * 255.0f); + col->g = round_fl_to_uchar_clamp(values[1] * 255.0f); + col->b = round_fl_to_uchar_clamp(values[2] * 255.0f); + col->a = round_fl_to_uchar_clamp(values[3] * 255.0f); +} + +static void rna_FloatColorAttributeValue_color_srgb_get(PointerRNA *ptr, float *values) +{ + MPropCol *col = (MPropCol *)ptr->data; + linearrgb_to_srgb_v4(values, col->color); +} + +static void rna_FloatColorAttributeValue_color_srgb_set(PointerRNA *ptr, const float *values) +{ + MPropCol *col = (MPropCol *)ptr->data; + srgb_to_linearrgb_v4(col->color, values); +} + /* Int8 Attribute. */ static int rna_ByteIntAttributeValue_get(PointerRNA *ptr) @@ -715,6 +745,16 @@ static void rna_def_attribute_float_color(BlenderRNA *brna) RNA_def_property_float_sdna(prop, NULL, "color"); RNA_def_property_array(prop, 4); RNA_def_property_update(prop, 0, "rna_Attribute_update_data"); + + prop = RNA_def_property(srna, "color_srgb", PROP_FLOAT, PROP_COLOR); + RNA_def_property_ui_text(prop, "Color", "RGBA color in sRGB color space"); + RNA_def_property_float_sdna(prop, NULL, "color"); + RNA_def_property_array(prop, 4); + RNA_def_property_float_funcs(prop, + "rna_FloatColorAttributeValue_color_srgb_get", + "rna_FloatColorAttributeValue_color_srgb_set", + NULL); + RNA_def_property_update(prop, 0, "rna_Attribute_update_data"); } static void rna_def_attribute_byte_color(BlenderRNA *brna) @@ -756,6 +796,16 @@ static void rna_def_attribute_byte_color(BlenderRNA *brna) NULL); RNA_def_property_ui_text(prop, "Color", "RGBA color in scene linear color space"); RNA_def_property_update(prop, 0, "rna_Attribute_update_data"); + + prop = RNA_def_property(srna, "color_srgb", PROP_FLOAT, PROP_COLOR); + RNA_def_property_array(prop, 4); + RNA_def_property_range(prop, 0.0f, 1.0f); + RNA_def_property_float_funcs(prop, + "rna_ByteColorAttributeValue_color_srgb_get", + "rna_ByteColorAttributeValue_color_srgb_set", + NULL); + RNA_def_property_ui_text(prop, "Color", "RGBA color in sRGB color space"); + RNA_def_property_update(prop, 0, "rna_Attribute_update_data"); } static void rna_def_attribute_int(BlenderRNA *brna) ___ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs
[Bf-blender-cvs] [a99a62231e0] master: obj: implement support for PBR .mtl extensions
Commit: a99a62231e040a15c93add9ffa582ec9e1d9c4f1 Author: Aras Pranckevicius Date: Tue Sep 13 13:28:57 2022 +0300 Branches: master https://developer.blender.org/rBa99a62231e040a15c93add9ffa582ec9e1d9c4f1 obj: implement support for PBR .mtl extensions Implement import & export support for "PBR extensions" in .mtl files (T101029, also fixes T86736). Newly supported parameters: - Roughness (Pr, map_Pr) - Metallic (Pm, map_Pm) - Sheen (Ps, map_Ps) - Clearcoat thickness (Pc) and roughness (Pcr) - Anisotropy (aniso) and rotation (anisor) - Transmittance (Tf / Kt) Exporter has an option to enable these additional PBR parameters export; defaults to off since not all software understands that. Exporter UI tweaked and all material-related options were put into their own separate box. Added/extended test files in Subversion repository for test coverage. === M source/blender/editors/io/io_obj.c M source/blender/io/wavefront_obj/IO_wavefront_obj.h M source/blender/io/wavefront_obj/exporter/obj_export_file_writer.cc M source/blender/io/wavefront_obj/exporter/obj_export_file_writer.hh M source/blender/io/wavefront_obj/exporter/obj_export_mtl.cc M source/blender/io/wavefront_obj/exporter/obj_export_mtl.hh M source/blender/io/wavefront_obj/exporter/obj_exporter.cc M source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc M source/blender/io/wavefront_obj/importer/obj_import_mtl.cc M source/blender/io/wavefront_obj/tests/obj_exporter_tests.cc M source/blender/io/wavefront_obj/tests/obj_exporter_tests.hh M source/blender/io/wavefront_obj/tests/obj_mtl_parser_tests.cc === diff --git a/source/blender/editors/io/io_obj.c b/source/blender/editors/io/io_obj.c index 619d8a34132..cb8eafeb52d 100644 --- a/source/blender/editors/io/io_obj.c +++ b/source/blender/editors/io/io_obj.c @@ -93,6 +93,7 @@ static int wm_obj_export_exec(bContext *C, wmOperator *op) export_params.path_mode = RNA_enum_get(op->ptr, "path_mode"); export_params.export_triangulated_mesh = RNA_boolean_get(op->ptr, "export_triangulated_mesh"); export_params.export_curves_as_nurbs = RNA_boolean_get(op->ptr, "export_curves_as_nurbs"); + export_params.export_pbr_extensions = RNA_boolean_get(op->ptr, "export_pbr_extensions"); export_params.export_object_groups = RNA_boolean_get(op->ptr, "export_object_groups"); export_params.export_material_groups = RNA_boolean_get(op->ptr, "export_material_groups"); @@ -118,7 +119,6 @@ static void ui_obj_export_settings(uiLayout *layout, PointerRNA *imfptr) /* Object Transform options. */ box = uiLayoutBox(layout); - uiItemL(box, IFACE_("Object Properties"), ICON_OBJECT_DATA); col = uiLayoutColumn(box, false); sub = uiLayoutColumnWithHeading(col, false, IFACE_("Limit to")); uiItemR(sub, imfptr, "export_selected_objects", 0, IFACE_("Selected Only"), ICON_NONE); @@ -134,27 +134,31 @@ static void ui_obj_export_settings(uiLayout *layout, PointerRNA *imfptr) sub = uiLayoutColumnWithHeading(col, false, IFACE_("Objects")); uiItemR(sub, imfptr, "apply_modifiers", 0, IFACE_("Apply Modifiers"), ICON_NONE); uiItemR(sub, imfptr, "export_eval_mode", 0, IFACE_("Properties"), ICON_NONE); - sub = uiLayoutColumn(sub, false); - uiLayoutSetEnabled(sub, export_materials); - uiItemR(sub, imfptr, "path_mode", 0, IFACE_("Path Mode"), ICON_NONE); - /* Options for what to write. */ + /* Geometry options. */ box = uiLayoutBox(layout); - uiItemL(box, IFACE_("Geometry"), ICON_EXPORT); col = uiLayoutColumn(box, false); - sub = uiLayoutColumnWithHeading(col, false, IFACE_("Export")); + sub = uiLayoutColumnWithHeading(col, false, IFACE_("Geometry")); uiItemR(sub, imfptr, "export_uv", 0, IFACE_("UV Coordinates"), ICON_NONE); uiItemR(sub, imfptr, "export_normals", 0, IFACE_("Normals"), ICON_NONE); uiItemR(sub, imfptr, "export_colors", 0, IFACE_("Colors"), ICON_NONE); - uiItemR(sub, imfptr, "export_materials", 0, IFACE_("Materials"), ICON_NONE); uiItemR(sub, imfptr, "export_triangulated_mesh", 0, IFACE_("Triangulated Mesh"), ICON_NONE); uiItemR(sub, imfptr, "export_curves_as_nurbs", 0, IFACE_("Curves as NURBS"), ICON_NONE); + /* Material options. */ + box = uiLayoutBox(layout); + col = uiLayoutColumn(box, false); + sub = uiLayoutColumnWithHeading(col, false, IFACE_("Materials")); + uiItemR(sub, imfptr, "export_materials", 0, IFACE_("Export"), ICON_NONE); + sub = uiLayou
[Bf-blender-cvs] [8af59cdb162] master: Cleanup: obj: rename MTLMaterial & MTLTexMapType members
Commit: 8af59cdb16298e71dd75e2221d57bd0cb48cab26 Author: Aras Pranckevicius Date: Mon Sep 12 21:04:37 2022 +0300 Branches: master https://developer.blender.org/rB8af59cdb16298e71dd75e2221d57bd0cb48cab26 Cleanup: obj: rename MTLMaterial & MTLTexMapType members The members were named after .mtl file syntax ("d") instead of their meaning ("alpha"). In preparation for extending OBJ code for more PBR parameters support, rename them for clarity. No functionality changes, just a pure rename. === M source/blender/io/wavefront_obj/exporter/obj_export_file_writer.cc M source/blender/io/wavefront_obj/exporter/obj_export_mtl.cc M source/blender/io/wavefront_obj/exporter/obj_export_mtl.hh M source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc M source/blender/io/wavefront_obj/importer/obj_import_mtl.cc M source/blender/io/wavefront_obj/tests/obj_mtl_parser_tests.cc === 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 4d934960010..27526734624 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 @@ -558,24 +558,26 @@ void MTLWriter::write_bsdf_properties(const MTLMaterial ) /* For various material properties, we only capture information * coming from the texture, or the default value of the socket. * When the texture is present, do not emit the default value. */ - if (!mtl.tex_map_of_type(MTLTexMapType::Ns).is_valid()) { -fmt_handler_.write_mtl_float("Ns", mtl.Ns); + if (!mtl.tex_map_of_type(MTLTexMapType::SpecularExponent).is_valid()) { +fmt_handler_.write_mtl_float("Ns", mtl.spec_exponent); } - fmt_handler_.write_mtl_float3("Ka", mtl.Ka.x, mtl.Ka.y, mtl.Ka.z); - if (!mtl.tex_map_of_type(MTLTexMapType::Kd).is_valid()) { -fmt_handler_.write_mtl_float3("Kd", mtl.Kd.x, mtl.Kd.y, mtl.Kd.z); + fmt_handler_.write_mtl_float3( + "Ka", mtl.ambient_color.x, mtl.ambient_color.y, mtl.ambient_color.z); + if (!mtl.tex_map_of_type(MTLTexMapType::Color).is_valid()) { +fmt_handler_.write_mtl_float3("Kd", mtl.color.x, mtl.color.y, mtl.color.z); } - if (!mtl.tex_map_of_type(MTLTexMapType::Ks).is_valid()) { -fmt_handler_.write_mtl_float3("Ks", mtl.Ks.x, mtl.Ks.y, mtl.Ks.z); + if (!mtl.tex_map_of_type(MTLTexMapType::Specular).is_valid()) { +fmt_handler_.write_mtl_float3("Ks", mtl.spec_color.x, mtl.spec_color.y, mtl.spec_color.z); } - if (!mtl.tex_map_of_type(MTLTexMapType::Ke).is_valid()) { -fmt_handler_.write_mtl_float3("Ke", mtl.Ke.x, mtl.Ke.y, mtl.Ke.z); + if (!mtl.tex_map_of_type(MTLTexMapType::Emission).is_valid()) { +fmt_handler_.write_mtl_float3( +"Ke", mtl.emission_color.x, mtl.emission_color.y, mtl.emission_color.z); } - fmt_handler_.write_mtl_float("Ni", mtl.Ni); - if (!mtl.tex_map_of_type(MTLTexMapType::d).is_valid()) { -fmt_handler_.write_mtl_float("d", mtl.d); + fmt_handler_.write_mtl_float("Ni", mtl.ior); + if (!mtl.tex_map_of_type(MTLTexMapType::Alpha).is_valid()) { +fmt_handler_.write_mtl_float("d", mtl.alpha); } - fmt_handler_.write_mtl_illum(mtl.illum); + fmt_handler_.write_mtl_illum(mtl.illum_mode); } void MTLWriter::write_texture_map(const MTLMaterial _material, @@ -594,8 +596,8 @@ void MTLWriter::write_texture_map(const MTLMaterial _material, if (texture_map.scale != float3{1.0f, 1.0f, 1.0f}) { options.append(" -s ").append(float3_to_string(texture_map.scale)); } - if (texture_key == MTLTexMapType::bump && mtl_material.map_Bump_strength > 0.0001f) { -options.append(" -bm ").append(std::to_string(mtl_material.map_Bump_strength)); + if (texture_key == MTLTexMapType::Normal && mtl_material.normal_strength > 0.0001f) { +options.append(" -bm ").append(std::to_string(mtl_material.normal_strength)); } std::string path = path_reference( diff --git a/source/blender/io/wavefront_obj/exporter/obj_export_mtl.cc b/source/blender/io/wavefront_obj/exporter/obj_export_mtl.cc index 6a02695c304..77cad18a040 100644 --- a/source/blender/io/wavefront_obj/exporter/obj_export_mtl.cc +++ b/source/blender/io/wavefront_obj/exporter/obj_export_mtl.cc @@ -212,11 +212,11 @@ static void store_bsdf_properties(const bNode *bsdf_node, copy_property_from_node(SOCK_FLOAT, bsdf_node, "IOR", {_index, 1}); } - float dissolved = material->a; + float alpha = material->a; if (bsdf_node) { -copy_property_from_node(SOCK_FLOAT, bsdf_node, "Alpha", {, 1}); +copy_property_from_nod
[Bf-blender-cvs] [129993c026e] master: Fix T100887: Some C++ importers/exporters (e.g. OBJ) reset file dialog Sort By mode
Commit: 129993c026e910b83b8bc7f0a394f7a4748a2cac Author: Aras Pranckevicius Date: Thu Sep 8 13:07:31 2022 +0300 Branches: master https://developer.blender.org/rB129993c026e910b83b8bc7f0a394f7a4748a2cac Fix T100887: Some C++ importers/exporters (e.g. OBJ) reset file dialog Sort By mode A couple years ago D8598 made it so that C++ operators generally should use "default" sort mode, which remembers previously used sort setting. Back then all the places that needed it got changed to use this "default" one, but since then some more IO code landed, where seemingly by accident it used "sort by file name": - USD importer, - Grease Pencil exporter, - OBJ importer & exporter, - STL importer. Reviewed By: Julian Eisel Differential Revision: https://developer.blender.org/D15906 === M source/blender/editors/io/io_gpencil_export.c M source/blender/editors/io/io_obj.c M source/blender/editors/io/io_stl_ops.c M source/blender/editors/io/io_usd.c === diff --git a/source/blender/editors/io/io_gpencil_export.c b/source/blender/editors/io/io_gpencil_export.c index 12d87113a66..662a372b608 100644 --- a/source/blender/editors/io/io_gpencil_export.c +++ b/source/blender/editors/io/io_gpencil_export.c @@ -217,7 +217,7 @@ void WM_OT_gpencil_export_svg(wmOperatorType *ot) FILE_SAVE, WM_FILESEL_FILEPATH | WM_FILESEL_SHOW_PROPS, FILE_DEFAULTDISPLAY, - FILE_SORT_ALPHA); + FILE_SORT_DEFAULT); gpencil_export_common_props_definition(ot); @@ -375,7 +375,7 @@ void WM_OT_gpencil_export_pdf(wmOperatorType *ot) FILE_SAVE, WM_FILESEL_FILEPATH | WM_FILESEL_SHOW_PROPS, FILE_DEFAULTDISPLAY, - FILE_SORT_ALPHA); + FILE_SORT_DEFAULT); static const EnumPropertyItem gpencil_export_frame_items[] = { {GP_EXPORT_FRAME_ACTIVE, "ACTIVE", 0, "Active", "Include only active frame"}, diff --git a/source/blender/editors/io/io_obj.c b/source/blender/editors/io/io_obj.c index ef68a15933f..66e95c019f6 100644 --- a/source/blender/editors/io/io_obj.c +++ b/source/blender/editors/io/io_obj.c @@ -266,7 +266,7 @@ void WM_OT_obj_export(struct wmOperatorType *ot) FILE_SAVE, WM_FILESEL_FILEPATH | WM_FILESEL_SHOW_PROPS, FILE_DEFAULTDISPLAY, - FILE_SORT_ALPHA); + FILE_SORT_DEFAULT); /* Animation options. */ RNA_def_boolean(ot->srna, @@ -494,7 +494,7 @@ void WM_OT_obj_import(struct wmOperatorType *ot) WM_FILESEL_FILEPATH | WM_FILESEL_SHOW_PROPS | WM_FILESEL_DIRECTORY | WM_FILESEL_FILES, FILE_DEFAULTDISPLAY, - FILE_SORT_ALPHA); + FILE_SORT_DEFAULT); RNA_def_float( ot->srna, "clamp_size", diff --git a/source/blender/editors/io/io_stl_ops.c b/source/blender/editors/io/io_stl_ops.c index 858ea131577..c98e5beaf3b 100644 --- a/source/blender/editors/io/io_stl_ops.c +++ b/source/blender/editors/io/io_stl_ops.c @@ -104,7 +104,7 @@ void WM_OT_stl_import(struct wmOperatorType *ot) WM_FILESEL_FILEPATH | WM_FILESEL_FILES | WM_FILESEL_DIRECTORY | WM_FILESEL_SHOW_PROPS, FILE_DEFAULTDISPLAY, - FILE_SORT_ALPHA); + FILE_SORT_DEFAULT); RNA_def_float(ot->srna, "global_scale", 1.0f, 1e-6f, 1e6f, "Scale", "", 0.001f, 1000.0f); RNA_def_boolean(ot->srna, diff --git a/source/blender/editors/io/io_usd.c b/source/blender/editors/io/io_usd.c index 74ce0cca16c..ba118a5e289 100644 --- a/source/blender/editors/io/io_usd.c +++ b/source/blender/editors/io/io_usd.c @@ -487,7 +487,7 @@ void WM_OT_usd_import(struct wmOperatorType *ot) FILE_OPENFILE, WM_FILESEL_FILEPATH | WM_FILESEL_RELPATH | WM_FILESEL_SHOW_PROPS, FILE_DEFAULTDISPLAY, - FILE_SORT_ALPHA); + FILE_SORT_DEFAULT); RNA_def_float( ot->srna, ___ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs
[Bf-blender-cvs] [268e1eff8a5] master: Fix T96297: obj: improve layout of UI fields and axis validation
Commit: 268e1eff8a54ef3b294b27e94b73e29338a3c469 Author: Aras Pranckevicius Date: Thu Sep 8 11:43:26 2022 +0300 Branches: master https://developer.blender.org/rB268e1eff8a54ef3b294b27e94b73e29338a3c469 Fix T96297: obj: improve layout of UI fields and axis validation Implement ideas from T96297: - Fix "invalid axis settings" (both forward & up along the same direction) validation: now similar to the Python based code, when invalid axis is applied, the other axis is changed to not conflict. - Make axis enums be expanded inside the row, similar to Collada UI. - Move "selected only" near the top, similar to how it's in Collada, USD, FBX and glTF export UIs. - Move animation export options to the bottom. === M source/blender/editors/io/io_obj.c M source/blender/io/wavefront_obj/IO_wavefront_obj.h === diff --git a/source/blender/editors/io/io_obj.c b/source/blender/editors/io/io_obj.c index 0c935a0e1da..ef68a15933f 100644 --- a/source/blender/editors/io/io_obj.c +++ b/source/blender/editors/io/io_obj.c @@ -114,28 +114,24 @@ static void ui_obj_export_settings(uiLayout *layout, PointerRNA *imfptr) uiLayoutSetPropSep(layout, true); uiLayoutSetPropDecorate(layout, false); - /* Animation options. */ - uiLayout *box = uiLayoutBox(layout); - uiItemL(box, IFACE_("Animation"), ICON_ANIM); - uiLayout *col = uiLayoutColumn(box, false); - uiLayout *sub = uiLayoutColumn(col, false); - uiItemR(sub, imfptr, "export_animation", 0, NULL, ICON_NONE); - sub = uiLayoutColumn(sub, true); - uiItemR(sub, imfptr, "start_frame", 0, IFACE_("Frame Start"), ICON_NONE); - uiItemR(sub, imfptr, "end_frame", 0, IFACE_("End"), ICON_NONE); - uiLayoutSetEnabled(sub, export_animation); + uiLayout *box, *col, *sub, *row; /* Object Transform options. */ box = uiLayoutBox(layout); uiItemL(box, IFACE_("Object Properties"), ICON_OBJECT_DATA); col = uiLayoutColumn(box, false); - sub = uiLayoutColumn(col, false); - uiItemR(sub, imfptr, "forward_axis", 0, IFACE_("Axis Forward"), ICON_NONE); - uiItemR(sub, imfptr, "up_axis", 0, IFACE_("Up"), ICON_NONE); - sub = uiLayoutColumn(col, false); + sub = uiLayoutColumnWithHeading(col, false, IFACE_("Limit to")); + uiItemR(sub, imfptr, "export_selected_objects", 0, IFACE_("Selected Only"), ICON_NONE); uiItemR(sub, imfptr, "scaling_factor", 0, NULL, ICON_NONE); + + row = uiLayoutRow(box, false); + uiItemR(row, imfptr, "forward_axis", UI_ITEM_R_EXPAND, IFACE_("Foward Axis"), ICON_NONE); + row = uiLayoutRow(box, false); + uiItemR(row, imfptr, "up_axis", UI_ITEM_R_EXPAND, IFACE_("Up Axis"), ICON_NONE); + + col = uiLayoutColumn(box, false); + sub = uiLayoutColumn(col, false); sub = uiLayoutColumnWithHeading(col, false, IFACE_("Objects")); - uiItemR(sub, imfptr, "export_selected_objects", 0, IFACE_("Selected Only"), ICON_NONE); uiItemR(sub, imfptr, "apply_modifiers", 0, IFACE_("Apply Modifiers"), ICON_NONE); uiItemR(sub, imfptr, "export_eval_mode", 0, IFACE_("Properties"), ICON_NONE); sub = uiLayoutColumn(sub, false); @@ -144,7 +140,7 @@ static void ui_obj_export_settings(uiLayout *layout, PointerRNA *imfptr) /* Options for what to write. */ box = uiLayoutBox(layout); - uiItemL(box, IFACE_("Geometry Export"), ICON_EXPORT); + uiItemL(box, IFACE_("Geometry"), ICON_EXPORT); col = uiLayoutColumn(box, false); sub = uiLayoutColumnWithHeading(col, false, IFACE_("Export")); uiItemR(sub, imfptr, "export_uv", 0, IFACE_("UV Coordinates"), ICON_NONE); @@ -166,6 +162,17 @@ static void ui_obj_export_settings(uiLayout *layout, PointerRNA *imfptr) sub = uiLayoutColumn(sub, false); uiLayoutSetEnabled(sub, export_smooth_groups); uiItemR(sub, imfptr, "smooth_group_bitflags", 0, IFACE_("Smooth Group Bitflags"), ICON_NONE); + + /* Animation options. */ + box = uiLayoutBox(layout); + uiItemL(box, IFACE_("Animation"), ICON_ANIM); + col = uiLayoutColumn(box, false); + sub = uiLayoutColumn(col, false); + uiItemR(sub, imfptr, "export_animation", 0, NULL, ICON_NONE); + sub = uiLayoutColumn(sub, true); + uiItemR(sub, imfptr, "start_frame", 0, IFACE_("Frame Start"), ICON_NONE); + uiItemR(sub, imfptr, "end_frame", 0, IFACE_("End"), ICON_NONE); + uiLayoutSetEnabled(sub, export_animation); } static void wm_obj_export_draw(bContext *UNUSED(C), wmOperator *op) @@ -211,15 +218,30 @@ static bool wm_obj_export_check(bContext *C, wmOperator *op) RNA_int_set(op->ptr,
[Bf-blender-cvs] [67dcdebb3a7] master: Fix T100669: OBJ exporter does not properly export image sequence texture names
Commit: 67dcdebb3a7cc057fe73079fc038f9264326daea Author: Aras Pranckevicius Date: Wed Sep 7 17:56:06 2022 +0300 Branches: master https://developer.blender.org/rB67dcdebb3a7cc057fe73079fc038f9264326daea Fix T100669: OBJ exporter does not properly export image sequence texture names When exporting OBJ/MTL animation, texture file paths of image sequences were not adjusted to contain the correct frame number. Fixes T100669. Also, the OBJ exporter was wrongly writing to the same .mtl file for each exported frame, which is a regression compared to the legacy Python exporter. === M source/blender/io/wavefront_obj/exporter/obj_export_mtl.cc M source/blender/io/wavefront_obj/exporter/obj_exporter.cc === diff --git a/source/blender/io/wavefront_obj/exporter/obj_export_mtl.cc b/source/blender/io/wavefront_obj/exporter/obj_export_mtl.cc index 0b228ef8c37..6a02695c304 100644 --- a/source/blender/io/wavefront_obj/exporter/obj_export_mtl.cc +++ b/source/blender/io/wavefront_obj/exporter/obj_export_mtl.cc @@ -121,28 +121,41 @@ static const bNode *get_node_of_type(Span sockets_list, con return nullptr; } -/** +/* * From a texture image shader node, get the image's filepath. * If packed image is found, only the file "name" is returned. */ -static const char *get_image_filepath(const bNode *tex_node) +static std::string get_image_filepath(const bNode *tex_node) { if (!tex_node) { -return nullptr; +return ""; } Image *tex_image = reinterpret_cast(tex_node->id); if (!tex_image || !BKE_image_has_filepath(tex_image)) { -return nullptr; +return ""; } - const char *path = tex_image->filepath; + if (BKE_image_has_packedfile(tex_image)) { /* Put image in the same directory as the .MTL file. */ -path = BLI_path_slash_rfind(path) + 1; +const char *filename = BLI_path_slash_rfind(tex_image->filepath) + 1; fprintf(stderr, "Packed image found:'%s'. Unpack and place the image in the same " "directory as the .MTL file.\n", -path); +filename); +return filename; } + + char path[FILE_MAX]; + BLI_strncpy(path, tex_image->filepath, FILE_MAX); + + if (tex_image->source == IMA_SRC_SEQUENCE) { +char head[FILE_MAX], tail[FILE_MAX]; +unsigned short numlen; +int framenr = static_cast(tex_node->storage)->iuser.framenr; +BLI_path_sequence_decode(path, head, tail, ); +BLI_path_sequence_encode(path, head, tail, numlen, framenr); + } + return path; } @@ -307,8 +320,8 @@ static void store_image_textures(const bNode *bsdf_node, if (!tex_node) { continue; } -const char *tex_image_filepath = get_image_filepath(tex_node); -if (!tex_image_filepath) { +const std::string tex_image_filepath = get_image_filepath(tex_node); +if (tex_image_filepath.empty()) { continue; } diff --git a/source/blender/io/wavefront_obj/exporter/obj_exporter.cc b/source/blender/io/wavefront_obj/exporter/obj_exporter.cc index 76cf9066bf4..294ea81fd58 100644 --- a/source/blender/io/wavefront_obj/exporter/obj_exporter.cc +++ b/source/blender/io/wavefront_obj/exporter/obj_exporter.cc @@ -268,7 +268,7 @@ void export_frame(Depsgraph *depsgraph, const OBJExportParams _params, co std::unique_ptr mtl_writer = nullptr; if (export_params.export_materials) { try { - mtl_writer = std::make_unique(export_params.filepath); + mtl_writer = std::make_unique(filepath); } catch (const std::system_error ) { print_exception_error(ex); ___ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs
[Bf-blender-cvs] [13a7516f436] master: Cleanup: factor out "set default filepath" into a ED_fileselect_ensure_default_filepath
Commit: 13a7516f436597e7f60d0696afa16e8e6d6735fb Author: Aras Pranckevicius Date: Wed Sep 7 13:27:27 2022 +0300 Branches: master https://developer.blender.org/rB13a7516f436597e7f60d0696afa16e8e6d6735fb Cleanup: factor out "set default filepath" into a ED_fileselect_ensure_default_filepath Follow up to D15904, a bunch of places had exact same logic for "is filepath set? if not, set some default one", so factor all that out into a separate ED_fileselect_ensure_default_filepath function. === M source/blender/editors/include/ED_fileselect.h M source/blender/editors/io/io_alembic.c M source/blender/editors/io/io_collada.c M source/blender/editors/io/io_gpencil_export.c M source/blender/editors/io/io_obj.c M source/blender/editors/io/io_usd.c M source/blender/editors/space_file/filesel.c M source/blender/editors/space_sequencer/sequencer_edit.c === diff --git a/source/blender/editors/include/ED_fileselect.h b/source/blender/editors/include/ED_fileselect.h index e9fcd2bd5fe..9d5d8dd54cb 100644 --- a/source/blender/editors/include/ED_fileselect.h +++ b/source/blender/editors/include/ED_fileselect.h @@ -175,6 +175,14 @@ struct ScrArea *ED_fileselect_handler_area_find(const struct wmWindow *win, */ struct ScrArea *ED_fileselect_handler_area_find_any_with_op(const struct wmWindow *win); +/** + * If filepath property is not set on the operator, sets it to + * the blend file path (or untitled if file is not saved yet) with the given extension. + */ +void ED_fileselect_ensure_default_filepath(struct bContext *C, + struct wmOperator *op, + const char *extension); + /* TODO: Maybe we should move this to BLI? * On the other hand, it's using defines from space-file area, so not sure... */ int ED_path_extension_type(const char *path); diff --git a/source/blender/editors/io/io_alembic.c b/source/blender/editors/io/io_alembic.c index 62b32d47678..d4855f470ff 100644 --- a/source/blender/editors/io/io_alembic.c +++ b/source/blender/editors/io/io_alembic.c @@ -39,6 +39,7 @@ # include "RNA_define.h" # include "RNA_enum_types.h" +# include "ED_fileselect.h" # include "ED_object.h" # include "UI_interface.h" @@ -75,20 +76,7 @@ static int wm_alembic_export_invoke(bContext *C, wmOperator *op, const wmEvent * RNA_boolean_set(op->ptr, "init_scene_frame_range", true); - if (!RNA_struct_property_is_set_ex(op->ptr, "filepath", false)) { -Main *bmain = CTX_data_main(C); -char filepath[FILE_MAX]; - -if (BKE_main_blendfile_path(bmain)[0] == '\0') { - BLI_strncpy(filepath, DATA_("untitled"), sizeof(filepath)); -} -else { - BLI_strncpy(filepath, BKE_main_blendfile_path(bmain), sizeof(filepath)); -} - -BLI_path_extension_replace(filepath, sizeof(filepath), ".abc"); -RNA_string_set(op->ptr, "filepath", filepath); - } + ED_fileselect_ensure_default_filepath(C, op, ".abc"); WM_event_add_fileselect(C, op); diff --git a/source/blender/editors/io/io_collada.c b/source/blender/editors/io/io_collada.c index 7397138d8c5..3da7c00d5e2 100644 --- a/source/blender/editors/io/io_collada.c +++ b/source/blender/editors/io/io_collada.c @@ -19,6 +19,7 @@ # include "DEG_depsgraph.h" +# include "ED_fileselect.h" # include "ED_object.h" # include "RNA_access.h" @@ -36,22 +37,7 @@ static int wm_collada_export_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) { - Main *bmain = CTX_data_main(C); - - if (!RNA_struct_property_is_set_ex(op->ptr, "filepath", false)) { -char filepath[FILE_MAX]; -const char *blendfile_path = BKE_main_blendfile_path(bmain); - -if (blendfile_path[0] == '\0') { - BLI_strncpy(filepath, DATA_("untitled"), sizeof(filepath)); -} -else { - BLI_strncpy(filepath, blendfile_path, sizeof(filepath)); -} - -BLI_path_extension_replace(filepath, sizeof(filepath), ".dae"); -RNA_string_set(op->ptr, "filepath", filepath); - } + ED_fileselect_ensure_default_filepath(C, op, ".dae"); WM_event_add_fileselect(C, op); diff --git a/source/blender/editors/io/io_gpencil_export.c b/source/blender/editors/io/io_gpencil_export.c index 6df56f1498a..12d87113a66 100644 --- a/source/blender/editors/io/io_gpencil_export.c +++ b/source/blender/editors/io/io_gpencil_export.c @@ -20,6 +20,8 @@ # include "BLT_translation.h" +# include "ED_fileselect.h" + # include "RNA_access.h" # include "RNA_define.h" @@ -71,24 +73,6 @@ static void gpencil_export_co
[Bf-blender-cvs] [97bd04d665c] master: Fix T100797: C++ exporters do not remember the path on subsequent exports
Commit: 97bd04d665cb8c964e9159da94a3c7941cd4841c Author: Aras Pranckevicius Date: Wed Sep 7 11:47:29 2022 +0300 Branches: master https://developer.blender.org/rB97bd04d665cb8c964e9159da94a3c7941cd4841c Fix T100797: C++ exporters do not remember the path on subsequent exports Most/all C++ based IO code had a pattern of doing using RNA_struct_property_is_set to check whether a default path needs to be set. However, it returns false for properties restored from "previous operator settings" (property restoration code sets IDP_FLAG_GHOST flag on them, which "is set" sees and goes "nope, not set"). The fix here is to apply similar logic as 10 years ago in the T32855 fix (rBdb250a4): use RNA_struct_property_is_set_ex instead. Reviewed By: Campbell Barton Differential Revision: https://developer.blender.org/D15904 === M source/blender/editors/io/io_alembic.c M source/blender/editors/io/io_collada.c M source/blender/editors/io/io_gpencil_export.c M source/blender/editors/io/io_gpencil_import.c M source/blender/editors/io/io_obj.c M source/blender/editors/io/io_stl_ops.c M source/blender/editors/io/io_usd.c === diff --git a/source/blender/editors/io/io_alembic.c b/source/blender/editors/io/io_alembic.c index dd35279e0d6..62b32d47678 100644 --- a/source/blender/editors/io/io_alembic.c +++ b/source/blender/editors/io/io_alembic.c @@ -75,7 +75,7 @@ static int wm_alembic_export_invoke(bContext *C, wmOperator *op, const wmEvent * RNA_boolean_set(op->ptr, "init_scene_frame_range", true); - if (!RNA_struct_property_is_set(op->ptr, "filepath")) { + if (!RNA_struct_property_is_set_ex(op->ptr, "filepath", false)) { Main *bmain = CTX_data_main(C); char filepath[FILE_MAX]; @@ -99,7 +99,7 @@ static int wm_alembic_export_invoke(bContext *C, wmOperator *op, const wmEvent * static int wm_alembic_export_exec(bContext *C, wmOperator *op) { - if (!RNA_struct_property_is_set(op->ptr, "filepath")) { + if (!RNA_struct_property_is_set_ex(op->ptr, "filepath", false)) { BKE_report(op->reports, RPT_ERROR, "No filename given"); return OPERATOR_CANCELLED; } @@ -619,7 +619,7 @@ static int wm_alembic_import_invoke(bContext *C, wmOperator *op, const wmEvent * static int wm_alembic_import_exec(bContext *C, wmOperator *op) { - if (!RNA_struct_property_is_set(op->ptr, "filepath")) { + if (!RNA_struct_property_is_set_ex(op->ptr, "filepath", false)) { BKE_report(op->reports, RPT_ERROR, "No filename given"); return OPERATOR_CANCELLED; } diff --git a/source/blender/editors/io/io_collada.c b/source/blender/editors/io/io_collada.c index 6a5547021e4..7397138d8c5 100644 --- a/source/blender/editors/io/io_collada.c +++ b/source/blender/editors/io/io_collada.c @@ -38,7 +38,7 @@ static int wm_collada_export_invoke(bContext *C, wmOperator *op, const wmEvent * { Main *bmain = CTX_data_main(C); - if (!RNA_struct_property_is_set(op->ptr, "filepath")) { + if (!RNA_struct_property_is_set_ex(op->ptr, "filepath", false)) { char filepath[FILE_MAX]; const char *blendfile_path = BKE_main_blendfile_path(bmain); @@ -98,7 +98,7 @@ static int wm_collada_export_exec(bContext *C, wmOperator *op) int export_count; int sample_animations; - if (!RNA_struct_property_is_set(op->ptr, "filepath")) { + if (!RNA_struct_property_is_set_ex(op->ptr, "filepath", false)) { BKE_report(op->reports, RPT_ERROR, "No filename given"); return OPERATOR_CANCELLED; } @@ -709,7 +709,7 @@ static int wm_collada_import_exec(bContext *C, wmOperator *op) int keep_bind_info; ImportSettings import_settings; - if (!RNA_struct_property_is_set(op->ptr, "filepath")) { + if (!RNA_struct_property_is_set_ex(op->ptr, "filepath", false)) { BKE_report(op->reports, RPT_ERROR, "No filename given"); return OPERATOR_CANCELLED; } diff --git a/source/blender/editors/io/io_gpencil_export.c b/source/blender/editors/io/io_gpencil_export.c index 7dfbf06f3c3..6df56f1498a 100644 --- a/source/blender/editors/io/io_gpencil_export.c +++ b/source/blender/editors/io/io_gpencil_export.c @@ -74,7 +74,7 @@ static void gpencil_export_common_props_definition(wmOperatorType *ot) static void set_export_filepath(bContext *C, wmOperator *op, const char *extension) { - if (!RNA_struct_property_is_set(op->ptr, "filepath")) { + if (!RNA_struct_property_is_set_ex(op->ptr, "filepath", false)) { Main *bmain = CTX_data_main(C); char filepath[FILE_MAX]; @@ -121,7 +121,7 @@ static int wm_gpencil_export_svg_exec(bContext *C, wmOperator *op) Sce
[Bf-blender-cvs] [d3242b772b3] master: obj: improve placement of shader nodes in imported materials
Commit: d3242b772b3cddb6f258836f5217ff04b0c46fa6 Author: Aras Pranckevicius Date: Fri Sep 2 16:29:45 2022 +0300 Branches: master https://developer.blender.org/rBd3242b772b3cddb6f258836f5217ff04b0c46fa6 obj: improve placement of shader nodes in imported materials Previously for most materials (especially the ones without any textures), the nodes were "off screen" way to the right, requiring a view framing to even see them. Also, as soon as multiple images were used, many nodes overlapped one another and the connections were all a mess. Simplify all that, and now each node type (coordinate, mapping, image, normal map, bsdf etc.) is in it's own column, with BSDF at zero coordinate. Each used image (along with any possible coordinate, mapping, normal map) is it's own row. The resulting connections are much cleaner. === M source/blender/io/wavefront_obj/importer/obj_import_mtl.cc === diff --git a/source/blender/io/wavefront_obj/importer/obj_import_mtl.cc b/source/blender/io/wavefront_obj/importer/obj_import_mtl.cc index 0aaf9048498..58d414a59ad 100644 --- a/source/blender/io/wavefront_obj/importer/obj_import_mtl.cc +++ b/source/blender/io/wavefront_obj/importer/obj_import_mtl.cc @@ -142,46 +142,38 @@ static Image *load_texture_image(Main *bmain, const MTLTexMap _map, bool rel return image; } -typedef Vector> NodeLocations; +/* Nodes are arranged in columns by type, with manually placed x coordinates + * based on node widths. */ +const float node_locx_texcoord = -880.0f; +const float node_locx_mapping = -680.0f; +const float node_locx_image = -480.0f; +const float node_locx_normalmap = -200.0f; +const float node_locx_bsdf = 0.0f; +const float node_locx_output = 280.0f; -static std::pair calc_location(int column, NodeLocations _locations) +/* Nodes are arranged in rows; one row for each image being used. */ +const float node_locy_top = 300.0f; +const float node_locy_step = 300.0f; + +/* Add a node of the given type at the given location. */ +static bNode *add_node(bNodeTree *ntree, int type, float x, float y) { - const float node_size = 300.f; - int row = 0; - bool found = false; - while (true) { -for (const auto : r_locations) { - if (location.first == column && location.second == row) { -row += 1; -found = true; - } - else { -found = false; - } -} -if (!found) { - r_locations.append({column, row}); - return {column * node_size, row * node_size * 2.0 / 3.0}; -} - } + bNode *node = nodeAddStaticNode(nullptr, ntree, type); + node->locx = x; + node->locy = y; + return node; } -/* Node layout columns: - * Texture Coordinates -> Mapping -> Image -> Normal Map -> BSDF -> Output */ -static void link_sockets(bNodeTree *nodetree, +static void link_sockets(bNodeTree *ntree, bNode *from_node, const char *from_node_id, bNode *to_node, - const char *to_node_id, - const int from_node_column, - NodeLocations _locations) + const char *to_node_id) { - std::tie(from_node->locx, from_node->locy) = calc_location(from_node_column, r_locations); - std::tie(to_node->locx, to_node->locy) = calc_location(from_node_column + 1, r_locations); bNodeSocket *from_sock{nodeFindSocket(from_node, SOCK_OUT, from_node_id)}; bNodeSocket *to_sock{nodeFindSocket(to_node, SOCK_IN, to_node_id)}; BLI_assert(from_sock && to_sock); - nodeAddLink(nodetree, from_node, from_sock, to_node, to_sock); + nodeAddLink(ntree, from_node, from_sock, to_node, to_sock); } static void set_bsdf_socket_values(bNode *bsdf, Material *mat, const MTLMaterial _mat) @@ -323,13 +315,13 @@ static void set_bsdf_socket_values(bNode *bsdf, Material *mat, const MTLMaterial } static void add_image_textures(Main *bmain, - bNodeTree *nodetree, + bNodeTree *ntree, bNode *bsdf, Material *mat, const MTLMaterial _mat, - bool relative_paths, - NodeLocations _locations) + bool relative_paths) { + float node_locy = node_locy_top; for (int key = 0; key < (int)MTLTexMapType::Count; ++key) { const MTLTexMap = mtl_mat.texture_maps[key]; if (!value.is_valid()) { @@ -337,47 +329,49 @@ static void add_image_textures(Main *bmain, continue; } -bNode *image_texture = nodeAddStaticNode(nullptr, nodetree, SH_NODE_TEX_IMAGE); -BLI_assert(image_texture); Image *image = load_texture_image(bmain, value, relative_paths); i
[Bf-blender-cvs] [9d59734ffd4] master: Fix build (missing include from fa40013009)
Commit: 9d59734ffd4093dea6d207ad8ee78f783f9b3fd6 Author: Aras Pranckevicius Date: Thu Sep 1 21:57:42 2022 +0300 Branches: master https://developer.blender.org/rB9d59734ffd4093dea6d207ad8ee78f783f9b3fd6 Fix build (missing include from fa40013009) === M source/blender/io/wavefront_obj/tests/obj_mtl_parser_tests.cc === diff --git a/source/blender/io/wavefront_obj/tests/obj_mtl_parser_tests.cc b/source/blender/io/wavefront_obj/tests/obj_mtl_parser_tests.cc index 41faba95b30..5691aa5bea1 100644 --- a/source/blender/io/wavefront_obj/tests/obj_mtl_parser_tests.cc +++ b/source/blender/io/wavefront_obj/tests/obj_mtl_parser_tests.cc @@ -6,6 +6,7 @@ #include "testing/testing.h" +#include "obj_export_mtl.hh" #include "obj_import_file_reader.hh" namespace blender::io::obj { ___ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs
[Bf-blender-cvs] [fa400130094] master: Cleanup: obj: simplify material node tree creation
Commit: fa40013009463703a22a8ae05d116723084966b7 Author: Aras Pranckevicius Date: Thu Sep 1 21:19:31 2022 +0300 Branches: master https://developer.blender.org/rBfa40013009463703a22a8ae05d116723084966b7 Cleanup: obj: simplify material node tree creation As pointed out in D15827 comment, the unique_ptr usage in ShaderNodetreeWrap related code does not sound very useful. Looking at it, whole ShaderNodetreeWrap does not make much sense - it's only ever created, and then immediately just one thing is fetched from it. This very much sounds like "a function", so make it just that - header file contains just a `create_mtl_node_tree` function, and the whole implementation is hidden from the users. Which I've also simplified into just a handful of freestanding functions. No functionality or performance changes, but the code does get ~80 lines shorter. === M source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc M source/blender/io/wavefront_obj/importer/obj_import_mesh.cc M source/blender/io/wavefront_obj/importer/obj_import_mtl.cc M source/blender/io/wavefront_obj/importer/obj_import_mtl.hh M source/blender/io/wavefront_obj/importer/obj_importer.cc === diff --git a/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc b/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc index 088784b4194..2ad8a09bd90 100644 --- a/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc +++ b/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc @@ -10,6 +10,7 @@ #include "BLI_string_ref.hh" #include "BLI_vector.hh" +#include "obj_export_mtl.hh" #include "obj_import_file_reader.hh" #include "obj_import_string_utils.hh" diff --git a/source/blender/io/wavefront_obj/importer/obj_import_mesh.cc b/source/blender/io/wavefront_obj/importer/obj_import_mesh.cc index 40a958919f1..e01b64d7885 100644 --- a/source/blender/io/wavefront_obj/importer/obj_import_mesh.cc +++ b/source/blender/io/wavefront_obj/importer/obj_import_mesh.cc @@ -22,6 +22,7 @@ #include "IO_wavefront_obj.h" #include "importer_mesh_utils.hh" +#include "obj_export_mtl.hh" #include "obj_import_mesh.hh" namespace blender::io::obj { @@ -304,9 +305,8 @@ static Material *get_or_create_material(Main *bmain, Material *mat = BKE_material_add(bmain, name.c_str()); id_us_min(>id); - ShaderNodetreeWrap mat_wrap{bmain, mtl, mat, relative_paths}; mat->use_nodes = true; - mat->nodetree = mat_wrap.get_nodetree(); + mat->nodetree = create_mtl_node_tree(bmain, mtl, mat, relative_paths); BKE_ntree_update_main_tree(bmain, mat->nodetree, nullptr); created_materials.add_new(name, mat); diff --git a/source/blender/io/wavefront_obj/importer/obj_import_mtl.cc b/source/blender/io/wavefront_obj/importer/obj_import_mtl.cc index a9c224445a7..0aaf9048498 100644 --- a/source/blender/io/wavefront_obj/importer/obj_import_mtl.cc +++ b/source/blender/io/wavefront_obj/importer/obj_import_mtl.cc @@ -17,6 +17,7 @@ #include "NOD_shader.h" +#include "obj_export_mtl.hh" #include "obj_import_mtl.hh" #include "obj_import_string_utils.hh" @@ -141,60 +142,17 @@ static Image *load_texture_image(Main *bmain, const MTLTexMap _map, bool rel return image; } -void UniqueNodetreeDeleter::operator()(bNodeTree *node) -{ - ntreeFreeEmbeddedTree(node); -} - -ShaderNodetreeWrap::ShaderNodetreeWrap(Main *bmain, - const MTLMaterial _mat, - Material *mat, - bool relative_paths) -: mtl_mat_(mtl_mat) -{ - nodetree_.reset(ntreeAddTree(nullptr, "Shader Nodetree", ntreeType_Shader->idname)); - bsdf_ = add_node_to_tree(SH_NODE_BSDF_PRINCIPLED); - shader_output_ = add_node_to_tree(SH_NODE_OUTPUT_MATERIAL); - - set_bsdf_socket_values(mat); - add_image_textures(bmain, mat, relative_paths); - link_sockets(bsdf_, "BSDF", shader_output_, "Surface", 4); - - nodeSetActive(nodetree_.get(), shader_output_); -} - -/** - * Assert if caller hasn't acquired nodetree. - */ -ShaderNodetreeWrap::~ShaderNodetreeWrap() -{ - if (nodetree_) { -/* nodetree's ownership must be acquired by the caller. */ -nodetree_.reset(); -BLI_assert(0); - } -} +typedef Vector> NodeLocations; -bNodeTree *ShaderNodetreeWrap::get_nodetree() +static std::pair calc_location(int column, NodeLocations _locations) { - /* If this function has been reached, we know that nodes and the nodetree - * can be added to the scene safely. */ - return nodetree_.release(); -} - -bNode *ShaderNodetreeWrap::add_node_to_tree(const int node_type) -{ - return nodeAddStaticNode(nul
[Bf-blender-cvs] [08894ac929c] master: Merge branch 'blender-v3.3-release'
Commit: 08894ac929cbad25219d107f7877b1300135fb60 Author: Aras Pranckevicius Date: Thu Sep 1 20:44:09 2022 +0300 Branches: master https://developer.blender.org/rB08894ac929cbad25219d107f7877b1300135fb60 Merge branch 'blender-v3.3-release' === === diff --cc source/blender/io/alembic/intern/abc_reader_mesh.cc index 16e5ee968a3,5b68b80b181..a4b6c32ef64 --- a/source/blender/io/alembic/intern/abc_reader_mesh.cc +++ b/source/blender/io/alembic/intern/abc_reader_mesh.cc @@@ -25,7 -25,8 +25,8 @@@ #include "BLI_listbase.h" #include "BLI_math_geom.h" -#include "BKE_attribute.h" +#include "BKE_attribute.hh" + #include "BKE_lib_id.h" #include "BKE_main.h" #include "BKE_material.h" #include "BKE_mesh.h" ___ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs
[Bf-blender-cvs] [f366d197db2] blender-v3.3-release: Fix T100737: OBJ/USD import: imported object has no active material, material has 2 users
Commit: f366d197db24cf611866a8d847b4022a6a46504e Author: Aras Pranckevicius Date: Thu Sep 1 20:38:56 2022 +0300 Branches: blender-v3.3-release https://developer.blender.org/rBf366d197db24cf611866a8d847b4022a6a46504e Fix T100737: OBJ/USD import: imported object has no active material, material has 2 users Fixes issues in importers written in C++ (T100737): - Materials had one reference count too much. Affected Collada, Alembic, USD, OBJ importers, looks like "since forever". - Active material index was not properly set on imported meshes. Regression since 3.3 (D15145). Affected Alembic, USD, OBJ. Note: now it sets the first material as the active one, whereas previously the last one was set as active. First one sounds more "intuitive" to me. Reviewed By: Bastien Montagne Differential Revision: https://developer.blender.org/D15831 === M source/blender/io/alembic/intern/abc_reader_mesh.cc M source/blender/io/collada/DocumentImporter.cpp M source/blender/io/usd/intern/usd_reader_material.cc M source/blender/io/usd/intern/usd_reader_mesh.cc M source/blender/io/wavefront_obj/importer/obj_import_mesh.cc === diff --git a/source/blender/io/alembic/intern/abc_reader_mesh.cc b/source/blender/io/alembic/intern/abc_reader_mesh.cc index bacc1f06599..5b68b80b181 100644 --- a/source/blender/io/alembic/intern/abc_reader_mesh.cc +++ b/source/blender/io/alembic/intern/abc_reader_mesh.cc @@ -26,6 +26,7 @@ #include "BLI_math_geom.h" #include "BKE_attribute.h" +#include "BKE_lib_id.h" #include "BKE_main.h" #include "BKE_material.h" #include "BKE_mesh.h" @@ -93,6 +94,7 @@ static void assign_materials(Main *bmain, mat_iter = matname_to_material.find(mat_name); if (mat_iter == matname_to_material.end()) { assigned_mat = BKE_material_add(bmain, mat_name.c_str()); + id_us_min(_mat->id); matname_to_material[mat_name] = assigned_mat; } else { @@ -101,6 +103,9 @@ static void assign_materials(Main *bmain, BKE_object_material_assign_single_obdata(bmain, ob, assigned_mat, mat_index); } + if (ob->totcol > 0) { +ob->actcol = 1; + } } } /* namespace utils */ diff --git a/source/blender/io/collada/DocumentImporter.cpp b/source/blender/io/collada/DocumentImporter.cpp index 2ce97bc8b5d..1ffe412b3ed 100644 --- a/source/blender/io/collada/DocumentImporter.cpp +++ b/source/blender/io/collada/DocumentImporter.cpp @@ -743,6 +743,7 @@ bool DocumentImporter::writeMaterial(const COLLADAFW::Material *cmat) const std::string _mat_id = cmat->getName().empty() ? cmat->getOriginalId() : cmat->getName(); Material *ma = BKE_material_add(bmain, (char *)str_mat_id.c_str()); + id_us_min(>id); this->uid_effect_map[cmat->getInstantiatedEffect()] = ma; this->uid_material_map[cmat->getUniqueId()] = ma; diff --git a/source/blender/io/usd/intern/usd_reader_material.cc b/source/blender/io/usd/intern/usd_reader_material.cc index 8feceee55ed..52addfeb418 100644 --- a/source/blender/io/usd/intern/usd_reader_material.cc +++ b/source/blender/io/usd/intern/usd_reader_material.cc @@ -4,6 +4,7 @@ #include "usd_reader_material.h" #include "BKE_image.h" +#include "BKE_lib_id.h" #include "BKE_main.h" #include "BKE_material.h" #include "BKE_node.h" @@ -266,6 +267,7 @@ Material *USDMaterialReader::add_material(const pxr::UsdShadeMaterial _mater /* Create the material. */ Material *mtl = BKE_material_add(bmain_, mtl_name.c_str()); + id_us_min(>id); /* Get the UsdPreviewSurface shader source for the material, * if there is one. */ diff --git a/source/blender/io/usd/intern/usd_reader_mesh.cc b/source/blender/io/usd/intern/usd_reader_mesh.cc index 45657525527..de638b0a837 100644 --- a/source/blender/io/usd/intern/usd_reader_mesh.cc +++ b/source/blender/io/usd/intern/usd_reader_mesh.cc @@ -168,6 +168,9 @@ static void assign_materials(Main *bmain, std::cout << "WARNING: Couldn't assign material " << it->first << std::endl; } } + if (ob->totcol > 0) { +ob->actcol = 1; + } } } // namespace utils diff --git a/source/blender/io/wavefront_obj/importer/obj_import_mesh.cc b/source/blender/io/wavefront_obj/importer/obj_import_mesh.cc index a570b374231..6b19d6573af 100644 --- a/source/blender/io/wavefront_obj/importer/obj_import_mesh.cc +++ b/source/blender/io/wavefront_obj/importer/obj_import_mesh.cc @@ -296,6 +296,8 @@ static Material *get_or_create_material(Main *bmain, const MTLMaterial = *materials.lookup_or_add(name, std::make_unique()); Material *mat = BKE_material_add(bmain, name.c_str(
[Bf-blender-cvs] [68f234b8ab2] master: Cleanup: obj: simplify import/export syntax handling code
Commit: 68f234b8ab2ef4f69498650ece54015d174bea07 Author: Aras Pranckevicius Date: Mon Aug 29 21:10:16 2022 +0300 Branches: master https://developer.blender.org/rB68f234b8ab2ef4f69498650ece54015d174bea07 Cleanup: obj: simplify import/export syntax handling code I want to add support for PBR materials extension to OBJ, but the way current I/O code syntax handling was done made it quite cumbersome to extend the number of MTL textures/parameters. Simplify all that by removing FormatHandler template on "syntax" that gets routed through keyword enums, and instead just have simple `write_obj_*` and `write_mtl_*` functions. Simplify MTLMaterial to not contain a map of textures (that is always fully filled with all possible textures), instead now there's a simple array. Rename `tex_map_XX` to `MTLTexMap`. All this does not affect behavior or performance, but it does result in 170 fewer lines of code, and saves a couple kilobytes of executable size. === M source/blender/io/wavefront_obj/exporter/obj_export_file_writer.cc M source/blender/io/wavefront_obj/exporter/obj_export_file_writer.hh M source/blender/io/wavefront_obj/exporter/obj_export_io.hh M source/blender/io/wavefront_obj/exporter/obj_export_mtl.cc M source/blender/io/wavefront_obj/exporter/obj_export_mtl.hh M source/blender/io/wavefront_obj/exporter/obj_exporter.cc M source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc M source/blender/io/wavefront_obj/importer/obj_import_mtl.cc M source/blender/io/wavefront_obj/importer/obj_import_mtl.hh M source/blender/io/wavefront_obj/tests/obj_exporter_tests.cc M source/blender/io/wavefront_obj/tests/obj_mtl_parser_tests.cc === 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 66dd71d4246..9bcc061caf7 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 @@ -44,7 +44,7 @@ static const char *DEFORM_GROUP_DISABLED = "off"; * So an empty material name is written. */ static const char *MATERIAL_GROUP_DISABLED = ""; -void OBJWriter::write_vert_uv_normal_indices(FormatHandler , +void OBJWriter::write_vert_uv_normal_indices(FormatHandler , const IndexOffsets , Span vert_indices, Span uv_indices, @@ -57,12 +57,12 @@ void OBJWriter::write_vert_uv_normal_indices(FormatHandler , const int uv_offset = offsets.uv_vertex_offset + 1; const int normal_offset = offsets.normal_offset + 1; const int n = vert_indices.size(); - fh.write(); + fh.write_obj_poly_begin(); if (!flip) { for (int j = 0; j < n; ++j) { - fh.write(vert_indices[j] + vertex_offset, -uv_indices[j] + uv_offset, -normal_indices[j] + normal_offset); + fh.write_obj_poly_v_uv_normal(vert_indices[j] + vertex_offset, +uv_indices[j] + uv_offset, +normal_indices[j] + normal_offset); } } else { @@ -71,15 +71,15 @@ void OBJWriter::write_vert_uv_normal_indices(FormatHandler , * then go backwards. Same logic in other write_*_indices functions below. */ for (int k = 0; k < n; ++k) { int j = k == 0 ? 0 : n - k; - fh.write(vert_indices[j] + vertex_offset, -uv_indices[j] + uv_offset, -normal_indices[j] + normal_offset); + fh.write_obj_poly_v_uv_normal(vert_indices[j] + vertex_offset, +uv_indices[j] + uv_offset, +normal_indices[j] + normal_offset); } } - fh.write(); + fh.write_obj_poly_end(); } -void OBJWriter::write_vert_normal_indices(FormatHandler , +void OBJWriter::write_vert_normal_indices(FormatHandler , const IndexOffsets , Span vert_indices, Span /*uv_indices*/, @@ -90,24 +90,24 @@ void OBJWriter::write_vert_normal_indices(FormatHandler , const int vertex_offset = offsets.vertex_offset + 1; const int normal_offset = offsets.normal_offset + 1; const int n = vert_indices.size(); - fh.write(); + fh.write_obj_poly_begin(); if (!flip) { for (int j = 0; j < n; ++j) { - fh.write(vert_indices[j] + vertex_offset, -
[Bf-blender-cvs] [a1c8a17b4d9] blender-v3.3-release: IDManagement: fix missing WM name validation when using "keep current WM list" code path
Commit: a1c8a17b4d95794ce36ee7db86f98ab818be0ed6 Author: Aras Pranckevicius Date: Fri Aug 26 11:48:48 2022 +0300 Branches: blender-v3.3-release https://developer.blender.org/rBa1c8a17b4d95794ce36ee7db86f98ab818be0ed6 IDManagement: fix missing WM name validation when using "keep current WM list" code path The blendfile_liblink and blendfile_io python tests in debug fired an assert that WMWinMan object was in Main database, but not in the ID name map. This was caused by wm_window_match_do going into case 3 there: the new WM list is completely empty, the old list is not empty, and it was directly using the old/current list (via wm_window_match_keep_current_wm function), without actually registering/validating the objects in it through the name map. Reviewed By: Bastien Montagne Differential Revision: https://developer.blender.org/D15787 === M source/blender/windowmanager/intern/wm_files.c === diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c index 45e8f8786df..25782cb4fe7 100644 --- a/source/blender/windowmanager/intern/wm_files.c +++ b/source/blender/windowmanager/intern/wm_files.c @@ -296,6 +296,12 @@ static void wm_window_match_keep_current_wm(const bContext *C, } } + /* we'll be using the current wm list directly; make sure + * the names are validated and in the name map. */ + LISTBASE_FOREACH (wmWindowManager *, wm_item, current_wm_list) { +BKE_main_namemap_get_name(bmain, _item->id, wm_item->id.name + 2); + } + *r_new_wm_list = *current_wm_list; } ___ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs
[Bf-blender-cvs] [3e51ebaf542] master: IDManagement: fix missing WM name validation when using "keep current WM list" code path
Commit: 3e51ebaf5424bfe14176be2a9020e3153eab122e Author: Aras Pranckevicius Date: Fri Aug 26 11:48:48 2022 +0300 Branches: master https://developer.blender.org/rB3e51ebaf5424bfe14176be2a9020e3153eab122e IDManagement: fix missing WM name validation when using "keep current WM list" code path The blendfile_liblink and blendfile_io python tests in debug fired an assert that WMWinMan object was in Main database, but not in the ID name map. This was caused by wm_window_match_do going into case 3 there: the new WM list is completely empty, the old list is not empty, and it was directly using the old/current list (via wm_window_match_keep_current_wm function), without actually registering/validating the objects in it through the name map. Reviewed By: Bastien Montagne Differential Revision: https://developer.blender.org/D15787 === M source/blender/windowmanager/intern/wm_files.c === diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c index 07a6f4bdc80..fb3da9dc7ec 100644 --- a/source/blender/windowmanager/intern/wm_files.c +++ b/source/blender/windowmanager/intern/wm_files.c @@ -296,6 +296,12 @@ static void wm_window_match_keep_current_wm(const bContext *C, } } + /* we'll be using the current wm list directly; make sure + * the names are validated and in the name map. */ + LISTBASE_FOREACH (wmWindowManager *, wm_item, current_wm_list) { +BKE_main_namemap_get_name(bmain, _item->id, wm_item->id.name + 2); + } + *r_new_wm_list = *current_wm_list; } ___ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs
[Bf-blender-cvs] [1221a4049cc] master: Merge branch 'blender-v3.3-release'
Commit: 1221a4049ccbb34bc7b43e85b09c366ca7e2dd35 Author: Aras Pranckevicius Date: Tue Aug 16 13:50:19 2022 +0300 Branches: master https://developer.blender.org/rB1221a4049ccbb34bc7b43e85b09c366ca7e2dd35 Merge branch 'blender-v3.3-release' === === ___ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs
[Bf-blender-cvs] [efdcef7855e] blender-v3.3-release: Fix T100421: OBJ importer in 3.3 does not keep the vertex order
Commit: efdcef7855e378bc3183ceab16e17f3dfd8e3c76 Author: Aras Pranckevicius Date: Tue Aug 16 13:49:27 2022 +0300 Branches: blender-v3.3-release https://developer.blender.org/rBefdcef7855e378bc3183ceab16e17f3dfd8e3c76 Fix T100421: OBJ importer in 3.3 does not keep the vertex order While fixing T100302 (rBd76583cb4a1) I did not realize that the change in imported vertex order would actually matter. Turns out, it does for morph targets / mesh shape keys. So redo the fix in a way that does not change the vertex order. Fixes T100421. === M source/blender/io/wavefront_obj/importer/obj_import_mesh.cc M source/blender/io/wavefront_obj/importer/obj_import_objects.hh M source/blender/io/wavefront_obj/tests/obj_importer_tests.cc === diff --git a/source/blender/io/wavefront_obj/importer/obj_import_mesh.cc b/source/blender/io/wavefront_obj/importer/obj_import_mesh.cc index e62470588ec..a570b374231 100644 --- a/source/blender/io/wavefront_obj/importer/obj_import_mesh.cc +++ b/source/blender/io/wavefront_obj/importer/obj_import_mesh.cc @@ -157,17 +157,21 @@ void MeshFromGeometry::fixup_invalid_faces() void MeshFromGeometry::create_vertices(Mesh *mesh) { - int mi = 0; - for (int vi : mesh_geometry_.vertices_) { -if (vi < global_vertices_.vertices.size()) { - copy_v3_v3(mesh->mvert[mi].co, global_vertices_.vertices[vi]); -} -else { - std::cerr << "Vertex index:" << vi -<< " larger than total vertices:" << global_vertices_.vertices.size() << " ." -<< std::endl; + /* Go through all the global vertex indices from min to max, + * checking which ones are actually and building a global->local + * index mapping. Write out the used vertex positions into the Mesh + * data. */ + mesh_geometry_.global_to_local_vertices_.clear(); + mesh_geometry_.global_to_local_vertices_.reserve(mesh_geometry_.vertices_.size()); + for (int vi = mesh_geometry_.vertex_index_min_; vi <= mesh_geometry_.vertex_index_max_; ++vi) { +BLI_assert(vi >= 0 && vi < global_vertices_.vertices.size()); +if (!mesh_geometry_.vertices_.contains(vi)) { + continue; } -++mi; +int local_vi = (int)mesh_geometry_.global_to_local_vertices_.size(); +BLI_assert(local_vi >= 0 && local_vi < mesh->totvert); +copy_v3_v3(mesh->mvert[local_vi].co, global_vertices_.vertices[vi]); +mesh_geometry_.global_to_local_vertices_.add_new(vi, local_vi); } } diff --git a/source/blender/io/wavefront_obj/importer/obj_import_objects.hh b/source/blender/io/wavefront_obj/importer/obj_import_objects.hh index f48b6dd55e8..04d9a665588 100644 --- a/source/blender/io/wavefront_obj/importer/obj_import_objects.hh +++ b/source/blender/io/wavefront_obj/importer/obj_import_objects.hh @@ -11,8 +11,8 @@ #include "BLI_map.hh" #include "BLI_math_base.hh" #include "BLI_math_vec_types.hh" +#include "BLI_set.hh" #include "BLI_vector.hh" -#include "BLI_vector_set.hh" #include "DNA_meshdata_types.h" #include "DNA_object_types.h" @@ -93,9 +93,11 @@ struct Geometry { int vertex_index_min_ = INT_MAX; int vertex_index_max_ = -1; - VectorSet vertices_; + /* Global vertex indices used by this geometry. */ + Set vertices_; + /* Mapping from global vertex index to geometry-local vertex index. */ Map global_to_local_vertices_; - /** Edges written in the file in addition to (or even without polygon) elements. */ + /* Loose edges in the file. */ Vector edges_; Vector face_corners_; @@ -112,19 +114,15 @@ struct Geometry { } void track_vertex_index(int index) { -if (vertices_.add(index)) { - global_to_local_vertices_.add_new(index, (int)vertices_.size() - 1); -} +vertices_.add(index); math::min_inplace(vertex_index_min_, index); math::max_inplace(vertex_index_max_, index); } void track_all_vertices(int count) { vertices_.reserve(count); -global_to_local_vertices_.reserve(count); for (int i = 0; i < count; ++i) { vertices_.add(i); - global_to_local_vertices_.add(i, i); } vertex_index_min_ = 0; vertex_index_max_ = count - 1; diff --git a/source/blender/io/wavefront_obj/tests/obj_importer_tests.cc b/source/blender/io/wavefront_obj/tests/obj_importer_tests.cc index f97546fe4f5..01a73ae42a0 100644 --- a/source/blender/io/wavefront_obj/tests/obj_importer_tests.cc +++ b/source/blender/io/wavefront_obj/tests/obj_importer_tests.cc @@ -153,7 +153,7 @@ TEST_F(obj_importer_test, import_cube) 12, 6, 24, - float3(1, -1, 1), + float3(-1, -1, 1), float3(1, -1, -1), float3(-0.57735f, 0.57735f, -0.57735f)}, }; @@ -
[Bf-blender-cvs] [4cbd799373d] master: obj: support importing multiple files at once
Commit: 4cbd799373d07498813ad84f8cee5f3a8c269631 Author: Aras Pranckevicius Date: Thu Aug 11 17:05:54 2022 +0300 Branches: master https://developer.blender.org/rB4cbd799373d07498813ad84f8cee5f3a8c269631 obj: support importing multiple files at once Implemented the same way as STL or GPencil SVG importers: loop over the input files, import one by one. Has been requested by the community for quite a long time (e.g. https://blender.community/c/rightclickselect/Jhbbbc/), as well as 3rd party addons to implement just this (https://github.com/p2or/blender-batch-import-wavefront-obj). === M source/blender/editors/io/io_obj.c M source/blender/io/wavefront_obj/IO_wavefront_obj.cc M source/blender/io/wavefront_obj/IO_wavefront_obj.h M source/blender/io/wavefront_obj/importer/obj_importer.cc M source/blender/io/wavefront_obj/tests/obj_importer_tests.cc === diff --git a/source/blender/editors/io/io_obj.c b/source/blender/editors/io/io_obj.c index 662ff601e29..c151baf13ef 100644 --- a/source/blender/editors/io/io_obj.c +++ b/source/blender/editors/io/io_obj.c @@ -382,11 +382,6 @@ static int wm_obj_import_invoke(bContext *C, wmOperator *op, const wmEvent *UNUS static int wm_obj_import_exec(bContext *C, wmOperator *op) { - if (!RNA_struct_property_is_set(op->ptr, "filepath")) { -BKE_report(op->reports, RPT_ERROR, "No filename given"); -return OPERATOR_CANCELLED; - } - struct OBJImportParams import_params; RNA_string_get(op->ptr, "filepath", import_params.filepath); import_params.clamp_size = RNA_float_get(op->ptr, "clamp_size"); @@ -395,8 +390,35 @@ static int wm_obj_import_exec(bContext *C, wmOperator *op) import_params.import_vertex_groups = RNA_boolean_get(op->ptr, "import_vertex_groups"); import_params.validate_meshes = RNA_boolean_get(op->ptr, "validate_meshes"); import_params.relative_paths = ((U.flag & USER_RELPATHS) != 0); - - OBJ_import(C, _params); + import_params.clear_selection = true; + + int files_len = RNA_collection_length(op->ptr, "files"); + if (files_len) { +/* Importing multiple files: loop over them and import one by one. */ +PointerRNA fileptr; +PropertyRNA *prop; +char dir_only[FILE_MAX], file_only[FILE_MAX]; + +RNA_string_get(op->ptr, "directory", dir_only); +prop = RNA_struct_find_property(op->ptr, "files"); +for (int i = 0; i < files_len; i++) { + RNA_property_collection_lookup_int(op->ptr, prop, i, ); + RNA_string_get(, "name", file_only); + BLI_join_dirfile( + import_params.filepath, sizeof(import_params.filepath), dir_only, file_only); + import_params.clear_selection = (i == 0); + OBJ_import(C, _params); +} + } + else if (RNA_struct_property_is_set(op->ptr, "filepath")) { +/* Importing one file. */ +RNA_string_get(op->ptr, "filepath", import_params.filepath); +OBJ_import(C, _params); + } + else { +BKE_report(op->reports, RPT_ERROR, "No filename given"); +return OPERATOR_CANCELLED; + } Scene *scene = CTX_data_scene(C); WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, scene); @@ -454,7 +476,8 @@ void WM_OT_obj_import(struct wmOperatorType *ot) FILE_TYPE_FOLDER, FILE_BLENDER, FILE_OPENFILE, - WM_FILESEL_FILEPATH | WM_FILESEL_SHOW_PROPS, + WM_FILESEL_FILEPATH | WM_FILESEL_SHOW_PROPS | + WM_FILESEL_DIRECTORY | WM_FILESEL_FILES, FILE_DEFAULTDISPLAY, FILE_SORT_ALPHA); RNA_def_float( diff --git a/source/blender/io/wavefront_obj/IO_wavefront_obj.cc b/source/blender/io/wavefront_obj/IO_wavefront_obj.cc index fb0b4a1aca9..2fd2973ee73 100644 --- a/source/blender/io/wavefront_obj/IO_wavefront_obj.cc +++ b/source/blender/io/wavefront_obj/IO_wavefront_obj.cc @@ -4,6 +4,7 @@ * \ingroup obj */ +#include "BLI_path_util.h" #include "BLI_timeit.hh" #include "IO_wavefront_obj.h" @@ -11,14 +12,26 @@ #include "obj_exporter.hh" #include "obj_importer.hh" +using namespace blender::timeit; + +static void report_duration(const char *job, const TimePoint _time, const char *path) +{ + Nanoseconds duration = Clock::now() - start_time; + std::cout << "OBJ " << job << " of '" << BLI_path_basename(path) << "' took "; + print_duration(duration); + std::cout << '\n'; +} + void OBJ_export(bContext *C, const OBJExportParams *export_params) { -
[Bf-blender-cvs] [c4a0438522b] master: Merge branch 'blender-v3.3-release'
Commit: c4a0438522b7eadccb5c2d723521d5b3933fc5e9 Author: Aras Pranckevicius Date: Thu Aug 11 15:54:04 2022 +0300 Branches: master https://developer.blender.org/rBc4a0438522b7eadccb5c2d723521d5b3933fc5e9 Merge branch 'blender-v3.3-release' === === ___ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs
[Bf-blender-cvs] [0a096f2be23] blender-v3.3-release: Fix T98781: OBJ exporter wrongly writing default material socket values when textures are present
Commit: 0a096f2be233b6faca468a1add615fb72e57909e Author: Aras Pranckevicius Date: Thu Aug 11 15:51:36 2022 +0300 Branches: blender-v3.3-release https://developer.blender.org/rB0a096f2be233b6faca468a1add615fb72e57909e Fix T98781: OBJ exporter wrongly writing default material socket values when textures are present Report T98781 and part of T97642: the MTLMaterial info only captures image nodes and the default socket values. When the image information is present, do not emit the socket defaults - the .MTL spec states they are multiplied together, but the default value is not used in blender when the socket is connected. Also contains svn tests repository update to extend the test coverage, and update test expectation outputs. === M source/blender/io/wavefront_obj/exporter/obj_export_file_writer.cc M source/blender/io/wavefront_obj/exporter/obj_export_mtl.hh M source/blender/io/wavefront_obj/importer/obj_import_mtl.cc M source/blender/io/wavefront_obj/tests/obj_importer_tests.cc === 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 36a9cf1b9ae..53aa80700cc 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 @@ -547,20 +547,29 @@ StringRefNull MTLWriter::mtl_file_path() const return mtl_filepath_; } -void MTLWriter::write_bsdf_properties(const MTLMaterial _material) +void MTLWriter::write_bsdf_properties(const MTLMaterial ) { - fmt_handler_.write(mtl_material.Ns); - fmt_handler_.write( - mtl_material.Ka.x, mtl_material.Ka.y, mtl_material.Ka.z); - fmt_handler_.write( - mtl_material.Kd.x, mtl_material.Kd.y, mtl_material.Kd.z); - fmt_handler_.write( - mtl_material.Ks.x, mtl_material.Ks.y, mtl_material.Ks.z); - fmt_handler_.write( - mtl_material.Ke.x, mtl_material.Ke.y, mtl_material.Ke.z); - fmt_handler_.write(mtl_material.Ni); - fmt_handler_.write(mtl_material.d); - fmt_handler_.write(mtl_material.illum); + /* For various material properties, we only capture information + * coming from the texture, or the default value of the socket. + * When the texture is present, do not emit the default value. */ + if (!mtl.tex_map_of_type(eMTLSyntaxElement::map_Ns).is_valid()) { +fmt_handler_.write(mtl.Ns); + } + fmt_handler_.write(mtl.Ka.x, mtl.Ka.y, mtl.Ka.z); + if (!mtl.tex_map_of_type(eMTLSyntaxElement::map_Kd).is_valid()) { +fmt_handler_.write(mtl.Kd.x, mtl.Kd.y, mtl.Kd.z); + } + if (!mtl.tex_map_of_type(eMTLSyntaxElement::map_Ks).is_valid()) { +fmt_handler_.write(mtl.Ks.x, mtl.Ks.y, mtl.Ks.z); + } + if (!mtl.tex_map_of_type(eMTLSyntaxElement::map_Ke).is_valid()) { +fmt_handler_.write(mtl.Ke.x, mtl.Ke.y, mtl.Ke.z); + } + fmt_handler_.write(mtl.Ni); + if (!mtl.tex_map_of_type(eMTLSyntaxElement::map_d).is_valid()) { +fmt_handler_.write(mtl.d); + } + fmt_handler_.write(mtl.illum); } void MTLWriter::write_texture_map( @@ -583,12 +592,13 @@ void MTLWriter::write_texture_map( options.append(" -bm ").append(std::to_string(mtl_material.map_Bump_strength)); } + std::string path = path_reference( + texture_map.value.image_path.c_str(), blen_filedir, dest_dir, path_mode, _set); + /* Always emit forward slashes for cross-platform compatibility. */ + std::replace(path.begin(), path.end(), '\\', '/'); + #define SYNTAX_DISPATCH(eMTLSyntaxElement) \ if (texture_map.key == eMTLSyntaxElement) { \ -std::string path = path_reference( \ -texture_map.value.image_path.c_str(), blen_filedir, dest_dir, path_mode, _set); \ -/* Always emit forward slashes for cross-platform compatibility. */ \ -std::replace(path.begin(), path.end(), '\\', '/'); \ fmt_handler_.write(options, path.c_str()); \ return; \ } @@ -600,6 +610,7 @@ void MTLWriter::write_texture_map( SYNTAX_DISPATCH(eMTLSyntaxElement::map_refl); SYNTAX_DISPATCH(eMTLSyntaxElement::map_Ke); SYNTAX_DISPATCH(eMTLSyntaxElement::map_Bump); +#undef SYNTAX_DISPATCH BLI_assert(!"This map type was not written to the file."); } @@ -626,7 +637,7 @@ void MTLWriter::write_materials(const char *blen_filepath, fmt_handler_.write(mtlmat.name); write_bsdf_properties(mtlmat); for (const auto : mtlmat.texture_maps.items()) { - if (tex.value.image_path.empty()) { + if (!tex.value.is_valid()) { continue; } write_texture_map(mtlmat, tex, blen_filedir, dest_dir, path_mode, copy_set); diff --git a/source/blender/io/wavefront_obj/exporter/obj_export_mtl.hh b/source/blender/io/wavefront_obj/exporter/obj_export_mtl.hh index 80e3127f69f..f83b3b49bf5 100644 --- a/source/blender/io/wavefront_obj/exporter/obj_export_mtl.hh +++ b/source/blen
[Bf-blender-cvs] [bb3174e15b6] master: Merge branch 'blender-v3.3-release'
Commit: bb3174e15b63809c733b3a1cc39f05bee5042ed3 Author: Aras Pranckevicius Date: Wed Aug 10 18:06:13 2022 +0300 Branches: master https://developer.blender.org/rBbb3174e15b63809c733b3a1cc39f05bee5042ed3 Merge branch 'blender-v3.3-release' === === ___ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs
[Bf-blender-cvs] [8c59b93505b] blender-v3.3-release: obj: Also find .mtl images by their basename, if all else fails (T77801)
Commit: 8c59b93505b3066c3fd8aac121d08395eb197307 Author: Aras Pranckevicius Date: Wed Aug 10 18:03:27 2022 +0300 Branches: blender-v3.3-release https://developer.blender.org/rB8c59b93505b3066c3fd8aac121d08395eb197307 obj: Also find .mtl images by their basename, if all else fails (T77801) While T77801 itself is working as expected in the new C++ obj importer, the repro file there uses absolute paths to material images, yet the images themselves are right there in the current folder. The old python based importer did find them, since it was doing a really complex image search. My understanding is that while C++ importer was developed, it was decided to not do that -- however just the "basename file in the mtl directory" sounds simple enough and gets the repro case file work correctly. === M source/blender/io/wavefront_obj/importer/obj_import_mtl.cc === diff --git a/source/blender/io/wavefront_obj/importer/obj_import_mtl.cc b/source/blender/io/wavefront_obj/importer/obj_import_mtl.cc index 0023d1159c5..27bb5aa0d71 100644 --- a/source/blender/io/wavefront_obj/importer/obj_import_mtl.cc +++ b/source/blender/io/wavefront_obj/importer/obj_import_mtl.cc @@ -134,6 +134,14 @@ static Image *load_texture_image(Main *bmain, return image; } } + /* Try taking just the basename from input path. */ + std::string base_path{tex_map.mtl_dir_path + BLI_path_basename(tex_map.image_path.c_str())}; + if (base_path != tex_path) { +image = load_image_at_path(bmain, base_path, relative_paths); +if (image != nullptr) { + return image; +} + } image = create_placeholder_image(bmain, tex_path); return image; ___ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs
[Bf-blender-cvs] [089216067fa] master: Merge branch 'blender-v3.3-release'
Commit: 089216067faa6c99d0282f9bae26f739d7e50ee9 Author: Aras Pranckevicius Date: Wed Aug 10 13:36:48 2022 +0300 Branches: master https://developer.blender.org/rB089216067faa6c99d0282f9bae26f739d7e50ee9 Merge branch 'blender-v3.3-release' === === ___ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs
[Bf-blender-cvs] [d76583cb4a1] blender-v3.3-release: Fix T100302: New OBJ importer produces too many vertices when faces don't span a continuous range
Commit: d76583cb4a16315c196f07f4acb9340f341bee47 Author: Aras Pranckevicius Date: Wed Aug 10 13:34:42 2022 +0300 Branches: blender-v3.3-release https://developer.blender.org/rBd76583cb4a16315c196f07f4acb9340f341bee47 Fix T100302: New OBJ importer produces too many vertices when faces don't span a continuous range As part of the previous fix (D15410), the importer got code to track min & max vertex indices used as part of the mesh faces. However, if faces refer to a "sparse" (i.e. non-contiguous) subset of all vertices, then the imported mesh would contain all the vertices between min & max range. Replace that with proper tracking of actually used vertex indices for each imported mesh. Fixes T100302. This does affect import performance a tiny bit, e.g. importing Blender 3.0 splash scene goes 21.7s -> 22.1s, and importing rungholt.obj goes 2.37s -> 2.48s. Importer related tests have a bunch of vertex changes in them, since now vertices are added in the order that the faces are referring to them. Which incidentally matches the order that the Python based importer was creating them too. === M source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc M source/blender/io/wavefront_obj/importer/obj_import_mesh.cc M source/blender/io/wavefront_obj/importer/obj_import_objects.hh M source/blender/io/wavefront_obj/tests/obj_importer_tests.cc === diff --git a/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc b/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc index 8594603867f..7069e1185e0 100644 --- a/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc +++ b/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc @@ -406,8 +406,7 @@ static void use_all_vertices_if_no_faces(Geometry *geom, all_geometries.begin(), all_geometries.end(), [](const std::unique_ptr ) { return g->get_vertex_count() == 0; })) { - geom->track_vertex_index(0); - geom->track_vertex_index(global_vertices.vertices.size() - 1); + geom->track_all_vertices(global_vertices.vertices.size()); } } } diff --git a/source/blender/io/wavefront_obj/importer/obj_import_mesh.cc b/source/blender/io/wavefront_obj/importer/obj_import_mesh.cc index d7b2bc2e67c..e62470588ec 100644 --- a/source/blender/io/wavefront_obj/importer/obj_import_mesh.cc +++ b/source/blender/io/wavefront_obj/importer/obj_import_mesh.cc @@ -157,17 +157,17 @@ void MeshFromGeometry::fixup_invalid_faces() void MeshFromGeometry::create_vertices(Mesh *mesh) { - const int tot_verts_object{mesh_geometry_.get_vertex_count()}; - for (int i = 0; i < tot_verts_object; ++i) { -int vi = mesh_geometry_.vertex_index_min_ + i; + int mi = 0; + for (int vi : mesh_geometry_.vertices_) { if (vi < global_vertices_.vertices.size()) { - copy_v3_v3(mesh->mvert[i].co, global_vertices_.vertices[vi]); + copy_v3_v3(mesh->mvert[mi].co, global_vertices_.vertices[vi]); } else { std::cerr << "Vertex index:" << vi << " larger than total vertices:" << global_vertices_.vertices.size() << " ." << std::endl; } +++mi; } } @@ -208,7 +208,7 @@ void MeshFromGeometry::create_polys_loops(Mesh *mesh, bool use_vertex_groups) const PolyCorner _corner = mesh_geometry_.face_corners_[curr_face.start_index_ + idx]; MLoop = mesh->mloop[tot_loop_idx]; tot_loop_idx++; - mloop.v = curr_corner.vert_index - mesh_geometry_.vertex_index_min_; + mloop.v = mesh_geometry_.global_to_local_vertices_.lookup_default(curr_corner.vert_index, 0); /* Setup vertex group data, if needed. */ if (!mesh->dvert) { @@ -240,8 +240,8 @@ void MeshFromGeometry::create_edges(Mesh *mesh) for (int i = 0; i < tot_edges; ++i) { const MEdge _edge = mesh_geometry_.edges_[i]; MEdge _edge = mesh->medge[i]; -dst_edge.v1 = src_edge.v1 - mesh_geometry_.vertex_index_min_; -dst_edge.v2 = src_edge.v2 - mesh_geometry_.vertex_index_min_; +dst_edge.v1 = mesh_geometry_.global_to_local_vertices_.lookup_default(src_edge.v1, 0); +dst_edge.v2 = mesh_geometry_.global_to_local_vertices_.lookup_default(src_edge.v2, 0); BLI_assert(dst_edge.v1 < total_verts && dst_edge.v2 < total_verts); dst_edge.flag = ME_LOOSEEDGE; } diff --git a/source/blender/io/wavefront_obj/importer/obj_import_objects.hh b/source/blender/io/wavefront_obj/importer/obj_import_objects.hh index 9f0079d7c53..f48b6dd55e8 100644 --- a/source/blender/io/wavefront_obj/importer/obj_import_objects.hh +++ b/source/blender/io/wavefront_obj/importer/obj_import_objects.hh @@ -9,6 +9,7 @@ #include "BKE_lib_id.
[Bf-blender-cvs] [ac32f5ac4f7] master: Merge branch 'blender-v3.3-release'
Commit: ac32f5ac4f737e667d8bd6389ff73f57891b49bc Author: Aras Pranckevicius Date: Wed Aug 3 19:09:57 2022 +0300 Branches: master https://developer.blender.org/rBac32f5ac4f737e667d8bd6389ff73f57891b49bc Merge branch 'blender-v3.3-release' === === ___ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs
[Bf-blender-cvs] [10c47349786] blender-v3.3-release: Fix T100173: fix missing removal of old name in BLO_update_defaults_startup_blend
Commit: 10c47349786a1197e66f057f09c0bddab11da583 Author: Aras Pranckevicius Date: Wed Aug 3 19:09:21 2022 +0300 Branches: blender-v3.3-release https://developer.blender.org/rB10c47349786a1197e66f057f09c0bddab11da583 Fix T100173: fix missing removal of old name in BLO_update_defaults_startup_blend If a screen had to be renamed, the old name was not removed from the name map. Fixes T100173. === M source/blender/blenloader/intern/versioning_defaults.c === diff --git a/source/blender/blenloader/intern/versioning_defaults.c b/source/blender/blenloader/intern/versioning_defaults.c index a2e3fd5346e..0749625137a 100644 --- a/source/blender/blenloader/intern/versioning_defaults.c +++ b/source/blender/blenloader/intern/versioning_defaults.c @@ -45,6 +45,7 @@ #include "BKE_layer.h" #include "BKE_lib_id.h" #include "BKE_main.h" +#include "BKE_main_namemap.h" #include "BKE_material.h" #include "BKE_mesh.h" #include "BKE_node.h" @@ -488,6 +489,7 @@ void BLO_update_defaults_startup_blend(Main *bmain, const char *app_template) if (layout->screen) { bScreen *screen = layout->screen; if (!STREQ(screen->id.name + 2, workspace->id.name + 2)) { +BKE_main_namemap_remove_name(bmain, >id, screen->id.name + 2); BLI_strncpy(screen->id.name + 2, workspace->id.name + 2, sizeof(screen->id.name) - 2); BLI_libblock_ensure_unique_name(bmain, screen->id.name); } ___ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs
[Bf-blender-cvs] [e3913ec6c15] master: Merge branch 'blender-v3.3-release'
Commit: e3913ec6c1517ca825eed5fb4f16dc9bc75e10f7 Author: Aras Pranckevicius Date: Wed Aug 3 09:51:34 2022 +0300 Branches: master https://developer.blender.org/rBe3913ec6c1517ca825eed5fb4f16dc9bc75e10f7 Merge branch 'blender-v3.3-release' === === ___ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs
[Bf-blender-cvs] [89f0fedb5cf] blender-v3.3-release: Fix T97769: new OBJ exporter does not replace spaces in object names
Commit: 89f0fedb5cfcde8d2d29f4cf08f3cfa194c375b2 Author: Aras Pranckevicius Date: Wed Aug 3 09:49:56 2022 +0300 Branches: blender-v3.3-release https://developer.blender.org/rB89f0fedb5cfcde8d2d29f4cf08f3cfa194c375b2 Fix T97769: new OBJ exporter does not replace spaces in object names The Python based exporter was replacing spaces with underscores in object/group names, mostly to handle cases where names could begin or end with spaces. The new exporter was not doing that. Note: spaces in material names were already handled by the new exporter. Fixes T97769. Updated test coverage expectations; one of the test files has an object with a space in the name. === M source/blender/io/wavefront_obj/exporter/obj_export_file_writer.cc M source/blender/io/wavefront_obj/tests/obj_importer_tests.cc === 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 731587bfcea..36a9cf1b9ae 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 @@ -179,13 +179,19 @@ void OBJWriter::write_mtllib_name(const StringRefNull mtl_filepath) const fh.write_to_file(outfile_); } +static void spaces_to_underscores(std::string _name) +{ + std::replace(r_name.begin(), r_name.end(), ' ', '_'); +} + void OBJWriter::write_object_name(FormatHandler , const OBJMesh _mesh_data) const { - const char *object_name = obj_mesh_data.get_object_name(); + std::string object_name = obj_mesh_data.get_object_name(); + spaces_to_underscores(object_name); if (export_params_.export_object_groups) { -const std::string object_name = obj_mesh_data.get_object_name(); -const char *mesh_name = obj_mesh_data.get_object_mesh_name(); +std::string mesh_name = obj_mesh_data.get_object_mesh_name(); +spaces_to_underscores(mesh_name); fh.write(object_name + "_" + mesh_name); return; } @@ -389,7 +395,8 @@ void OBJWriter::write_poly_elements(FormatHandler , mat_name = MATERIAL_GROUP_DISABLED; } if (export_params_.export_material_groups) { -const std::string object_name = obj_mesh_data.get_object_name(); +std::string object_name = obj_mesh_data.get_object_name(); +spaces_to_underscores(object_name); fh.write(object_name + "_" + mat_name); } buf.write(mat_name); diff --git a/source/blender/io/wavefront_obj/tests/obj_importer_tests.cc b/source/blender/io/wavefront_obj/tests/obj_importer_tests.cc index 4055d892332..339f672c3e0 100644 --- a/source/blender/io/wavefront_obj/tests/obj_importer_tests.cc +++ b/source/blender/io/wavefront_obj/tests/obj_importer_tests.cc @@ -290,7 +290,7 @@ TEST_F(obj_importer_test, import_nurbs_mesh) { Expectation expect[] = { {"OBCube", OB_MESH, 8, 12, 6, 24, float3(1, 1, -1), float3(-1, 1, 1)}, - {"OBTorus Knot", + {"OBTorus_Knot", OB_MESH, 108, 108, ___ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs
[Bf-blender-cvs] [5ddaf2fa7b8] master: Merge branch 'blender-v3.3-release'
Commit: 5ddaf2fa7b878e8c6299033e9f9392a0a174dde5 Author: Aras Pranckevicius Date: Tue Aug 2 21:01:54 2022 +0300 Branches: master https://developer.blender.org/rB5ddaf2fa7b878e8c6299033e9f9392a0a174dde5 Merge branch 'blender-v3.3-release' === === ___ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs
[Bf-blender-cvs] [ead8260a49d] blender-v3.3-release: Object: move collection resync after empty duplicate early-out
Commit: ead8260a49debaeb69967b2b4d2b62bf9728 Author: Aras Pranckevicius Date: Tue Aug 2 21:01:09 2022 +0300 Branches: blender-v3.3-release https://developer.blender.org/rBead8260a49debaeb69967b2b4d2b62bf9728 Object: move collection resync after empty duplicate early-out As pointed out in rB02b1a209be88 comment, the BKE_main_collection_sync should be after "nothing to duplicate" early-out. === M source/blender/editors/object/object_add.cc === diff --git a/source/blender/editors/object/object_add.cc b/source/blender/editors/object/object_add.cc index 55366348f38..acd7a8e3c13 100644 --- a/source/blender/editors/object/object_add.cc +++ b/source/blender/editors/object/object_add.cc @@ -3715,14 +3715,15 @@ static int duplicate_exec(bContext *C, wmOperator *op) } } CTX_DATA_END; - /* Sync the collection now, after everything is duplicated. */ BKE_layer_collection_resync_allow(); - BKE_main_collection_sync(bmain); if (source_bases_new_objects.is_empty()) { return OPERATOR_CANCELLED; } + /* Sync the collection now, after everything is duplicated. */ + BKE_main_collection_sync(bmain); + /* After sync we can get to the new Base data, process it here. */ for (const auto : source_bases_new_objects) { Object *ob_new = item.second; ___ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs
[Bf-blender-cvs] [f263334529a] master: Merge branch 'blender-v3.3-release'
Commit: f263334529a56381adcebe8d55d829502db2c717 Author: Aras Pranckevicius Date: Tue Aug 2 09:28:38 2022 +0300 Branches: master https://developer.blender.org/rBf263334529a56381adcebe8d55d829502db2c717 Merge branch 'blender-v3.3-release' === === ___ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs
[Bf-blender-cvs] [02b1a209be8] blender-v3.3-release: Fix T100118: Crash after Shift+D with nothing selected and then making new object
Commit: 02b1a209be88dc58cb635b79f4d4b300a86733e9 Author: Aras Pranckevicius Date: Tue Aug 2 09:28:17 2022 +0300 Branches: blender-v3.3-release https://developer.blender.org/rB02b1a209be88dc58cb635b79f4d4b300a86733e9 Fix T100118: Crash after Shift+D with nothing selected and then making new object Regression from rB2d041fc46823, the "nothing to do, return" code path was not re-enabling layer collection sync. Fixes T100118. === M source/blender/editors/object/object_add.cc === diff --git a/source/blender/editors/object/object_add.cc b/source/blender/editors/object/object_add.cc index e9abf8c1441..55366348f38 100644 --- a/source/blender/editors/object/object_add.cc +++ b/source/blender/editors/object/object_add.cc @@ -3715,13 +3715,13 @@ static int duplicate_exec(bContext *C, wmOperator *op) } } CTX_DATA_END; + /* Sync the collection now, after everything is duplicated. */ + BKE_layer_collection_resync_allow(); + BKE_main_collection_sync(bmain); if (source_bases_new_objects.is_empty()) { return OPERATOR_CANCELLED; } - /* Sync the collection now, after everything is duplicated. */ - BKE_layer_collection_resync_allow(); - BKE_main_collection_sync(bmain); /* After sync we can get to the new Base data, process it here. */ for (const auto : source_bases_new_objects) { ___ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs
[Bf-blender-cvs] [6b6d3b86d5b] master: Merge branch 'blender-v3.3-release'
Commit: 6b6d3b86d5b08142656fbdd06217e9f029d12193 Author: Aras Pranckevicius Date: Mon Aug 1 21:19:27 2022 +0300 Branches: master https://developer.blender.org/rB6b6d3b86d5b08142656fbdd06217e9f029d12193 Merge branch 'blender-v3.3-release' === === ___ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs
[Bf-blender-cvs] [2542fda14d8] blender-v3.3-release: Fix T99502: OBJ/MTL import: behavior changed for missing texture files
Commit: 2542fda14d851674f0ab109a0a84bab1f4040f8a Author: Aras Pranckevicius Date: Mon Aug 1 21:13:58 2022 +0300 Branches: blender-v3.3-release https://developer.blender.org/rB2542fda14d851674f0ab109a0a84bab1f4040f8a Fix T99502: OBJ/MTL import: behavior changed for missing texture files Python based OBJ importer, as well as glTF2 importer, are creating "placeholder" images for texture images that can't be found. These are empty textures (displayed as magenta), but with their file paths set so that File > External Data > Report Missing Files can report them as missing. Make the new C++ OBJ importer do the same as well. Fixes T99502. === M source/blender/io/wavefront_obj/importer/obj_import_mtl.cc M source/blender/io/wavefront_obj/tests/obj_importer_tests.cc === diff --git a/source/blender/io/wavefront_obj/importer/obj_import_mtl.cc b/source/blender/io/wavefront_obj/importer/obj_import_mtl.cc index 099929b0e67..0023d1159c5 100644 --- a/source/blender/io/wavefront_obj/importer/obj_import_mtl.cc +++ b/source/blender/io/wavefront_obj/importer/obj_import_mtl.cc @@ -62,65 +62,81 @@ static void set_property_of_socket(eNodeSocketDatatype property_type, } } -static bool load_texture_image_at_path(Main *bmain, - const tex_map_XX _map, - bNode *r_node, - const std::string , - bool relative_paths) +static Image *load_image_at_path(Main *bmain, const std::string , bool relative_paths) { - Image *tex_image = BKE_image_load_exists(bmain, path.c_str()); - if (!tex_image) { + Image *image = BKE_image_load_exists(bmain, path.c_str()); + if (!image) { fprintf(stderr, "Cannot load image file: '%s'\n", path.c_str()); -return false; +return nullptr; } fprintf(stderr, "Loaded image from: '%s'\n", path.c_str()); if (relative_paths) { -BLI_path_rel(tex_image->filepath, BKE_main_blendfile_path(bmain)); +BLI_path_rel(image->filepath, BKE_main_blendfile_path(bmain)); } - r_node->id = reinterpret_cast(tex_image); - NodeTexImage *image = static_cast(r_node->storage); - image->projection = tex_map.projection_type; - return true; + return image; } -/** - * Load image for Image Texture node and set the node properties. - * Return success if Image can be loaded successfully. - */ -static bool load_texture_image(Main *bmain, - const tex_map_XX _map, - bNode *r_node, - bool relative_paths) +static Image *create_placeholder_image(Main *bmain, const std::string ) +{ + const float color[4] = {0, 0, 0, 1}; + Image *image = BKE_image_add_generated(bmain, + 32, + 32, + BLI_path_basename(path.c_str()), + 24, + false, + IMA_GENTYPE_BLANK, + color, + false, + false, + false); + STRNCPY(image->filepath, path.c_str()); + image->source = IMA_SRC_FILE; + return image; +} + +static Image *load_texture_image(Main *bmain, + const tex_map_XX _map, + bNode *r_node, + bool relative_paths) { BLI_assert(r_node && r_node->type == SH_NODE_TEX_IMAGE); + Image *image = nullptr; /* First try treating texture path as relative. */ std::string tex_path{tex_map.mtl_dir_path + tex_map.image_path}; - if (load_texture_image_at_path(bmain, tex_map, r_node, tex_path, relative_paths)) { -return true; + image = load_image_at_path(bmain, tex_path, relative_paths); + if (image != nullptr) { +return image; } /* Then try using it directly as absolute path. */ std::string raw_path{tex_map.image_path}; - if (load_texture_image_at_path(bmain, tex_map, r_node, raw_path, relative_paths)) { -return true; + image = load_image_at_path(bmain, raw_path, relative_paths); + if (image != nullptr) { +return image; } /* Try removing quotes. */ std::string no_quote_path{tex_path}; auto end_pos = std::remove(no_quote_path.begin(), no_quote_path.end(), '"'); no_quote_path.erase(end_pos, no_quote_path.end()); - if (no_quote_path != tex_path && - load_texture_image_at_path(bmain, tex_map, r_node, no_quote_path, relative_paths)) { -return true; + if (no_quote_path != tex_path) { +image = load_image_at_path(bmain,
[Bf-blender-cvs] [0adedaa4cc9] master: Merge branch 'blender-v3.3-release'
Commit: 0adedaa4cc9a36fbf08458917837f707a5d04c74 Author: Aras Pranckevicius Date: Mon Aug 1 13:39:59 2022 +0300 Branches: master https://developer.blender.org/rB0adedaa4cc9a36fbf08458917837f707a5d04c74 Merge branch 'blender-v3.3-release' === === ___ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs
[Bf-blender-cvs] [e2be6bc03fb] blender-v3.3-release: Fix T100076: OBJ import: new importer doesn't use //relative/image/paths
Commit: e2be6bc03fbab9783f117de95d560fbc09442de2 Author: Aras Pranckevicius Date: Mon Aug 1 13:39:08 2022 +0300 Branches: blender-v3.3-release https://developer.blender.org/rBe2be6bc03fbab9783f117de95d560fbc09442de2 Fix T100076: OBJ import: new importer doesn't use //relative/image/paths The Python based importer had logic to immediately turn image paths into relative-to-blender-file paths, if user preference for relative paths is used (which is on by default). The new importer code did not have that. Fixes T100076. === M source/blender/editors/io/io_obj.c M source/blender/io/wavefront_obj/IO_wavefront_obj.h M source/blender/io/wavefront_obj/importer/obj_import_mesh.cc M source/blender/io/wavefront_obj/importer/obj_import_mesh.hh M source/blender/io/wavefront_obj/importer/obj_import_mtl.cc M source/blender/io/wavefront_obj/importer/obj_import_mtl.hh M source/blender/io/wavefront_obj/tests/obj_importer_tests.cc === diff --git a/source/blender/editors/io/io_obj.c b/source/blender/editors/io/io_obj.c index 79ec7ebf2a5..662ff601e29 100644 --- a/source/blender/editors/io/io_obj.c +++ b/source/blender/editors/io/io_obj.c @@ -394,6 +394,7 @@ static int wm_obj_import_exec(bContext *C, wmOperator *op) import_params.up_axis = RNA_enum_get(op->ptr, "up_axis"); import_params.import_vertex_groups = RNA_boolean_get(op->ptr, "import_vertex_groups"); import_params.validate_meshes = RNA_boolean_get(op->ptr, "validate_meshes"); + import_params.relative_paths = ((U.flag & USER_RELPATHS) != 0); OBJ_import(C, _params); diff --git a/source/blender/io/wavefront_obj/IO_wavefront_obj.h b/source/blender/io/wavefront_obj/IO_wavefront_obj.h index b4a00deb99c..6ad96083e37 100644 --- a/source/blender/io/wavefront_obj/IO_wavefront_obj.h +++ b/source/blender/io/wavefront_obj/IO_wavefront_obj.h @@ -74,6 +74,7 @@ struct OBJImportParams { eIOAxis up_axis; bool import_vertex_groups; bool validate_meshes; + bool relative_paths; }; /** diff --git a/source/blender/io/wavefront_obj/importer/obj_import_mesh.cc b/source/blender/io/wavefront_obj/importer/obj_import_mesh.cc index 01f05466b3a..6f66ce5a6bd 100644 --- a/source/blender/io/wavefront_obj/importer/obj_import_mesh.cc +++ b/source/blender/io/wavefront_obj/importer/obj_import_mesh.cc @@ -57,7 +57,7 @@ Object *MeshFromGeometry::create_mesh(Main *bmain, create_uv_verts(mesh); create_normals(mesh); create_colors(mesh); - create_materials(bmain, materials, created_materials, obj); + create_materials(bmain, materials, created_materials, obj, import_params.relative_paths); if (import_params.validate_meshes || mesh_geometry_.has_invalid_polys_) { bool verbose_validate = false; @@ -277,7 +277,8 @@ void MeshFromGeometry::create_uv_verts(Mesh *mesh) static Material *get_or_create_material(Main *bmain, const std::string , Map> , -Map _materials) +Map _materials, +bool relative_paths) { /* Have we created this material already? */ Material **found_mat = created_materials.lookup_ptr(name); @@ -291,7 +292,7 @@ static Material *get_or_create_material(Main *bmain, const MTLMaterial = *materials.lookup_or_add(name, std::make_unique()); Material *mat = BKE_material_add(bmain, name.c_str()); - ShaderNodetreeWrap mat_wrap{bmain, mtl, mat}; + ShaderNodetreeWrap mat_wrap{bmain, mtl, mat, relative_paths}; mat->use_nodes = true; mat->nodetree = mat_wrap.get_nodetree(); BKE_ntree_update_main_tree(bmain, mat->nodetree, nullptr); @@ -303,10 +304,12 @@ static Material *get_or_create_material(Main *bmain, void MeshFromGeometry::create_materials(Main *bmain, Map> , Map _materials, -Object *obj) +Object *obj, +bool relative_paths) { for (const std::string : mesh_geometry_.material_order_) { -Material *mat = get_or_create_material(bmain, name, materials, created_materials); +Material *mat = get_or_create_material( +bmain, name, materials, created_materials, relative_paths); if (mat == nullptr) { continue; } diff --git a/source/blender/io/wavefront_obj/importer/obj_import_mesh.hh b/source/blender/io/wavefront_obj/importer/obj_import_mesh.hh index 591a7b81e63..cdc88528f1e 100644 --- a/source/blender/io/wavefront_obj/importer/obj_import_mesh.hh +++ b/source/blender/io/wavefront_obj/importer/obj_import_mesh.hh @@ -62,7 +62,8 @@ class MeshFromGeometry : NonM
[Bf-blender-cvs] [5b1ad3d7cfc] master: Merge branch 'blender-v3.3-release'
Commit: 5b1ad3d7cfc29f69b6f340169e1fe2b0db7e3b45 Author: Aras Pranckevicius Date: Sun Jul 31 18:32:26 2022 +0300 Branches: master https://developer.blender.org/rB5b1ad3d7cfc29f69b6f340169e1fe2b0db7e3b45 Merge branch 'blender-v3.3-release' === === ___ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs
[Bf-blender-cvs] [bea52819190] blender-v3.3-release: Fix T100075: OBJ import: images loaded multiple times instead of being reused
Commit: bea52819190e54da2907e6c367b493db29f6f5c9 Author: Aras Pranckevicius Date: Sun Jul 31 18:10:48 2022 +0300 Branches: blender-v3.3-release https://developer.blender.org/rBbea52819190e54da2907e6c367b493db29f6f5c9 Fix T100075: OBJ import: images loaded multiple times instead of being reused The new OBJ/MTL importer was creating a new image for any referenced texture, even if another material (or another property of the same material) already referenced the same texture. Make it use BKE_image_load_exists function just like Collada or USD importers do. Fixes T100075. Extended test coverage to count imported images; without the fix import_cubes_with_textures_rel would have incorrectly created 5 images instead of 4. === M source/blender/io/wavefront_obj/importer/obj_import_mtl.cc M source/blender/io/wavefront_obj/tests/obj_importer_tests.cc === diff --git a/source/blender/io/wavefront_obj/importer/obj_import_mtl.cc b/source/blender/io/wavefront_obj/importer/obj_import_mtl.cc index 60e419728f3..f7685ba0b7b 100644 --- a/source/blender/io/wavefront_obj/importer/obj_import_mtl.cc +++ b/source/blender/io/wavefront_obj/importer/obj_import_mtl.cc @@ -65,7 +65,7 @@ static bool load_texture_image_at_path(Main *bmain, bNode *r_node, const std::string ) { - Image *tex_image = BKE_image_load(bmain, path.c_str()); + Image *tex_image = BKE_image_load_exists(bmain, path.c_str()); if (!tex_image) { fprintf(stderr, "Cannot load image file: '%s'\n", path.c_str()); return false; diff --git a/source/blender/io/wavefront_obj/tests/obj_importer_tests.cc b/source/blender/io/wavefront_obj/tests/obj_importer_tests.cc index 183c543d7e3..ecf1243fa86 100644 --- a/source/blender/io/wavefront_obj/tests/obj_importer_tests.cc +++ b/source/blender/io/wavefront_obj/tests/obj_importer_tests.cc @@ -47,7 +47,8 @@ class obj_importer_test : public BlendfileLoadingBaseTest { void import_and_check(const char *path, const Expectation *expect, size_t expect_count, -int expect_mat_count) +int expect_mat_count, +int expect_image_count = 0) { if (!blendfile_load("io_tests/blend_geometry/all_quads.blend")) { ADD_FAILURE(); @@ -132,12 +133,12 @@ class obj_importer_test : public BlendfileLoadingBaseTest { DEG_OBJECT_ITER_END; EXPECT_EQ(object_index, expect_count); -/* Count number of materials. */ -int mat_count = 0; -LISTBASE_FOREACH (ID *, id, >main->materials) { - ++mat_count; -} +/* Check number of materials & textures. */ +const int mat_count = BLI_listbase_count(>main->materials); EXPECT_EQ(mat_count, expect_mat_count); + +const int ima_count = BLI_listbase_count(>main->images); +EXPECT_EQ(ima_count, expect_image_count); } }; @@ -306,7 +307,45 @@ TEST_F(obj_importer_test, import_materials) {"OBCube", OB_MESH, 8, 12, 6, 24, float3(1, 1, -1), float3(-1, 1, 1)}, {"OBmaterials", OB_MESH, 8, 12, 6, 24, float3(-1, -1, 1), float3(1, -1, -1)}, }; - import_and_check("materials.obj", expect, std::size(expect), 4); + import_and_check("materials.obj", expect, std::size(expect), 4, 1); +} + +TEST_F(obj_importer_test, import_cubes_with_textures_rel) +{ + Expectation expect[] = { + {"OBCube", OB_MESH, 8, 12, 6, 24, float3(1, 1, -1), float3(-1, 1, 1)}, + {"OBCube4Tex", + OB_MESH, + 8, + 12, + 6, + 24, + float3(1, 1, -1), + float3(-1, -1, 1), + float3(0, 1, 0), + float2(0.9935f, 0.0020f)}, + {"OBCubeTiledTex", + OB_MESH, + 8, + 12, + 6, + 24, + float3(4, 1, -1), + float3(2, -1, 1), + float3(0, 1, 0), + float2(0.9935f, 0.0020f)}, + {"OBCubeTiledTexFromAnotherFolder", + OB_MESH, + 8, + 12, + 6, + 24, + float3(7, 1, -1), + float3(5, -1, 1), + float3(0, 1, 0), + float2(0.9935f, 0.0020f)}, + }; + import_and_check("cubes_with_textures_rel.obj", expect, std::size(expect), 3, 4); } TEST_F(obj_importer_test, import_faces_invalid_or_with_holes) ___ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs
[Bf-blender-cvs] [d31886b3fe3] master: Cleanup: braces around statements in OBJ parser
Commit: d31886b3fe3b939fb86079d5fb607e80103078da Author: Aras Pranckevicius Date: Sat Jul 30 13:10:35 2022 +0300 Branches: master https://developer.blender.org/rBd31886b3fe3b939fb86079d5fb607e80103078da Cleanup: braces around statements in OBJ parser === M source/blender/io/wavefront_obj/importer/obj_import_string_utils.cc === diff --git a/source/blender/io/wavefront_obj/importer/obj_import_string_utils.cc b/source/blender/io/wavefront_obj/importer/obj_import_string_utils.cc index 9a457167fca..7e282b164b0 100644 --- a/source/blender/io/wavefront_obj/importer/obj_import_string_utils.cc +++ b/source/blender/io/wavefront_obj/importer/obj_import_string_utils.cc @@ -41,12 +41,14 @@ void fixup_line_continuations(char *p, char *end) while (true) { /* Find next backslash, if any. */ char *backslash = std::find(p, end, '\\'); -if (backslash == end) +if (backslash == end) { break; +} /* Skip over possible whitespace right after it. */ p = backslash + 1; -while (p < end && is_whitespace(*p) && *p != '\n') +while (p < end && is_whitespace(*p) && *p != '\n') { ++p; +} /* If then we have a newline, turn both backslash * and the newline into regular spaces. */ if (p < end && *p == '\n') { ___ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs
[Bf-blender-cvs] [9c65af2df0b] master: Merge branch 'blender-v3.3-release'
Commit: 9c65af2df0bfb50ec6369b2344d9b9e691397f0d Author: Aras Pranckevicius Date: Thu Jul 28 21:27:14 2022 +0300 Branches: master https://developer.blender.org/rB9c65af2df0bfb50ec6369b2344d9b9e691397f0d Merge branch 'blender-v3.3-release' === === ___ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs
[Bf-blender-cvs] [68db023329b] blender-v3.3-release: ID namemap: fix missing removal of old name in do_versions_rename_id
Commit: 68db023329b77ac06e2a7c7881391631e986c79d Author: Aras Pranckevicius Date: Thu Jul 28 21:26:30 2022 +0300 Branches: blender-v3.3-release https://developer.blender.org/rB68db023329b77ac06e2a7c7881391631e986c79d ID namemap: fix missing removal of old name in do_versions_rename_id Was causing an assert that the old name exists in the name map, but is not present in the actual database. Reported in #blender-coders === M source/blender/blenloader/intern/versioning_common.cc === diff --git a/source/blender/blenloader/intern/versioning_common.cc b/source/blender/blenloader/intern/versioning_common.cc index d2a55f6f37e..823385727e1 100644 --- a/source/blender/blenloader/intern/versioning_common.cc +++ b/source/blender/blenloader/intern/versioning_common.cc @@ -18,6 +18,7 @@ #include "BKE_animsys.h" #include "BKE_lib_id.h" #include "BKE_main.h" +#include "BKE_main_namemap.h" #include "BKE_node.h" #include "MEM_guardedalloc.h" @@ -66,6 +67,7 @@ ID *do_versions_rename_id(Main *bmain, } } if (id != nullptr) { +BKE_main_namemap_remove_name(bmain, id, id->name + 2); BLI_strncpy(id->name + 2, name_dst, sizeof(id->name) - 2); /* We know it's unique, this just sorts. */ BLI_libblock_ensure_unique_name(bmain, id->name); ___ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs
[Bf-blender-cvs] [f11dc58667f] blender-v3.2-release: Fix T99532: New OBJ importer in some cases fails to import faces
Commit: f11dc58667fbcabe6b9f0c7f5df736fc5f8d52f2 Author: Aras Pranckevicius Date: Sun Jul 10 20:09:29 2022 +0300 Branches: blender-v3.2-release https://developer.blender.org/rBf11dc58667fbcabe6b9f0c7f5df736fc5f8d52f2 Fix T99532: New OBJ importer in some cases fails to import faces The importer code was written under incorrect assumption that vertex data (v, vn, vt commands etc.) are grouped by object, i.e. follow the o command, and that each object has its own vertex data commands. This is not the case -- all the vertex data in the whole OBJ file is "global", with no relation to any objects/groups; it's just that the faces belong to the object, and then they pull in any vertices they like. This patch fixes this incorrect assumption in the importer: - Vertex data is now properly global; no need to track some sort of "offsets" per object like it was doing before. - For each object, face definitions track the minimum & maximum vertex indices referenced by the object, and then all that vertex range is created in the final Blender object. Note: it might be (unusual, but possible) that an object does not reference a sequential range of vertices, e.g. just a single face with vertex indices 1, 10, 100 -- the resulting Blender mesh will have all the 100 vertices (some "loose" without belonging to a face). It should be possible to track the used vertices exactly (e.g. with a vector set), but I haven't done that for performance reasons. Reviewed By: Howard Trickey Differential Revision: https://developer.blender.org/D15410 # Conflicts: # source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc # source/blender/io/wavefront_obj/importer/obj_import_mesh.cc # source/blender/io/wavefront_obj/importer/obj_import_objects.hh # source/blender/io/wavefront_obj/tests/obj_importer_tests.cc === M source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc M source/blender/io/wavefront_obj/importer/obj_import_mesh.cc M source/blender/io/wavefront_obj/importer/obj_import_objects.hh M source/blender/io/wavefront_obj/tests/obj_importer_tests.cc === diff --git a/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc b/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc index f801bb1d3fa..6dd696d0c21 100644 --- a/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc +++ b/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc @@ -20,31 +20,24 @@ using std::string; /** * Based on the properties of the given Geometry instance, create a new Geometry instance * or return the previous one. - * - * Also update index offsets which should always happen if a new Geometry instance is created. */ static Geometry *create_geometry(Geometry *const prev_geometry, const eGeometryType new_type, StringRef name, - const GlobalVertices _vertices, - Vector> _all_geometries, - VertexIndexOffset _offset) + Vector> _all_geometries) { auto new_geometry = [&]() { r_all_geometries.append(std::make_unique()); Geometry *g = r_all_geometries.last().get(); g->geom_type_ = new_type; g->geometry_name_ = name.is_empty() ? "New object" : name; -g->vertex_start_ = global_vertices.vertices.size(); -r_offset.set_index_offset(g->vertex_start_); return g; }; if (prev_geometry && prev_geometry->geom_type_ == GEOM_MESH) { /* After the creation of a Geometry instance, at least one element has been found in the OBJ - * file that indicates that it is a mesh (basically anything but the vertex positions). */ -if (!prev_geometry->face_elements_.is_empty() || prev_geometry->has_vertex_normals_ || -!prev_geometry->edges_.is_empty()) { + * file that indicates that it is a mesh (faces or edges). */ +if (!prev_geometry->face_elements_.is_empty() || !prev_geometry->edges_.is_empty()) { return new_geometry(); } if (new_type == GEOM_MESH) { @@ -67,19 +60,14 @@ static Geometry *create_geometry(Geometry *const prev_geometry, return new_geometry(); } -static void geom_add_vertex(Geometry *geom, -const StringRef line, -GlobalVertices _global_vertices) +static void geom_add_vertex(const StringRef line, GlobalVertices _global_vertices) { float3 vert; parse_floats(line, 0.0f, vert, 3); r_global_vertices.vertices.append(vert); - geom->vertex_count_++; } -static void geom_add_vertex_normal(Geometry *geom, - const St
[Bf-blender-cvs] [c857405c0d2] blender-v3.2-release: Fix T100017: OBJ: new importer does not import vertices that aren't part of any face
Commit: c857405c0d28a187889ce8890bd09e7391bc0218 Author: Aras Pranckevicius Date: Thu Jul 28 16:39:42 2022 +0300 Branches: blender-v3.2-release https://developer.blender.org/rBc857405c0d28a187889ce8890bd09e7391bc0218 Fix T100017: OBJ: new importer does not import vertices that aren't part of any face The Python based importer had a special case handling of "no faces in the whole file at all", where it ended up treating the whole file as essentially a point-cloud-like object (just loose vertices, no faces or edges). The new importer code was missing this special case. Fixes T100017. Added gtest coverage that was failing without the fix. # Conflicts: # source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc === M source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc M source/blender/io/wavefront_obj/tests/obj_importer_tests.cc === diff --git a/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc b/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc index 6dd696d0c21..2a8ffd44d63 100644 --- a/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc +++ b/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc @@ -13,6 +13,8 @@ #include "obj_import_file_reader.hh" +#include + namespace blender::io::obj { using std::string; @@ -322,6 +324,23 @@ static bool parse_keyword(StringRef , StringRef keyword) return true; } +/* Special case: if there were no faces/edges in any geometries, + * treat all the vertices as a point cloud. */ +static void use_all_vertices_if_no_faces(Geometry *geom, + const Vector> _geometries, + const GlobalVertices _vertices) +{ + if (!global_vertices.vertices.is_empty() && geom && geom->geom_type_ == GEOM_MESH) { +if (std::all_of( +all_geometries.begin(), all_geometries.end(), [](const std::unique_ptr ) { + return g->get_vertex_count() == 0; +})) { + geom->track_vertex_index(0); + geom->track_vertex_index(global_vertices.vertices.size() - 1); +} + } +} + void OBJParser::parse(Vector> _all_geometries, GlobalVertices _global_vertices) { @@ -493,6 +512,7 @@ void OBJParser::parse(Vector> _all_geometries, buffer_offset = left_size; } + use_all_vertices_if_no_faces(curr_geom, r_all_geometries, r_global_vertices); add_default_mtl_library(); } diff --git a/source/blender/io/wavefront_obj/tests/obj_importer_tests.cc b/source/blender/io/wavefront_obj/tests/obj_importer_tests.cc index 4c7e06e5a00..5d425d91fe6 100644 --- a/source/blender/io/wavefront_obj/tests/obj_importer_tests.cc +++ b/source/blender/io/wavefront_obj/tests/obj_importer_tests.cc @@ -522,4 +522,14 @@ TEST_F(obj_importer_test, import_all_objects) import_and_check("all_objects.obj", expect, std::size(expect), 7); } +TEST_F(obj_importer_test, import_vertices) +{ + Expectation expect[] = { + {"OBCube", OB_MESH, 8, 12, 6, 24, float3(1, 1, -1), float3(-1, 1, 1)}, + /* Loose vertices without faces or edges. */ + {"OBCube.001", OB_MESH, 8, 0, 0, 0, float3(1, 1, -1), float3(-1, 1, 1)}, + }; + import_and_check("vertices.obj", expect, std::size(expect), 0); +} + } // namespace blender::io::obj ___ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs
[Bf-blender-cvs] [38f8dfa6111] blender-v3.2-release: Fix T99536: new 3.2 OBJ importer fails with trailing space after wrapped lines
Commit: 38f8dfa611158f9d529ec89f27d5732e91e27cf8 Author: Aras Pranckevicius Date: Sun Jul 10 18:27:07 2022 +0300 Branches: blender-v3.2-release https://developer.blender.org/rB38f8dfa611158f9d529ec89f27d5732e91e27cf8 Fix T99536: new 3.2 OBJ importer fails with trailing space after wrapped lines Address the issue by re-working line continuation handling: stop trying to parse sequences like "backslash, newline" (which is the bug: it should also handle "backslash, possible whitespace, newline") during parsing. Instead, fixup line continuations after reading chunks of input file data - turn backslash and the following newline into spaces. The rest of parsing code does not have to be aware of them at all then. Makes the file attached to T99536 load correctly now. # Conflicts: # source/blender/io/common/intern/string_utils_test.cc # source/blender/io/wavefront_obj/importer/obj_import_string_utils.cc # source/blender/io/wavefront_obj/importer/obj_import_string_utils.hh === M source/blender/io/common/IO_string_utils.hh M source/blender/io/common/intern/string_utils.cc M source/blender/io/common/intern/string_utils_test.cc M source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc === diff --git a/source/blender/io/common/IO_string_utils.hh b/source/blender/io/common/IO_string_utils.hh index 25f1f01c6ed..23cb5ec7d84 100644 --- a/source/blender/io/common/IO_string_utils.hh +++ b/source/blender/io/common/IO_string_utils.hh @@ -16,21 +16,22 @@ namespace blender::io { * The returned line will not have '\n' characters at the end; * the `buffer` is modified to contain remaining text without * the input line. - * - * Note that backslash (\) character is treated as a line - * continuation, similar to OBJ file format or a C preprocessor. */ StringRef read_next_line(StringRef ); +/** + * Fix up OBJ line continuations by replacing backslash (\) and the + * following newline with spaces. + */ +void fixup_line_continuations(char *p, char *end); + /** * Drop leading white-space from a StringRef. - * Note that backslash character is considered white-space. */ StringRef drop_whitespace(StringRef str); /** * Drop leading non-white-space from a StringRef. - * Note that backslash character is considered white-space. */ StringRef drop_non_whitespace(StringRef str); diff --git a/source/blender/io/common/intern/string_utils.cc b/source/blender/io/common/intern/string_utils.cc index 3a12250e14b..eff50e40f13 100644 --- a/source/blender/io/common/intern/string_utils.cc +++ b/source/blender/io/common/intern/string_utils.cc @@ -18,14 +18,12 @@ StringRef read_next_line(StringRef ) const char *start = buffer.begin(); const char *end = buffer.end(); size_t len = 0; - char prev = 0; const char *ptr = start; while (ptr < end) { char c = *ptr++; -if (c == '\n' && prev != '\\') { +if (c == '\n') { break; } -prev = c; ++len; } @@ -35,7 +33,27 @@ StringRef read_next_line(StringRef ) static bool is_whitespace(char c) { - return c <= ' ' || c == '\\'; + return c <= ' '; +} + +void fixup_line_continuations(char *p, char *end) +{ + while (true) { +/* Find next backslash, if any. */ +char *backslash = std::find(p, end, '\\'); +if (backslash == end) + break; +/* Skip over possible whitespace right after it. */ +p = backslash + 1; +while (p < end && is_whitespace(*p) && *p != '\n') + ++p; +/* If then we have a newline, turn both backslash + * and the newline into regular spaces. */ +if (p < end && *p == '\n') { + *backslash = ' '; + *p = ' '; +} + } } StringRef drop_whitespace(StringRef str) diff --git a/source/blender/io/common/intern/string_utils_test.cc b/source/blender/io/common/intern/string_utils_test.cc index a78bd7ab8a3..91b94d22fb9 100644 --- a/source/blender/io/common/intern/string_utils_test.cc +++ b/source/blender/io/common/intern/string_utils_test.cc @@ -10,17 +10,34 @@ namespace blender::io { TEST(string_utils, read_next_line) { - std::string str = "abc\n \n\nline with \\\ncontinuation\nCRLF ending:\r\na"; + std::string str = "abc\n \n\nline with \t spaces\nCRLF ending:\r\na"; StringRef s = str; EXPECT_STRREF_EQ("abc", read_next_line(s)); EXPECT_STRREF_EQ(" ", read_next_line(s)); EXPECT_STRREF_EQ("", read_next_line(s)); - EXPECT_STRREF_EQ("line with \\\ncontinuation", read_next_line(s)); + EXPECT_STRREF_EQ("line with \t spaces", read_next_line(s)); EXPECT_STRREF_EQ("CRLF ending:\r", read_next_line(s)); EXPECT_STRREF_EQ("a", read_next_line(s)); EXPECT_TRUE(s.is_empty()); } +TEST(string_utils, fixup_line
[Bf-blender-cvs] [69bf74bd765] master: Merge branch 'blender-v3.3-release'
Commit: 69bf74bd7650f97fd186e937a53169c2eb6ad406 Author: Aras Pranckevicius Date: Thu Jul 28 16:40:37 2022 +0300 Branches: master https://developer.blender.org/rB69bf74bd7650f97fd186e937a53169c2eb6ad406 Merge branch 'blender-v3.3-release' === === ___ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs
[Bf-blender-cvs] [c49717a8247] blender-v3.3-release: Fix T100017: OBJ: new importer does not import vertices that aren't part of any face
Commit: c49717a82473e078ea4e58ef7b42d425a1b7d45a Author: Aras Pranckevicius Date: Thu Jul 28 16:39:42 2022 +0300 Branches: blender-v3.3-release https://developer.blender.org/rBc49717a82473e078ea4e58ef7b42d425a1b7d45a Fix T100017: OBJ: new importer does not import vertices that aren't part of any face The Python based importer had a special case handling of "no faces in the whole file at all", where it ended up treating the whole file as essentially a point-cloud-like object (just loose vertices, no faces or edges). The new importer code was missing this special case. Fixes T100017. Added gtest coverage that was failing without the fix. === M source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc M source/blender/io/wavefront_obj/tests/obj_importer_tests.cc === diff --git a/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc b/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc index a32fd90594d..8594603867f 100644 --- a/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc +++ b/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc @@ -13,6 +13,7 @@ #include "obj_import_file_reader.hh" #include "obj_import_string_utils.hh" +#include #include namespace blender::io::obj { @@ -394,6 +395,23 @@ static bool parse_keyword(const char *, const char *end, StringRef keyword) return true; } +/* Special case: if there were no faces/edges in any geometries, + * treat all the vertices as a point cloud. */ +static void use_all_vertices_if_no_faces(Geometry *geom, + const Vector> _geometries, + const GlobalVertices _vertices) +{ + if (!global_vertices.vertices.is_empty() && geom && geom->geom_type_ == GEOM_MESH) { +if (std::all_of( +all_geometries.begin(), all_geometries.end(), [](const std::unique_ptr ) { + return g->get_vertex_count() == 0; +})) { + geom->track_vertex_index(0); + geom->track_vertex_index(global_vertices.vertices.size() - 1); +} + } +} + void OBJParser::parse(Vector> _all_geometries, GlobalVertices _global_vertices) { @@ -571,6 +589,7 @@ void OBJParser::parse(Vector> _all_geometries, buffer_offset = left_size; } + use_all_vertices_if_no_faces(curr_geom, r_all_geometries, r_global_vertices); add_default_mtl_library(); } diff --git a/source/blender/io/wavefront_obj/tests/obj_importer_tests.cc b/source/blender/io/wavefront_obj/tests/obj_importer_tests.cc index c59269f5a7d..183c543d7e3 100644 --- a/source/blender/io/wavefront_obj/tests/obj_importer_tests.cc +++ b/source/blender/io/wavefront_obj/tests/obj_importer_tests.cc @@ -664,4 +664,14 @@ TEST_F(obj_importer_test, import_cubes_vertex_colors_mrgb) import_and_check("cubes_vertex_colors_mrgb.obj", expect, std::size(expect), 0); } +TEST_F(obj_importer_test, import_vertices) +{ + Expectation expect[] = { + {"OBCube", OB_MESH, 8, 12, 6, 24, float3(1, 1, -1), float3(-1, 1, 1)}, + /* Loose vertices without faces or edges. */ + {"OBCube.001", OB_MESH, 8, 0, 0, 0, float3(1, 1, -1), float3(-1, 1, 1)}, + }; + import_and_check("vertices.obj", expect, std::size(expect), 0); +} + } // namespace blender::io::obj ___ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs
[Bf-blender-cvs] [092732d1136] master: IO: speed up import of large amounts of objects in USD/OBJ by pre-sorting objects by name
Commit: 092732d1136cf4bed04f5dcb117e7f4a0df5fc0c Author: Aras Pranckevicius Date: Sat Jul 23 15:16:14 2022 +0300 Branches: master https://developer.blender.org/rB092732d1136cf4bed04f5dcb117e7f4a0df5fc0c IO: speed up import of large amounts of objects in USD/OBJ by pre-sorting objects by name Previously, when creating "very large" (tens-hundreds of thousands) amounts of objects, the Blender code that was ensuring name uniqueness was the bottleneck. That got recently addressed (D14162), however now sorting of IDs by their names is the remaining bottleneck. Name sorting code in Blender is optimized for the pattern where names are inserted in already sorted order (i.e. objects expect to get added near the end of the list). By doing this pre-sorting of objects intended to get created by an importer (USD and OBJ, in this patch), this sorting bottleneck can be largely removed, especially with very high object counts. Windows, Ryzen 5950X, import times: - OBJ, splash screen scene (26k objects): 22.0s -> 20.7s - USD, Disney Moana scene (250k objects): 585s -> 82.2s (10 minutes -> 1.5 minutes) Reviewed By: Michael Kowalski, Howard Trickey Differential Revision: https://developer.blender.org/D15506 === M source/blender/io/usd/intern/usd_capi_import.cc M source/blender/io/usd/intern/usd_reader_stage.cc M source/blender/io/usd/intern/usd_reader_stage.h M source/blender/io/wavefront_obj/importer/obj_importer.cc M source/blender/io/wavefront_obj/tests/obj_importer_tests.cc === diff --git a/source/blender/io/usd/intern/usd_capi_import.cc b/source/blender/io/usd/intern/usd_capi_import.cc index 13ae6f4d4c0..03af3aed2d0 100644 --- a/source/blender/io/usd/intern/usd_capi_import.cc +++ b/source/blender/io/usd/intern/usd_capi_import.cc @@ -218,6 +218,7 @@ static void import_startjob(void *customdata, short *stop, short *do_update, flo data->scene->r.efra = stage->GetEndTimeCode(); } + *data->do_update = true; *data->progress = 0.15f; USDStageReader *archive = new USDStageReader(stage, data->params, data->settings); @@ -226,13 +227,32 @@ static void import_startjob(void *customdata, short *stop, short *do_update, flo archive->collect_readers(data->bmain); + *data->do_update = true; *data->progress = 0.2f; const float size = static_cast(archive->readers().size()); size_t i = 0; - /* Setup parenthood */ + /* Sort readers by name: when creating a lot of objects in Blender, + * it is much faster if the order is sorted by name. */ + archive->sort_readers(); + *data->do_update = true; + *data->progress = 0.25f; + + /* Create blender objects. */ + for (USDPrimReader *reader : archive->readers()) { +if (!reader) { + continue; +} +reader->create_object(data->bmain, 0.0); +if ((++i & 1023) == 0) { + *data->do_update = true; + *data->progress = 0.25f + 0.25f * (i / size); +} + } + /* Setup parenthood and read actual object data. */ + i = 0; for (USDPrimReader *reader : archive->readers()) { if (!reader) { @@ -252,7 +272,7 @@ static void import_startjob(void *customdata, short *stop, short *do_update, flo ob->parent = parent->object(); } -*data->progress = 0.2f + 0.8f * (++i / size); +*data->progress = 0.5f + 0.5f * (++i / size); *data->do_update = true; if (G.is_break) { diff --git a/source/blender/io/usd/intern/usd_reader_stage.cc b/source/blender/io/usd/intern/usd_reader_stage.cc index 583c58a1356..df75be849e2 100644 --- a/source/blender/io/usd/intern/usd_reader_stage.cc +++ b/source/blender/io/usd/intern/usd_reader_stage.cc @@ -28,6 +28,9 @@ #include +#include "BLI_sort.hh" +#include "BLI_string.h" + namespace blender::io::usd { USDStageReader::USDStageReader(pxr::UsdStageRefPtr stage, @@ -252,8 +255,6 @@ USDPrimReader *USDStageReader::collect_readers(Main *bmain, const pxr::UsdPrim & return nullptr; } - reader->create_object(bmain, 0.0); - readers_.push_back(reader); reader->incref(); @@ -310,4 +311,14 @@ void USDStageReader::clear_readers() readers_.clear(); } +void USDStageReader::sort_readers() +{ + blender::parallel_sort( + readers_.begin(), readers_.end(), [](const USDPrimReader *a, const USDPrimReader *b) { +const char *na = a ? a->name().c_str() : ""; +const char *nb = b ? b->name().c_str() : ""; +return BLI_strcasecmp(na, nb) < 0; + }); +} + } // Namespace blender::io::usd diff --git a/source/blender/io/usd/intern/usd_reader_stage.h b/source/blender/io/usd/intern/usd_reader_stage.h index 0ed964c7679..5f4a343f874 100644 --- a/source/blender/io/usd/intern/usd_reader_stage.h +++ b/source/blend
[Bf-blender-cvs] [7f8d05131a7] master: IDManagement: Speedup ID unique name assignment by tracking used names/basenames/suffixes
Commit: 7f8d05131a7738327ae125d065df44be492ff1f2 Author: Aras Pranckevicius Date: Wed Jul 20 14:27:14 2022 +0300 Branches: master https://developer.blender.org/rB7f8d05131a7738327ae125d065df44be492ff1f2 IDManagement: Speedup ID unique name assignment by tracking used names/basenames/suffixes An implementation of T73412, roughly as outlined there: Track the names that are in use, as well as base names (before numeric suffix) plus a bit map for each base name, indicating which numeric suffixes are already used. This is done per-Main/Library, per-object-type. Timings (Windows, VS2022 Release build, AMD Ryzen 5950X): - Scene with 10k cubes, Shift+D to duplicate them all: 8.7s -> 1.9s. Name map memory usage for resulting 20k objects: 4.3MB. - Importing a 2.5GB .obj file of exported Blender 3.0 splash scene (24k objects), using the new C++ importer: 34.2s-> 22.0s. Name map memory usage for resulting scene: 8.6MB. - Importing Disney Moana USD scene (almost half a million objects): 56min -> 10min. Name map usage: ~100MB. Blender crashes later on when trying to render it, in the same place in both cases, but that's for another day. Reviewed By: Bastien Montagne Differential Revision: https://developer.blender.org/D14162 === M source/blender/blenkernel/BKE_lib_id.h M source/blender/blenkernel/BKE_main.h A source/blender/blenkernel/BKE_main_namemap.h M source/blender/blenkernel/CMakeLists.txt M source/blender/blenkernel/intern/lib_id.c M source/blender/blenkernel/intern/lib_id_delete.c M source/blender/blenkernel/intern/lib_id_test.cc M source/blender/blenkernel/intern/library.c M source/blender/blenkernel/intern/main.c A source/blender/blenkernel/intern/main_namemap.cc M source/blender/blenloader/intern/versioning_250.c M source/blender/blenloader/intern/versioning_280.c M source/blender/blenloader/intern/versioning_290.c M source/blender/blenloader/intern/versioning_300.c M source/blender/blenloader/intern/versioning_defaults.c M source/blender/editors/space_outliner/outliner_draw.cc M source/blender/makesdna/DNA_ID.h M source/blender/makesrna/intern/rna_ID.c === diff --git a/source/blender/blenkernel/BKE_lib_id.h b/source/blender/blenkernel/BKE_lib_id.h index beac608a138..59c842d614e 100644 --- a/source/blender/blenkernel/BKE_lib_id.h +++ b/source/blender/blenkernel/BKE_lib_id.h @@ -478,10 +478,12 @@ void BKE_lib_id_expand_local(struct Main *bmain, struct ID *id, int flags); * * \return true if a new name had to be created. */ -bool BKE_id_new_name_validate(struct ListBase *lb, +bool BKE_id_new_name_validate(struct Main *bmain, + struct ListBase *lb, struct ID *id, const char *name, - bool do_linked_data) ATTR_NONNULL(1, 2); + bool do_linked_data) ATTR_NONNULL(1, 2, 3); + /** * Pull an ID out of a library (make it local). Only call this for IDs that * don't have other library users. @@ -526,7 +528,7 @@ void BKE_main_lib_objects_recalc_all(struct Main *bmain); /** * Only for repairing files via versioning, avoid for general use. */ -void BKE_main_id_repair_duplicate_names_listbase(struct ListBase *lb); +void BKE_main_id_repair_duplicate_names_listbase(struct Main *bmain, struct ListBase *lb); #define MAX_ID_FULL_NAME (64 + 64 + 3 + 1) /* 64 is MAX_ID_NAME - 2 */ #define MAX_ID_FULL_NAME_UI (MAX_ID_FULL_NAME + 3) /* Adds 'keycode' two letters at beginning. */ diff --git a/source/blender/blenkernel/BKE_main.h b/source/blender/blenkernel/BKE_main.h index 2c444f42c46..4d26ed11f1b 100644 --- a/source/blender/blenkernel/BKE_main.h +++ b/source/blender/blenkernel/BKE_main.h @@ -36,6 +36,7 @@ struct IDNameLib_Map; struct ImBuf; struct Library; struct MainLock; +struct UniqueName_Map; /* Blender thumbnail, as written on file (width, height, and data as char RGBA). */ /* We pack pixel data after that struct. */ @@ -193,6 +194,9 @@ typedef struct Main { /* IDMap of IDs. Currently used when reading (expanding) libraries. */ struct IDNameLib_Map *id_map; + /* Used for efficient calculations of unique names. */ + struct UniqueName_Map *name_map; + struct MainLock *lock; } Main; diff --git a/source/blender/blenkernel/BKE_main_namemap.h b/source/blender/blenkernel/BKE_main_namemap.h new file mode 100644 index 000..d201e45a2c9 --- /dev/null +++ b/source/blender/blenkernel/BKE_main_namemap.h @@ -0,0 +1,51 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +#pragma once + +/** \file + * \ingroup bke + * + * API to ensure name uniqueness. + * + * Main database contains the UniqueName_Map which is a cache that tracks names, base + * names and their
[Bf-blender-cvs] [8fd2b79ca19] master: BLI_bitmap: ability to declare by-value, and function to find lowest unset bit
Commit: 8fd2b79ca190946fe95d915d19abbe9ddac895e9 Author: Aras Pranckevicius Date: Fri Jul 15 10:20:04 2022 +0300 Branches: master https://developer.blender.org/rB8fd2b79ca190946fe95d915d19abbe9ddac895e9 BLI_bitmap: ability to declare by-value, and function to find lowest unset bit In preparation for a larger change (D14162), some BLI_bitmap functionality that could be submitted separately: - Ability to declare a fixed size bitmap by-value, without extra memory allocation: BLI_BITMAP_DECLARE - Function to find the index of lowest unset bit: BLI_bitmap_find_first_unset - Test coverage of the above. Reviewed By: Campbell Barton, Bastien Montagne Differential Revision: https://developer.blender.org/D15454 === M source/blender/blenlib/BLI_bitmap.h M source/blender/blenlib/CMakeLists.txt M source/blender/blenlib/intern/bitmap.c A source/blender/blenlib/tests/BLI_bitmap_test.cc === diff --git a/source/blender/blenlib/BLI_bitmap.h b/source/blender/blenlib/BLI_bitmap.h index 19d8525311c..26dc6c7ffc9 100644 --- a/source/blender/blenlib/BLI_bitmap.h +++ b/source/blender/blenlib/BLI_bitmap.h @@ -53,6 +53,11 @@ typedef unsigned int BLI_bitmap; (CHECK_TYPE_INLINE(_mem, MemArena *), \ ((BLI_bitmap *)BLI_memarena_calloc(_mem, BLI_BITMAP_SIZE(_num +/** + * Declares a bitmap as a variable. + */ +#define BLI_BITMAP_DECLARE(_name, _num) BLI_bitmap _name[_BITMAP_NUM_BLOCKS(_num)] = {} + /** * Get the value of a single bit at '_index'. */ @@ -137,6 +142,12 @@ void BLI_bitmap_and_all(BLI_bitmap *dst, const BLI_bitmap *src, size_t bits); */ void BLI_bitmap_or_all(BLI_bitmap *dst, const BLI_bitmap *src, size_t bits); +/** + * Find index of the lowest unset bit. + * Returns -1 if all the bits are set. + */ +int BLI_bitmap_find_first_unset(const BLI_bitmap *bitmap, size_t bits); + #ifdef __cplusplus } #endif diff --git a/source/blender/blenlib/CMakeLists.txt b/source/blender/blenlib/CMakeLists.txt index 95b4987596e..d39a586206f 100644 --- a/source/blender/blenlib/CMakeLists.txt +++ b/source/blender/blenlib/CMakeLists.txt @@ -424,6 +424,7 @@ if(WITH_GTESTS) tests/BLI_array_store_test.cc tests/BLI_array_test.cc tests/BLI_array_utils_test.cc +tests/BLI_bitmap_test.cc tests/BLI_bounds_test.cc tests/BLI_color_test.cc tests/BLI_cpp_type_test.cc diff --git a/source/blender/blenlib/intern/bitmap.c b/source/blender/blenlib/intern/bitmap.c index 7fcbc31c066..2cc2fbc3e2f 100644 --- a/source/blender/blenlib/intern/bitmap.c +++ b/source/blender/blenlib/intern/bitmap.c @@ -11,6 +11,7 @@ #include #include "BLI_bitmap.h" +#include "BLI_math_bits.h" #include "BLI_utildefines.h" void BLI_bitmap_set_all(BLI_bitmap *bitmap, bool set, size_t bits) @@ -46,3 +47,22 @@ void BLI_bitmap_or_all(BLI_bitmap *dst, const BLI_bitmap *src, size_t bits) dst[i] |= src[i]; } } + +int BLI_bitmap_find_first_unset(const BLI_bitmap *bitmap, const size_t bits) +{ + const size_t blocks_num = _BITMAP_NUM_BLOCKS(bits); + int result = -1; + /* Skip over completely set blocks. */ + int index = 0; + while (index < blocks_num && bitmap[index] == ~0u) { +index++; + } + if (index < blocks_num) { +/* Found a partially used block: find the lowest unused bit. */ +const uint m = ~bitmap[index]; +BLI_assert(m != 0); +const uint bit_index = bitscan_forward_uint(m); +result = bit_index + (index << _BITMAP_POWER); + } + return result; +} diff --git a/source/blender/blenlib/tests/BLI_bitmap_test.cc b/source/blender/blenlib/tests/BLI_bitmap_test.cc new file mode 100644 index 000..fb9e03e3136 --- /dev/null +++ b/source/blender/blenlib/tests/BLI_bitmap_test.cc @@ -0,0 +1,46 @@ +/* SPDX-License-Identifier: Apache-2.0 */ + +#include "BLI_bitmap.h" +#include "testing/testing.h" + +namespace blender::tests { + +TEST(bitmap, empty_is_all_unset) +{ + BLI_BITMAP_DECLARE(bitmap, 10); + for (int i = 0; i < 10; ++i) { +EXPECT_FALSE(BLI_BITMAP_TEST_BOOL(bitmap, i)); + } +} + +TEST(bitmap, find_first_unset_empty) +{ + BLI_BITMAP_DECLARE(bitmap, 10); + EXPECT_EQ(0, BLI_bitmap_find_first_unset(bitmap, 10)); +} + +TEST(bitmap, find_first_unset_full) +{ + BLI_BITMAP_DECLARE(bitmap, 10); + BLI_bitmap_flip_all(bitmap, 10); + EXPECT_EQ(-1, BLI_bitmap_find_first_unset(bitmap, 10)); +} + +TEST(bitmap, find_first_unset_middle) +{ + BLI_BITMAP_DECLARE(bitmap, 100); + BLI_bitmap_flip_all(bitmap, 100); + /* Turn some bits off */ + BLI_BITMAP_DISABLE(bitmap, 53); + BLI_BITMAP_DISABLE(bitmap, 81); + BLI_BITMAP_DISABLE(bitmap, 85); + BLI_BITMAP_DISABLE(bitmap, 86); + + /* Find lowest unset bit, and set it. */ + EXPECT_EQ(53, BLI_bitmap_find_first_unset(bitmap, 100)); + BLI_BITMAP_ENABLE(bitmap, 53); + /* Now should find the nex
[Bf-blender-cvs] [63ea0f7581f] master: BLI_bitmap: fix _BITMAP_NUM_BLOCKS to not over-count by one block
Commit: 63ea0f7581faeeb629b040b7a4dc661bc84c789c Author: Aras Pranckevicius Date: Fri Jul 15 10:21:27 2022 +0300 Branches: master https://developer.blender.org/rB63ea0f7581faeeb629b040b7a4dc661bc84c789c BLI_bitmap: fix _BITMAP_NUM_BLOCKS to not over-count by one block For bit counts that were exact multiple of block size, the macro was computing one block too much. Reviewed By: Campbell Barton, Bastien Montagne Differential Revision: https://developer.blender.org/D15454 === M source/blender/blenlib/BLI_bitmap.h === diff --git a/source/blender/blenlib/BLI_bitmap.h b/source/blender/blenlib/BLI_bitmap.h index 26dc6c7ffc9..973cc5c3d1e 100644 --- a/source/blender/blenlib/BLI_bitmap.h +++ b/source/blender/blenlib/BLI_bitmap.h @@ -27,7 +27,7 @@ typedef unsigned int BLI_bitmap; /** * Number of blocks needed to hold '_num' bits. */ -#define _BITMAP_NUM_BLOCKS(_num) (((_num) >> _BITMAP_POWER) + 1) +#define _BITMAP_NUM_BLOCKS(_num) (((_num) + _BITMAP_MASK) >> _BITMAP_POWER) /** * Size (in bytes) used to hold '_num' bits. ___ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs
[Bf-blender-cvs] [6cd30d5ff04] master: IDManagement: add more ID naming tests
Commit: 6cd30d5ff04afd690e396f4aff14b38a6bc9e466 Author: Aras Pranckevicius Date: Thu Jul 14 13:41:43 2022 +0300 Branches: master https://developer.blender.org/rB6cd30d5ff04afd690e396f4aff14b38a6bc9e466 IDManagement: add more ID naming tests As part of a larger change (https://developer.blender.org/D14162), adding more test coverage for existing functionality separately. New tests: - ids_sorted_by_default - ids_sorted_by_default_with_libraries - name_too_long_handling - create_equivalent_numeric_suffixes - zero_suffix_is_never_assigned - remove_after_dup_get_original_name - name_number_suffix_assignment - renames_with_duplicates - names_are_unique_per_id_type === M source/blender/blenkernel/intern/lib_id_test.cc === diff --git a/source/blender/blenkernel/intern/lib_id_test.cc b/source/blender/blenkernel/intern/lib_id_test.cc index d6101d71be5..96718b3a65b 100644 --- a/source/blender/blenkernel/intern/lib_id_test.cc +++ b/source/blender/blenkernel/intern/lib_id_test.cc @@ -18,19 +18,18 @@ namespace blender::bke::tests { struct LibIDMainSortTestContext { - Main *bmain; -}; + Main *bmain = nullptr; -static void test_lib_id_main_sort_init(LibIDMainSortTestContext *ctx) -{ - BKE_idtype_init(); - ctx->bmain = BKE_main_new(); -} - -static void test_lib_id_main_sort_free(LibIDMainSortTestContext *ctx) -{ - BKE_main_free(ctx->bmain); -} + LibIDMainSortTestContext() + { +BKE_idtype_init(); +bmain = BKE_main_new(); + } + ~LibIDMainSortTestContext() + { +BKE_main_free(bmain); + } +}; static void test_lib_id_main_sort_check_order(std::initializer_list list) { @@ -47,8 +46,7 @@ static void test_lib_id_main_sort_check_order(std::initializer_list list) TEST(lib_id_main_sort, local_ids_1) { - LibIDMainSortTestContext ctx = {nullptr}; - test_lib_id_main_sort_init(); + LibIDMainSortTestContext ctx; EXPECT_TRUE(BLI_listbase_is_empty(>libraries)); ID *id_c = static_cast(BKE_id_new(ctx.bmain, ID_OB, "OB_C")); @@ -57,14 +55,22 @@ TEST(lib_id_main_sort, local_ids_1) EXPECT_TRUE(ctx.bmain->objects.first == id_a); EXPECT_TRUE(ctx.bmain->objects.last == id_c); test_lib_id_main_sort_check_order({id_a, id_b, id_c}); +} - test_lib_id_main_sort_free(); +static void change_lib(Main *bmain, ID *id, Library *lib) +{ + id->lib = lib; +} + +static void change_name(Main *bmain, ID *id, const char *name) +{ + BLI_strncpy(id->name + 2, name, MAX_NAME); + BKE_id_new_name_validate(>objects, id, nullptr, true); } TEST(lib_id_main_sort, linked_ids_1) { - LibIDMainSortTestContext ctx = {nullptr}; - test_lib_id_main_sort_init(); + LibIDMainSortTestContext ctx; EXPECT_TRUE(BLI_listbase_is_empty(>libraries)); Library *lib_a = static_cast(BKE_id_new(ctx.bmain, ID_LI, "LI_A")); @@ -92,14 +98,11 @@ TEST(lib_id_main_sort, linked_ids_1) EXPECT_TRUE(ctx.bmain->objects.first == id_c); EXPECT_TRUE(ctx.bmain->objects.last == id_b); test_lib_id_main_sort_check_order({id_c, id_a, id_b}); - - test_lib_id_main_sort_free(); } TEST(lib_id_main_unique_name, local_ids_1) { - LibIDMainSortTestContext ctx = {nullptr}; - test_lib_id_main_sort_init(); + LibIDMainSortTestContext ctx; EXPECT_TRUE(BLI_listbase_is_empty(>libraries)); ID *id_c = static_cast(BKE_id_new(ctx.bmain, ID_OB, "OB_C")); @@ -107,21 +110,18 @@ TEST(lib_id_main_unique_name, local_ids_1) ID *id_b = static_cast(BKE_id_new(ctx.bmain, ID_OB, "OB_B")); test_lib_id_main_sort_check_order({id_a, id_b, id_c}); - BLI_strncpy(id_c->name, id_a->name, sizeof(id_c->name)); - BKE_id_new_name_validate(>objects, id_c, nullptr, false); - EXPECT_TRUE(strcmp(id_c->name + 2, "OB_A.001") == 0); - EXPECT_TRUE(strcmp(id_a->name + 2, "OB_A") == 0); + change_name(ctx.bmain, id_c, "OB_A"); + + EXPECT_STREQ(id_c->name + 2, "OB_A.001"); + EXPECT_STREQ(id_a->name + 2, "OB_A"); EXPECT_TRUE(ctx.bmain->objects.first == id_a); EXPECT_TRUE(ctx.bmain->objects.last == id_b); test_lib_id_main_sort_check_order({id_a, id_c, id_b}); - - test_lib_id_main_sort_free(); } TEST(lib_id_main_unique_name, linked_ids_1) { - LibIDMainSortTestContext ctx = {nullptr}; - test_lib_id_main_sort_init(); + LibIDMainSortTestContext ctx; EXPECT_TRUE(BLI_listbase_is_empty(>libraries)); Library *lib_a = static_cast(BKE_id_new(ctx.bmain, ID_LI, "LI_A")); @@ -130,29 +130,263 @@ TEST(lib_id_main_unique_name, linked_ids_1) ID *id_a = static_cast(BKE_id_new(ctx.bmain, ID_OB, "OB_A")); ID *id_b = static_cast(BKE_id_new(ctx.bmain, ID_OB, "OB_B")); - id_a->lib = lib_a; + change_lib(ctx.bmain, id_a, lib_a); id_sort_by_name(>objects, id_a, nullptr); - id_b->lib = lib_a; +
[Bf-blender-cvs] [1275786238d] temp-T97352-3d-texturing-seam-bleeding-b2: Fix T99536: new 3.2 OBJ importer fails with trailing space after wrapped lines
Commit: 1275786238db72a1f4229d4c47f7ce6de06771a7 Author: Aras Pranckevicius Date: Sun Jul 10 18:27:07 2022 +0300 Branches: temp-T97352-3d-texturing-seam-bleeding-b2 https://developer.blender.org/rB1275786238db72a1f4229d4c47f7ce6de06771a7 Fix T99536: new 3.2 OBJ importer fails with trailing space after wrapped lines Address the issue by re-working line continuation handling: stop trying to parse sequences like "backslash, newline" (which is the bug: it should also handle "backslash, possible whitespace, newline") during parsing. Instead, fixup line continuations after reading chunks of input file data - turn backslash and the following newline into spaces. The rest of parsing code does not have to be aware of them at all then. Makes the file attached to T99536 load correctly now. Also will extend one of the test files in subversion tests repo to contain backslashes followed by newlines. === M source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc M source/blender/io/wavefront_obj/importer/obj_import_string_utils.cc M source/blender/io/wavefront_obj/importer/obj_import_string_utils.hh M source/blender/io/wavefront_obj/tests/obj_import_string_utils_tests.cc === diff --git a/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc b/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc index c2aa96713b1..6eb1bbc51f3 100644 --- a/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc +++ b/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc @@ -427,6 +427,11 @@ void OBJParser::parse(Vector> _all_geometries, break; /* No more data to read. */ } +/* Take care of line continuations now (turn them into spaces); + * the rest of the parsing code does not need to worry about them anymore. */ +fixup_line_continuations(buffer.data() + buffer_offset, + buffer.data() + buffer_offset + bytes_read); + /* Ensure buffer ends in a newline. */ if (bytes_read < read_buffer_size_) { if (bytes_read == 0 || buffer[buffer_offset + bytes_read - 1] != '\n') { @@ -445,9 +450,7 @@ void OBJParser::parse(Vector> _all_geometries, while (last_nl > 0) { --last_nl; if (buffer[last_nl] == '\n') { -if (last_nl < 1 || buffer[last_nl - 1] != '\\') { - break; -} +break; } } if (buffer[last_nl] != '\n') { diff --git a/source/blender/io/wavefront_obj/importer/obj_import_string_utils.cc b/source/blender/io/wavefront_obj/importer/obj_import_string_utils.cc index bc9006e1051..9a457167fca 100644 --- a/source/blender/io/wavefront_obj/importer/obj_import_string_utils.cc +++ b/source/blender/io/wavefront_obj/importer/obj_import_string_utils.cc @@ -18,14 +18,12 @@ StringRef read_next_line(StringRef ) const char *start = buffer.begin(); const char *end = buffer.end(); size_t len = 0; - char prev = 0; const char *ptr = start; while (ptr < end) { char c = *ptr++; -if (c == '\n' && prev != '\\') { +if (c == '\n') { break; } -prev = c; ++len; } @@ -35,7 +33,27 @@ StringRef read_next_line(StringRef ) static bool is_whitespace(char c) { - return c <= ' ' || c == '\\'; + return c <= ' '; +} + +void fixup_line_continuations(char *p, char *end) +{ + while (true) { +/* Find next backslash, if any. */ +char *backslash = std::find(p, end, '\\'); +if (backslash == end) + break; +/* Skip over possible whitespace right after it. */ +p = backslash + 1; +while (p < end && is_whitespace(*p) && *p != '\n') + ++p; +/* If then we have a newline, turn both backslash + * and the newline into regular spaces. */ +if (p < end && *p == '\n') { + *backslash = ' '; + *p = ' '; +} + } } const char *drop_whitespace(const char *p, const char *end) diff --git a/source/blender/io/wavefront_obj/importer/obj_import_string_utils.hh b/source/blender/io/wavefront_obj/importer/obj_import_string_utils.hh index f6dd1a6b675..e42f5080d25 100644 --- a/source/blender/io/wavefront_obj/importer/obj_import_string_utils.hh +++ b/source/blender/io/wavefront_obj/importer/obj_import_string_utils.hh @@ -6,9 +6,6 @@ /* * Various text parsing utilities used by OBJ importer. - * The utilities are not directly usable by other formats, since - * they treat backslash (\) as a whitespace character (OBJ format - * allows backslashes to function as a line-continuation character). * * Many of these functions take two pointers (p, end) indicating * which part of a string to operate on, and return a possibly @@ -27,21 +24,22 @@ namespace blender::io::obj { * The returned line will not have '\n' characters at the end; * the `buff
[Bf-blender-cvs] [3db63e67d4e] temp-T97352-3d-texturing-seam-bleeding-b2: Fix T99532: New OBJ importer in some cases fails to import faces
Commit: 3db63e67d4e7c863126b6b004ee64b34ff12e25f Author: Aras Pranckevicius Date: Sun Jul 10 20:09:29 2022 +0300 Branches: temp-T97352-3d-texturing-seam-bleeding-b2 https://developer.blender.org/rB3db63e67d4e7c863126b6b004ee64b34ff12e25f Fix T99532: New OBJ importer in some cases fails to import faces The importer code was written under incorrect assumption that vertex data (v, vn, vt commands etc.) are grouped by object, i.e. follow the o command, and that each object has its own vertex data commands. This is not the case -- all the vertex data in the whole OBJ file is "global", with no relation to any objects/groups; it's just that the faces belong to the object, and then they pull in any vertices they like. This patch fixes this incorrect assumption in the importer: - Vertex data is now properly global; no need to track some sort of "offsets" per object like it was doing before. - For each object, face definitions track the minimum & maximum vertex indices referenced by the object, and then all that vertex range is created in the final Blender object. Note: it might be (unusual, but possible) that an object does not reference a sequential range of vertices, e.g. just a single face with vertex indices 1, 10, 100 -- the resulting Blender mesh will have all the 100 vertices (some "loose" without belonging to a face). It should be possible to track the used vertices exactly (e.g. with a vector set), but I haven't done that for performance reasons. Reviewed By: Howard Trickey Differential Revision: https://developer.blender.org/D15410 === M source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc M source/blender/io/wavefront_obj/importer/obj_import_mesh.cc M source/blender/io/wavefront_obj/importer/obj_import_objects.hh M source/blender/io/wavefront_obj/tests/obj_importer_tests.cc === diff --git a/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc b/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc index 6eb1bbc51f3..a32fd90594d 100644 --- a/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc +++ b/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc @@ -22,32 +22,24 @@ using std::string; /** * Based on the properties of the given Geometry instance, create a new Geometry instance * or return the previous one. - * - * Also update index offsets which should always happen if a new Geometry instance is created. */ static Geometry *create_geometry(Geometry *const prev_geometry, const eGeometryType new_type, StringRef name, - const GlobalVertices _vertices, - Vector> _all_geometries, - VertexIndexOffset _offset) + Vector> _all_geometries) { auto new_geometry = [&]() { r_all_geometries.append(std::make_unique()); Geometry *g = r_all_geometries.last().get(); g->geom_type_ = new_type; g->geometry_name_ = name.is_empty() ? "New object" : name; -g->vertex_start_ = global_vertices.vertices.size(); -g->vertex_color_start_ = global_vertices.vertex_colors.size(); -r_offset.set_index_offset(g->vertex_start_); return g; }; if (prev_geometry && prev_geometry->geom_type_ == GEOM_MESH) { /* After the creation of a Geometry instance, at least one element has been found in the OBJ - * file that indicates that it is a mesh (basically anything but the vertex positions). */ -if (!prev_geometry->face_elements_.is_empty() || prev_geometry->has_vertex_normals_ || -!prev_geometry->edges_.is_empty()) { + * file that indicates that it is a mesh (faces or edges). */ +if (!prev_geometry->face_elements_.is_empty() || !prev_geometry->edges_.is_empty()) { return new_geometry(); } if (new_type == GEOM_MESH) { @@ -70,15 +62,11 @@ static Geometry *create_geometry(Geometry *const prev_geometry, return new_geometry(); } -static void geom_add_vertex(Geometry *geom, -const char *p, -const char *end, -GlobalVertices _global_vertices) +static void geom_add_vertex(const char *p, const char *end, GlobalVertices _global_vertices) { float3 vert; p = parse_floats(p, end, 0.0f, vert, 3); r_global_vertices.vertices.append(vert); - geom->vertex_count_++; /* OBJ extension: `xyzrgb` vertex colors, when the vertex position * is followed by 3 more RGB color components. See * http://paulbourke.net/dataformats/obj/colour.html */ @@ -88,16 +76,22 @@ static void geom_add_vertex(Geometry *geom, if
[Bf-blender-cvs] [fad857f4731] master: Fix T99532: New OBJ importer in some cases fails to import faces
Commit: fad857f47319166d3ff97029385b50059731a576 Author: Aras Pranckevicius Date: Sun Jul 10 20:09:29 2022 +0300 Branches: master https://developer.blender.org/rBfad857f47319166d3ff97029385b50059731a576 Fix T99532: New OBJ importer in some cases fails to import faces The importer code was written under incorrect assumption that vertex data (v, vn, vt commands etc.) are grouped by object, i.e. follow the o command, and that each object has its own vertex data commands. This is not the case -- all the vertex data in the whole OBJ file is "global", with no relation to any objects/groups; it's just that the faces belong to the object, and then they pull in any vertices they like. This patch fixes this incorrect assumption in the importer: - Vertex data is now properly global; no need to track some sort of "offsets" per object like it was doing before. - For each object, face definitions track the minimum & maximum vertex indices referenced by the object, and then all that vertex range is created in the final Blender object. Note: it might be (unusual, but possible) that an object does not reference a sequential range of vertices, e.g. just a single face with vertex indices 1, 10, 100 -- the resulting Blender mesh will have all the 100 vertices (some "loose" without belonging to a face). It should be possible to track the used vertices exactly (e.g. with a vector set), but I haven't done that for performance reasons. Reviewed By: Howard Trickey Differential Revision: https://developer.blender.org/D15410 === M source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc M source/blender/io/wavefront_obj/importer/obj_import_mesh.cc M source/blender/io/wavefront_obj/importer/obj_import_objects.hh M source/blender/io/wavefront_obj/tests/obj_importer_tests.cc === diff --git a/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc b/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc index 6eb1bbc51f3..a32fd90594d 100644 --- a/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc +++ b/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc @@ -22,32 +22,24 @@ using std::string; /** * Based on the properties of the given Geometry instance, create a new Geometry instance * or return the previous one. - * - * Also update index offsets which should always happen if a new Geometry instance is created. */ static Geometry *create_geometry(Geometry *const prev_geometry, const eGeometryType new_type, StringRef name, - const GlobalVertices _vertices, - Vector> _all_geometries, - VertexIndexOffset _offset) + Vector> _all_geometries) { auto new_geometry = [&]() { r_all_geometries.append(std::make_unique()); Geometry *g = r_all_geometries.last().get(); g->geom_type_ = new_type; g->geometry_name_ = name.is_empty() ? "New object" : name; -g->vertex_start_ = global_vertices.vertices.size(); -g->vertex_color_start_ = global_vertices.vertex_colors.size(); -r_offset.set_index_offset(g->vertex_start_); return g; }; if (prev_geometry && prev_geometry->geom_type_ == GEOM_MESH) { /* After the creation of a Geometry instance, at least one element has been found in the OBJ - * file that indicates that it is a mesh (basically anything but the vertex positions). */ -if (!prev_geometry->face_elements_.is_empty() || prev_geometry->has_vertex_normals_ || -!prev_geometry->edges_.is_empty()) { + * file that indicates that it is a mesh (faces or edges). */ +if (!prev_geometry->face_elements_.is_empty() || !prev_geometry->edges_.is_empty()) { return new_geometry(); } if (new_type == GEOM_MESH) { @@ -70,15 +62,11 @@ static Geometry *create_geometry(Geometry *const prev_geometry, return new_geometry(); } -static void geom_add_vertex(Geometry *geom, -const char *p, -const char *end, -GlobalVertices _global_vertices) +static void geom_add_vertex(const char *p, const char *end, GlobalVertices _global_vertices) { float3 vert; p = parse_floats(p, end, 0.0f, vert, 3); r_global_vertices.vertices.append(vert); - geom->vertex_count_++; /* OBJ extension: `xyzrgb` vertex colors, when the vertex position * is followed by 3 more RGB color components. See * http://paulbourke.net/dataformats/obj/colour.html */ @@ -88,16 +76,22 @@ static void geom_add_vertex(Geometry *geom, if (srgb.x >=
[Bf-blender-cvs] [4114ace6169] master: Fix T99536: new 3.2 OBJ importer fails with trailing space after wrapped lines
Commit: 4114ace6169282390b199ea593c93445af748903 Author: Aras Pranckevicius Date: Sun Jul 10 18:27:07 2022 +0300 Branches: master https://developer.blender.org/rB4114ace6169282390b199ea593c93445af748903 Fix T99536: new 3.2 OBJ importer fails with trailing space after wrapped lines Address the issue by re-working line continuation handling: stop trying to parse sequences like "backslash, newline" (which is the bug: it should also handle "backslash, possible whitespace, newline") during parsing. Instead, fixup line continuations after reading chunks of input file data - turn backslash and the following newline into spaces. The rest of parsing code does not have to be aware of them at all then. Makes the file attached to T99536 load correctly now. Also will extend one of the test files in subversion tests repo to contain backslashes followed by newlines. === M source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc M source/blender/io/wavefront_obj/importer/obj_import_string_utils.cc M source/blender/io/wavefront_obj/importer/obj_import_string_utils.hh M source/blender/io/wavefront_obj/tests/obj_import_string_utils_tests.cc === diff --git a/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc b/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc index c2aa96713b1..6eb1bbc51f3 100644 --- a/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc +++ b/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc @@ -427,6 +427,11 @@ void OBJParser::parse(Vector> _all_geometries, break; /* No more data to read. */ } +/* Take care of line continuations now (turn them into spaces); + * the rest of the parsing code does not need to worry about them anymore. */ +fixup_line_continuations(buffer.data() + buffer_offset, + buffer.data() + buffer_offset + bytes_read); + /* Ensure buffer ends in a newline. */ if (bytes_read < read_buffer_size_) { if (bytes_read == 0 || buffer[buffer_offset + bytes_read - 1] != '\n') { @@ -445,9 +450,7 @@ void OBJParser::parse(Vector> _all_geometries, while (last_nl > 0) { --last_nl; if (buffer[last_nl] == '\n') { -if (last_nl < 1 || buffer[last_nl - 1] != '\\') { - break; -} +break; } } if (buffer[last_nl] != '\n') { diff --git a/source/blender/io/wavefront_obj/importer/obj_import_string_utils.cc b/source/blender/io/wavefront_obj/importer/obj_import_string_utils.cc index bc9006e1051..9a457167fca 100644 --- a/source/blender/io/wavefront_obj/importer/obj_import_string_utils.cc +++ b/source/blender/io/wavefront_obj/importer/obj_import_string_utils.cc @@ -18,14 +18,12 @@ StringRef read_next_line(StringRef ) const char *start = buffer.begin(); const char *end = buffer.end(); size_t len = 0; - char prev = 0; const char *ptr = start; while (ptr < end) { char c = *ptr++; -if (c == '\n' && prev != '\\') { +if (c == '\n') { break; } -prev = c; ++len; } @@ -35,7 +33,27 @@ StringRef read_next_line(StringRef ) static bool is_whitespace(char c) { - return c <= ' ' || c == '\\'; + return c <= ' '; +} + +void fixup_line_continuations(char *p, char *end) +{ + while (true) { +/* Find next backslash, if any. */ +char *backslash = std::find(p, end, '\\'); +if (backslash == end) + break; +/* Skip over possible whitespace right after it. */ +p = backslash + 1; +while (p < end && is_whitespace(*p) && *p != '\n') + ++p; +/* If then we have a newline, turn both backslash + * and the newline into regular spaces. */ +if (p < end && *p == '\n') { + *backslash = ' '; + *p = ' '; +} + } } const char *drop_whitespace(const char *p, const char *end) diff --git a/source/blender/io/wavefront_obj/importer/obj_import_string_utils.hh b/source/blender/io/wavefront_obj/importer/obj_import_string_utils.hh index f6dd1a6b675..e42f5080d25 100644 --- a/source/blender/io/wavefront_obj/importer/obj_import_string_utils.hh +++ b/source/blender/io/wavefront_obj/importer/obj_import_string_utils.hh @@ -6,9 +6,6 @@ /* * Various text parsing utilities used by OBJ importer. - * The utilities are not directly usable by other formats, since - * they treat backslash (\) as a whitespace character (OBJ format - * allows backslashes to function as a line-continuation character). * * Many of these functions take two pointers (p, end) indicating * which part of a string to operate on, and return a possibly @@ -27,21 +24,22 @@ namespace blender::io::obj { * The returned line will not have '\n' characters at the end; * the `buffer` is modified to contain remaining tex
[Bf-blender-cvs] [50f9c1c09ce] master: OBJ: more robust .mtl texture offset/scale parsing (T89421)
Commit: 50f9c1c09ce331c7ce09115016ba3e4407691701 Author: Aras Pranckevicius Date: Thu Jul 7 11:34:04 2022 +0300 Branches: master https://developer.blender.org/rB50f9c1c09ce331c7ce09115016ba3e4407691701 OBJ: more robust .mtl texture offset/scale parsing (T89421) As pointed out in a comment on T89421, if a MTL file contained something like: `map_Ka -o 1 2.png` then it was parsed as having offset `1 2` and the texture filename just a `.png`. Make it so that mtl option numbers are parsed in a way where the number is only accepted only if it's followed by whitespace. Differential Revision: https://developer.blender.org/D15385 === M source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc M source/blender/io/wavefront_obj/importer/obj_import_string_utils.cc M source/blender/io/wavefront_obj/importer/obj_import_string_utils.hh M source/blender/io/wavefront_obj/tests/obj_import_string_utils_tests.cc M source/blender/io/wavefront_obj/tests/obj_mtl_parser_tests.cc === diff --git a/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc b/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc index 3cc17e7d8e6..c2aa96713b1 100644 --- a/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc +++ b/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc @@ -626,15 +626,15 @@ static bool parse_texture_option(const char *, { p = drop_whitespace(p, end); if (parse_keyword(p, end, "-o")) { -p = parse_floats(p, end, 0.0f, tex_map.translation, 3); +p = parse_floats(p, end, 0.0f, tex_map.translation, 3, true); return true; } if (parse_keyword(p, end, "-s")) { -p = parse_floats(p, end, 1.0f, tex_map.scale, 3); +p = parse_floats(p, end, 1.0f, tex_map.scale, 3, true); return true; } if (parse_keyword(p, end, "-bm")) { -p = parse_float(p, end, 1.0f, material->map_Bump_strength); +p = parse_float(p, end, 1.0f, material->map_Bump_strength, true, true); return true; } if (parse_keyword(p, end, "-type")) { diff --git a/source/blender/io/wavefront_obj/importer/obj_import_string_utils.cc b/source/blender/io/wavefront_obj/importer/obj_import_string_utils.cc index c8eaa046e68..bc9006e1051 100644 --- a/source/blender/io/wavefront_obj/importer/obj_import_string_utils.cc +++ b/source/blender/io/wavefront_obj/importer/obj_import_string_utils.cc @@ -62,8 +62,12 @@ static const char *drop_plus(const char *p, const char *end) return p; } -const char *parse_float( -const char *p, const char *end, float fallback, float , bool skip_space) +const char *parse_float(const char *p, +const char *end, +float fallback, +float , +bool skip_space, +bool require_trailing_space) { if (skip_space) { p = drop_whitespace(p, end); @@ -73,13 +77,23 @@ const char *parse_float( if (res.ec == std::errc::invalid_argument || res.ec == std::errc::result_out_of_range) { dst = fallback; } + else if (require_trailing_space && res.ptr < end && !is_whitespace(*res.ptr)) { +/* If there are trailing non-space characters, do not eat up the number. */ +dst = fallback; +return p; + } return res.ptr; } -const char *parse_floats(const char *p, const char *end, float fallback, float *dst, int count) +const char *parse_floats(const char *p, + const char *end, + float fallback, + float *dst, + int count, + bool require_trailing_space) { for (int i = 0; i < count; ++i) { -p = parse_float(p, end, fallback, dst[i]); +p = parse_float(p, end, fallback, dst[i], true, require_trailing_space); } return p; } diff --git a/source/blender/io/wavefront_obj/importer/obj_import_string_utils.hh b/source/blender/io/wavefront_obj/importer/obj_import_string_utils.hh index 3f428b1ab5c..f6dd1a6b675 100644 --- a/source/blender/io/wavefront_obj/importer/obj_import_string_utils.hh +++ b/source/blender/io/wavefront_obj/importer/obj_import_string_utils.hh @@ -62,12 +62,17 @@ const char *parse_int( * The parsed result is stored in `dst`. The function skips * leading white-space unless `skip_space=false`. If the * number can't be parsed (invalid syntax, out of range), - * `fallback` value is stored instead. + * `fallback` value is stored instead. If `require_trailing_space` + * is true, the character after the number has to be whitespace. * * Returns the start of remainder of the input string after parsing. */ -const char *parse_float( -const char *p, const char *end, float fallback, float , bool skip_space = true); +const char
[Bf-blender-cvs] [bddcb89cdaa] master: OBJ: always set eevee blend mode when material "d" is below 1.0
Commit: bddcb89cdaa6d9b36b3e42547a95bff792d37610 Author: Aras Pranckevicius Date: Thu Jul 7 11:32:56 2022 +0300 Branches: master https://developer.blender.org/rBbddcb89cdaa6d9b36b3e42547a95bff792d37610 OBJ: always set eevee blend mode when material "d" is below 1.0 Fixes T97743: the import code was setting EEVEE blending mode whenever a transparency texture was present (map_d), or when the materials illum was saying "yo, transparency!". But if only the material's d was below 1.0, it was not setting the blend mode, which is different to user expectations. Differential Revision: https://developer.blender.org/D15383 === M source/blender/io/wavefront_obj/importer/obj_import_mtl.cc === diff --git a/source/blender/io/wavefront_obj/importer/obj_import_mtl.cc b/source/blender/io/wavefront_obj/importer/obj_import_mtl.cc index f39def0a4af..60e419728f3 100644 --- a/source/blender/io/wavefront_obj/importer/obj_import_mtl.cc +++ b/source/blender/io/wavefront_obj/importer/obj_import_mtl.cc @@ -320,7 +320,7 @@ void ShaderNodetreeWrap::set_bsdf_socket_values(Material *mat) if (alpha != -1) { set_property_of_socket(SOCK_FLOAT, "Alpha", {alpha}, bsdf_); } - if (do_tranparency) { + if (do_tranparency || (alpha >= 0.0f && alpha < 1.0f)) { mat->blend_method = MA_BM_BLEND; } } ___ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs
[Bf-blender-cvs] [2d041fc4682] master: Object: Speed up duplication of large selections by doing fewer collection syncs
Commit: 2d041fc46823810219280f34a46a9cedd7a1151d Author: Aras Pranckevicius Date: Wed Jul 6 21:30:35 2022 +0300 Branches: master https://developer.blender.org/rB2d041fc46823810219280f34a46a9cedd7a1151d Object: Speed up duplication of large selections by doing fewer collection syncs Previous code was doing N collection syncs when duplicating N objects. New code avoids all the intermediate syncs by using BKE_layer_collection_resync_forbid and BKE_layer_collection_resync_allow, and then does one BKE_main_collection_sync + BKE_main_collection_sync_remap for the whole operation. There is some complexity involved where the Base things of newly duplicated objects can't be found yet, without the sync, so some work on them (marking them selected, active, ...) has to be deferred until after the sync. Timings: scene with 10k cubes, each with unique mesh (Windows, VS2022 Release build, AMD Ryzen 5950X): - Shift+D duplicate: 13.6s -> 9.2s - Alt+D duplicate: 4.76s -> 1.53s Reviewed By: Bastien Montagne Differential Revision: https://developer.blender.org/D14150 === M source/blender/editors/object/object_add.cc === diff --git a/source/blender/editors/object/object_add.cc b/source/blender/editors/object/object_add.cc index 41aaede8d6f..64026f7b06b 100644 --- a/source/blender/editors/object/object_add.cc +++ b/source/blender/editors/object/object_add.cc @@ -36,6 +36,7 @@ #include "BLI_math.h" #include "BLI_string.h" #include "BLI_utildefines.h" +#include "BLI_vector.hh" #include "BLT_translation.h" @@ -3600,7 +3601,8 @@ static Base *object_add_duplicate_internal(Main *bmain, ViewLayer *view_layer, Object *ob, const eDupli_ID_Flags dupflag, - const eLibIDDuplicateFlags duplicate_options) + const eLibIDDuplicateFlags duplicate_options, + Object **r_ob_new) { Base *base, *basen = nullptr; Object *obn; @@ -3611,6 +3613,9 @@ static Base *object_add_duplicate_internal(Main *bmain, else { obn = static_cast( ID_NEW_SET(ob, BKE_object_duplicate(bmain, ob, dupflag, duplicate_options))); +if (r_ob_new) { + *r_ob_new = obn; +} DEG_id_tag_update(>id, ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY); base = BKE_view_layer_base_find(view_layer, ob); @@ -3623,7 +3628,7 @@ static Base *object_add_duplicate_internal(Main *bmain, } basen = BKE_view_layer_base_find(view_layer, obn); -if (base != nullptr) { +if (base != nullptr && basen != nullptr) { basen->local_view_bits = base->local_view_bits; } @@ -3654,7 +3659,8 @@ Base *ED_object_add_duplicate( base->object, dupflag, LIB_ID_DUPLICATE_IS_SUBPROCESS | -LIB_ID_DUPLICATE_IS_ROOT_ID); +LIB_ID_DUPLICATE_IS_ROOT_ID, +nullptr); if (basen == nullptr) { return nullptr; } @@ -3687,45 +3693,73 @@ static int duplicate_exec(bContext *C, wmOperator *op) ViewLayer *view_layer = CTX_data_view_layer(C); const bool linked = RNA_boolean_get(op->ptr, "linked"); const eDupli_ID_Flags dupflag = (linked) ? (eDupli_ID_Flags)0 : (eDupli_ID_Flags)U.dupflag; - bool changed = false; /* We need to handle that here ourselves, because we may duplicate several objects, in which case * we also want to remap pointers between those... */ BKE_main_id_newptr_and_tag_clear(bmain); + /* Do not do collection re-syncs for each object; will do it once afterwards. + * However this means we can't get to new duplicated Base's immediately, will + * have to process them after the sync. */ + BKE_layer_collection_resync_forbid(); + + /* Duplicate the selected objects, remember data needed to process + * after the sync (the base of the original object, and the copy of the + * original object). */ + blender::Vector> source_bases_new_objects; + Object *ob_new_active = nullptr; + CTX_DATA_BEGIN (C, Base *, base, selected_bases) { -Base *basen = object_add_duplicate_internal(bmain, -scene, -view_layer, -base->object, -dupflag, -LIB_ID_DUPLICATE_IS_SUBPROCESS | - LIB
[Bf-blender-cvs] [94323bb4274] master: IO: speed up import of large Alembic/USD/OBJ scenes by optimizing material assignment
Commit: 94323bb427480aaaeea52f6833173866fbacf2e1 Author: Aras Pranckevicius Date: Wed Jul 6 13:29:59 2022 +0300 Branches: master https://developer.blender.org/rB94323bb427480aaaeea52f6833173866fbacf2e1 IO: speed up import of large Alembic/USD/OBJ scenes by optimizing material assignment The importer parts that were doing assignment of materials to the imported objects/meshes were essentially having a quadratic complexity in terms of scene object count. For each material assigned to each object, they were scanning the whole scene, checking which other Objects use the same Mesh data, in order to resize their material arrays to match the size. Performance details (Windows, Ryzen 5950X): - Import OBJ Blender 3.0 splash scene (24k objects): 43.0s -> 32.9s - Import USD Disney Moana scene (260k objects): saves two hours (~7400s). Note that later on this crashes when trying to render the imported result; crashes in the same way/place both in master and this patch. Implementation details: The importers were doing "scan the world" basically twice for each object, for each material: once when creating a new material slot (assigns an empty material), and then again when assigning the material. However, all these importers (USD, Alembic, OBJ) always create one Object for one Mesh. So that whole quadratic complexity resulting from "scan the world for possible other users of this obdata" is completely not needed; it just never finds anything. So add a new dedicated function BKE_object_material_assign_single_obdata that skips the expensive part, but should only be used when the caller knows that the obdata has exactly one user (the passed object). Reviewed By: Bastien Montagne, Michael Kowalski Differential Revision: https://developer.blender.org/D15145 === M source/blender/blenkernel/BKE_material.h M source/blender/blenkernel/intern/material.c M source/blender/io/alembic/intern/abc_reader_mesh.cc M source/blender/io/usd/intern/usd_reader_mesh.cc M source/blender/io/wavefront_obj/importer/obj_import_mesh.cc === diff --git a/source/blender/blenkernel/BKE_material.h b/source/blender/blenkernel/BKE_material.h index 05e502f06c2..ab14fa92514 100644 --- a/source/blender/blenkernel/BKE_material.h +++ b/source/blender/blenkernel/BKE_material.h @@ -87,6 +87,17 @@ struct Material *BKE_object_material_get(struct Object *ob, short act); void BKE_id_material_assign(struct Main *bmain, struct ID *id, struct Material *ma, short act); void BKE_object_material_assign( struct Main *bmain, struct Object *ob, struct Material *ma, short act, int assign_type); + +/** + * Similar to #BKE_object_material_assign with #BKE_MAT_ASSIGN_OBDATA type, + * but does not scan whole Main for other usages of the same obdata. Only + * use in cases where you know that the object's obdata is only used by this one + * object. + */ +void BKE_object_material_assign_single_obdata(struct Main *bmain, + struct Object *ob, + struct Material *ma, + short act); /** * \warning this calls many more update calls per object then are needed, could be optimized. */ diff --git a/source/blender/blenkernel/intern/material.c b/source/blender/blenkernel/intern/material.c index 04a07fb42be..f899901b54e 100644 --- a/source/blender/blenkernel/intern/material.c +++ b/source/blender/blenkernel/intern/material.c @@ -954,7 +954,8 @@ void BKE_id_material_assign(Main *bmain, ID *id, Material *ma, short act) BKE_objects_materials_test_all(bmain, id); } -void BKE_object_material_assign(Main *bmain, Object *ob, Material *ma, short act, int assign_type) +static void object_material_assign( +Main *bmain, Object *ob, Material *ma, short act, int assign_type, bool do_test_all) { Material *mao, **matar, ***matarar; short *totcolp; @@ -1037,7 +1038,10 @@ void BKE_object_material_assign(Main *bmain, Object *ob, Material *ma, short act id_us_min(>id); } (*matarar)[act - 1] = ma; -BKE_objects_materials_test_all(bmain, ob->data); /* Data may be used by several objects... */ +/* Data may be used by several objects. */ +if (do_test_all) { + BKE_objects_materials_test_all(bmain, ob->data); +} } if (ma) { @@ -1045,6 +1049,19 @@ void BKE_object_material_assign(Main *bmain, Object *ob, Material *ma, short act } } +void BKE_object_material_assign(Main *bmain, Object *ob, Material *ma, short act, int assign_type) +{ + object_material_assign(bmain, ob, ma, act, assign_type, true); +} + +void BKE_object_material_assign_single_obdata(struct Main *bmain, + struct Object *ob, +
[Bf-blender-cvs] [26f721b5163] master: OBJ: extend test coverage for parsing MTL scale/offsets (T89421)
Commit: 26f721b51638f4a350e19c18406298f8cc57f453 Author: Aras Pranckevicius Date: Wed Jul 6 09:05:20 2022 +0300 Branches: master https://developer.blender.org/rB26f721b51638f4a350e19c18406298f8cc57f453 OBJ: extend test coverage for parsing MTL scale/offsets (T89421) The new OBJ/MTL importer was already handling case T89421 correctly, but there was no test coverage to prove it. Extend the tests to parse various forms of "-o" and "-s" (one, two, three numbers). === M source/blender/io/wavefront_obj/tests/obj_mtl_parser_tests.cc === diff --git a/source/blender/io/wavefront_obj/tests/obj_mtl_parser_tests.cc b/source/blender/io/wavefront_obj/tests/obj_mtl_parser_tests.cc index 068cdc0bf3a..5b909865d9b 100644 --- a/source/blender/io/wavefront_obj/tests/obj_mtl_parser_tests.cc +++ b/source/blender/io/wavefront_obj/tests/obj_mtl_parser_tests.cc @@ -158,7 +158,7 @@ TEST_F(obj_mtl_parser_test, all_objects) TEST_F(obj_mtl_parser_test, materials) { - MTLMaterial mat[5]; + MTLMaterial mat[6]; mat[0].name = "no_textures_red"; mat[0].Ka = {0.3f, 0.3f, 0.3f}; mat[0].Kd = {0.8f, 0.3f, 0.1f}; @@ -236,6 +236,20 @@ TEST_F(obj_mtl_parser_test, materials) bump.scale = {3, 4, 5}; } + mat[5].name = "Parser_ScaleOffset_Test"; + { +tex_map_XX = mat[5].tex_map_of_type(eMTLSyntaxElement::map_Kd); +kd.translation = {2.5f, 0.0f, 0.0f}; +kd.image_path = "OffsetOneValue.png"; +tex_map_XX = mat[5].tex_map_of_type(eMTLSyntaxElement::map_Ks); +ks.scale = {1.5f, 2.5f, 1.0f}; +ks.translation = {3.5f, 4.5f, 0.0f}; +ks.image_path = "ScaleOffsetBothTwovalues.png"; +tex_map_XX = mat[5].tex_map_of_type(eMTLSyntaxElement::map_Ns); +ns.scale = {0.5f, 1.0f, 1.0f}; +ns.image_path = "ScaleOneValue.png"; + } + check("materials.mtl", mat, ARRAY_SIZE(mat)); } ___ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs
[Bf-blender-cvs] [8fb8a6529fa] master: OBJ: remove "experimental" from C++ based importer/exporter, mark Python legacy
Commit: 8fb8a6529fa64d6e17042cdf469d9920eb939660 Author: Aras Pranckevicius Date: Mon Jul 4 19:10:13 2022 +0300 Branches: master https://developer.blender.org/rB8fb8a6529fa64d6e17042cdf469d9920eb939660 OBJ: remove "experimental" from C++ based importer/exporter, mark Python legacy By now I'm not aware of any serious regressions or missing functionality in the C++ based OBJ importer/exporter. They have more features (vertex colors support), and are way faster than the Python based importer/exporter. Reviewed By: Thomas Dinges, Howard Trickey Differential Revision: https://developer.blender.org/D15360 === M release/datafiles/locale M release/scripts/addons M release/scripts/startup/bl_ui/space_topbar.py === diff --git a/release/datafiles/locale b/release/datafiles/locale index 9a85b137951..055bc5223c1 16 --- a/release/datafiles/locale +++ b/release/datafiles/locale @@ -1 +1 @@ -Subproject commit 9a85b13795157560b319235c63f5a13b0107ba41 +Subproject commit 055bc5223c1cd249e32ccbc8e8796ba9925c8c33 diff --git a/release/scripts/addons b/release/scripts/addons index 807a64cdfc5..403b95ef6ff 16 --- a/release/scripts/addons +++ b/release/scripts/addons @@ -1 +1 @@ -Subproject commit 807a64cdfc50de1cfb263f2eb68680feddb66ec7 +Subproject commit 403b95ef6ff38918de966ed2a5843cfa3274a58b diff --git a/release/scripts/startup/bl_ui/space_topbar.py b/release/scripts/startup/bl_ui/space_topbar.py index d8bd724f554..31ecd67eb08 100644 --- a/release/scripts/startup/bl_ui/space_topbar.py +++ b/release/scripts/startup/bl_ui/space_topbar.py @@ -457,7 +457,7 @@ class TOPBAR_MT_file_import(Menu): self.layout.operator("wm.gpencil_import_svg", text="SVG as Grease Pencil") if bpy.app.build_options.io_wavefront_obj: -self.layout.operator("wm.obj_import", text="Wavefront (.obj) (experimental)") +self.layout.operator("wm.obj_import", text="Wavefront (.obj)") if bpy.app.build_options.io_stl: self.layout.operator("wm.stl_import", text="STL (.stl) (experimental)") @@ -485,7 +485,7 @@ class TOPBAR_MT_file_export(Menu): self.layout.operator("wm.gpencil_export_pdf", text="Grease Pencil as PDF") if bpy.app.build_options.io_wavefront_obj: -self.layout.operator("wm.obj_export", text="Wavefront (.obj) (experimental)") +self.layout.operator("wm.obj_export", text="Wavefront (.obj)") class TOPBAR_MT_file_external_data(Menu): ___ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs
[Bf-blender-cvs] [e7a21275c0f] master: IO: print import & export times of Alembic & USD
Commit: e7a21275c0f1bfb0e8bbeda384e5b46131e48b93 Author: Aras Pranckevicius Date: Fri Jul 1 12:17:50 2022 +0300 Branches: master https://developer.blender.org/rBe7a21275c0f1bfb0e8bbeda384e5b46131e48b93 IO: print import & export times of Alembic & USD Many existing importers/exporters do log the time it takes to system console (some others log more information too). In particular, OBJ (C++ & python), STL (C++ & python), PLY, glTF2 all log the time it takes. However, neither USD nor Alembic do. And also it's harder to know the time it takes there from a profiler, since all the work normally is done on a background job and is split between several threads (so you can't just find some top-level function and see how much time it took). This change: - Adds import/export time logging to USD & Alembic importer/exporter, - In the time utility class (also used by OBJ & STL), improve the output formatting: 1) print only one decimal digit, 2) for long times, print seconds and also produce a hours:minutes:seconds form. Reviewed By: Michael Kowalski, Kévin Dietrich Differential Revision: https://developer.blender.org/D15170 === M source/blender/blenlib/intern/timeit.cc M source/blender/io/alembic/exporter/abc_export_capi.cc M source/blender/io/alembic/intern/alembic_capi.cc M source/blender/io/usd/intern/usd_capi_export.cc M source/blender/io/usd/intern/usd_capi_import.cc === diff --git a/source/blender/blenlib/intern/timeit.cc b/source/blender/blenlib/intern/timeit.cc index f11f9c4ad94..7a8cf8da038 100644 --- a/source/blender/blenlib/intern/timeit.cc +++ b/source/blender/blenlib/intern/timeit.cc @@ -3,19 +3,29 @@ #include "BLI_timeit.hh" #include +#include namespace blender::timeit { void print_duration(Nanoseconds duration) { - if (duration < std::chrono::microseconds(100)) { + using namespace std::chrono; + if (duration < microseconds(100)) { std::cout << duration.count() << " ns"; } - else if (duration < std::chrono::seconds(5)) { -std::cout << duration.count() / 1.0e6 << " ms"; + else if (duration < seconds(5)) { +std::cout << std::fixed << std::setprecision(1) << duration.count() / 1.0e6 << " ms"; + } + else if (duration > seconds(90)) { +/* Long durations: print seconds, and also H:m:s */ +const auto dur_hours = duration_cast(duration); +const auto dur_mins = duration_cast(duration - dur_hours); +const auto dur_sec = duration_cast(duration - dur_hours - dur_mins); +std::cout << std::fixed << std::setprecision(1) << duration.count() / 1.0e9 << " s (" + << dur_hours.count() << "H:" << dur_mins.count() << "m:" << dur_sec.count() << "s)"; } else { -std::cout << duration.count() / 1.0e9 << " s"; +std::cout << std::fixed << std::setprecision(1) << duration.count() / 1.0e9 << " s"; } } diff --git a/source/blender/io/alembic/exporter/abc_export_capi.cc b/source/blender/io/alembic/exporter/abc_export_capi.cc index 5554fb505a4..dfca89e2c6d 100644 --- a/source/blender/io/alembic/exporter/abc_export_capi.cc +++ b/source/blender/io/alembic/exporter/abc_export_capi.cc @@ -24,6 +24,7 @@ #include "BLI_fileops.h" #include "BLI_path_util.h" #include "BLI_string.h" +#include "BLI_timeit.hh" #include "WM_api.h" #include "WM_types.h" @@ -44,6 +45,7 @@ struct ExportJobData { bool was_canceled; bool export_ok; + blender::timeit::TimePoint start_time; }; namespace blender::io::alembic { @@ -59,6 +61,14 @@ static void build_depsgraph(Depsgraph *depsgraph, const bool visible_objects_onl } } +static void report_job_duration(const ExportJobData *data) +{ + blender::timeit::Nanoseconds duration = blender::timeit::Clock::now() - data->start_time; + std::cout << "Alembic export of '" << data->filename << "' took "; + blender::timeit::print_duration(duration); + std::cout << '\n'; +} + static void export_startjob(void *customdata, /* Cannot be const, this function implements wm_jobs_start_callback. * NOLINTNEXTLINE: readability-non-const-parameter. */ @@ -68,6 +78,7 @@ static void export_startjob(void *customdata, { ExportJobData *data = static_cast(customdata); data->was_canceled = false; + data->start_time = blender::timeit::Clock::now(); G.is_rendering = true; WM_set_locked_interface(data->wm, true); @@ -177,6 +188,7 @@ static void export_endjob(void *customdata) G
[Bf-blender-cvs] [b6c5763b8ea] blender-v3.2-release: Fix T98782: ignore OBJ face normal indices if no normals are present
Commit: b6c5763b8eaec697a714a070409cdc5109a67ba5 Author: Aras Pranckevicius Date: Tue Jun 14 10:23:28 2022 +0300 Branches: blender-v3.2-release https://developer.blender.org/rBb6c5763b8eaec697a714a070409cdc5109a67ba5 Fix T98782: ignore OBJ face normal indices if no normals are present Some OBJ files out there (see T98782) have face definitions that contain vertex normal indices, but the files themselves don't contain any vertex normals. The code was doing a "hey, that's an invalid index" and skipping these faces. But the old python importer was silently ignoring these normal indices, so do the same here. Reviewed By: Howard Trickey Differential Revision: https://developer.blender.org/D15177 === M source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc === diff --git a/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc b/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc index 5720aadf39c..94d723cacf5 100644 --- a/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc +++ b/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc @@ -151,7 +151,7 @@ static void geom_add_polygon(Geometry *geom, if (!line.is_empty() && line[0] == '/') { line = line.drop_prefix(1); line = parse_int(line, INT32_MAX, corner.vertex_normal_index, false); -got_normal = corner.uv_vert_index != INT32_MAX; +got_normal = corner.vertex_normal_index != INT32_MAX; } } /* Always keep stored indices non-negative and zero-based. */ @@ -174,7 +174,10 @@ static void geom_add_polygon(Geometry *geom, face_valid = false; } } -if (got_normal) { +/* Ignore corner normal index, if the geometry does not have any normals. + * Some obj files out there do have face definitions that refer to normal indices, + * without any normals being present (T98782). */ +if (got_normal && geom->has_vertex_normals_) { corner.vertex_normal_index += corner.vertex_normal_index < 0 ? global_vertices.vertex_normals.size() : -1; ___ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs
[Bf-blender-cvs] [c5c384d6ead] blender-v3.2-release: Fix T98874: new obj importer missing an option to import vertex groups
Commit: c5c384d6eadf0a6698511cb8d81fb975389cc9ac Author: Aras Pranckevicius Date: Sun Jun 19 17:39:54 2022 +0300 Branches: blender-v3.2-release https://developer.blender.org/rBc5c384d6eadf0a6698511cb8d81fb975389cc9ac Fix T98874: new obj importer missing an option to import vertex groups The old Python OBJ importer had a (somewhat confusingly named) "Keep Vertex Order -> Poly Groups" option, that imported OBJ groups as "vertex groups" on the resulting mesh. All vertices of any face were assigned the vertex group, with a 1.0 weight. The new C++ importer did not have this option. It was trying to do something with vertex groups, but failing to actually achieve anything :) -- the vertex groups were created on the wrong object (later on overwritten by "nomain mesh to main mesh" operation); vertex weights were set to 1.0/vertex_count, and each vertex was only set to be in one group, even when it belongs to multiple faces from different groups. End result was that to the user, vertex groups were not visible/present at all (see T98874). This patch adds the import option (named "Vertex Groups"), which is off by default, and fixes the import code logic to actually do the right thing. Tested on file from T98874; vertex groups are imported just like with the Python importer. Reviewed By: Howard Trickey Differential Revision: https://developer.blender.org/D15200 === M source/blender/editors/io/io_obj.c M source/blender/io/wavefront_obj/IO_wavefront_obj.h M source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc M source/blender/io/wavefront_obj/importer/obj_import_mesh.cc M source/blender/io/wavefront_obj/importer/obj_import_mesh.hh M source/blender/io/wavefront_obj/importer/obj_import_objects.hh M source/blender/io/wavefront_obj/tests/obj_importer_tests.cc === diff --git a/source/blender/editors/io/io_obj.c b/source/blender/editors/io/io_obj.c index f1cd7607771..bb3b1a43ba5 100644 --- a/source/blender/editors/io/io_obj.c +++ b/source/blender/editors/io/io_obj.c @@ -408,6 +408,7 @@ static int wm_obj_import_exec(bContext *C, wmOperator *op) import_params.clamp_size = RNA_float_get(op->ptr, "clamp_size"); import_params.forward_axis = RNA_enum_get(op->ptr, "forward_axis"); import_params.up_axis = RNA_enum_get(op->ptr, "up_axis"); + import_params.import_vertex_groups = RNA_boolean_get(op->ptr, "import_vertex_groups"); import_params.validate_meshes = RNA_boolean_get(op->ptr, "validate_meshes"); OBJ_import(C, _params); @@ -438,6 +439,7 @@ static void ui_obj_import_settings(uiLayout *layout, PointerRNA *imfptr) box = uiLayoutBox(layout); uiItemL(box, IFACE_("Options"), ICON_EXPORT); col = uiLayoutColumn(box, false); + uiItemR(col, imfptr, "import_vertex_groups", 0, NULL, ICON_NONE); uiItemR(col, imfptr, "validate_meshes", 0, NULL, ICON_NONE); } @@ -486,6 +488,11 @@ void WM_OT_obj_import(struct wmOperatorType *ot) "Forward Axis", ""); RNA_def_enum(ot->srna, "up_axis", io_obj_transform_axis_up, OBJ_AXIS_Y_UP, "Up Axis", ""); + RNA_def_boolean(ot->srna, + "import_vertex_groups", + false, + "Vertex Groups", + "Import OBJ groups as vertex groups"); RNA_def_boolean(ot->srna, "validate_meshes", false, diff --git a/source/blender/io/wavefront_obj/IO_wavefront_obj.h b/source/blender/io/wavefront_obj/IO_wavefront_obj.h index bebad06d37f..3caf766216c 100644 --- a/source/blender/io/wavefront_obj/IO_wavefront_obj.h +++ b/source/blender/io/wavefront_obj/IO_wavefront_obj.h @@ -88,6 +88,7 @@ struct OBJImportParams { float clamp_size; eTransformAxisForward forward_axis; eTransformAxisUp up_axis; + bool import_vertex_groups; bool validate_meshes; }; diff --git a/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc b/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc index f1c9959cae5..5720aadf39c 100644 --- a/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc +++ b/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc @@ -126,7 +126,7 @@ static void geom_add_polygon(Geometry *geom, curr_face.material_index = material_index; if (group_index >= 0) { curr_face.vertex_group_index = group_index; -geom->use_vertex_groups_ = true; +geom->has_vertex_groups_ = true; } const int orig_corners_size = geom->face_corners_.size(); diff --git a/source/blender/io/wavefront_obj/importer/obj_import_mesh.cc b/source/blender/io/wavefront_obj/import
[Bf-blender-cvs] [fb64ee005ae] blender-v3.2-release: Fix T98293: Scene stats info not updated after new OBJ import
Commit: fb64ee005ae9ff60b556ca41361833682ab7c803 Author: Aras Pranckevicius Date: Mon May 23 20:42:27 2022 +0300 Branches: blender-v3.2-release https://developer.blender.org/rBfb64ee005ae9ff60b556ca41361833682ab7c803 Fix T98293: Scene stats info not updated after new OBJ import The importer was not doing a notification that the scene has changed, so the bottom status bar scene stats info was not updated right after the new OBJ import. Reviewed By: Julian Eisel Differential Revision: https://developer.blender.org/D15015 === M source/blender/editors/io/io_obj.c M source/blender/io/wavefront_obj/IO_wavefront_obj.h === diff --git a/source/blender/editors/io/io_obj.c b/source/blender/editors/io/io_obj.c index 886586ff236..f1cd7607771 100644 --- a/source/blender/editors/io/io_obj.c +++ b/source/blender/editors/io/io_obj.c @@ -16,6 +16,8 @@ #include "BLT_translation.h" +#include "ED_outliner.h" + #include "MEM_guardedalloc.h" #include "RNA_access.h" @@ -410,6 +412,12 @@ static int wm_obj_import_exec(bContext *C, wmOperator *op) OBJ_import(C, _params); + Scene *scene = CTX_data_scene(C); + WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, scene); + WM_event_add_notifier(C, NC_SCENE | ND_OB_ACTIVE, scene); + WM_event_add_notifier(C, NC_SCENE | ND_LAYER_CONTENT, scene); + ED_outliner_select_sync_from_object_tag(C); + return OPERATOR_FINISHED; } diff --git a/source/blender/io/wavefront_obj/IO_wavefront_obj.h b/source/blender/io/wavefront_obj/IO_wavefront_obj.h index f7bf678310f..bebad06d37f 100644 --- a/source/blender/io/wavefront_obj/IO_wavefront_obj.h +++ b/source/blender/io/wavefront_obj/IO_wavefront_obj.h @@ -92,12 +92,14 @@ struct OBJImportParams { }; /** - * Time the full import process. + * Perform the full import process. + * Import also changes the selection & the active object; callers + * need to update the UI bits if needed. */ void OBJ_import(bContext *C, const struct OBJImportParams *import_params); /** - * C-interface for the exporter. + * Perform the full export process. */ void OBJ_export(bContext *C, const struct OBJExportParams *export_params); ___ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs
[Bf-blender-cvs] [f02d54440de] blender-v3.2-release: Fix T97820: new OBJ importer wrongly producing "sharp" edges in some cases
Commit: f02d54440dea3716893962c6fcbe6e2f9173666f Author: Aras Pranckevicius Date: Sun Jun 19 17:38:32 2022 +0300 Branches: blender-v3.2-release https://developer.blender.org/rBf02d54440dea3716893962c6fcbe6e2f9173666f Fix T97820: new OBJ importer wrongly producing "sharp" edges in some cases The new OBJ importer is producing "sharp" edges on some meshes that should be completely smooth. Only observed on UV-Sphere type meshes so far (see T97820). I'm not 100% sure what is the root cause, but my theory was that maybe due to limited number of float digits that are printed for vertex normals in the file, the normals that are read in are not always exactly 1.0 length. And then the Blender's "set custom loop normals" function (which expects normalized inputs) wrongly marks some edges as sharp. Adding explicit normalization for the normals that are read from the file fixes the wrongly-sharp edges in test cases from T97820. I have not observed measurable performance impact in importing large models (e.g. 6-level subdivided Monkey) that contain vertex normals. Reviewed By: Howard Trickey Differential Revision: https://developer.blender.org/D15202 === M source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc === diff --git a/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc b/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc index d14401224ed..c069093ac06 100644 --- a/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc +++ b/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc @@ -5,6 +5,7 @@ */ #include "BLI_map.hh" +#include "BLI_math_vector.h" #include "BLI_string_ref.hh" #include "BLI_vector.hh" @@ -82,6 +83,10 @@ static void geom_add_vertex_normal(Geometry *geom, { float3 normal; parse_floats(line, 0.0f, normal, 3); + /* Normals can be printed with only several digits in the file, + * making them ever-so-slightly non unit length. Make sure they are + * normalized. */ + normalize_v3(normal); r_global_vertices.vertex_normals.append(normal); geom->has_vertex_normals_ = true; } ___ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs
[Bf-blender-cvs] [cf8922ef577] master: Fix T97820: new OBJ importer wrongly producing "sharp" edges in some cases
Commit: cf8922ef577083668a22d52b9b01fc545bafd206 Author: Aras Pranckevicius Date: Sun Jun 19 17:38:32 2022 +0300 Branches: master https://developer.blender.org/rBcf8922ef577083668a22d52b9b01fc545bafd206 Fix T97820: new OBJ importer wrongly producing "sharp" edges in some cases The new OBJ importer is producing "sharp" edges on some meshes that should be completely smooth. Only observed on UV-Sphere type meshes so far (see T97820). I'm not 100% sure what is the root cause, but my theory was that maybe due to limited number of float digits that are printed for vertex normals in the file, the normals that are read in are not always exactly 1.0 length. And then the Blender's "set custom loop normals" function (which expects normalized inputs) wrongly marks some edges as sharp. Adding explicit normalization for the normals that are read from the file fixes the wrongly-sharp edges in test cases from T97820. I have not observed measurable performance impact in importing large models (e.g. 6-level subdivided Monkey) that contain vertex normals. Reviewed By: Howard Trickey Differential Revision: https://developer.blender.org/D15202 === M source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc === diff --git a/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc b/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc index ee55dd1e45a..13e28be5668 100644 --- a/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc +++ b/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc @@ -6,6 +6,7 @@ #include "BLI_map.hh" #include "BLI_math_color.h" +#include "BLI_math_vector.h" #include "BLI_string_ref.hh" #include "BLI_vector.hh" @@ -129,6 +130,10 @@ static void geom_add_vertex_normal(Geometry *geom, { float3 normal; parse_floats(p, end, 0.0f, normal, 3); + /* Normals can be printed with only several digits in the file, + * making them ever-so-slightly non unit length. Make sure they are + * normalized. */ + normalize_v3(normal); r_global_vertices.vertex_normals.append(normal); geom->has_vertex_normals_ = true; } ___ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs
[Bf-blender-cvs] [91b52545989] master: Fix T98874: new obj importer missing an option to import vertex groups
Commit: 91b52545989ce29c6cd350a99191accf23d3d9dd Author: Aras Pranckevicius Date: Sun Jun 19 17:39:54 2022 +0300 Branches: master https://developer.blender.org/rB91b52545989ce29c6cd350a99191accf23d3d9dd Fix T98874: new obj importer missing an option to import vertex groups The old Python OBJ importer had a (somewhat confusingly named) "Keep Vertex Order -> Poly Groups" option, that imported OBJ groups as "vertex groups" on the resulting mesh. All vertices of any face were assigned the vertex group, with a 1.0 weight. The new C++ importer did not have this option. It was trying to do something with vertex groups, but failing to actually achieve anything :) -- the vertex groups were created on the wrong object (later on overwritten by "nomain mesh to main mesh" operation); vertex weights were set to 1.0/vertex_count, and each vertex was only set to be in one group, even when it belongs to multiple faces from different groups. End result was that to the user, vertex groups were not visible/present at all (see T98874). This patch adds the import option (named "Vertex Groups"), which is off by default, and fixes the import code logic to actually do the right thing. Tested on file from T98874; vertex groups are imported just like with the Python importer. Reviewed By: Howard Trickey Differential Revision: https://developer.blender.org/D15200 === M source/blender/editors/io/io_obj.c M source/blender/io/wavefront_obj/IO_wavefront_obj.h M source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc M source/blender/io/wavefront_obj/importer/obj_import_mesh.cc M source/blender/io/wavefront_obj/importer/obj_import_mesh.hh M source/blender/io/wavefront_obj/importer/obj_import_objects.hh M source/blender/io/wavefront_obj/tests/obj_importer_tests.cc === diff --git a/source/blender/editors/io/io_obj.c b/source/blender/editors/io/io_obj.c index 4819ae09785..53fa4788d0e 100644 --- a/source/blender/editors/io/io_obj.c +++ b/source/blender/editors/io/io_obj.c @@ -392,6 +392,7 @@ static int wm_obj_import_exec(bContext *C, wmOperator *op) import_params.clamp_size = RNA_float_get(op->ptr, "clamp_size"); import_params.forward_axis = RNA_enum_get(op->ptr, "forward_axis"); import_params.up_axis = RNA_enum_get(op->ptr, "up_axis"); + import_params.import_vertex_groups = RNA_boolean_get(op->ptr, "import_vertex_groups"); import_params.validate_meshes = RNA_boolean_get(op->ptr, "validate_meshes"); OBJ_import(C, _params); @@ -422,6 +423,7 @@ static void ui_obj_import_settings(uiLayout *layout, PointerRNA *imfptr) box = uiLayoutBox(layout); uiItemL(box, IFACE_("Options"), ICON_EXPORT); col = uiLayoutColumn(box, false); + uiItemR(col, imfptr, "import_vertex_groups", 0, NULL, ICON_NONE); uiItemR(col, imfptr, "validate_meshes", 0, NULL, ICON_NONE); } @@ -467,6 +469,11 @@ void WM_OT_obj_import(struct wmOperatorType *ot) RNA_def_enum( ot->srna, "forward_axis", io_transform_axis, IO_AXIS_NEGATIVE_Z, "Forward Axis", ""); RNA_def_enum(ot->srna, "up_axis", io_transform_axis, IO_AXIS_Y, "Up Axis", ""); + RNA_def_boolean(ot->srna, + "import_vertex_groups", + false, + "Vertex Groups", + "Import OBJ groups as vertex groups"); RNA_def_boolean(ot->srna, "validate_meshes", false, diff --git a/source/blender/io/wavefront_obj/IO_wavefront_obj.h b/source/blender/io/wavefront_obj/IO_wavefront_obj.h index a719dff2126..b4a00deb99c 100644 --- a/source/blender/io/wavefront_obj/IO_wavefront_obj.h +++ b/source/blender/io/wavefront_obj/IO_wavefront_obj.h @@ -72,6 +72,7 @@ struct OBJImportParams { float clamp_size; eIOAxis forward_axis; eIOAxis up_axis; + bool import_vertex_groups; bool validate_meshes; }; diff --git a/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc b/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc index 13e28be5668..3cc17e7d8e6 100644 --- a/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc +++ b/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc @@ -175,7 +175,7 @@ static void geom_add_polygon(Geometry *geom, curr_face.material_index = material_index; if (group_index >= 0) { curr_face.vertex_group_index = group_index; -geom->use_vertex_groups_ = true; +geom->has_vertex_groups_ = true; } const int orig_corners_size = geom->face_corners_.size(); diff --git a/source/blender/io/wavefront_obj/importer/obj_import_mesh.cc b/source/blender
[Bf-blender-cvs] [5b5811c97b5] master: USD: speed up large USD imports by not rebuilding material name map for each object
Commit: 5b5811c97b59fd187a7aafd874535c749054d5db Author: Aras Pranckevicius Date: Fri Jun 17 22:28:22 2022 +0300 Branches: master https://developer.blender.org/rB5b5811c97b59fd187a7aafd874535c749054d5db USD: speed up large USD imports by not rebuilding material name map for each object Previous code was rebuilding "name to material" map for each object being imported. Which means O(N*M) complexity (N=object count, M=material count). There was already a TODO comment suggesting that a single map that's maintained for the whole import would be enough. This commit does exactly that. While importing Moana USD scene (260k objects, 18k materials) this saves about 6 minutes of import time. Reviewed By: Bastien Montagne Differential Revision: https://developer.blender.org/D15222 === M source/blender/io/usd/intern/usd_reader_mesh.cc M source/blender/io/usd/intern/usd_reader_prim.h === diff --git a/source/blender/io/usd/intern/usd_reader_mesh.cc b/source/blender/io/usd/intern/usd_reader_mesh.cc index 368d0e1bab9..36e1a40953c 100644 --- a/source/blender/io/usd/intern/usd_reader_mesh.cc +++ b/source/blender/io/usd/intern/usd_reader_mesh.cc @@ -111,6 +111,7 @@ static void assign_materials(Main *bmain, const std::map _index_map, const USDImportParams , pxr::UsdStageRefPtr stage, + std::map _name_to_mat, std::map _path_to_mat_name) { if (!(stage && bmain && ob)) { @@ -132,16 +133,12 @@ static void assign_materials(Main *bmain, return; } - /* TODO(kevin): use global map? */ - std::map mat_map; - build_mat_map(bmain, _map); - blender::io::usd::USDMaterialReader mat_reader(params, bmain); for (it = mat_index_map.begin(); it != mat_index_map.end(); ++it) { Material *assigned_mat = find_existing_material( -it->first, params, mat_map, usd_path_to_mat_name); +it->first, params, mat_name_to_mat, usd_path_to_mat_name); if (!assigned_mat) { /* Blender material doesn't exist, so create it now. */ @@ -165,7 +162,7 @@ static void assign_materials(Main *bmain, } const std::string mat_name = pxr::TfMakeValidIdentifier(assigned_mat->id.name + 2); - mat_map[mat_name] = assigned_mat; + mat_name_to_mat[mat_name] = assigned_mat; if (params.mtl_name_collision_mode == USD_MTL_NAME_COLLISION_MAKE_UNIQUE) { /* Record the name of the Blender material we created for the USD material @@ -805,11 +802,16 @@ void USDMeshReader::readFaceSetsSample(Main *bmain, Mesh *mesh, const double mot std::map mat_map; assign_facesets_to_mpoly(motionSampleTime, mesh->mpoly, mesh->totpoly, _map); + /* Build material name map if it's not built yet. */ + if (this->settings_->mat_name_to_mat.empty()) { +utils::build_mat_map(bmain, >settings_->mat_name_to_mat); + } utils::assign_materials(bmain, object_, mat_map, this->import_params_, this->prim_.GetStage(), + this->settings_->mat_name_to_mat, this->settings_->usd_path_to_mat_name); } diff --git a/source/blender/io/usd/intern/usd_reader_prim.h b/source/blender/io/usd/intern/usd_reader_prim.h index f2df00accf6..c44c4a14ad7 100644 --- a/source/blender/io/usd/intern/usd_reader_prim.h +++ b/source/blender/io/usd/intern/usd_reader_prim.h @@ -11,6 +11,7 @@ #include struct Main; +struct Material; struct Object; namespace blender::io::usd { @@ -42,6 +43,10 @@ struct ImportSettings { * of what the importer is doing. This is necessary even * when all the other import settings are to remain const. */ mutable std::map usd_path_to_mat_name; + /* Map a material name to Blender material. + * This map is updated by readers during stage traversal, + * and is mutable similar to the map above. */ + mutable std::map mat_name_to_mat; ImportSettings() : do_convert_mat(false), ___ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs
[Bf-blender-cvs] [230f72347a9] master: IO: speed up large Alembic & USD imports by doing fewer collection syncs
Commit: 230f72347a9931b0f2e39ffeff63db43db3787a1 Author: Aras Pranckevicius Date: Fri Jun 17 22:22:30 2022 +0300 Branches: master https://developer.blender.org/rB230f72347a9931b0f2e39ffeff63db43db3787a1 IO: speed up large Alembic & USD imports by doing fewer collection syncs Previous code was doing N collection syncs when importing N objects (essentially quadratic complexity in terms of object count). New code avoids all the intermediate syncs by using BKE_layer_collection_resync_forbid and BKE_layer_collection_resync_allow, and then does one BKE_main_collection_sync + BKE_main_collection_sync_remap for the whole operation. The things done on the importer objects that are dependent on the sync happening (marking them selected) are done in a separate loop after the sync. Timings: importing Moana USD scene (480k objects) on Windows, VS2022 Release build, AMD Ryzen 5950X: 12344sec -> 10979sec (saves 22 minutes). Reviewed By: Bastien Montagne Differential Revision: https://developer.blender.org/D15215 === M source/blender/io/alembic/intern/alembic_capi.cc M source/blender/io/usd/intern/usd_capi_import.cc === diff --git a/source/blender/io/alembic/intern/alembic_capi.cc b/source/blender/io/alembic/intern/alembic_capi.cc index 0d4e1d04db0..1fb535a57f2 100644 --- a/source/blender/io/alembic/intern/alembic_capi.cc +++ b/source/blender/io/alembic/intern/alembic_capi.cc @@ -573,12 +573,10 @@ static void import_endjob(void *user_data) ImportJobData *data = static_cast(user_data); - std::vector::iterator iter; - /* Delete objects on cancellation. */ if (data->was_cancelled) { -for (iter = data->readers.begin(); iter != data->readers.end(); ++iter) { - Object *ob = (*iter)->object(); +for (AbcObjectReader *reader : data->readers) { + Object *ob = reader->object(); /* It's possible that cancellation occurred between the creation of * the reader and the creation of the Blender object. */ @@ -590,7 +588,6 @@ static void import_endjob(void *user_data) } } else { -/* Add object to scene. */ Base *base; LayerCollection *lc; ViewLayer *view_layer = data->view_layer; @@ -599,11 +596,17 @@ static void import_endjob(void *user_data) lc = BKE_layer_collection_get_active(view_layer); -for (iter = data->readers.begin(); iter != data->readers.end(); ++iter) { - Object *ob = (*iter)->object(); - +/* Add all objects to the collection (don't do sync for each object). */ +BKE_layer_collection_resync_forbid(); +for (AbcObjectReader *reader : data->readers) { + Object *ob = reader->object(); BKE_collection_object_add(data->bmain, lc->collection, ob); - +} +/* Sync the collection, and do view layer operations. */ +BKE_layer_collection_resync_allow(); +BKE_main_collection_sync(data->bmain); +for (AbcObjectReader *reader : data->readers) { + Object *ob = reader->object(); base = BKE_view_layer_base_find(view_layer, ob); /* TODO: is setting active needed? */ BKE_view_layer_base_select_and_set_active(view_layer, base); @@ -625,8 +628,7 @@ static void import_endjob(void *user_data) } } - for (iter = data->readers.begin(); iter != data->readers.end(); ++iter) { -AbcObjectReader *reader = *iter; + for (AbcObjectReader *reader : data->readers) { reader->decref(); if (reader->refcount() == 0) { diff --git a/source/blender/io/usd/intern/usd_capi_import.cc b/source/blender/io/usd/intern/usd_capi_import.cc index 29b256125f0..4118205d87f 100644 --- a/source/blender/io/usd/intern/usd_capi_import.cc +++ b/source/blender/io/usd/intern/usd_capi_import.cc @@ -277,7 +277,6 @@ static void import_endjob(void *customdata) } } else if (data->archive) { -/* Add object to scene. */ Base *base; LayerCollection *lc; ViewLayer *view_layer = data->view_layer; @@ -286,20 +285,30 @@ static void import_endjob(void *customdata) lc = BKE_layer_collection_get_active(view_layer); +/* Add all objects to the collection (don't do sync for each object). */ +BKE_layer_collection_resync_forbid(); for (USDPrimReader *reader : data->archive->readers()) { - if (!reader) { continue; } - Object *ob = reader->object(); - if (!ob) { continue; } - BKE_collection_object_add(data->bmain, lc->collection, ob); +} +/* Sync the collection, and do view layer operations. */ +BKE_layer_collection_resync_allow(); +BKE_main_collection_sync(data->bmain); +for (USDPrimReader *reader : data->archive->readers()) { + if (!reader) { +continue; + } + Object *ob = reader->object(); + if (!ob) { +
[Bf-blender-cvs] [653100cd651] master: obj: reduce vertex colors to 4 decimal places, reenable tests
Commit: 653100cd651d43daa1f814ef49d1f0d7a9a0ee52 Author: Aras Pranckevicius Date: Wed Jun 15 20:59:38 2022 +0300 Branches: master https://developer.blender.org/rB653100cd651d43daa1f814ef49d1f0d7a9a0ee52 obj: reduce vertex colors to 4 decimal places, reenable tests OBJ vertex color related tests were not producing identical results across various platforms, primarily due to sRGB<->Linear color space conversions. While D15193 has just made the color space conversion accuracy match much closer between platforms, it's still not 100% the same. This change reduces the amount of decimal places used for exporting vertex colors, to 4 digits (down from 6). Vertex normals were already always printed with 4 digits, and colors are conceptually similar (usually 0..1 range etc.). This makes the vertex color tests pass again, so re-enable them after adjusting to 4 decimals expectations. === M source/blender/io/wavefront_obj/exporter/obj_export_io.hh M source/blender/io/wavefront_obj/tests/obj_exporter_tests.cc M source/blender/io/wavefront_obj/tests/obj_importer_tests.cc === diff --git a/source/blender/io/wavefront_obj/exporter/obj_export_io.hh b/source/blender/io/wavefront_obj/exporter/obj_export_io.hh index 157d7760307..5413c9969e3 100644 --- a/source/blender/io/wavefront_obj/exporter/obj_export_io.hh +++ b/source/blender/io/wavefront_obj/exporter/obj_export_io.hh @@ -132,7 +132,7 @@ constexpr FormattingSyntax syntax_elem_to_formatting(const eOBJSyntaxElement key return {"v {:.6f} {:.6f} {:.6f}\n", 3, is_type_float}; } case eOBJSyntaxElement::vertex_coords_color: { - return {"v {:.6f} {:.6f} {:.6f} {:.6f} {:.6f} {:.6f}\n", 6, is_type_float}; + return {"v {:.6f} {:.6f} {:.6f} {:.4f} {:.4f} {:.4f}\n", 6, is_type_float}; } case eOBJSyntaxElement::uv_vertex_coords: { return {"vt {:.6f} {:.6f}\n", 2, is_type_float}; diff --git a/source/blender/io/wavefront_obj/tests/obj_exporter_tests.cc b/source/blender/io/wavefront_obj/tests/obj_exporter_tests.cc index fea74c2fd90..6aec848573f 100644 --- a/source/blender/io/wavefront_obj/tests/obj_exporter_tests.cc +++ b/source/blender/io/wavefront_obj/tests/obj_exporter_tests.cc @@ -436,8 +436,6 @@ TEST_F(obj_exporter_regression_test, cubes_positioned) _export.params); } -/* Disabled until sRGB<->Linear conversion produces close enough results between - * SSE2 and non-SSE2. TEST_F(obj_exporter_regression_test, cubes_vertex_colors) { OBJExportParamsDefault _export; @@ -450,7 +448,6 @@ TEST_F(obj_exporter_regression_test, cubes_vertex_colors) "", _export.params); } -*/ TEST_F(obj_exporter_regression_test, cubes_with_textures_strip) { @@ -510,7 +507,7 @@ TEST_F(obj_exporter_regression_test, all_objects) _export.params.forward_axis = IO_AXIS_Y; _export.params.up_axis = IO_AXIS_Z; _export.params.export_smooth_groups = true; - //_export.params.export_colors = true; + _export.params.export_colors = true; compare_obj_export_to_golden("io_tests/blend_scene/all_objects.blend", "io_tests/obj/all_objects.obj", "io_tests/obj/all_objects.mtl", diff --git a/source/blender/io/wavefront_obj/tests/obj_importer_tests.cc b/source/blender/io/wavefront_obj/tests/obj_importer_tests.cc index efdd8839615..b67adbc9753 100644 --- a/source/blender/io/wavefront_obj/tests/obj_importer_tests.cc +++ b/source/blender/io/wavefront_obj/tests/obj_importer_tests.cc @@ -453,7 +453,8 @@ TEST_F(obj_importer_test, import_all_objects) float3(13, 1, -1), float3(11, 1, 1), float3(0, 0, 1), - float2(0, 0)}, + float2(0, 0), + float4(0.0f, 0.002125f, 1.0f, 1.0f)}, {"OBUVCube", OB_MESH, 8, @@ -509,7 +510,6 @@ TEST_F(obj_importer_test, import_all_objects) import_and_check("all_objects.obj", expect, std::size(expect), 7); } -/* TEST_F(obj_importer_test, import_cubes_vertex_colors) { Expectation expect[] = { @@ -524,7 +524,7 @@ TEST_F(obj_importer_test, import_cubes_vertex_colors) float3(-1.0f, -1.0f, 1.0f), float3(0, 0, 0), float2(0, 0), - float4(0.846873f, 0.027321f, 0.982251f, 1.0f)}, + float4(0.846873f, 0.027321f, 0.982123f, 1.0f)}, {"OBCubeVertexFloat", OB_MESH, 8, @@ -535,7 +535,7 @@ TEST_F(obj_importer_test, import_cubes_vertex_colors) float3(1.392028f, -1.0f, 1.0f), float3(0, 0, 0), float2(0, 0), - float4(49.99558f, 0.027321f, 0.982251f, 1.0f)}, + float4(49.99467f, 0.027321f, 0.982123f, 1.0f)}, {"OBCubeCornerByte", OB_MESH,
[Bf-blender-cvs] [004d858138f] master: math: improve accuracy of Linear->sRGB conversion SIMD path
Commit: 004d858138fced20d45cf3cc0149fcef1922c8a0 Author: Aras Pranckevicius Date: Wed Jun 15 20:51:12 2022 +0300 Branches: master https://developer.blender.org/rB004d858138fced20d45cf3cc0149fcef1922c8a0 math: improve accuracy of Linear->sRGB conversion SIMD path srgb_to_linearrgb_v3_v3 is using an approximation of powf that is SIMD. However, while the accuracy of it is ok, a larger issue is that it produces different results on Intel compared to ARM architectures. On ARM (e.g. AppleSilicon), the result of the SIMD code path is much closer to the reference implementation. This seems to be because of _mm_rsqrt_ps usage in _bli_math_fastpow512. The ARM/NEON code path emulates inverse square root with a combination of vrsqrteq_f32 followed by two Newton-Raphson iterations, because blender uses the SSE2NEON_PRECISE_SQRT define. This commit adds similar NR iterations to the "actual SSE" code path as well. Max error of srgb->linear->srgb conversion roundtrip goes from 0.000211 down to about 0.62. Reviewed By: Sergey Sharybin Differential Revision: https://developer.blender.org/D15193 === M source/blender/blenlib/intern/math_base_inline.c M source/blender/blenlib/tests/BLI_math_color_test.cc === diff --git a/source/blender/blenlib/intern/math_base_inline.c b/source/blender/blenlib/intern/math_base_inline.c index a983821f15e..4a213f5fe74 100644 --- a/source/blender/blenlib/intern/math_base_inline.c +++ b/source/blender/blenlib/intern/math_base_inline.c @@ -767,6 +767,20 @@ MALWAYS_INLINE __m128 _bli_math_fastpow24(const __m128 arg) return _mm_mul_ps(x, _mm_mul_ps(x, x)); } +MALWAYS_INLINE __m128 _bli_math_rsqrt(__m128 in) +{ + __m128 r = _mm_rsqrt_ps(in); + /* Only do additional Newton-Raphson iterations when using actual SSE + * code path. When we are emulating SSE on NEON via sse2neon, the + * additional NR iterations are already done inside _mm_rsqrt_ps + * emulation. */ +# if defined(__SSE2__) + r = _mm_add_ps(_mm_mul_ps(_mm_set1_ps(1.5f), r), + _mm_mul_ps(_mm_mul_ps(_mm_mul_ps(in, _mm_set1_ps(-0.5f)), r), _mm_mul_ps(r, r))); +# endif + return r; +} + /* Calculate powf(x, 1.0f / 2.4) */ MALWAYS_INLINE __m128 _bli_math_fastpow512(const __m128 arg) { @@ -776,14 +790,14 @@ MALWAYS_INLINE __m128 _bli_math_fastpow512(const __m128 arg) */ __m128 xf = _bli_math_fastpow(0x3f2b, 0x5eb504f3, arg); __m128 xover = _mm_mul_ps(arg, xf); - __m128 xfm1 = _mm_rsqrt_ps(xf); + __m128 xfm1 = _bli_math_rsqrt(xf); __m128 x2 = _mm_mul_ps(arg, arg); __m128 xunder = _mm_mul_ps(x2, xfm1); /* sqrt2 * over + 2 * sqrt2 * under */ __m128 xavg = _mm_mul_ps(_mm_set1_ps(1.0f / (3.0f * 0.629960524947437f) * 0.999852f), _mm_add_ps(xover, xunder)); - xavg = _mm_mul_ps(xavg, _mm_rsqrt_ps(xavg)); - xavg = _mm_mul_ps(xavg, _mm_rsqrt_ps(xavg)); + xavg = _mm_mul_ps(xavg, _bli_math_rsqrt(xavg)); + xavg = _mm_mul_ps(xavg, _bli_math_rsqrt(xavg)); return xavg; } diff --git a/source/blender/blenlib/tests/BLI_math_color_test.cc b/source/blender/blenlib/tests/BLI_math_color_test.cc index 7f2c0a3f1ca..4d928477870 100644 --- a/source/blender/blenlib/tests/BLI_math_color_test.cc +++ b/source/blender/blenlib/tests/BLI_math_color_test.cc @@ -74,3 +74,71 @@ TEST(math_color, LinearRGBTosRGBRoundtrip) EXPECT_NEAR(orig_linear_color, linear_color, 1e-5); } } + +TEST(math_color, linearrgb_to_srgb_v3_v3) +{ + float srgb_color[3]; + { +const float kTolerance = 1.0e-8f; +const float linear_color[3] = {0.0023f, 0.0024f, 0.0025f}; +linearrgb_to_srgb_v3_v3(srgb_color, linear_color); +EXPECT_NEAR(0.029716f, srgb_color[0], kTolerance); +EXPECT_NEAR(0.031008f, srgb_color[1], kTolerance); +EXPECT_NEAR(0.032300f, srgb_color[2], kTolerance); + } + + { +/* SIMD implementation of linear->srgb for larger inputs + * is less accurate; use larger tolerance. */ +const float kTolerance = 3.6e-5f; +const float linear_color[3] = {0.71f, 0.75f, 0.78f}; +linearrgb_to_srgb_v3_v3(srgb_color, linear_color); +EXPECT_NEAR(0.859696f, srgb_color[0], kTolerance); +EXPECT_NEAR(0.880825f, srgb_color[1], kTolerance); +EXPECT_NEAR(0.896244f, srgb_color[2], kTolerance); + } + + { +/* Not a common, but possible case: values beyond 1.0 range. */ +const float kTolerance = 2.3e-4f; +const float linear_color[3] = {1.5f, 2.8f, 5.6f}; +linearrgb_to_srgb_v3_v3(srgb_color, linear_color); +EXPECT_NEAR(1.19418f, srgb_color[0], kTolerance); +EXPECT_NEAR(1.56520f, srgb_color[1], kTolerance); +EXPECT_NEAR(2.10771f, srgb_color[2], kTolerance); + } +} + +TEST(math_color, srgb_to_linearrgb_v3_v3) +{ + float linear_color[3]; + { +const float kTolerance = 1.0e-8f; +const float srgb_color[3] = {0.0023f, 0.0024f, 0.0025f}; +s
[Bf-blender-cvs] [06e07761753] master: obj: disable vertex color tests until it produces identical results across platforms
Commit: 06e07761753a19fe192cce889e5040f0bc4e61a7 Author: Aras Pranckevicius Date: Tue Jun 14 12:17:14 2022 +0300 Branches: master https://developer.blender.org/rB06e07761753a19fe192cce889e5040f0bc4e61a7 obj: disable vertex color tests until it produces identical results across platforms === M source/blender/io/wavefront_obj/tests/obj_exporter_tests.cc M source/blender/io/wavefront_obj/tests/obj_importer_tests.cc === diff --git a/source/blender/io/wavefront_obj/tests/obj_exporter_tests.cc b/source/blender/io/wavefront_obj/tests/obj_exporter_tests.cc index 6aec848573f..fea74c2fd90 100644 --- a/source/blender/io/wavefront_obj/tests/obj_exporter_tests.cc +++ b/source/blender/io/wavefront_obj/tests/obj_exporter_tests.cc @@ -436,6 +436,8 @@ TEST_F(obj_exporter_regression_test, cubes_positioned) _export.params); } +/* Disabled until sRGB<->Linear conversion produces close enough results between + * SSE2 and non-SSE2. TEST_F(obj_exporter_regression_test, cubes_vertex_colors) { OBJExportParamsDefault _export; @@ -448,6 +450,7 @@ TEST_F(obj_exporter_regression_test, cubes_vertex_colors) "", _export.params); } +*/ TEST_F(obj_exporter_regression_test, cubes_with_textures_strip) { @@ -507,7 +510,7 @@ TEST_F(obj_exporter_regression_test, all_objects) _export.params.forward_axis = IO_AXIS_Y; _export.params.up_axis = IO_AXIS_Z; _export.params.export_smooth_groups = true; - _export.params.export_colors = true; + //_export.params.export_colors = true; compare_obj_export_to_golden("io_tests/blend_scene/all_objects.blend", "io_tests/obj/all_objects.obj", "io_tests/obj/all_objects.mtl", diff --git a/source/blender/io/wavefront_obj/tests/obj_importer_tests.cc b/source/blender/io/wavefront_obj/tests/obj_importer_tests.cc index 7cc528d4f3d..efdd8839615 100644 --- a/source/blender/io/wavefront_obj/tests/obj_importer_tests.cc +++ b/source/blender/io/wavefront_obj/tests/obj_importer_tests.cc @@ -453,8 +453,7 @@ TEST_F(obj_importer_test, import_all_objects) float3(13, 1, -1), float3(11, 1, 1), float3(0, 0, 1), - float2(0, 0), - float4(0.0f, 0.002125f, 1.0f, 1.0f)}, + float2(0, 0)}, {"OBUVCube", OB_MESH, 8, @@ -510,6 +509,7 @@ TEST_F(obj_importer_test, import_all_objects) import_and_check("all_objects.obj", expect, std::size(expect), 7); } +/* TEST_F(obj_importer_test, import_cubes_vertex_colors) { Expectation expect[] = { @@ -580,6 +580,7 @@ TEST_F(obj_importer_test, import_cubes_vertex_colors) }; import_and_check("cubes_vertex_colors.obj", expect, std::size(expect), 0); } + */ TEST_F(obj_importer_test, import_cubes_vertex_colors_mrgb) { ___ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs
[Bf-blender-cvs] [e1f15e3b323] master: Fix T98782: ignore OBJ face normal indices if no normals are present
Commit: e1f15e3b323e9e0dd4a2514395934ec44969ecfb Author: Aras Pranckevicius Date: Tue Jun 14 10:23:28 2022 +0300 Branches: master https://developer.blender.org/rBe1f15e3b323e9e0dd4a2514395934ec44969ecfb Fix T98782: ignore OBJ face normal indices if no normals are present Some OBJ files out there (see T98782) have face definitions that contain vertex normal indices, but the files themselves don't contain any vertex normals. The code was doing a "hey, that's an invalid index" and skipping these faces. But the old python importer was silently ignoring these normal indices, so do the same here. Reviewed By: Howard Trickey Differential Revision: https://developer.blender.org/D15177 === M source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc === diff --git a/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc b/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc index 4a27d734819..9cfce5c2257 100644 --- a/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc +++ b/source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc @@ -195,7 +195,7 @@ static void geom_add_polygon(Geometry *geom, if (p < end && *p == '/') { ++p; p = parse_int(p, end, INT32_MAX, corner.vertex_normal_index, false); -got_normal = corner.uv_vert_index != INT32_MAX; +got_normal = corner.vertex_normal_index != INT32_MAX; } } /* Always keep stored indices non-negative and zero-based. */ @@ -218,7 +218,10 @@ static void geom_add_polygon(Geometry *geom, face_valid = false; } } -if (got_normal) { +/* Ignore corner normal index, if the geometry does not have any normals. + * Some obj files out there do have face definitions that refer to normal indices, + * without any normals being present (T98782). */ +if (got_normal && geom->has_vertex_normals_) { corner.vertex_normal_index += corner.vertex_normal_index < 0 ? global_vertices.vertex_normals.size() : -1; ___ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs
[Bf-blender-cvs] [1b4f35f6a58] master: obj: vertex colors support in importer and exporter
Commit: 1b4f35f6a5889d8d2e65c6231e84f8b1744c4f96 Author: Aras Pranckevicius Date: Tue Jun 14 10:19:02 2022 +0300 Branches: master https://developer.blender.org/rB1b4f35f6a5889d8d2e65c6231e84f8b1744c4f96 obj: vertex colors support in importer and exporter Adds support for vertex colors to OBJ I/O. Importer: - Supports both "xyzrgb" and "MRGB" vertex color formats. - Whenever vertex color is present in the file for a model, it is imported and a Color attribute is created (per-vertex, full float color data type). Color coming from the file is assumed to be sRGB, and is converted to linear upon import. Exporter: - Option to export the vertex colors. Defaults to "off", since not all 3rd party software supports vertex colors. - When the option is "on", if a mesh has a color attribute layer, the active one is exported in "xyzrgb" form. If the mesh has per-face-corner colors, they are averaged on the vertices. Colors are converted from linear to sRGB upon export. Reviewed By: Howard Trickey Differential Revision: https://developer.blender.org/D15159 === M source/blender/editors/io/io_obj.c M source/blender/io/wavefront_obj/IO_wavefront_obj.h M source/blender/io/wavefront_obj/exporter/obj_export_file_writer.cc M source/blender/io/wavefront_obj/exporter/obj_export_file_writer.hh M source/blender/io/wavefront_obj/exporter/obj_export_io.hh M source/blender/io/wavefront_obj/exporter/obj_export_mesh.hh M source/blender/io/wavefront_obj/exporter/obj_exporter.cc M source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc M source/blender/io/wavefront_obj/importer/obj_import_mesh.cc M source/blender/io/wavefront_obj/importer/obj_import_mesh.hh M source/blender/io/wavefront_obj/importer/obj_import_objects.hh M source/blender/io/wavefront_obj/tests/obj_exporter_tests.cc M source/blender/io/wavefront_obj/tests/obj_exporter_tests.hh M source/blender/io/wavefront_obj/tests/obj_importer_tests.cc === diff --git a/source/blender/editors/io/io_obj.c b/source/blender/editors/io/io_obj.c index a8eed136df3..4819ae09785 100644 --- a/source/blender/editors/io/io_obj.c +++ b/source/blender/editors/io/io_obj.c @@ -100,6 +100,7 @@ static int wm_obj_export_exec(bContext *C, wmOperator *op) export_params.export_selected_objects = RNA_boolean_get(op->ptr, "export_selected_objects"); export_params.export_uv = RNA_boolean_get(op->ptr, "export_uv"); export_params.export_normals = RNA_boolean_get(op->ptr, "export_normals"); + export_params.export_colors = RNA_boolean_get(op->ptr, "export_colors"); export_params.export_materials = RNA_boolean_get(op->ptr, "export_materials"); export_params.path_mode = RNA_enum_get(op->ptr, "path_mode"); export_params.export_triangulated_mesh = RNA_boolean_get(op->ptr, "export_triangulated_mesh"); @@ -160,6 +161,7 @@ static void ui_obj_export_settings(uiLayout *layout, PointerRNA *imfptr) sub = uiLayoutColumnWithHeading(col, false, IFACE_("Export")); uiItemR(sub, imfptr, "export_uv", 0, IFACE_("UV Coordinates"), ICON_NONE); uiItemR(sub, imfptr, "export_normals", 0, IFACE_("Normals"), ICON_NONE); + uiItemR(sub, imfptr, "export_colors", 0, IFACE_("Colors"), ICON_NONE); uiItemR(sub, imfptr, "export_materials", 0, IFACE_("Materials"), ICON_NONE); uiItemR(sub, imfptr, "export_triangulated_mesh", 0, IFACE_("Triangulated Mesh"), ICON_NONE); uiItemR(sub, imfptr, "export_curves_as_nurbs", 0, IFACE_("Curves as NURBS"), ICON_NONE); @@ -315,6 +317,7 @@ void WM_OT_obj_export(struct wmOperatorType *ot) "Export Normals", "Export per-face normals if the face is flat-shaded, per-face-per-loop " "normals if smooth-shaded"); + RNA_def_boolean(ot->srna, "export_colors", false, "Export Colors", "Export per-vertex colors"); RNA_def_boolean(ot->srna, "export_materials", true, diff --git a/source/blender/io/wavefront_obj/IO_wavefront_obj.h b/source/blender/io/wavefront_obj/IO_wavefront_obj.h index 0a78cdc714d..a719dff2126 100644 --- a/source/blender/io/wavefront_obj/IO_wavefront_obj.h +++ b/source/blender/io/wavefront_obj/IO_wavefront_obj.h @@ -45,6 +45,7 @@ struct OBJExportParams { eEvaluationMode export_eval_mode; bool export_uv; bool export_normals; + bool export_colors; bool export_materials; bool export_triangulated_mesh; bool export_curves_as_nurbs; diff --git a/source/blend