Skip to content

Commit 8d3573f

Browse files
committed
wip
1 parent 59f0dda commit 8d3573f

File tree

58 files changed

+302
-421
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+302
-421
lines changed

libs/cannon/debug/src/lib/debug.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import { Component, CUSTOM_ELEMENTS_SCHEMA, forwardRef, Input, type OnInit } from '@angular/core';
1+
import { Component, CUSTOM_ELEMENTS_SCHEMA, Input, type OnInit } from '@angular/core';
22
import { propsToBody, type BodyProps, type BodyShapeType } from '@pmndrs/cannon-worker-api';
3-
import { injectBeforeRender, NgtArgs } from 'angular-three';
3+
import { createApiToken, injectBeforeRender, NgtArgs } from 'angular-three';
44
import { injectNgtcPhysicsApi } from 'angular-three-cannon';
55
import type { Body, Quaternion as CQuarternion, Vec3, World } from 'cannon-es';
66
import CannonDebugger from 'cannon-es-debugger';
7-
import { createInjectionToken } from 'ngxtension/create-injection-token';
87
import * as THREE from 'three';
98

109
const q = new THREE.Quaternion();
@@ -20,10 +19,7 @@ function getMatrix(o: THREE.Object3D): THREE.Matrix4 {
2019
return o.matrix;
2120
}
2221

23-
export const [injectNgtcDebugApi, provideNgtcDebugApi] = createInjectionToken((debug: NgtcDebug) => debug.api, {
24-
isRoot: false,
25-
deps: [forwardRef(() => NgtcDebug)],
26-
});
22+
export const [injectNgtcDebugApi, provideNgtcDebugApi] = createApiToken(() => NgtcDebug);
2723

