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

◆ recenter_attachment()

MAYAFLUX_API void MayaFlux::Nexus::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.

The Agent stays where it is: its offset from the new anchor absorbs the difference. Blocks for a ComputeMeshBuffer, so call it off the graphics thread.

Parameters
attachmentAttachment to recenter.
positionPosition of the Agent. Set if empty.
orientationOrientation of the Agent, if it has one.

Definition at line 129 of file Attachment.cpp.

133{
134 const glm::quat rotation = frame(orientation);
135
136 if (const auto anchor = read_anchor(attachment.buf, attachment.config.index)) {
137 attachment.anchor = *anchor;
138 } else {
139 MF_WARN(Journal::Component::Nexus, Journal::Context::Runtime,
140 "recenter kept the previous anchor: no geometry could be read from the buffer");
141 }
142
143 const glm::vec3 placed = glm::vec3(*attachment.transform * glm::vec4(attachment.anchor, 1.0F));
144
145 if (position) {
146 attachment.config.offset = glm::inverse(rotation) * (*position - placed);
147 } else {
148 position = placed + rotation * attachment.config.offset;
149 }
150 attachment.applied = *position;
151}
#define MF_WARN(comp, ctx,...)
std::optional< glm::vec3 > position
Definition Decoder.cpp:93
std::optional< glm::vec3 > read_anchor(const std::shared_ptr< Buffers::VKBuffer > &buf, const std::optional< uint32_t > &index)
Anchor of a buffer's geometry in its own stored coordinates.
Definition Survey.cpp:213
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.
std::shared_ptr< Buffers::VKBuffer > buf
std::shared_ptr< glm::mat4 > transform

References MayaFlux::Nexus::Attachment::anchor, MayaFlux::Nexus::Attachment::applied, MayaFlux::Nexus::Attachment::buf, MayaFlux::Nexus::Attachment::config, MayaFlux::Nexus::AttachConfig::index, MF_WARN, MayaFlux::Journal::Nexus, MayaFlux::Nexus::AttachConfig::offset, position, read_anchor(), MayaFlux::Journal::Runtime, and MayaFlux::Nexus::Attachment::transform.

Referenced by MayaFlux::Nexus::Agent::recenter(), and MayaFlux::Nexus::Emitter::recenter().

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