-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #148 from musehq/dev
v2.8.0
- Loading branch information
Showing
23 changed files
with
401 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { ColorRepresentation } from "three"; | ||
import { Interactable, InteractableProps } from "../modifiers/Interactable"; | ||
import { MeshProps } from "@react-three/fiber"; | ||
|
||
type HitBox = { | ||
args: [number, number, number]; | ||
visible?: boolean; | ||
color?: ColorRepresentation; | ||
} & Omit<InteractableProps, "children"> & | ||
Omit<MeshProps, "args">; | ||
|
||
export function HitBox(props: HitBox) { | ||
const { | ||
args, | ||
visible = false, | ||
color = "red", | ||
onClick, | ||
onHover, | ||
onUnHover, | ||
...rest | ||
} = props; | ||
|
||
return ( | ||
<Interactable onClick={onClick} onHover={onHover} onUnHover={onUnHover}> | ||
<mesh visible={visible} name="spacesvr-hitbox" {...rest}> | ||
<boxBufferGeometry args={args} /> | ||
{visible && ( | ||
<meshBasicMaterial color={color} transparent opacity={0.7} /> | ||
)} | ||
</mesh> | ||
</Interactable> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
import { cache } from "../../logic/cache"; | ||
import { NamedArrayTuple } from "@react-three/drei/helpers/ts-utils"; | ||
import { useMemo } from "react"; | ||
import { RoundedBoxGeometry } from "three/examples/jsm/geometries/RoundedBoxGeometry"; | ||
|
||
type RoundedBox = { | ||
args?: NamedArrayTuple< | ||
(width?: number, height?: number, depth?: number) => void | ||
>; | ||
} & Omit<JSX.IntrinsicElements["mesh"], "args">; | ||
|
||
export function RoundedBox(props: RoundedBox) { | ||
const { | ||
args: [width = 1, height = 1, depth = 0.25] = [], | ||
children, | ||
...rest | ||
} = props; | ||
|
||
const geo = useMemo(() => { | ||
const tolerance = 0.25; // 25% tolerance | ||
|
||
let closestBox = undefined; | ||
let closestOffset = Infinity; | ||
for (const box of CACHED_BOXES) { | ||
const scale = box.width / width; | ||
const heightDiff = Math.abs(box.height - height * scale); | ||
const depthDiff = Math.abs(box.depth - depth * scale); | ||
if ( | ||
heightDiff / box.height < tolerance && | ||
depthDiff / box.depth < tolerance && | ||
heightDiff + depthDiff < closestOffset | ||
) { | ||
closestBox = box; | ||
closestOffset = heightDiff + depthDiff; | ||
} | ||
} | ||
|
||
if (closestBox) { | ||
return (cache[closestBox.key] as RoundedBoxGeometry) | ||
.clone() | ||
.scale( | ||
width / closestBox.width, | ||
height / closestBox.height, | ||
depth / closestBox.depth | ||
); | ||
} | ||
|
||
const radius = Math.min(width, height, depth) / 2; | ||
return new RoundedBoxGeometry(width, height, depth, 4, radius); | ||
}, [width, height, depth]); | ||
|
||
return ( | ||
<mesh name="spacesvr-rounded-box" {...rest} geometry={geo}> | ||
{children} | ||
</mesh> | ||
); | ||
} | ||
|
||
type CachedBox = { | ||
width: number; | ||
height: number; | ||
depth: number; | ||
key: keyof typeof cache; | ||
}; | ||
|
||
const CACHED_BOXES: CachedBox[] = [ | ||
{ | ||
width: 1, | ||
height: 1, | ||
depth: 0.25, | ||
key: "geo_rounded_box_1x1x0_25", | ||
}, | ||
{ | ||
width: 1, | ||
height: 0.35, | ||
depth: 0.125, | ||
key: "geo_rounded_box_1x0_35x0_125", | ||
}, | ||
{ | ||
width: 1, | ||
height: 0.3, | ||
depth: 0.1, | ||
key: "geo_rounded_box_1x0_3x0_1", | ||
}, | ||
{ | ||
width: 1, | ||
height: 0.19, | ||
depth: 0.23, | ||
key: "geo_rounded_box_1x0_19x0_23", | ||
}, | ||
{ | ||
width: 1, | ||
height: 0.44, | ||
depth: 0.23, | ||
key: "geo_rounded_box_1x0_44x0_23", | ||
}, | ||
{ | ||
width: 1, | ||
height: 0.11, | ||
depth: 0.06, | ||
key: "geo_rounded_box_1x0_11x0_06", | ||
}, | ||
{ | ||
width: 1, | ||
height: 0.13, | ||
depth: 0.04, | ||
key: "geo_rounded_box_1x0_13x0_04", | ||
}, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
08bceb6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
spacesvr – ./
spacesvr-git-master-muse-hq.vercel.app
spacesvr.vercel.app
spacesvr.io
www.spacesvr.io
spacesvr-muse-hq.vercel.app