Geometry Nodes: Use a default value in the point scale node
This commit adds the ability to provide a default value to `attribute_try_get_for_output` and uses it for the `Point Scale` node, which is important because the node uses multiplication. The idea is to keep "name-specific" functionality in nodes rather than in the attribute API, otherwise the complexity will be hard to keep track of. So this fix doesn't apply to the Attribute Vector Math node, but hopfully that is okay since that's now a lower level node for this purpose anyway. Differential Revision: https://developer.blender.org/D10115
This commit is contained in:
parent
3732508c64
commit
0b0e45252b
Notes:
blender-bot
2023-02-14 06:37:09 +01:00
Referenced by issue #84639, Scale attribute has no default value after distribution
|
@ -242,7 +242,8 @@ class GeometryComponent {
|
|||
|
||||
/**
|
||||
* If an attribute with the given params exist, it is returned.
|
||||
* If no attribute with the given name exists, it is created and returned.
|
||||
* If no attribute with the given name exists, create it and
|
||||
* fill it with the default value if it is provided.
|
||||
* If an attribute with the given name but different domain or type exists, a temporary attribute
|
||||
* is created that has to be saved after the output has been computed. This avoids deleting
|
||||
* another attribute, before a computation is finished.
|
||||
|
@ -251,7 +252,8 @@ class GeometryComponent {
|
|||
*/
|
||||
OutputAttributePtr attribute_try_get_for_output(const blender::StringRef attribute_name,
|
||||
const AttributeDomain domain,
|
||||
const CustomDataType data_type);
|
||||
const CustomDataType data_type,
|
||||
const void *default_value = nullptr);
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
|
|
|
@ -814,7 +814,8 @@ blender::bke::ReadAttributePtr GeometryComponent::attribute_get_constant_for_rea
|
|||
|
||||
OutputAttributePtr GeometryComponent::attribute_try_get_for_output(const StringRef attribute_name,
|
||||
const AttributeDomain domain,
|
||||
const CustomDataType data_type)
|
||||
const CustomDataType data_type,
|
||||
const void *default_value)
|
||||
{
|
||||
BLI_assert(this->attribute_domain_with_type_supported(domain, data_type));
|
||||
|
||||
|
@ -827,6 +828,11 @@ OutputAttributePtr GeometryComponent::attribute_try_get_for_output(const StringR
|
|||
if (!attribute) {
|
||||
this->attribute_try_create(attribute_name, domain, data_type);
|
||||
attribute = this->attribute_try_get_for_write(attribute_name);
|
||||
if (default_value != nullptr) {
|
||||
void *data = attribute->get_span_for_write_only().data();
|
||||
cpp_type->fill_initialized(default_value, data, attribute->size());
|
||||
attribute->apply_span();
|
||||
}
|
||||
return OutputAttributePtr(std::move(attribute));
|
||||
}
|
||||
|
||||
|
|
|
@ -34,8 +34,9 @@ namespace blender::nodes {
|
|||
|
||||
static void execute_on_component(GeoNodeExecParams params, GeometryComponent &component)
|
||||
{
|
||||
static const float3 scale_default = float3(1.0f);
|
||||
OutputAttributePtr scale_attribute = component.attribute_try_get_for_output(
|
||||
"scale", ATTR_DOMAIN_POINT, CD_PROP_FLOAT3);
|
||||
"scale", ATTR_DOMAIN_POINT, CD_PROP_FLOAT3, &scale_default);
|
||||
ReadAttributePtr attribute = params.get_input_attribute(
|
||||
"Factor", component, ATTR_DOMAIN_POINT, CD_PROP_FLOAT3, nullptr);
|
||||
if (!attribute) {
|
||||
|
|
Loading…
Reference in New Issue