Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1.0] Rename thumb bone names #1001

Merged
merged 3 commits into from
Jul 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 27 additions & 17 deletions .github/workflows/inspect.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
- name: Fetch Deps
run: yarn install --frozen-lockfile

lint:
build:
runs-on: ubuntu-latest
needs: fetch
steps:
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions packages/three-vrm-core/src/humanoid/VRMHumanBoneName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
Expand Down
39 changes: 35 additions & 4 deletions packages/three-vrm-core/src/humanoid/VRMHumanoidLoaderPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
};

ke456-png marked this conversation as resolved.
Show resolved Hide resolved
/**
* A plugin of GLTFLoader that imports a {@link VRMHumanoid} from a VRM extension of a GLTF.
*/
Expand Down Expand Up @@ -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<VRMHumanBones> = {};
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
Expand Down Expand Up @@ -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 };
}),
);
}
Expand Down
Binary file modified packages/three-vrm/examples/models/three-vrm-girl.vrm
Binary file not shown.
4 changes: 2 additions & 2 deletions packages/types-vrmc-vrm-1.0/src/HumanoidHumanBoneName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ export type HumanoidHumanBoneName =
| 'rightUpperArm'
| 'rightLowerArm'
| 'rightHand'
| 'leftThumbMetacarpal'
| 'leftThumbProximal'
| 'leftThumbIntermediate'
| 'leftThumbDistal'
| 'leftIndexProximal'
| 'leftIndexIntermediate'
Expand All @@ -39,8 +39,8 @@ export type HumanoidHumanBoneName =
| 'leftLittleProximal'
| 'leftLittleIntermediate'
| 'leftLittleDistal'
| 'rightThumbMetacarpal'
| 'rightThumbProximal'
| 'rightThumbIntermediate'
| 'rightThumbDistal'
| 'rightIndexProximal'
| 'rightIndexIntermediate'
Expand Down