@pmndrs/viverse 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +34 -0
- package/README.md +41 -0
- package/dist/animation/gltf.d.ts +3 -0
- package/dist/animation/gltf.js +8 -0
- package/dist/animation/index.d.ts +30 -0
- package/dist/animation/index.js +150 -0
- package/dist/animation/mixamo-bone-map.json +54 -0
- package/dist/animation/mixamo.d.ts +3 -0
- package/dist/animation/mixamo.js +9 -0
- package/dist/animation/utils.d.ts +3 -0
- package/dist/animation/utils.js +28 -0
- package/dist/animation/vrma.d.ts +3 -0
- package/dist/animation/vrma.js +8 -0
- package/dist/assets/idle.d.ts +1 -0
- package/dist/assets/idle.js +1 -0
- package/dist/assets/jump-down.d.ts +1 -0
- package/dist/assets/jump-down.js +1 -0
- package/dist/assets/jump-forward.d.ts +1 -0
- package/dist/assets/jump-forward.js +1 -0
- package/dist/assets/jump-loop.d.ts +1 -0
- package/dist/assets/jump-loop.js +1 -0
- package/dist/assets/jump-up.d.ts +1 -0
- package/dist/assets/jump-up.js +1 -0
- package/dist/assets/mannequin.d.ts +1 -0
- package/dist/assets/mannequin.js +1 -0
- package/dist/assets/prototype-texture.d.ts +1 -0
- package/dist/assets/prototype-texture.js +1 -0
- package/dist/assets/run.d.ts +1 -0
- package/dist/assets/run.js +1 -0
- package/dist/assets/walk.d.ts +1 -0
- package/dist/assets/walk.js +1 -0
- package/dist/camera.d.ts +79 -0
- package/dist/camera.js +139 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +7 -0
- package/dist/input/index.d.ts +30 -0
- package/dist/input/index.js +64 -0
- package/dist/input/keyboard.d.ts +8 -0
- package/dist/input/keyboard.js +77 -0
- package/dist/input/pointer-capture.d.ts +14 -0
- package/dist/input/pointer-capture.js +59 -0
- package/dist/input/pointer-lock.d.ts +13 -0
- package/dist/input/pointer-lock.js +51 -0
- package/dist/material.d.ts +6 -0
- package/dist/material.js +18 -0
- package/dist/model/gltf.d.ts +8 -0
- package/dist/model/gltf.js +7 -0
- package/dist/model/index.d.ts +32 -0
- package/dist/model/index.js +57 -0
- package/dist/model/vrm.d.ts +9 -0
- package/dist/model/vrm.js +19 -0
- package/dist/physics/index.d.ts +50 -0
- package/dist/physics/index.js +127 -0
- package/dist/physics/world.d.ts +9 -0
- package/dist/physics/world.js +27 -0
- package/dist/simple-character.d.ts +105 -0
- package/dist/simple-character.js +329 -0
- package/dist/utils.d.ts +2 -0
- package/dist/utils.js +34 -0
- package/package.json +47 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
Copyright 2024 Bela Bohlender
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
8
|
+
|
|
9
|
+
Link to License of robot.vrm from "FinBeenWhere?"
|
|
10
|
+
https://creativecommons.org/licenses/by/4.0/
|
|
11
|
+
|
|
12
|
+
License of @pixiv/three-vrm
|
|
13
|
+
Copyright (c) 2019-2025 pixiv Inc.
|
|
14
|
+
|
|
15
|
+
MIT License
|
|
16
|
+
|
|
17
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
18
|
+
a copy of this software and associated documentation files (the
|
|
19
|
+
"Software"), to deal in the Software without restriction, including
|
|
20
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
21
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
22
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
23
|
+
the following conditions:
|
|
24
|
+
|
|
25
|
+
The above copyright notice and this permission notice shall be
|
|
26
|
+
included in all copies or substantial portions of the Software.
|
|
27
|
+
|
|
28
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
29
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
30
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
31
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
32
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
33
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
34
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
<h1 align="center">@pmndrs/viverse</h1>
|
|
2
|
+
<h3 align="center">Build 3D web games with threejs and viverse.</h3>
|
|
3
|
+
<br/>
|
|
4
|
+
|
|
5
|
+
<p align="center">
|
|
6
|
+
<a href="https://npmjs.com/package/@react-three/viverse" target="_blank">
|
|
7
|
+
<img src="https://img.shields.io/npm/v/@react-three/viverse?style=flat&colorA=000000&colorB=000000" alt="NPM" />
|
|
8
|
+
</a>
|
|
9
|
+
<a href="https://npmjs.com/package/@react-three/viverse" target="_blank">
|
|
10
|
+
<img src="https://img.shields.io/npm/dt/@react-three/viverse.svg?style=flat&colorA=000000&colorB=000000" alt="NPM" />
|
|
11
|
+
</a>
|
|
12
|
+
<a href="https://twitter.com/pmndrs" target="_blank">
|
|
13
|
+
<img src="https://img.shields.io/twitter/follow/pmndrs?label=%40pmndrs&style=flat&colorA=000000&colorB=000000&logo=twitter&logoColor=000000" alt="Twitter" />
|
|
14
|
+
</a>
|
|
15
|
+
<a href="https://discord.gg/ZZjjNvJ" target="_blank">
|
|
16
|
+
<img src="https://img.shields.io/discord/740090768164651008?style=flat&colorA=000000&colorB=000000&label=discord&logo=discord&logoColor=000000" alt="Discord" />
|
|
17
|
+
</a>
|
|
18
|
+
</p>
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npm install three @react-three/fiber @react-three/viverse
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
### What does it look like?
|
|
25
|
+
|
|
26
|
+
| A prototype map with the `SimpleCharacter` class and its default model. |  |
|
|
27
|
+
| --------------------------------------------------------------------------- | --------------------------------------------------------------------- |
|
|
28
|
+
|
|
29
|
+
```jsx
|
|
30
|
+
const world = new BvhPhysicsWorld()
|
|
31
|
+
world.addFixedBody(ground.scene)
|
|
32
|
+
const character = new SimpleCharacter(camera, world, canvas, { model: { url: profile.activeAvatar?.vrmUrl } })
|
|
33
|
+
scene.add(character)
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## How to get started
|
|
37
|
+
|
|
38
|
+
> Some familiarity with
|
|
39
|
+
> threej is recommended.
|
|
40
|
+
|
|
41
|
+
Get started with building games using @pmndrs/viverse [vanilla three.js](https://pmndrs.github.io/viverse/without-react).
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { AnimationClip } from 'three';
|
|
2
|
+
import { loadCharacterModel } from '../model/index.js';
|
|
3
|
+
export declare function loadVrmModelGltfAnimations(model: Exclude<Awaited<ReturnType<typeof loadCharacterModel>>, undefined>, url: string, removeXZMovement: boolean): Promise<Array<AnimationClip>>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { GLTFLoader } from 'three/examples/jsm/Addons.js';
|
|
2
|
+
import { fixModelAnimationClip } from './index.js';
|
|
3
|
+
const loader = new GLTFLoader();
|
|
4
|
+
export async function loadVrmModelGltfAnimations(model, url, removeXZMovement) {
|
|
5
|
+
const { animations, scene: clipScene } = await loader.loadAsync(url);
|
|
6
|
+
animations.forEach((clip) => fixModelAnimationClip(model, clip, clipScene, removeXZMovement));
|
|
7
|
+
return animations;
|
|
8
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { VRMHumanBoneName } from '@pixiv/three-vrm';
|
|
2
|
+
import { AnimationClip, Object3D } from 'three';
|
|
3
|
+
import { loadCharacterModel } from '../model/index.js';
|
|
4
|
+
export declare function fixModelAnimationClip(model: Exclude<Awaited<ReturnType<typeof loadCharacterModel>>, undefined>, clip: AnimationClip, clipScene: Object3D, removeXZMovement: boolean, boneMap?: Record<string, VRMHumanBoneName>): void;
|
|
5
|
+
export * from './gltf.js';
|
|
6
|
+
export * from './mixamo.js';
|
|
7
|
+
export * from './vrma.js';
|
|
8
|
+
export * from './utils.js';
|
|
9
|
+
export type ModelAnimationOptions = {
|
|
10
|
+
type: 'mixamo' | 'gltf' | 'vrma';
|
|
11
|
+
url: string;
|
|
12
|
+
removeXZMovement?: boolean;
|
|
13
|
+
trimTime?: {
|
|
14
|
+
start?: number;
|
|
15
|
+
end?: number;
|
|
16
|
+
};
|
|
17
|
+
scaleTime?: number;
|
|
18
|
+
};
|
|
19
|
+
export declare function loadCharacterModelAnimation(model: Exclude<Awaited<ReturnType<typeof loadCharacterModel>>, undefined>, options: ModelAnimationOptions): Promise<AnimationClip>;
|
|
20
|
+
declare const simpleCharacterAnimationUrls: {
|
|
21
|
+
walk: () => Promise<typeof import("../assets/walk.js")>;
|
|
22
|
+
run: () => Promise<typeof import("../assets/run.js")>;
|
|
23
|
+
idle: () => Promise<typeof import("../assets/idle.js")>;
|
|
24
|
+
jumpUp: () => Promise<typeof import("../assets/jump-up.js")>;
|
|
25
|
+
jumpLoop: () => Promise<typeof import("../assets/jump-loop.js")>;
|
|
26
|
+
jumpDown: () => Promise<typeof import("../assets/jump-down.js")>;
|
|
27
|
+
jumpForward: () => Promise<typeof import("../assets/jump-forward.js")>;
|
|
28
|
+
};
|
|
29
|
+
export declare const simpleCharacterAnimationNames: Array<keyof typeof simpleCharacterAnimationUrls>;
|
|
30
|
+
export declare function getSimpleCharacterModelAnimationOptions(animationName: keyof typeof simpleCharacterAnimationUrls): Promise<ModelAnimationOptions>;
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { VRM } from '@pixiv/three-vrm';
|
|
2
|
+
import { Euler, Quaternion, QuaternionKeyframeTrack, Vector3, VectorKeyframeTrack, } from 'three';
|
|
3
|
+
import { loadVrmModelGltfAnimations as loadModelGltfAnimations } from './gltf.js';
|
|
4
|
+
import { loadVrmModelMixamoAnimations as loadModelMixamoAnimations } from './mixamo.js';
|
|
5
|
+
import { scaleAnimationClipTime, trimAnimationClip } from './utils.js';
|
|
6
|
+
import { loadVrmModelVrmaAnimations } from './vrma.js';
|
|
7
|
+
import { cached } from '../utils.js';
|
|
8
|
+
const parentWorldVector = new Vector3();
|
|
9
|
+
const restRotationInverse = new Quaternion();
|
|
10
|
+
const parentRestWorldRotation = new Quaternion();
|
|
11
|
+
const parentRestWorldRotationInverse = new Quaternion();
|
|
12
|
+
const quaternion = new Quaternion();
|
|
13
|
+
const vector = new Vector3();
|
|
14
|
+
const nonVrmRotationOffset = new Quaternion().setFromEuler(new Euler(0, Math.PI, 0));
|
|
15
|
+
export function fixModelAnimationClip(model, clip, clipScene, removeXZMovement, boneMap) {
|
|
16
|
+
const hipsBoneName = boneMap == null ? 'hips' : Object.entries(boneMap).find(([, vrmBoneName]) => vrmBoneName === 'hips')?.[0];
|
|
17
|
+
if (hipsBoneName == null) {
|
|
18
|
+
throw new Error('Failed to determine hips bone name for VRM animation. Please check the bone map or animation file.');
|
|
19
|
+
}
|
|
20
|
+
const clipSceneHips = clipScene.getObjectByName(hipsBoneName);
|
|
21
|
+
const vrmHipsPosition = model instanceof VRM ? model.humanoid.normalizedRestPose.hips?.position : clipSceneHips?.position;
|
|
22
|
+
if (clipSceneHips == null || vrmHipsPosition == null) {
|
|
23
|
+
throw new Error('Failed to load VRM animation: missing animation hips object or VRM hips position.');
|
|
24
|
+
}
|
|
25
|
+
// Adjust with reference to hips height.
|
|
26
|
+
const motionHipsHeight = clipSceneHips.position.y;
|
|
27
|
+
const [_, vrmHipsHeight] = vrmHipsPosition;
|
|
28
|
+
const hipsPositionScale = vrmHipsHeight / motionHipsHeight;
|
|
29
|
+
for (const track of clip.tracks) {
|
|
30
|
+
// Convert each tracks for VRM use, and push to `tracks`
|
|
31
|
+
const [boneName, propertyName] = track.name.split('.');
|
|
32
|
+
const vrmBoneName = boneMap?.[boneName] ?? boneName;
|
|
33
|
+
const vrmNodeName = model instanceof VRM ? model.humanoid.getNormalizedBoneNode(vrmBoneName)?.name : vrmBoneName;
|
|
34
|
+
const bone = clipScene.getObjectByName(boneName);
|
|
35
|
+
if (vrmNodeName == null || bone == null || bone.parent == null) {
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
bone.getWorldQuaternion(restRotationInverse).invert();
|
|
39
|
+
bone.parent.getWorldQuaternion(parentRestWorldRotation);
|
|
40
|
+
parentRestWorldRotationInverse.copy(parentRestWorldRotation).invert();
|
|
41
|
+
bone.parent.getWorldPosition(parentWorldVector);
|
|
42
|
+
if (track instanceof QuaternionKeyframeTrack) {
|
|
43
|
+
// Store rotations of rest-pose.
|
|
44
|
+
for (let i = 0; i < track.values.length; i += 4) {
|
|
45
|
+
quaternion.fromArray(track.values, i);
|
|
46
|
+
if (model instanceof VRM) {
|
|
47
|
+
quaternion.premultiply(parentRestWorldRotation).multiply(restRotationInverse);
|
|
48
|
+
if (model.meta.metaVersion === '0') {
|
|
49
|
+
quaternion.x *= -1;
|
|
50
|
+
quaternion.z *= -1;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
if (vrmBoneName === 'root') {
|
|
54
|
+
quaternion.multiply(nonVrmRotationOffset);
|
|
55
|
+
}
|
|
56
|
+
if (removeXZMovement) {
|
|
57
|
+
//TODO
|
|
58
|
+
}
|
|
59
|
+
quaternion.toArray(track.values, i);
|
|
60
|
+
}
|
|
61
|
+
track.name = `${vrmNodeName}.${propertyName}`;
|
|
62
|
+
}
|
|
63
|
+
else if (track instanceof VectorKeyframeTrack) {
|
|
64
|
+
track.name = `${vrmNodeName}.${propertyName}`;
|
|
65
|
+
if (propertyName === 'scale') {
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
for (let i = 0; i < track.values.length; i += 3) {
|
|
69
|
+
vector.fromArray(track.values, i);
|
|
70
|
+
vector.multiplyScalar(hipsPositionScale);
|
|
71
|
+
if (model instanceof VRM) {
|
|
72
|
+
if (model.meta.metaVersion === '0') {
|
|
73
|
+
vector.negate();
|
|
74
|
+
vector.y *= -1;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (vrmBoneName === 'hips' && removeXZMovement) {
|
|
78
|
+
vector.x = 0;
|
|
79
|
+
vector.z = 0;
|
|
80
|
+
}
|
|
81
|
+
vector.toArray(track.values, i);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
export * from './gltf.js';
|
|
87
|
+
export * from './mixamo.js';
|
|
88
|
+
export * from './vrma.js';
|
|
89
|
+
export * from './utils.js';
|
|
90
|
+
async function uncachedLoadModelAnimation(model, type, url, removeXZMovement, trimStartTime, trimEndTime, scaleTime) {
|
|
91
|
+
let clips;
|
|
92
|
+
switch (type) {
|
|
93
|
+
case 'gltf':
|
|
94
|
+
clips = await loadModelGltfAnimations(model, url, removeXZMovement);
|
|
95
|
+
break;
|
|
96
|
+
case 'mixamo':
|
|
97
|
+
clips = await loadModelMixamoAnimations(model, url, removeXZMovement);
|
|
98
|
+
break;
|
|
99
|
+
case 'vrma':
|
|
100
|
+
if (!(model instanceof VRM)) {
|
|
101
|
+
throw new Error(`Model must be an instance of VRM to load VRMA animations`);
|
|
102
|
+
}
|
|
103
|
+
clips = await loadVrmModelVrmaAnimations(model, url, removeXZMovement);
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
if (clips.length != 1) {
|
|
107
|
+
throw new Error(`Expected exactly one animation clip, but got ${clips.length} for url ${url}`);
|
|
108
|
+
}
|
|
109
|
+
const [clip] = clips;
|
|
110
|
+
if (trimStartTime != null || trimEndTime != null) {
|
|
111
|
+
trimAnimationClip(clip, trimStartTime, trimEndTime);
|
|
112
|
+
}
|
|
113
|
+
if (scaleTime != null) {
|
|
114
|
+
scaleAnimationClipTime(clip, scaleTime);
|
|
115
|
+
}
|
|
116
|
+
return clip;
|
|
117
|
+
}
|
|
118
|
+
export function loadCharacterModelAnimation(model, options) {
|
|
119
|
+
return cached(uncachedLoadModelAnimation, [
|
|
120
|
+
model,
|
|
121
|
+
options.type,
|
|
122
|
+
options.url,
|
|
123
|
+
options.removeXZMovement ?? false,
|
|
124
|
+
options.trimTime?.start,
|
|
125
|
+
options.trimTime?.end,
|
|
126
|
+
options.scaleTime,
|
|
127
|
+
]);
|
|
128
|
+
}
|
|
129
|
+
const extraOptions = {
|
|
130
|
+
walk: { scaleTime: 0.5 },
|
|
131
|
+
run: { scaleTime: 0.8 },
|
|
132
|
+
jumpForward: { scaleTime: 0.9 },
|
|
133
|
+
};
|
|
134
|
+
const simpleCharacterAnimationUrls = {
|
|
135
|
+
walk: () => import('../assets/walk.js'),
|
|
136
|
+
run: () => import('../assets/run.js'),
|
|
137
|
+
idle: () => import('../assets/idle.js'),
|
|
138
|
+
jumpUp: () => import('../assets/jump-up.js'),
|
|
139
|
+
jumpLoop: () => import('../assets/jump-loop.js'),
|
|
140
|
+
jumpDown: () => import('../assets/jump-down.js'),
|
|
141
|
+
jumpForward: () => import('../assets/jump-forward.js'),
|
|
142
|
+
};
|
|
143
|
+
export const simpleCharacterAnimationNames = Object.keys(simpleCharacterAnimationUrls);
|
|
144
|
+
export async function getSimpleCharacterModelAnimationOptions(animationName) {
|
|
145
|
+
return {
|
|
146
|
+
type: 'gltf',
|
|
147
|
+
...extraOptions[animationName],
|
|
148
|
+
url: (await simpleCharacterAnimationUrls[animationName]()).url,
|
|
149
|
+
};
|
|
150
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"mixamorigHips": "hips",
|
|
3
|
+
"mixamorigSpine": "spine",
|
|
4
|
+
"mixamorigSpine1": "chest",
|
|
5
|
+
"mixamorigSpine2": "upperChest",
|
|
6
|
+
"mixamorigNeck": "neck",
|
|
7
|
+
"mixamorigHead": "head",
|
|
8
|
+
"mixamorigLeftShoulder": "leftShoulder",
|
|
9
|
+
"mixamorigLeftArm": "leftUpperArm",
|
|
10
|
+
"mixamorigLeftForeArm": "leftLowerArm",
|
|
11
|
+
"mixamorigLeftHand": "leftHand",
|
|
12
|
+
"mixamorigLeftHandThumb1": "leftThumbMetacarpal",
|
|
13
|
+
"mixamorigLeftHandThumb2": "leftThumbProximal",
|
|
14
|
+
"mixamorigLeftHandThumb3": "leftThumbDistal",
|
|
15
|
+
"mixamorigLeftHandIndex1": "leftIndexProximal",
|
|
16
|
+
"mixamorigLeftHandIndex2": "leftIndexIntermediate",
|
|
17
|
+
"mixamorigLeftHandIndex3": "leftIndexDistal",
|
|
18
|
+
"mixamorigLeftHandMiddle1": "leftMiddleProximal",
|
|
19
|
+
"mixamorigLeftHandMiddle2": "leftMiddleIntermediate",
|
|
20
|
+
"mixamorigLeftHandMiddle3": "leftMiddleDistal",
|
|
21
|
+
"mixamorigLeftHandRing1": "leftRingProximal",
|
|
22
|
+
"mixamorigLeftHandRing2": "leftRingIntermediate",
|
|
23
|
+
"mixamorigLeftHandRing3": "leftRingDistal",
|
|
24
|
+
"mixamorigLeftHandPinky1": "leftLittleProximal",
|
|
25
|
+
"mixamorigLeftHandPinky2": "leftLittleIntermediate",
|
|
26
|
+
"mixamorigLeftHandPinky3": "leftLittleDistal",
|
|
27
|
+
"mixamorigRightShoulder": "rightShoulder",
|
|
28
|
+
"mixamorigRightArm": "rightUpperArm",
|
|
29
|
+
"mixamorigRightForeArm": "rightLowerArm",
|
|
30
|
+
"mixamorigRightHand": "rightHand",
|
|
31
|
+
"mixamorigRightHandPinky1": "rightLittleProximal",
|
|
32
|
+
"mixamorigRightHandPinky2": "rightLittleIntermediate",
|
|
33
|
+
"mixamorigRightHandPinky3": "rightLittleDistal",
|
|
34
|
+
"mixamorigRightHandRing1": "rightRingProximal",
|
|
35
|
+
"mixamorigRightHandRing2": "rightRingIntermediate",
|
|
36
|
+
"mixamorigRightHandRing3": "rightRingDistal",
|
|
37
|
+
"mixamorigRightHandMiddle1": "rightMiddleProximal",
|
|
38
|
+
"mixamorigRightHandMiddle2": "rightMiddleIntermediate",
|
|
39
|
+
"mixamorigRightHandMiddle3": "rightMiddleDistal",
|
|
40
|
+
"mixamorigRightHandIndex1": "rightIndexProximal",
|
|
41
|
+
"mixamorigRightHandIndex2": "rightIndexIntermediate",
|
|
42
|
+
"mixamorigRightHandIndex3": "rightIndexDistal",
|
|
43
|
+
"mixamorigRightHandThumb1": "rightThumbMetacarpal",
|
|
44
|
+
"mixamorigRightHandThumb2": "rightThumbProximal",
|
|
45
|
+
"mixamorigRightHandThumb3": "rightThumbDistal",
|
|
46
|
+
"mixamorigLeftUpLeg": "leftUpperLeg",
|
|
47
|
+
"mixamorigLeftLeg": "leftLowerLeg",
|
|
48
|
+
"mixamorigLeftFoot": "leftFoot",
|
|
49
|
+
"mixamorigLeftToeBase": "leftToes",
|
|
50
|
+
"mixamorigRightUpLeg": "rightUpperLeg",
|
|
51
|
+
"mixamorigRightLeg": "rightLowerLeg",
|
|
52
|
+
"mixamorigRightFoot": "rightFoot",
|
|
53
|
+
"mixamorigRightToeBase": "rightToes"
|
|
54
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { AnimationClip } from 'three';
|
|
2
|
+
import { loadCharacterModel } from '../model/index.js';
|
|
3
|
+
export declare function loadVrmModelMixamoAnimations(model: Exclude<Awaited<ReturnType<typeof loadCharacterModel>>, undefined>, url: string, removeXZMovement: boolean): Promise<Array<AnimationClip>>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { FBXLoader } from 'three/examples/jsm/Addons.js';
|
|
2
|
+
import { fixModelAnimationClip } from './index.js';
|
|
3
|
+
import mixamoBoneMap from './mixamo-bone-map.json';
|
|
4
|
+
const loader = new FBXLoader();
|
|
5
|
+
export async function loadVrmModelMixamoAnimations(model, url, removeXZMovement) {
|
|
6
|
+
const clipScene = await loader.loadAsync(url);
|
|
7
|
+
clipScene.animations.forEach((clip) => fixModelAnimationClip(model, clip, clipScene, removeXZMovement, mixamoBoneMap));
|
|
8
|
+
return clipScene.animations;
|
|
9
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
const changeSymbol = Symbol('was-changed');
|
|
2
|
+
function wasAlreadyChanged(value, id) {
|
|
3
|
+
if (value[changeSymbol] === id) {
|
|
4
|
+
return true;
|
|
5
|
+
}
|
|
6
|
+
value[changeSymbol] = id;
|
|
7
|
+
}
|
|
8
|
+
export function trimAnimationClip(originalClip, startTime = 0, endTime = originalClip.duration) {
|
|
9
|
+
const changeId = Math.random();
|
|
10
|
+
originalClip.duration = endTime - startTime;
|
|
11
|
+
originalClip.tracks.forEach((track) => {
|
|
12
|
+
if (wasAlreadyChanged(track.times, changeId)) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
track.shift(-startTime);
|
|
16
|
+
track.trim(0, originalClip.duration);
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
export function scaleAnimationClipTime(originalClip, scale) {
|
|
20
|
+
const changeId = Math.random();
|
|
21
|
+
originalClip.duration *= scale;
|
|
22
|
+
originalClip.tracks.forEach((track) => {
|
|
23
|
+
if (wasAlreadyChanged(track.times, changeId)) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
track.scale(scale);
|
|
27
|
+
});
|
|
28
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { createVRMAnimationClip } from '@pixiv/three-vrm-animation';
|
|
2
|
+
import { vrmaLoader } from '../index.js';
|
|
3
|
+
export async function loadVrmModelVrmaAnimations(vrm, url, removeXZMovement) {
|
|
4
|
+
const animations = await vrmaLoader.loadAsync(url);
|
|
5
|
+
const vrmAnimations = animations.userData.vrmAnimations;
|
|
6
|
+
const clips = vrmAnimations.map((vrmAnimation) => createVRMAnimationClip(vrmAnimation, vrm));
|
|
7
|
+
return clips;
|
|
8
|
+
}
|