Skip to content

Commit 450a8c7

Browse files
committed
feat(soba/misc): rename inject* to just function name
1 parent 79184dc commit 450a8c7

File tree

3 files changed

+58
-18
lines changed

3 files changed

+58
-18
lines changed

libs/soba/misc/src/lib/animations.ts

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { computed, effect, ElementRef, Injector, isSignal, signal, untracked } from '@angular/core';
2-
import { injectBeforeRender, resolveRef } from 'angular-three';
2+
import { beforeRender, resolveRef } from 'angular-three';
33
import { assertInjector } from 'ngxtension/assert-injector';
44
import * as THREE from 'three';
55

@@ -38,17 +38,17 @@ export type NgtsAnimation<TAnimation extends NgtsAnimationClip = NgtsAnimationCl
3838
/**
3939
* Use afterNextRender
4040
*/
41-
export function injectAnimations<TAnimation extends NgtsAnimationClip>(
42-
animations: () => NgtsAnimation<TAnimation> | undefined | null,
41+
export function animations<TAnimation extends NgtsAnimationClip>(
42+
animationsFactory: () => NgtsAnimation<TAnimation> | undefined | null,
4343
object:
4444
| ElementRef<THREE.Object3D>
4545
| THREE.Object3D
4646
| (() => ElementRef<THREE.Object3D> | THREE.Object3D | undefined | null),
4747
{ injector }: { injector?: Injector } = {},
4848
): NgtsAnimationApi<TAnimation> {
49-
return assertInjector(injectAnimations, injector, () => {
49+
return assertInjector(animations, injector, () => {
5050
const mixer = new THREE.AnimationMixer(null!);
51-
injectBeforeRender(({ delta }) => {
51+
beforeRender(({ delta }) => {
5252
if (!mixer.getRoot()) return;
5353
mixer.update(delta);
5454
});
@@ -74,7 +74,7 @@ export function injectAnimations<TAnimation extends NgtsAnimationClip>(
7474

7575
Object.assign(mixer, { _root: obj });
7676

77-
const maybeAnimationClips = animations();
77+
const maybeAnimationClips = animationsFactory();
7878
if (!maybeAnimationClips) return;
7979

8080
const animationClips = Array.isArray(maybeAnimationClips)
@@ -117,10 +117,27 @@ export function injectAnimations<TAnimation extends NgtsAnimationClip>(
117117
});
118118
});
119119

120-
const result = { ready, clips, mixer, actions, names } as unknown as NgtsAnimationApi<TAnimation>;
120+
const result = { clips, mixer, actions, names } as NgtsAnimationApi<TAnimation>;
121121

122122
Object.defineProperty(result, 'isReady', { get: ready });
123123

124124
return result;
125125
});
126126
}
127+
128+
/**
129+
* @deprecated use animations instead. Will be removed in v5.0.0
130+
* @since v4.0.0
131+
*/
132+
export function injectAnimations<TAnimation extends NgtsAnimationClip>(
133+
animationsFactory: () => NgtsAnimation<TAnimation> | undefined | null,
134+
object:
135+
| ElementRef<THREE.Object3D>
136+
| THREE.Object3D
137+
| (() => ElementRef<THREE.Object3D> | THREE.Object3D | undefined | null),
138+
{ injector }: { injector?: Injector } = {},
139+
): NgtsAnimationApi<TAnimation> {
140+
return assertInjector(injectAnimations, injector, () => {
141+
return animations(animationsFactory, object, { injector });
142+
});
143+
}

libs/soba/misc/src/lib/depth-buffer.ts

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { computed, Injector } from '@angular/core';
2-
import { injectBeforeRender, injectStore } from 'angular-three';
2+
import { beforeRender, injectStore } from 'angular-three';
33
import { assertInjector } from 'ngxtension/assert-injector';
44
import * as THREE from 'three';
5-
import { injectFBO } from './fbo';
5+
import { fbo } from './fbo';
66

7-
export function injectDepthBuffer(
7+
export function depthBuffer(
88
params: () => { size?: number; frames?: number } = () => ({}),
99
{ injector }: { injector?: Injector } = {},
1010
) {
11-
return assertInjector(injectDepthBuffer, injector, () => {
11+
return assertInjector(depthBuffer, injector, () => {
1212
const size = computed(() => params().size || 256);
1313
const frames = computed(() => params().frames || Infinity);
1414

@@ -24,10 +24,10 @@ export function injectDepthBuffer(
2424
return { depthTexture };
2525
});
2626

27-
const depthFBO = injectFBO(() => ({ width: w(), height: h(), settings: depthConfig() }));
27+
const depthFBO = fbo(() => ({ width: w(), height: h(), settings: depthConfig() }));
2828

2929
let count = 0;
30-
injectBeforeRender(({ gl, scene, camera }) => {
30+
beforeRender(({ gl, scene, camera }) => {
3131
if (frames() === Infinity || count < frames()) {
3232
gl.setRenderTarget(depthFBO);
3333
gl.render(scene, camera);
@@ -39,3 +39,16 @@ export function injectDepthBuffer(
3939
return depthFBO.depthTexture;
4040
});
4141
}
42+
43+
/**
44+
* @deprecated use depthBuffer instead. Will be removed in v5.0.0
45+
* @since v4.0.0
46+
*/
47+
export function injectDepthBuffer(
48+
params: () => { size?: number; frames?: number } = () => ({}),
49+
{ injector }: { injector?: Injector } = {},
50+
) {
51+
return assertInjector(injectDepthBuffer, injector, () => {
52+
return depthBuffer(params, { injector });
53+
});
54+
}

libs/soba/misc/src/lib/fbo.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ export interface NgtsFBOParams {
4242
settings?: FBOSettings;
4343
}
4444

45-
export function injectFBO(params: () => NgtsFBOParams = () => ({}), { injector }: { injector?: Injector } = {}) {
46-
return assertInjector(injectFBO, injector, () => {
45+
export function fbo(params: () => NgtsFBOParams = () => ({}), { injector }: { injector?: Injector } = {}) {
46+
return assertInjector(fbo, injector, () => {
4747
const store = injectStore();
4848

4949
const width = computed(() => {
@@ -99,6 +99,16 @@ export function injectFBO(params: () => NgtsFBOParams = () => ({}), { injector }
9999
});
100100
}
101101

102+
/**
103+
* @deprecated use fbo instead. Will be removed in v5.0.0
104+
* @since v4.0.0
105+
*/
106+
export function injectFBO(params: () => NgtsFBOParams = () => ({}), { injector }: { injector?: Injector } = {}) {
107+
return assertInjector(injectFBO, injector, () => {
108+
return fbo(params, { injector });
109+
});
110+
}
111+
102112
@Directive({ selector: 'ng-template[fbo]' })
103113
export class NgtsFBO {
104114
fbo = input({} as { width: NgtsFBOParams['width']; height: NgtsFBOParams['height'] } & FBOSettings);
@@ -107,9 +117,9 @@ export class NgtsFBO {
107117
private viewContainerRef = inject(ViewContainerRef);
108118

109119
constructor() {
110-
let ref: EmbeddedViewRef<{ $implicit: ReturnType<typeof injectFBO> }>;
120+
let ref: EmbeddedViewRef<{ $implicit: ReturnType<typeof fbo> }>;
111121

112-
const fboTarget = injectFBO(() => {
122+
const fboTarget = fbo(() => {
113123
const { width, height, ...settings } = this.fbo();
114124
return { width, height, settings };
115125
});
@@ -124,7 +134,7 @@ export class NgtsFBO {
124134
});
125135
}
126136

127-
static ngTemplateContextGuard(_: NgtsFBO, ctx: unknown): ctx is { $implicit: ReturnType<typeof injectFBO> } {
137+
static ngTemplateContextGuard(_: NgtsFBO, ctx: unknown): ctx is { $implicit: ReturnType<typeof fbo> } {
128138
return true;
129139
}
130140
}

0 commit comments

Comments
 (0)