Skip to content

Commit

Permalink
Fix/101: Type 'GLTFActions' constraint to 'AnimationClip' (#193)
Browse files Browse the repository at this point in the history
* Fix/101: Type 'GLTFActions' does not satisfy the constraint 'AnimationClip'

* Update parser.js

* Update cli.js

---------

Co-authored-by: drcmda <drcmda@gmail.com>
  • Loading branch information
rafelis1997 and drcmda committed Dec 21, 2023
1 parent 199157b commit 1990133
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion cli.js
Expand Up @@ -63,7 +63,7 @@ const cli = meow(
keepmeshes: { type: 'boolean', shortFlag: 'j', default: false },
keepmaterials: { type: 'boolean', shortFlag: 'M', default: false },
format: { type: 'string', shortFlag: 'f', default: 'webp' },
exportdefault: { type: 'boolean', alias: 'E' },
exportdefault: { type: 'boolean', shortFlag: 'E' },
weld: { type: 'number', default: 0.0001 },
ratio: { type: 'number', default: 0.75 },
error: { type: 'number', default: 0.001 },
Expand Down
9 changes: 5 additions & 4 deletions src/utils/parser.js
Expand Up @@ -101,7 +101,9 @@ function parse(gltf, { fileName = 'model', ...options } = {}) {
if (animations.length) {
animationTypes = `\n
type ActionName = ${animations.map((clip, i) => `"${clip.name}"`).join(' | ')};
type GLTFActions = Record<ActionName, THREE.AnimationAction>;\n`
interface GLTFAction extends THREE.AnimationClip {\n
name: ActionName;\n
}`
}

const types = [...new Set([...meshes, ...bones].map((o) => getType(o)))]
Expand All @@ -117,6 +119,7 @@ function parse(gltf, { fileName = 'model', ...options } = {}) {
materials: {
${materials.map(({ name, type }) => (isVarName(name) ? name : `['${name}']`) + ': THREE.' + type).join(',')}
}
animations: GLTFAction[]
}\n${animationTypes}\n${contextType}`
}

Expand Down Expand Up @@ -376,9 +379,7 @@ function parse(gltf, { fileName = 'model', ...options } = {}) {
}

function printAnimations(animations) {
return animations.length
? `\nconst { actions } = useAnimations${options.types ? '<GLTFActions>' : ''}(animations, group)`
: ''
return animations.length ? `\nconst { actions } = useAnimations(animations, group)` : ''
}

function parseExtras(extras) {
Expand Down

0 comments on commit 1990133

Please sign in to comment.