diff --git a/doc/XMLreference.rst b/doc/XMLreference.rst index c5c53c1f..63bf1952 100644 --- a/doc/XMLreference.rst +++ b/doc/XMLreference.rst @@ -9321,10 +9321,10 @@ is effectively a miscellaneous subsection. .. _visual-global-bvactive: -:at:`bvactive`: :at-val:`[false, true], "true"` +:at:`bvactive`: :at-val:`[false, true], "false"` This attribute specifies whether collision and raycasting code should mark elements of Bounding Volume Hierarchies - as intersecting, for the purpose of visualization. Setting this attribute to "false" can speed up simulation for - models with high-resolution meshes. + as intersecting, for the purpose of visualization. Setting this attribute to "true" can slow down simulation for + models with high-resolution meshes, due to the O(N) cost of clearing visualization flags at each step. .. _visual-quality: diff --git a/doc/changelog.rst b/doc/changelog.rst index b27170e2..b426be22 100644 --- a/doc/changelog.rst +++ b/doc/changelog.rst @@ -47,6 +47,9 @@ Engine of the effective-metric Cholesky factor, which no longer exists; ``mjData.efm_L`` now holds dense 3x3 blocks, 9 numbers per covered vertex. ``mjData.efm_active`` no longer takes the value 2: nothing selects a solve path on preconditioner exactness, so it is now a plain 0/1 flag. + - Changed the default value of :ref:`bvactive` from "true" to "false". This avoids + unnecessarily clearing bounding volume hierarchy visualization flags at every simulation step, which can be a + bottleneck for models with large meshes. Models ^^^^^^ diff --git a/src/engine/engine_collision_driver.c b/src/engine/engine_collision_driver.c index 3345a2e7..99541354 100644 --- a/src/engine/engine_collision_driver.c +++ b/src/engine/engine_collision_driver.c @@ -599,17 +599,17 @@ void mj_collision(const mjModel* m, mjData* d) { resetArena(d); mj_clearEfc(d); - // reset the visualization flags - if (m->vis.global.bvactive) { - memset(d->bvh_active, 0, m->nbvh); - } - // return if disabled if (mjDISABLED(mjDSBL_CONSTRAINT) || mjDISABLED(mjDSBL_CONTACT) || nbodyflex < 2) { TM_END1(mjTIMER_POS_COLLISION); return; } + // reset the visualization flags + if (m->vis.global.bvactive) { + memset(d->bvh_active, 0, m->nbvh); + } + mj_markStack(d); // broadphase collision detector diff --git a/src/engine/engine_init.c b/src/engine/engine_init.c index 2232473b..c910c260 100644 --- a/src/engine/engine_init.c +++ b/src/engine/engine_init.c @@ -144,7 +144,7 @@ void mj_defaultVisual(mjVisual* vis) { vis->global.offheight = 480; vis->global.realtime = 1.0; vis->global.ellipsoidinertia = 0; - vis->global.bvactive = 1; + vis->global.bvactive = 0; // rendering quality vis->quality.shadowsize = 4096; diff --git a/src/xml/generated/mjcf.xsd b/src/xml/generated/mjcf.xsd index 61c1ab66..fc094bff 100644 --- a/src/xml/generated/mjcf.xsd +++ b/src/xml/generated/mjcf.xsd @@ -1193,7 +1193,7 @@ - + diff --git a/src/xml/generated/mjcf_default_table.inc b/src/xml/generated/mjcf_default_table.inc index 2d737ae9..592cdb36 100644 --- a/src/xml/generated/mjcf_default_table.inc +++ b/src/xml/generated/mjcf_default_table.inc @@ -122,7 +122,7 @@ static const mjXDefaultEntry kDefaults_mjVisual_global[] = { {"offheight", (int)offsetof(mjVisual, global.offheight), 2, 1, 1, 0, {480.0}}, {"realtime", (int)offsetof(mjVisual, global.realtime), 1, 1, 1, 0, {1.0}}, {"ellipsoidinertia", (int)offsetof(mjVisual, global.ellipsoidinertia), 2, 1, 1, 0, {0}}, - {"bvactive", (int)offsetof(mjVisual, global.bvactive), 2, 1, 1, 0, {1}}, + {"bvactive", (int)offsetof(mjVisual, global.bvactive), 2, 1, 1, 0, {0}}, }; static const mjXDefaultEntry kDefaults_mjVisual_headlight[] = { diff --git a/src/xml/mjcf.schema b/src/xml/mjcf.schema index 3848cd74..0454625b 100644 --- a/src/xml/mjcf.schema +++ b/src/xml/mjcf.schema @@ -687,7 +687,7 @@ element global : mjVisual (field=global) { offheight : int = 480 realtime : float = 1 (positive) ellipsoidinertia : bool = false - bvactive : bool = true + bvactive : bool = false } element quality : mjVisual (field=quality) { diff --git a/test/testdata/flex.xml b/test/testdata/flex.xml index 07c08b6d..b8e9b287 100644 --- a/test/testdata/flex.xml +++ b/test/testdata/flex.xml @@ -14,7 +14,7 @@ - + diff --git a/test/testdata/model.xml b/test/testdata/model.xml index 595eaae4..0e59f1e4 100644 --- a/test/testdata/model.xml +++ b/test/testdata/model.xml @@ -26,6 +26,10 @@ + + + +