MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ apply_color_gradient()

MAYAFLUX_API std::vector< Kakshya::Vertex > MayaFlux::Kinesis::apply_color_gradient ( const std::vector< glm::vec3 > &  positions,
const std::vector< glm::vec3 > &  colors,
const std::vector< float > &  color_positions = {},
float  scalar = 1.0F 
)

Apply color interpolation to position vertices.

Parameters
positionsInput position vertices
colorsColor stops for interpolation
color_positionsNormalized positions [0,1] for each color stop
default_thicknessLine thickness for all vertices (default: 1.0)
Returns
LineVertex array with interpolated colors

Example: colors = {red, blue} color_positions = {0.0, 1.0} → Linear gradient from red to blue along path

If color_positions.empty(), distributes colors uniformly.

Definition at line 569 of file GeometryPrimitives.cpp.

574{
575 if (positions.empty() || colors.empty()) {
576 return {};
577 }
578
579 std::vector<Kakshya::Vertex> vertices;
580 vertices.reserve(positions.size());
581
582 if (colors.size() == 1) {
583 for (const auto& pos : positions) {
584 vertices.push_back({ .position = pos,
585 .color = colors[0],
586 .scalar = scalar });
587 }
588 return vertices;
589 }
590
591 std::vector<float> stops = color_positions;
592 if (stops.empty()) {
593 stops.reserve(colors.size());
594 for (size_t i = 0; i < colors.size(); ++i) {
595 stops.push_back(static_cast<float>(i) / static_cast<float>(colors.size() - 1));
596 }
597 }
598
599 for (size_t i = 0; i < positions.size(); ++i) {
600 float t = static_cast<float>(i) / static_cast<float>(positions.size() - 1);
601
602 glm::vec3 color;
603 if (t <= stops[0]) {
604 color = colors[0];
605 } else if (t >= stops.back()) {
606 color = colors.back();
607 } else {
608 size_t idx = 0;
609 for (size_t j = 1; j < stops.size(); ++j) {
610 if (t <= stops[j]) {
611 idx = j - 1;
612 break;
613 }
614 }
615
616 float local_t = (t - stops[idx]) / (stops[idx + 1] - stops[idx]);
617 color = glm::mix(colors[idx], colors[idx + 1], local_t);
618 }
619
620 vertices.push_back({ .position = positions[i],
621 .color = color,
622 .scalar = scalar });
623 }
624
625 return vertices;
626}

References apply_color_gradient().

Referenced by apply_color_gradient().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: