@@ -10,6 +10,10 @@ import {
1010 SkinnedMesh
1111} from 'three' ;
1212
13+ /**
14+ * @typedef {import("three/examples/jsm/loaders/GLTFLoader").GLTFLoaderPlugin } GLTFLoaderPlugin
15+ */
16+
1317// DUPLICATED from GLTFLoader.js
1418const ANIMATION_TARGET_TYPE = {
1519 node : 'node' ,
@@ -29,25 +33,32 @@ const INTERPOLATION = {
2933 STEP : InterpolateDiscrete
3034} ;
3135
32- // HACK monkey patching findNode to ensure we can map to other types required by KHR_animation_pointer.
33- const find = PropertyBinding . findNode ;
3436const _animationPointerDebug = false ;
3537
38+
3639/**
3740 * Animation Pointer Extension
3841 *
3942 * Draft Specification: https://github.com/ux3d/glTF/tree/extensions/KHR_animation_pointer/extensions/2.0/Khronos/KHR_animation_pointer
43+ *
44+ * @implements {GLTFLoaderPlugin}
4045 */
4146export class GLTFAnimationPointerExtension {
4247
48+ /** @type {import("three/examples/jsm/loaders/GLTFLoader").GLTFParser } */
4349 constructor ( parser ) {
4450
45- this . parser = parser ;
4651 this . name = KHR_ANIMATION_POINTER ;
52+ this . parser = parser ;
53+
54+ /** @type {import("..").AnimationPointerResolver | null } */
4755 this . animationPointerResolver = null ;
4856
4957 }
5058
59+ /**
60+ * @param {import("..").AnimationPointerResolver | null } animationPointerResolver
61+ */
5162 setAnimationPointerResolver ( animationPointerResolver ) {
5263
5364 this . animationPointerResolver = animationPointerResolver ;
@@ -318,10 +329,9 @@ export class GLTFAnimationPointerExtension {
318329
319330 }
320331
321- const pointerResolver = this . animationPointerResolver ;
322- if ( pointerResolver && pointerResolver . resolvePath ) {
332+ if ( this . animationPointerResolver ?. resolvePath ) {
323333
324- path = pointerResolver . resolvePath ( path ) ;
334+ path = this . animationPointerResolver . resolvePath ( path ) ;
325335
326336 }
327337
@@ -627,11 +637,17 @@ export class GLTFAnimationPointerExtension {
627637
628638let _havePatchedPropertyBindings = false ;
629639
640+ // HACK monkey patching findNode to ensure we can map to other types required by KHR_animation_pointer.
641+ /** @type {PropertyBinding.findNode | null } */
642+ let findNodeFn = null ;
643+
630644function _ensurePropertyBindingPatch ( ) {
631645
632646 if ( _havePatchedPropertyBindings ) return ;
633647 _havePatchedPropertyBindings = true ;
634648
649+ const findNode = ( findNodeFn ||= PropertyBinding . findNode ) ;
650+
635651 // "node" is the Animator component in our case
636652 // "path" is the animated property path, just with translated material names.
637653 PropertyBinding . findNode = function ( node , path ) {
@@ -707,7 +723,7 @@ function _ensurePropertyBindingPatch() {
707723
708724 if ( ! currentTarget ) {
709725
710- const originalFindResult = find ( node , sections [ 2 ] ) ;
726+ const originalFindResult = findNode ( node , sections [ 2 ] ) ;
711727
712728 if ( ! originalFindResult )
713729 console . warn ( KHR_ANIMATION_POINTER + ': Property binding not found' , path , node , node . name , sections ) ;
@@ -723,7 +739,7 @@ function _ensurePropertyBindingPatch() {
723739
724740 }
725741
726- return find ( node , path ) ;
742+ return findNode ( node , path ) ;
727743
728744 } ;
729745
0 commit comments