Skip to content

Commit 39e145f

Browse files
authored
Merge pull request #162 from musehq/dev
v2.10.4
2 parents 3aa7edf + bb0a94d commit 39e145f

File tree

8 files changed

+42
-33
lines changed

8 files changed

+42
-33
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "spacesvr",
3-
"version": "2.10.3",
3+
"version": "2.10.4",
44
"private": true,
55
"description": "A standardized reality for future of the 3D Web",
66
"keywords": [

src/ideas/modifiers/Tool/index.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ type ToolProps = {
1616
range?: number;
1717
orderIndex?: number;
1818
bobStrength?: number;
19+
disableDraggable?: boolean;
1920
onSwitch?: (enabled: boolean) => void;
2021
};
2122

@@ -38,6 +39,7 @@ export function Tool(props: ToolProps) {
3839
range,
3940
bobStrength,
4041
orderIndex,
42+
disableDraggable = false,
4143
onSwitch,
4244
} = props;
4345

@@ -74,7 +76,12 @@ export function Tool(props: ToolProps) {
7476
range={range}
7577
bobStrength={bobStrength}
7678
>
77-
<OnScreen distance={DISTANCE} name={name} pos={pos}>
79+
<OnScreen
80+
distance={DISTANCE}
81+
name={name}
82+
pos={pos}
83+
disableDraggable={disableDraggable}
84+
>
7885
<FacePlayer enabled={face}>{visible && children}</FacePlayer>
7986
</OnScreen>
8087
</HUD>

src/ideas/modifiers/Tool/modifiers/OnScreen.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ type OnScreenProps = {
1010
distance: number;
1111
name: string;
1212
pos: [number, number];
13+
disableDraggable: boolean;
1314
children: ReactNode | ReactNode[];
1415
};
1516

1617
export default function OnScreen(props: OnScreenProps) {
17-
const { distance, name, pos, children } = props;
18+
const { distance, name, pos, disableDraggable, children } = props;
1819

1920
const toolbelt = useToolbelt();
2021

@@ -80,7 +81,11 @@ export default function OnScreen(props: OnScreenProps) {
8081

8182
return (
8283
<animated.group position={spring.pos} name="onscreen">
83-
<Draggable set={set} distance={distance} enabled={ENABLED}>
84+
<Draggable
85+
set={set}
86+
distance={distance}
87+
enabled={ENABLED && !disableDraggable}
88+
>
8489
{children}
8590
</Draggable>
8691
</animated.group>

src/ideas/ui/TextInput/index.tsx

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { animated, useSpring } from "@react-spring/three";
66
import { useTextInput } from "../../../logic/input";
77
import { useKeypress, useShiftHold } from "../../../logic/keys";
88
import { usePlayer } from "../../../layers/Player";
9-
import { Mesh, MeshStandardMaterial, Raycaster } from "three";
9+
import { Group, Mesh, MeshStandardMaterial, Raycaster, Vector3 } from "three";
1010
import { syncOnChange } from "./logic/sync";
1111
import {
1212
getClickedCaret,
@@ -19,6 +19,7 @@ import { useDragSelect } from "./logic/drag";
1919
import { useLimitedFrame } from "../../../logic/limiter";
2020
import { cache } from "../../../logic/cache";
2121
import { HitBox } from "../../primitives/HitBox";
22+
import { useEnvironment } from "../../../layers/Environment";
2223

2324
type TextProps = {
2425
value?: string;
@@ -51,9 +52,12 @@ export function TextInput(props: TextProps) {
5152
} = props;
5253

5354
const clock = useThree((st) => st.clock);
55+
const camera = useThree((st) => st.camera);
5456
const player = usePlayer();
57+
const { device } = useEnvironment();
5558
const RAYCASTER = passedRaycaster || player.raycaster;
5659

60+
const group = useRef<Group>(null);
5761
const textRef = useRef<any>();
5862
const caret = useRef<Mesh>(null);
5963
const highlight = useRef<Mesh>(null);
@@ -67,18 +71,27 @@ export function TextInput(props: TextProps) {
6771

6872
const { input, focused, focusInput } = useTextInput(type, val, setVal);
6973

74+
// focus callback
7075
useEffect(() => {
7176
if (!onFocus) return;
7277
input.addEventListener("focus", onFocus);
7378
return () => input.removeEventListener("focus", onFocus);
7479
}, [input, onFocus]);
7580

81+
// blur callback
7682
useEffect(() => {
7783
if (!onBlur) return;
7884
input.addEventListener("blur", onBlur);
7985
return () => input.removeEventListener("blur", onBlur);
8086
}, [input, onBlur]);
8187

88+
// look at input when focused, only on mobile
89+
useEffect(() => {
90+
if (!group.current || !focused || !device.mobile) return;
91+
const worldpos = group.current.getWorldPosition(new Vector3());
92+
camera.lookAt(worldpos);
93+
}, [focused, camera, device]);
94+
8295
const { color } = useSpring({ color: focused ? "#000" : "#828282" });
8396

8497
const highlightMat = cache.useResource(
@@ -321,7 +334,7 @@ export function TextInput(props: TextProps) {
321334
});
322335

323336
return (
324-
<group name="spacesvr-text-input" {...rest}>
337+
<group name="spacesvr-text-input" {...rest} ref={group}>
325338
<group name="content" position-z={DEPTH / 2 + 0.001}>
326339
<Suspense fallback={null}>
327340
<Text

src/layers/Environment/ui/PauseMenu/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export default function PauseMenu(props: PauseMenuProps) {
4040
const PAUSE_ITEMS: MenuItem[] = [
4141
...pauseMenuItems,
4242
{
43-
text: "v2.10.3",
43+
text: "v2.10.4",
4444
link: "https://www.npmjs.com/package/spacesvr",
4545
},
4646
...menuItems,

src/layers/Player/components/controls/TouchFPSCamera.tsx

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,20 +59,17 @@ export default function TouchFPSCamera() {
5959
const onTouchMove = (ev: TouchEvent) => {
6060
const touch = getCurrentTouch(touchStartPos.current.id, ev.touches);
6161

62-
if (!touch) {
63-
return;
64-
}
62+
if (!touch) return;
6563

6664
const { clientX, clientY } = touch;
6765
const newEuler = getNewEuler(clientX, clientY);
6866
camera.quaternion.setFromEuler(newEuler);
6967
};
68+
7069
const onTouchEnd = (ev: TouchEvent) => {
7170
const touch = getCurrentTouch(touchStartPos.current.id, ev.changedTouches);
7271

73-
if (!touch) {
74-
return;
75-
}
72+
if (!touch) return;
7673

7774
const { clientX, clientY } = touch;
7875
originEuler.current = getNewEuler(clientX, clientY);
@@ -89,7 +86,7 @@ export default function TouchFPSCamera() {
8986
document.removeEventListener("touchmove", onTouchMove);
9087
document.removeEventListener("touchend", onTouchEnd);
9188
};
92-
}, []);
89+
}, [onTouchEnd, onTouchMove, onTouchStart]);
9390

9491
return null;
9592
}

src/layers/Toolbelt/ideas/ToolSwitcher.tsx

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,23 @@ export default function ToolSwitcher() {
88
const { size, gl } = useThree();
99

1010
const registered = useRef(false);
11-
const type = useRef<"side" | "bottom">("side");
1211

1312
const DETECT_RANGE_X = screen.width * 0.04;
1413
const DRAG_RANGE_X = screen.width * 0.08;
15-
16-
const DETECT_RANGE_Y = screen.height * 0.085;
17-
const DRAG_RANGE_Y = screen.height * 0.17;
14+
const DETECT_RANGE_Y = screen.height * 0.5;
1815

1916
const valid = useRef(false);
2017
useDrag(
2118
{
2219
onStart: ({ e, touch }) => {
2320
valid.current = false;
2421

25-
const inBottomEdge = size.height - touch.clientY < DETECT_RANGE_Y;
2622
const inSideEdge =
2723
Math.min(touch.clientX, size.width - touch.clientX) < DETECT_RANGE_X;
24+
const inTopThird = touch.clientY < DETECT_RANGE_Y;
2825

29-
// ignore corners or no match
30-
if (inBottomEdge === inSideEdge) return;
31-
// don't trigger bottom swipe if there's an active tool
32-
if (inBottomEdge && toolbelt.activeIndex !== undefined) return;
33-
34-
if (inBottomEdge) type.current = "bottom";
35-
if (inSideEdge) type.current = "side";
26+
// ignore if not in top third or side edge
27+
if (!inSideEdge || !inTopThird) return;
3628

3729
valid.current = true;
3830
registered.current = false;
@@ -43,12 +35,7 @@ export default function ToolSwitcher() {
4335
onMove: ({ delta }) => {
4436
if (!valid.current || registered.current) return;
4537

46-
if (type.current == "bottom" && delta.y < -DRAG_RANGE_Y) {
47-
registered.current = true;
48-
toolbelt.show();
49-
}
50-
51-
if (type.current == "side" && Math.abs(delta.x) > DRAG_RANGE_X) {
38+
if (Math.abs(delta.x) > DRAG_RANGE_X) {
5239
registered.current = true;
5340
if (delta.x > 0) {
5441
toolbelt.next();

src/logic/dom.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
// check whether the user is currently typing
22
export const isTyping = (): boolean =>
3-
document?.activeElement?.tagName === "INPUT";
3+
document?.activeElement?.tagName === "INPUT" && document?.hasFocus();

0 commit comments

Comments
 (0)