@@ -98,6 +98,7 @@ pub struct Transform {
98
98
///
99
99
/// [`scale`]: https://github.com/bevyengine/bevy/blob/latest/examples/transforms/scale.rs
100
100
pub scale : Vec3 ,
101
+ pub flip_model_forward : bool ,
101
102
}
102
103
103
104
impl Transform {
@@ -106,6 +107,7 @@ impl Transform {
106
107
translation : Vec3 :: ZERO ,
107
108
rotation : Quat :: IDENTITY ,
108
109
scale : Vec3 :: ONE ,
110
+ flip_model_forward : false ,
109
111
} ;
110
112
111
113
/// Creates a new [`Transform`] at the position `(x, y, z)`. In 2d, the `z` component
@@ -126,6 +128,7 @@ impl Transform {
126
128
translation,
127
129
rotation,
128
130
scale,
131
+ flip_model_forward : false ,
129
132
}
130
133
}
131
134
@@ -317,16 +320,44 @@ impl Transform {
317
320
318
321
/// Equivalent to [`-local_z()`][Transform::local_z]
319
322
#[ inline]
320
- pub fn forward ( & self ) -> Dir3 {
323
+ pub fn camera_forward ( & self ) -> Dir3 {
321
324
-self . local_z ( )
322
325
}
323
326
324
327
/// Equivalent to [`local_z()`][Transform::local_z]
325
328
#[ inline]
326
- pub fn back ( & self ) -> Dir3 {
329
+ pub fn camera_back ( & self ) -> Dir3 {
327
330
self . local_z ( )
328
331
}
329
332
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
+
330
361
/// Rotates this [`Transform`] by the given rotation.
331
362
///
332
363
/// If this [`Transform`] has a parent, the `rotation` is relative to the rotation of the parent.
@@ -469,7 +500,11 @@ impl Transform {
469
500
/// * if `direction` is parallel with `up`, an orthogonal vector is used as the "right" direction
470
501
#[ inline]
471
502
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
+ } ;
473
508
let up = up. try_into ( ) . unwrap_or ( Dir3 :: Y ) ;
474
509
let right = up
475
510
. cross ( back. into ( ) )
@@ -572,6 +607,7 @@ impl Transform {
572
607
translation,
573
608
rotation,
574
609
scale,
610
+ flip_model_forward : self . flip_model_forward ,
575
611
}
576
612
}
577
613
0 commit comments