Changeset View
Changeset View
Standalone View
Standalone View
source/blender/nodes/geometry/nodes/node_geo_attribute_map_range.cc
| Show First 20 Lines • Show All 202 Lines • ▼ Show 20 Lines | static void map_range_float(const VArray<float> &attribute_input, | ||||
| const float max_from = params.get_input<float>("From Max"); | const float max_from = params.get_input<float>("From Max"); | ||||
| const float min_to = params.get_input<float>("To Min"); | const float min_to = params.get_input<float>("To Min"); | ||||
| const float max_to = params.get_input<float>("To Max"); | const float max_to = params.get_input<float>("To Max"); | ||||
| VArray_Span<float> span{attribute_input}; | VArray_Span<float> span{attribute_input}; | ||||
| switch (interpolation_type) { | switch (interpolation_type) { | ||||
| case NODE_MAP_RANGE_LINEAR: { | case NODE_MAP_RANGE_LINEAR: { | ||||
| for (int i : span.index_range()) { | for (int i : iter_indices(span)) { | ||||
| results[i] = map_linear(span[i], min_from, max_from, min_to, max_to); | results[i] = map_linear(span[i], min_from, max_from, min_to, max_to); | ||||
| } | } | ||||
| break; | break; | ||||
| } | } | ||||
| case NODE_MAP_RANGE_STEPPED: { | case NODE_MAP_RANGE_STEPPED: { | ||||
| const float steps = params.get_input<float>("Steps"); | const float steps = params.get_input<float>("Steps"); | ||||
| for (int i : span.index_range()) { | for (int i : iter_indices(span)) { | ||||
| results[i] = map_stepped(span[i], min_from, max_from, min_to, max_to, steps); | results[i] = map_stepped(span[i], min_from, max_from, min_to, max_to, steps); | ||||
| } | } | ||||
| break; | break; | ||||
| } | } | ||||
| case NODE_MAP_RANGE_SMOOTHSTEP: { | case NODE_MAP_RANGE_SMOOTHSTEP: { | ||||
| for (int i : span.index_range()) { | for (int i : iter_indices(span)) { | ||||
| results[i] = map_smoothstep(span[i], min_from, max_from, min_to, max_to); | results[i] = map_smoothstep(span[i], min_from, max_from, min_to, max_to); | ||||
| } | } | ||||
| break; | break; | ||||
| } | } | ||||
| case NODE_MAP_RANGE_SMOOTHERSTEP: { | case NODE_MAP_RANGE_SMOOTHERSTEP: { | ||||
| for (int i : span.index_range()) { | for (int i : iter_indices(span)) { | ||||
| results[i] = map_smootherstep(span[i], min_from, max_from, min_to, max_to); | results[i] = map_smootherstep(span[i], min_from, max_from, min_to, max_to); | ||||
| } | } | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| if (ELEM(interpolation_type, NODE_MAP_RANGE_LINEAR, NODE_MAP_RANGE_STEPPED) && | if (ELEM(interpolation_type, NODE_MAP_RANGE_LINEAR, NODE_MAP_RANGE_STEPPED) && | ||||
| params.get_input<bool>("Clamp")) { | params.get_input<bool>("Clamp")) { | ||||
| /* Users can specify min_to > max_to, but clamping expects min < max. */ | /* Users can specify min_to > max_to, but clamping expects min < max. */ | ||||
| const float clamp_min = min_to < max_to ? min_to : max_to; | const float clamp_min = min_to < max_to ? min_to : max_to; | ||||
| const float clamp_max = min_to < max_to ? max_to : min_to; | const float clamp_max = min_to < max_to ? max_to : min_to; | ||||
| for (int i : results.index_range()) { | for (int i : iter_indices(results)) { | ||||
| results[i] = std::clamp(results[i], clamp_min, clamp_max); | results[i] = std::clamp(results[i], clamp_min, clamp_max); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| static void map_range_float3(const VArray<float3> &attribute_input, | static void map_range_float3(const VArray<float3> &attribute_input, | ||||
| const MutableSpan<float3> results, | const MutableSpan<float3> results, | ||||
| const GeoNodeExecParams ¶ms) | const GeoNodeExecParams ¶ms) | ||||
| { | { | ||||
| const bNode &node = params.node(); | const bNode &node = params.node(); | ||||
| NodeAttributeMapRange &node_storage = *(NodeAttributeMapRange *)node.storage; | NodeAttributeMapRange &node_storage = *(NodeAttributeMapRange *)node.storage; | ||||
| const int interpolation_type = node_storage.interpolation_type; | const int interpolation_type = node_storage.interpolation_type; | ||||
| const float3 min_from = params.get_input<float3>("From Min_001"); | const float3 min_from = params.get_input<float3>("From Min_001"); | ||||
| const float3 max_from = params.get_input<float3>("From Max_001"); | const float3 max_from = params.get_input<float3>("From Max_001"); | ||||
| const float3 min_to = params.get_input<float3>("To Min_001"); | const float3 min_to = params.get_input<float3>("To Min_001"); | ||||
| const float3 max_to = params.get_input<float3>("To Max_001"); | const float3 max_to = params.get_input<float3>("To Max_001"); | ||||
| VArray_Span<float3> span{attribute_input}; | VArray_Span<float3> span{attribute_input}; | ||||
| switch (interpolation_type) { | switch (interpolation_type) { | ||||
| case NODE_MAP_RANGE_LINEAR: { | case NODE_MAP_RANGE_LINEAR: { | ||||
| for (int i : span.index_range()) { | for (int i : iter_indices(span)) { | ||||
| results[i].x = map_linear(span[i].x, min_from.x, max_from.x, min_to.x, max_to.x); | results[i].x = map_linear(span[i].x, min_from.x, max_from.x, min_to.x, max_to.x); | ||||
| results[i].y = map_linear(span[i].y, min_from.y, max_from.y, min_to.y, max_to.y); | results[i].y = map_linear(span[i].y, min_from.y, max_from.y, min_to.y, max_to.y); | ||||
| results[i].z = map_linear(span[i].z, min_from.z, max_from.z, min_to.z, max_to.z); | results[i].z = map_linear(span[i].z, min_from.z, max_from.z, min_to.z, max_to.z); | ||||
| } | } | ||||
| break; | break; | ||||
| } | } | ||||
| case NODE_MAP_RANGE_STEPPED: { | case NODE_MAP_RANGE_STEPPED: { | ||||
| const float3 steps = params.get_input<float3>("Steps_001"); | const float3 steps = params.get_input<float3>("Steps_001"); | ||||
| for (int i : span.index_range()) { | for (int i : iter_indices(span)) { | ||||
| results[i].x = map_stepped(span[i].x, min_from.x, max_from.x, min_to.x, max_to.x, steps.x); | results[i].x = map_stepped(span[i].x, min_from.x, max_from.x, min_to.x, max_to.x, steps.x); | ||||
| results[i].y = map_stepped(span[i].y, min_from.y, max_from.y, min_to.y, max_to.y, steps.y); | results[i].y = map_stepped(span[i].y, min_from.y, max_from.y, min_to.y, max_to.y, steps.y); | ||||
| results[i].z = map_stepped(span[i].z, min_from.z, max_from.z, min_to.z, max_to.z, steps.z); | results[i].z = map_stepped(span[i].z, min_from.z, max_from.z, min_to.z, max_to.z, steps.z); | ||||
| } | } | ||||
| break; | break; | ||||
| } | } | ||||
| case NODE_MAP_RANGE_SMOOTHSTEP: { | case NODE_MAP_RANGE_SMOOTHSTEP: { | ||||
| for (int i : span.index_range()) { | for (int i : iter_indices(span)) { | ||||
| results[i].x = map_smoothstep(span[i].x, min_from.x, max_from.x, min_to.x, max_to.x); | results[i].x = map_smoothstep(span[i].x, min_from.x, max_from.x, min_to.x, max_to.x); | ||||
| results[i].y = map_smoothstep(span[i].y, min_from.y, max_from.y, min_to.y, max_to.y); | results[i].y = map_smoothstep(span[i].y, min_from.y, max_from.y, min_to.y, max_to.y); | ||||
| results[i].z = map_smoothstep(span[i].z, min_from.z, max_from.z, min_to.z, max_to.z); | results[i].z = map_smoothstep(span[i].z, min_from.z, max_from.z, min_to.z, max_to.z); | ||||
| } | } | ||||
| break; | break; | ||||
| } | } | ||||
| case NODE_MAP_RANGE_SMOOTHERSTEP: { | case NODE_MAP_RANGE_SMOOTHERSTEP: { | ||||
| for (int i : span.index_range()) { | for (int i : iter_indices(span)) { | ||||
| results[i].x = map_smootherstep(span[i].x, min_from.x, max_from.x, min_to.x, max_to.x); | results[i].x = map_smootherstep(span[i].x, min_from.x, max_from.x, min_to.x, max_to.x); | ||||
| results[i].y = map_smootherstep(span[i].y, min_from.y, max_from.y, min_to.y, max_to.y); | results[i].y = map_smootherstep(span[i].y, min_from.y, max_from.y, min_to.y, max_to.y); | ||||
| results[i].z = map_smootherstep(span[i].z, min_from.z, max_from.z, min_to.z, max_to.z); | results[i].z = map_smootherstep(span[i].z, min_from.z, max_from.z, min_to.z, max_to.z); | ||||
| } | } | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| if (ELEM(interpolation_type, NODE_MAP_RANGE_LINEAR, NODE_MAP_RANGE_STEPPED) && | if (ELEM(interpolation_type, NODE_MAP_RANGE_LINEAR, NODE_MAP_RANGE_STEPPED) && | ||||
| params.get_input<bool>("Clamp")) { | params.get_input<bool>("Clamp")) { | ||||
| /* Users can specify min_to > max_to, but clamping expects min < max. */ | /* Users can specify min_to > max_to, but clamping expects min < max. */ | ||||
| float3 clamp_min; | float3 clamp_min; | ||||
| float3 clamp_max; | float3 clamp_max; | ||||
| clamp_min.x = min_to.x < max_to.x ? min_to.x : max_to.x; | clamp_min.x = min_to.x < max_to.x ? min_to.x : max_to.x; | ||||
| clamp_max.x = min_to.x < max_to.x ? max_to.x : min_to.x; | clamp_max.x = min_to.x < max_to.x ? max_to.x : min_to.x; | ||||
| clamp_min.y = min_to.y < max_to.y ? min_to.y : max_to.y; | clamp_min.y = min_to.y < max_to.y ? min_to.y : max_to.y; | ||||
| clamp_max.y = min_to.y < max_to.y ? max_to.y : min_to.y; | clamp_max.y = min_to.y < max_to.y ? max_to.y : min_to.y; | ||||
| clamp_min.z = min_to.z < max_to.z ? min_to.z : max_to.z; | clamp_min.z = min_to.z < max_to.z ? min_to.z : max_to.z; | ||||
| clamp_max.z = min_to.z < max_to.z ? max_to.z : min_to.z; | clamp_max.z = min_to.z < max_to.z ? max_to.z : min_to.z; | ||||
| for (int i : results.index_range()) { | for (int i : iter_indices(results)) { | ||||
| clamp_v3_v3v3(results[i], clamp_min, clamp_max); | clamp_v3_v3v3(results[i], clamp_min, clamp_max); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| static AttributeDomain get_result_domain(const GeometryComponent &component, | static AttributeDomain get_result_domain(const GeometryComponent &component, | ||||
| StringRef source_name, | StringRef source_name, | ||||
| StringRef result_name) | StringRef result_name) | ||||
| ▲ Show 20 Lines • Show All 93 Lines • Show Last 20 Lines | |||||