Changeset View
Changeset View
Standalone View
Standalone View
source/blender/nodes/geometry/nodes/node_geo_random_attribute.cc
| Show First 20 Lines • Show All 53 Lines • ▼ Show 20 Lines | static void geo_node_random_attribute_update(bNodeTree *UNUSED(ntree), bNode *node) | ||||
| nodeSetSocketAvailability(sock_min_vector, data_type == CD_PROP_FLOAT3); | nodeSetSocketAvailability(sock_min_vector, data_type == CD_PROP_FLOAT3); | ||||
| nodeSetSocketAvailability(sock_max_vector, data_type == CD_PROP_FLOAT3); | nodeSetSocketAvailability(sock_max_vector, data_type == CD_PROP_FLOAT3); | ||||
| nodeSetSocketAvailability(sock_min_float, data_type == CD_PROP_FLOAT); | nodeSetSocketAvailability(sock_min_float, data_type == CD_PROP_FLOAT); | ||||
| nodeSetSocketAvailability(sock_max_float, data_type == CD_PROP_FLOAT); | nodeSetSocketAvailability(sock_max_float, data_type == CD_PROP_FLOAT); | ||||
| } | } | ||||
| namespace blender::nodes { | namespace blender::nodes { | ||||
| static void randomize_attribute(BooleanWriteAttribute &attribute, RandomNumberGenerator &rng) | |||||
| { | |||||
| MutableSpan<bool> attribute_span = attribute.get_span(); | |||||
| for (const int i : IndexRange(attribute.size())) { | |||||
| const bool value = rng.get_float() > 0.5f; | |||||
| attribute_span[i] = value; | |||||
| } | |||||
| attribute.apply_span(); | |||||
| } | |||||
| static void randomize_attribute(FloatWriteAttribute &attribute, | static void randomize_attribute(FloatWriteAttribute &attribute, | ||||
| float min, | float min, | ||||
| float max, | float max, | ||||
| RandomNumberGenerator &rng) | RandomNumberGenerator &rng) | ||||
| { | { | ||||
| MutableSpan<float> attribute_span = attribute.get_span(); | MutableSpan<float> attribute_span = attribute.get_span(); | ||||
| for (const int i : IndexRange(attribute.size())) { | for (const int i : IndexRange(attribute.size())) { | ||||
| const float value = rng.get_float() * (max - min) + min; | const float value = rng.get_float() * (max - min) + min; | ||||
| ▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | switch (data_type) { | ||||
| } | } | ||||
| case CD_PROP_FLOAT3: { | case CD_PROP_FLOAT3: { | ||||
| Float3WriteAttribute float3_attribute = std::move(attribute); | Float3WriteAttribute float3_attribute = std::move(attribute); | ||||
| const float3 min_value = params.get_input<float3>("Min"); | const float3 min_value = params.get_input<float3>("Min"); | ||||
| const float3 max_value = params.get_input<float3>("Max"); | const float3 max_value = params.get_input<float3>("Max"); | ||||
| randomize_attribute(float3_attribute, min_value, max_value, rng); | randomize_attribute(float3_attribute, min_value, max_value, rng); | ||||
| break; | break; | ||||
| } | } | ||||
| case CD_PROP_BOOL: { | |||||
| BooleanWriteAttribute boolean_attribute = std::move(attribute); | |||||
| randomize_attribute(boolean_attribute, rng); | |||||
| break; | |||||
| } | |||||
| default: | default: | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| static void geo_node_random_attribute_exec(GeoNodeExecParams params) | static void geo_node_random_attribute_exec(GeoNodeExecParams params) | ||||
| { | { | ||||
| GeometrySet geometry_set = params.extract_input<GeometrySet>("Geometry"); | GeometrySet geometry_set = params.extract_input<GeometrySet>("Geometry"); | ||||
| Show All 30 Lines | |||||