• Stars
    star
    528
  • Rank 83,941 (Top 2 %)
  • Language
    TypeScript
  • Created about 5 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

GUI tools for react-three-fiber and react-spring

react-three-gui

A graphical user interface for changing variable states in React.

Using this repo

To use this repo, run the following commands inside the repo directory:
yarn install
yarn build
yarn pack
This will generate a tarball .tgz that you can copy to your project directory.
Then you can run: yarn add ./react-three-gui.tgz which will install it.

Examples

https://codesandbox.io/s/react-three-fiber-gui-62pvp

Example

Usage

Basic example

import { Controls, useControl } from 'react-three-gui';

const MyMesh = () => {
  const rotationX = useControl('Rotation X', { type: 'number' });
  return <mesh rotation-x={rotationX} />;
}


export const App = () => {
  return (
    <Controls.Provider>
      <Controls.Canvas>
        <MyMesh />
      </Controls.Canvas>
      <Controls />
    </Controls.Provider>
  );
};

Use the spring option to return a react-spring value:

useControl('My ctrl', {
  type: 'number',
  spring: true,
});

// or pass a react-spring configuration value

useControl('My ctrl', {
  type: 'number',
  spring: { mass: 5, tension: 280, friction: 50 },
});

Also possible to pass in your own state:

const [value, set] = useState(0);

useControl('Adjust value', {
  type: 'number',
  state: [value, set],
});

Also you can pass your own control component:

const MyControl = ({ value, setValue }) => (
  <input
    type="number"
    onChange={e => setValue(e.currentTarget.value)}
    value={value}
  />
);

useControl('Test', {
  type: 'custom',
  value: 2,
  component: MyControl,
});

Use your own Canvas

import { Canvas } from 'react-three-fiber';
import { withControls } from 'react-three-gui';

// Wrap the <Canvas> with `withControls`
const YourCanvas = withControls(Canvas);

const Scene = () => (
  <YourCanvas>
    <mesh rotation-x={rotationX} />
  </YourCanvas>
);

const App = () => {
  return (
    <Controls.Provider>
      <Scene />
      <Controls />
    </Controls.Provider>
  );
};

API

import { useControl, Controls } from 'react-three-gui';

// All the possible options
useControl(name: string, {
  // General
  type: 'number' | 'xypad' | 'boolean' | 'button' | 'color' | 'select' | 'string' | 'file' | 'custom';
  value: any; // Initial value
  spring: boolean | SpringConfig; // Use spring
  group: string; // Group name
  state: [any, Dispatch<SetStateAction<any>>]; // Use your own state
  onChange(value: any): void; // onChange callback

  // number | xypad
  min: number; // Minimum value (default: 0)
  max: number; // Maximum value (default: 1)
  distance: number; // The end-to-end slider distance (default: 1)
  scrub: boolean; // When slider is released it will reset to the center but keep its value

  // select
  items: string[];

  // button
  onClick(): void;

  // file
  loader?: THREE.TextureLoader | THREE.FileLoader | etc;

  // custom
  component?: React.Component;
});

// Controls component
<Controls
  title="react-three-gui"
  collapsed={true}
  defaultClosedGroups={['Other', 'Stuff']}
  width={300} // default 300
  anchor={'top_left' | 'bottom_left' | 'top_right' | 'bottom_right'} // see ControlsAnchor enum
  style={{ ... }} // pass any kind of styles here. Supports @react-spring/web styles.
/>

