Skip to content

Commit 3f21e0a

Browse files
committed
fix: adjust animations parser
1 parent 13c5eae commit 3f21e0a

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

cli.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const cli = meow(
1818
Options
1919
--output, -o Output file name/path
2020
--selector Selector for the component
21+
--name, -n Name of the component
2122
--keepnames, -k Keep original names
2223
--keepgroups, -K Keep (empty) groups, disable pruning
2324
--meta, -m Include metadata (as userData)
@@ -40,6 +41,7 @@ const cli = meow(
4041
flags: {
4142
output: { type: "string", shortFlag: "o" },
4243
selector: { type: "string" },
44+
name: { type: "string" },
4345
types: { type: "boolean", shortFlag: "t" },
4446
keepnames: { type: "boolean", shortFlag: "k" },
4547
keepgroups: { type: "boolean", shortFlag: "K" },

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-three-gltf",
3-
"version": "1.0.9",
3+
"version": "1.0.10",
44
"description": "GLTF to Angular Three converter",
55
"scripts": {
66
"cleanup": "rimraf node_modules"

src/utils/parser.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ function parse(fileName, gltf, options = {}) {
66
const animations = gltf.animations;
77
const hasAnimations = animations.length > 0;
88
const selector = options.selector ?? "app-model";
9+
const componentName = options.name ?? "Model";
910
const ngtTypes = new Set();
1011

1112
// Collect all objects
@@ -107,7 +108,8 @@ function parse(fileName, gltf, options = {}) {
107108

108109
if (animations.length) {
109110
types.push(
110-
`type ActionName = ${animations.map((clip, i) => `"${clip.name}"`).join(" | ")};`,
111+
`type ActionName = ${animations.map((clip, i) => `"${clip.name}"`).join(" | ")};
112+
type GLTFAnimationClips = NgtsAnimationClips<ActionName>;`,
111113
);
112114
}
113115

@@ -581,7 +583,7 @@ function parse(fileName, gltf, options = {}) {
581583
import { Component, ChangeDetectionStrategy, CUSTOM_ELEMENTS_SCHEMA, Signal, input, viewChild, ElementRef, inject, effect${hasAnimations ? ", computed, model" : ""} } from '@angular/core';
582584
import { injectGLTF } from 'angular-three-soba/loaders';
583585
import { GLTF } from 'three-stdlib';
584-
${hasAnimations ? "import { injectAnimations } from 'angular-three-soba/misc';" : ""}
586+
${hasAnimations ? "import { injectAnimations, NgtsAnimationClips } from 'angular-three-soba/misc';" : ""}
585587
${ngtTypes.has("PerspectiveCamera") ? "import { NgtsPerspectiveCamera } from 'angular-three-soba/cameras';" : ""}
586588
${ngtTypes.has("OrthographicCamera") ? "import { NgtsOrthographicCamera } from 'angular-three-soba/cameras';" : ""}
587589
`;
@@ -641,11 +643,11 @@ ${printTypes(objects, animations)}
641643
schemas: [CUSTOM_ELEMENTS_SCHEMA],
642644
changeDetection: ChangeDetectionStrategy.OnPush
643645
})
644-
export class Model {
646+
export class ${componentName} {
645647
protected readonly Math = Math;
646648
647649
options = input({} as Partial<NgtGroup>);
648-
${hasAnimations ? "animations = model<any>();" : ""}
650+
${hasAnimations ? "animations = model<ReturnType<typeof injectAnimations<GLTFAnimationClips>>>();" : ""}
649651
modelRef = viewChild<ElementRef<Group>>('model');
650652
651653
protected gltf = injectGLTF(() => "${url}"${gltfOptions ? `, ${JSON.stringify(gltfOptions)}` : ""}) as unknown as Signal<GLTFResult | null>;

0 commit comments

Comments
 (0)