Skip to content

Commit 5a47b14

Browse files
committed
add types + gthub workflow
1 parent d5819c8 commit 5a47b14

File tree

4 files changed

+71
-10
lines changed

4 files changed

+71
-10
lines changed

.github/workflows/publish.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Release Workflow
2+
on:
3+
push:
4+
branches:
5+
- 'release/next'
6+
- 'release/rc'
7+
- 'release/stable'
8+
9+
jobs:
10+
run-release-script:
11+
runs-on: ubuntu-latest
12+
timeout-minutes: 5
13+
defaults:
14+
run:
15+
working-directory: .
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v4
19+
20+
- name: Setup Node.js
21+
uses: actions/setup-node@v4
22+
with:
23+
node-version: '22'
24+
cache: 'npm'
25+
cache-dependency-path: './package.json'
26+
27+
- name: Publish to npm (stable branch)
28+
if: startsWith(github.ref_name, 'release/stable')
29+
run: npx --yes needle-publish-helper@next publish "." --webhook "${{ secrets.DISCORD_WEBHOOK }}" --access-token "${{ secrets.NPM_TOKEN }}" --tag "stable" --create-tag "release/" --llm-api-key "${{ secrets.LLM_API_KEY }}"
30+
31+
- name: Publish to npm (rc branch)
32+
if: startsWith(github.ref_name, 'release/rc')
33+
run: npx --yes needle-publish-helper@next publish "." --webhook "${{ secrets.DISCORD_WEBHOOK }}" --access-token "${{ secrets.NPM_TOKEN }}" --tag "rc" --version+tag --create-tag "release/" --llm-api-key "${{ secrets.LLM_API_KEY }}"
34+
35+
- name: Publish to npm (next and experimental branches)
36+
if: startsWith(github.ref_name, 'release/next')
37+
run: npx --yes needle-publish-helper@next publish "." --webhook "${{ secrets.DISCORD_WEBHOOK }}" --access-token "${{ secrets.NPM_TOKEN }}" --tag "${{ github.ref_name }}" --version+tag --version+hash --create-tag "release/" --llm-api-key "${{ secrets.LLM_API_KEY }}"
38+
39+

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
{
2-
"name": "@needle-tools/three-animationpointer",
3-
"version": "1.0.0",
2+
"name": "@needle-tools/three-animation-pointer",
3+
"version": "1.0.0-alpha",
44
"description": "KHR_animation_pointer support for three.js",
55
"type": "module",
66
"main": "src/index.js",
7+
"types": "types/index.d.ts",
78
"author": {
89
"name": "Needle",
910
"email": "[email protected]",

src/GLTFLoaderAnimationPointer.js

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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
1418
const 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;
3436
const _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
*/
4146
export 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

628638
let _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+
630644
function _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

types/index.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
3+
export type AnimationPointerResolver = {
4+
resolvePath(path: string): string | null;
5+
}

0 commit comments

Comments
 (0)