Skip to content

Commit 5b1f717

Browse files
Chau TranChau Tran
Chau Tran
authored and
Chau Tran
committed
feat(cannon): migrate contact material
1 parent 5c425de commit 5b1f717

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { Injector, effect, inject, runInInjectionContext, untracked } from '@angular/core';
2+
import { ContactMaterialOptions, MaterialOptions } from '@pmndrs/cannon-worker-api';
3+
import { NgtAnyRecord, assertInjectionContext, makeId } from 'angular-three';
4+
import { NGTC_PHYSICS_API } from 'angular-three-cannon';
5+
6+
export function injectContactMaterial(
7+
materialB: MaterialOptions,
8+
materialA: MaterialOptions,
9+
{
10+
opts,
11+
deps = () => ({}),
12+
injector,
13+
}: { opts: () => ContactMaterialOptions; deps?: () => NgtAnyRecord; injector?: Injector }
14+
): void {
15+
injector = assertInjectionContext(injectContactMaterial, injector);
16+
return runInInjectionContext(injector, () => {
17+
const physicsApi = inject(NGTC_PHYSICS_API);
18+
const { worker } = physicsApi();
19+
const uuid = makeId();
20+
effect((onCleanup) => {
21+
deps();
22+
worker.addContactMaterial({
23+
props: [materialA, materialB, untracked(opts)],
24+
uuid,
25+
});
26+
onCleanup(() => worker.removeContactMaterial({ uuid }));
27+
});
28+
});
29+
}

libs/cannon/services/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export * from './body';
22
export * from './constraint';
3+
export * from './contact-material';
34
export * from './ray';
45
export * from './raycast-vehicle';
56
export * from './spring';

0 commit comments

Comments
 (0)