@@ -53,21 +53,35 @@ const colliderDefaultOptions: NgtrColliderOptions = {
53
53
@Directive ( { selector : 'ngt-object3D[collider]' } )
54
54
export class NgtrAnyCollider {
55
55
position = input < NgtVector3 | undefined > ( [ 0 , 0 , 0 ] ) ;
56
- rotation = input < NgtEuler | undefined > ( [ 0 , 0 , 0 ] ) ;
56
+ rotation = input < NgtEuler | undefined > ( ) ;
57
57
scale = input < NgtVector3 | undefined > ( [ 1 , 1 , 1 ] ) ;
58
- quaternion = input < NgtQuaternion | undefined > ( [ 0 , 0 , 0 , 1 ] ) ;
58
+ quaternion = input < NgtQuaternion | undefined > ( ) ;
59
59
userData = input < NgtThreeElements [ 'ngt-object3D' ] [ 'userData' ] | undefined > ( undefined ) ;
60
60
name = input < NgtThreeElements [ 'ngt-object3D' ] [ 'name' ] | undefined > ( undefined ) ;
61
61
options = input ( colliderDefaultOptions , { transform : mergeInputs ( rigidBodyDefaultOptions ) } ) ;
62
62
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
+ } ) ;
71
85
72
86
// TODO: change this to input required when Angular allows setting hostDirective input
73
87
shape = model < NgtrColliderShape | undefined > ( undefined , { alias : 'collider' } ) ;
@@ -429,13 +443,27 @@ export class NgtrRigidBody {
429
443
userData = input < NgtThreeElements [ 'ngt-object3D' ] [ 'userData' ] | undefined > ( undefined ) ;
430
444
options = input ( rigidBodyDefaultOptions , { transform : mergeInputs ( rigidBodyDefaultOptions ) } ) ;
431
445
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
+ } ) ;
439
467
440
468
wake = output < void > ( ) ;
441
469
sleep = output < void > ( ) ;
0 commit comments