Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am mwmwmw on github.
  • I am mwmwmw (https://keybase.io/mwmwmw) on keybase.
  • I have a public key whose fingerprint is 45FB 1BC7 C090 C925 DF2B 5A12 BE11 ACCE 6CBD 72CB

To claim this, I am signing this object:

@mwmwmw
mwmwmw / Color.js
Created December 16, 2017 08:04
Just some color conversion stuff
const HEX = /#([0-9ABCDEF]{2})([0-9ABCDEF]{2})([0-9ABCDEF]{2})/;
const VEC3 = /vec3\s?\(([0-9.]*),\s?([0-9.]*),\s?([0-9.]*)\)/;
const DEFAULT_VALUE = 0;
class Color {
static hex2vec3(hex) {
let matches = Color.parseHex(hex);
return Color.vec3(matches, 256);
}
@mwmwmw
mwmwmw / ScrollPos.js
Last active June 14, 2019 21:22
Acceleration Based Scroll Position
const MOUSE_WHEEL_EVENT = "wheel";
const TOUCH_MOVE = "touchmove";
const TOUCH_END = "touchend";
const MOUSE_DOWN = "mousedown";
const MOUSE_UP = "mouseup";
const MOUSE_MOVE = "mousemove";
class ScrollPos {
constructor() {
this.acceleration = 0;
this.maxAcceleration = 5;
@mwmwmw
mwmwmw / PillCollision.js
Created October 16, 2019 22:24
A basic line with distance collider. It's called a pill collider because of the pill shape it.
import { Vector3, Object3D, BufferGeometry, Math as M, Group, LineBasicMaterial, Line, Line3, CylinderBufferGeometry, BufferAttribute, SphereBufferGeometry } from "three";
export function Pill(start, end, radius) {
Object3D.call(this);
this.radius = radius;
this.type = "Pill";
this._start = start;
this._end = end;
@mwmwmw
mwmwmw / useOpenSeaAssets.js
Last active October 4, 2021 16:09
A React hook for grabbing assets from OpenSea
import { useEffect, useState } from 'react';
const options = { method: 'GET' };
export default function useOpenSeaAssets({
owner,
sortDirection = 'asc',
offset = 0,
limit = 50,
collection,
@mwmwmw
mwmwmw / useOpenSeaCollections.js
Last active October 4, 2021 16:09
A React hook for querying OpenSea collections
import { useEffect, useState } from 'react';
const options = { method: 'GET' };
export default function useOpenSeaCollections({
owner,
offset = 0,
limit = 50,
}) {
const [collections, setCollections] = useState([]);
@mwmwmw
mwmwmw / Portal.js
Last active December 8, 2022 13:59
React Portal
import { useEffect, useMemo } from "react";
import { createPortal } from "react-dom";
export default function Portal({ children, root = 'overlay', pointerEvents = true }) {
const el = useMemo(() => document.createElement("div"), []);
const rootElement = useMemo(() => document.getElementById(root), [root]);
useEffect(() => {
rootElement.style = `pointer-events: ${pointerEvents ? 'all' : 'none'}`;
@mwmwmw
mwmwmw / usePipedreamSSE.js
Last active November 17, 2021 09:18
A React Hook for using Pipedreams SSE endpoints
/**
This hook is for interacting with Pipedreams Server Signal Events.
Padd in the endpointId, channel to listen to, and a callback function for when an event arrives.
Passed out of the hook is a function for sending messages back to the server as well as a list of messages.
*/
import { useCallback, useEffect, useState } from 'react';
export default function usePipeDreamSSE(
@mwmwmw
mwmwmw / TeleportTravel.js
Last active November 16, 2021 06:09
TeleportTravel.js is a rudimentary ReactXR teleportation system. Wrap the geometry that you want to player to be able to target in <TeleportTravel> to use it.
import { Raycaster, Vector3 } from 'three';
import { useXR, Interactive } from '@react-three/xr';
import { useFrame } from '@react-three/fiber';
import { useCallback, useRef, useState } from 'react';
export function TeleportIndicator(props) {
return (
<>
<pointLight position={[0, 0.5, 0]} args={[0xff00ff, 2, 0.6]} />