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

◆ read_anchor()

MAYAFLUX_API std::optional< glm::vec3 > MayaFlux::Nexus::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.

The position of the vertex at index, else the surface centroid, else the vertex mean for a mesh without faces. A point or path buffer reports the mean of its vertices; an InstanceNetworkBuffer, with no index, the centre of its bounds. Blocks for a ComputeMeshBuffer and for a buffer a field processor drives.

Parameters
bufBuffer to read.
indexVertex to anchor at, if any.
Returns
The anchor, or nullopt when no geometry can be read from the buffer.

Definition at line 213 of file Survey.cpp.

216{
217 if (const auto cloud = cloud_of(buf); cloud && !cloud->positions.empty()) {
218 if (!index) {
219 return Kinesis::centroid(cloud->positions);
220 }
221 return *index < cloud->positions.size()
222 ? std::optional<glm::vec3> { cloud->positions.at(*index) }
223 : std::nullopt;
224 }
225
226 if (const auto instances = std::dynamic_pointer_cast<Buffers::InstanceNetworkBuffer>(buf);
227 instances && !index) {
228 const auto bounds = instance_bounds(instances);
229 return bounds ? std::optional<glm::vec3> { bounds->center() } : std::nullopt;
230 }
231
232 const auto mesh = snapshot_mesh(buf);
233 if (!mesh) {
234 return std::nullopt;
235 }
236
237 const auto bytes = vertex_bytes(*mesh);
238 if (bytes.empty()) {
239 return std::nullopt;
240 }
241
242 const size_t stride = mesh->layout.stride_bytes;
243 const size_t offset = position_offset(mesh->layout);
244
245 if (index) {
246 return Kinesis::position_at(bytes, stride, offset, *index);
247 }
248
249 if (const auto* faces = std::get_if<std::vector<uint32_t>>(&mesh->index_variant);
250 faces && !faces->empty()) {
251 return Kinesis::surface_centroid(bytes, stride, offset, *faces);
252 }
253 return Kinesis::centroid(bytes, stride, offset);
254}
uint64_t offset
Definition Composite.cpp:10
uint32_t position_offset
uint32_t index
Definition VKDevice.cpp:122

References index, offset, position_offset, and read_anchor().

Referenced by make_attachment(), read_anchor(), and recenter_attachment().

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