Use num_ prefix consistently in API.

PiperOrigin-RevId: 932391786
Change-Id: I71c7f300fdb84ce1129ea3da6336df2fcffc5712
This commit is contained in:
Haroon Qureshi
2026-06-15 05:07:58 -07:00
committed by Copybara-Service
parent 7c22920720
commit 9e45ce9801
9 changed files with 37 additions and 37 deletions
@@ -125,8 +125,8 @@ static void UpdateSkinFlexMeshData(mjrfMeshData* data, const mjModel* model,
data->attributes[2].usage = mjVERTEX_ATTRIBUTE_USAGE_UV; data->attributes[2].usage = mjVERTEX_ATTRIBUTE_USAGE_UV;
data->attributes[2].type = mjVERTEX_ATTRIBUTE_TYPE_FLOAT2; data->attributes[2].type = mjVERTEX_ATTRIBUTE_TYPE_FLOAT2;
data->attributes[2].bytes = uvs.data(); data->attributes[2].bytes = uvs.data();
data->nvertices = positions.size() / 3; data->num_vertices = positions.size() / 3;
data->nindices = num_indices; data->num_indices = num_indices;
data->indices = indices.data(); data->indices = indices.data();
data->index_type = mjINDEX_TYPE_U32; data->index_type = mjINDEX_TYPE_U32;
data->primitive_type = mjMESH_PRIMITIVE_TYPE_TRIANGLES; data->primitive_type = mjMESH_PRIMITIVE_TYPE_TRIANGLES;
+4 -4
View File
@@ -99,7 +99,7 @@ uintptr_t ImguiBridge::UploadImage(uintptr_t tex_id, const uint8_t* pixels,
mjrfTextureData texture_data; mjrfTextureData texture_data;
mjrf_defaultTextureData(&texture_data); mjrf_defaultTextureData(&texture_data);
texture_data.bytes = bytes; texture_data.bytes = bytes;
texture_data.nbytes = num_bytes; texture_data.num_bytes = num_bytes;
texture_data.user_data = bytes; texture_data.user_data = bytes;
texture_data.release = callback; texture_data.release = callback;
@@ -136,7 +136,7 @@ void ImguiBridge::UpdateTexture(ImTextureData* data) {
mjrfTextureData texture_data; mjrfTextureData texture_data;
mjrf_defaultTextureData(&texture_data); mjrf_defaultTextureData(&texture_data);
texture_data.bytes = data->GetPixels(); texture_data.bytes = data->GetPixels();
texture_data.nbytes = data->Width * data->Height * 4; texture_data.num_bytes = data->Width * data->Height * 4;
texture_data.user_data = nullptr; texture_data.user_data = nullptr;
texture_data.release = nullptr; texture_data.release = nullptr;
mjrf_setTextureData(iter->second.get(), &texture_data); mjrf_setTextureData(iter->second.get(), &texture_data);
@@ -232,8 +232,8 @@ void ImguiBridge::Update() {
data.attributes[2].type = mjVERTEX_ATTRIBUTE_TYPE_UBYTE4; data.attributes[2].type = mjVERTEX_ATTRIBUTE_TYPE_UBYTE4;
data.attributes[2].bytes = cmds->VtxBuffer.Data + sizeof(float) * 4; data.attributes[2].bytes = cmds->VtxBuffer.Data + sizeof(float) * 4;
data.interleaved = true; data.interleaved = true;
data.nvertices = cmds->VtxBuffer.Size; data.num_vertices = cmds->VtxBuffer.Size;
data.nindices = cmds->IdxBuffer.Size; data.num_indices = cmds->IdxBuffer.Size;
data.indices = cmds->IdxBuffer.Data; data.indices = cmds->IdxBuffer.Data;
data.index_type = mjINDEX_TYPE_U16; data.index_type = mjINDEX_TYPE_U16;
data.primitive_type = mjMESH_PRIMITIVE_TYPE_TRIANGLES; data.primitive_type = mjMESH_PRIMITIVE_TYPE_TRIANGLES;
+2 -2
View File
@@ -85,10 +85,10 @@ class BuiltinBuilder : public mjrfMeshData {
attributes[1].usage = mjVERTEX_ATTRIBUTE_USAGE_TANGENTS; attributes[1].usage = mjVERTEX_ATTRIBUTE_USAGE_TANGENTS;
attributes[1].type = mjVERTEX_ATTRIBUTE_TYPE_FLOAT4; attributes[1].type = mjVERTEX_ATTRIBUTE_TYPE_FLOAT4;
attributes[1].bytes = reinterpret_cast<const void*>(orientations_.data()); attributes[1].bytes = reinterpret_cast<const void*>(orientations_.data());
nvertices = positions_.size(); num_vertices = positions_.size();
indices = indices_.data(); indices = indices_.data();
nindices = indices_.size(); num_indices = indices_.size();
index_type = mjINDEX_TYPE_U16; index_type = mjINDEX_TYPE_U16;
return this; return this;
} }
+14 -14
View File
@@ -130,7 +130,7 @@ Mesh::~Mesh() {
} }
void Mesh::BuildVertexBuffer(const mjrfMeshData& data) { void Mesh::BuildVertexBuffer(const mjrfMeshData& data) {
if (data.nvertices == 0) { if (data.num_vertices == 0) {
mju_error("mjrfMeshData has no vertices."); mju_error("mjrfMeshData has no vertices.");
} }
@@ -182,7 +182,7 @@ void Mesh::BuildVertexBuffer(const mjrfMeshData& data) {
// Build the vertex buffer. // Build the vertex buffer.
filament::VertexBuffer::Builder vb_builder; filament::VertexBuffer::Builder vb_builder;
vb_builder.vertexCount(data.nvertices); vb_builder.vertexCount(data.num_vertices);
if (data.interleaved) { if (data.interleaved) {
// For an interleaved vertex buffer, we will create a single buffer which // For an interleaved vertex buffer, we will create a single buffer which
@@ -194,7 +194,7 @@ void Mesh::BuildVertexBuffer(const mjrfMeshData& data) {
total_vertex_size += VertexAttributeTypeSize(data.attributes[i]); total_vertex_size += VertexAttributeTypeSize(data.attributes[i]);
} }
const void* bytes = data.attributes[0].bytes; const void* bytes = data.attributes[0].bytes;
const size_t nbytes = data.nvertices * total_vertex_size; const size_t nbytes = data.num_vertices * total_vertex_size;
// We assume the buffer is tightly packed with no padding between // We assume the buffer is tightly packed with no padding between
// attributes. As such, the stride is equal to the total vertex size and // attributes. As such, the stride is equal to the total vertex size and
@@ -240,11 +240,11 @@ void Mesh::BuildVertexBuffer(const mjrfMeshData& data) {
for (int i = 0; i < data.nattributes; ++i) { for (int i = 0; i < data.nattributes; ++i) {
const mjrVertexAttribute& attrib = data.attributes[i]; const mjrVertexAttribute& attrib = data.attributes[i];
const void* bytes = attrib.bytes; const void* bytes = attrib.bytes;
size_t nbytes = data.nvertices * VertexAttributeTypeSize(attrib); size_t nbytes = data.num_vertices * VertexAttributeTypeSize(attrib);
if (attrib.usage == mjVERTEX_ATTRIBUTE_USAGE_NORMAL) { if (attrib.usage == mjVERTEX_ATTRIBUTE_USAGE_NORMAL) {
// Replace normals with orientations. // Replace normals with orientations.
nbytes = data.nvertices * sizeof(float4); nbytes = data.num_vertices * sizeof(float4);
bytes = BuildOrientationsFromNormals(data.nvertices, attrib); bytes = BuildOrientationsFromNormals(data.num_vertices, attrib);
} }
auto* user_data = new std::shared_ptr<SharedState>(shared_state_); auto* user_data = new std::shared_ptr<SharedState>(shared_state_);
vertex_buffer_->setBufferAt(*engine_, i, vertex_buffer_->setBufferAt(*engine_, i,
@@ -254,15 +254,15 @@ void Mesh::BuildVertexBuffer(const mjrfMeshData& data) {
} }
void Mesh::BuildIndexBuffer(const mjrfMeshData& data) { void Mesh::BuildIndexBuffer(const mjrfMeshData& data) {
if (data.nindices == 0) { if (data.num_indices == 0) {
return; return;
} }
const int element_size = const int element_size =
data.index_type == mjINDEX_TYPE_U16 ? sizeof(uint16_t) : sizeof(uint32_t); data.index_type == mjINDEX_TYPE_U16 ? sizeof(uint16_t) : sizeof(uint32_t);
const int num_bytes = data.nindices * element_size; const int num_bytes = data.num_indices * element_size;
// If indices == 0 and nindices > 0, then the user is specifying that the // If indices == 0 and num_indices > 0, then the user is specifying that the
// vertices are provided "in order", i.e. the indices are 0, 1, 2, 3, ... // vertices are provided "in order", i.e. the indices are 0, 1, 2, 3, ...
// In this case, we need to create the sequence of indices explicitly. // In this case, we need to create the sequence of indices explicitly.
const void* indices = data.indices; const void* indices = data.indices;
@@ -279,7 +279,7 @@ void Mesh::BuildIndexBuffer(const mjrfMeshData& data) {
} }
filament::IndexBuffer::Builder ib_builder; filament::IndexBuffer::Builder ib_builder;
ib_builder.indexCount(data.nindices); ib_builder.indexCount(data.num_indices);
ib_builder.bufferType(data.index_type == mjINDEX_TYPE_U16 ib_builder.bufferType(data.index_type == mjINDEX_TYPE_U16
? filament::IndexBuffer::IndexType::USHORT ? filament::IndexBuffer::IndexType::USHORT
: filament::IndexBuffer::IndexType::UINT); : filament::IndexBuffer::IndexType::UINT);
@@ -290,12 +290,12 @@ void Mesh::BuildIndexBuffer(const mjrfMeshData& data) {
index_buffer_->setBuffer(*engine_, std::move(desc)); index_buffer_->setBuffer(*engine_, std::move(desc));
} }
float4* Mesh::BuildOrientationsFromNormals(int nvertices, float4* Mesh::BuildOrientationsFromNormals(int num_vertices,
const mjrVertexAttribute& normals) { const mjrVertexAttribute& normals) {
float4* orientations = new float4[nvertices]; float4* orientations = new float4[num_vertices];
shared_state_->callbacks.push_back([=]() { delete[] orientations; }); shared_state_->callbacks.push_back([=]() { delete[] orientations; });
const float* normals_ptr = reinterpret_cast<const float*>(normals.bytes); const float* normals_ptr = reinterpret_cast<const float*>(normals.bytes);
for (int i = 0; i < nvertices; ++i) { for (int i = 0; i < num_vertices; ++i) {
orientations[i] = CalculateOrientation(ReadFloat3(normals_ptr, i)); orientations[i] = CalculateOrientation(ReadFloat3(normals_ptr, i));
} }
return orientations; return orientations;
@@ -316,7 +316,7 @@ void Mesh::UpdateBounds(const mjrfMeshData& data) {
const float* positions = const float* positions =
reinterpret_cast<const float*>(data.attributes[0].bytes); reinterpret_cast<const float*>(data.attributes[0].bytes);
for (int i = 0; i < data.nvertices; ++i) { for (int i = 0; i < data.num_vertices; ++i) {
const float3 position = ReadFloat3(positions, i); const float3 position = ReadFloat3(positions, i);
bounds_min = min(bounds_min, position); bounds_min = min(bounds_min, position);
bounds_max = max(bounds_max, position); bounds_max = max(bounds_max, position);
+1 -1
View File
@@ -71,7 +71,7 @@ class Mesh : public mjrfMesh {
void UpdateBounds(const mjrfMeshData& data); void UpdateBounds(const mjrfMeshData& data);
filament::math::float4* BuildOrientationsFromNormals( filament::math::float4* BuildOrientationsFromNormals(
int nvertices, const mjrVertexAttribute& normals); int num_vertices, const mjrVertexAttribute& normals);
void ReleaseResources(); void ReleaseResources();
+6 -6
View File
@@ -165,14 +165,14 @@ void Texture::Upload(const mjrfTextureData& data) {
user_data_ = data.user_data; user_data_ = data.user_data;
release_callback_ = data.release; release_callback_ = data.release;
if (data.bytes == nullptr || data.nbytes == 0) { if (data.bytes == nullptr || data.num_bytes == 0) {
ReleaseData(); ReleaseData();
return; return;
} }
if (config_.format == mjPIXEL_FORMAT_KTX) { if (config_.format == mjPIXEL_FORMAT_KTX) {
image::Ktx1Bundle* bundle = new image::Ktx1Bundle( image::Ktx1Bundle* bundle = new image::Ktx1Bundle(
reinterpret_cast<const uint8_t*>(data.bytes), data.nbytes); reinterpret_cast<const uint8_t*>(data.bytes), data.num_bytes);
has_spherical_harmonics_ = true; has_spherical_harmonics_ = true;
bundle->getSphericalHarmonics(spherical_harmonics_); bundle->getSphericalHarmonics(spherical_harmonics_);
const bool is_srgb = false; const bool is_srgb = false;
@@ -188,14 +188,14 @@ void Texture::Upload(const mjrfTextureData& data) {
const filament::Texture::Format format = GetTextureFormat(config_); const filament::Texture::Format format = GetTextureFormat(config_);
if (!IsCubeMap(config_)) { if (!IsCubeMap(config_)) {
if (config_.width * config_.height * num_channels != data.nbytes) { if (config_.width * config_.height * num_channels != data.num_bytes) {
mju_error("Texture size does not match data size."); mju_error("Texture size does not match data size.");
} }
auto callback = +[](void* buffer, size_t size, void* user) { auto callback = +[](void* buffer, size_t size, void* user) {
reinterpret_cast<Texture*>(user)->ReleaseData(); reinterpret_cast<Texture*>(user)->ReleaseData();
}; };
filament::Texture::PixelBufferDescriptor desc(data.bytes, data.nbytes, filament::Texture::PixelBufferDescriptor desc(data.bytes, data.num_bytes,
format, type, callback, this); format, type, callback, this);
texture_->setImage(*engine_, 0, std::move(desc)); texture_->setImage(*engine_, 0, std::move(desc));
} else { } else {
@@ -217,14 +217,14 @@ void Texture::Upload(const mjrfTextureData& data) {
/*depth=*/6, std::move(desc)); /*depth=*/6, std::move(desc));
ReleaseData(); ReleaseData();
} else { } else {
if (num_bytes != data.nbytes) { if (num_bytes != data.num_bytes) {
mju_error("Texture size does not match data size."); mju_error("Texture size does not match data size.");
} }
auto callback = +[](void* buffer, size_t size, void* user) { auto callback = +[](void* buffer, size_t size, void* user) {
reinterpret_cast<Texture*>(user)->ReleaseData(); reinterpret_cast<Texture*>(user)->ReleaseData();
}; };
filament::Texture::PixelBufferDescriptor desc( filament::Texture::PixelBufferDescriptor desc(
data.bytes, data.nbytes, format, type, callback, this); data.bytes, data.num_bytes, format, type, callback, this);
texture_->setImage(*engine_, /*level=*/0, /*xoffset=*/0, /*yoffset=*/0, texture_->setImage(*engine_, /*level=*/0, /*xoffset=*/0, /*yoffset=*/0,
/*zoffset=*/0, config_.width, GetFaceHeight(config_), /*zoffset=*/0, config_.width, GetFaceHeight(config_),
/*depth=*/6, std::move(desc)); /*depth=*/6, std::move(desc));
+3 -3
View File
@@ -200,7 +200,7 @@ void mjrf_destroyTexture(mjrfTexture* texture);
struct mjrfTextureData { // binary data for a texture (mjrfTexture) struct mjrfTextureData { // binary data for a texture (mjrfTexture)
const void* bytes; // pointer to image data, or nullptr for empty texture const void* bytes; // pointer to image data, or nullptr for empty texture
mjtSize nbytes; // number of bytes in the image data mjtSize num_bytes; // number of bytes in the image data
mjrfCallback release; // callback when data has finished uploading mjrfCallback release; // callback when data has finished uploading
void* user_data; // user data for release callback void* user_data; // user data for release callback
}; };
@@ -246,11 +246,11 @@ int mjrf_getSamplerType(const mjrfTexture* texture);
enum { mjMAX_VERTEX_ATTRIBUTES = 16 }; enum { mjMAX_VERTEX_ATTRIBUTES = 16 };
struct mjrfMeshData { // binary data for a mesh (mjrfMesh) struct mjrfMeshData { // binary data for a mesh (mjrfMesh)
mjtSize nvertices; // number of vertices; all vertex attributes share this size mjtSize num_vertices; // number of vertices; all vertex attributes share this size
int nattributes; // number of attributes defined int nattributes; // number of attributes defined
mjrVertexAttribute attributes[mjMAX_VERTEX_ATTRIBUTES]; // per-vertex attribute information mjrVertexAttribute attributes[mjMAX_VERTEX_ATTRIBUTES]; // per-vertex attribute information
mjtBool interleaved; // true if vertex attributes are interleaved mjtBool interleaved; // true if vertex attributes are interleaved
mjtSize nindices; // number of indices mjtSize num_indices; // number of indices
const void* indices; // indices data array const void* indices; // indices data array
int index_type; // mjrIndexType; (e.g. UINT16 or UINT32) int index_type; // mjrIndexType; (e.g. UINT16 or UINT32)
int primitive_type; // mjrMeshPrimitiveType; (e.g. TRIANGLES, etc.) int primitive_type; // mjrMeshPrimitiveType; (e.g. TRIANGLES, etc.)
+1 -1
View File
@@ -62,7 +62,7 @@ static UniquePtr<mjrfTexture> CreateFallbackIndirectLightTexture(
mjrfTextureData payload; mjrfTextureData payload;
mjrf_defaultTextureData(&payload); mjrf_defaultTextureData(&payload);
payload.bytes = bytes; payload.bytes = bytes;
payload.nbytes = nbytes; payload.num_bytes = nbytes;
payload.release = +[](void* user_data) { payload.release = +[](void* user_data) {
mju_closeResource((mjResource*)user_data); mju_closeResource((mjResource*)user_data);
}; };
+4 -4
View File
@@ -358,10 +358,10 @@ static void UpdateMeshData(mjrfMeshData* data, const mjModel* model, int id,
} }
data->primitive_type = mjMESH_PRIMITIVE_TYPE_TRIANGLES; data->primitive_type = mjMESH_PRIMITIVE_TYPE_TRIANGLES;
data->nvertices = num_vertices; data->num_vertices = num_vertices;
data->nindices = data->nvertices; data->num_indices = data->num_vertices;
data->indices = nullptr; data->indices = nullptr;
data->index_type = data->nvertices >= std::numeric_limits<uint16_t>::max() data->index_type = data->num_vertices >= std::numeric_limits<uint16_t>::max()
? mjINDEX_TYPE_U32 ? mjINDEX_TYPE_U32
: mjINDEX_TYPE_U16; : mjINDEX_TYPE_U16;
data->nattributes = has_uvs ? 3 : 2; data->nattributes = has_uvs ? 3 : 2;
@@ -463,7 +463,7 @@ void ModelObjects::UploadTexture(const mjModel* model, int id) {
mjrfTextureData payload; mjrfTextureData payload;
mjrf_defaultTextureData(&payload); mjrf_defaultTextureData(&payload);
payload.bytes = model->tex_data + model->tex_adr[id]; payload.bytes = model->tex_data + model->tex_adr[id];
payload.nbytes = payload.num_bytes =
model->tex_width[id] * model->tex_height[id] * model->tex_nchannel[id]; model->tex_width[id] * model->tex_height[id] * model->tex_nchannel[id];
// We assume that the model has the same lifetime as the engine. // We assume that the model has the same lifetime as the engine.
payload.user_data = nullptr; payload.user_data = nullptr;