MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
Hull.hpp
Go to the documentation of this file.
1#pragma once
2
4
5namespace MayaFlux::Buffers {
6class VKBuffer;
7}
8
9namespace MayaFlux::Nexus {
10
11class StateEncoder;
12
13/**
14 * @class Hull
15 * @brief An Expanse whose region is the bounds of a buffer that already exists.
16 *
17 * The buffer's geometry is read once, when the Hull is built and on refit(),
18 * and the box is kept in the buffer's stored coordinates. Containment takes a
19 * world position back through the transform the buffer is drawn with, so the
20 * region follows the buffer wherever it is placed, for example by an Agent
21 * attached to it, and stays an exact box under rotation and scale. The buffer
22 * is neither registered nor written to, and nothing is encoded for a Hull.
23 *
24 * Only the buffer's primary render processor is read. A buffer whose geometry
25 * cannot be read contains nothing. Reading a buffer that a GpuFieldOperator drives
26 * downloads it from the device, so refit() belongs on a FRAME_ACCURATE metro.
27 */
28class MAYAFLUX_API Hull : public Expanse {
29public:
30 /**
31 * @brief Build from a buffer. Blocks for a ComputeMeshBuffer.
32 * @param buf Buffer to wrap. Must not be null.
33 * @param on_enter Fired with the entity id when it enters. May be empty.
34 * @param on_exit Fired with the entity id when it leaves. May be empty.
35 * @param collection One collection of a NetworkGeometryBuffer to wrap, for a
36 * buffer that holds several bodies. Unset wraps all of it.
37 */
38 explicit Hull(std::shared_ptr<Buffers::VKBuffer> buf,
41 std::optional<uint32_t> collection = std::nullopt);
42
43 /** @brief Test whether a world position lies within the buffer's bounds as drawn. */
44 [[nodiscard]] bool contains(const glm::vec3& p) const override;
45
46 /**
47 * @brief Read the buffer's geometry again and take its bounds.
48 *
49 * For a deforming mesh or a drifting cloud. Blocks for a ComputeMeshBuffer or a
50 * buffer a GpuFieldOperator drives, so call it off the graphics thread. The previous bounds are kept if nothing can be read.
51 */
52 void refit();
53
54protected:
55 /** @brief The centre of the bounds as drawn, and the distance to their farthest corner. */
56 [[nodiscard]] std::pair<glm::vec3, float> reach() const override;
57
58private:
59 friend class StateEncoder;
60
61 std::shared_ptr<Buffers::VKBuffer> m_buf;
62 std::optional<uint32_t> m_collection;
63 std::optional<Kinesis::AABB3D> m_local;
64};
65
66} // namespace MayaFlux::Nexus
Expanse::ContainsFn contains
Definition Decoder.cpp:517
Expanse::CrossingFn on_enter
Definition Decoder.cpp:518
Expanse::CrossingFn on_exit
Definition Decoder.cpp:519
std::function< void(uint32_t)> CrossingFn
Definition Expanse.hpp:58
A defined region of space with a containment test and crossing actions.
Definition Expanse.hpp:55
std::optional< uint32_t > m_collection
Definition Hull.hpp:62
std::optional< Kinesis::AABB3D > m_local
Definition Hull.hpp:63
std::shared_ptr< Buffers::VKBuffer > m_buf
Definition Hull.hpp:61
An Expanse whose region is the bounds of a buffer that already exists.
Definition Hull.hpp:28
Serializes Fabric state to an EXR texture and JSON schema.
Definition Encoder.hpp:25