Skip to content

Commit

Permalink
fix: adjust animations parser
Browse files Browse the repository at this point in the history
  • Loading branch information
nartc committed Dec 2, 2024
1 parent 13c5eae commit 3f21e0a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
2 changes: 2 additions & 0 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const cli = meow(
Options
--output, -o Output file name/path
--selector Selector for the component
--name, -n Name of the component
--keepnames, -k Keep original names
--keepgroups, -K Keep (empty) groups, disable pruning
--meta, -m Include metadata (as userData)
Expand All @@ -40,6 +41,7 @@ const cli = meow(
flags: {
output: { type: "string", shortFlag: "o" },
selector: { type: "string" },
name: { type: "string" },
types: { type: "boolean", shortFlag: "t" },
keepnames: { type: "boolean", shortFlag: "k" },
keepgroups: { type: "boolean", shortFlag: "K" },
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "angular-three-gltf",
"version": "1.0.9",
"version": "1.0.10",
"description": "GLTF to Angular Three converter",
"scripts": {
"cleanup": "rimraf node_modules"
Expand Down
10 changes: 6 additions & 4 deletions src/utils/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ function parse(fileName, gltf, options = {}) {
const animations = gltf.animations;
const hasAnimations = animations.length > 0;
const selector = options.selector ?? "app-model";
const componentName = options.name ?? "Model";
const ngtTypes = new Set();

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

if (animations.length) {
types.push(
`type ActionName = ${animations.map((clip, i) => `"${clip.name}"`).join(" | ")};`,
`type ActionName = ${animations.map((clip, i) => `"${clip.name}"`).join(" | ")};
type GLTFAnimationClips = NgtsAnimationClips<ActionName>;`,
);
}

Expand Down Expand Up @@ -581,7 +583,7 @@ function parse(fileName, gltf, options = {}) {
import { Component, ChangeDetectionStrategy, CUSTOM_ELEMENTS_SCHEMA, Signal, input, viewChild, ElementRef, inject, effect${hasAnimations ? ", computed, model" : ""} } from '@angular/core';
import { injectGLTF } from 'angular-three-soba/loaders';
import { GLTF } from 'three-stdlib';
${hasAnimations ? "import { injectAnimations } from 'angular-three-soba/misc';" : ""}
${hasAnimations ? "import { injectAnimations, NgtsAnimationClips } from 'angular-three-soba/misc';" : ""}
${ngtTypes.has("PerspectiveCamera") ? "import { NgtsPerspectiveCamera } from 'angular-three-soba/cameras';" : ""}
${ngtTypes.has("OrthographicCamera") ? "import { NgtsOrthographicCamera } from 'angular-three-soba/cameras';" : ""}
`;
Expand Down Expand Up @@ -641,11 +643,11 @@ ${printTypes(objects, animations)}
schemas: [CUSTOM_ELEMENTS_SCHEMA],
changeDetection: ChangeDetectionStrategy.OnPush
})
export class Model {
export class ${componentName} {
protected readonly Math = Math;
options = input({} as Partial<NgtGroup>);
${hasAnimations ? "animations = model<any>();" : ""}
${hasAnimations ? "animations = model<ReturnType<typeof injectAnimations<GLTFAnimationClips>>>();" : ""}
modelRef = viewChild<ElementRef<Group>>('model');
protected gltf = injectGLTF(() => "${url}"${gltfOptions ? `, ${JSON.stringify(gltfOptions)}` : ""}) as unknown as Signal<GLTFResult | null>;
Expand Down

0 comments on commit 3f21e0a

Please sign in to comment.