@react-three/viverse 0.1.16 → 0.1.18
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/README.md +2 -0
- package/dist/character.js +12 -9
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/mobile.d.ts +1 -0
- package/dist/mobile.js +15 -0
- package/package.json +2 -2
package/README.md
CHANGED
package/dist/character.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { VRM } from '@pixiv/three-vrm';
|
|
3
|
-
import { BvhPhysicsWorld as BvhPhysicsWorldImpl, SimpleCharacter as SimpleCharacterImpl, preloadSimpleCharacterAssets, simpleCharacterAnimationNames, InputSystem, LocomotionKeyboardInput, PointerCaptureInput, } from '@pmndrs/viverse';
|
|
4
|
-
import { useFrame, useThree, extend, createPortal } from '@react-three/fiber';
|
|
5
|
-
import { createContext, forwardRef, Fragment, useContext, useEffect, useImperativeHandle, useMemo, useRef, useState, } from 'react';
|
|
3
|
+
import { BvhPhysicsWorld as BvhPhysicsWorldImpl, SimpleCharacter as SimpleCharacterImpl, preloadSimpleCharacterAssets, simpleCharacterAnimationNames, InputSystem, LocomotionKeyboardInput, PointerCaptureInput, ScreenJoystickInput, ScreenJumpButtonInput, extractProxy, } from '@pmndrs/viverse';
|
|
4
|
+
import { useFrame, useThree, extend, createPortal, useStore } from '@react-three/fiber';
|
|
5
|
+
import { createContext, forwardRef, Fragment, useCallback, useContext, useEffect, useImperativeHandle, useMemo, useRef, useState, } from 'react';
|
|
6
6
|
import { clear, suspend } from 'suspend-react';
|
|
7
7
|
import { create } from 'zustand';
|
|
8
8
|
import { useViverseActiveAvatar } from './index.js';
|
|
@@ -20,15 +20,15 @@ const PreloadSimpleCharacterAssetsSymbol = Symbol('preload-simple-character-asse
|
|
|
20
20
|
/**
|
|
21
21
|
* creates a simple character controller supporting running, walking, and jumping with a default avatar and animations with can be configutred
|
|
22
22
|
*/
|
|
23
|
-
export const SimpleCharacter = forwardRef(({ children, useViverseAvatar = true, input, movement, model, physics, cameraBehavior, animation, ...groupProps }, ref) => {
|
|
23
|
+
export const SimpleCharacter = forwardRef(({ children, useViverseAvatar = true, input, movement, model, physics, cameraBehavior, animation, inputOptions, ...groupProps }, ref) => {
|
|
24
24
|
const avatar = useViverseActiveAvatar();
|
|
25
25
|
const world = useContext(BvhPhyiscsWorldContext);
|
|
26
26
|
if (world == null) {
|
|
27
27
|
throw new Error('SimpleCharacter must be used within a BvhPhysicsWorld component');
|
|
28
28
|
}
|
|
29
|
-
const camera = useThree((s) => s.camera);
|
|
30
29
|
const domElement = useThree((s) => s.gl.domElement);
|
|
31
30
|
const newOptions = {
|
|
31
|
+
inputOptions,
|
|
32
32
|
movement,
|
|
33
33
|
physics,
|
|
34
34
|
cameraBehavior,
|
|
@@ -59,8 +59,9 @@ export const SimpleCharacter = forwardRef(({ children, useViverseAvatar = true,
|
|
|
59
59
|
if (internalRef.current == null) {
|
|
60
60
|
return;
|
|
61
61
|
}
|
|
62
|
+
internalRef.current.inputSystem.dispose();
|
|
62
63
|
if (input == null || 'length' in input) {
|
|
63
|
-
internalRef.current.inputSystem = new InputSystem(domElement, input ?? [
|
|
64
|
+
internalRef.current.inputSystem = new InputSystem(domElement, input ?? [ScreenJoystickInput, ScreenJumpButtonInput, PointerCaptureInput, LocomotionKeyboardInput], extractProxy(currentOptions, 'inputOptions'));
|
|
64
65
|
return;
|
|
65
66
|
}
|
|
66
67
|
internalRef.current.inputSystem = input;
|
|
@@ -79,11 +80,13 @@ export const SimpleCharacter = forwardRef(({ children, useViverseAvatar = true,
|
|
|
79
80
|
store.setState({ model: simpleCharacter.model });
|
|
80
81
|
}
|
|
81
82
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
82
|
-
}, [
|
|
83
|
+
}, [world, domElement, currentOptions]);
|
|
83
84
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
84
|
-
useImperativeHandle(ref, () => internalRef.current, [
|
|
85
|
+
useImperativeHandle(ref, () => internalRef.current, [world, domElement, currentOptions]);
|
|
85
86
|
useFrame((_, delta) => internalRef.current?.update(delta));
|
|
86
|
-
|
|
87
|
+
const r3fStore = useStore();
|
|
88
|
+
const getCamera = useCallback(() => r3fStore.getState().camera, [r3fStore]);
|
|
89
|
+
return (_jsx("simpleCharacterImpl", { ...groupProps, args: [getCamera, world, domElement, currentOptions], ref: internalRef, children: _jsx(CharacterModelStoreContext.Provider, { value: store, children: children }) }));
|
|
87
90
|
});
|
|
88
91
|
/**
|
|
89
92
|
* @deprecated use <BvhPhysicsBody kinematic={false} /> instead (kinematic={false} can be skipped as its the default)
|
package/dist/index.d.ts
CHANGED
|
@@ -69,7 +69,8 @@ export declare function useViversePublicAvatarList(): Awaited<ReturnType<AvatarC
|
|
|
69
69
|
export declare function useViversePublicAvatarByID(id: string): Awaited<ReturnType<AvatarClient['getPublicAvatarByID']>> | undefined;
|
|
70
70
|
export * from './character.js';
|
|
71
71
|
export * from './material.js';
|
|
72
|
-
export { FirstPersonCharacterCameraBehavior, SimpleCharacter as SimpleCharacterImpl, LocomotionKeyboardInput, PointerCaptureInput, PointerLockInput, VRMHumanBoneName, } from '@pmndrs/viverse';
|
|
72
|
+
export { FirstPersonCharacterCameraBehavior, SimpleCharacter as SimpleCharacterImpl, LocomotionKeyboardInput, PointerCaptureInput, PointerLockInput, type InputField, InputSystem, type LocomotionKeyboardInputOptions, type PointerLockInputOptions, type PointerCaptureInputOptions, ScreenJoystickInput, type ScreenJoystickInputOptions, type SimpleCharacterInputOptions, ScreenJumpButtonInput, VRMHumanBoneName, } from '@pmndrs/viverse';
|
|
73
73
|
export * from '@viverse/sdk';
|
|
74
74
|
export * from '@viverse/sdk/avatar-client';
|
|
75
75
|
export * from './gamepad.js';
|
|
76
|
+
export * from './mobile.js';
|
package/dist/index.js
CHANGED
|
@@ -154,7 +154,8 @@ export function useViversePublicAvatarByID(id) {
|
|
|
154
154
|
}
|
|
155
155
|
export * from './character.js';
|
|
156
156
|
export * from './material.js';
|
|
157
|
-
export { FirstPersonCharacterCameraBehavior, SimpleCharacter as SimpleCharacterImpl, LocomotionKeyboardInput, PointerCaptureInput, PointerLockInput, VRMHumanBoneName, } from '@pmndrs/viverse';
|
|
157
|
+
export { FirstPersonCharacterCameraBehavior, SimpleCharacter as SimpleCharacterImpl, LocomotionKeyboardInput, PointerCaptureInput, PointerLockInput, InputSystem, ScreenJoystickInput, ScreenJumpButtonInput, VRMHumanBoneName, } from '@pmndrs/viverse';
|
|
158
158
|
export * from '@viverse/sdk';
|
|
159
159
|
export * from '@viverse/sdk/avatar-client';
|
|
160
160
|
export * from './gamepad.js';
|
|
161
|
+
export * from './mobile.js';
|
package/dist/mobile.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function useIsMobile(): boolean;
|
package/dist/mobile.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { getIsMobileMediaQuery } from '@pmndrs/viverse';
|
|
2
|
+
import { useSyncExternalStore } from 'react';
|
|
3
|
+
export function useIsMobile() {
|
|
4
|
+
const subscribe = (onStoreChange) => {
|
|
5
|
+
const mediaQuery = getIsMobileMediaQuery();
|
|
6
|
+
if (mediaQuery == null)
|
|
7
|
+
return () => { };
|
|
8
|
+
const handler = () => onStoreChange();
|
|
9
|
+
mediaQuery.addEventListener('change', handler);
|
|
10
|
+
return () => mediaQuery.removeEventListener('change', handler);
|
|
11
|
+
};
|
|
12
|
+
const getSnapshot = () => getIsMobileMediaQuery()?.matches ?? false;
|
|
13
|
+
const getServerSnapshot = () => false;
|
|
14
|
+
return useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);
|
|
15
|
+
}
|
package/package.json
CHANGED
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"@pixiv/three-vrm": "^3.4.2",
|
|
29
29
|
"zustand": "^5.0.6",
|
|
30
30
|
"@react-three/xr": "^6.6.20",
|
|
31
|
-
"@pmndrs/viverse": "^0.1.
|
|
31
|
+
"@pmndrs/viverse": "^0.1.18"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
34
|
"@react-three/fiber": "*"
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"@types/react": "^19.1.8",
|
|
40
40
|
"react": "^19.1.0"
|
|
41
41
|
},
|
|
42
|
-
"version": "0.1.
|
|
42
|
+
"version": "0.1.18",
|
|
43
43
|
"scripts": {
|
|
44
44
|
"build": "tsc",
|
|
45
45
|
"check:prettier": "prettier --check src",
|