Expose several functions in the public C API.

PiperOrigin-RevId: 910629209
Change-Id: I8623309e348c72350703f6874a887592f0607bba
This commit is contained in:
Haroon Qureshi
2026-05-05 05:55:21 -07:00
committed by Copybara-Service
parent 4ed69b5ce7
commit d168eb2d7d
2 changed files with 215 additions and 0 deletions
@@ -18,6 +18,8 @@
#include <cstdint>
#include <cstring>
#include <math/mat3.h>
#include <math/vec3.h>
#include <mujoco/mjmodel.h>
#include <mujoco/mjrender.h>
#include <mujoco/mjvisualize.h>
@@ -193,6 +195,139 @@ void mjrf_destroyRenderTarget(mjrRenderTarget* render_target) {
delete mujoco::RenderTarget::downcast(render_target);
}
void mjrf_setTextureData(mjrTexture* texture, const mjrTextureData* data) {
mujoco::Texture::downcast(texture)->Upload(*data);
}
int mjrf_getTextureWidth(const mjrTexture* texture) {
return mujoco::Texture::downcast(texture)->GetWidth();
}
int mjrf_getTextureHeight(const mjrTexture* texture) {
return mujoco::Texture::downcast(texture)->GetHeight();
}
mjrTextureTarget mjrf_getTextureTarget(const mjrTexture* texture) {
return mujoco::Texture::downcast(texture)->GetTarget();
}
void mjrf_setLightEnabled(mjrLight* light, bool enabled) {
if (enabled) {
mujoco::Light::downcast(light)->Enable();
} else {
mujoco::Light::downcast(light)->Disable();
}
}
void mjrf_setLightIntensity(mjrLight* light, float intensity) {
mujoco::Light::downcast(light)->SetIntensity(intensity);
}
void mjrf_setLightColor(mjrLight* light, const float color[3]) {
mujoco::Light::downcast(light)->SetColor({color[0], color[1], color[2]});
}
void mjrf_setLightTransform(mjrLight* light, const float position[3],
const float direction[3]) {
mujoco::Light::downcast(light)->SetTransform(
{position[0], position[1], position[2]},
{direction[0], direction[1], direction[2]});
}
mjrLightType mjrf_getLightType(const mjrLight* light) {
return mujoco::Light::downcast(light)->GetType();
}
void mjrf_setRenderableMesh(mjrRenderable* renderable, const mjrMesh* mesh,
int elem_offset, int elem_count) {
mujoco::Renderable::downcast(renderable)
->SetMesh(mujoco::Mesh::downcast(mesh), elem_offset, elem_count);
}
void mjrf_setRenderableMaterial(mjrRenderable* renderable,
const mjrMaterialParams* params,
const mjrMaterialTextures* textures) {
mujoco::Renderable::downcast(renderable)->UpdateMaterial(*params, *textures);
}
void mjrf_setRenderableTransform(mjrRenderable* renderable,
const float position[3],
const float rotation[9], const float size[3]) {
const filament::math::float3 fposition{position[0], position[1], position[2]};
const filament::math::float3 fsize{size[0], size[1], size[2]};
const filament::math::mat3f frotation{rotation[0], rotation[1], rotation[2],
rotation[3], rotation[4], rotation[5],
rotation[6], rotation[7], rotation[8]};
mujoco::Renderable::downcast(renderable)
->SetTransform({fposition, frotation, fsize});
}
void mjrf_setRenderableLayerMask(mjrRenderable* renderable,
uint8_t layer_mask) {
mujoco::Renderable::downcast(renderable)->SetLayerMask(layer_mask);
}
void mjrf_setRenderableWireframe(mjrRenderable* renderable, bool wireframe) {
mujoco::Renderable::downcast(renderable)->SetWireframe(wireframe);
}
void mjrf_setRenderableCastShadows(mjrRenderable* renderable,
bool cast_shadows) {
mujoco::Renderable::downcast(renderable)->SetCastShadows(cast_shadows);
}
void mjrf_setRenderableReceiveShadows(mjrRenderable* renderable,
bool receive_shadows) {
mujoco::Renderable::downcast(renderable)->SetReceiveShadows(receive_shadows);
}
void mjrf_addLightToScene(mjrScene* scene, mjrLight* light) {
mujoco::SceneView::downcast(scene)->AddToScene(
mujoco::Light::downcast(light));
}
void mjrf_removeLightFromScene(mjrScene* scene, mjrLight* light) {
mujoco::SceneView::downcast(scene)->RemoveFromScene(
mujoco::Light::downcast(light));
}
void mjrf_addRenderableToScene(mjrScene* scene, mjrRenderable* renderable) {
mujoco::SceneView::downcast(scene)->AddToScene(
mujoco::Renderable::downcast(renderable));
}
void mjrf_removeRenderableFromScene(mjrScene* scene,
mjrRenderable* renderable) {
mujoco::SceneView::downcast(scene)->RemoveFromScene(
mujoco::Renderable::downcast(renderable));
}
void mjrf_setSceneSkybox(mjrScene* scene, const mjrTexture* texture) {
mujoco::SceneView::downcast(scene)->SetSkybox(
mujoco::Texture::downcast(texture));
}
void mjrf_setSceneShadowsEnabled(mjrScene* scene, bool enabled) {
if (enabled) {
mujoco::SceneView::downcast(scene)->EnableShadows();
} else {
mujoco::SceneView::downcast(scene)->DisableShadows();
}
}
void mjrf_setSceneReflectionsEnabled(mjrScene* scene, bool enabled) {
if (enabled) {
mujoco::SceneView::downcast(scene)->EnableReflections();
} else {
mujoco::SceneView::downcast(scene)->DisableReflections();
}
}
void mjrf_configureSceneFromModel(mjrScene* scene, const mjModel* model) {
mujoco::SceneView::downcast(scene)->Configure(model);
}
void mjrf_makeFilamentContext(const mjModel* m, mjrContext* con,
const mjrFilamentConfig* config) {
// TODO: Support multiple contexts and multiple threads. For now, we'll just
@@ -458,6 +458,86 @@ mjrRenderTarget* mjrf_createRenderTarget(mjrfContext* ctx,
// Destroys the render target.
void mjrf_destroyRenderTarget(mjrRenderTarget* render_target);
// Uploads the given texture data to the texture.
void mjrf_setTextureData(mjrTexture* texture, const mjrTextureData* data);
// Returns the width of the texture.
int mjrf_getTextureWidth(const mjrTexture* texture);
// Returns the height of the texture.
int mjrf_getTextureHeight(const mjrTexture* texture);
// Returns the target type of the texture.
mjrTextureTarget mjrf_getTextureTarget(const mjrTexture* texture);
// Enables or disables the light.
void mjrf_setLightEnabled(mjrLight* light, bool enabled);
// Sets the intensity of the light, in candela.
void mjrf_setLightIntensity(mjrLight* light, float intensity);
// Sets the RGB color of the light.
void mjrf_setLightColor(mjrLight* light, const float color[3]);
// Sets the position and direction of the light.
void mjrf_setLightTransform(mjrLight* light, const float position[3],
const float direction[3]);
// Returns the type of the light.
mjrLightType mjrf_getLightType(const mjrLight* light);
// Sets the mesh of the renderable.
void mjrf_setRenderableMesh(mjrRenderable* renderable, const mjrMesh* mesh,
int elem_offset, int elem_count);
// Sets the material properties and textures of the renderable.
void mjrf_setRenderableMaterial(mjrRenderable* renderable,
const mjrMaterialParams* params,
const mjrMaterialTextures* textures);
// Sets the transform (position, rotation, and size) of the renderable.
void mjrf_setRenderableTransform(mjrRenderable* renderable,
const float position[3],
const float rotation[9], const float size[3]);
// Sets whether the renderable casts shadows or not.
void mjrf_setRenderableCastShadows(mjrRenderable* renderable,
bool cast_shadows);
// Sets whether the renderable receives shadows or not.
void mjrf_setRenderableReceiveShadows(mjrRenderable* renderable,
bool receive_shadows);
// Forces the renderable to be rendered using lines.
void mjrf_setRenderableWireframe(mjrRenderable* renderable, bool wireframe);
// Sets the layer mask of the renderable. See mjrRenderableParams for details.
void mjrf_setRenderableLayerMask(mjrRenderable* renderable, uint8_t layer_mask);
// Adds the light to the scene.
void mjrf_addLightToScene(mjrScene* scene, mjrLight* light);
// Removes the light from the scene.
void mjrf_removeLightFromScene(mjrScene* scene, mjrLight* light);
// Adds the renderable to the scene.
void mjrf_addRenderableToScene(mjrScene* scene, mjrRenderable* renderable);
// Removes the renderable from the scene.
void mjrf_removeRenderableFromScene(mjrScene* scene, mjrRenderable* renderable);
// Sets the skybox texture of the scene.
void mjrf_setSceneSkybox(mjrScene* scene, const mjrTexture* texture);
// Enables (or disables) shadows in the scene..
void mjrf_setSceneShadowsEnabled(mjrScene* scene, bool enabled);
// Enables (or disables) reflections in the scene.
void mjrf_setSceneReflectionsEnabled(mjrScene* scene, bool enabled);
// Configures the scene based on the parameters in the model.
void mjrf_configureSceneFromModel(mjrScene* scene, const mjModel* model);
// Legacy API, to be deprecated.
void mjrf_defaultFilamentConfig(mjrFilamentConfig* config);