Skip to content

Commit 1362a8b

Browse files
quaglacopybara-github
authored andcommitted
Move BVH active visualization flag reset after early return check in MuJoCo collision driver.
This avoids unnecessarily resetting the bvh_active flags when the collision driver returns early due to disabled constraints, disabled contacts, or having fewer than two bodies/flexes. PiperOrigin-RevId: 959531283 Change-Id: I85caf054b06e3be1018d710f9ab762627fc3356a
1 parent f9a00bd commit 1362a8b

9 files changed

Lines changed: 20 additions & 13 deletions

File tree

‎doc/XMLreference.rst‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9321,10 +9321,10 @@ is effectively a miscellaneous subsection.
93219321

93229322
.. _visual-global-bvactive:
93239323

9324-
:at:`bvactive`: :at-val:`[false, true], "true"`
9324+
:at:`bvactive`: :at-val:`[false, true], "false"`
93259325
This attribute specifies whether collision and raycasting code should mark elements of Bounding Volume Hierarchies
9326-
as intersecting, for the purpose of visualization. Setting this attribute to "false" can speed up simulation for
9327-
models with high-resolution meshes.
9326+
as intersecting, for the purpose of visualization. Setting this attribute to "true" can slow down simulation for
9327+
models with high-resolution meshes, due to the O(N) cost of clearing visualization flags at each step.
93289328

93299329
.. _visual-quality:
93309330

‎doc/changelog.rst‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ Engine
4747
of the effective-metric Cholesky factor, which no longer exists; ``mjData.efm_L`` now holds dense 3x3 blocks,
4848
9 numbers per covered vertex. ``mjData.efm_active`` no longer takes the value 2: nothing selects a solve path on
4949
preconditioner exactness, so it is now a plain 0/1 flag.
50+
- Changed the default value of :ref:`bvactive<visual-global-bvactive>` from "true" to "false". This avoids
51+
unnecessarily clearing bounding volume hierarchy visualization flags at every simulation step, which can be a
52+
bottleneck for models with large meshes.
5053

5154
Models
5255
^^^^^^

‎src/engine/engine_collision_driver.c‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -599,17 +599,17 @@ void mj_collision(const mjModel* m, mjData* d) {
599599
resetArena(d);
600600
mj_clearEfc(d);
601601

602-
// reset the visualization flags
603-
if (m->vis.global.bvactive) {
604-
memset(d->bvh_active, 0, m->nbvh);
605-
}
606-
607602
// return if disabled
608603
if (mjDISABLED(mjDSBL_CONSTRAINT) || mjDISABLED(mjDSBL_CONTACT) || nbodyflex < 2) {
609604
TM_END1(mjTIMER_POS_COLLISION);
610605
return;
611606
}
612607

608+
// reset the visualization flags
609+
if (m->vis.global.bvactive) {
610+
memset(d->bvh_active, 0, m->nbvh);
611+
}
612+
613613
mj_markStack(d);
614614

615615
// broadphase collision detector

‎src/engine/engine_init.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ void mj_defaultVisual(mjVisual* vis) {
144144
vis->global.offheight = 480;
145145
vis->global.realtime = 1.0;
146146
vis->global.ellipsoidinertia = 0;
147-
vis->global.bvactive = 1;
147+
vis->global.bvactive = 0;
148148

149149
// rendering quality
150150
vis->quality.shadowsize = 4096;

‎src/xml/generated/mjcf.xsd‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1193,7 +1193,7 @@
11931193
</xs:simpleType>
11941194
</xs:attribute>
11951195
<xs:attribute name="ellipsoidinertia" type="kw_bool" default="false"/>
1196-
<xs:attribute name="bvactive" type="kw_bool" default="true"/>
1196+
<xs:attribute name="bvactive" type="kw_bool" default="false"/>
11971197
</xs:complexType>
11981198

11991199
<xs:complexType name="quality">

‎src/xml/generated/mjcf_default_table.inc‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ static const mjXDefaultEntry kDefaults_mjVisual_global[] = {
122122
{"offheight", (int)offsetof(mjVisual, global.offheight), 2, 1, 1, 0, {480.0}},
123123
{"realtime", (int)offsetof(mjVisual, global.realtime), 1, 1, 1, 0, {1.0}},
124124
{"ellipsoidinertia", (int)offsetof(mjVisual, global.ellipsoidinertia), 2, 1, 1, 0, {0}},
125-
{"bvactive", (int)offsetof(mjVisual, global.bvactive), 2, 1, 1, 0, {1}},
125+
{"bvactive", (int)offsetof(mjVisual, global.bvactive), 2, 1, 1, 0, {0}},
126126
};
127127

128128
static const mjXDefaultEntry kDefaults_mjVisual_headlight[] = {

‎src/xml/mjcf.schema‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,7 @@ element global : mjVisual (field=global) {
687687
offheight : int = 480
688688
realtime : float = 1 (positive)
689689
ellipsoidinertia : bool = false
690-
bvactive : bool = true
690+
bvactive : bool = false
691691
}
692692

693693
element quality : mjVisual (field=quality) {

‎test/testdata/flex.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<map force="0.1" zfar="30"/>
1515
<rgba haze="0.15 0.25 0.35 1"/>
1616
<quality shadowsize="4096"/>
17-
<global offwidth="800" offheight="800"/>
17+
<global offwidth="800" offheight="800" bvactive="true"/>
1818
</visual>
1919

2020
<worldbody>

‎test/testdata/model.xml‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
<material name="grid" texture="grid" texrepeat="1 1" texuniform="true" reflectance=".2"/>
2727
</asset>
2828

29+
<visual>
30+
<global bvactive="true"/>
31+
</visual>
32+
2933
<default>
3034
<site rgba=".5 .5 .5 .5"/>
3135
<joint armature="1" damping="10"/>

0 commit comments

Comments
 (0)
⌂ 换网址