Adds rendering of ball and free joints actuators using an inflated joint geometry.

PiperOrigin-RevId: 453939612
Change-Id: I621f91d242b2974e6ae6acf239cdcb10efcb2629
This commit is contained in:
Alessio Quaglino
2022-06-09 09:09:22 -07:00
committed by Copybara-Service
parent e050f36b5a
commit 6ead14614f
2 changed files with 65 additions and 34 deletions
+36 -34
View File
@@ -835,48 +835,50 @@ void mjv_addGeoms(const mjModel* m, mjData* d, const mjvOption* vopt,
int j = m->actuator_trnid[2*i]; int j = m->actuator_trnid[2*i];
// slide and hinge joint actuators // slide and hinge joint actuators
if ((m->actuator_trntype[i]==mjTRN_JOINT || m->actuator_trntype[i]==mjTRN_JOINTINPARENT) && if (m->actuator_trntype[i]==mjTRN_JOINT ||
(m->jnt_type[j]==mjJNT_HINGE || m->jnt_type[j]==mjJNT_SLIDE)) { m->actuator_trntype[i]==mjTRN_JOINTINPARENT ||
// set length(1) and width(0) of the connectors m->actuator_trntype[i]==mjTRN_SITE) {
sz[1] = m->vis.scale.actuatorlength * scl;
sz[0] = m->vis.scale.actuatorwidth * scl;
START START
// make geom // site actuators
mjv_makeConnector(thisgeom, if (m->actuator_trntype[i]==mjTRN_SITE) {
m->jnt_type[j]==mjJNT_SLIDE ? mjGEOM_ARROW : mjGEOM_ARROW1, sz[0], // set size of the geometry
d->xanchor[3*j+0], mju_scl3(sz, m->site_size+3*j, 1.1);
d->xanchor[3*j+1],
d->xanchor[3*j+2],
d->xanchor[3*j+0] + sz[1]*d->xaxis[3*j+0],
d->xanchor[3*j+1] + sz[1]*d->xaxis[3*j+1],
d->xanchor[3*j+2] + sz[1]*d->xaxis[3*j+2]);
// set interpolated color // make geom
f2f(thisgeom->rgba, rgba, 4); mjv_initGeom(thisgeom,
m->site_type[j], sz,
d->site_xpos + 3*j,
d->site_xmat + 9*j,
thisgeom->rgba);
} else if (m->jnt_type[j]==mjJNT_HINGE || m->jnt_type[j]==mjJNT_SLIDE) {
// set length(1) and width(0) of the connectors
sz[1] = m->vis.scale.actuatorlength * scl;
sz[0] = m->vis.scale.actuatorwidth * scl;
// vopt->label // make geom
if (vopt->label==mjLABEL_ACTUATOR) { mjv_makeConnector(thisgeom,
makeLabel(m, mjOBJ_ACTUATOR, i, thisgeom->label); m->jnt_type[j]==mjJNT_SLIDE ? mjGEOM_ARROW : mjGEOM_ARROW1, sz[0],
d->xanchor[3*j+0],
d->xanchor[3*j+1],
d->xanchor[3*j+2],
d->xanchor[3*j+0] + sz[1]*d->xaxis[3*j+0],
d->xanchor[3*j+1] + sz[1]*d->xaxis[3*j+1],
d->xanchor[3*j+2] + sz[1]*d->xaxis[3*j+2]);
} }
FINISH // ball or free joint
} else if (m->jnt_type[j]==mjJNT_BALL || m->jnt_type[j]==mjJNT_FREE) {
sz[0] = sz[1] = sz[2] = m->vis.scale.jointlength * scl * 0.33;
// site actuators // make geom
if (m->actuator_trntype[i]==mjTRN_SITE) { mjv_initGeom(thisgeom,
// actuator size is site size scaled by 1.1 m->jnt_type[j]==mjJNT_BALL ? mjGEOM_SPHERE : mjGEOM_BOX, sz,
mju_scl3(sz, m->site_size+3*j, 1.1); d->xanchor + 3*j,
d->xmat + 9*m->jnt_bodyid[j],
START thisgeom->rgba);
}
// make geom overlapping the actuated site
mjv_initGeom(thisgeom,
m->site_type[j], sz,
d->site_xpos + 3*j,
d->site_xmat + 9*j,
thisgeom->rgba);
// set interpolated color // set interpolated color
f2f(thisgeom->rgba, rgba, 4); f2f(thisgeom->rgba, rgba, 4);
+29
View File
@@ -0,0 +1,29 @@
<!-- This file is a playground for understanding different rotations.
Currently, two examples are given:
- A rotation in the xy plane about a ball joint located in the corner of a box.
- A rotation in the xy plane about a free joing located in the center of a box.
-->
<mujoco>
<option density="1000">
<flag gravity="disable"/>
</option>
<worldbody>
<geom type="plane" size="10 10 .1" rgba="1 1 1 1"/>
<light pos="0 0 20"/>
<body name="body_ball" pos="0 0 .5">
<geom type="box" size=".5 .5 .1" pos="0 0 0"/>
<joint name="ball" pos=".5 .5 0" axis="0 0 1" type="ball"/>
</body>
<body name="body_free" pos="3 0 .5">
<freejoint name="free"/>
<geom type="box" size=".5 .5 .1" pos="0 0 0"/>
</body>
</worldbody>
<actuator>
<general name="ball" joint="ball" dyntype="integrator" gear="0 0 1" ctrllimited="true" ctrlrange="-100 100"/>
<general name="free" joint="free" dyntype="integrator" gear="0 0 0 0 0 1" ctrllimited="true" ctrlrange="-100 100"/>
</actuator>
</mujoco>