Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/nickjs/remix-three

Utilities to integrate react-three-fiber into a remix.run app
https://github.com/nickjs/remix-three

Last synced: 3 months ago
JSON representation

Utilities to integrate react-three-fiber into a remix.run app

Awesome Lists containing this project

README

        

## remix-three

Hi! remix-three is a very tiny shim layer allowing you to render a `` from [`@react-three/fiber`](https://docs.pmnd.rs/react-three-fiber/) into a [Remix](https://remix.run) app, as well as render Remix ``s and calls to `useLoaderData()` _inside_ your ``.

This repo consists of three things:

1. A set of `patch-package` patches to make all the `@react-three/*` libraries play nice with the Remix compiler.
2. A `useRemixBridge` utility build on `@react-three/drei`'s `useContextBridge` that will replay all of the necessary Remix context values into the `` rendering fiber.
3. A `` component that allows you to have any object in your 3D scene participate in Remix navigation.

## Getting started

1. `npm i remix-three @react-three/[email protected] @react-three/[email protected] @remix-run/[email protected] patch-package`

2. Add the following to your `package.json`:

```json
{
"scripts": {
"postinstall": "patch-package --patch-dir node_modules/remix-three/patches"
}
}
```

3. Use `useRemixBridge()` when you create your ``:

```tsx
// app/routes/canvas.tsx
import { useRemixBridge } from "remix-three";

export default function CanvasRoute() {
let RemixBridge = useRemixBridge();

return (





);
}

function MyScene() {
let matches = useMatches();
let data = useLoaderData();
let location = useLocation();

return (




);
}
```

> NB: You **must** split out your scene content into a separate component that you render _inside_ the RemixBridge in order to access anything from the remix or react-router context.

## Link3d

In general, this component takes the exact same props as a regular Remix `` but wraps an `Object3D` inside your scene. It works by invoking navigation directly in the same way a regular `` would. It is totally possible this component may mess with your refs or click handlers of the child element, but I've done my best to avoid that.

```tsx
import { Link3d } from 'remix-three'

function MyScene() {
return (






)
}
```