@@ -85,9 +85,8 @@ pub struct PhysicsGizmos {
8585 pub shapecast_normal_color : Option < Color > ,
8686 /// The color used for the bounds of [`PhysicsIsland`](dynamics::solver::islands::PhysicsIsland)s.
8787 pub island_color : Option < Color > ,
88- /// Determines if the visibility of entities with [colliders](Collider) should be set to `Visibility::Hidden`,
89- /// which will only show the debug renders.
90- pub hide_meshes : bool ,
88+ /// Determines if the visibility of entities with [colliders](Collider).
89+ pub mesh_visibility : MeshVisibility ,
9190}
9291
9392impl Default for PhysicsGizmos {
@@ -110,7 +109,7 @@ impl Default for PhysicsGizmos {
110109 shapecast_point_color : Some ( YELLOW . into ( ) ) ,
111110 shapecast_normal_color : Some ( PINK . into ( ) ) ,
112111 island_color : None ,
113- hide_meshes : false ,
112+ mesh_visibility : MeshVisibility :: Ignore ,
114113 }
115114 }
116115}
@@ -133,6 +132,32 @@ impl Default for ContactGizmoScale {
133132 }
134133}
135134
135+ /// Determines if the visibility of entities with [colliders](Collider) should
136+ /// be overwritten. Setting this to `MeshVisibility::Overwrite(Visibility::Hidden)`,
137+ /// will only show the debug renders.
138+ #[ derive( Reflect , Clone , Copy , PartialEq , Default ) ]
139+ #[ cfg_attr( feature = "serialize" , derive( serde:: Serialize , serde:: Deserialize ) ) ]
140+ #[ cfg_attr( feature = "serialize" , reflect( Serialize , Deserialize ) ) ]
141+ #[ reflect( PartialEq ) ]
142+ pub enum MeshVisibility {
143+ /// Do not change the visibility of the entity's mesh.
144+ #[ default]
145+ Ignore ,
146+ /// Always overwrite the visibility of the entity's mesh.
147+ Overwrite ( Visibility ) ,
148+ }
149+
150+ impl MeshVisibility {
151+ /// Returns the first non-ignore visibility.
152+ pub fn or ( self , other : Self ) -> Self {
153+ if self == Self :: Ignore {
154+ other
155+ } else {
156+ self
157+ }
158+ }
159+ }
160+
136161impl PhysicsGizmos {
137162 /// Creates a [`PhysicsGizmos`] configuration with all rendering options enabled.
138163 pub fn all ( ) -> Self {
@@ -154,7 +179,7 @@ impl PhysicsGizmos {
154179 shapecast_point_color : Some ( YELLOW . into ( ) ) ,
155180 shapecast_normal_color : Some ( PINK . into ( ) ) ,
156181 island_color : Some ( RED . into ( ) ) ,
157- hide_meshes : true ,
182+ mesh_visibility : MeshVisibility :: Overwrite ( Visibility :: Hidden ) ,
158183 }
159184 }
160185
@@ -180,7 +205,7 @@ impl PhysicsGizmos {
180205 shapecast_point_color : None ,
181206 shapecast_normal_color : None ,
182207 island_color : None ,
183- hide_meshes : false ,
208+ mesh_visibility : MeshVisibility :: Ignore ,
184209 }
185210 }
186211
@@ -319,8 +344,8 @@ impl PhysicsGizmos {
319344 }
320345
321346 /// Sets the visibility of the entity's visual mesh.
322- pub fn with_mesh_visibility ( mut self , is_visible : bool ) -> Self {
323- self . hide_meshes = !is_visible ;
347+ pub fn with_mesh_visibility ( mut self , visibility : MeshVisibility ) -> Self {
348+ self . mesh_visibility = visibility ;
324349 self
325350 }
326351
@@ -426,8 +451,8 @@ pub struct DebugRender {
426451 /// If the entity is [sleeping](Sleeping), its colors (in HSLA) will be multiplied by this array.
427452 /// If `None`, sleeping will have no effect on the colors.
428453 pub sleeping_color_multiplier : Option < [ f32 ; 4 ] > ,
429- /// Determines if the entity's visibility should be set to `Visibility::Hidden`, which will only show the debug render .
430- pub hide_mesh : bool ,
454+ /// Determines if the entity's visibility should be overwritten .
455+ pub mesh_visibility : MeshVisibility ,
431456}
432457
433458impl Default for DebugRender {
@@ -440,7 +465,7 @@ impl Default for DebugRender {
440465 aabb_color : None ,
441466 collider_color : Some ( ORANGE . into ( ) ) ,
442467 sleeping_color_multiplier : Some ( [ 1.0 , 1.0 , 0.4 , 1.0 ] ) ,
443- hide_mesh : false ,
468+ mesh_visibility : MeshVisibility :: Ignore ,
444469 }
445470 }
446471}
@@ -456,7 +481,7 @@ impl DebugRender {
456481 aabb_color : Some ( Color :: srgb ( 0.8 , 0.8 , 0.8 ) ) ,
457482 collider_color : Some ( ORANGE . into ( ) ) ,
458483 sleeping_color_multiplier : Some ( [ 1.0 , 1.0 , 0.4 , 1.0 ] ) ,
459- hide_mesh : true ,
484+ mesh_visibility : MeshVisibility :: Overwrite ( Visibility :: Hidden ) ,
460485 }
461486 }
462487
@@ -467,7 +492,7 @@ impl DebugRender {
467492 aabb_color : None ,
468493 collider_color : None ,
469494 sleeping_color_multiplier : None ,
470- hide_mesh : false ,
495+ mesh_visibility : MeshVisibility :: Ignore ,
471496 }
472497 }
473498
@@ -523,8 +548,8 @@ impl DebugRender {
523548 }
524549
525550 /// Sets the visibility of the entity's visual mesh.
526- pub fn with_mesh_visibility ( mut self , is_visible : bool ) -> Self {
527- self . hide_mesh = !is_visible ;
551+ pub fn with_mesh_visibility ( mut self , visibility : MeshVisibility ) -> Self {
552+ self . mesh_visibility = visibility ;
528553 self
529554 }
530555
0 commit comments