@@ -53,21 +53,35 @@ const colliderDefaultOptions: NgtrColliderOptions = {
5353@Directive ( { selector : 'ngt-object3D[collider]' } )
5454export class NgtrAnyCollider {
5555 position = input < NgtVector3 | undefined > ( [ 0 , 0 , 0 ] ) ;
56- rotation = input < NgtEuler | undefined > ( [ 0 , 0 , 0 ] ) ;
56+ rotation = input < NgtEuler | undefined > ( ) ;
5757 scale = input < NgtVector3 | undefined > ( [ 1 , 1 , 1 ] ) ;
58- quaternion = input < NgtQuaternion | undefined > ( [ 0 , 0 , 0 , 1 ] ) ;
58+ quaternion = input < NgtQuaternion | undefined > ( ) ;
5959 userData = input < NgtThreeElements [ 'ngt-object3D' ] [ 'userData' ] | undefined > ( undefined ) ;
6060 name = input < NgtThreeElements [ 'ngt-object3D' ] [ 'name' ] | undefined > ( undefined ) ;
6161 options = input ( colliderDefaultOptions , { transform : mergeInputs ( rigidBodyDefaultOptions ) } ) ;
6262
63- private object3DParameters = computed ( ( ) => ( {
64- position : this . position ( ) ,
65- rotation : this . rotation ( ) ,
66- scale : this . scale ( ) ,
67- quaternion : this . quaternion ( ) ,
68- userData : this . userData ( ) ,
69- name : this . name ( ) ,
70- } ) ) ;
63+ private object3DParameters = computed ( ( ) => {
64+ const [ position , rotation , scale , quaternion , userData , name ] = [
65+ this . position ( ) ,
66+ this . rotation ( ) ,
67+ this . scale ( ) ,
68+ this . quaternion ( ) ,
69+ this . userData ( ) ,
70+ this . name ( ) ,
71+ ] ;
72+
73+ const parameters = { position, scale, userData, name } ;
74+
75+ if ( quaternion ) {
76+ Object . assign ( parameters , { quaternion } ) ;
77+ } else if ( rotation ) {
78+ Object . assign ( parameters , { rotation } ) ;
79+ } else {
80+ Object . assign ( parameters , { rotation : [ 0 , 0 , 0 ] } ) ;
81+ }
82+
83+ return parameters ;
84+ } ) ;
7185
7286 // TODO: change this to input required when Angular allows setting hostDirective input
7387 shape = model < NgtrColliderShape | undefined > ( undefined , { alias : 'collider' } ) ;
@@ -429,13 +443,27 @@ export class NgtrRigidBody {
429443 userData = input < NgtThreeElements [ 'ngt-object3D' ] [ 'userData' ] | undefined > ( undefined ) ;
430444 options = input ( rigidBodyDefaultOptions , { transform : mergeInputs ( rigidBodyDefaultOptions ) } ) ;
431445
432- private object3DParameters = computed ( ( ) => ( {
433- position : this . position ( ) ,
434- rotation : this . rotation ( ) ,
435- scale : this . scale ( ) ,
436- quaternion : this . quaternion ( ) ,
437- userData : this . userData ( ) ,
438- } ) ) ;
446+ private object3DParameters = computed ( ( ) => {
447+ const [ position , rotation , scale , quaternion , userData ] = [
448+ this . position ( ) ,
449+ this . rotation ( ) ,
450+ this . scale ( ) ,
451+ this . quaternion ( ) ,
452+ this . userData ( ) ,
453+ ] ;
454+
455+ const parameters = { position, scale, userData } ;
456+
457+ if ( quaternion ) {
458+ Object . assign ( parameters , { quaternion } ) ;
459+ } else if ( rotation ) {
460+ Object . assign ( parameters , { rotation } ) ;
461+ } else {
462+ Object . assign ( parameters , { rotation : [ 0 , 0 , 0 ] } ) ;
463+ }
464+
465+ return parameters ;
466+ } ) ;
439467
440468 wake = output < void > ( ) ;
441469 sleep = output < void > ( ) ;
0 commit comments