diff --git a/.github/workflows/inspect.yml b/.github/workflows/inspect.yml index 549d0760e..c8a2c8aa8 100644 --- a/.github/workflows/inspect.yml +++ b/.github/workflows/inspect.yml @@ -28,7 +28,7 @@ jobs: - name: Fetch Deps run: yarn install --frozen-lockfile - lint: + build: runs-on: ubuntu-latest needs: fetch steps: @@ -47,12 +47,20 @@ jobs: key: ${{ runner.os }}-yarn-${{ hashFiles( 'yarn.lock' ) }} restore-keys: | ${{ runner.os }}-yarn- - - name: Lint - run: yarn lint + - name: Build + run: yarn build + - name: Upload Builds + uses: actions/upload-artifact@v3 + with: + name: build + path: | + packages/*/lib/ + packages/*/types/ + packages/*/ts*/ - test: + lint: runs-on: ubuntu-latest - needs: fetch + needs: build steps: - name: Checkout uses: actions/checkout@v3 @@ -69,12 +77,17 @@ jobs: key: ${{ runner.os }}-yarn-${{ hashFiles( 'yarn.lock' ) }} restore-keys: | ${{ runner.os }}-yarn- - - name: Test - run: yarn test + - name: Download Builds + uses: actions/download-artifact@v3 + with: + name: build + path: packages + - name: Lint + run: yarn lint - build: + test: runs-on: ubuntu-latest - needs: fetch + needs: build steps: - name: Checkout uses: actions/checkout@v3 @@ -91,16 +104,13 @@ jobs: key: ${{ runner.os }}-yarn-${{ hashFiles( 'yarn.lock' ) }} restore-keys: | ${{ runner.os }}-yarn- - - name: Build - run: yarn build - - name: Upload Builds - uses: actions/upload-artifact@v3 + - name: Download Builds + uses: actions/download-artifact@v3 with: name: build - path: | - packages/*/lib/ - packages/*/types/ - packages/*/ts*/ + path: packages + - name: Test + run: yarn test docs: runs-on: ubuntu-latest diff --git a/packages/three-vrm-core/src/humanoid/VRMHumanBoneName.ts b/packages/three-vrm-core/src/humanoid/VRMHumanBoneName.ts index 6538e344d..e6503bc62 100644 --- a/packages/three-vrm-core/src/humanoid/VRMHumanBoneName.ts +++ b/packages/three-vrm-core/src/humanoid/VRMHumanBoneName.ts @@ -26,8 +26,8 @@ export const VRMHumanBoneName = { RightUpperArm: 'rightUpperArm', RightLowerArm: 'rightLowerArm', RightHand: 'rightHand', + LeftThumbMetacarpal: 'leftThumbMetacarpal', LeftThumbProximal: 'leftThumbProximal', - LeftThumbIntermediate: 'leftThumbIntermediate', LeftThumbDistal: 'leftThumbDistal', LeftIndexProximal: 'leftIndexProximal', LeftIndexIntermediate: 'leftIndexIntermediate', @@ -41,8 +41,8 @@ export const VRMHumanBoneName = { LeftLittleProximal: 'leftLittleProximal', LeftLittleIntermediate: 'leftLittleIntermediate', LeftLittleDistal: 'leftLittleDistal', + RightThumbMetacarpal: 'rightThumbMetacarpal', RightThumbProximal: 'rightThumbProximal', - RightThumbIntermediate: 'rightThumbIntermediate', RightThumbDistal: 'rightThumbDistal', RightIndexProximal: 'rightIndexProximal', RightIndexIntermediate: 'rightIndexIntermediate', diff --git a/packages/three-vrm-core/src/humanoid/VRMHumanoidLoaderPlugin.ts b/packages/three-vrm-core/src/humanoid/VRMHumanoidLoaderPlugin.ts index 4ffa990d6..fc419081a 100644 --- a/packages/three-vrm-core/src/humanoid/VRMHumanoidLoaderPlugin.ts +++ b/packages/three-vrm-core/src/humanoid/VRMHumanoidLoaderPlugin.ts @@ -8,6 +8,16 @@ import { GLTF as GLTFSchema } from '@gltf-transform/core'; import { VRMHumanoidHelper } from './helpers/VRMHumanoidHelper'; import { VRMHumanoidLoaderPluginOptions } from './VRMHumanoidLoaderPluginOptions'; +/** + * A map from old thumb bone names to new thumb bone names + */ +const thumbBoneNameMap: { [key: string]: V1VRMSchema.HumanoidHumanBoneName | undefined } = { + leftThumbProximal: 'leftThumbMetacarpal', + leftThumbIntermediate: 'leftThumbProximal', + rightThumbProximal: 'rightThumbMetacarpal', + rightThumbIntermediate: 'rightThumbProximal', +}; + /** * A plugin of GLTFLoader that imports a {@link VRMHumanoid} from a VRM extension of a GLTF. */ @@ -79,13 +89,30 @@ export class VRMHumanoidLoaderPlugin implements GLTFLoaderPlugin { return null; } + /** + * compat: 1.0-beta thumb bone names + * + * `true` if `leftThumbIntermediate` or `rightThumbIntermediate` exists + */ + const existsPreviousThumbName = + (schemaHumanoid.humanBones as any).leftThumbIntermediate != null || + (schemaHumanoid.humanBones as any).rightThumbIntermediate != null; + const humanBones: Partial = {}; if (schemaHumanoid.humanBones != null) { await Promise.all( Object.entries(schemaHumanoid.humanBones).map(async ([boneNameString, schemaHumanBone]) => { - const boneName = boneNameString as V1VRMSchema.HumanoidHumanBoneName; + let boneName = boneNameString as V1VRMSchema.HumanoidHumanBoneName; const index = schemaHumanBone.node; + // compat: 1.0-beta previous thumb bone names + if (existsPreviousThumbName) { + const thumbBoneName = thumbBoneNameMap[boneName]; + if (thumbBoneName != null) { + boneName = thumbBoneName; + } + } + const node = await this.parser.getDependency('node', index); // if the specified node does not exist, emit a warning @@ -143,17 +170,21 @@ export class VRMHumanoidLoaderPlugin implements GLTFLoaderPlugin { return; } + // map to new bone name + const thumbBoneName = thumbBoneNameMap[boneName]; + const newBoneName = (thumbBoneName ?? boneName) as V1VRMSchema.HumanoidHumanBoneName; + // v0 VRMs might have a multiple nodes attached to a single bone... // so if there already is an entry in the `humanBones`, show a warning and ignore it - if (humanBones[boneName] != null) { + if (humanBones[newBoneName] != null) { console.warn( - `Multiple bone entries for ${boneName} detected (index = ${index}), ignoring duplicated entries.`, + `Multiple bone entries for ${newBoneName} detected (index = ${index}), ignoring duplicated entries.`, ); return; } // set to the `humanBones` - humanBones[boneName] = { node }; + humanBones[newBoneName] = { node }; }), ); } diff --git a/packages/three-vrm/examples/models/three-vrm-girl.vrm b/packages/three-vrm/examples/models/three-vrm-girl.vrm index 6d862126c..5e11e0a74 100644 Binary files a/packages/three-vrm/examples/models/three-vrm-girl.vrm and b/packages/three-vrm/examples/models/three-vrm-girl.vrm differ diff --git a/packages/types-vrmc-vrm-1.0/src/HumanoidHumanBoneName.ts b/packages/types-vrmc-vrm-1.0/src/HumanoidHumanBoneName.ts index e266c3e15..ee982cda1 100644 --- a/packages/types-vrmc-vrm-1.0/src/HumanoidHumanBoneName.ts +++ b/packages/types-vrmc-vrm-1.0/src/HumanoidHumanBoneName.ts @@ -24,8 +24,8 @@ export type HumanoidHumanBoneName = | 'rightUpperArm' | 'rightLowerArm' | 'rightHand' + | 'leftThumbMetacarpal' | 'leftThumbProximal' - | 'leftThumbIntermediate' | 'leftThumbDistal' | 'leftIndexProximal' | 'leftIndexIntermediate' @@ -39,8 +39,8 @@ export type HumanoidHumanBoneName = | 'leftLittleProximal' | 'leftLittleIntermediate' | 'leftLittleDistal' + | 'rightThumbMetacarpal' | 'rightThumbProximal' - | 'rightThumbIntermediate' | 'rightThumbDistal' | 'rightIndexProximal' | 'rightIndexIntermediate'