@@ -14,6 +14,7 @@ import {
1414} from '@angular/core' ;
1515import { ActiveEvents , Collider , ColliderDesc , RigidBody , RigidBodyDesc } from '@dimforge/rapier3d-compat' ;
1616import {
17+ applyProps ,
1718 extend ,
1819 getEmitter ,
1920 getLocalState ,
@@ -47,18 +48,7 @@ const colliderDefaultOptions: NgtrColliderOptions = {
4748 contactSkin : 0 ,
4849} ;
4950
50- @Directive ( {
51- selector : 'ngt-object3D[ngtrCollider]' ,
52- standalone : true ,
53- host : {
54- '[position]' : 'position()' ,
55- '[rotation]' : 'rotation()' ,
56- '[scale]' : 'scale()' ,
57- '[quaternion]' : 'quaternion()' ,
58- '[userData]' : 'userData()' ,
59- '[name]' : 'name()' ,
60- } ,
61- } )
51+ @Directive ( { selector : 'ngt-object3D[ngtrCollider]' , standalone : true } )
6252export class NgtrAnyCollider {
6353 position = input < NgtVector3 | undefined > ( [ 0 , 0 , 0 ] ) ;
6454 rotation = input < NgtEuler | undefined > ( [ 0 , 0 , 0 ] ) ;
@@ -68,6 +58,17 @@ export class NgtrAnyCollider {
6858 name = input < NgtObject3D [ 'name' ] | undefined > ( ) ;
6959 options = input ( colliderDefaultOptions , { transform : mergeInputs ( rigidBodyDefaultOptions ) } ) ;
7060
61+ private object3DParameters = computed ( ( ) => {
62+ return {
63+ position : this . position ( ) ,
64+ rotation : this . rotation ( ) ,
65+ scale : this . scale ( ) ,
66+ quaternion : this . quaternion ( ) ,
67+ userData : this . userData ( ) ,
68+ name : this . name ( ) ,
69+ } ;
70+ } ) ;
71+
7172 // TODO: change this to input required when Angular allows setting hostDirective input
7273 shape = model < NgtrColliderShape | undefined > ( undefined , { alias : 'ngtrCollider' } ) ;
7374 args = model < unknown [ ] > ( [ ] ) ;
@@ -93,7 +94,7 @@ export class NgtrAnyCollider {
9394
9495 private rigidBody = inject ( NgtrRigidBody , { optional : true } ) ;
9596 private physics = inject ( NgtrPhysics ) ;
96- objectRef = inject < ElementRef < Object3D > > ( ElementRef ) ;
97+ private objectRef = inject < ElementRef < Object3D > > ( ElementRef ) ;
9798
9899 private scaledArgs = computed ( ( ) => {
99100 const [ shape , args ] = [
@@ -140,6 +141,11 @@ export class NgtrAnyCollider {
140141 constructor ( ) {
141142 extend ( { Object3D } ) ;
142143
144+ effect ( ( ) => {
145+ const object3DParameters = this . object3DParameters ( ) ;
146+ applyProps ( this . objectRef . nativeElement , object3DParameters ) ;
147+ } ) ;
148+
143149 effect ( ( onCleanup ) => {
144150 const cleanup = this . createColliderStateEffect ( ) ;
145151 onCleanup ( ( ) => cleanup ?.( ) ) ;
@@ -407,13 +413,6 @@ export const rigidBodyDefaultOptions: NgtrRigidBodyOptions = {
407413 ` ,
408414 schemas : [ CUSTOM_ELEMENTS_SCHEMA ] ,
409415 changeDetection : ChangeDetectionStrategy . OnPush ,
410- host : {
411- '[position]' : 'position()' ,
412- '[rotation]' : 'rotation()' ,
413- '[scale]' : 'scale()' ,
414- '[quaternion]' : 'quaternion()' ,
415- '[userData]' : 'userData()' ,
416- } ,
417416 imports : [ NgtrAnyCollider ] ,
418417} )
419418export class NgtrRigidBody {
@@ -431,6 +430,16 @@ export class NgtrRigidBody {
431430 userData = input < NgtObject3D [ 'userData' ] | undefined > ( { } ) ;
432431 options = input ( rigidBodyDefaultOptions , { transform : mergeInputs ( rigidBodyDefaultOptions ) } ) ;
433432
433+ private object3DParameters = computed ( ( ) => {
434+ return {
435+ position : this . position ( ) ,
436+ rotation : this . rotation ( ) ,
437+ scale : this . scale ( ) ,
438+ quaternion : this . quaternion ( ) ,
439+ userData : this . userData ( ) ,
440+ } ;
441+ } ) ;
442+
434443 wake = output < void > ( ) ;
435444 sleep = output < void > ( ) ;
436445 collisionEnter = output < NgtrCollisionEnterPayload > ( ) ;
@@ -496,6 +505,11 @@ export class NgtrRigidBody {
496505 constructor ( ) {
497506 extend ( { Object3D } ) ;
498507
508+ effect ( ( ) => {
509+ const object3DParameters = this . object3DParameters ( ) ;
510+ applyProps ( this . objectRef . nativeElement , object3DParameters ) ;
511+ } ) ;
512+
499513 effect ( ( onCleanup ) => {
500514 const cleanup = this . createRigidBodyStateEffect ( ) ;
501515 onCleanup ( ( ) => cleanup ?.( ) ) ;
0 commit comments