MayaFlux 1.0.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 629 of file GeometryPrimitives.cpp.

634{
635 if (positions.empty() || colors.empty()) {
636 return {};
637 }
638
639 std::vector<Kakshya::Vertex> vertices;
640 vertices.reserve(positions.size());
641
642 if (colors.size() == 1) {
643 for (const auto& pos : positions) {
644 vertices.push_back({ .position = pos,
645 .color = colors[0],
646 .scalar = scalar });
647 }
648 return vertices;
649 }
650
651 std::vector<float> stops = color_positions;
652 if (stops.empty()) {
653 stops.reserve(colors.size());
654 for (size_t i = 0; i < colors.size(); ++i) {
655 stops.push_back(static_cast<float>(i) / static_cast<float>(colors.size() - 1));
656 }
657 }
658
659 for (size_t i = 0; i < positions.size(); ++i) {
660 float t = static_cast<float>(i) / static_cast<float>(positions.size() - 1);
661
662 glm::vec3 color;
663 if (t <= stops[0]) {
664 color = colors[0];
665 } else if (t >= stops.back()) {
666 color = colors.back();
667 } else {
668 size_t idx = 0;
669 for (size_t j = 1; j < stops.size(); ++j) {
670 if (t <= stops[j]) {
671 idx = j - 1;
672 break;
673 }
674 }
675
676 float local_t = (t - stops[idx]) / (stops[idx + 1] - stops[idx]);
677 color = glm::mix(colors[idx], colors[idx + 1], local_t);
678 }
679
680 vertices.push_back({ .position = positions[i],
681 .color = color,
682 .scalar = scalar });
683 }
684
685 return vertices;
686}
glm::vec3 color
Definition Decoder.cpp:97
uint32_t scalar
std::vector< glm::vec3 > positions

References apply_color_gradient(), color, positions, and scalar.

Referenced by apply_color_gradient().

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