From fe18e58ad2a7dcc59929a64d712f5cb55af3b9d3 Mon Sep 17 00:00:00 2001 From: Yuval Tassa Date: Tue, 14 Mar 2023 08:16:56 -0700 Subject: [PATCH] Rendering of `mjGEOM_LINE` respects size[0] (width argument of `mjv_makeconnector`), denominated in pixels. - Before this change, line width was hardcoded to 3 pixels and the width argument of mjv_makeConnector was ignored. - After this change, the width argument is respected and interpreted in units of pixel. The non-standard width unit is ok since lines can only be drawn programmatically. PiperOrigin-RevId: 516529265 Change-Id: I27bffabba69cde415d2ada67263a887c9240efbf --- doc/APIreference/functions.rst | 1 + include/mujoco/mujoco.h | 1 + introspect/functions.py | 2 +- src/engine/engine_vis_visualize.c | 3 +-- src/render/render_gl3.c | 2 +- 5 files changed, 5 insertions(+), 4 deletions(-) diff --git a/doc/APIreference/functions.rst b/doc/APIreference/functions.rst index 4b0e4bc2..de3e67cf 100644 --- a/doc/APIreference/functions.rst +++ b/doc/APIreference/functions.rst @@ -1436,6 +1436,7 @@ mjv_makeConnector Set (type, size, pos, mat) for connector-type geom between given points. Assume that mjv_initGeom was already called to set all other properties. +Width of mjGEOM_LINE is denominated in pixels. .. _mjv_defaultScene: diff --git a/include/mujoco/mujoco.h b/include/mujoco/mujoco.h index 9716fa4b..c1d18ec2 100644 --- a/include/mujoco/mujoco.h +++ b/include/mujoco/mujoco.h @@ -587,6 +587,7 @@ MJAPI void mjv_initGeom(mjvGeom* geom, int type, const mjtNum size[3], // Set (type, size, pos, mat) for connector-type geom between given points. // Assume that mjv_initGeom was already called to set all other properties. +// Width of mjGEOM_LINE is denominated in pixels. MJAPI void mjv_makeConnector(mjvGeom* geom, int type, mjtNum width, mjtNum a0, mjtNum a1, mjtNum a2, mjtNum b0, mjtNum b1, mjtNum b2); diff --git a/introspect/functions.py b/introspect/functions.py index 508944cf..764cc07e 100644 --- a/introspect/functions.py +++ b/introspect/functions.py @@ -3630,7 +3630,7 @@ FUNCTIONS: Mapping[str, FunctionDecl] = dict([ type=ValueType(name='mjtNum'), ), ), - doc='Set (type, size, pos, mat) for connector-type geom between given points. Assume that mjv_initGeom was already called to set all other properties.', # pylint: disable=line-too-long + doc='Set (type, size, pos, mat) for connector-type geom between given points. Assume that mjv_initGeom was already called to set all other properties. Width of mjGEOM_LINE is denominated in pixels.', # pylint: disable=line-too-long )), ('mjv_defaultScene', FunctionDecl( diff --git a/src/engine/engine_vis_visualize.c b/src/engine/engine_vis_visualize.c index e079b0e8..fe18487e 100644 --- a/src/engine/engine_vis_visualize.c +++ b/src/engine/engine_vis_visualize.c @@ -14,7 +14,6 @@ #include "engine/engine_vis_visualize.h" -#include #include #include @@ -1591,7 +1590,7 @@ void mjv_addGeoms(const mjModel* m, mjData* d, const mjvOption* vopt, // make ray START - mjv_makeConnector(thisgeom, mjGEOM_LINE, .01, + mjv_makeConnector(thisgeom, mjGEOM_LINE, 3, d->site_xpos[3*sid], d->site_xpos[3*sid+1], d->site_xpos[3*sid+2], diff --git a/src/render/render_gl3.c b/src/render/render_gl3.c index a51dbc06..405de274 100644 --- a/src/render/render_gl3.c +++ b/src/render/render_gl3.c @@ -390,7 +390,7 @@ static void renderGeom(const mjvGeom* geom, int mode, const float* headpos, break; case mjGEOM_LINE: // line - glLineWidth(3*con->lineWidth); + glLineWidth(size[0]*con->lineWidth); lighting = glIsEnabled(GL_LIGHTING); glDisable(GL_LIGHTING); glBegin(GL_LINES);