@@ -99,7 +99,7 @@ const quaternionToRotation = (callback: (v: Triplet) => void) => {
9999
100100let incrementingId = 0 ;
101101
102- export function subscribe < T extends SubscriptionName > (
102+ export function createSubscribe < T extends SubscriptionName > (
103103 ref : ElementRef < THREE . Object3D > ,
104104 worker : CannonWorkerAPI ,
105105 subscriptions : Subscriptions ,
@@ -236,14 +236,17 @@ function injectBody<TBodyProps extends BodyProps, TObject extends THREE.Object3D
236236) : NgtcBodyReturn < TObject > {
237237 injector = assertInjector ( injectBody , injector ) ;
238238 return runInInjectionContext ( injector , ( ) => {
239- const bodyRef = ref || injectNgtRef < TObject > ( ) ;
240-
241- const physicsApi = injectNgtcPhysicsApi ( ) ;
242- const debugApi = injectNgtcDebugApi ( { optional : true } ) ;
243-
244- const { add : debugAdd , remove : debugRemove } = debugApi || { } ;
245- const { refs, subscriptions, scaleOverrides, events, bodies } = physicsApi . get ( ) ;
246- const worker = physicsApi . select ( 'worker' ) ;
239+ const [ bodyRef , physicsApi , debugApi ] = [
240+ ref || injectNgtRef < TObject > ( ) ,
241+ injectNgtcPhysicsApi ( ) ,
242+ injectNgtcDebugApi ( { optional : true } ) ,
243+ ] ;
244+
245+ const [
246+ { add : addToDebug , remove : removeFromDebug } ,
247+ { refs, subscriptions, scaleOverrides, events, bodies } ,
248+ worker ,
249+ ] = [ debugApi || { } , physicsApi . get ( ) , physicsApi . select ( 'worker' ) ] ;
247250
248251 effect ( ( onCleanup ) => {
249252 // register deps
@@ -277,15 +280,15 @@ function injectBody<TBodyProps extends BodyProps, TObject extends THREE.Object3D
277280 object . setMatrixAt ( i , temp . matrix ) ;
278281 object . instanceMatrix . needsUpdate = true ;
279282 refs [ id ] = object ;
280- debugAdd ?.( id , props , type ) ;
283+ addToDebug ?.( id , props , type ) ;
281284 setupCollision ( events , props , id ) ;
282285 return { ...props , args : argsFn ( props . args ) } ;
283286 } )
284287 : uuid . map ( ( id , i ) => {
285288 const props = getPropsFn ( i ) ;
286289 prepare ( object , props ) ;
287290 refs [ id ] = object ;
288- debugAdd ?.( id , props , type ) ;
291+ addToDebug ?.( id , props , type ) ;
289292 setupCollision ( events , props , id ) ;
290293 return { ...props , args : argsFn ( props . args ) } ;
291294 } ) ;
@@ -302,7 +305,7 @@ function injectBody<TBodyProps extends BodyProps, TObject extends THREE.Object3D
302305 onCleanup ( ( ) => {
303306 uuid . forEach ( ( id ) => {
304307 delete refs [ id ] ;
305- debugRemove ?.( id ) ;
308+ removeFromDebug ?.( id ) ;
306309 delete events [ id ] ;
307310 } ) ;
308311 currentWorker . removeBodies ( { uuid } ) ;
@@ -322,7 +325,7 @@ function injectBody<TBodyProps extends BodyProps, TObject extends THREE.Object3D
322325 uuid,
323326 } as never ) ;
324327 } ,
325- subscribe : subscribe ( bodyRef , worker ( ) , subscriptions , type , index ) ,
328+ subscribe : createSubscribe ( bodyRef , worker ( ) , subscriptions , type , index ) ,
326329 } ;
327330 } ;
328331
@@ -337,7 +340,7 @@ function injectBody<TBodyProps extends BodyProps, TObject extends THREE.Object3D
337340 const uuid = getUUID ( bodyRef , index ) ;
338341 uuid && bodies [ uuid ] != null && worker ( ) . setQuaternion ( { props : [ x , y , z , w ] , uuid } ) ;
339342 } ,
340- subscribe : subscribe ( bodyRef , worker ( ) , subscriptions , type , index ) ,
343+ subscribe : createSubscribe ( bodyRef , worker ( ) , subscriptions , type , index ) ,
341344 } ;
342345 } ;
343346
@@ -378,7 +381,7 @@ function injectBody<TBodyProps extends BodyProps, TObject extends THREE.Object3D
378381 const uuid = getUUID ( bodyRef , index ) ;
379382 uuid && bodies [ uuid ] != null && worker ( ) [ op ] ( { props : [ x , y , z ] , uuid } ) ;
380383 } ,
381- subscribe : subscribe ( bodyRef , worker ( ) , subscriptions , type , index ) ,
384+ subscribe : createSubscribe ( bodyRef , worker ( ) , subscriptions , type , index ) ,
382385 } ;
383386 } ;
384387
0 commit comments