Geometry Nodes: expose builtin crease attribute
This exposes the `crease` attribute, that is used by the Subdivide Smooth node. It is also the first attribute on the edge domain. Domain interpolations for the edge domain have not been implemented yet. Ref T86397. Differential Revision: https://developer.blender.org/D10660
This commit is contained in:
parent
992abd4734
commit
3618948df8
Notes:
blender-bot
2023-02-14 08:47:25 +01:00
Referenced by issue #86397, Expose Crease attribute to use with the Smooth subdivide node
|
@ -604,6 +604,28 @@ static WriteAttributePtr make_vertex_color_write_attribute(void *data, const int
|
|||
ATTR_DOMAIN_CORNER, MutableSpan((MLoopCol *)data, domain_size));
|
||||
}
|
||||
|
||||
static float get_crease(const MEdge &edge)
|
||||
{
|
||||
return edge.crease / 255.0f;
|
||||
}
|
||||
|
||||
static void set_crease(MEdge &edge, const float &value)
|
||||
{
|
||||
edge.crease = round_fl_to_uchar_clamp(value * 255.0f);
|
||||
}
|
||||
|
||||
static ReadAttributePtr make_crease_read_attribute(const void *data, const int domain_size)
|
||||
{
|
||||
return std::make_unique<DerivedArrayReadAttribute<MEdge, float, get_crease>>(
|
||||
ATTR_DOMAIN_EDGE, Span((const MEdge *)data, domain_size));
|
||||
}
|
||||
|
||||
static WriteAttributePtr make_crease_write_attribute(void *data, const int domain_size)
|
||||
{
|
||||
return std::make_unique<DerivedArrayWriteAttribute<MEdge, float, get_crease, set_crease>>(
|
||||
ATTR_DOMAIN_EDGE, MutableSpan((MEdge *)data, domain_size));
|
||||
}
|
||||
|
||||
class VertexWeightWriteAttribute final : public WriteAttribute {
|
||||
private:
|
||||
MDeformVert *dverts_;
|
||||
|
@ -903,6 +925,18 @@ static ComponentAttributeProviders create_attribute_providers_for_mesh()
|
|||
make_shade_smooth_write_attribute,
|
||||
nullptr);
|
||||
|
||||
static BuiltinCustomDataLayerProvider crease("crease",
|
||||
ATTR_DOMAIN_EDGE,
|
||||
CD_PROP_FLOAT,
|
||||
CD_MEDGE,
|
||||
BuiltinAttributeProvider::NonCreatable,
|
||||
BuiltinAttributeProvider::Writable,
|
||||
BuiltinAttributeProvider::NonDeletable,
|
||||
edge_access,
|
||||
make_crease_read_attribute,
|
||||
make_crease_write_attribute,
|
||||
nullptr);
|
||||
|
||||
static NamedLegacyCustomDataProvider uvs(ATTR_DOMAIN_CORNER,
|
||||
CD_PROP_FLOAT2,
|
||||
CD_MLOOPUV,
|
||||
|
@ -923,7 +957,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, &shade_smooth, &normal},
|
||||
return ComponentAttributeProviders({&position, &material_index, &shade_smooth, &normal, &crease},
|
||||
{&uvs,
|
||||
&vertex_colors,
|
||||
&corner_custom_data,
|
||||
|
|
|
@ -381,7 +381,7 @@ static void join_instance_groups_mesh(Span<GeometryInstanceGroup> set_groups,
|
|||
gather_attribute_info(attributes,
|
||||
component_types,
|
||||
set_groups,
|
||||
{"position", "material_index", "normal", "shade_smooth"});
|
||||
{"position", "material_index", "normal", "shade_smooth", "crease"});
|
||||
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", "normal", "shade_smooth"});
|
||||
{"position", "material_index", "normal", "shade_smooth", "crease"});
|
||||
}
|
||||
|
||||
static void join_components(Span<const PointCloudComponent *> src_components, GeometrySet &result)
|
||||
|
|
Loading…
Reference in New Issue