Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYimingWu <xp8110@outlook.com>2021-09-15 09:03:18 +0300
committerYimingWu <xp8110@outlook.com>2021-09-15 09:03:39 +0300
commitc1cf66bff3c0753512a2d1f2f8c03430bdd1f045 (patch)
treea4286c805915d71b0b781fc7b1d5cf9bac8fc2a7
parent202dc3631e3f27c53c48d76e818170d204995794 (diff)
LineArt: Automatic crease with flat/smooth faces.
This allows crease lines to be automatically hidden on smooth surfaces, also provided options for: - Showing crease on marked sharp edges. - Force crease detection on smooth surfaces. Reviewed By: Antonio Vazquez (antoniov) Differential Revision: http://developer.blender.org/D12051
-rw-r--r--source/blender/blenloader/intern/versioning_300.c15
-rw-r--r--source/blender/gpencil_modifiers/intern/MOD_gpencillineart.c2
-rw-r--r--source/blender/gpencil_modifiers/intern/lineart/MOD_lineart.h3
-rw-r--r--source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c42
-rw-r--r--source/blender/makesdna/DNA_gpencil_modifier_defaults.h2
-rw-r--r--source/blender/makesdna/DNA_lineart_types.h2
-rw-r--r--source/blender/makesrna/intern/rna_gpencil_modifier.c12
7 files changed, 65 insertions, 13 deletions
diff --git a/source/blender/blenloader/intern/versioning_300.c b/source/blender/blenloader/intern/versioning_300.c
index 6b8f011e9fc..4eba9f5f42e 100644
--- a/source/blender/blenloader/intern/versioning_300.c
+++ b/source/blender/blenloader/intern/versioning_300.c
@@ -37,6 +37,8 @@
#include "DNA_constraint_types.h"
#include "DNA_curve_types.h"
#include "DNA_genfile.h"
+#include "DNA_gpencil_modifier_types.h"
+#include "DNA_lineart_types.h"
#include "DNA_listBase.h"
#include "DNA_material_types.h"
#include "DNA_modifier_types.h"
@@ -1225,6 +1227,19 @@ void blo_do_versions_300(FileData *fd, Library *UNUSED(lib), Main *bmain)
version_geometry_nodes_change_legacy_names(ntree);
}
}
+ if (!DNA_struct_elem_find(
+ fd->filesdna, "LineartGpencilModifierData", "bool", "use_crease_on_smooth")) {
+ LISTBASE_FOREACH (Object *, ob, &bmain->objects) {
+ if (ob->type == OB_GPENCIL) {
+ LISTBASE_FOREACH (GpencilModifierData *, md, &ob->greasepencil_modifiers) {
+ if (md->type == eGpencilModifierType_Lineart) {
+ LineartGpencilModifierData *lmd = (LineartGpencilModifierData *)md;
+ lmd->calculation_flags |= LRT_USE_CREASE_ON_SMOOTH_SURFACES;
+ }
+ }
+ }
+ }
+ }
}
/**
diff --git a/source/blender/gpencil_modifiers/intern/MOD_gpencillineart.c b/source/blender/gpencil_modifiers/intern/MOD_gpencillineart.c
index 73ca4b9c529..01488a8b2de 100644
--- a/source/blender/gpencil_modifiers/intern/MOD_gpencillineart.c
+++ b/source/blender/gpencil_modifiers/intern/MOD_gpencillineart.c
@@ -390,6 +390,8 @@ static void options_panel_draw(const bContext *UNUSED(C), Panel *panel)
uiItemR(col, ptr, "use_edge_overlap", 0, IFACE_("Overlapping Edges As Contour"), ICON_NONE);
uiItemR(col, ptr, "use_object_instances", 0, NULL, ICON_NONE);
uiItemR(col, ptr, "use_clip_plane_boundaries", 0, NULL, ICON_NONE);
+ uiItemR(col, ptr, "use_crease_on_smooth", 0, IFACE_("Crease On Smooth"), ICON_NONE);
+ uiItemR(layout, ptr, "use_crease_on_sharp", 0, IFACE_("Crease On Sharp"), ICON_NONE);
}
static void style_panel_draw(const bContext *UNUSED(C), Panel *panel)
diff --git a/source/blender/gpencil_modifiers/intern/lineart/MOD_lineart.h b/source/blender/gpencil_modifiers/intern/lineart/MOD_lineart.h
index 4b71011b99a..134d9707ade 100644
--- a/source/blender/gpencil_modifiers/intern/lineart/MOD_lineart.h
+++ b/source/blender/gpencil_modifiers/intern/lineart/MOD_lineart.h
@@ -304,6 +304,9 @@ typedef struct LineartRenderBuffer {
bool filter_face_mark_invert;
bool filter_face_mark_boundaries;
+ bool force_crease;
+ bool sharp_as_crease;
+
/* Keep an copy of these data so when line art is running it's self-contained. */
bool cam_is_persp;
float cam_obmat[4][4];
diff --git a/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c b/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c
index c71cde8ec43..725cc0741f0 100644
--- a/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c
+++ b/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c
@@ -1453,7 +1453,7 @@ static uint16_t lineart_identify_feature_line(LineartRenderBuffer *rb,
LineartTriangle *rt_array,
LineartVert *rv_array,
float crease_threshold,
- bool no_crease,
+ bool use_auto_smooth,
bool use_freestyle_edge,
bool use_freestyle_face,
BMesh *bm_if_freestyle)
@@ -1533,10 +1533,20 @@ static uint16_t lineart_identify_feature_line(LineartRenderBuffer *rb,
edge_flag_result |= LRT_EDGE_FLAG_CONTOUR;
}
- if (rb->use_crease && (dot_v3v3_db(tri1->gn, tri2->gn) < crease_threshold)) {
- if (!no_crease) {
+ if (rb->use_crease) {
+ if (rb->sharp_as_crease && !BM_elem_flag_test(e, BM_ELEM_SMOOTH)) {
edge_flag_result |= LRT_EDGE_FLAG_CREASE;
}
+ else {
+ bool do_crease = true;
+ if (!rb->force_crease && !use_auto_smooth &&
+ (BM_elem_flag_test(ll->f, BM_ELEM_SMOOTH) && BM_elem_flag_test(lr->f, BM_ELEM_SMOOTH))) {
+ do_crease = false;
+ }
+ if (do_crease && (dot_v3v3_db(tri1->gn, tri2->gn) < crease_threshold)) {
+ edge_flag_result |= LRT_EDGE_FLAG_CREASE;
+ }
+ }
}
if (rb->use_material && (ll->f->mat_nr != lr->f->mat_nr)) {
edge_flag_result |= LRT_EDGE_FLAG_MATERIAL;
@@ -1746,9 +1756,14 @@ static void lineart_geometry_object_load(LineartObjectInfo *obi, LineartRenderBu
eln->object_ref = orig_ob;
obi->v_eln = eln;
+ bool use_auto_smooth = false;
if (orig_ob->lineart.flags & OBJECT_LRT_OWN_CREASE) {
use_crease = cosf(M_PI - orig_ob->lineart.crease_threshold);
}
+ if (obi->original_me->flag & ME_AUTOSMOOTH) {
+ use_crease = cosf(obi->original_me->smoothresh);
+ use_auto_smooth = true;
+ }
else {
use_crease = rb->crease_threshold;
}
@@ -1832,15 +1847,15 @@ static void lineart_geometry_object_load(LineartObjectInfo *obi, LineartRenderBu
e = BM_edge_at_index(bm, i);
/* Because e->head.hflag is char, so line type flags should not exceed positive 7 bits. */
- char eflag = lineart_identify_feature_line(rb,
- e,
- ort,
- orv,
- use_crease,
- orig_ob->type == OB_FONT,
- can_find_freestyle_edge,
- can_find_freestyle_face,
- bm);
+ uint16_t eflag = lineart_identify_feature_line(rb,
+ e,
+ ort,
+ orv,
+ use_crease,
+ use_auto_smooth,
+ can_find_freestyle_edge,
+ can_find_freestyle_face,
+ bm);
if (eflag) {
/* Only allocate for feature lines (instead of all lines) to save memory.
* If allow duplicated edges, one edge gets added multiple times if it has multiple types. */
@@ -3057,6 +3072,9 @@ static LineartRenderBuffer *lineart_create_render_buffer(Scene *scene,
rb->allow_duplicated_types = (lmd->calculation_flags & LRT_ALLOW_OVERLAP_EDGE_TYPES) != 0;
+ rb->force_crease = (lmd->calculation_flags & LRT_USE_CREASE_ON_SMOOTH_SURFACES) != 0;
+ rb->sharp_as_crease = (lmd->calculation_flags & LRT_USE_CREASE_ON_SHARP_EDGES) != 0;
+
int16_t edge_types = lmd->edge_types_override;
rb->use_contour = (edge_types & LRT_EDGE_FLAG_CONTOUR) != 0;
diff --git a/source/blender/makesdna/DNA_gpencil_modifier_defaults.h b/source/blender/makesdna/DNA_gpencil_modifier_defaults.h
index 81e9abc4916..8ab15b97537 100644
--- a/source/blender/makesdna/DNA_gpencil_modifier_defaults.h
+++ b/source/blender/makesdna/DNA_gpencil_modifier_defaults.h
@@ -304,7 +304,7 @@
.opacity = 1.0f, \
.flags = LRT_GPENCIL_MATCH_OUTPUT_VGROUP, \
.crease_threshold = DEG2RAD(140.0f), \
- .calculation_flags = LRT_ALLOW_DUPLI_OBJECTS | LRT_ALLOW_CLIPPING_BOUNDARIES, \
+ .calculation_flags = LRT_ALLOW_DUPLI_OBJECTS | LRT_ALLOW_CLIPPING_BOUNDARIES | LRT_USE_CREASE_ON_SHARP_EDGES, \
.angle_splitting_threshold = DEG2RAD(60.0f), \
.chaining_image_threshold = 0.001f, \
.overscan = 0.1f,\
diff --git a/source/blender/makesdna/DNA_lineart_types.h b/source/blender/makesdna/DNA_lineart_types.h
index cdb09c3af50..bdc9bcb6980 100644
--- a/source/blender/makesdna/DNA_lineart_types.h
+++ b/source/blender/makesdna/DNA_lineart_types.h
@@ -47,6 +47,8 @@ typedef enum eLineartMainFlags {
LRT_CHAIN_LOOSE_EDGES = (1 << 12),
LRT_CHAIN_GEOMETRY_SPACE = (1 << 13),
LRT_ALLOW_OVERLAP_EDGE_TYPES = (1 << 14),
+ LRT_USE_CREASE_ON_SMOOTH_SURFACES = (1 << 15),
+ LRT_USE_CREASE_ON_SHARP_EDGES = (1 << 16),
} eLineartMainFlags;
typedef enum eLineartEdgeFlag {
diff --git a/source/blender/makesrna/intern/rna_gpencil_modifier.c b/source/blender/makesrna/intern/rna_gpencil_modifier.c
index 55fe74cab4f..e125149dad2 100644
--- a/source/blender/makesrna/intern/rna_gpencil_modifier.c
+++ b/source/blender/makesrna/intern/rna_gpencil_modifier.c
@@ -3188,6 +3188,18 @@ static void rna_def_modifier_gpencillineart(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Masks", "Mask bits to match from Collection Line Art settings");
RNA_def_property_update(prop, 0, "rna_GpencilModifier_update");
+ prop = RNA_def_property(srna, "use_crease_on_smooth", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_sdna(
+ prop, NULL, "calculation_flags", LRT_USE_CREASE_ON_SMOOTH_SURFACES);
+ RNA_def_property_ui_text(
+ prop, "Crease On Smooth Surfaces", "Allow crease edges to show inside smooth surfaces");
+ RNA_def_property_update(prop, 0, "rna_GpencilModifier_update");
+
+ prop = RNA_def_property(srna, "use_crease_on_sharp", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_sdna(prop, NULL, "calculation_flags", LRT_USE_CREASE_ON_SHARP_EDGES);
+ RNA_def_property_ui_text(prop, "Crease On Sharp Edges", "Allow crease to show on sharp edges");
+ RNA_def_property_update(prop, 0, "rna_GpencilModifier_update");
+
RNA_define_lib_overridable(false);
}