2824
@Component({
2925
selector: 'ngtc-debug',

libs/cannon/services/src/lib/body.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { effect, runInInjectionContext, type ElementRef, type Injector } from '@angular/core';
1+
import { effect, type ElementRef, type Injector } from '@angular/core';
22
import type {
33
AtomicName,
44
AtomicProps,
@@ -19,8 +19,8 @@ import type {
1919
SphereArgs,
2020
SphereProps,
2121
SubscriptionName,
22-
SubscriptionTarget,
2322
Subscriptions,
23+
SubscriptionTarget,
2424
TrimeshProps,
2525
Triplet,
2626
VectorName,
@@ -234,8 +234,7 @@ function injectBody<TBodyProps extends BodyProps, TObject extends THREE.Object3D
234234
argsFn: NgtcArgFn<TBodyProps['args']>,
235235
{ ref, injector, deps = () => ({}) }: NgtcBodyOptions<TObject> = {},
236236
): NgtcBodyReturn<TObject> {
237-
injector = assertInjector(injectBody, injector);
238-
return runInInjectionContext(injector, () => {
237+
return assertInjector(injectBody, injector, () => {
239238
const [bodyRef, physicsApi, debugApi] = [
240239
ref || injectNgtRef<TObject>(),
241240
injectNgtcPhysicsApi(),

libs/cannon/services/src/lib/constraints.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { effect, runInInjectionContext, untracked, type Injector } from '@angular/core';
1+
import { effect, untracked, type Injector } from '@angular/core';
22
import type {
33
ConstraintOptns,
44
ConstraintTypes,
@@ -97,8 +97,7 @@ function injectConstraint<
9797
opts = () => ({}) as TOptions,
9898
}: NgtcConstraintOptions<TConstraintType, TOptions> = {},
9999
): NgtcConstraintReturn<TConstraintType, A, B> {
100-
injector = assertInjector(injectConstraint, injector);
101-
return runInInjectionContext(injector, () => {
100+
return assertInjector(injectConstraint, injector, () => {
102101
const physicsApi = injectNgtcPhysicsApi();
103102
const worker = physicsApi.select('worker');
104103

@@ -109,9 +108,10 @@ function injectConstraint<
109108

110109
effect((onCleanup) => {
111110
deps();
112-
if (bodyARef.nativeElement && bodyBRef.nativeElement) {
111+
const [a, b] = [bodyARef.nativeElement, bodyBRef.nativeElement];
112+
if (a && b) {
113113
worker().addConstraint({
114-
props: [bodyARef.untracked.uuid, bodyBRef.untracked.uuid, untracked(opts)],
114+
props: [a.uuid, b.uuid, untracked(opts)],
115115
type,
116116
uuid,
117117
});

libs/cannon/services/src/lib/contact-material.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { effect, runInInjectionContext, untracked, type Injector } from '@angular/core';
1+
import { effect, untracked, type Injector } from '@angular/core';
22
import type { ContactMaterialOptions, MaterialOptions } from '@pmndrs/cannon-worker-api';
33
import { makeId, type NgtAnyRecord } from 'angular-three';
44
import { injectNgtcPhysicsApi } from 'angular-three-cannon';
@@ -13,8 +13,7 @@ export function injectContactMaterial(
1313
injector,
1414
}: { opts: () => ContactMaterialOptions; deps?: () => NgtAnyRecord; injector?: Injector },
1515
): void {
16-
injector = assertInjector(injectContactMaterial, injector);
17-
return runInInjectionContext(injector, () => {
16+
return assertInjector(injectContactMaterial, injector, () => {
1817
const physicsApi = injectNgtcPhysicsApi();
1918
const worker = physicsApi.select('worker');
2019
const uuid = makeId();

libs/cannon/services/src/lib/ray.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { effect, runInInjectionContext, untracked, type Injector } from '@angular/core';
1+
import { effect, untracked, type Injector } from '@angular/core';
22
import type { RayMode, RayOptions, RayhitEvent } from '@pmndrs/cannon-worker-api';
33
import { makeId, type NgtAnyRecord } from 'angular-three';
44
import { injectNgtcPhysicsApi } from 'angular-three-cannon';
@@ -24,8 +24,7 @@ export function useRaycastAll(opts: NgtcRayOptions) {
2424
}
2525

2626
function injectRay(mode: RayMode, { options, callback, deps = () => ({}), injector }: NgtcRayOptions) {
27-
injector = assertInjector(injectRay, injector);
28-
return runInInjectionContext(injector, () => {
27+
return assertInjector(injectRay, injector, () => {
2928
const physicsApi = injectNgtcPhysicsApi();
3029
const [worker, events] = [physicsApi.select('worker'), physicsApi.get('events')];
3130
const uuid = makeId();

libs/cannon/services/src/lib/raycast-vehicle.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { effect, runInInjectionContext, untracked, type Injector } from '@angular/core';
1+
import { effect, untracked, type Injector } from '@angular/core';
22
import type { WheelInfoOptions } from '@pmndrs/cannon-worker-api';
33
import { injectNgtRef, type NgtAnyRecord, type NgtInjectedRef } from 'angular-three';
44
import { injectNgtcPhysicsApi } from 'angular-three-cannon';
@@ -40,8 +40,7 @@ export function injectRaycastVehicle<TObject extends THREE.Object3D = THREE.Obje
4040
deps = () => ({}),
4141
}: { ref?: NgtInjectedRef<TObject>; injector?: Injector; deps?: () => NgtAnyRecord } = {},
4242
): NgtcRaycastVehicleReturn<TObject> {
43-
injector = assertInjector(injectRaycastVehicle, injector);
44-
return runInInjectionContext(injector, () => {
43+
return assertInjector(injectRaycastVehicle, injector, () => {
4544
const physicsApi = injectNgtcPhysicsApi();
4645
const [worker, subscriptions] = [physicsApi.select('worker'), physicsApi.get('subscriptions')];
4746

libs/cannon/services/src/lib/spring.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { effect, runInInjectionContext, untracked, type Injector } from '@angular/core';
1+
import { effect, untracked, type Injector } from '@angular/core';
22
import type { SpringOptns } from '@pmndrs/cannon-worker-api';
33
import { injectNgtRef, is, makeId, type NgtAnyRecord, type NgtInjectedRef } from 'angular-three';
44
import { injectNgtcPhysicsApi } from 'angular-three-cannon';
@@ -29,8 +29,7 @@ export function injectSpring<A extends THREE.Object3D, B extends THREE.Object3D>
2929
deps = () => ({}),
3030
}: { injector?: Injector; deps?: () => NgtAnyRecord; opts?: () => SpringOptns } = {},
3131
): NgtcSpringReturn<A, B> {
32-
injector = assertInjector(injectSpring, injector);
33-
return runInInjectionContext(injector, () => {
32+
return assertInjector(injectSpring, injector, () => {
3433
const physicsApi = injectNgtcPhysicsApi();
3534
const worker = physicsApi.select('worker');
3635

libs/cannon/src/lib/physics.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, Injector, Input, NgZone, effect, forwardRef, inject, untracked, type OnInit } from '@angular/core';
1+
import { Component, Injector, Input, NgZone, effect, inject, untracked, type OnInit } from '@angular/core';
22
import {
33
CannonWorkerAPI,
44
type Broadphase,
@@ -18,8 +18,7 @@ import {
1818
type WorkerFrameMessage,
1919
type WorkerRayhitEvent,
2020
} from '@pmndrs/cannon-worker-api';
21-
import { injectBeforeRender, injectNgtStore, signalStore } from 'angular-three';
22-
import { createInjectionToken } from 'ngxtension/create-injection-token';
21+
import { createApiToken, injectBeforeRender, injectNgtStore, signalStore } from 'angular-three';
2322
import * as THREE from 'three';
2423

2524
const v = new THREE.Vector3();
@@ -69,10 +68,7 @@ export type NgtcPhysicsApi = {
6968
worker: CannonWorkerAPI;
7069
};
7170

72-
export const [injectNgtcPhysicsApi, provideNgtcPhysicsApi] = createInjectionToken(
73-
(physics: NgtcPhysics) => physics.api,
74-
{ isRoot: false, deps: [forwardRef(() => NgtcPhysics)] },
75-
);
71+
export const [injectNgtcPhysicsApi, provideNgtcPhysicsApi] = createApiToken(() => NgtcPhysics);
7672

7773
@Component({
7874
selector: 'ngtc-physics',

libs/core/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export * from './lib/three-types';
1616
export * from './lib/types';
1717
export * from './lib/utils/apply-props';
1818
export { createAttachFunction } from './lib/utils/attach';
19+
export * from './lib/utils/create-api-token';
1920
export * from './lib/utils/is';
2021
export * from './lib/utils/make';
2122
export * from './lib/utils/safe-detect-changes';

libs/core/src/lib/before-render.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
import { DestroyRef, Injector, inject, runInInjectionContext } from '@angular/core';
1+
import { DestroyRef, Injector, inject } from '@angular/core';
22
import { assertInjector } from 'ngxtension/assert-injector';
33
import { injectNgtStore, type NgtBeforeRenderRecord } from './store';
44

55
export function injectBeforeRender(
66
cb: NgtBeforeRenderRecord['callback'],
77
{ priority = 0, injector }: { priority?: number; injector?: Injector } = {},
88
) {
9-
injector = assertInjector(injectBeforeRender, injector);
10-
return runInInjectionContext(injector, () => {
9+
return assertInjector(injectBeforeRender, injector, () => {
1110
const store = injectNgtStore();
1211
const sub = store.get('internal').subscribe(cb, priority, store);
1312
inject(DestroyRef).onDestroy(() => void sub());

0 commit comments

Comments
 (0)