Supported controls

  • number
    • Returns number
  • xypad
    • Returns { x: number, y: number } object
  • boolean
    • Returns boolean
  • button
    • Returns void
  • color
    • Returns string (as hex: #ffffff)
  • select
    • Returns string
  • file
    • Returns new THREE.FileLoader
  • string
    • Returns string

Future plans

  • Support custom control components
  • File upload loader control
  • Groups
  • Draggable Widget
  • Collapsable widget
  • Persist state localstorage
  • Multi platform?

More Repositories

1

prime

✨Open Source GraphQL CMS
TypeScript
1,718
star
2

react-native-carplay

CarPlay with React Native
TypeScript
657
star
3

hekla

Hekla for Hacker News (open source React Native app)
TypeScript
363
star
4

gatsby-source-prismic-graphql

Gatsby source plugin for Prismic GraphQL
TypeScript
137
star
5

react-native-sfsymbols

SF Symbols in your iOS app
Objective-C
126
star
6

react-native-appstore

App Store clone in React Native
JavaScript
109
star
7

homebridge-plugin-eufy-security

Eufy security homebridge plugin
TypeScript
84
star
8

kvikmyndr-app

Whats in the movies tonight?
TypeScript
50
star
9

graphql-gatsby

Direct access to Gatsby's GraphQL schema and resolvers without the ecosystem
JavaScript
49
star
10

react-three-fiber-examples

react-three-fiber examples in react native
JavaScript
36
star
11

react-native-webgl-arkit

THREE.js ARKit extension for react-native-webgl
Objective-C
32
star
12

kohana-gitweb

GitHub 'like Repository Browser for Kohana 3.3
JavaScript
29
star
13

gatsby-plugin-prismic-preview

Preview plugin for gatsby-source-prismic
CSS
25
star
14

graphql-mst

Convert GraphQL to mobx-state-tree models
TypeScript
23
star
15

react-typescript-iso-kit

Another starter kit with typescript, jest, isomorphic, webpack etc.
JavaScript
22
star
16

gatsby-source-graphql-universal

Plugin for connecting arbitrary GraphQL APIs to Gatsby GraphQL with client side execution
JavaScript
20
star
17

react-suspense-demo

React Suspense Demo inspired by Dan's future api
JavaScript
20
star
18

obdii

OBD2 in TypeScript
JavaScript
19
star
19

react-native-youtubetv-demo

Re-creating YouTube TV's animated list in React Native
JavaScript
12
star
20

arduino-wiegand

Wiegand-26 library for communicating with 2-wire wiegand protocol.
C++
10
star
21

next-meets-gatsby

NextJS meets Gatsby source plugins as a graphql server
JavaScript
10
star
22

kohana-schema

Kohana 3.3 database schema and migration.
PHP
8
star
23

evrange

Estimate kW consumption routes for electric vehicles
TypeScript
8
star
24

react-starter-kit-rdb

React Starter Kit - Rethinkdb Universal Edition
JavaScript
7
star
25

react-children-addons

React Children Addons
TypeScript
7
star
26

bootstrap-tableselect

Table row selection for twitter bootstrap
7
star
27

kohana-media

Kohana 3.3 media module
PHP
6
star
28

react-native-three-renderer

Experimental react-native three.js renderer
JavaScript
6
star
29

kohana-app-places

The mobile and desktop website to find something to eat.
PHP
5
star
30

matr-app

JavaScript
5
star
31

plugin.video.oztv

XBMC Port of the popular OZ app for Android and iOS devices
Python
3
star
32

kohana-api-bokun

Kohana REST client for Bokun API.
PHP
3
star
33

universal-redux-demo

Universal redux demo
JavaScript
3
star
34

support-tickets

Support Ticket system written for Kohana 3.3
PHP
2
star
35

codingame

CodinGame solutions
JavaScript
2
star
36

kohana-app-drag

Drag times application
JavaScript
2
star
37

gatsby-plugin-config

Config plugin for gatsby
JavaScript
2
star
38

ovms-client

OVMS client written in TypeScript
TypeScript
2
star
39

react-native-css-modules-theme

Theme support for CSS Modules in React Native
TypeScript
2
star
40

material-components-react-native

React Native wrapper for material-components-ios
Objective-C
2
star
41

sensornodes

A RF node network providing sensing devices to my home
C++
2
star
42

arduino-ledtable

led-table matrix effect generator
C++
2
star
43

OZ.bundle

OZ TV bundle for Plex Media Server
Python
1
star
44

sass-flexbox-grid

Sass flexbox grid
CSS
1
star
45

kohana-hhvm

HHVM module for the Kohana Framework
PHP
1
star
46

cra-pipeline

create-react-app pipeline experiments
JavaScript
1
star
47

prime-bokun

Bokun module for Prime 3.3
PHP
1
star
48

app-postbox

React Native Postbox Client
JavaScript
1
star
49

cheffy

Recipes in React, Redux and Firebase
JavaScript
1
star
50

react-native-app-center-ndk

Example repo to reproduce NDK build failure in AppCenter
Objective-C
1
star