diff --git a/src/experimental/filament/filament/mesh.cc b/src/experimental/filament/filament/mesh.cc index 8acc2d59..0736cbd9 100644 --- a/src/experimental/filament/filament/mesh.cc +++ b/src/experimental/filament/filament/mesh.cc @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -202,6 +203,7 @@ void Mesh::BuildVertexBuffer(const MeshData& data) { vb_builder.normalized(usage); } offset += VertexAttributeTypeSize(attrib); + attributes_[i] = usage; } vertex_buffer_ = vb_builder.build(*engine_); vertex_buffer_->setBufferAt(*engine_, 0, {bytes, nbytes, callback, this}); @@ -221,7 +223,9 @@ void Mesh::BuildVertexBuffer(const MeshData& data) { if (usage == filament::VertexAttribute::COLOR) { vb_builder.normalized(usage); } + attributes_[i] = usage; } + num_attributes_ = data.nattributes; vertex_buffer_ = vb_builder.build(*engine_); // Assign the individual data buffers. @@ -334,6 +338,10 @@ filament::RenderableManager::PrimitiveType Mesh::GetPrimitiveType() const { return type_; } +std::span Mesh::GetVertexAttributes() const { + return {attributes_.data(), attributes_.data() + num_attributes_}; +} + bool Mesh::HasBounds() const { return bounds_.has_value(); } diff --git a/src/experimental/filament/filament/mesh.h b/src/experimental/filament/filament/mesh.h index 5953d0da..cc30b6d3 100644 --- a/src/experimental/filament/filament/mesh.h +++ b/src/experimental/filament/filament/mesh.h @@ -15,10 +15,12 @@ #ifndef MUJOCO_SRC_EXPERIMENTAL_FILAMENT_FILAMENT_MESH_H_ #define MUJOCO_SRC_EXPERIMENTAL_FILAMENT_FILAMENT_MESH_H_ +#include #include #include #include #include +#include #include #include @@ -31,6 +33,9 @@ // Functions for creating filament vertex and index buffers. namespace mujoco { +// Maximum number of vertex attributes that can be used by a mesh. +static constexpr int kMaxVertexAttributes = 16; + // The type of data stored in an index buffer. typedef enum mjtIndexType_ { mjINDEX_TYPE_USHORT = 0, @@ -83,7 +88,7 @@ struct MeshData { // Information about each attribute of a vertex in the mesh. See `interleaved` // for more details. - VertexAttribute attributes[16]; + VertexAttribute attributes[kMaxVertexAttributes]; // Whether the vertex attributes are interleaved or not. // @@ -147,6 +152,9 @@ class Mesh { // Returns the primitive type of the mesh. filament::RenderableManager::PrimitiveType GetPrimitiveType() const; + // Returns the vertex attribute usages for the mesh. + std::span GetVertexAttributes() const; + // Returns whether the mesh has bounds. bool HasBounds() const; @@ -173,6 +181,8 @@ class Mesh { filament::RenderableManager::PrimitiveType::TRIANGLES; std::optional bounds_; std::vector> release_callbacks_; + std::array attributes_; + int num_attributes_ = 0; }; using MeshPtr = std::unique_ptr;