@react-three/viverse 0.1.14 → 0.1.15

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.
@@ -27,8 +27,18 @@ export declare const FixedBvhPhysicsBody: import("react").ForwardRefExoticCompon
27
27
  children?: ReactNode;
28
28
  } & import("react").RefAttributes<Object3D<import("three").Object3DEventMap>>>;
29
29
  /**
30
- * allows to add all children as static (non-moving) objects to the bvh physics world
31
- * @requires that the inner content is not dynamic
30
+ * allows to add all children as static (non-moving) objects as sensors to the bvh physics world
31
+ * @requires that the structure of the inner content is not changing or has a suspense boundary
32
+ * do not wrap the content inside in a suspense!
33
+ */
34
+ export declare const BvhPhysicsSensor: import("react").ForwardRefExoticComponent<{
35
+ children?: ReactNode;
36
+ isStatic?: boolean;
37
+ onIntersectedChanged?: (intersected: boolean) => void;
38
+ } & import("react").RefAttributes<Object3D<import("three").Object3DEventMap>>>;
39
+ /**
40
+ * allows to add all children as static (non-moving) or kinematic (moving) objects as obstacles to the bvh physics world
41
+ * @requires that the structure of the inner content is not changing or has a suspense boundary
32
42
  * do not wrap the content inside in a suspense!
33
43
  */
34
44
  export declare const BvhPhysicsBody: import("react").ForwardRefExoticComponent<{
package/dist/character.js CHANGED
@@ -92,8 +92,32 @@ export const FixedBvhPhysicsBody = forwardRef(({ children }, ref) => {
92
92
  return _jsxs(BvhPhysicsBody, { children: [" ", children] });
93
93
  });
94
94
  /**
95
- * allows to add all children as static (non-moving) objects to the bvh physics world
96
- * @requires that the inner content is not dynamic
95
+ * allows to add all children as static (non-moving) objects as sensors to the bvh physics world
96
+ * @requires that the structure of the inner content is not changing or has a suspense boundary
97
+ * do not wrap the content inside in a suspense!
98
+ */
99
+ export const BvhPhysicsSensor = forwardRef(({ children, isStatic = true, onIntersectedChanged }, ref) => {
100
+ const world = useContext(BvhPhyiscsWorldContext);
101
+ if (world == null) {
102
+ throw new Error('BvhPhysicsSensor must be used within a BvhPhysicsWorld component');
103
+ }
104
+ const internalRef = useRef(null);
105
+ const listenerRef = useRef(onIntersectedChanged);
106
+ listenerRef.current = onIntersectedChanged;
107
+ useEffect(() => {
108
+ const body = internalRef.current;
109
+ if (body == null) {
110
+ return;
111
+ }
112
+ world.addSensor(body, isStatic, (intersected) => listenerRef.current?.(intersected));
113
+ return () => world.removeSensor(body);
114
+ }, [world, isStatic]);
115
+ useImperativeHandle(ref, () => internalRef.current, []);
116
+ return _jsx("group", { ref: internalRef, children: children });
117
+ });
118
+ /**
119
+ * allows to add all children as static (non-moving) or kinematic (moving) objects as obstacles to the bvh physics world
120
+ * @requires that the structure of the inner content is not changing or has a suspense boundary
97
121
  * do not wrap the content inside in a suspense!
98
122
  */
99
123
  export const BvhPhysicsBody = forwardRef(({ children, kinematic = false }, ref) => {
package/dist/index.d.ts CHANGED
@@ -20,7 +20,7 @@ export declare function Viverse({ children, loginRequired, checkAuth, ...options
20
20
  /**
21
21
  * Hook to access the Viverse client instance for making API calls.
22
22
  */
23
- export declare function useViverseClient(): Client;
23
+ export declare function useViverseClient(): Client | undefined;
24
24
  /**
25
25
  * Hook to access the current authentication state.
26
26
  */
package/dist/index.js CHANGED
@@ -65,11 +65,7 @@ export function Viverse({ children, loginRequired = false, checkAuth, ...options
65
65
  * Hook to access the Viverse client instance for making API calls.
66
66
  */
67
67
  export function useViverseClient() {
68
- const client = useContext(ViverseClientContext);
69
- if (client == null) {
70
- throw new Error('Viverse client is not available in context. Did you forget to wrap your component tree with <Viverse>?');
71
- }
72
- return client;
68
+ return useContext(ViverseClientContext);
73
69
  }
74
70
  /**
75
71
  * Hook to access the current authentication state.
@@ -98,6 +94,10 @@ export function useViverseProfile() {
98
94
  export function useViverseLogin() {
99
95
  const client = useViverseClient();
100
96
  return useCallback((...params) => {
97
+ if (client == null) {
98
+ console.warn(`useViverseLogin was called without an available client either because not Viverse provider is available or because no client id was provided to the Viverse provider`);
99
+ return;
100
+ }
101
101
  clearViverseAuthCheck();
102
102
  client.loginWithWorlds(...params);
103
103
  }, [client]);
@@ -108,6 +108,10 @@ export function useViverseLogin() {
108
108
  export function useViverseLogout() {
109
109
  const client = useViverseClient();
110
110
  return useCallback((...params) => {
111
+ if (client == null) {
112
+ console.warn(`useViverseLogout was called without an available client either because not Viverse provider is available or because no client id was provided to the Viverse provider`);
113
+ return;
114
+ }
111
115
  clearViverseAuthCheck();
112
116
  client.logoutWithWorlds(...params);
113
117
  }, [client]);
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.14"
31
+ "@pmndrs/viverse": "^0.1.15"
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.14",
42
+ "version": "0.1.15",
43
43
  "scripts": {
44
44
  "build": "tsc",
45
45
  "check:prettier": "prettier --check src",