@pmndrs/viverse 0.2.8 → 0.2.10
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/index.d.ts +1 -0
- package/dist/animation/index.js +1 -0
- package/dist/utils.d.ts +2 -2
- package/dist/utils.js +20 -8
- package/package.json +1 -1
|
@@ -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';
|
package/dist/animation/index.js
CHANGED
|
@@ -181,6 +181,7 @@ export function fixModelAnimationClip(model, clip, clipScene, removeXZMovement)
|
|
|
181
181
|
export * from './utils.js';
|
|
182
182
|
export * from './default.js';
|
|
183
183
|
export * from './mask.js';
|
|
184
|
+
export * from './bone-map.js';
|
|
184
185
|
export function flattenCharacterAnimationOptions(options) {
|
|
185
186
|
return [
|
|
186
187
|
options.url,
|
package/dist/utils.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export type StartAnimationOptions = {
|
|
|
9
9
|
sync?: boolean;
|
|
10
10
|
paused?: boolean;
|
|
11
11
|
crossFade?: boolean;
|
|
12
|
-
layer?: string
|
|
12
|
+
layer?: string | Array<string | undefined>;
|
|
13
13
|
};
|
|
14
|
-
export declare function startAnimation(animation: AnimationAction, currentAnimations: CharacterModel['currentAnimations'], { crossFade, layer, fadeDuration, paused, sync }
|
|
14
|
+
export declare function startAnimation(animation: AnimationAction, currentAnimations: CharacterModel['currentAnimations'], { crossFade, layer: layers, 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: layers, fadeDuration = 0.1, paused = false, sync = false } = {}) {
|
|
12
12
|
animation.reset();
|
|
13
13
|
animation.play();
|
|
14
14
|
animation.paused = paused;
|
|
@@ -18,17 +18,29 @@ export function startAnimation(animation, currentAnimations, { crossFade = true,
|
|
|
18
18
|
animation.fadeOut(fadeDuration);
|
|
19
19
|
};
|
|
20
20
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
animation.syncWith(currentAnimation);
|
|
21
|
+
if (!Array.isArray(layers)) {
|
|
22
|
+
layers = [layers];
|
|
24
23
|
}
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
//deduplicated set of current animations
|
|
25
|
+
const resolvedCurrentAnimations = new Set(layers.map((layer) => currentAnimations.get(layer)).filter((animation) => animation != null));
|
|
26
|
+
//sync with current animation if there is exactly one current animation that is not equal to the new animation
|
|
27
|
+
if (resolvedCurrentAnimations.size === 1 && !resolvedCurrentAnimations.has(animation) && sync) {
|
|
28
|
+
const [currentAnimation] = resolvedCurrentAnimations;
|
|
29
|
+
animation.syncWith(currentAnimation);
|
|
27
30
|
}
|
|
28
|
-
|
|
31
|
+
//fade in only if not already playing the new animation
|
|
32
|
+
if (!resolvedCurrentAnimations.has(animation)) {
|
|
29
33
|
animation.fadeIn(fadeDuration);
|
|
30
34
|
}
|
|
31
|
-
|
|
35
|
+
//fading out all animations except for the new animation
|
|
36
|
+
resolvedCurrentAnimations.delete(animation);
|
|
37
|
+
for (const currentAnimation of resolvedCurrentAnimations) {
|
|
38
|
+
currentAnimation.fadeOut(fadeDuration);
|
|
39
|
+
}
|
|
40
|
+
//write the new animation to all the layers, if current and new animations are all the same, its just writing the same content again
|
|
41
|
+
for (const layer of layers) {
|
|
42
|
+
currentAnimations.set(layer, animation);
|
|
43
|
+
}
|
|
32
44
|
}
|
|
33
45
|
export function shouldJump(physics, lastJump, bufferTime = 0.1) {
|
|
34
46
|
if (!physics.isGrounded) {
|