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
This commit is contained in:
parent
eaada56591
commit
0700441578
|
@ -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,
|
||||
|
|
|
@ -378,8 +378,10 @@ static void join_instance_groups_mesh(Span<GeometryInstanceGroup> set_groups,
|
|||
|
||||
/* Don't copy attributes that are stored directly in the mesh data structs. */
|
||||
Map<std::string, AttributeKind> attributes;
|
||||
gather_attribute_info(
|
||||
attributes, component_types, set_groups, {"position", "material_index", "vertex_normal"});
|
||||
gather_attribute_info(attributes,
|
||||
component_types,
|
||||
set_groups,
|
||||
{"position", "material_index", "vertex_normal", "shade_smooth"});
|
||||
join_attributes(
|
||||
set_groups, component_types, attributes, static_cast<GeometryComponent &>(dst_component));
|
||||
}
|
||||
|
|
|
@ -224,7 +224,7 @@ static void join_components(Span<const MeshComponent *> src_components, Geometry
|
|||
/* Don't copy attributes that are stored directly in the mesh data structs. */
|
||||
join_attributes(to_base_components(src_components),
|
||||
dst_component,
|
||||
{"position", "material_index", "vertex_normal"});
|
||||
{"position", "material_index", "vertex_normal", "shade_smooth"});
|
||||
}
|
||||
|
||||
static void join_components(Span<const PointCloudComponent *> src_components, GeometrySet &result)
|
||||
|
|
Loading…
Reference in New Issue