MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
Attachment.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "Influence.hpp"
4
5namespace MayaFlux::Buffers {
6class VKBuffer;
7class RenderProcessor;
8}
9
10namespace MayaFlux::Nexus {
11
12/**
13 * @struct AttachConfig
14 * @brief How an Agent attaches to a buffer that already exists.
15 */
17 /** @brief What a move of the Agent from outside does to the attachment. */
18 enum class OnMove : uint8_t {
19 Offset, ///< The move becomes the Agent's new offset from the buffer.
20 Carry, ///< The buffer is moved along with the Agent.
21 };
22
23 /**
24 * @brief Vertex whose position anchors the Agent. Unset anchors at the
25 * surface centroid, or the vertex mean for a mesh without faces.
26 *
27 * The geometry is read once, when attaching and on recenter(), by
28 * read_anchor. A buffer it cannot read anchors at its local origin.
29 */
30 std::optional<uint32_t> index;
31
32 /**
33 * @brief Offset of the Agent from the anchor, in the Agent's own frame.
34 *
35 * Rotated by the Agent's orientation, so a look that sits in front of its
36 * Agent stays in front as the Agent turns. Without an orientation it is a
37 * world-space offset.
38 */
39 glm::vec3 offset {};
40
42};
43
44/**
45 * @struct PlacementStack
46 * @brief The placements layered on one render processor, kept by its geometry transform source.
47 */
48struct PlacementStack;
49
50/**
51 * @struct Attachment
52 * @brief State of one Agent attached to an existing buffer.
53 *
54 * The transform is applied to every render processor the buffer has, outside
55 * whatever geometry transform that processor already had, which is kept
56 * beside it and restored when the last placement on the processor is released.
57 * Placements on one processor stack, later ones outside earlier ones, and each
58 * is released on its own. Nothing is registered with a manager and nothing is
59 * written to the buffer.
60 */
61struct Attachment {
62 std::shared_ptr<Buffers::VKBuffer> buf;
64 std::shared_ptr<glm::mat4> transform;
65 std::vector<std::pair<std::shared_ptr<Buffers::RenderProcessor>, std::shared_ptr<PlacementStack>>> followed;
66 glm::vec3 anchor {};
67 glm::vec3 applied {};
68};
69
70/**
71 * @brief Build an attachment to @p buf.
72 * @param buf Buffer to attach to. Must not be null.
73 * @param config Anchor vertex, offset and move behaviour.
74 * @param orientation Orientation of the Agent, if it has one.
75 */
76MAYAFLUX_API Attachment make_attachment(
77 std::shared_ptr<Buffers::VKBuffer> buf,
78 const AttachConfig& config,
79 const std::optional<glm::quat>& orientation);
80
81/**
82 * @brief Set @p position from the buffer, or fold an outside move into the attachment.
83 * @param attachment Attachment to follow.
84 * @param position Position of the Agent. Set if empty.
85 * @param orientation Orientation of the Agent, if it has one.
86 */
87MAYAFLUX_API void follow_attachment(
88 Attachment& attachment,
89 std::optional<glm::vec3>& position,
90 const std::optional<glm::quat>& orientation);
91
92/**
93 * @brief Read the buffer's geometry again and move the anchor to match.
94 *
95 * The Agent stays where it is: its offset from the new anchor absorbs the
96 * difference. Blocks for a ComputeMeshBuffer, so call it off the graphics thread.
97 *
98 * @param attachment Attachment to recenter.
99 * @param position Position of the Agent. Set if empty.
100 * @param orientation Orientation of the Agent, if it has one.
101 */
102MAYAFLUX_API void recenter_attachment(
103 Attachment& attachment,
104 std::optional<glm::vec3>& position,
105 const std::optional<glm::quat>& orientation);
106
107/**
108 * @brief Rebuild the transform from @p ctx and place every render processor of the buffer.
109 * @param attachment Attachment to apply.
110 * @param ctx Current InfluenceContext.
111 */
112MAYAFLUX_API void apply_attachment(
113 Attachment& attachment,
114 const InfluenceContext& ctx);
115
116/**
117 * @brief Place every render processor of the buffer that is not placed yet.
118 *
119 * For an attachment whose transform is set by the caller. Processors already
120 * followed are left alone; they read the same transform.
121 * @param attachment Attachment to place.
122 */
123MAYAFLUX_API void place_attachment(Attachment& attachment);
124
125/**
126 * @brief Give every placed render processor back the geometry transform it had.
127 * @param attachment Attachment to release.
128 */
129MAYAFLUX_API void release_attachment(Attachment& attachment);
130
131} // namespace MayaFlux::Nexus
std::optional< glm::vec3 > position
Definition Decoder.cpp:93
void apply_attachment(Attachment &attachment, const InfluenceContext &ctx)
Rebuild the transform from ctx and place every render processor of the buffer.
void recenter_attachment(Attachment &attachment, std::optional< glm::vec3 > &position, const std::optional< glm::quat > &orientation)
Read the buffer's geometry again and move the anchor to match.
void place_attachment(Attachment &attachment)
Place every render processor of the buffer that is not placed yet.
void follow_attachment(Attachment &attachment, std::optional< glm::vec3 > &position, const std::optional< glm::quat > &orientation)
Set position from the buffer, or fold an outside move into the attachment.
void release_attachment(Attachment &attachment)
Give every placed render processor back the geometry transform it had.
Attachment make_attachment(std::shared_ptr< Buffers::VKBuffer > buf, const AttachConfig &config, const std::optional< glm::quat > &orientation)
Build an attachment to buf.
std::optional< uint32_t > index
Vertex whose position anchors the Agent.
glm::vec3 offset
Offset of the Agent from the anchor, in the Agent's own frame.
OnMove
What a move of the Agent from outside does to the attachment.
@ Carry
The buffer is moved along with the Agent.
@ Offset
The move becomes the Agent's new offset from the buffer.
How an Agent attaches to a buffer that already exists.
std::shared_ptr< Buffers::VKBuffer > buf
std::shared_ptr< glm::mat4 > transform
std::vector< std::pair< std::shared_ptr< Buffers::RenderProcessor >, std::shared_ptr< PlacementStack > > > followed
State of one Agent attached to an existing buffer.