MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
Mantle.cpp
Go to the documentation of this file.
1#include "Mantle.hpp"
2
6
7namespace MayaFlux::Nexus {
8
9namespace {
10
11 constexpr float k_epsilon = 1.0e-6F;
12
13 float uniform_scale(const glm::vec3& from, const glm::vec3& to, bool largest)
14 {
15 const std::array<std::pair<float, float>, 3> axes { {
16 { from.x, to.x },
17 { from.y, to.y },
18 { from.z, to.z },
19 } };
20
21 bool any = false;
22 float scale = 1.0F;
23 for (const auto& [source, target] : axes) {
24 if (source <= k_epsilon) {
25 continue;
26 }
27 const float ratio = target / source;
28 scale = !any ? ratio : (largest ? std::max(scale, ratio) : std::min(scale, ratio));
29 any = true;
30 }
31 return scale;
32 }
33
34 Kinesis::AABB3D resolve(
35 const Kinesis::AABB3D& source,
36 const Kinesis::AABB3D& target,
38 {
40
41 const glm::vec3 from = source.extent();
42 const glm::vec3 to = target.extent();
43
44 switch (mode) {
45 case FitMode::CONTAIN:
46 return Kinesis::AABB3D::from_center(target.center(), from * uniform_scale(from, to, false) * 0.5F);
47 case FitMode::COVER:
48 return Kinesis::AABB3D::from_center(target.center(), from * uniform_scale(from, to, true) * 0.5F);
49 case FitMode::CENTER:
50 return Kinesis::AABB3D::from_center(target.center(), from * 0.5F);
51 case FitMode::STRETCH:
52 case FitMode::TILE:
53 case FitMode::TILE_MIRRORED:
54 break;
55 }
56 return target;
57 }
58
59}
60
62 std::shared_ptr<Buffers::VKBuffer> buf,
66 : Expanse(bounds, std::move(on_enter), std::move(on_exit))
67 , m_look { .buf = std::move(buf), .transform = std::make_shared<glm::mat4>(1.0F) }
68 , m_fit(fit)
69{
70 if (!m_look.buf) {
72 "Mantle needs a buffer");
73 return;
74 }
75
78 "Mantle fits tiling modes as STRETCH: tiling has no meaning for geometry");
79 }
80
82 if (!m_local) {
84 "Mantle leaves the buffer where it is: no geometry could be read from it");
85 return;
86 }
87
88 refresh();
89}
90
95
101
103{
104 if (!m_look.buf) {
105 return;
106 }
107
108 if (const auto local = read_bounds(m_look.buf)) {
109 m_local = local;
110 refresh();
111 } else {
113 "Mantle::refit kept the previous geometry: no geometry could be read from the buffer");
114 }
115}
116
118{
119 if (m_local) {
121 }
122}
123
125{
126 if (!m_local || !bounds()) {
127 return;
128 }
129
132}
133
134} // namespace MayaFlux::Nexus
#define MF_ERROR(comp, ctx,...)
#define MF_WARN(comp, ctx,...)
Expanse::CrossingFn on_enter
Definition Decoder.cpp:518
Expanse::CrossingFn on_exit
Definition Decoder.cpp:519
uint32_t mode
glm::ivec3 min
uint32_t largest
std::function< void(uint32_t)> CrossingFn
Definition Expanse.hpp:58
const std::optional< Kinesis::AABB3D > & bounds() const
The box, if set.
Definition Expanse.hpp:153
virtual void set_bounds(const Kinesis::AABB3D &bounds)
Set or replace the box.
Definition Expanse.hpp:147
A defined region of space with a containment test and crossing actions.
Definition Expanse.hpp:55
void refit()
Read the buffer's geometry again and place it to match.
Definition Mantle.cpp:102
std::optional< Kinesis::AABB3D > m_local
Definition Mantle.hpp:77
Portal::Graphics::FitMode m_fit
Definition Mantle.hpp:76
void begin_evaluate() override
Called at the start of every evaluate(), before any position is tested.
Definition Mantle.cpp:117
void set_bounds(const Kinesis::AABB3D &bounds) override
Set or replace the box and place the buffer to match.
Definition Mantle.cpp:96
Mantle(const Kinesis::AABB3D &bounds, std::shared_ptr< Buffers::VKBuffer > buf, Portal::Graphics::FitMode fit=Portal::Graphics::FitMode::STRETCH, CrossingFn on_enter={}, CrossingFn on_exit={})
Build from a box and a buffer.
Definition Mantle.cpp:61
@ Init
Engine/subsystem initialization.
@ Runtime
General runtime operations (default fallback)
@ Nexus
Spatial indexing and scheduling for user-defined behaviour.
std::vector< ResolvedSequence > resolve(const VisionQuery &query)
Resolve a VisionQuery into the ResolvedSequences needed to satisfy every active intent.
glm::mat4 box_transform(const AABB3D &source, const AABB3D &target)
Transform that scales and translates one box onto another.
Tendency< D, float > scale(const Tendency< D, float > &t, float factor)
Uniform scaling of a scalar-output tendency.
Definition Tendency.hpp:98
void place_attachment(Attachment &attachment)
Place every render processor of the buffer that is not placed yet.
void release_attachment(Attachment &attachment)
Give every placed render processor back the geometry transform it had.
std::optional< Kinesis::AABB3D > read_bounds(const std::shared_ptr< Buffers::VKBuffer > &buf, const std::optional< uint32_t > &collection)
Bounds of a buffer's geometry in its own stored coordinates.
Definition Survey.cpp:256
Source source()
Begin a Source chain.
Definition Plot.hpp:127
FitMode
How a source extent is mapped onto a destination extent.
@ TILE_MIRRORED
Source repeated, every other tile mirrored.
@ TILE
Source repeated at its own size.
static AABB3D from_center(const glm::vec3 &c, const glm::vec3 &half) noexcept
Construct from a center point and half-extents.
Definition Bounds.hpp:225
Axis-aligned bounding box in 3D world space.
Definition Bounds.hpp:188
std::shared_ptr< Buffers::VKBuffer > buf
std::shared_ptr< glm::mat4 > transform