question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] Type 'GLTFActions' does not satisfy the constraint 'AnimationClip'.

See original GitHub issue

Problem

Using --types, for example:

npx gltfjsx --types model.gltf

TypeScript error message:

Type 'GLTFActions' does not satisfy the constraint 'AnimationClip'.
  Type 'GLTFActions' is missing the following properties from type 'AnimationClip': name, tracks, blendMode, duration, and 8 more.ts(2344)

From GLTFActions as shown:

image

  const { actions } = useAnimations<GLTFActions>(animations, group);

Redacted versions list:

$ yarn list --depth=0
yarn list v1.22.5
├─ @react-three/drei@7.2.2
├─ @react-three/fiber@7.0.6
├─ @types/react@17.0.14
├─ react@17.0.2
├─ three-stdlib@2.0.8
├─ three@0.124.0

Cause

I think it was caused by this commit appears to have changed the TypeScript generic interface for useAnimations: https://github.com/pmndrs/drei/commit/fe00d576fa39c7059cbba89d441ec996deb5d251 PR: https://github.com/pmndrs/drei/pull/378 Original bug: https://github.com/pmndrs/drei/issues/377

Solution

What worked for me:

- type GLTFActions = Record<ActionName, THREE.AnimationAction>
+ interface GLTFAction extends THREE.AnimationClip {
+  name: ActionName;
+ }

Move GLTFResult below GLTFAction / GLTFActions declaration and apply change:

type GLTFResult = GLTF & {
  nodes: {
// ...
  }
  materials: {
// ...
  }
+  animations: GLTFAction[];
}
  const { nodes, materials, animations } = useGLTF('MODEL_NAME.glb') as GLTFResult
-  const { actions } = useAnimations<GLTFActions>(animations, group);
+  const { actions } = useAnimations(animations, group);

actions['SOME_ACTION'].play();

actions has index signature with ActionName keys instead of `string

useAnimations does not need to explicitly pass the type GLTFActions because GLTFResult already has type narrowed interface for animations, which extends THREE.AnimationClip.


Please let me know if you think this is an acceptable work around and then I can try to make a Pull Request to contribute to GLTFJSX. Thank you for this awesome tool!

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:28
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
shaasecommented, Sep 21, 2022

Hey @Glavin001, I’m new to this, but using this in a Typescript react app. I saw the same warnings you saw, and your fixes worked perfectly for me. Let me know if there’s something else that would be helpful to test. Cheers!

0reactions
drcmdacommented, Dec 23, 2022

could you make this a pr?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Type 'ActionTypes' does not satisfy the constraint 'Action<any ...
I am writing a TypeScript application using React and Redux and am having a problem. I need a second default ...
Read more >
Parent Constraint losing sources when animating via timeline ...
I found a workaround: Convert the animation clip to a clip-asset, open it to for edit in the animation window, delete every animated...
Read more >
Scripting API: AnimationClip - Unity - Manual
AnimationClip is used by Animation to play back animations. Properties. empty, Returns true if the animation clip has no curves and no events....
Read more >
Pmndrs Gltfjsx Statistics & Issues - Codesti
Issue Title State Comments Created Date Updated Date run: npx gltfjsx model.gltf open 9 2022‑12‑11 2022‑12‑22 Error with types in useGLTF hook open 0 2022‑11‑24...
Read more >
UMotion Manual - Release Notes - Soxware Interactive
Bug Fixes. Fixed that the FBX export feature doesn't set the "Root Motion Node" setting correctly to "<Root Transform>" when the exported animation...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found