@@ -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,28 @@ 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 { other } else { self }
154+ }
155+ }
156+
136157impl PhysicsGizmos {
137158 /// Creates a [`PhysicsGizmos`] configuration with all rendering options enabled.
138159 pub fn all ( ) -> Self {
@@ -154,7 +175,7 @@ impl PhysicsGizmos {
154175 shapecast_point_color : Some ( YELLOW . into ( ) ) ,
155176 shapecast_normal_color : Some ( PINK . into ( ) ) ,
156177 island_color : Some ( RED . into ( ) ) ,
157- hide_meshes : true ,
178+ mesh_visibility : MeshVisibility :: Overwrite ( Visibility :: Hidden ) ,
158179 }
159180 }
160181
@@ -180,7 +201,7 @@ impl PhysicsGizmos {
180201 shapecast_point_color : None ,
181202 shapecast_normal_color : None ,
182203 island_color : None ,
183- hide_meshes : false ,
204+ mesh_visibility : MeshVisibility :: Ignore ,
184205 }
185206 }
186207
@@ -319,8 +340,8 @@ impl PhysicsGizmos {
319340 }
320341
321342 /// 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 ;
343+ pub fn with_mesh_visibility ( mut self , visibility : MeshVisibility ) -> Self {
344+ self . mesh_visibility = visibility ;
324345 self
325346 }
326347
@@ -426,8 +447,8 @@ pub struct DebugRender {
426447 /// If the entity is [sleeping](Sleeping), its colors (in HSLA) will be multiplied by this array.
427448 /// If `None`, sleeping will have no effect on the colors.
428449 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 ,
450+ /// Determines if the entity's visibility should be overwritten .
451+ pub mesh_visibility : MeshVisibility ,
431452}
432453
433454impl Default for DebugRender {
@@ -440,7 +461,7 @@ impl Default for DebugRender {
440461 aabb_color : None ,
441462 collider_color : Some ( ORANGE . into ( ) ) ,
442463 sleeping_color_multiplier : Some ( [ 1.0 , 1.0 , 0.4 , 1.0 ] ) ,
443- hide_mesh : false ,
464+ mesh_visibility : MeshVisibility :: Ignore ,
444465 }
445466 }
446467}
@@ -456,7 +477,7 @@ impl DebugRender {
456477 aabb_color : Some ( Color :: srgb ( 0.8 , 0.8 , 0.8 ) ) ,
457478 collider_color : Some ( ORANGE . into ( ) ) ,
458479 sleeping_color_multiplier : Some ( [ 1.0 , 1.0 , 0.4 , 1.0 ] ) ,
459- hide_mesh : true ,
480+ mesh_visibility : MeshVisibility :: Overwrite ( Visibility :: Hidden ) ,
460481 }
461482 }
462483
@@ -467,7 +488,7 @@ impl DebugRender {
467488 aabb_color : None ,
468489 collider_color : None ,
469490 sleeping_color_multiplier : None ,
470- hide_mesh : false ,
491+ mesh_visibility : MeshVisibility :: Ignore ,
471492 }
472493 }
473494
@@ -523,8 +544,8 @@ impl DebugRender {
523544 }
524545
525546 /// 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 ;
547+ pub fn with_mesh_visibility ( mut self , visibility : MeshVisibility ) -> Self {
548+ self . mesh_visibility = visibility ;
528549 self
529550 }
530551
0 commit comments