@@ -83,7 +83,7 @@ function capitalize<T extends string>(str: T): Capitalize<T> {
83
83
return ( str . charAt ( 0 ) . toUpperCase ( ) + str . slice ( 1 ) ) as Capitalize < T > ;
84
84
}
85
85
86
- function getUUID ( ref : ElementRef < THREE . Object3D > , index ?: number ) : string | null {
86
+ export function getUUID ( ref : ElementRef < THREE . Object3D > , index ?: number ) : string | null {
87
87
const suffix = index === undefined ? '' : `/${ index } ` ;
88
88
if ( typeof ref === 'function' ) return null ;
89
89
return ref && ref . nativeElement && `${ ref . nativeElement . uuid } ${ suffix } ` ;
@@ -98,7 +98,7 @@ const quaternionToRotation = (callback: (v: Triplet) => void) => {
98
98
99
99
let incrementingId = 0 ;
100
100
101
- function subscribe < T extends SubscriptionName > (
101
+ export function subscribe < T extends SubscriptionName > (
102
102
ref : ElementRef < THREE . Object3D > ,
103
103
worker : CannonWorkerAPI ,
104
104
subscriptions : Subscriptions ,
@@ -245,66 +245,69 @@ function injectBody<TBodyProps extends BodyProps, TObject extends THREE.Object3D
245
245
const { refs, worker, subscriptions, scaleOverrides, events } = physicsApi ( ) ;
246
246
const { add : debugAdd , remove : debugRemove } = debugApi ?.( ) || { } ;
247
247
248
- effect ( ( onCleanup ) => {
249
- // register deps
250
- deps ( ) ;
251
-
252
- if ( ! bodyRef . untracked ) {
253
- bodyRef . nativeElement = new THREE . Object3D ( ) as TObject ;
254
- }
248
+ effect (
249
+ ( onCleanup ) => {
250
+ // register deps
251
+ deps ( ) ;
252
+
253
+ if ( ! bodyRef . untracked ) {
254
+ bodyRef . nativeElement = new THREE . Object3D ( ) as TObject ;
255
+ }
256
+
257
+ const object = bodyRef . untracked ;
258
+ const currentWorker = worker ;
259
+
260
+ const objectCount =
261
+ object instanceof THREE . InstancedMesh
262
+ ? ( object . instanceMatrix . setUsage ( THREE . DynamicDrawUsage ) , object . count )
263
+ : 1 ;
264
+
265
+ const uuid =
266
+ object instanceof THREE . InstancedMesh
267
+ ? new Array ( objectCount ) . fill ( 0 ) . map ( ( _ , i ) => `${ object . uuid } /${ i } ` )
268
+ : [ object . uuid ] ;
269
+
270
+ const props : ( TBodyProps & { args : unknown } ) [ ] =
271
+ object instanceof THREE . InstancedMesh
272
+ ? uuid . map ( ( id , i ) => {
273
+ const props = getPropsFn ( i ) ;
274
+ prepare ( temp , props ) ;
275
+ object . setMatrixAt ( i , temp . matrix ) ;
276
+ object . instanceMatrix . needsUpdate = true ;
277
+ refs [ id ] = object ;
278
+ debugAdd ?.( id , props , type ) ;
279
+ setupCollision ( events , props , id ) ;
280
+ return { ...props , args : argsFn ( props . args ) } ;
281
+ } )
282
+ : uuid . map ( ( id , i ) => {
283
+ const props = getPropsFn ( i ) ;
284
+ prepare ( object , props ) ;
285
+ refs [ id ] = object ;
286
+ debugAdd ?.( id , props , type ) ;
287
+ setupCollision ( events , props , id ) ;
288
+ return { ...props , args : argsFn ( props . args ) } ;
289
+ } ) ;
290
+
291
+ // Register on mount, unregister on unmount
292
+ currentWorker . addBodies ( {
293
+ props : props . map ( ( { onCollide, onCollideBegin, onCollideEnd, ...serializableProps } ) => {
294
+ return { onCollide : Boolean ( onCollide ) , ...serializableProps } ;
295
+ } ) ,
296
+ type,
297
+ uuid,
298
+ } ) ;
255
299
256
- const object = bodyRef . untracked ;
257
- const currentWorker = worker ;
258
-
259
- const objectCount =
260
- object instanceof THREE . InstancedMesh
261
- ? ( object . instanceMatrix . setUsage ( THREE . DynamicDrawUsage ) , object . count )
262
- : 1 ;
263
-
264
- const uuid =
265
- object instanceof THREE . InstancedMesh
266
- ? new Array ( objectCount ) . fill ( 0 ) . map ( ( _ , i ) => `${ object . uuid } /${ i } ` )
267
- : [ object . uuid ] ;
268
-
269
- const props : ( TBodyProps & { args : unknown } ) [ ] =
270
- object instanceof THREE . InstancedMesh
271
- ? uuid . map ( ( id , i ) => {
272
- const props = getPropsFn ( i ) ;
273
- prepare ( temp , props ) ;
274
- object . setMatrixAt ( i , temp . matrix ) ;
275
- object . instanceMatrix . needsUpdate = true ;
276
- refs [ id ] = object ;
277
- debugAdd ?.( id , props , type ) ;
278
- setupCollision ( events , props , id ) ;
279
- return { ...props , args : argsFn ( props . args ) } ;
280
- } )
281
- : uuid . map ( ( id , i ) => {
282
- const props = getPropsFn ( i ) ;
283
- prepare ( object , props ) ;
284
- refs [ id ] = object ;
285
- debugAdd ?.( id , props , type ) ;
286
- setupCollision ( events , props , id ) ;
287
- return { ...props , args : argsFn ( props . args ) } ;
288
- } ) ;
289
-
290
- // Register on mount, unregister on unmount
291
- currentWorker . addBodies ( {
292
- props : props . map ( ( { onCollide, onCollideBegin, onCollideEnd, ...serializableProps } ) => {
293
- return { onCollide : Boolean ( onCollide ) , ...serializableProps } ;
294
- } ) ,
295
- type,
296
- uuid,
297
- } ) ;
298
-
299
- onCleanup ( ( ) => {
300
- uuid . forEach ( ( id ) => {
301
- delete refs [ id ] ;
302
- debugRemove ?.( id ) ;
303
- delete events [ id ] ;
300
+ onCleanup ( ( ) => {
301
+ uuid . forEach ( ( id ) => {
302
+ delete refs [ id ] ;
303
+ debugRemove ?.( id ) ;
304
+ delete events [ id ] ;
305
+ } ) ;
306
+ currentWorker . removeBodies ( { uuid } ) ;
304
307
} ) ;
305
- currentWorker . removeBodies ( { uuid } ) ;
306
- } ) ;
307
- } ) ;
308
+ } ,
309
+ { allowSignalWrites : true }
310
+ ) ;
308
311
309
312
const api = computed ( ( ) => {
310
313
const makeAtomic = < T extends AtomicName > ( type : T , index ?: number ) => {
0 commit comments