Keep track of the vertex attributes in a Mesh.

PiperOrigin-RevId: 900583030
Change-Id: I5b1ff5ad7b698e3e68fd06f44f2c5d3399d08504
This commit is contained in:
Haroon Qureshi
2026-04-16 01:41:13 -07:00
committed by Copybara-Service
parent eacbce95f4
commit a6b98e5a78
2 changed files with 19 additions and 1 deletions
@@ -18,6 +18,7 @@
#include <cstddef>
#include <cstdint>
#include <cstring>
#include <span>
#include <utility>
#include <filament/Box.h>
@@ -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<const filament::VertexAttribute> Mesh::GetVertexAttributes() const {
return {attributes_.data(), attributes_.data() + num_attributes_};
}
bool Mesh::HasBounds() const {
return bounds_.has_value();
}
+11 -1
View File
@@ -15,10 +15,12 @@
#ifndef MUJOCO_SRC_EXPERIMENTAL_FILAMENT_FILAMENT_MESH_H_
#define MUJOCO_SRC_EXPERIMENTAL_FILAMENT_FILAMENT_MESH_H_
#include <array>
#include <cstddef>
#include <functional>
#include <memory>
#include <optional>
#include <span>
#include <vector>
#include <filament/Box.h>
@@ -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<const filament::VertexAttribute> GetVertexAttributes() const;
// Returns whether the mesh has bounds.
bool HasBounds() const;
@@ -173,6 +181,8 @@ class Mesh {
filament::RenderableManager::PrimitiveType::TRIANGLES;
std::optional<filament::Box> bounds_;
std::vector<std::function<void()>> release_callbacks_;
std::array<filament::VertexAttribute, kMaxVertexAttributes> attributes_;
int num_attributes_ = 0;
};
using MeshPtr = std::unique_ptr<Mesh>;