diff options
author | Hans Goudey <h.goudey@me.com> | 2021-03-09 17:27:44 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2021-03-09 17:27:44 +0300 |
commit | 0700441578c9bb4d3f45d59183f26d3293499113 (patch) | |
tree | 8253f2645054c56f1677710b66058e8bd970c664 /source/blender/blenkernel/intern/geometry_component_mesh.cc | |
parent | eaada565910b4ff31081ced86c3b7242f2f28b4e (diff) |
Geometry Nodes: Expose "shade smooth" as an attribute
This patch exposes the "Shade Smooth" value as a boolean attribute.
This setting is exposed as a check-box in the mesh data properties,
but the value is actually stored for every face, allowing some faces
to be shaded smooth with a simple per-face control.
One bonus, this allows at least a workaround to the lack of control
of whether meshes created by nodes are shaded smooth or not: just use
an attribute fill node.
Differential Revision: https://developer.blender.org/D10538
Diffstat (limited to 'source/blender/blenkernel/intern/geometry_component_mesh.cc')
-rw-r--r-- | source/blender/blenkernel/intern/geometry_component_mesh.cc | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/source/blender/blenkernel/intern/geometry_component_mesh.cc b/source/blender/blenkernel/intern/geometry_component_mesh.cc index 03b938942a7..31809b1ffec 100644 --- a/source/blender/blenkernel/intern/geometry_component_mesh.cc +++ b/source/blender/blenkernel/intern/geometry_component_mesh.cc @@ -405,6 +405,29 @@ static void update_vertex_normals_when_dirty(const GeometryComponent &component) } } +static bool get_shade_smooth(const MPoly &mpoly) +{ + return mpoly.flag & ME_SMOOTH; +} + +static void set_shade_smooth(MPoly &mpoly, const bool &value) +{ + SET_FLAG_FROM_TEST(mpoly.flag, value, ME_SMOOTH); +} + +static ReadAttributePtr make_shade_smooth_read_attribute(const void *data, const int domain_size) +{ + return std::make_unique<DerivedArrayReadAttribute<MPoly, bool, get_shade_smooth>>( + ATTR_DOMAIN_POLYGON, Span<MPoly>((const MPoly *)data, domain_size)); +} + +static WriteAttributePtr make_shade_smooth_write_attribute(void *data, const int domain_size) +{ + return std::make_unique< + DerivedArrayWriteAttribute<MPoly, bool, get_shade_smooth, set_shade_smooth>>( + ATTR_DOMAIN_POLYGON, MutableSpan<MPoly>((MPoly *)data, domain_size)); +} + static float2 get_loop_uv(const MLoopUV &uv) { return float2(uv.uv); @@ -680,6 +703,19 @@ static ComponentAttributeProviders create_attribute_providers_for_mesh() nullptr, nullptr); + static BuiltinCustomDataLayerProvider shade_smooth("shade_smooth", + ATTR_DOMAIN_POLYGON, + CD_PROP_BOOL, + CD_MPOLY, + BuiltinAttributeProvider::NonCreatable, + BuiltinAttributeProvider::Writable, + BuiltinAttributeProvider::NonDeletable, + polygon_access, + make_shade_smooth_read_attribute, + make_shade_smooth_write_attribute, + nullptr, + nullptr); + static BuiltinCustomDataLayerProvider vertex_normal("vertex_normal", ATTR_DOMAIN_POINT, CD_PROP_FLOAT3, @@ -713,7 +749,7 @@ static ComponentAttributeProviders create_attribute_providers_for_mesh() static CustomDataAttributeProvider edge_custom_data(ATTR_DOMAIN_EDGE, edge_access); static CustomDataAttributeProvider polygon_custom_data(ATTR_DOMAIN_POLYGON, polygon_access); - return ComponentAttributeProviders({&position, &material_index, &vertex_normal}, + return ComponentAttributeProviders({&position, &material_index, &vertex_normal, &shade_smooth}, {&uvs, &vertex_colors, &corner_custom_data, |