[Bf-blender-cvs] [d1409d2420d] soc-2019-fast-io: [Fast import/export] Added support for smooth groups
Hugo Sales
noreply at git.blender.org
Thu Jul 11 11:43:24 CEST 2019
Commit: d1409d2420d929f47a79df70bca4301394d10b12
Author: Hugo Sales
Date: Thu Jul 11 10:43:05 2019 +0100
Branches: soc-2019-fast-io
https://developer.blender.org/rBd1409d2420d929f47a79df70bca4301394d10b12
[Fast import/export] Added support for smooth groups
===================================================================
M source/blender/editors/io/intern/obj.cpp
M source/blender/editors/io/io_obj.c
M source/blender/editors/io/io_obj.h
===================================================================
diff --git a/source/blender/editors/io/intern/obj.cpp b/source/blender/editors/io/intern/obj.cpp
index e9cae2f8f34..6f6a43a44de 100644
--- a/source/blender/editors/io/intern/obj.cpp
+++ b/source/blender/editors/io/intern/obj.cpp
@@ -332,7 +332,41 @@ bool OBJ_export_meshes(bContext *UNUSED(C),
fprintf(file, "g %s\n", name.c_str());
}
- for (const MPoly &p : common::poly_iter(me.mesh)) {
+ int group_total = 0, *smooth_groups = nullptr;
+ if (format_specific->export_smooth_groups) {
+ smooth_groups = BKE_mesh_calc_smoothgroups(me.mesh->medge,
+ me.mesh->totedge,
+ me.mesh->mpoly,
+ me.mesh->totpoly,
+ me.mesh->mloop,
+ me.mesh->totloop,
+ &group_total,
+ format_specific->smooth_groups_bitflags);
+ }
+
+ size_t poly_index = 0;
+ int state_smooth = -1;
+ for (auto pi = common::poly_iter(me.mesh); pi != pi.end(); ++pi, ++poly_index) {
+ const MPoly &p = *pi;
+ // Smooth indices start at 1, so 0 is not a valid index
+ int smooth = (p.flag & ME_SMOOTH) ? 1 : 0;
+ if (smooth && smooth_groups) {
+ smooth = smooth_groups[poly_index % group_total];
+ }
+
+ if (smooth != state_smooth) {
+ state_smooth = smooth;
+ if (smooth && smooth_groups) {
+ fprintf(file, "s %d\n", smooth_groups[poly_index]);
+ }
+ else if (smooth) {
+ fputs("s 1\n", file);
+ }
+ else {
+ fputs("s off\n", file);
+ }
+ }
+
fputc('f', file);
// Loop index
int li = p.loopstart;
diff --git a/source/blender/editors/io/io_obj.c b/source/blender/editors/io/io_obj.c
index 220a8595714..2633ef7a1f2 100644
--- a/source/blender/editors/io/io_obj.c
+++ b/source/blender/editors/io/io_obj.c
@@ -54,6 +54,8 @@ static int wm_obj_export_exec(bContext *C, wmOperator *op)
format_specific->export_objects_as_objects = RNA_boolean_get(op->ptr,
"export_objects_as_objects");
format_specific->export_objects_as_groups = RNA_boolean_get(op->ptr, "export_objects_as_groups");
+ format_specific->export_smooth_groups = RNA_boolean_get(op->ptr, "export_smooth_groups");
+ format_specific->smooth_groups_bitflags = RNA_boolean_get(op->ptr, "smooth_groups_bitflags");
if (!format_specific->export_animations) {
format_specific->start_frame = BKE_scene_frame_get(CTX_data_scene(C));
@@ -167,6 +169,15 @@ static void wm_obj_export_draw(bContext *C, wmOperator *op)
uiLayoutSetEnabled(row, materials);
uiItemR(row, &ptr, "path_mode", 0, NULL, ICON_NONE);
+ sub_box = uiLayoutBox(box);
+ row = uiLayoutRow(sub_box, false);
+ uiItemR(row, &ptr, "export_smooth_groups", 0, NULL, ICON_NONE);
+
+ const bool smooth_groups = RNA_boolean_get(&ptr, "export_smooth_groups");
+ row = uiLayoutRow(sub_box, false);
+ uiLayoutSetEnabled(row, smooth_groups);
+ uiItemR(row, &ptr, "smooth_groups_bitflags", 0, NULL, ICON_NONE);
+
row = uiLayoutRow(box, false);
uiItemR(row, &ptr, "export_vcolors", 0, NULL, ICON_NONE);
@@ -318,7 +329,7 @@ void WM_OT_obj_export(struct wmOperatorType *ot)
RNA_def_boolean(
ot->srna, "export_curves", false, "Export curves", "Export curves and NURBS surfaces");
- RNA_def_boolean(ot->srna, "pack_uv", 1, "Pack UV Islands", "Export UVs with packed island");
+ RNA_def_boolean(ot->srna, "pack_uv", false, "Pack UV Islands", "Export UVs with packed island");
RNA_def_enum(ot->srna,
"path_mode",
@@ -327,6 +338,18 @@ void WM_OT_obj_export(struct wmOperatorType *ot)
"Path mode",
"How external files (such as images) are treated");
+ RNA_def_boolean(ot->srna,
+ "export_smooth_groups",
+ false,
+ "Smooth Groups",
+ "Write sharp edges as smooth groups");
+
+ RNA_def_boolean(ot->srna,
+ "smooth_groups_bitflags",
+ false,
+ "Bitflags",
+ "Use bitflags for smooth groups (produces at most 32 groups)");
+
/* This dummy prop is used to check whether we need to init the start and
* end frame values to that of the scene's, otherwise they are reset at
* every change, draw update. */
diff --git a/source/blender/editors/io/io_obj.h b/source/blender/editors/io/io_obj.h
index b470a94ae6d..395edea6519 100644
--- a/source/blender/editors/io/io_obj.h
+++ b/source/blender/editors/io/io_obj.h
@@ -47,6 +47,9 @@ typedef struct OBJExportSettings {
bool dedup_uvs;
float dedup_normals_threshold;
float dedup_uvs_threshold;
+
+ bool export_smooth_groups;
+ bool smooth_groups_bitflags;
} OBJExportSettings;
void WM_OT_obj_export(struct wmOperatorType *ot);
More information about the Bf-blender-cvs
mailing list