@@ -98,6 +98,11 @@ pub struct Transform {
9898 ///
9999 /// [`scale`]: https://github.com/bevyengine/bevy/blob/latest/examples/transforms/scale.rs
100100 pub scale : Vec3 ,
101+ /// Whether the model forward direction is flipped from -z to +z.
102+ ///
103+ /// glTF specifies that models have a forward direction of +z whereas cameras and lights have -z.
104+ /// This option allows the glTF importer and other usages to make appropriate adjustments.
105+ pub flip_model_forward : bool ,
101106}
102107
103108impl Transform {
@@ -106,6 +111,7 @@ impl Transform {
106111 translation : Vec3 :: ZERO ,
107112 rotation : Quat :: IDENTITY ,
108113 scale : Vec3 :: ONE ,
114+ flip_model_forward : false ,
109115 } ;
110116
111117 /// Creates a new [`Transform`] at the position `(x, y, z)`. In 2d, the `z` component
@@ -126,6 +132,7 @@ impl Transform {
126132 translation,
127133 rotation,
128134 scale,
135+ flip_model_forward : false ,
129136 }
130137 }
131138
@@ -317,16 +324,44 @@ impl Transform {
317324
318325 /// Equivalent to [`-local_z()`][Transform::local_z]
319326 #[ inline]
320- pub fn forward ( & self ) -> Dir3 {
327+ pub fn camera_forward ( & self ) -> Dir3 {
321328 -self . local_z ( )
322329 }
323330
324331 /// Equivalent to [`local_z()`][Transform::local_z]
325332 #[ inline]
326- pub fn back ( & self ) -> Dir3 {
333+ pub fn camera_back ( & self ) -> Dir3 {
327334 self . local_z ( )
328335 }
329336
337+ /// Equivalent to [`-local_z()`][Transform::local_z] if `flip_model_forward` is false,
338+ /// else [`local_z()`][Transform::local_z]
339+ ///
340+ /// glTF has opposing forward directions for cameras and lights, and for models. Model
341+ /// forward is +z, whereas camera and light forward is -z.
342+ #[ inline]
343+ pub fn model_forward ( & self ) -> Dir3 {
344+ if self . flip_model_forward {
345+ self . local_z ( )
346+ } else {
347+ -self . local_z ( )
348+ }
349+ }
350+
351+ /// Equivalent to [`local_z()`][Transform::local_z] if `flip_model_forward` is false,
352+ /// else [`-local_z()`][Transform::local_z]
353+ ///
354+ /// glTF has opposing forward directions for cameras and lights, and for models. Model
355+ /// forward is +z, whereas camera and light forward is -z. Back is the opposite of this.
356+ #[ inline]
357+ pub fn model_back ( & self ) -> Dir3 {
358+ if self . flip_model_forward {
359+ -self . local_z ( )
360+ } else {
361+ self . local_z ( )
362+ }
363+ }
364+
330365 /// Rotates this [`Transform`] by the given rotation.
331366 ///
332367 /// If this [`Transform`] has a parent, the `rotation` is relative to the rotation of the parent.
@@ -469,7 +504,11 @@ impl Transform {
469504 /// * if `direction` is parallel with `up`, an orthogonal vector is used as the "right" direction
470505 #[ inline]
471506 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 ) ;
507+ let back = if self . flip_model_forward {
508+ direction. try_into ( ) . unwrap_or ( Dir3 :: NEG_Z )
509+ } else {
510+ -direction. try_into ( ) . unwrap_or ( Dir3 :: NEG_Z )
511+ } ;
473512 let up = up. try_into ( ) . unwrap_or ( Dir3 :: Y ) ;
474513 let right = up
475514 . cross ( back. into ( ) )
@@ -572,6 +611,7 @@ impl Transform {
572611 translation,
573612 rotation,
574613 scale,
614+ flip_model_forward : self . flip_model_forward ,
575615 }
576616 }
577617
0 commit comments