@pmndrs/viverse 0.2.6 → 0.2.8
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/dist/animation/bone-map.d.ts +2 -3
- package/dist/animation/bone-map.js +2 -2
- package/dist/animation/index.js +22 -10
- package/dist/model/index.d.ts +4 -1
- package/dist/model/index.js +10 -2
- package/dist/model/vrm.d.ts +1 -1
- package/dist/model/vrm.js +1 -1
- package/dist/utils.d.ts +2 -1
- package/package.json +1 -1
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { VRMHumanBoneName } from '@pixiv/three-vrm';
|
|
2
1
|
import { AnimationClip, Object3D } from 'three';
|
|
3
|
-
|
|
4
|
-
export declare function
|
|
2
|
+
import type { BoneMap } from '../utils.js';
|
|
3
|
+
export declare function applyAnimationBoneMap(clip: AnimationClip, clipScene: Object3D | undefined, boneMap: BoneMap): void;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export function
|
|
1
|
+
export function applyAnimationBoneMap(clip, clipScene, boneMap) {
|
|
2
2
|
for (const track of clip.tracks) {
|
|
3
3
|
const [clipBoneName, propertyName] = track.name.split('.');
|
|
4
4
|
const clipBone = clipScene?.getObjectByName(clipBoneName);
|
|
5
|
-
const normalizedBoneName =
|
|
5
|
+
const normalizedBoneName = boneMap?.[clipBoneName] ?? clipBoneName;
|
|
6
6
|
if (clipBone != null) {
|
|
7
7
|
clipBone.name = normalizedBoneName;
|
|
8
8
|
}
|
package/dist/animation/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import { Euler, Quaternion, QuaternionKeyframeTrack, Vector3, VectorKeyframeTrac
|
|
|
3
3
|
import { BVHLoader } from 'three/examples/jsm/loaders/BVHLoader.js';
|
|
4
4
|
import { FBXLoader } from 'three/examples/jsm/loaders/FBXLoader.js';
|
|
5
5
|
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js';
|
|
6
|
-
import {
|
|
6
|
+
import { applyAnimationBoneMap } from './bone-map.js';
|
|
7
7
|
import _bvhBoneMap from './bvh-bone-map.json';
|
|
8
8
|
import { resolveDefaultCharacterAnimationUrl } from './default.js';
|
|
9
9
|
import { applyMask } from './mask.js';
|
|
@@ -24,12 +24,25 @@ const position = new Vector3();
|
|
|
24
24
|
const nonVrmRotationOffset = new Quaternion().setFromEuler(new Euler(0, Math.PI, 0));
|
|
25
25
|
//TODO: currently assumes the model is not yet transformed - loaded for the first time
|
|
26
26
|
export function fixModelAnimationClip(model, clip, clipScene, removeXZMovement) {
|
|
27
|
+
clip.tracks = clip.tracks.filter((track) => {
|
|
28
|
+
if (track instanceof QuaternionKeyframeTrack) {
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
const [clipBoneName, propertyName] = track.name.split('.');
|
|
32
|
+
if (propertyName != 'position') {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
if (clipBoneName == 'hips' || clipBoneName == 'root') {
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
return false;
|
|
39
|
+
});
|
|
27
40
|
let restRoot;
|
|
28
41
|
let restRootParent;
|
|
29
42
|
if (!(model instanceof VRM)) {
|
|
30
|
-
restRoot = model.scene.getObjectByName('
|
|
43
|
+
restRoot = model.scene.getObjectByName('rest_hips')?.parent;
|
|
31
44
|
if (restRoot == null) {
|
|
32
|
-
throw new Error(`Model
|
|
45
|
+
throw new Error(`Model hips.parent not found.`);
|
|
33
46
|
}
|
|
34
47
|
restRootParent = restRoot?.parent;
|
|
35
48
|
restRoot.parent = null;
|
|
@@ -127,12 +140,6 @@ export function fixModelAnimationClip(model, clip, clipScene, removeXZMovement)
|
|
|
127
140
|
track.name = trackName;
|
|
128
141
|
}
|
|
129
142
|
else if (track instanceof VectorKeyframeTrack) {
|
|
130
|
-
if (clipBoneName != 'hips' && clipBoneName != 'root') {
|
|
131
|
-
continue;
|
|
132
|
-
}
|
|
133
|
-
if (propertyName != 'position') {
|
|
134
|
-
continue;
|
|
135
|
-
}
|
|
136
143
|
for (let i = 0; i < track.values.length; i += 3) {
|
|
137
144
|
position.fromArray(track.values, i);
|
|
138
145
|
if (clipSceneHips?.parent != null) {
|
|
@@ -143,6 +150,11 @@ export function fixModelAnimationClip(model, clip, clipScene, removeXZMovement)
|
|
|
143
150
|
position.multiplyScalar(clipSceneHips.parent.matrixWorld.getMaxScaleOnAxis());
|
|
144
151
|
}
|
|
145
152
|
}
|
|
153
|
+
const modelBone = model.scene.getObjectByName(`rest_${clipBoneName}`);
|
|
154
|
+
if (modelBone != null) {
|
|
155
|
+
modelBone.updateMatrixWorld();
|
|
156
|
+
position.divideScalar(modelBone.matrixWorld.getMaxScaleOnAxis());
|
|
157
|
+
}
|
|
146
158
|
position.multiplyScalar(positionScale);
|
|
147
159
|
if (!(model instanceof VRM) && clipBoneName === 'hips') {
|
|
148
160
|
position.applyQuaternion(nonVrmRotationOffset);
|
|
@@ -248,7 +260,7 @@ export async function loadCharacterAnimation(model, url, type, removeXZMovement
|
|
|
248
260
|
}
|
|
249
261
|
const [clip] = clips;
|
|
250
262
|
if (boneMap != null) {
|
|
251
|
-
|
|
263
|
+
applyAnimationBoneMap(clip, clipScene, boneMap);
|
|
252
264
|
}
|
|
253
265
|
if (mask != null) {
|
|
254
266
|
applyMask(clip, mask);
|
package/dist/model/index.d.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { AnimationAction, AnimationMixer, Object3D, Quaternion } from 'three';
|
|
2
|
+
import type { BoneMap } from '../utils.js';
|
|
3
|
+
import type { VRMHumanBoneName } from '@pixiv/three-vrm';
|
|
2
4
|
export { VRMHumanBoneName } from '@pixiv/three-vrm';
|
|
3
5
|
export * from './vrm.js';
|
|
4
6
|
export type CharacterModelOptions = {
|
|
5
7
|
readonly type?: 'vrm' | 'gltf';
|
|
8
|
+
readonly boneMap?: Record<string, VRMHumanBoneName>;
|
|
6
9
|
readonly url?: string;
|
|
7
10
|
/**
|
|
8
11
|
* allows to apply an rotation offset when placing objects as children of the character's bones
|
|
@@ -25,4 +28,4 @@ export type CharacterModel = {
|
|
|
25
28
|
currentAnimations: Map<string | undefined, AnimationAction>;
|
|
26
29
|
boneRotationOffset?: Quaternion;
|
|
27
30
|
};
|
|
28
|
-
export declare function loadCharacterModel(url?: string, type?: Exclude<CharacterModelOptions, boolean>['type'], boneRotationOffset?: Quaternion, castShadow?: boolean, receiveShadow?: boolean): Promise<CharacterModel>;
|
|
31
|
+
export declare function loadCharacterModel(url?: string, type?: Exclude<CharacterModelOptions, boolean>['type'], boneRotationOffset?: Quaternion, castShadow?: boolean, receiveShadow?: boolean, boneMap?: BoneMap): Promise<CharacterModel>;
|
package/dist/model/index.js
CHANGED
|
@@ -7,9 +7,16 @@ export function flattenCharacterModelOptions(options) {
|
|
|
7
7
|
if (options == null) {
|
|
8
8
|
return [];
|
|
9
9
|
}
|
|
10
|
-
return [
|
|
10
|
+
return [
|
|
11
|
+
options.url,
|
|
12
|
+
options.type,
|
|
13
|
+
options.boneRotationOffset,
|
|
14
|
+
options.castShadow,
|
|
15
|
+
options.receiveShadow,
|
|
16
|
+
options.boneMap,
|
|
17
|
+
];
|
|
11
18
|
}
|
|
12
|
-
export async function loadCharacterModel(url, type, boneRotationOffset, castShadow = true, receiveShadow = true) {
|
|
19
|
+
export async function loadCharacterModel(url, type, boneRotationOffset, castShadow = true, receiveShadow = true, boneMap) {
|
|
13
20
|
let result;
|
|
14
21
|
if (url == null) {
|
|
15
22
|
//prepare loading the default model
|
|
@@ -38,6 +45,7 @@ export async function loadCharacterModel(url, type, boneRotationOffset, castShad
|
|
|
38
45
|
}
|
|
39
46
|
result.boneRotationOffset = boneRotationOffset;
|
|
40
47
|
result.scene.traverse((obj) => {
|
|
48
|
+
obj.name = boneMap?.[obj.name] ?? obj.name;
|
|
41
49
|
obj.frustumCulled = false;
|
|
42
50
|
if (castShadow) {
|
|
43
51
|
obj.castShadow = true;
|
package/dist/model/vrm.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { VRM } from '@pixiv/three-vrm';
|
|
2
2
|
import { Object3D, Object3DEventMap } from 'three';
|
|
3
|
-
import { GLTFLoader } from 'three/examples/jsm/
|
|
3
|
+
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js';
|
|
4
4
|
export declare const vrmaLoader: GLTFLoader;
|
|
5
5
|
export declare function loadVrmCharacterModel(url: string): Promise<VRM & {
|
|
6
6
|
scene: Object3D<Object3DEventMap & {
|
package/dist/model/vrm.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { VRMLoaderPlugin, VRMUtils } from '@pixiv/three-vrm';
|
|
2
2
|
import { VRMAnimationLoaderPlugin } from '@pixiv/three-vrm-animation';
|
|
3
|
-
import { GLTFLoader } from 'three/examples/jsm/
|
|
3
|
+
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js';
|
|
4
4
|
export const vrmaLoader = new GLTFLoader();
|
|
5
5
|
vrmaLoader.register((parser) => new VRMLoaderPlugin(parser, { autoUpdateHumanBones: true }));
|
|
6
6
|
vrmaLoader.register((parser) => new VRMAnimationLoaderPlugin(parser));
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import type { CharacterModel } from './model/index.js';
|
|
1
|
+
import type { CharacterModel, VRMHumanBoneName } from './model/index.js';
|
|
2
2
|
import type { BvhCharacterPhysics } from './physics/index.js';
|
|
3
3
|
import type { AnimationAction } from 'three';
|
|
4
|
+
export type BoneMap = Record<string, VRMHumanBoneName>;
|
|
4
5
|
export declare function getIsMobileMediaQuery(): MediaQueryList | undefined;
|
|
5
6
|
export declare function isMobile(): boolean;
|
|
6
7
|
export type StartAnimationOptions = {
|