@pmndrs/viverse 0.2.7 → 0.2.9

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.
@@ -7,6 +7,7 @@ export declare function fixModelAnimationClip(model: CharacterModel, clip: Anima
7
7
  export * from './utils.js';
8
8
  export * from './default.js';
9
9
  export * from './mask.js';
10
+ export * from './bone-map.js';
10
11
  export type CharacterAnimationOptions = {
11
12
  url: string | DefaultUrl;
12
13
  type?: 'mixamo' | 'gltf' | 'vrma' | 'fbx' | 'bvh';
@@ -24,6 +24,19 @@ 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)) {
@@ -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);
@@ -169,6 +181,7 @@ export function fixModelAnimationClip(model, clip, clipScene, removeXZMovement)
169
181
  export * from './utils.js';
170
182
  export * from './default.js';
171
183
  export * from './mask.js';
184
+ export * from './bone-map.js';
172
185
  export function flattenCharacterAnimationOptions(options) {
173
186
  return [
174
187
  options.url,
package/dist/utils.d.ts CHANGED
@@ -11,5 +11,5 @@ export type StartAnimationOptions = {
11
11
  crossFade?: boolean;
12
12
  layer?: string;
13
13
  };
14
- export declare function startAnimation(animation: AnimationAction, currentAnimations: CharacterModel['currentAnimations'], { crossFade, layer, fadeDuration, paused, sync }: StartAnimationOptions): (() => void) | undefined;
14
+ export declare function startAnimation(animation: AnimationAction, currentAnimations: CharacterModel['currentAnimations'], { crossFade, layer, fadeDuration, paused, sync }?: StartAnimationOptions): (() => void) | undefined;
15
15
  export declare function shouldJump(physics: BvhCharacterPhysics, lastJump: number, bufferTime?: number): boolean;
package/dist/utils.js CHANGED
@@ -8,7 +8,7 @@ export function getIsMobileMediaQuery() {
8
8
  export function isMobile() {
9
9
  return getIsMobileMediaQuery()?.matches ?? false;
10
10
  }
11
- export function startAnimation(animation, currentAnimations, { crossFade = true, layer, fadeDuration = 0.1, paused = false, sync = false }) {
11
+ export function startAnimation(animation, currentAnimations, { crossFade = true, layer, fadeDuration = 0.1, paused = false, sync = false } = {}) {
12
12
  animation.reset();
13
13
  animation.play();
14
14
  animation.paused = paused;
package/package.json CHANGED
@@ -21,7 +21,7 @@
21
21
  "peerDependencies": {
22
22
  "three": "*"
23
23
  },
24
- "version": "0.2.7",
24
+ "version": "0.2.9",
25
25
  "type": "module",
26
26
  "dependencies": {
27
27
  "@pixiv/three-vrm": "^3.4.2",