@pmndrs/viverse 0.2.6 → 0.2.7

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.
@@ -1,4 +1,3 @@
1
- import { VRMHumanBoneName } from '@pixiv/three-vrm';
2
1
  import { AnimationClip, Object3D } from 'three';
3
- export type BoneMap = Record<string, VRMHumanBoneName>;
4
- export declare function applyBoneMap(clip: AnimationClip, clipScene: Object3D | undefined, boneMap: BoneMap): void;
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 applyBoneMap(clip, clipScene, boneMap) {
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 = (boneMap?.[clipBoneName] ?? clipBoneName);
5
+ const normalizedBoneName = boneMap?.[clipBoneName] ?? clipBoneName;
6
6
  if (clipBone != null) {
7
7
  clipBone.name = normalizedBoneName;
8
8
  }
@@ -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 { applyBoneMap } from './bone-map.js';
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';
@@ -27,9 +27,9 @@ export function fixModelAnimationClip(model, clip, clipScene, removeXZMovement)
27
27
  let restRoot;
28
28
  let restRootParent;
29
29
  if (!(model instanceof VRM)) {
30
- restRoot = model.scene.getObjectByName('rest_root');
30
+ restRoot = model.scene.getObjectByName('rest_hips')?.parent;
31
31
  if (restRoot == null) {
32
- throw new Error(`Model rest root not found.`);
32
+ throw new Error(`Model hips.parent not found.`);
33
33
  }
34
34
  restRootParent = restRoot?.parent;
35
35
  restRoot.parent = null;
@@ -248,7 +248,7 @@ export async function loadCharacterAnimation(model, url, type, removeXZMovement
248
248
  }
249
249
  const [clip] = clips;
250
250
  if (boneMap != null) {
251
- applyBoneMap(clip, clipScene, boneMap);
251
+ applyAnimationBoneMap(clip, clipScene, boneMap);
252
252
  }
253
253
  if (mask != null) {
254
254
  applyMask(clip, mask);
@@ -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>;
@@ -7,9 +7,16 @@ export function flattenCharacterModelOptions(options) {
7
7
  if (options == null) {
8
8
  return [];
9
9
  }
10
- return [options.url, options.type, options.boneRotationOffset, options.castShadow, options.receiveShadow];
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;
@@ -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/Addons.js';
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/Addons.js';
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 = {
package/package.json CHANGED
@@ -21,7 +21,7 @@
21
21
  "peerDependencies": {
22
22
  "three": "*"
23
23
  },
24
- "version": "0.2.6",
24
+ "version": "0.2.7",
25
25
  "type": "module",
26
26
  "dependencies": {
27
27
  "@pixiv/three-vrm": "^3.4.2",