Skip to content

Commit 0ea3280

Browse files
committed
matcap and animations
1 parent 67207ee commit 0ea3280

File tree

18 files changed

+448
-30
lines changed

18 files changed

+448
-30
lines changed
13.9 KB
Binary file not shown.
30.9 KB
Loading
32.9 KB
Loading
168 KB
Loading
32.9 KB
Loading
Binary file not shown.
2.35 MB
Binary file not shown.

libs/soba/loaders/src/gltf-loader/gltf-loader.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ function _extensions(useDraco: boolean | string, useMeshOpt: boolean, extensions
2929
};
3030
}
3131

32+
export type NgtsGLTF<T extends Partial<NgtObjectMap>> = GLTF & NgtObjectMap & T;
33+
3234
export function injectNgtsGLTFLoader<TUrl extends string | string[] | Record<string, string>>(
3335
path: () => TUrl,
3436
{

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

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { DestroyRef, Injector, effect, inject, runInInjectionContext } from '@angular/core';
1+
import { DestroyRef, Injector, effect, inject, runInInjectionContext, signal, untracked } from '@angular/core';
22
import { assertInjectionContext, injectBeforeRender, injectNgtRef, type NgtInjectedRef } from 'angular-three';
33
import * as THREE from 'three';
44

@@ -23,6 +23,7 @@ export function injectNgtsAnimations(
2323
}
2424

2525
const mixer = new THREE.AnimationMixer(null!);
26+
const ready = signal(false);
2627
const actions = {} as Record<string, THREE.AnimationAction>;
2728
let cached = {} as Record<string, THREE.AnimationAction>;
2829

@@ -42,30 +43,37 @@ export function injectNgtsAnimations(
4243

4344
injectBeforeRender(({ delta }) => mixer.update(delta));
4445

45-
effect(() => {
46-
const actual = actualRef.nativeElement;
47-
if (!actual) return;
48-
const animations = animationsFactory();
46+
effect(
47+
() => {
48+
const actual = actualRef.nativeElement;
49+
if (!actual) return;
50+
const animations = animationsFactory();
4951

50-
for (let i = 0; i < animations.length; i++) {
51-
const clip = animations[i];
52+
for (let i = 0; i < animations.length; i++) {
53+
const clip = animations[i];
5254

53-
names.push(clip.name);
54-
clips.push(clip);
55+
names.push(clip.name);
56+
clips.push(clip);
5557

56-
Object.defineProperty(actions, clip.name, {
57-
enumerable: true,
58-
get: () => {
59-
return cached[clip.name] || (cached[clip.name] = mixer.clipAction(clip, actual));
60-
},
61-
});
58+
Object.defineProperty(actions, clip.name, {
59+
enumerable: true,
60+
get: () => {
61+
return cached[clip.name] || (cached[clip.name] = mixer.clipAction(clip, actual));
62+
},
63+
});
6264

63-
if (i === 0 && playFirstClip) {
64-
actions[clip.name].play();
65+
if (i === 0 && playFirstClip) {
66+
actions[clip.name].play();
67+
}
6568
}
66-
}
67-
});
6869

69-
return { ref: actualRef, actions, mixer, names, clips };
70+
if (!untracked(ready)) {
71+
ready.set(true);
72+
}
73+
},
74+
{ allowSignalWrites: true },
75+
);
76+
77+
return { ref: actualRef, actions, mixer, names, clips, ready };
7078
});
7179
}

libs/soba/src/abstractions/billboard.stories.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { Component, CUSTOM_ELEMENTS_SCHEMA, Input } from '@angular/core';
2-
import { Meta, moduleMetadata } from '@storybook/angular';
2+
import { Meta } from '@storybook/angular';
33
import { NgtArgs } from 'angular-three';
44
import { NgtsBillboard, NgtsText } from 'angular-three-soba/abstractions';
55
import { NgtsOrbitControls } from 'angular-three-soba/controls';
66
import { BoxGeometry, ConeGeometry, PlaneGeometry } from 'three';
7-
import { makeStoryObject, StorybookSetup } from '../setup-canvas';
7+
import { makeDecorators, makeStoryObject } from '../setup-canvas';
88

99
@Component({
1010
selector: 'BillboardCone',
@@ -135,7 +135,7 @@ class DefaultBillboardStory {
135135

136136
export default {
137137
title: 'Abstractions/Billboard',
138-
decorators: [moduleMetadata({ imports: [StorybookSetup] })],
138+
decorators: makeDecorators(),
139139
} as Meta;
140140

141141
const canvasOptions = { camera: { position: [0, 0, 10] }, controls: false };

0 commit comments

Comments
 (0)