@@ -98,6 +98,7 @@ pub struct Transform {
9898 ///
9999 /// [`scale`]: https://github.com/bevyengine/bevy/blob/latest/examples/transforms/scale.rs
100100 pub scale : Vec3 ,
101+ pub flip_model_forward : bool ,
101102}
102103
103104impl Transform {
@@ -106,6 +107,7 @@ impl Transform {
106107 translation : Vec3 :: ZERO ,
107108 rotation : Quat :: IDENTITY ,
108109 scale : Vec3 :: ONE ,
110+ flip_model_forward : false ,
109111 } ;
110112
111113 /// Creates a new [`Transform`] at the position `(x, y, z)`. In 2d, the `z` component
@@ -126,6 +128,7 @@ impl Transform {
126128 translation,
127129 rotation,
128130 scale,
131+ flip_model_forward : false ,
129132 }
130133 }
131134
@@ -317,16 +320,44 @@ impl Transform {
317320
318321 /// Equivalent to [`-local_z()`][Transform::local_z]
319322 #[ inline]
320- pub fn forward ( & self ) -> Dir3 {
323+ pub fn camera_forward ( & self ) -> Dir3 {
321324 -self . local_z ( )
322325 }
323326
324327 /// Equivalent to [`local_z()`][Transform::local_z]
325328 #[ inline]
326- pub fn back ( & self ) -> Dir3 {
329+ pub fn camera_back ( & self ) -> Dir3 {
327330 self . local_z ( )
328331 }
329332
333+ /// Equivalent to [`-local_z()`][Transform::local_z] if `flip_model_forward` is false,
334+ /// else [`local_z()`][Transform::local_z]
335+ ///
336+ /// glTF has opposing forward directions for cameras and lights, and for models. Model
337+ /// forward is +z, whereas camera and light forward is -z.
338+ #[ inline]
339+ pub fn model_forward ( & self ) -> Dir3 {
340+ if self . flip_model_forward {
341+ self . local_z ( )
342+ } else {
343+ -self . local_z ( )
344+ }
345+ }
346+
347+ /// Equivalent to [`local_z()`][Transform::local_z] if `flip_model_forward` is false,
348+ /// else [`-local_z()`][Transform::local_z]
349+ ///
350+ /// glTF has opposing forward directions for cameras and lights, and for models. Model
351+ /// forward is +z, whereas camera and light forward is -z. Back is the opposite of this.
352+ #[ inline]
353+ pub fn model_back ( & self ) -> Dir3 {
354+ if self . flip_model_forward {
355+ -self . local_z ( )
356+ } else {
357+ self . local_z ( )
358+ }
359+ }
360+
330361 /// Rotates this [`Transform`] by the given rotation.
331362 ///
332363 /// If this [`Transform`] has a parent, the `rotation` is relative to the rotation of the parent.
@@ -469,7 +500,11 @@ impl Transform {
469500 /// * if `direction` is parallel with `up`, an orthogonal vector is used as the "right" direction
470501 #[ inline]
471502 pub fn look_to ( & mut self , direction : impl TryInto < Dir3 > , up : impl TryInto < Dir3 > ) {
472- let back = -direction. try_into ( ) . unwrap_or ( Dir3 :: NEG_Z ) ;
503+ let back = if self . flip_model_forward {
504+ direction. try_into ( ) . unwrap_or ( Dir3 :: NEG_Z )
505+ } else {
506+ -direction. try_into ( ) . unwrap_or ( Dir3 :: NEG_Z )
507+ } ;
473508 let up = up. try_into ( ) . unwrap_or ( Dir3 :: Y ) ;
474509 let right = up
475510 . cross ( back. into ( ) )
@@ -572,6 +607,7 @@ impl Transform {
572607 translation,
573608 rotation,
574609 scale,
610+ flip_model_forward : self . flip_model_forward ,
575611 }
576612 }
577613
0 commit comments